Chromium Code Reviews| 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_messages.h" | 22 #include "extensions/common/extension_messages.h" |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const Extension* GetExtensionForRenderFrame( | 27 const Extension* GetExtensionForRenderFrame( |
| 27 content::RenderFrameHost* render_frame_host) { | 28 content::RenderFrameHost* render_frame_host) { |
| 28 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 29 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 29 GURL url = render_frame_host->GetLastCommittedURL(); | 30 GURL url = render_frame_host->GetLastCommittedURL(); |
| 30 if (!url.is_empty()) { | 31 if (!url.is_empty()) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 } | 150 } |
| 150 | 151 |
| 151 void ExtensionWebContentsObserver::NotifyRenderViewType( | 152 void ExtensionWebContentsObserver::NotifyRenderViewType( |
| 152 content::RenderViewHost* render_view_host) { | 153 content::RenderViewHost* render_view_host) { |
| 153 if (render_view_host) { | 154 if (render_view_host) { |
| 154 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( | 155 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( |
| 155 render_view_host->GetRoutingID(), GetViewType(web_contents()))); | 156 render_view_host->GetRoutingID(), GetViewType(web_contents()))); |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 160 void ExtensionWebContentsObserver::PepperInstanceCreated() { | |
| 161 ProcessManager* const process_manager = ProcessManager::Get(browser_context_); | |
| 162 const Extension* const extension = | |
|
not at google - send to devlin
2015/05/26 21:18:42
Kinda overboard-ing the "const" here IMO, but what
| |
| 163 process_manager->GetExtensionForWebContents(web_contents()); | |
| 164 if (extension) | |
| 165 process_manager->IncrementLazyKeepaliveCount(extension); | |
| 166 } | |
| 167 | |
| 168 void ExtensionWebContentsObserver::PepperInstanceDeleted() { | |
| 169 ProcessManager* const process_manager = ProcessManager::Get(browser_context_); | |
| 170 const Extension* const extension = | |
| 171 process_manager->GetExtensionForWebContents(web_contents()); | |
| 172 if (extension) | |
| 173 process_manager->DecrementLazyKeepaliveCount(extension); | |
| 174 } | |
| 175 | |
| 159 const Extension* ExtensionWebContentsObserver::GetExtension( | 176 const Extension* ExtensionWebContentsObserver::GetExtension( |
| 160 content::RenderViewHost* render_view_host) { | 177 content::RenderViewHost* render_view_host) { |
| 161 std::string extension_id = GetExtensionId(render_view_host); | 178 std::string extension_id = GetExtensionId(render_view_host); |
| 162 if (extension_id.empty()) | 179 if (extension_id.empty()) |
| 163 return NULL; | 180 return NULL; |
| 164 | 181 |
| 165 // May be null if the extension doesn't exist, for example if somebody typos | 182 // May be null if the extension doesn't exist, for example if somebody typos |
| 166 // a chrome-extension:// URL. | 183 // a chrome-extension:// URL. |
| 167 return ExtensionRegistry::Get(browser_context_) | 184 return ExtensionRegistry::Get(browser_context_) |
| 168 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 185 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 169 } | 186 } |
| 170 | 187 |
| 171 // static | 188 // static |
| 172 std::string ExtensionWebContentsObserver::GetExtensionId( | 189 std::string ExtensionWebContentsObserver::GetExtensionId( |
| 173 content::RenderViewHost* render_view_host) { | 190 content::RenderViewHost* render_view_host) { |
| 174 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps | 191 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps |
| 175 // (excluding bookmark apps) will have a chrome-extension:// URL for their | 192 // (excluding bookmark apps) will have a chrome-extension:// URL for their |
| 176 // site, so we can ignore that wrinkle here. | 193 // site, so we can ignore that wrinkle here. |
| 177 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); | 194 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); |
| 178 | 195 |
| 179 if (!site.SchemeIs(kExtensionScheme)) | 196 if (!site.SchemeIs(kExtensionScheme)) |
| 180 return std::string(); | 197 return std::string(); |
| 181 | 198 |
| 182 return site.host(); | 199 return site.host(); |
| 183 } | 200 } |
| 184 | 201 |
| 185 } // namespace extensions | 202 } // namespace extensions |
| OLD | NEW |