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 "chrome/browser/extensions/chrome_content_browser_client_extensions_par
t.h" | 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par
t.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "extensions/browser/extension_message_filter.h" | 34 #include "extensions/browser/extension_message_filter.h" |
35 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
36 #include "extensions/browser/extension_system.h" | 36 #include "extensions/browser/extension_system.h" |
37 #include "extensions/browser/info_map.h" | 37 #include "extensions/browser/info_map.h" |
38 #include "extensions/browser/view_type_utils.h" | 38 #include "extensions/browser/view_type_utils.h" |
39 #include "extensions/common/constants.h" | 39 #include "extensions/common/constants.h" |
40 #include "extensions/common/manifest_handlers/background_info.h" | 40 #include "extensions/common/manifest_handlers/background_info.h" |
41 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" | 41 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
42 #include "extensions/common/switches.h" | 42 #include "extensions/common/switches.h" |
43 | 43 |
| 44 using content::BrowserContext; |
44 using content::BrowserThread; | 45 using content::BrowserThread; |
45 using content::BrowserURLHandler; | 46 using content::BrowserURLHandler; |
46 using content::RenderViewHost; | 47 using content::RenderViewHost; |
47 using content::SiteInstance; | 48 using content::SiteInstance; |
48 using content::WebContents; | 49 using content::WebContents; |
49 using content::WebPreferences; | 50 using content::WebPreferences; |
50 | 51 |
51 namespace extensions { | 52 namespace extensions { |
52 | 53 |
53 namespace { | 54 namespace { |
54 | 55 |
55 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions | 56 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
56 // below. Extension, and isolated apps require different privileges to be | 57 // below. Extension, and isolated apps require different privileges to be |
57 // granted to their RenderProcessHosts. This classification allows us to make | 58 // granted to their RenderProcessHosts. This classification allows us to make |
58 // sure URLs are served by hosts with the right set of privileges. | 59 // sure URLs are served by hosts with the right set of privileges. |
59 enum RenderProcessHostPrivilege { | 60 enum RenderProcessHostPrivilege { |
60 PRIV_NORMAL, | 61 PRIV_NORMAL, |
61 PRIV_HOSTED, | 62 PRIV_HOSTED, |
62 PRIV_ISOLATED, | 63 PRIV_ISOLATED, |
63 PRIV_EXTENSION, | 64 PRIV_EXTENSION, |
64 }; | 65 }; |
65 | 66 |
66 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( | 67 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
67 const GURL& url, | 68 const GURL& url, |
68 ExtensionService* service) { | 69 ExtensionRegistry* registry) { |
69 // Default to a normal renderer cause it is lower privileged. This should only | 70 // Default to a normal renderer cause it is lower privileged. This should only |
70 // occur if the URL on a site instance is either malformed, or uninitialized. | 71 // occur if the URL on a site instance is either malformed, or uninitialized. |
71 // If it is malformed, then there is no need for better privileges anyways. | 72 // If it is malformed, then there is no need for better privileges anyways. |
72 // If it is uninitialized, but eventually settles on being an a scheme other | 73 // If it is uninitialized, but eventually settles on being an a scheme other |
73 // than normal webrenderer, the navigation logic will correct us out of band | 74 // than normal webrenderer, the navigation logic will correct us out of band |
74 // anyways. | 75 // anyways. |
75 if (!url.is_valid()) | 76 if (!url.is_valid()) |
76 return PRIV_NORMAL; | 77 return PRIV_NORMAL; |
77 | 78 |
78 if (!url.SchemeIs(kExtensionScheme)) | 79 if (!url.SchemeIs(kExtensionScheme)) |
79 return PRIV_NORMAL; | 80 return PRIV_NORMAL; |
80 | 81 |
81 const Extension* extension = service->extensions()->GetByID(url.host()); | 82 const Extension* extension = |
| 83 registry->enabled_extensions().GetByID(url.host()); |
82 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) | 84 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) |
83 return PRIV_ISOLATED; | 85 return PRIV_ISOLATED; |
84 if (extension && extension->is_hosted_app()) | 86 if (extension && extension->is_hosted_app()) |
85 return PRIV_HOSTED; | 87 return PRIV_HOSTED; |
86 return PRIV_EXTENSION; | 88 return PRIV_EXTENSION; |
87 } | 89 } |
88 | 90 |
89 RenderProcessHostPrivilege GetProcessPrivilege( | 91 RenderProcessHostPrivilege GetProcessPrivilege( |
90 content::RenderProcessHost* process_host, | 92 content::RenderProcessHost* process_host, |
91 ProcessMap* process_map, | 93 ProcessMap* process_map, |
92 ExtensionService* service) { | 94 ExtensionRegistry* registry) { |
93 std::set<std::string> extension_ids = | 95 std::set<std::string> extension_ids = |
94 process_map->GetExtensionsInProcess(process_host->GetID()); | 96 process_map->GetExtensionsInProcess(process_host->GetID()); |
95 if (extension_ids.empty()) | 97 if (extension_ids.empty()) |
96 return PRIV_NORMAL; | 98 return PRIV_NORMAL; |
97 | 99 |
98 for (std::set<std::string>::iterator iter = extension_ids.begin(); | 100 for (const std::string& extension_id : extension_ids) { |
99 iter != extension_ids.end(); ++iter) { | 101 const Extension* extension = |
100 const Extension* extension = service->GetExtensionById(*iter, false); | 102 registry->enabled_extensions().GetByID(extension_id); |
101 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) | 103 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) |
102 return PRIV_ISOLATED; | 104 return PRIV_ISOLATED; |
103 if (extension && extension->is_hosted_app()) | 105 if (extension && extension->is_hosted_app()) |
104 return PRIV_HOSTED; | 106 return PRIV_HOSTED; |
105 } | 107 } |
106 | 108 |
107 return PRIV_EXTENSION; | 109 return PRIV_EXTENSION; |
108 } | 110 } |
109 | 111 |
110 } // namespace | 112 } // namespace |
111 | 113 |
112 ChromeContentBrowserClientExtensionsPart:: | 114 ChromeContentBrowserClientExtensionsPart:: |
113 ChromeContentBrowserClientExtensionsPart() { | 115 ChromeContentBrowserClientExtensionsPart() { |
114 permissions_policy_delegate_.reset(new BrowserPermissionsPolicyDelegate()); | 116 permissions_policy_delegate_.reset(new BrowserPermissionsPolicyDelegate()); |
115 } | 117 } |
116 | 118 |
117 ChromeContentBrowserClientExtensionsPart:: | 119 ChromeContentBrowserClientExtensionsPart:: |
118 ~ChromeContentBrowserClientExtensionsPart() { | 120 ~ChromeContentBrowserClientExtensionsPart() { |
119 } | 121 } |
120 | 122 |
121 // static | 123 // static |
122 GURL ChromeContentBrowserClientExtensionsPart::GetEffectiveURL( | 124 GURL ChromeContentBrowserClientExtensionsPart::GetEffectiveURL( |
123 Profile* profile, const GURL& url) { | 125 Profile* profile, const GURL& url) { |
124 // If the input |url| is part of an installed app, the effective URL is an | 126 // If the input |url| is part of an installed app, the effective URL is an |
125 // extension URL with the ID of that extension as the host. This has the | 127 // extension URL with the ID of that extension as the host. This has the |
126 // effect of grouping apps together in a common SiteInstance. | 128 // effect of grouping apps together in a common SiteInstance. |
127 ExtensionService* extension_service = | 129 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
128 ExtensionSystem::Get(profile)->extension_service(); | 130 if (!registry) |
129 if (!extension_service) | |
130 return url; | 131 return url; |
131 | 132 |
132 const Extension* extension = | 133 const Extension* extension = |
133 extension_service->extensions()->GetHostedAppByURL(url); | 134 registry->enabled_extensions().GetHostedAppByURL(url); |
134 if (!extension) | 135 if (!extension) |
135 return url; | 136 return url; |
136 | 137 |
137 // Bookmark apps do not use the hosted app process model, and should be | 138 // Bookmark apps do not use the hosted app process model, and should be |
138 // treated as normal URLs. | 139 // treated as normal URLs. |
139 if (extension->from_bookmark()) | 140 if (extension->from_bookmark()) |
140 return url; | 141 return url; |
141 | 142 |
142 // If the URL is part of an extension's web extent, convert it to an | 143 // If the URL is part of an extension's web extent, convert it to an |
143 // extension URL. | 144 // extension URL. |
144 return extension->GetResourceURL(url.path()); | 145 return extension->GetResourceURL(url.path()); |
145 } | 146 } |
146 | 147 |
147 // static | 148 // static |
148 bool ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( | 149 bool ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
149 Profile* profile, const GURL& effective_url) { | 150 Profile* profile, const GURL& effective_url) { |
150 if (!effective_url.SchemeIs(kExtensionScheme)) | 151 if (!effective_url.SchemeIs(kExtensionScheme)) |
151 return false; | 152 return false; |
152 | 153 |
153 ExtensionService* extension_service = | 154 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
154 ExtensionSystem::Get(profile)->extension_service(); | 155 if (!registry) |
155 if (!extension_service) | |
156 return false; | 156 return false; |
157 | 157 |
158 const Extension* extension = | 158 const Extension* extension = |
159 extension_service->extensions()->GetExtensionOrAppByURL(effective_url); | 159 registry->enabled_extensions().GetByID(effective_url.host()); |
160 if (!extension) | 160 if (!extension) |
161 return false; | 161 return false; |
162 | 162 |
163 // If the URL is part of a hosted app that does not have the background | 163 // If the URL is part of a hosted app that does not have the background |
164 // permission, or that does not allow JavaScript access to the background | 164 // permission, or that does not allow JavaScript access to the background |
165 // page, we want to give each instance its own process to improve | 165 // page, we want to give each instance its own process to improve |
166 // responsiveness. | 166 // responsiveness. |
167 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { | 167 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { |
168 if (!extension->permissions_data()->HasAPIPermission( | 168 if (!extension->permissions_data()->HasAPIPermission( |
169 APIPermission::kBackground) || | 169 APIPermission::kBackground) || |
170 !BackgroundInfo::AllowJSAccess(extension)) { | 170 !BackgroundInfo::AllowJSAccess(extension)) { |
171 return false; | 171 return false; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 // Hosted apps that have script access to their background page must use | 175 // Hosted apps that have script access to their background page must use |
176 // process per site, since all instances can make synchronous calls to the | 176 // process per site, since all instances can make synchronous calls to the |
177 // background window. Other extensions should use process per site as well. | 177 // background window. Other extensions should use process per site as well. |
178 return true; | 178 return true; |
179 } | 179 } |
180 | 180 |
181 // static | 181 // static |
182 bool ChromeContentBrowserClientExtensionsPart::CanCommitURL( | 182 bool ChromeContentBrowserClientExtensionsPart::CanCommitURL( |
183 content::RenderProcessHost* process_host, const GURL& url) { | 183 content::RenderProcessHost* process_host, const GURL& url) { |
184 // We need to let most extension URLs commit in any process, since this can | 184 // We need to let most extension URLs commit in any process, since this can |
185 // be allowed due to web_accessible_resources. Most hosted app URLs may also | 185 // be allowed due to web_accessible_resources. Most hosted app URLs may also |
186 // load in any process (e.g., in an iframe). However, the Chrome Web Store | 186 // load in any process (e.g., in an iframe). However, the Chrome Web Store |
187 // cannot be loaded in iframes and should never be requested outside its | 187 // cannot be loaded in iframes and should never be requested outside its |
188 // process. | 188 // process. |
189 Profile* profile = | 189 ExtensionRegistry* registry = |
190 Profile::FromBrowserContext(process_host->GetBrowserContext()); | 190 ExtensionRegistry::Get(process_host->GetBrowserContext()); |
191 ExtensionService* service = | 191 if (!registry) |
192 ExtensionSystem::Get(profile)->extension_service(); | |
193 if (!service) | |
194 return true; | 192 return true; |
195 | 193 |
196 const Extension* new_extension = | 194 const Extension* new_extension = |
197 service->extensions()->GetExtensionOrAppByURL(url); | 195 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
198 if (new_extension && | 196 if (new_extension && new_extension->is_hosted_app() && |
199 new_extension->is_hosted_app() && | |
200 new_extension->id() == extensions::kWebStoreAppId && | 197 new_extension->id() == extensions::kWebStoreAppId && |
201 !ProcessMap::Get(profile)->Contains( | 198 !ProcessMap::Get(process_host->GetBrowserContext()) |
202 new_extension->id(), process_host->GetID())) { | 199 ->Contains(new_extension->id(), process_host->GetID())) { |
203 return false; | 200 return false; |
204 } | 201 } |
205 return true; | 202 return true; |
206 } | 203 } |
207 | 204 |
208 // static | 205 // static |
209 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( | 206 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
210 Profile* profile, | 207 Profile* profile, |
211 content::RenderProcessHost* process_host, | 208 content::RenderProcessHost* process_host, |
212 const GURL& site_url) { | 209 const GURL& site_url) { |
213 DCHECK(profile); | 210 DCHECK(profile); |
214 | 211 |
215 ExtensionService* service = | 212 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
216 ExtensionSystem::Get(profile)->extension_service(); | |
217 ProcessMap* process_map = ProcessMap::Get(profile); | 213 ProcessMap* process_map = ProcessMap::Get(profile); |
218 | 214 |
219 // These may be NULL during tests. In that case, just assume any site can | 215 // These may be NULL during tests. In that case, just assume any site can |
220 // share any host. | 216 // share any host. |
221 if (!service || !process_map) | 217 if (!registry || !process_map) |
222 return true; | 218 return true; |
223 | 219 |
224 // Otherwise, just make sure the process privilege matches the privilege | 220 // Otherwise, just make sure the process privilege matches the privilege |
225 // required by the site. | 221 // required by the site. |
226 RenderProcessHostPrivilege privilege_required = | 222 RenderProcessHostPrivilege privilege_required = |
227 GetPrivilegeRequiredByUrl(site_url, service); | 223 GetPrivilegeRequiredByUrl(site_url, registry); |
228 return GetProcessPrivilege(process_host, process_map, service) == | 224 return GetProcessPrivilege(process_host, process_map, registry) == |
229 privilege_required; | 225 privilege_required; |
230 } | 226 } |
231 | 227 |
232 // static | 228 // static |
233 bool | 229 bool |
234 ChromeContentBrowserClientExtensionsPart::ShouldTryToUseExistingProcessHost( | 230 ChromeContentBrowserClientExtensionsPart::ShouldTryToUseExistingProcessHost( |
235 Profile* profile, const GURL& url) { | 231 Profile* profile, const GURL& url) { |
236 // This function is trying to limit the amount of processes used by extensions | 232 // This function is trying to limit the amount of processes used by extensions |
237 // with background pages. It uses a globally set percentage of processes to | 233 // with background pages. It uses a globally set percentage of processes to |
238 // run such extensions and if the limit is exceeded, it returns true, to | 234 // run such extensions and if the limit is exceeded, it returns true, to |
239 // indicate to the content module to group extensions together. | 235 // indicate to the content module to group extensions together. |
240 ExtensionService* service = profile ? | 236 ExtensionRegistry* registry = |
241 ExtensionSystem::Get(profile)->extension_service() : NULL; | 237 profile ? ExtensionRegistry::Get(profile) : NULL; |
242 if (!service) | 238 if (!registry) |
243 return false; | 239 return false; |
244 | 240 |
245 // We have to have a valid extension with background page to proceed. | 241 // We have to have a valid extension with background page to proceed. |
246 const Extension* extension = | 242 const Extension* extension = |
247 service->extensions()->GetExtensionOrAppByURL(url); | 243 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
248 if (!extension) | 244 if (!extension) |
249 return false; | 245 return false; |
250 if (!BackgroundInfo::HasBackgroundPage(extension)) | 246 if (!BackgroundInfo::HasBackgroundPage(extension)) |
251 return false; | 247 return false; |
252 | 248 |
253 std::set<int> process_ids; | 249 std::set<int> process_ids; |
254 size_t max_process_count = | 250 size_t max_process_count = |
255 content::RenderProcessHost::GetMaxRendererProcessCount(); | 251 content::RenderProcessHost::GetMaxRendererProcessCount(); |
256 | 252 |
257 // Go through all profiles to ensure we have total count of extension | 253 // Go through all profiles to ensure we have total count of extension |
(...skipping 12 matching lines...) Expand all Loading... |
270 | 266 |
271 return (process_ids.size() > | 267 return (process_ids.size() > |
272 (max_process_count * chrome::kMaxShareOfExtensionProcesses)); | 268 (max_process_count * chrome::kMaxShareOfExtensionProcesses)); |
273 } | 269 } |
274 | 270 |
275 // static | 271 // static |
276 bool ChromeContentBrowserClientExtensionsPart:: | 272 bool ChromeContentBrowserClientExtensionsPart:: |
277 ShouldSwapBrowsingInstancesForNavigation(SiteInstance* site_instance, | 273 ShouldSwapBrowsingInstancesForNavigation(SiteInstance* site_instance, |
278 const GURL& current_url, | 274 const GURL& current_url, |
279 const GURL& new_url) { | 275 const GURL& new_url) { |
280 // If we don't have an ExtensionService, then rely on the SiteInstance logic | 276 // If we don't have an ExtensionRegistry, then rely on the SiteInstance logic |
281 // in RenderFrameHostManager to decide when to swap. | 277 // in RenderFrameHostManager to decide when to swap. |
282 Profile* profile = | 278 ExtensionRegistry* registry = |
283 Profile::FromBrowserContext(site_instance->GetBrowserContext()); | 279 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
284 ExtensionService* service = | 280 if (!registry) |
285 ExtensionSystem::Get(profile)->extension_service(); | |
286 if (!service) | |
287 return false; | 281 return false; |
288 | 282 |
289 // We must use a new BrowsingInstance (forcing a process swap and disabling | 283 // We must use a new BrowsingInstance (forcing a process swap and disabling |
290 // scripting by existing tabs) if one of the URLs is an extension and the | 284 // scripting by existing tabs) if one of the URLs is an extension and the |
291 // other is not the exact same extension. | 285 // other is not the exact same extension. |
292 // | 286 // |
293 // We ignore hosted apps here so that other tabs in their BrowsingInstance can | 287 // We ignore hosted apps here so that other tabs in their BrowsingInstance can |
294 // use postMessage with them. (The exception is the Chrome Web Store, which | 288 // use postMessage with them. (The exception is the Chrome Web Store, which |
295 // is a hosted app that requires its own BrowsingInstance.) Navigations | 289 // is a hosted app that requires its own BrowsingInstance.) Navigations |
296 // to/from a hosted app will still trigger a SiteInstance swap in | 290 // to/from a hosted app will still trigger a SiteInstance swap in |
297 // RenderFrameHostManager. | 291 // RenderFrameHostManager. |
298 const Extension* current_extension = | 292 const Extension* current_extension = |
299 service->extensions()->GetExtensionOrAppByURL(current_url); | 293 registry->enabled_extensions().GetExtensionOrAppByURL(current_url); |
300 if (current_extension && | 294 if (current_extension && |
301 current_extension->is_hosted_app() && | 295 current_extension->is_hosted_app() && |
302 current_extension->id() != extensions::kWebStoreAppId) | 296 current_extension->id() != extensions::kWebStoreAppId) |
303 current_extension = NULL; | 297 current_extension = NULL; |
304 | 298 |
305 const Extension* new_extension = | 299 const Extension* new_extension = |
306 service->extensions()->GetExtensionOrAppByURL(new_url); | 300 registry->enabled_extensions().GetExtensionOrAppByURL(new_url); |
307 if (new_extension && | 301 if (new_extension && |
308 new_extension->is_hosted_app() && | 302 new_extension->is_hosted_app() && |
309 new_extension->id() != extensions::kWebStoreAppId) | 303 new_extension->id() != extensions::kWebStoreAppId) |
310 new_extension = NULL; | 304 new_extension = NULL; |
311 | 305 |
312 // First do a process check. We should force a BrowsingInstance swap if the | 306 // First do a process check. We should force a BrowsingInstance swap if the |
313 // current process doesn't know about new_extension, even if current_extension | 307 // current process doesn't know about new_extension, even if current_extension |
314 // is somehow the same as new_extension. | 308 // is somehow the same as new_extension. |
315 ProcessMap* process_map = ProcessMap::Get(profile); | 309 ProcessMap* process_map = ProcessMap::Get(site_instance->GetBrowserContext()); |
316 if (new_extension && | 310 if (new_extension && |
317 site_instance->HasProcess() && | 311 site_instance->HasProcess() && |
318 !process_map->Contains( | 312 !process_map->Contains( |
319 new_extension->id(), site_instance->GetProcess()->GetID())) | 313 new_extension->id(), site_instance->GetProcess()->GetID())) |
320 return true; | 314 return true; |
321 | 315 |
322 // Otherwise, swap BrowsingInstances if current_extension and new_extension | 316 // Otherwise, swap BrowsingInstances if current_extension and new_extension |
323 // differ. | 317 // differ. |
324 return current_extension != new_extension; | 318 return current_extension != new_extension; |
325 } | 319 } |
(...skipping 16 matching lines...) Expand all Loading... |
342 const GURL& to_url, | 336 const GURL& to_url, |
343 bool* result) { | 337 bool* result) { |
344 DCHECK(result); | 338 DCHECK(result); |
345 | 339 |
346 // Do not allow pages from the web or other extensions navigate to | 340 // Do not allow pages from the web or other extensions navigate to |
347 // non-web-accessible extension resources. | 341 // non-web-accessible extension resources. |
348 if (to_url.SchemeIs(kExtensionScheme) && | 342 if (to_url.SchemeIs(kExtensionScheme) && |
349 (from_url.SchemeIsHTTPOrHTTPS() || from_url.SchemeIs(kExtensionScheme))) { | 343 (from_url.SchemeIsHTTPOrHTTPS() || from_url.SchemeIs(kExtensionScheme))) { |
350 Profile* profile = Profile::FromBrowserContext( | 344 Profile* profile = Profile::FromBrowserContext( |
351 site_instance->GetProcess()->GetBrowserContext()); | 345 site_instance->GetProcess()->GetBrowserContext()); |
352 ExtensionService* service = | 346 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
353 ExtensionSystem::Get(profile)->extension_service(); | 347 if (!registry) { |
354 if (!service) { | |
355 *result = true; | 348 *result = true; |
356 return true; | 349 return true; |
357 } | 350 } |
358 const Extension* extension = | 351 const Extension* extension = |
359 service->extensions()->GetExtensionOrAppByURL(to_url); | 352 registry->enabled_extensions().GetExtensionOrAppByURL(to_url); |
360 if (!extension) { | 353 if (!extension) { |
361 *result = true; | 354 *result = true; |
362 return true; | 355 return true; |
363 } | 356 } |
364 const Extension* from_extension = | 357 const Extension* from_extension = |
365 service->extensions()->GetExtensionOrAppByURL( | 358 registry->enabled_extensions().GetExtensionOrAppByURL( |
366 site_instance->GetSiteURL()); | 359 site_instance->GetSiteURL()); |
367 if (from_extension && from_extension->id() == extension->id()) { | 360 if (from_extension && from_extension->id() == extension->id()) { |
368 *result = true; | 361 *result = true; |
369 return true; | 362 return true; |
370 } | 363 } |
371 | 364 |
372 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible( | 365 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible( |
373 extension, to_url.path())) { | 366 extension, to_url.path())) { |
374 *result = false; | 367 *result = false; |
375 return true; | 368 return true; |
(...skipping 21 matching lines...) Expand all Loading... |
397 int id = host->GetID(); | 390 int id = host->GetID(); |
398 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 391 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
399 | 392 |
400 host->AddFilter(new ChromeExtensionMessageFilter(id, profile)); | 393 host->AddFilter(new ChromeExtensionMessageFilter(id, profile)); |
401 host->AddFilter(new ExtensionMessageFilter(id, profile)); | 394 host->AddFilter(new ExtensionMessageFilter(id, profile)); |
402 extension_web_request_api_helpers::SendExtensionWebRequestStatusToHost(host); | 395 extension_web_request_api_helpers::SendExtensionWebRequestStatusToHost(host); |
403 } | 396 } |
404 | 397 |
405 void ChromeContentBrowserClientExtensionsPart::SiteInstanceGotProcess( | 398 void ChromeContentBrowserClientExtensionsPart::SiteInstanceGotProcess( |
406 SiteInstance* site_instance) { | 399 SiteInstance* site_instance) { |
407 Profile* profile = Profile::FromBrowserContext( | 400 BrowserContext* context = site_instance->GetProcess()->GetBrowserContext(); |
408 site_instance->GetProcess()->GetBrowserContext()); | 401 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
409 ExtensionService* service = | 402 if (!registry) |
410 ExtensionSystem::Get(profile)->extension_service(); | |
411 if (!service) | |
412 return; | 403 return; |
413 | 404 |
414 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( | 405 const Extension* extension = |
415 site_instance->GetSiteURL()); | 406 registry->enabled_extensions().GetExtensionOrAppByURL( |
| 407 site_instance->GetSiteURL()); |
416 if (!extension) | 408 if (!extension) |
417 return; | 409 return; |
418 | 410 |
419 ProcessMap::Get(profile)->Insert(extension->id(), | 411 ProcessMap::Get(context)->Insert(extension->id(), |
420 site_instance->GetProcess()->GetID(), | 412 site_instance->GetProcess()->GetID(), |
421 site_instance->GetId()); | 413 site_instance->GetId()); |
422 | 414 |
423 BrowserThread::PostTask(BrowserThread::IO, | 415 BrowserThread::PostTask( |
424 FROM_HERE, | 416 BrowserThread::IO, FROM_HERE, |
425 base::Bind(&InfoMap::RegisterExtensionProcess, | 417 base::Bind(&InfoMap::RegisterExtensionProcess, |
426 ExtensionSystem::Get(profile)->info_map(), | 418 ExtensionSystem::Get(context)->info_map(), extension->id(), |
427 extension->id(), | 419 site_instance->GetProcess()->GetID(), site_instance->GetId())); |
428 site_instance->GetProcess()->GetID(), | |
429 site_instance->GetId())); | |
430 } | 420 } |
431 | 421 |
432 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( | 422 void ChromeContentBrowserClientExtensionsPart::SiteInstanceDeleting( |
433 SiteInstance* site_instance) { | 423 SiteInstance* site_instance) { |
434 Profile* profile = | 424 BrowserContext* context = site_instance->GetBrowserContext(); |
435 Profile::FromBrowserContext(site_instance->GetBrowserContext()); | 425 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
436 ExtensionService* service = | 426 if (!registry) |
437 ExtensionSystem::Get(profile)->extension_service(); | |
438 if (!service) | |
439 return; | 427 return; |
440 | 428 |
441 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( | 429 const Extension* extension = |
442 site_instance->GetSiteURL()); | 430 registry->enabled_extensions().GetExtensionOrAppByURL( |
| 431 site_instance->GetSiteURL()); |
443 if (!extension) | 432 if (!extension) |
444 return; | 433 return; |
445 | 434 |
446 ProcessMap::Get(profile)->Remove(extension->id(), | 435 ProcessMap::Get(context)->Remove(extension->id(), |
447 site_instance->GetProcess()->GetID(), | 436 site_instance->GetProcess()->GetID(), |
448 site_instance->GetId()); | 437 site_instance->GetId()); |
449 | 438 |
450 BrowserThread::PostTask(BrowserThread::IO, | 439 BrowserThread::PostTask( |
451 FROM_HERE, | 440 BrowserThread::IO, FROM_HERE, |
452 base::Bind(&InfoMap::UnregisterExtensionProcess, | 441 base::Bind(&InfoMap::UnregisterExtensionProcess, |
453 ExtensionSystem::Get(profile)->info_map(), | 442 ExtensionSystem::Get(context)->info_map(), extension->id(), |
454 extension->id(), | 443 site_instance->GetProcess()->GetID(), site_instance->GetId())); |
455 site_instance->GetProcess()->GetID(), | |
456 site_instance->GetId())); | |
457 } | 444 } |
458 | 445 |
459 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( | 446 void ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs( |
460 RenderViewHost* rvh, | 447 RenderViewHost* rvh, |
461 const GURL& url, | 448 const GURL& url, |
462 WebPreferences* web_prefs) { | 449 WebPreferences* web_prefs) { |
463 Profile* profile = | 450 const ExtensionRegistry* registry = |
464 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | 451 ExtensionRegistry::Get(rvh->GetProcess()->GetBrowserContext()); |
465 | 452 if (!registry) |
466 ExtensionService* service = | |
467 ExtensionSystem::Get(profile)->extension_service(); | |
468 if (!service) | |
469 return; | 453 return; |
470 | 454 |
471 // Note: it's not possible for kExtensionsScheme to change during the lifetime | 455 // Note: it's not possible for kExtensionsScheme to change during the lifetime |
472 // of the process. | 456 // of the process. |
473 // | 457 // |
474 // Ensure that we are only granting extension preferences to URLs with | 458 // Ensure that we are only granting extension preferences to URLs with |
475 // the correct scheme. Without this check, chrome-guest:// schemes used by | 459 // the correct scheme. Without this check, chrome-guest:// schemes used by |
476 // webview tags as well as hosts that happen to match the id of an | 460 // webview tags as well as hosts that happen to match the id of an |
477 // installed extension would get the wrong preferences. | 461 // installed extension would get the wrong preferences. |
478 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL(); | 462 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL(); |
479 if (!site_url.SchemeIs(kExtensionScheme)) | 463 if (!site_url.SchemeIs(kExtensionScheme)) |
480 return; | 464 return; |
481 | 465 |
482 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 466 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
483 ViewType view_type = GetViewType(web_contents); | 467 ViewType view_type = GetViewType(web_contents); |
484 const Extension* extension = service->extensions()->GetByID(site_url.host()); | 468 const Extension* extension = |
| 469 registry->enabled_extensions().GetByID(site_url.host()); |
485 extension_webkit_preferences::SetPreferences(extension, view_type, web_prefs); | 470 extension_webkit_preferences::SetPreferences(extension, view_type, web_prefs); |
486 } | 471 } |
487 | 472 |
488 void ChromeContentBrowserClientExtensionsPart::BrowserURLHandlerCreated( | 473 void ChromeContentBrowserClientExtensionsPart::BrowserURLHandlerCreated( |
489 BrowserURLHandler* handler) { | 474 BrowserURLHandler* handler) { |
490 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, | 475 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
491 BrowserURLHandler::null_handler()); | 476 BrowserURLHandler::null_handler()); |
492 handler->AddHandlerPair(BrowserURLHandler::null_handler(), | 477 handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
493 &ExtensionWebUI::HandleChromeURLOverrideReverse); | 478 &ExtensionWebUI::HandleChromeURLOverrideReverse); |
494 } | 479 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); | 518 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); |
534 #endif | 519 #endif |
535 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 520 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
536 switches::kEnableMojoSerialService)) { | 521 switches::kEnableMojoSerialService)) { |
537 command_line->AppendSwitch(switches::kEnableMojoSerialService); | 522 command_line->AppendSwitch(switches::kEnableMojoSerialService); |
538 } | 523 } |
539 } | 524 } |
540 } | 525 } |
541 | 526 |
542 } // namespace extensions | 527 } // namespace extensions |
OLD | NEW |