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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 266 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
266 if (new_extension && new_extension->is_hosted_app() && | 267 if (new_extension && new_extension->is_hosted_app() && |
267 new_extension->id() == kWebStoreAppId && | 268 new_extension->id() == kWebStoreAppId && |
268 !ProcessMap::Get(process_host->GetBrowserContext()) | 269 !ProcessMap::Get(process_host->GetBrowserContext()) |
269 ->Contains(new_extension->id(), process_host->GetID())) { | 270 ->Contains(new_extension->id(), process_host->GetID())) { |
270 return false; | 271 return false; |
271 } | 272 } |
272 return true; | 273 return true; |
273 } | 274 } |
274 | 275 |
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; | |
Charlie Reis
2016/08/02 20:41:42
Sanity check: We'll still deny this case because t
ananta
2016/08/02 22:28:27
The URL won't be found in the RDH map and hence wi
| |
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. | |
Charlie Reis
2016/08/02 20:41:42
Please don't lose all the comments in this method.
ananta
2016/08/02 22:28:27
Done.
| |
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 | 276 // static |
322 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( | 277 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
323 Profile* profile, | 278 Profile* profile, |
324 content::RenderProcessHost* process_host, | 279 content::RenderProcessHost* process_host, |
325 const GURL& site_url) { | 280 const GURL& site_url) { |
326 DCHECK(profile); | 281 DCHECK(profile); |
327 | 282 |
328 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 283 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
329 ProcessMap* process_map = ProcessMap::Get(profile); | 284 ProcessMap* process_map = ProcessMap::Get(profile); |
330 | 285 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 site_instance->GetSiteURL()); | 501 site_instance->GetSiteURL()); |
547 if (!extension) | 502 if (!extension) |
548 return; | 503 return; |
549 | 504 |
550 ProcessMap::Get(context)->Insert(extension->id(), | 505 ProcessMap::Get(context)->Insert(extension->id(), |
551 site_instance->GetProcess()->GetID(), | 506 site_instance->GetProcess()->GetID(), |
552 site_instance->GetId()); | 507 site_instance->GetId()); |
553 | 508 |
554 BrowserThread::PostTask( | 509 BrowserThread::PostTask( |
555 BrowserThread::IO, FROM_HERE, | 510 BrowserThread::IO, FROM_HERE, |
556 base::Bind(&InfoMap::RegisterExtensionProcess, | 511 base::Bind(&ChromeContentBrowserClientExtensionsPart:: |
557 ExtensionSystem::Get(context)->info_map(), extension->id(), | 512 RegisterExtensionProcessHelper, |
558 site_instance->GetProcess()->GetID(), site_instance->GetId())); | 513 base::RetainedRef(ExtensionSystem::Get(context)->info_map()), |
514 base::RetainedRef(extension), | |
515 site_instance->GetProcess()->GetID(), site_instance->GetId(), | |
516 context->GetResourceContext())); | |
559 } | 517 } |
560 | 518 |
561 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( | 519 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( |
562 SiteInstance* site_instance) { | 520 SiteInstance* site_instance) { |
563 BrowserContext* context = site_instance->GetBrowserContext(); | 521 BrowserContext* context = site_instance->GetBrowserContext(); |
564 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 522 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
565 if (!registry) | 523 if (!registry) |
566 return; | 524 return; |
567 | 525 |
568 const Extension* extension = | 526 const Extension* extension = |
569 registry->enabled_extensions().GetExtensionOrAppByURL( | 527 registry->enabled_extensions().GetExtensionOrAppByURL( |
570 site_instance->GetSiteURL()); | 528 site_instance->GetSiteURL()); |
571 if (!extension) | 529 if (!extension) |
572 return; | 530 return; |
573 | 531 |
574 ProcessMap::Get(context)->Remove(extension->id(), | 532 ProcessMap::Get(context)->Remove(extension->id(), |
575 site_instance->GetProcess()->GetID(), | 533 site_instance->GetProcess()->GetID(), |
576 site_instance->GetId()); | 534 site_instance->GetId()); |
577 | 535 |
578 BrowserThread::PostTask( | 536 BrowserThread::PostTask( |
579 BrowserThread::IO, FROM_HERE, | 537 BrowserThread::IO, FROM_HERE, |
580 base::Bind(&InfoMap::UnregisterExtensionProcess, | 538 base::Bind(&ChromeContentBrowserClientExtensionsPart:: |
581 ExtensionSystem::Get(context)->info_map(), extension->id(), | 539 UnregisterExtensionProcessHelper, |
582 site_instance->GetProcess()->GetID(), site_instance->GetId())); | 540 base::RetainedRef(ExtensionSystem::Get(context)->info_map()), |
541 base::RetainedRef(extension), | |
542 site_instance->GetProcess()->GetID(), site_instance->GetId(), | |
543 context->GetResourceContext())); | |
583 } | 544 } |
584 | 545 |
585 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( | 546 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( |
586 RenderViewHost* rvh, | 547 RenderViewHost* rvh, |
587 WebPreferences* web_prefs) { | 548 WebPreferences* web_prefs) { |
588 const ExtensionRegistry* registry = | 549 const ExtensionRegistry* registry = |
589 ExtensionRegistry::Get(rvh->GetProcess()->GetBrowserContext()); | 550 ExtensionRegistry::Get(rvh->GetProcess()->GetBrowserContext()); |
590 if (!registry) | 551 if (!registry) |
591 return; | 552 return; |
592 | 553 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 #if defined(ENABLE_WEBRTC) | 616 #if defined(ENABLE_WEBRTC) |
656 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); | 617 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); |
657 #endif | 618 #endif |
658 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 619 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
659 switches::kEnableMojoSerialService)) { | 620 switches::kEnableMojoSerialService)) { |
660 command_line->AppendSwitch(switches::kEnableMojoSerialService); | 621 command_line->AppendSwitch(switches::kEnableMojoSerialService); |
661 } | 622 } |
662 } | 623 } |
663 } | 624 } |
664 | 625 |
626 // static | |
627 void ChromeContentBrowserClientExtensionsPart::RegisterExtensionProcessHelper( | |
628 InfoMap* info_map, | |
629 const Extension* extension, | |
630 int process_id, | |
631 int site_instance_id, | |
632 const content::ResourceContext* context) { | |
633 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
634 | |
635 info_map->RegisterExtensionProcess(extension->id(), process_id, | |
636 site_instance_id); | |
637 | |
638 if (extension->is_platform_app()) { | |
Charlie Reis
2016/08/02 20:41:42
This would be a good place for some of the previou
ananta
2016/08/02 22:28:27
Done.
| |
639 content::ResourceDispatcherHost::Get()->AddProcessForOrigin( | |
640 context, | |
641 Extension::GetBaseURLFromExtensionId(extension->id()).spec(), | |
642 process_id); | |
643 } | |
644 } | |
645 | |
646 // static | |
647 void ChromeContentBrowserClientExtensionsPart::UnregisterExtensionProcessHelper( | |
648 InfoMap* info_map, | |
649 const Extension* extension, | |
650 int process_id, | |
651 int site_instance_id, | |
652 const content::ResourceContext* context) { | |
653 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
654 | |
655 info_map->UnregisterExtensionProcess(extension->id(), process_id, | |
656 site_instance_id); | |
657 | |
658 if (extension->is_platform_app()) { | |
659 content::ResourceDispatcherHost::Get()->RemoveProcessForOrigin( | |
660 context, | |
661 Extension::GetBaseURLFromExtensionId(extension->id()).spec(), | |
662 process_id); | |
663 } | |
664 } | |
665 | |
665 } // namespace extensions | 666 } // namespace extensions |
OLD | NEW |