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_messages.h" | 21 #include "extensions/common/extension_messages.h" |
| 22 #include "extensions/common/view_type.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()) { |
| 31 if (site_instance->GetSiteURL().GetOrigin() != url.GetOrigin()) | 32 if (site_instance->GetSiteURL().GetOrigin() != url.GetOrigin()) |
| (...skipping 117 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 if (GetViewType(web_contents()) == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | |
|
not at google - send to devlin
2015/05/11 17:53:48
I'm not sure I'd bother with this extra "is backgr
bartfab (slow)
2015/05/18 09:57:41
If we leave out this check, we will be keeping bac
emaxx
2015/05/18 15:06:30
I've already talked to Ben about that. The point i
emaxx
2015/05/18 15:06:30
OK, removed this check as it didn't make much diff
| |
| 162 ProcessManager* process_manager = ProcessManager::Get(browser_context_); | |
|
bartfab (slow)
2015/05/18 09:57:41
Nit 1: const pointer.
Nit 2: If you move this insi
emaxx
2015/05/18 15:06:30
1: Done.
2: Didn't get your point: the ProcessMana
bartfab (slow)
2015/05/19 10:34:58
Nevermind :).
| |
| 163 const Extension* extension = | |
|
bartfab (slow)
2015/05/18 09:57:41
Nit 1: const pointer.
Nit 2: #include "extensions/
emaxx
2015/05/18 15:06:30
Done.
| |
| 164 process_manager->GetExtensionForWebContents(web_contents()); | |
| 165 if (extension) | |
| 166 process_manager->IncrementLazyKeepaliveCount(extension); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void ExtensionWebContentsObserver::PepperInstanceDeleted() { | |
| 171 if (GetViewType(web_contents()) == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | |
| 172 ProcessManager* process_manager = ProcessManager::Get(browser_context_); | |
|
bartfab (slow)
2015/05/18 09:57:41
Nit 1: const pointer.
Nit 2: As above, better move
| |
| 173 const Extension* extension = | |
|
bartfab (slow)
2015/05/18 09:57:41
Nit: const pointer.
| |
| 174 process_manager->GetExtensionForWebContents(web_contents()); | |
| 175 if (extension) | |
| 176 process_manager->DecrementLazyKeepaliveCount(extension); | |
| 177 } | |
| 178 } | |
| 179 | |
| 159 const Extension* ExtensionWebContentsObserver::GetExtension( | 180 const Extension* ExtensionWebContentsObserver::GetExtension( |
| 160 content::RenderViewHost* render_view_host) { | 181 content::RenderViewHost* render_view_host) { |
| 161 std::string extension_id = GetExtensionId(render_view_host); | 182 std::string extension_id = GetExtensionId(render_view_host); |
| 162 if (extension_id.empty()) | 183 if (extension_id.empty()) |
| 163 return NULL; | 184 return NULL; |
| 164 | 185 |
| 165 // May be null if the extension doesn't exist, for example if somebody typos | 186 // May be null if the extension doesn't exist, for example if somebody typos |
| 166 // a chrome-extension:// URL. | 187 // a chrome-extension:// URL. |
| 167 return ExtensionRegistry::Get(browser_context_) | 188 return ExtensionRegistry::Get(browser_context_) |
| 168 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 189 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 169 } | 190 } |
| 170 | 191 |
| 171 // static | 192 // static |
| 172 std::string ExtensionWebContentsObserver::GetExtensionId( | 193 std::string ExtensionWebContentsObserver::GetExtensionId( |
| 173 content::RenderViewHost* render_view_host) { | 194 content::RenderViewHost* render_view_host) { |
| 174 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps | 195 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps |
| 175 // (excluding bookmark apps) will have a chrome-extension:// URL for their | 196 // (excluding bookmark apps) will have a chrome-extension:// URL for their |
| 176 // site, so we can ignore that wrinkle here. | 197 // site, so we can ignore that wrinkle here. |
| 177 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); | 198 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); |
| 178 | 199 |
| 179 if (!site.SchemeIs(kExtensionScheme)) | 200 if (!site.SchemeIs(kExtensionScheme)) |
| 180 return std::string(); | 201 return std::string(); |
| 181 | 202 |
| 182 return site.host(); | 203 return site.host(); |
| 183 } | 204 } |
| 184 | 205 |
| 185 } // namespace extensions | 206 } // namespace extensions |
| OLD | NEW |