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_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (render_view_host) { | 91 if (render_view_host) { |
92 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( | 92 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( |
93 render_view_host->GetRoutingID(), GetViewType(web_contents()))); | 93 render_view_host->GetRoutingID(), GetViewType(web_contents()))); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 const Extension* ExtensionWebContentsObserver::GetExtension( | 97 const Extension* ExtensionWebContentsObserver::GetExtension( |
98 content::RenderViewHost* render_view_host) { | 98 content::RenderViewHost* render_view_host) { |
99 std::string extension_id = GetExtensionId(render_view_host); | 99 std::string extension_id = GetExtensionId(render_view_host); |
100 if (extension_id.empty()) | 100 if (extension_id.empty()) |
101 return NULL; | 101 return nullptr; |
102 | 102 |
103 // May be null if the extension doesn't exist, for example if somebody typos | 103 // May be null if the extension doesn't exist, for example if somebody typos |
104 // a chrome-extension:// URL. | 104 // a chrome-extension:// URL. |
105 return ExtensionRegistry::Get(browser_context_) | 105 return ExtensionRegistry::Get(browser_context_) |
106 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 106 ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
107 } | 107 } |
108 | 108 |
109 // static | 109 // static |
110 std::string ExtensionWebContentsObserver::GetExtensionId( | 110 std::string ExtensionWebContentsObserver::GetExtensionId( |
111 content::RenderViewHost* render_view_host) { | 111 content::RenderViewHost* render_view_host) { |
112 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps | 112 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps |
113 // (excluding bookmark apps) will have a chrome-extension:// URL for their | 113 // (excluding bookmark apps) will have a chrome-extension:// URL for their |
114 // site, so we can ignore that wrinkle here. | 114 // site, so we can ignore that wrinkle here. |
115 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); | 115 const GURL& site = render_view_host->GetSiteInstance()->GetSiteURL(); |
116 | 116 |
117 if (!site.SchemeIs(kExtensionScheme)) | 117 if (!site.SchemeIs(kExtensionScheme)) |
118 return std::string(); | 118 return std::string(); |
119 | 119 |
120 return site.host(); | 120 return site.host(); |
121 } | 121 } |
122 | 122 |
123 } // namespace extensions | 123 } // namespace extensions |
OLD | NEW |