| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 registrar_.Add(this, | 256 registrar_.Add(this, |
| 257 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 257 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 258 content::Source<BrowserContext>(original_context)); | 258 content::Source<BrowserContext>(original_context)); |
| 259 } | 259 } |
| 260 registrar_.Add(this, | 260 registrar_.Add(this, |
| 261 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 261 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 262 content::Source<BrowserContext>(context)); | 262 content::Source<BrowserContext>(context)); |
| 263 registrar_.Add(this, | 263 registrar_.Add(this, |
| 264 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 264 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 265 content::Source<BrowserContext>(context)); | 265 content::Source<BrowserContext>(context)); |
| 266 devtools_callback_ = base::Bind(&ProcessManager::OnDevToolsStateChanged, | 266 content::DevToolsAgentHost::AddObserver(this); |
| 267 weak_ptr_factory_.GetWeakPtr()); | |
| 268 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); | |
| 269 | 267 |
| 270 OnKeepaliveImpulseCheck(); | 268 OnKeepaliveImpulseCheck(); |
| 271 } | 269 } |
| 272 | 270 |
| 273 ProcessManager::~ProcessManager() { | 271 ProcessManager::~ProcessManager() { |
| 274 extension_registry_->RemoveObserver(this); | 272 extension_registry_->RemoveObserver(this); |
| 275 CloseBackgroundHosts(); | 273 CloseBackgroundHosts(); |
| 276 DCHECK(background_hosts_.empty()); | 274 DCHECK(background_hosts_.empty()); |
| 277 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); | 275 content::DevToolsAgentHost::RemoveObserver(this); |
| 278 } | 276 } |
| 279 | 277 |
| 280 void ProcessManager::RegisterRenderFrameHost( | 278 void ProcessManager::RegisterRenderFrameHost( |
| 281 content::WebContents* web_contents, | 279 content::WebContents* web_contents, |
| 282 content::RenderFrameHost* render_frame_host, | 280 content::RenderFrameHost* render_frame_host, |
| 283 const Extension* extension) { | 281 const Extension* extension) { |
| 284 ExtensionRenderFrameData* data = &all_extension_frames_[render_frame_host]; | 282 ExtensionRenderFrameData* data = &all_extension_frames_[render_frame_host]; |
| 285 data->view_type = GetViewType(web_contents); | 283 data->view_type = GetViewType(web_contents); |
| 286 | 284 |
| 287 // Keep the lazy background page alive as long as any non-background-page | 285 // Keep the lazy background page alive as long as any non-background-page |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 // To avoid this, unregister the view now. | 882 // To avoid this, unregister the view now. |
| 885 UnregisterRenderFrameHost(frame); | 883 UnregisterRenderFrameHost(frame); |
| 886 } | 884 } |
| 887 | 885 |
| 888 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 886 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| 889 if (host) | 887 if (host) |
| 890 CloseBackgroundHost(host); | 888 CloseBackgroundHost(host); |
| 891 } | 889 } |
| 892 } | 890 } |
| 893 | 891 |
| 894 void ProcessManager::OnDevToolsStateChanged( | 892 const Extension* ProcessManager::GetExtensionForAgentHost( |
| 895 content::DevToolsAgentHost* agent_host, | 893 content::DevToolsAgentHost* agent_host) { |
| 896 bool attached) { | |
| 897 content::WebContents* web_contents = agent_host->GetWebContents(); | 894 content::WebContents* web_contents = agent_host->GetWebContents(); |
| 898 // Ignore unrelated notifications. | 895 // Ignore unrelated notifications. |
| 899 if (!web_contents || web_contents->GetBrowserContext() != browser_context_) | 896 if (!web_contents || web_contents->GetBrowserContext() != browser_context_) |
| 900 return; | 897 return nullptr; |
| 901 if (GetViewType(web_contents) != VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) | 898 if (GetViewType(web_contents) != VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) |
| 902 return; | 899 return nullptr; |
| 903 const Extension* extension = | 900 return GetExtensionForWebContents(web_contents); |
| 904 extension_registry_->enabled_extensions().GetByID( | 901 } |
| 905 GetExtensionIdForSiteInstance(web_contents->GetSiteInstance())); | 902 |
| 906 if (!extension) | 903 void ProcessManager::DevToolsAgentHostAttached( |
| 907 return; | 904 content::DevToolsAgentHost* agent_host) { |
| 908 if (attached) { | 905 if (const Extension* extension = GetExtensionForAgentHost(agent_host)) { |
| 909 // Keep the lazy background page alive while it's being inspected. | 906 // Keep the lazy background page alive while it's being inspected. |
| 910 CancelSuspend(extension); | 907 CancelSuspend(extension); |
| 911 IncrementLazyKeepaliveCount(extension); | 908 IncrementLazyKeepaliveCount(extension); |
| 912 } else { | 909 } |
| 910 } |
| 911 |
| 912 void ProcessManager::DevToolsAgentHostDetached( |
| 913 content::DevToolsAgentHost* agent_host) { |
| 914 if (const Extension* extension = GetExtensionForAgentHost(agent_host)) |
| 913 DecrementLazyKeepaliveCount(extension); | 915 DecrementLazyKeepaliveCount(extension); |
| 914 } | |
| 915 } | 916 } |
| 916 | 917 |
| 917 void ProcessManager::UnregisterExtension(const std::string& extension_id) { | 918 void ProcessManager::UnregisterExtension(const std::string& extension_id) { |
| 918 // The lazy_keepalive_count may be greater than zero at this point because | 919 // The lazy_keepalive_count may be greater than zero at this point because |
| 919 // RenderFrameHosts are still alive. During extension reloading, they will | 920 // RenderFrameHosts are still alive. During extension reloading, they will |
| 920 // decrement the lazy_keepalive_count to negative for the new extension | 921 // decrement the lazy_keepalive_count to negative for the new extension |
| 921 // instance when they are destroyed. Since we are erasing the background page | 922 // instance when they are destroyed. Since we are erasing the background page |
| 922 // data for the unloaded extension, unregister the RenderFrameHosts too. | 923 // data for the unloaded extension, unregister the RenderFrameHosts too. |
| 923 for (ExtensionRenderFrames::iterator it = all_extension_frames_.begin(); | 924 for (ExtensionRenderFrames::iterator it = all_extension_frames_.begin(); |
| 924 it != all_extension_frames_.end(); ) { | 925 it != all_extension_frames_.end(); ) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 988 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 988 BrowserContext* original_context = | 989 BrowserContext* original_context = |
| 989 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); | 990 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); |
| 990 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); | 991 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); |
| 991 } | 992 } |
| 992 | 993 |
| 993 return ProcessManager::GetSiteInstanceForURL(url); | 994 return ProcessManager::GetSiteInstanceForURL(url); |
| 994 } | 995 } |
| 995 | 996 |
| 996 } // namespace extensions | 997 } // namespace extensions |
| OLD | NEW |