| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/public/browser/devtools_manager.h" | 26 #include "content/public/browser/devtools_manager.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.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/site_instance.h" | 30 #include "content/public/browser/site_instance.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
| 33 #include "content/public/browser/web_contents_observer.h" | 33 #include "content/public/browser/web_contents_observer.h" |
| 34 #include "content/public/browser/web_contents_user_data.h" | 34 #include "content/public/browser/web_contents_user_data.h" |
| 35 #include "content/public/common/renderer_preferences.h" | 35 #include "content/public/common/renderer_preferences.h" |
| 36 #include "extensions/browser/extension_registry.h" |
| 36 #include "extensions/browser/extensions_browser_client.h" | 37 #include "extensions/browser/extensions_browser_client.h" |
| 37 #include "extensions/browser/view_type_utils.h" | 38 #include "extensions/browser/view_type_utils.h" |
| 38 #include "extensions/common/extension.h" | 39 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/manifest_handlers/background_info.h" | 40 #include "extensions/common/manifest_handlers/background_info.h" |
| 40 #include "extensions/common/manifest_handlers/incognito_info.h" | 41 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 41 #include "extensions/common/switches.h" | 42 #include "extensions/common/switches.h" |
| 42 | 43 |
| 43 using content::BrowserContext; | 44 using content::BrowserContext; |
| 44 using content::RenderViewHost; | 45 using content::RenderViewHost; |
| 45 using content::SiteInstance; | 46 using content::SiteInstance; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 295 } |
| 295 | 296 |
| 296 return result; | 297 return result; |
| 297 } | 298 } |
| 298 | 299 |
| 299 const Extension* ProcessManager::GetExtensionForRenderViewHost( | 300 const Extension* ProcessManager::GetExtensionForRenderViewHost( |
| 300 RenderViewHost* render_view_host) { | 301 RenderViewHost* render_view_host) { |
| 301 if (!render_view_host->GetSiteInstance()) | 302 if (!render_view_host->GetSiteInstance()) |
| 302 return NULL; | 303 return NULL; |
| 303 | 304 |
| 304 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 305 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext()); |
| 305 GetBrowserContext())->extension_service(); | 306 if (!registry) |
| 306 if (!service) | |
| 307 return NULL; | 307 return NULL; |
| 308 | 308 |
| 309 return service->extensions()->GetByID(GetExtensionID(render_view_host)); | 309 return registry->enabled_extensions().GetByID( |
| 310 GetExtensionID(render_view_host)); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void ProcessManager::UnregisterRenderViewHost( | 313 void ProcessManager::UnregisterRenderViewHost( |
| 313 RenderViewHost* render_view_host) { | 314 RenderViewHost* render_view_host) { |
| 314 ExtensionRenderViews::iterator view = | 315 ExtensionRenderViews::iterator view = |
| 315 all_extension_views_.find(render_view_host); | 316 all_extension_views_.find(render_view_host); |
| 316 if (view == all_extension_views_.end()) | 317 if (view == all_extension_views_.end()) |
| 317 return; | 318 return; |
| 318 | 319 |
| 319 OnRenderViewHostUnregistered(GetBrowserContext(), render_view_host); | 320 OnRenderViewHostUnregistered(GetBrowserContext(), render_view_host); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 } | 696 } |
| 696 } | 697 } |
| 697 | 698 |
| 698 void ProcessManager::CreateBackgroundHostsForProfileStartup() { | 699 void ProcessManager::CreateBackgroundHostsForProfileStartup() { |
| 699 if (startup_background_hosts_created_ || | 700 if (startup_background_hosts_created_ || |
| 700 !ExtensionsBrowserClient::Get()-> | 701 !ExtensionsBrowserClient::Get()-> |
| 701 IsBackgroundPageAllowed(GetBrowserContext())) { | 702 IsBackgroundPageAllowed(GetBrowserContext())) { |
| 702 return; | 703 return; |
| 703 } | 704 } |
| 704 | 705 |
| 705 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 706 const ExtensionSet& enabled_extensions = |
| 706 GetBrowserContext())->extension_service(); | 707 ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions(); |
| 707 DCHECK(service); | 708 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); |
| 708 for (ExtensionSet::const_iterator extension = service->extensions()->begin(); | 709 extension != enabled_extensions.end(); |
| 709 extension != service->extensions()->end(); ++extension) { | 710 ++extension) { |
| 710 CreateBackgroundHostForExtensionLoad(this, extension->get()); | 711 CreateBackgroundHostForExtensionLoad(this, extension->get()); |
| 711 | 712 |
| 712 RuntimeEventRouter::DispatchOnStartupEvent(GetBrowserContext(), | 713 RuntimeEventRouter::DispatchOnStartupEvent(GetBrowserContext(), |
| 713 (*extension)->id()); | 714 (*extension)->id()); |
| 714 } | 715 } |
| 715 startup_background_hosts_created_ = true; | 716 startup_background_hosts_created_ = true; |
| 716 | 717 |
| 717 // Background pages should only be loaded once. To prevent any further loads | 718 // Background pages should only be loaded once. To prevent any further loads |
| 718 // occurring, we remove the notification listeners. | 719 // occurring, we remove the notification listeners. |
| 719 BrowserContext* original_context = | 720 BrowserContext* original_context = |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 if (IsIncognitoEnabled(extension)) | 835 if (IsIncognitoEnabled(extension)) |
| 835 return ProcessManager::CreateBackgroundHost(extension, url); | 836 return ProcessManager::CreateBackgroundHost(extension, url); |
| 836 } else { | 837 } else { |
| 837 // Do nothing. If an extension is spanning, then its original-profile | 838 // Do nothing. If an extension is spanning, then its original-profile |
| 838 // background page is shared with incognito, so we don't create another. | 839 // background page is shared with incognito, so we don't create another. |
| 839 } | 840 } |
| 840 return NULL; | 841 return NULL; |
| 841 } | 842 } |
| 842 | 843 |
| 843 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { | 844 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { |
| 844 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 845 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext()); |
| 845 GetBrowserContext())->extension_service(); | 846 if (registry) { |
| 846 if (service) { | |
| 847 const Extension* extension = | 847 const Extension* extension = |
| 848 service->extensions()->GetExtensionOrAppByURL(url); | 848 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 849 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 849 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 850 return original_manager_->GetSiteInstanceForURL(url); | 850 return original_manager_->GetSiteInstanceForURL(url); |
| 851 } | 851 } |
| 852 } | 852 } |
| 853 return ProcessManager::GetSiteInstanceForURL(url); | 853 return ProcessManager::GetSiteInstanceForURL(url); |
| 854 } | 854 } |
| 855 | 855 |
| 856 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { | 856 bool IncognitoProcessManager::IsIncognitoEnabled(const Extension* extension) { |
| 857 // Keep in sync with duplicate in extension_info_map.cc. | 857 // Keep in sync with duplicate in extension_info_map.cc. |
| 858 ExtensionService* service = ExtensionSystem::GetForBrowserContext( | 858 ExtensionService* service = ExtensionSystem::GetForBrowserContext( |
| 859 GetBrowserContext())->extension_service(); | 859 GetBrowserContext())->extension_service(); |
| 860 return extension_util::IsIncognitoEnabled(extension->id(), service); | 860 return extension_util::IsIncognitoEnabled(extension->id(), service); |
| 861 } | 861 } |
| 862 | 862 |
| 863 } // namespace extensions | 863 } // namespace extensions |
| OLD | NEW |