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

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

Issue 10821133: Move c/r/extensions/* into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq Created 8 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/extension_resource_request_policy.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/stringprintf.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_set.h"
14 #include "googleurl/src/gurl.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
19
20 using extensions::Extension;
21
22 // static
23 bool ExtensionResourceRequestPolicy::CanRequestResource(
24 const GURL& resource_url,
25 WebKit::WebFrame* frame,
26 const ExtensionSet* loaded_extensions) {
27 CHECK(resource_url.SchemeIs(chrome::kExtensionScheme));
28
29 const Extension* extension =
30 loaded_extensions->GetExtensionOrAppByURL(ExtensionURLInfo(resource_url));
31 if (!extension) {
32 // Allow the load in the case of a non-existent extension. We'll just get a
33 // 404 from the browser process.
34 return true;
35 }
36
37 // Disallow loading of packaged resources for hosted apps. We don't allow
38 // hybrid hosted/packaged apps. The one exception is access to icons, since
39 // some extensions want to be able to do things like create their own
40 // launchers.
41 std::string resource_root_relative_path =
42 resource_url.path().empty() ? "" : resource_url.path().substr(1);
43 if (extension->is_hosted_app() &&
44 !extension->icons().ContainsPath(resource_root_relative_path)) {
45 LOG(ERROR) << "Denying load of " << resource_url.spec() << " from "
46 << "hosted app.";
47 return false;
48 }
49
50 // Disallow loading of extension resources which are not explicitely listed
51 // as web accessible if the manifest version is 2 or greater.
52 if (!extension->IsResourceWebAccessible(resource_url.path()) &&
53 !CommandLine::ForCurrentProcess()->HasSwitch(
54 switches::kDisableExtensionsResourceWhitelist)) {
55 GURL frame_url = frame->document().url();
56 GURL page_url = frame->top()->document().url();
57
58 // Exceptions are:
59 // - empty origin (needed for some edge cases when we have empty origins)
60 bool is_empty_origin = frame_url.is_empty();
61 // - extensions requesting their own resources (frame_url check is for
62 // images, page_url check is for iframes)
63 bool is_own_resource = frame_url.GetOrigin() == extension->url() ||
64 page_url.GetOrigin() == extension->url();
65 // - devtools (chrome-extension:// URLs are loaded into frames of devtools
66 // to support the devtools extension APIs)
67 bool is_dev_tools = page_url.SchemeIs(chrome::kChromeDevToolsScheme) &&
68 !extension->devtools_url().is_empty();
69
70 if (!is_empty_origin && !is_own_resource && !is_dev_tools) {
71 std::string message = base::StringPrintf(
72 "Denying load of %s. Resources must be listed in the "
73 "web_accessible_resources manifest key in order to be loaded by "
74 "pages outside the extension.",
75 resource_url.spec().c_str());
76 frame->addMessageToConsole(
77 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError,
78 WebKit::WebString::fromUTF8(message)));
79 return false;
80 }
81 }
82
83 return true;
84 }
85
86 // static
87 bool ExtensionResourceRequestPolicy::CanRequestExtensionResourceScheme(
88 const GURL& resource_url,
89 WebKit::WebFrame* frame) {
90 CHECK(resource_url.SchemeIs(chrome::kExtensionResourceScheme));
91
92 GURL frame_url = frame->document().url();
93 if (!frame_url.is_empty() &&
94 !frame_url.SchemeIs(chrome::kExtensionScheme)) {
95 std::string message = base::StringPrintf(
96 "Denying load of %s. chrome-extension-resources:// can only be "
97 "loaded from extensions.",
98 resource_url.spec().c_str());
99 frame->addMessageToConsole(
100 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError,
101 WebKit::WebString::fromUTF8(message)));
102 return false;
103 }
104
105 return true;
106 }
107
108 ExtensionResourceRequestPolicy::ExtensionResourceRequestPolicy() {
109 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_resource_request_policy.h ('k') | chrome/renderer/extensions/json_schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698