OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/extensions/extension_event_router.h" | 8 #include "chrome/browser/extensions/extension_event_router.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
11 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_view_type.h" | 19 #include "chrome/common/chrome_view_type.h" |
19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
20 #include "chrome/common/extensions/extension_messages.h" | 21 #include "chrome/common/extensions/extension_messages.h" |
21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/render_view_host_delegate.h" | 27 #include "content/public/browser/render_view_host_delegate.h" |
27 #include "content/public/browser/site_instance.h" | 28 #include "content/public/browser/site_instance.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/common/renderer_preferences.h" | 30 #include "content/public/common/renderer_preferences.h" |
30 | 31 |
31 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
32 #include "chrome/browser/extensions/extension_host_mac.h" | 33 #include "chrome/browser/extensions/extension_host_mac.h" |
33 #endif | 34 #endif |
34 | 35 |
35 using content::BrowserThread; | 36 using content::BrowserThread; |
36 using content::OpenURLParams; | 37 using content::OpenURLParams; |
37 using content::Referrer; | 38 using content::Referrer; |
38 using content::RenderViewHost; | 39 using content::RenderViewHost; |
39 using content::SiteInstance; | 40 using content::SiteInstance; |
41 using content::WebContents; | |
Aaron Boodman
2012/04/20 06:34:56
not needed
benwells
2012/04/23 05:00:26
Done.
| |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
43 std::string GetExtensionID(RenderViewHost* render_view_host) { | 45 std::string GetExtensionID(RenderViewHost* render_view_host) { |
44 // This works for both apps and extensions because the site has been | 46 // This works for both apps and extensions because the site has been |
45 // normalized to the extension URL for apps. | 47 // normalized to the extension URL for apps. |
46 return render_view_host->GetSiteInstance()->GetSite().host(); | 48 return render_view_host->GetSiteInstance()->GetSite().host(); |
47 } | 49 } |
48 | 50 |
49 // Incognito profiles use this process manager. It is mostly a shim that decides | 51 // Incognito profiles use this process manager. It is mostly a shim that decides |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 // Gather up all the views for that site. | 311 // Gather up all the views for that site. |
310 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); | 312 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); |
311 view != all_extension_views_.end(); ++view) { | 313 view != all_extension_views_.end(); ++view) { |
312 if (view->first->GetSiteInstance() == site_instance) | 314 if (view->first->GetSiteInstance() == site_instance) |
313 result.insert(view->first); | 315 result.insert(view->first); |
314 } | 316 } |
315 | 317 |
316 return result; | 318 return result; |
317 } | 319 } |
318 | 320 |
321 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( | |
322 content::RenderViewHost* render_view_host) { | |
323 ExtensionService* service = | |
324 ExtensionSystem::Get(GetProfile())->extension_service(); | |
325 return service->extensions()->GetByID( | |
326 render_view_host->GetSiteInstance()->GetSite().host()); | |
327 } | |
328 | |
319 void ExtensionProcessManager::RegisterRenderViewHost( | 329 void ExtensionProcessManager::RegisterRenderViewHost( |
320 RenderViewHost* render_view_host, | 330 RenderViewHost* render_view_host, |
321 const Extension* extension) { | 331 const Extension* extension) { |
322 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; | 332 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; |
323 } | 333 } |
324 | 334 |
325 void ExtensionProcessManager::UnregisterRenderViewHost( | 335 void ExtensionProcessManager::UnregisterRenderViewHost( |
326 RenderViewHost* render_view_host) { | 336 RenderViewHost* render_view_host) { |
327 ExtensionRenderViews::iterator view = | 337 ExtensionRenderViews::iterator view = |
328 all_extension_views_.find(render_view_host); | 338 all_extension_views_.find(render_view_host); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 GetExtensionID(render_view_host)); | 372 GetExtensionID(render_view_host)); |
363 if (extension) | 373 if (extension) |
364 IncrementLazyKeepaliveCount(extension); | 374 IncrementLazyKeepaliveCount(extension); |
365 } | 375 } |
366 } | 376 } |
367 | 377 |
368 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 378 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
369 return site_instance_->GetRelatedSiteInstance(url); | 379 return site_instance_->GetRelatedSiteInstance(url); |
370 } | 380 } |
371 | 381 |
372 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { | |
373 return all_hosts_.find(host) != all_hosts_.end(); | |
374 } | |
375 | |
376 bool ExtensionProcessManager::IsBackgroundHostClosing( | 382 bool ExtensionProcessManager::IsBackgroundHostClosing( |
377 const std::string& extension_id) { | 383 const std::string& extension_id) { |
378 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 384 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
379 return (host && background_page_data_[extension_id].is_closing); | 385 return (host && background_page_data_[extension_id].is_closing); |
380 } | 386 } |
381 | 387 |
382 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { | 388 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { |
383 if (!extension->has_lazy_background_page()) | 389 if (!extension->has_lazy_background_page()) |
384 return 0; | 390 return 0; |
385 | 391 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 CloseBackgroundHost(host); | 510 CloseBackgroundHost(host); |
505 break; | 511 break; |
506 } | 512 } |
507 } | 513 } |
508 background_page_data_.erase(extension->id()); | 514 background_page_data_.erase(extension->id()); |
509 break; | 515 break; |
510 } | 516 } |
511 | 517 |
512 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 518 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
513 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 519 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
514 all_hosts_.erase(host); | |
515 if (background_hosts_.erase(host)) | 520 if (background_hosts_.erase(host)) |
516 background_page_data_.erase(host->extension()->id()); | 521 background_page_data_.erase(host->extension()->id()); |
522 platform_app_hosts_.erase(host); | |
517 break; | 523 break; |
518 } | 524 } |
519 | 525 |
520 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 526 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
521 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 527 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
522 if (host->extension_host_type() == | 528 if (host->extension_host_type() == |
523 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 529 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
524 CloseBackgroundHost(host); | 530 CloseBackgroundHost(host); |
525 } | 531 } |
526 break; | 532 break; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 } | 583 } |
578 } | 584 } |
579 | 585 |
580 Profile* ExtensionProcessManager::GetProfile() const { | 586 Profile* ExtensionProcessManager::GetProfile() const { |
581 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); | 587 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); |
582 } | 588 } |
583 | 589 |
584 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 590 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
585 bool is_background) { | 591 bool is_background) { |
586 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); | 592 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); |
587 | |
588 all_hosts_.insert(host); | |
589 if (is_background) | 593 if (is_background) |
590 background_hosts_.insert(host); | 594 background_hosts_.insert(host); |
595 if (host->extension()->is_platform_app()) | |
596 platform_app_hosts_.insert(host); | |
591 } | 597 } |
592 | 598 |
593 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { | 599 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { |
594 CHECK(host->extension_host_type() == | 600 CHECK(host->extension_host_type() == |
595 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 601 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
596 delete host; | 602 delete host; |
597 // |host| should deregister itself from our structures. | 603 // |host| should deregister itself from our structures. |
598 CHECK(background_hosts_.find(host) == background_hosts_.end()); | 604 CHECK(background_hosts_.find(host) == background_hosts_.end()); |
599 } | 605 } |
600 | 606 |
(...skipping 13 matching lines...) Expand all Loading... | |
614 Profile* profile) | 620 Profile* profile) |
615 : ExtensionProcessManager(profile), | 621 : ExtensionProcessManager(profile), |
616 original_manager_(profile->GetOriginalProfile()-> | 622 original_manager_(profile->GetOriginalProfile()-> |
617 GetExtensionProcessManager()) { | 623 GetExtensionProcessManager()) { |
618 DCHECK(profile->IsOffTheRecord()); | 624 DCHECK(profile->IsOffTheRecord()); |
619 | 625 |
620 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 626 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
621 content::NotificationService::AllSources()); | 627 content::NotificationService::AllSources()); |
622 } | 628 } |
623 | 629 |
630 const ExtensionProcessManager::ViewSet | |
631 ExtensionProcessManager::GetAllViews() const { | |
632 ViewSet result; | |
633 for (ExtensionRenderViews::const_iterator iter = | |
634 all_extension_views_.begin(); | |
635 iter != all_extension_views_.end(); ++iter) { | |
636 result.insert(iter->first); | |
637 } | |
638 return result; | |
639 } | |
640 | |
624 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( | 641 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( |
625 const Extension* extension, | 642 const Extension* extension, |
626 const GURL& url, | 643 const GURL& url, |
627 Browser* browser, | 644 Browser* browser, |
628 content::ViewType view_type) { | 645 content::ViewType view_type) { |
629 if (extension->incognito_split_mode()) { | 646 if (extension->incognito_split_mode()) { |
630 if (IsIncognitoEnabled(extension)) { | 647 if (IsIncognitoEnabled(extension)) { |
631 return ExtensionProcessManager::CreateViewHost(extension, url, | 648 return ExtensionProcessManager::CreateViewHost(extension, url, |
632 browser, view_type); | 649 browser, view_type); |
633 } else { | 650 } else { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 if (service && service->is_ready()) | 707 if (service && service->is_ready()) |
691 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 708 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
692 } | 709 } |
693 break; | 710 break; |
694 } | 711 } |
695 default: | 712 default: |
696 ExtensionProcessManager::Observe(type, source, details); | 713 ExtensionProcessManager::Observe(type, source, details); |
697 break; | 714 break; |
698 } | 715 } |
699 } | 716 } |
OLD | NEW |