Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: chrome/browser/extensions/extension_protocols.cc

Issue 22793018: <webview>: Implement support for package-local chrome-extension:// URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a comment Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extension_protocols.h" 5 #include "chrome/browser/extensions/extension_protocols.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/format_macros.h" 13 #include "base/format_macros.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/sha1.h" 18 #include "base/sha1.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "chrome/browser/extensions/extension_info_map.h" 26 #include "chrome/browser/extensions/extension_info_map.h"
27 #include "chrome/browser/extensions/extension_renderer_state.h"
27 #include "chrome/browser/extensions/image_loader.h" 28 #include "chrome/browser/extensions/image_loader.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/extensions/background_info.h" 30 #include "chrome/common/extensions/background_info.h"
30 #include "chrome/common/extensions/csp_handler.h" 31 #include "chrome/common/extensions/csp_handler.h"
31 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
32 #include "chrome/common/extensions/extension_file_util.h" 33 #include "chrome/common/extensions/extension_file_util.h"
33 #include "chrome/common/extensions/incognito_handler.h" 34 #include "chrome/common/extensions/incognito_handler.h"
34 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 35 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
35 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 36 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
36 #include "chrome/common/extensions/manifest_url_handler.h" 37 #include "chrome/common/extensions/manifest_url_handler.h"
37 #include "chrome/common/extensions/web_accessible_resources_handler.h" 38 #include "chrome/common/extensions/web_accessible_resources_handler.h"
39 #include "chrome/common/extensions/webview_handler.h"
38 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
39 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/resource_request_info.h" 42 #include "content/public/browser/resource_request_info.h"
41 #include "extensions/common/constants.h" 43 #include "extensions/common/constants.h"
42 #include "extensions/common/extension_resource.h" 44 #include "extensions/common/extension_resource.h"
43 #include "grit/component_extension_resources_map.h" 45 #include "grit/component_extension_resources_map.h"
44 #include "net/base/mime_util.h" 46 #include "net/base/mime_util.h"
45 #include "net/base/net_errors.h" 47 #include "net/base/net_errors.h"
46 #include "net/http/http_request_headers.h" 48 #include "net/http/http_request_headers.h"
47 #include "net/http/http_response_headers.h" 49 #include "net/http/http_response_headers.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 340 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
339 341
340 // We have seen crashes where info is NULL: crbug.com/52374. 342 // We have seen crashes where info is NULL: crbug.com/52374.
341 if (!info) { 343 if (!info) {
342 LOG(ERROR) << "Allowing load of " << request->url().spec() 344 LOG(ERROR) << "Allowing load of " << request->url().spec()
343 << "from unknown origin. Could not find user data for " 345 << "from unknown origin. Could not find user data for "
344 << "request."; 346 << "request.";
345 return true; 347 return true;
346 } 348 }
347 349
348 if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(),
349 extension_info_map)) {
350 return false;
351 }
352
353 // The following checks are meant to replicate similar set of checks in the 350 // The following checks are meant to replicate similar set of checks in the
354 // renderer process, performed by ResourceRequestPolicy::CanRequestResource. 351 // renderer process, performed by ResourceRequestPolicy::CanRequestResource.
355 // These are not exactly equivalent, because we don't have the same bits of 352 // These are not exactly equivalent, because we don't have the same bits of
356 // information. The two checks need to be kept in sync as much as possible, as 353 // information. The two checks need to be kept in sync as much as possible, as
357 // an exploited renderer can bypass the checks in ResourceRequestPolicy. 354 // an exploited renderer can bypass the checks in ResourceRequestPolicy.
358 355
359 // Check if the extension for which this request is made is indeed loaded in 356 // Check if the extension for which this request is made is indeed loaded in
360 // the process sending the request. If not, we need to explicitly check if 357 // the process sending the request. If not, we need to explicitly check if
361 // the resource is explicitly accessible or fits in a set of exception cases. 358 // the resource is explicitly accessible or fits in a set of exception cases.
362 // Note: This allows a case where two extensions execute in the same renderer 359 // Note: This allows a case where two extensions execute in the same renderer
363 // process to request each other's resources. We can't do a more precise 360 // process to request each other's resources. We can't do a more precise
364 // check, since the renderer can lie about which extension has made the 361 // check, since the renderer can lie about which extension has made the
365 // request. 362 // request.
366 if (extension_info_map->process_map().Contains( 363 if (extension_info_map->process_map().Contains(
367 request->url().host(), info->GetChildID())) { 364 request->url().host(), info->GetChildID())) {
368 return true; 365 return true;
369 } 366 }
370 367
368 // Extensions with webview: allow loading certain resources by guest renderers
369 // with privileged partition IDs as specified in the manifest file.
370 ExtensionRendererState* renderer_state =
371 ExtensionRendererState::GetInstance();
372 ExtensionRendererState::WebViewInfo webview_info;
373 bool is_guest = renderer_state->GetWebViewInfo(info->GetChildID(),
374 info->GetRouteID(),
375 &webview_info);
376 std::string resource_path = request->url().path();
377 if (is_guest &&
378 extensions::WebviewInfo::IsResourceWebviewAccessible(
379 extension, webview_info.partition_id, resource_path)) {
380 return true;
381 }
382
371 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition())) 383 if (!content::PageTransitionIsWebTriggerable(info->GetPageTransition()))
372 return false; 384 return false;
373 385
374 // The following checks require that we have an actual extension object. If we 386 // The following checks require that we have an actual extension object. If we
375 // don't have it, allow the request handling to continue with the rest of the 387 // don't have it, allow the request handling to continue with the rest of the
376 // checks. 388 // checks.
377 if (!extension) 389 if (!extension)
378 return true; 390 return true;
379 391
380 // Disallow loading of packaged resources for hosted apps. We don't allow 392 // Disallow loading of packaged resources for hosted apps. We don't allow
(...skipping 14 matching lines...) Expand all
395 // Extensions with web_accessible_resources: allow loading by regular 407 // Extensions with web_accessible_resources: allow loading by regular
396 // renderers. Since not all subresources are required to be listed in a v2 408 // renderers. Since not all subresources are required to be listed in a v2
397 // manifest, we must allow all loads if there are any web accessible 409 // manifest, we must allow all loads if there are any web accessible
398 // resources. See http://crbug.com/179127. 410 // resources. See http://crbug.com/179127.
399 if (extension->manifest_version() < 2 || 411 if (extension->manifest_version() < 2 ||
400 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources( 412 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources(
401 extension)) { 413 extension)) {
402 return true; 414 return true;
403 } 415 }
404 416
417 if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(),
418 extension_info_map)) {
419 return false;
420 }
421
422
405 // If there aren't any explicitly marked web accessible resources, the 423 // If there aren't any explicitly marked web accessible resources, the
406 // load should be allowed only if it is by DevTools. A close approximation is 424 // load should be allowed only if it is by DevTools. A close approximation is
407 // checking if the extension contains a DevTools page. 425 // checking if the extension contains a DevTools page.
408 if (extensions::ManifestURL::GetDevToolsPage(extension).is_empty()) 426 if (extensions::ManifestURL::GetDevToolsPage(extension).is_empty())
409 return false; 427 return false;
410 428
411 return true; 429 return true;
412 } 430 }
413 431
414 // Returns true if the given URL references an icon in the given extension. 432 // Returns true if the given URL references an icon in the given extension.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 send_cors_header); 590 send_cors_header);
573 } 591 }
574 592
575 } // namespace 593 } // namespace
576 594
577 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 595 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
578 bool is_incognito, 596 bool is_incognito,
579 ExtensionInfoMap* extension_info_map) { 597 ExtensionInfoMap* extension_info_map) {
580 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 598 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
581 } 599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698