| 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 "extensions/browser/extension_web_contents_observer.h" | 5 #include "extensions/browser/extension_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "content/public/browser/child_process_security_policy.h" | 7 #include "content/public/browser/child_process_security_policy.h" |
| 8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/site_instance.h" | 11 #include "content/public/browser/site_instance.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
| 15 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extensions_browser_client.h" | 16 #include "extensions/browser/extensions_browser_client.h" |
| 17 #include "extensions/browser/mojo/service_registration.h" | 17 #include "extensions/browser/mojo/service_registration.h" |
| 18 #include "extensions/browser/process_manager.h" | 18 #include "extensions/browser/process_manager.h" |
| 19 #include "extensions/browser/view_type_utils.h" | 19 #include "extensions/browser/view_type_utils.h" |
| 20 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
| 21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/extension_messages.h" | 22 #include "extensions/common/extension_messages.h" |
| 23 #include "extensions/common/view_type.h" |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 ExtensionWebContentsObserver* ExtensionWebContentsObserver::GetForWebContents( | 28 ExtensionWebContentsObserver* ExtensionWebContentsObserver::GetForWebContents( |
| 28 content::WebContents* web_contents) { | 29 content::WebContents* web_contents) { |
| 29 return ExtensionsBrowserClient::Get()->GetExtensionWebContentsObserver( | 30 return ExtensionsBrowserClient::Get()->GetExtensionWebContentsObserver( |
| 30 web_contents); | 31 web_contents); |
| 31 } | 32 } |
| 32 | 33 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 bool handled = true; | 116 bool handled = true; |
| 116 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM( | 117 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM( |
| 117 ExtensionWebContentsObserver, message, render_frame_host) | 118 ExtensionWebContentsObserver, message, render_frame_host) |
| 118 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 119 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 119 IPC_MESSAGE_UNHANDLED(handled = false) | 120 IPC_MESSAGE_UNHANDLED(handled = false) |
| 120 IPC_END_MESSAGE_MAP() | 121 IPC_END_MESSAGE_MAP() |
| 121 return handled; | 122 return handled; |
| 122 } | 123 } |
| 123 | 124 |
| 124 void ExtensionWebContentsObserver::PepperInstanceCreated() { | 125 void ExtensionWebContentsObserver::PepperInstanceCreated() { |
| 125 ProcessManager* const process_manager = ProcessManager::Get(browser_context_); | 126 if (GetViewType(web_contents()) == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 126 const Extension* const extension = | 127 ProcessManager* const process_manager = |
| 127 process_manager->GetExtensionForWebContents(web_contents()); | 128 ProcessManager::Get(browser_context_); |
| 128 if (extension) | 129 const Extension* const extension = |
| 129 process_manager->IncrementLazyKeepaliveCount(extension); | 130 process_manager->GetExtensionForWebContents(web_contents()); |
| 131 if (extension) |
| 132 process_manager->IncrementLazyKeepaliveCount(extension); |
| 133 } |
| 130 } | 134 } |
| 131 | 135 |
| 132 void ExtensionWebContentsObserver::PepperInstanceDeleted() { | 136 void ExtensionWebContentsObserver::PepperInstanceDeleted() { |
| 133 ProcessManager* const process_manager = ProcessManager::Get(browser_context_); | 137 if (GetViewType(web_contents()) == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 134 const Extension* const extension = | 138 ProcessManager* const process_manager = |
| 135 process_manager->GetExtensionForWebContents(web_contents()); | 139 ProcessManager::Get(browser_context_); |
| 136 if (extension) | 140 const Extension* const extension = |
| 137 process_manager->DecrementLazyKeepaliveCount(extension); | 141 process_manager->GetExtensionForWebContents(web_contents()); |
| 142 if (extension) |
| 143 process_manager->DecrementLazyKeepaliveCount(extension); |
| 144 } |
| 138 } | 145 } |
| 139 | 146 |
| 140 std::string ExtensionWebContentsObserver::GetExtensionIdFromFrame( | 147 std::string ExtensionWebContentsObserver::GetExtensionIdFromFrame( |
| 141 content::RenderFrameHost* render_frame_host) const { | 148 content::RenderFrameHost* render_frame_host) const { |
| 142 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 149 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 143 GURL url = render_frame_host->GetLastCommittedURL(); | 150 GURL url = render_frame_host->GetLastCommittedURL(); |
| 144 if (!url.is_empty()) { | 151 if (!url.is_empty()) { |
| 145 if (site_instance->GetSiteURL().GetOrigin() != url.GetOrigin()) | 152 if (site_instance->GetSiteURL().GetOrigin() != url.GetOrigin()) |
| 146 return std::string(); | 153 return std::string(); |
| 147 } else { | 154 } else { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // Since this is called for all existing RenderFrameHosts during the | 203 // Since this is called for all existing RenderFrameHosts during the |
| 197 // ExtensionWebContentsObserver's creation, it's possible that not all hosts | 204 // ExtensionWebContentsObserver's creation, it's possible that not all hosts |
| 198 // are ready. | 205 // are ready. |
| 199 // We only initialize the frame if the renderer counterpart is live; otherwise | 206 // We only initialize the frame if the renderer counterpart is live; otherwise |
| 200 // we wait for the RenderFrameCreated notification. | 207 // we wait for the RenderFrameCreated notification. |
| 201 if (render_frame_host->IsRenderFrameLive()) | 208 if (render_frame_host->IsRenderFrameLive()) |
| 202 InitializeRenderFrame(render_frame_host); | 209 InitializeRenderFrame(render_frame_host); |
| 203 } | 210 } |
| 204 | 211 |
| 205 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |