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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_web_ui.h" | 14 #include "chrome/browser/extensions/extension_web_ui.h" |
15 #include "chrome/browser/extensions/extension_webkit_preferences.h" | 15 #include "chrome/browser/extensions/extension_webkit_preferences.h" |
16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" | 20 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" |
21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 21 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/extensions/extension_process_policy.h" | 24 #include "chrome/common/extensions/extension_process_policy.h" |
25 #include "components/guest_view/browser/guest_view_message_filter.h" | 25 #include "components/guest_view/browser/guest_view_message_filter.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/browser_url_handler.h" | 27 #include "content/public/browser/browser_url_handler.h" |
28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/resource_dispatcher_host.h" | |
30 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
31 #include "content/public/browser/vpn_service_proxy.h" | 32 #include "content/public/browser/vpn_service_proxy.h" |
32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
34 #include "extensions/browser/api/web_request/web_request_api.h" | 35 #include "extensions/browser/api/web_request/web_request_api.h" |
35 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 36 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
37 #include "extensions/browser/bad_message.h" | |
36 #include "extensions/browser/extension_host.h" | 38 #include "extensions/browser/extension_host.h" |
37 #include "extensions/browser/extension_message_filter.h" | 39 #include "extensions/browser/extension_message_filter.h" |
38 #include "extensions/browser/extension_registry.h" | 40 #include "extensions/browser/extension_registry.h" |
39 #include "extensions/browser/extension_service_worker_message_filter.h" | 41 #include "extensions/browser/extension_service_worker_message_filter.h" |
40 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
41 #include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" | 43 #include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" |
42 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 44 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
43 #include "extensions/browser/info_map.h" | 45 #include "extensions/browser/info_map.h" |
44 #include "extensions/browser/io_thread_extension_message_filter.h" | 46 #include "extensions/browser/io_thread_extension_message_filter.h" |
45 #include "extensions/browser/view_type_utils.h" | 47 #include "extensions/browser/view_type_utils.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 registry->enabled_extensions().GetByID(extension_id); | 120 registry->enabled_extensions().GetByID(extension_id); |
119 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) | 121 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) |
120 return PRIV_ISOLATED; | 122 return PRIV_ISOLATED; |
121 if (extension && extension->is_hosted_app()) | 123 if (extension && extension->is_hosted_app()) |
122 return PRIV_HOSTED; | 124 return PRIV_HOSTED; |
123 } | 125 } |
124 | 126 |
125 return PRIV_EXTENSION; | 127 return PRIV_EXTENSION; |
126 } | 128 } |
127 | 129 |
130 // Determines whether the extension |origin| passed in can be committed by | |
131 // the process identified by |child_id| and returns true or false | |
132 // accordingly. Please refer to the implementation for more information. | |
133 bool IsIllegalOrigin(content::ResourceContext* resource_context, | |
134 int child_id, | |
135 const GURL& origin) { | |
136 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
137 | |
138 // Consider non-extension URLs safe; they will be checked elsewhere. | |
139 if (!origin.SchemeIs(kExtensionScheme)) | |
140 return false; | |
141 | |
142 // If there is no extension installed for the URL, it couldn't have | |
143 // committed. | |
Charlie Reis
2016/08/10 20:44:01
nit: Does "committed" fit on the previous line? I
| |
144 // (If the extension was recently uninstalled, the tab would have closed.) | |
145 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
146 InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); | |
147 const Extension* extension = | |
148 extension_info_map->extensions().GetExtensionOrAppByURL(origin); | |
149 if (!extension) | |
150 return true; | |
151 | |
152 // Check for platform app origins. These can only be committed by the app | |
153 // itself, or by one if its guests if there are accessible_resources. | |
154 const ProcessMap& process_map = extension_info_map->process_map(); | |
155 if (extension->is_platform_app() && | |
156 !process_map.Contains(extension->id(), child_id)) { | |
157 // This is a platform app origin not in the app's own process. If there | |
158 // are | |
Charlie Reis
2016/08/10 20:44:02
nit: Fix line wrap.
| |
159 // no accessible resources, this is illegal. | |
160 if (!extension->GetManifestData(manifest_keys::kWebviewAccessibleResources)) | |
161 return true; | |
162 | |
163 // If there are accessible resources, the origin is only legal if the | |
164 // given | |
Charlie Reis
2016/08/10 20:44:01
Same.
| |
165 // process is a guest of the app. | |
166 std::string owner_extension_id; | |
167 int owner_process_id; | |
168 WebViewRendererState::GetInstance()->GetOwnerInfo( | |
169 child_id, &owner_process_id, &owner_extension_id); | |
170 const Extension* owner_extension = | |
171 extension_info_map->extensions().GetByID(owner_extension_id); | |
172 return !owner_extension || owner_extension != extension; | |
173 } | |
174 | |
175 // With only the origin and not the full URL, we don't have enough | |
176 // information | |
Charlie Reis
2016/08/10 20:44:02
Same.
| |
177 // to validate hosted apps or web_accessible_resources in normal extensions. | |
178 // Assume they're legal. | |
179 return false; | |
180 } | |
181 | |
182 // This callback is registered on the ResourceDispatcherHost for the chrome | |
183 // extension Origin scheme. We determine whether the extension origin is | |
184 // valid. Please see the IsIllegalOrigin() function. | |
185 void OnHttpHeaderReceived(const std::string& header, | |
186 const std::string& value, | |
187 int child_id, | |
188 content::ResourceContext* resource_context, | |
189 content::OnHeaderProcessedCallback callback) { | |
190 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
191 | |
192 GURL origin(value); | |
193 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); | |
194 | |
195 if (IsIllegalOrigin(resource_context, child_id, origin)) { | |
196 callback.Run(false, bad_message::INVALID_ORIGIN); | |
197 } else { | |
198 callback.Run(true, 0); | |
199 } | |
200 } | |
201 | |
128 } // namespace | 202 } // namespace |
129 | 203 |
130 ChromeContentBrowserClientExtensionsPart:: | 204 ChromeContentBrowserClientExtensionsPart:: |
131 ChromeContentBrowserClientExtensionsPart() { | 205 ChromeContentBrowserClientExtensionsPart() { |
132 } | 206 } |
133 | 207 |
134 ChromeContentBrowserClientExtensionsPart:: | 208 ChromeContentBrowserClientExtensionsPart:: |
135 ~ChromeContentBrowserClientExtensionsPart() { | 209 ~ChromeContentBrowserClientExtensionsPart() { |
136 } | 210 } |
137 | 211 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 339 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
266 if (new_extension && new_extension->is_hosted_app() && | 340 if (new_extension && new_extension->is_hosted_app() && |
267 new_extension->id() == kWebStoreAppId && | 341 new_extension->id() == kWebStoreAppId && |
268 !ProcessMap::Get(process_host->GetBrowserContext()) | 342 !ProcessMap::Get(process_host->GetBrowserContext()) |
269 ->Contains(new_extension->id(), process_host->GetID())) { | 343 ->Contains(new_extension->id(), process_host->GetID())) { |
270 return false; | 344 return false; |
271 } | 345 } |
272 return true; | 346 return true; |
273 } | 347 } |
274 | 348 |
275 bool ChromeContentBrowserClientExtensionsPart::IsIllegalOrigin( | |
276 content::ResourceContext* resource_context, | |
277 int child_process_id, | |
278 const GURL& origin) { | |
279 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
280 | |
281 // Consider non-extension URLs safe; they will be checked elsewhere. | |
282 if (!origin.SchemeIs(kExtensionScheme)) | |
283 return false; | |
284 | |
285 // If there is no extension installed for the URL, it couldn't have committed. | |
286 // (If the extension was recently uninstalled, the tab would have closed.) | |
287 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
288 InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); | |
289 const Extension* extension = | |
290 extension_info_map->extensions().GetExtensionOrAppByURL(origin); | |
291 if (!extension) | |
292 return true; | |
293 | |
294 // Check for platform app origins. These can only be committed by the app | |
295 // itself, or by one if its guests if there are accessible_resources. | |
296 const ProcessMap& process_map = extension_info_map->process_map(); | |
297 if (extension->is_platform_app() && | |
298 !process_map.Contains(extension->id(), child_process_id)) { | |
299 // This is a platform app origin not in the app's own process. If there are | |
300 // no accessible resources, this is illegal. | |
301 if (!extension->GetManifestData(manifest_keys::kWebviewAccessibleResources)) | |
302 return true; | |
303 | |
304 // If there are accessible resources, the origin is only legal if the given | |
305 // process is a guest of the app. | |
306 std::string owner_extension_id; | |
307 int owner_process_id; | |
308 WebViewRendererState::GetInstance()->GetOwnerInfo( | |
309 child_process_id, &owner_process_id, &owner_extension_id); | |
310 const Extension* owner_extension = | |
311 extension_info_map->extensions().GetByID(owner_extension_id); | |
312 return !owner_extension || owner_extension != extension; | |
313 } | |
314 | |
315 // With only the origin and not the full URL, we don't have enough information | |
316 // to validate hosted apps or web_accessible_resources in normal extensions. | |
317 // Assume they're legal. | |
318 return false; | |
319 } | |
320 | |
321 // static | 349 // static |
322 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( | 350 bool ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
323 Profile* profile, | 351 Profile* profile, |
324 content::RenderProcessHost* process_host, | 352 content::RenderProcessHost* process_host, |
325 const GURL& site_url) { | 353 const GURL& site_url) { |
326 DCHECK(profile); | 354 DCHECK(profile); |
327 | 355 |
328 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 356 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
329 ProcessMap* process_map = ProcessMap::Get(profile); | 357 ProcessMap* process_map = ProcessMap::Get(profile); |
330 | 358 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 #if defined(ENABLE_WEBRTC) | 683 #if defined(ENABLE_WEBRTC) |
656 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); | 684 command_line->AppendSwitch(::switches::kEnableWebRtcHWH264Encoding); |
657 #endif | 685 #endif |
658 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 686 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
659 switches::kEnableMojoSerialService)) { | 687 switches::kEnableMojoSerialService)) { |
660 command_line->AppendSwitch(switches::kEnableMojoSerialService); | 688 command_line->AppendSwitch(switches::kEnableMojoSerialService); |
661 } | 689 } |
662 } | 690 } |
663 } | 691 } |
664 | 692 |
693 void ChromeContentBrowserClientExtensionsPart::ResourceDispatcherHostCreated() { | |
694 content::ResourceDispatcherHost::Get()->RegisterInterceptor( | |
695 "Origin", kExtensionScheme, base::Bind(&OnHttpHeaderReceived)); | |
696 } | |
697 | |
665 } // namespace extensions | 698 } // namespace extensions |
OLD | NEW |