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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | |
18 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/devtools_agent_host.h" | 19 #include "content/public/browser/devtools_agent_host.h" |
21 #include "content/public/browser/devtools_manager.h" | 20 #include "content/public/browser/devtools_manager.h" |
22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
29 #include "content/public/browser/web_contents_observer.h" | 28 #include "content/public/browser/web_contents_observer.h" |
30 #include "content/public/browser/web_contents_user_data.h" | 29 #include "content/public/browser/web_contents_user_data.h" |
31 #include "content/public/common/renderer_preferences.h" | 30 #include "content/public/common/renderer_preferences.h" |
32 #include "extensions/browser/extension_host.h" | 31 #include "extensions/browser/extension_host.h" |
33 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
34 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
35 #include "extensions/browser/extensions_browser_client.h" | 34 #include "extensions/browser/extensions_browser_client.h" |
| 35 #include "extensions/browser/process_manager_observer.h" |
36 #include "extensions/browser/view_type_utils.h" | 36 #include "extensions/browser/view_type_utils.h" |
37 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
38 #include "extensions/common/extension_messages.h" | 38 #include "extensions/common/extension_messages.h" |
39 #include "extensions/common/manifest_handlers/background_info.h" | 39 #include "extensions/common/manifest_handlers/background_info.h" |
40 #include "extensions/common/manifest_handlers/incognito_info.h" | 40 #include "extensions/common/manifest_handlers/incognito_info.h" |
41 #include "extensions/common/one_shot_event.h" | 41 #include "extensions/common/one_shot_event.h" |
42 #include "extensions/common/switches.h" | 42 #include "extensions/common/switches.h" |
43 | 43 |
44 using content::BrowserContext; | 44 using content::BrowserContext; |
45 using content::RenderViewHost; | 45 using content::RenderViewHost; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 const ProcessManager::ViewSet ProcessManager::GetAllViews() const { | 275 const ProcessManager::ViewSet ProcessManager::GetAllViews() const { |
276 ViewSet result; | 276 ViewSet result; |
277 for (ExtensionRenderViews::const_iterator iter = | 277 for (ExtensionRenderViews::const_iterator iter = |
278 all_extension_views_.begin(); | 278 all_extension_views_.begin(); |
279 iter != all_extension_views_.end(); ++iter) { | 279 iter != all_extension_views_.end(); ++iter) { |
280 result.insert(iter->first); | 280 result.insert(iter->first); |
281 } | 281 } |
282 return result; | 282 return result; |
283 } | 283 } |
284 | 284 |
| 285 void ProcessManager::AddObserver(ProcessManagerObserver* observer) { |
| 286 observer_list_.AddObserver(observer); |
| 287 } |
| 288 |
| 289 void ProcessManager::RemoveObserver(ProcessManagerObserver* observer) { |
| 290 observer_list_.RemoveObserver(observer); |
| 291 } |
| 292 |
285 bool ProcessManager::CreateBackgroundHost(const Extension* extension, | 293 bool ProcessManager::CreateBackgroundHost(const Extension* extension, |
286 const GURL& url) { | 294 const GURL& url) { |
287 // Hosted apps are taken care of from BackgroundContentsService. Ignore them | 295 // Hosted apps are taken care of from BackgroundContentsService. Ignore them |
288 // here. | 296 // here. |
289 if (extension->is_hosted_app() || | 297 if (extension->is_hosted_app() || |
290 !ExtensionsBrowserClient::Get()-> | 298 !ExtensionsBrowserClient::Get()-> |
291 IsBackgroundPageAllowed(GetBrowserContext())) { | 299 IsBackgroundPageAllowed(GetBrowserContext())) { |
292 return false; | 300 return false; |
293 } | 301 } |
294 | 302 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 return; | 772 return; |
765 } | 773 } |
766 | 774 |
767 const ExtensionSet& enabled_extensions = | 775 const ExtensionSet& enabled_extensions = |
768 ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions(); | 776 ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions(); |
769 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); | 777 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); |
770 extension != enabled_extensions.end(); | 778 extension != enabled_extensions.end(); |
771 ++extension) { | 779 ++extension) { |
772 CreateBackgroundHostForExtensionLoad(this, extension->get()); | 780 CreateBackgroundHostForExtensionLoad(this, extension->get()); |
773 | 781 |
774 RuntimeEventRouter::DispatchOnStartupEvent(GetBrowserContext(), | 782 FOR_EACH_OBSERVER(ProcessManagerObserver, |
775 (*extension)->id()); | 783 observer_list_, |
| 784 OnBackgroundHostStartup(*extension)); |
776 } | 785 } |
777 startup_background_hosts_created_ = true; | 786 startup_background_hosts_created_ = true; |
778 | 787 |
779 // Background pages should only be loaded once. To prevent any further loads | 788 // Background pages should only be loaded once. To prevent any further loads |
780 // occurring, we remove the notification listeners. | 789 // occurring, we remove the notification listeners. |
781 BrowserContext* original_context = | 790 BrowserContext* original_context = |
782 ExtensionsBrowserClient::Get()->GetOriginalContext(GetBrowserContext()); | 791 ExtensionsBrowserClient::Get()->GetOriginalContext(GetBrowserContext()); |
783 if (registrar_.IsRegistered( | 792 if (registrar_.IsRegistered( |
784 this, | 793 this, |
785 chrome::NOTIFICATION_PROFILE_CREATED, | 794 chrome::NOTIFICATION_PROFILE_CREATED, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 const Extension* extension = | 918 const Extension* extension = |
910 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 919 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
911 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 920 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
912 return original_manager_->GetSiteInstanceForURL(url); | 921 return original_manager_->GetSiteInstanceForURL(url); |
913 } | 922 } |
914 } | 923 } |
915 return ProcessManager::GetSiteInstanceForURL(url); | 924 return ProcessManager::GetSiteInstanceForURL(url); |
916 } | 925 } |
917 | 926 |
918 } // namespace extensions | 927 } // namespace extensions |
OLD | NEW |