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

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

Issue 9805004: Add a helpful error in case web-inaccessible request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change message Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/extension_resource_request_policy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extension_resource_request_policy.h" 5 #include "chrome/renderer/extensions/extension_resource_request_policy.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stringprintf.h"
9 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_set.h" 13 #include "chrome/common/extensions/extension_set.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
16 19
17 // static 20 // static
18 bool ExtensionResourceRequestPolicy::CanRequestResource( 21 bool ExtensionResourceRequestPolicy::CanRequestResource(
19 const GURL& resource_url, 22 const GURL& resource_url,
20 const WebKit::WebFrame* frame, 23 WebKit::WebFrame* frame,
21 const ExtensionSet* loaded_extensions) { 24 const ExtensionSet* loaded_extensions) {
22 CHECK(resource_url.SchemeIs(chrome::kExtensionScheme)); 25 CHECK(resource_url.SchemeIs(chrome::kExtensionScheme));
23 26
24 const Extension* extension = 27 const Extension* extension =
25 loaded_extensions->GetExtensionOrAppByURL(ExtensionURLInfo(resource_url)); 28 loaded_extensions->GetExtensionOrAppByURL(ExtensionURLInfo(resource_url));
26 if (!extension) { 29 if (!extension) {
27 // Allow the load in the case of a non-existent extension. We'll just get a 30 // Allow the load in the case of a non-existent extension. We'll just get a
28 // 404 from the browser process. 31 // 404 from the browser process.
29 return true; 32 return true;
30 } 33 }
(...skipping 21 matching lines...) Expand all
52 // - chrome-extension:// (for legacy reasons -- some extensions interop) 55 // - chrome-extension:// (for legacy reasons -- some extensions interop)
53 // - devtools (chrome-extension:// URLs are loaded into frames of devtools 56 // - devtools (chrome-extension:// URLs are loaded into frames of devtools
54 // to support the devtools extension APIs) 57 // to support the devtools extension APIs)
55 if (!CommandLine::ForCurrentProcess()->HasSwitch( 58 if (!CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kDisableExtensionsResourceWhitelist) && 59 switches::kDisableExtensionsResourceWhitelist) &&
57 !frame_url.is_empty() && 60 !frame_url.is_empty() &&
58 !frame_url.SchemeIs(chrome::kExtensionScheme) && 61 !frame_url.SchemeIs(chrome::kExtensionScheme) &&
59 !(page_url.SchemeIs(chrome::kChromeDevToolsScheme) && 62 !(page_url.SchemeIs(chrome::kChromeDevToolsScheme) &&
60 !extension->devtools_url().is_empty()) && 63 !extension->devtools_url().is_empty()) &&
61 !extension->IsResourceWebAccessible(resource_url.path())) { 64 !extension->IsResourceWebAccessible(resource_url.path())) {
62 LOG(ERROR) << "Denying load of " << resource_url.spec() << " which " 65 std::string message = base::StringPrintf(
63 << "is not a web accessible resource."; 66 "Denying load of %s. Resources must be listed in the "
67 "web_accessible_resources manifest key in order to be loaded by web "
68 "pages.",
69 resource_url.spec().c_str());
70 frame->addMessageToConsole(
71 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError,
72 WebKit::WebString::fromUTF8(message)));
64 return false; 73 return false;
65 } 74 }
66 75
67 return true; 76 return true;
68 } 77 }
69 78
70 ExtensionResourceRequestPolicy::ExtensionResourceRequestPolicy() { 79 ExtensionResourceRequestPolicy::ExtensionResourceRequestPolicy() {
71 } 80 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_resource_request_policy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698