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

Side by Side Diff: chrome/renderer/extensions/resource_request_policy.cc

Issue 1312653003: Fix for WebView accessible resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments by lfg@. Created 5 years, 3 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/renderer/extensions/resource_request_policy.h" 5 #include "chrome/renderer/extensions/resource_request_policy.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" 9 #include "chrome/common/extensions/chrome_manifest_url_handlers.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "extensions/common/constants.h" 11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/manifest_handlers/icons_handler.h" 14 #include "extensions/common/manifest_handlers/icons_handler.h"
14 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" 15 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
16 #include "extensions/common/manifest_handlers/webview_info.h"
15 #include "extensions/renderer/renderer_extension_registry.h" 17 #include "extensions/renderer/renderer_extension_registry.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 19 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 20 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "ui/base/page_transition_types.h" 22 #include "ui/base/page_transition_types.h"
21 #include "url/gurl.h" 23 #include "url/gurl.h"
22 24
23 namespace extensions { 25 namespace extensions {
24 26
(...skipping 26 matching lines...) Expand all
51 resource_url.path().empty() ? std::string() 53 resource_url.path().empty() ? std::string()
52 : resource_url.path().substr(1); 54 : resource_url.path().substr(1);
53 if (extension->is_hosted_app() && 55 if (extension->is_hosted_app() &&
54 !IconsInfo::GetIcons(extension) 56 !IconsInfo::GetIcons(extension)
55 .ContainsPath(resource_root_relative_path)) { 57 .ContainsPath(resource_root_relative_path)) {
56 LOG(ERROR) << "Denying load of " << resource_url.spec() << " from " 58 LOG(ERROR) << "Denying load of " << resource_url.spec() << " from "
57 << "hosted app."; 59 << "hosted app.";
58 return false; 60 return false;
59 } 61 }
60 62
61 // Disallow loading of extension resources which are not explicitly listed 63 // Allow loading of extension resources which are explicitly listed as web or
62 // as web accessible if the manifest version is 2 or greater. 64 // webview accessible if the manifest version is 2 or greater.
63 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible( 65 const WebviewInfo* webview_info = static_cast<const extensions::WebviewInfo*>(
64 extension, resource_url.path())) { 66 extension->GetManifestData(manifest_keys::kWebviewAccessibleResources));
not at google - send to devlin 2015/08/27 20:01:25 Usually there would be a WebviewInfo::Get(extensio
paulmeyer 2015/08/31 15:32:55 Done.
65 GURL frame_url = frame->document().url(); 67 if (WebAccessibleResourcesInfo::IsResourceWebAccessible(
not at google - send to devlin 2015/08/27 20:01:25 Is there a way to improve this diff? Like, go back
paulmeyer 2015/08/31 15:32:55 You're right, it's hard to tell. Done.
68 extension, resource_url.path()) ||
69 (webview_info &&
70 webview_info->IsResourceWebviewAccessible(
71 extension, RendererExtensionRegistry::Get()->webview_partition_id(),
72 resource_url.path()))) {
73 return true;
74 }
66 75
67 // The page_origin may be GURL("null") for unique origins like data URLs, 76 GURL frame_url = frame->document().url();
68 // but this is ok for the checks below. We only care if it matches the
69 // current extension or has a devtools scheme.
70 GURL page_origin = GURL(frame->top()->securityOrigin().toString());
71 77
72 // Exceptions are: 78 // The page_origin may be GURL("null") for unique origins like data URLs,
73 // - empty origin (needed for some edge cases when we have empty origins) 79 // but this is ok for the checks below. We only care if it matches the
74 bool is_empty_origin = frame_url.is_empty(); 80 // current extension or has a devtools scheme.
75 // - extensions requesting their own resources (frame_url check is for 81 GURL page_origin = GURL(frame->top()->securityOrigin().toString());
76 // images, page_url check is for iframes)
77 bool is_own_resource = frame_url.GetOrigin() == extension->url() ||
78 page_origin == extension->url();
79 // - devtools (chrome-extension:// URLs are loaded into frames of devtools
80 // to support the devtools extension APIs)
81 bool is_dev_tools =
82 page_origin.SchemeIs(content::kChromeDevToolsScheme) &&
83 !chrome_manifest_urls::GetDevToolsPage(extension).is_empty();
84 bool transition_allowed =
85 !ui::PageTransitionIsWebTriggerable(transition_type);
86 // - unreachable web page error page (to allow showing the icon of the
87 // unreachable app on this page)
88 bool is_error_page = frame_url == GURL(content::kUnreachableWebDataURL);
89 82
90 if (!is_empty_origin && !is_own_resource && 83 // Exceptions are:
91 !is_dev_tools && !transition_allowed && !is_error_page) { 84 // - empty origin (needed for some edge cases when we have empty origins)
92 std::string message = base::StringPrintf( 85 bool is_empty_origin = frame_url.is_empty();
93 "Denying load of %s. Resources must be listed in the " 86 // - extensions requesting their own resources (frame_url check is for
94 "web_accessible_resources manifest key in order to be loaded by " 87 // images, page_url check is for iframes)
95 "pages outside the extension.", 88 bool is_own_resource = frame_url.GetOrigin() == extension->url() ||
96 resource_url.spec().c_str()); 89 page_origin == extension->url();
97 frame->addMessageToConsole( 90 // - devtools (chrome-extension:// URLs are loaded into frames of devtools
98 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError, 91 // to support the devtools extension APIs)
99 blink::WebString::fromUTF8(message))); 92 bool is_dev_tools =
100 return false; 93 page_origin.SchemeIs(content::kChromeDevToolsScheme) &&
101 } 94 !chrome_manifest_urls::GetDevToolsPage(extension).is_empty();
95 bool transition_allowed =
96 !ui::PageTransitionIsWebTriggerable(transition_type);
97 // - unreachable web page error page (to allow showing the icon of the
98 // unreachable app on this page)
99 bool is_error_page = frame_url == GURL(content::kUnreachableWebDataURL);
100
101 if (!is_empty_origin && !is_own_resource && !is_dev_tools &&
102 !transition_allowed && !is_error_page) {
103 std::string message = base::StringPrintf(
104 "Denying load of %s. Resources must be listed in the "
105 "web_accessible_resources manifest key in order to be loaded by "
106 "pages outside the extension.",
107 resource_url.spec().c_str());
108 frame->addMessageToConsole(
109 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError,
110 blink::WebString::fromUTF8(message)));
111 return false;
102 } 112 }
103 113
104 return true; 114 return true;
105 } 115 }
106 116
107 // static 117 // static
108 bool ResourceRequestPolicy::CanRequestExtensionResourceScheme( 118 bool ResourceRequestPolicy::CanRequestExtensionResourceScheme(
109 const GURL& resource_url, 119 const GURL& resource_url,
110 blink::WebFrame* frame) { 120 blink::WebFrame* frame) {
111 CHECK(resource_url.SchemeIs(extensions::kExtensionResourceScheme)); 121 CHECK(resource_url.SchemeIs(extensions::kExtensionResourceScheme));
(...skipping 11 matching lines...) Expand all
123 return false; 133 return false;
124 } 134 }
125 135
126 return true; 136 return true;
127 } 137 }
128 138
129 ResourceRequestPolicy::ResourceRequestPolicy() { 139 ResourceRequestPolicy::ResourceRequestPolicy() {
130 } 140 }
131 141
132 } // namespace extensions 142 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698