| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par
t.h" | 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par
t.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_web_ui.h" | 14 #include "chrome/browser/extensions/extension_web_ui.h" |
| 15 #include "chrome/browser/extensions/extension_webkit_preferences.h" | 15 #include "chrome/browser/extensions/extension_webkit_preferences.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" | 20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" |
| 21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/extension_process_policy.h" | 24 #include "chrome/common/extensions/extension_process_policy.h" |
| 25 #include "components/guest_view/browser/guest_view_message_filter.h" | 25 #include "components/guest_view/browser/guest_view_message_filter.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/browser_url_handler.h" | 27 #include "content/public/browser/browser_url_handler.h" |
| 28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/resource_dispatcher_host.h" |
| 30 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
| 31 #include "content/public/browser/vpn_service_proxy.h" | 32 #include "content/public/browser/vpn_service_proxy.h" |
| 32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 34 #include "extensions/browser/api/web_request/web_request_api.h" | 35 #include "extensions/browser/api/web_request/web_request_api.h" |
| 35 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 36 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
| 36 #include "extensions/browser/extension_host.h" | 37 #include "extensions/browser/extension_host.h" |
| 37 #include "extensions/browser/extension_message_filter.h" | 38 #include "extensions/browser/extension_message_filter.h" |
| 38 #include "extensions/browser/extension_registry.h" | 39 #include "extensions/browser/extension_registry.h" |
| 39 #include "extensions/browser/extension_service_worker_message_filter.h" | 40 #include "extensions/browser/extension_service_worker_message_filter.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 registry->enabled_extensions().GetByID(extension_id); | 119 registry->enabled_extensions().GetByID(extension_id); |
| 119 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) | 120 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) |
| 120 return PRIV_ISOLATED; | 121 return PRIV_ISOLATED; |
| 121 if (extension && extension->is_hosted_app()) | 122 if (extension && extension->is_hosted_app()) |
| 122 return PRIV_HOSTED; | 123 return PRIV_HOSTED; |
| 123 } | 124 } |
| 124 | 125 |
| 125 return PRIV_EXTENSION; | 126 return PRIV_EXTENSION; |
| 126 } | 127 } |
| 127 | 128 |
| 129 // Helper functions to register and unregister an extension process. Invoked |
| 130 // on the IO thread. |
| 131 void RegisterExtensionProcessHelper(InfoMap* info_map, |
| 132 const Extension* extension, |
| 133 int process_id, |
| 134 int site_instance_id, |
| 135 const content::ResourceContext* context) { |
| 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 137 |
| 138 info_map->RegisterExtensionProcess(extension->id(), process_id, |
| 139 site_instance_id); |
| 140 |
| 141 // Please refer to the ResourceDispatcherHostImpl::IsIllegalOrigin() function |
| 142 // for more information on how we decide whether an extension URL being |
| 143 // committed is allowed or not. |
| 144 // In general we want to achieve this. |
| 145 // 1. If there is no extension installed for the URL, it should not be |
| 146 // committed |
| 147 // 2. Extension owner processes are always allowed. |
| 148 // 3. Guest processes are allowed only for platform apps which have resources |
| 149 // accessible to WebViews. |
| 150 if (content::ResourceDispatcherHost::Get()) { |
| 151 content::ResourceDispatcherHost::Get()->AddProcessForOrigin( |
| 152 context, |
| 153 Extension::GetBaseURLFromExtensionId(extension->id()).spec(), |
| 154 process_id, |
| 155 true); |
| 156 } |
| 157 } |
| 158 |
| 159 void UnregisterExtensionProcessHelper(InfoMap* info_map, |
| 160 const Extension* extension, |
| 161 int process_id, |
| 162 int site_instance_id, |
| 163 const content::ResourceContext* context) { |
| 164 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 165 |
| 166 info_map->UnregisterExtensionProcess(extension->id(), process_id, |
| 167 site_instance_id); |
| 168 |
| 169 if (content::ResourceDispatcherHost::Get()) { |
| 170 content::ResourceDispatcherHost::Get()->RemoveProcessForOrigin( |
| 171 context, |
| 172 Extension::GetBaseURLFromExtensionId(extension->id()).spec(), |
| 173 process_id, |
| 174 true); |
| 175 } |
| 176 } |
| 177 |
| 128 } // namespace | 178 } // namespace |
| 129 | 179 |
| 130 ChromeContentBrowserClientExtensionsPart:: | 180 ChromeContentBrowserClientExtensionsPart:: |
| 131 ChromeContentBrowserClientExtensionsPart() { | 181 ChromeContentBrowserClientExtensionsPart() { |
| 132 } | 182 } |
| 133 | 183 |
| 134 ChromeContentBrowserClientExtensionsPart:: | 184 ChromeContentBrowserClientExtensionsPart:: |
| 135 ~ChromeContentBrowserClientExtensionsPart() { | 185 ~ChromeContentBrowserClientExtensionsPart() { |
| 136 } | 186 } |
| 137 | 187 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 315 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 266 if (new_extension && new_extension->is_hosted_app() && | 316 if (new_extension && new_extension->is_hosted_app() && |
| 267 new_extension->id() == kWebStoreAppId && | 317 new_extension->id() == kWebStoreAppId && |
| 268 !ProcessMap::Get(process_host->GetBrowserContext()) | 318 !ProcessMap::Get(process_host->GetBrowserContext()) |
| 269 ->Contains(new_extension->id(), process_host->GetID())) { | 319 ->Contains(new_extension->id(), process_host->GetID())) { |
| 270 return false; | 320 return false; |
| 271 } | 321 } |
| 272 return true; | 322 return true; |
| 273 } | 323 } |
| 274 | 324 |
| 275 bool ChromeContentBrowserClientExtensionsPart::IsIllegalOrigin( | |
| 276 content::ResourceContext* resource_context, | |
| 277 int child_process_id, | |
| 278 const GURL& origin) { | |
| 279 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 280 | |
| 281 // Consider non-extension URLs safe; they will be checked elsewhere. | |
| 282 if (!origin.SchemeIs(kExtensionScheme)) | |
| 283 return false; | |
| 284 | |
| 285 // If there is no extension installed for the URL, it couldn't have committed. | |
| 286 // (If the extension was recently uninstalled, the tab would have closed.) | |
| 287 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
| 288 InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); | |
| 289 const Extension* extension = | |
| 290 extension_info_map->extensions().GetExtensionOrAppByURL(origin); | |
| 291 if (!extension) | |
| 292 return true; | |
| 293 | |
| 294 // Check for platform app origins. These can only be committed by the app | |
| 295 // itself, or by one if its guests if there are accessible_resources. | |
| 296 const ProcessMap& process_map = extension_info_map->process_map(); | |
| 297 if (extension->is_platform_app() && | |
| 298 !process_map.Contains(extension->id(), child_process_id)) { | |
| 299 // This is a platform app origin not in the app's own process. If there are | |
| 300 // no accessible resources, this is illegal. | |
| 301 if (!extension->GetManifestData(manifest_keys::kWebviewAccessibleResources)) | |
| 302 return true; | |
| 303 | |
| 304 // If there are accessible resources, the origin is only legal if the given | |
| 305 // process is a guest of the app. | |
| 306 std::string owner_extension_id; | |
| 307 int owner_process_id; | |
| 308 WebViewRendererState::GetInstance()->GetOwnerInfo( | |
| 309 child_process_id, &owner_process_id, &owner_extension_id); | |
| 310 const Extension* owner_extension = | |
| 311 extension_info_map->extensions().GetByID(owner_extension_id); | |
| 312 return !owner_extension || owner_extension != extension; | |
| 313 } | |
| 314 | |
| 315 // With only the origin and not the full URL, we don't have enough information | |
| 316 // to validate hosted apps or web_accessible_resources in normal extensions. | |
| 317 // Assume they're legal. | |
| 318 return false; | |
| 319 } | |
| 320 | |
| 321 // static | 325 // static |
| 322 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( | 326 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 323 Profile* profile, | 327 Profile* profile, |
| 324 content::RenderProcessHost* process_host, | 328 content::RenderProcessHost* process_host, |
| 325 const GURL& site_url) { | 329 const GURL& site_url) { |
| 326 DCHECK(profile); | 330 DCHECK(profile); |
| 327 | 331 |
| 328 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 332 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
| 329 ProcessMap* process_map = ProcessMap::Get(profile); | 333 ProcessMap* process_map = ProcessMap::Get(profile); |
| 330 | 334 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 site_instance->GetSiteURL()); | 550 site_instance->GetSiteURL()); |
| 547 if (!extension) | 551 if (!extension) |
| 548 return; | 552 return; |
| 549 | 553 |
| 550 ProcessMap::Get(context)->Insert(extension->id(), | 554 ProcessMap::Get(context)->Insert(extension->id(), |
| 551 site_instance->GetProcess()->GetID(), | 555 site_instance->GetProcess()->GetID(), |
| 552 site_instance->GetId()); | 556 site_instance->GetId()); |
| 553 | 557 |
| 554 BrowserThread::PostTask( | 558 BrowserThread::PostTask( |
| 555 BrowserThread::IO, FROM_HERE, | 559 BrowserThread::IO, FROM_HERE, |
| 556 base::Bind(&InfoMap::RegisterExtensionProcess, | 560 base::Bind(&RegisterExtensionProcessHelper, |
| 557 ExtensionSystem::Get(context)->info_map(), extension->id(), | 561 base::RetainedRef(ExtensionSystem::Get(context)->info_map()), |
| 558 site_instance->GetProcess()->GetID(), site_instance->GetId())); | 562 base::RetainedRef(extension), |
| 563 site_instance->GetProcess()->GetID(), site_instance->GetId(), |
| 564 context->GetResourceContext())); |
| 559 } | 565 } |
| 560 | 566 |
| 561 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( | 567 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( |
| 562 SiteInstance* site_instance) { | 568 SiteInstance* site_instance) { |
| 563 BrowserContext* context = site_instance->GetBrowserContext(); | 569 BrowserContext* context = site_instance->GetBrowserContext(); |
| 564 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 570 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 565 if (!registry) | 571 if (!registry) |
| 566 return; | 572 return; |
| 567 | 573 |
| 568 const Extension* extension = | 574 const Extension* extension = |
| 569 registry->enabled_extensions().GetExtensionOrAppByURL( | 575 registry->enabled_extensions().GetExtensionOrAppByURL( |
| 570 site_instance->GetSiteURL()); | 576 site_instance->GetSiteURL()); |
| 571 if (!extension) | 577 if (!extension) |
| 572 return; | 578 return; |
| 573 | 579 |
| 574 ProcessMap::Get(context)->Remove(extension->id(), | 580 ProcessMap::Get(context)->Remove(extension->id(), |
| 575 site_instance->GetProcess()->GetID(), | 581 site_instance->GetProcess()->GetID(), |
| 576 site_instance->GetId()); | 582 site_instance->GetId()); |
| 577 | 583 |
| 578 BrowserThread::PostTask( | 584 BrowserThread::PostTask( |
| 579 BrowserThread::IO, FROM_HERE, | 585 BrowserThread::IO, FROM_HERE, |
| 580 base::Bind(&InfoMap::UnregisterExtensionProcess, | 586 base::Bind(&UnregisterExtensionProcessHelper, |
| 581 ExtensionSystem::Get(context)->info_map(), extension->id(), | 587 base::RetainedRef(ExtensionSystem::Get(context)->info_map()), |
| 582 site_instance->GetProcess()->GetID(), site_instance->GetId())); | 588 base::RetainedRef(extension), |
| 589 site_instance->GetProcess()->GetID(), site_instance->GetId(), |
| 590 context->GetResourceContext())); |
| 583 } | 591 } |
| 584 | 592 |
| 585 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( | 593 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( |
| 586 RenderViewHost* rvh, | 594 RenderViewHost* rvh, |
| 587 WebPreferences* web_prefs) { | 595 WebPreferences* web_prefs) { |
| 588 const ExtensionRegistry* registry = | 596 const ExtensionRegistry* registry = |
| 589 ExtensionRegistry::Get(rvh->GetProcess()->GetBrowserContext()); | 597 ExtensionRegistry::Get(rvh->GetProcess()->GetBrowserContext()); |
| 590 if (!registry) | 598 if (!registry) |
| 591 return; | 599 return; |
| 592 | 600 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); | 664 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); |
| 657 #endif | 665 #endif |
| 658 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 666 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 659 switches::kEnableMojoSerialService)) { | 667 switches::kEnableMojoSerialService)) { |
| 660 command_line->AppendSwitch(switches::kEnableMojoSerialService); | 668 command_line->AppendSwitch(switches::kEnableMojoSerialService); |
| 661 } | 669 } |
| 662 } | 670 } |
| 663 } | 671 } |
| 664 | 672 |
| 665 } // namespace extensions | 673 } // namespace extensions |
| OLD | NEW |