OLD | NEW |
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/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 "base/stringprintf.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_set.h" | 13 #include "chrome/common/extensions/extension_set.h" |
| 14 #include "content/public/common/page_transition_types.h" |
14 #include "googleurl/src/gurl.h" | 15 #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/WebConsoleMessage.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #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/WebFrame.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
22 // static | 23 // static |
23 bool ResourceRequestPolicy::CanRequestResource( | 24 bool ResourceRequestPolicy::CanRequestResource( |
24 const GURL& resource_url, | 25 const GURL& resource_url, |
25 WebKit::WebFrame* frame, | 26 WebKit::WebFrame* frame, |
| 27 content::PageTransition transition_type, |
26 const ExtensionSet* loaded_extensions) { | 28 const ExtensionSet* loaded_extensions) { |
27 CHECK(resource_url.SchemeIs(chrome::kExtensionScheme)); | 29 CHECK(resource_url.SchemeIs(chrome::kExtensionScheme)); |
28 | 30 |
29 const Extension* extension = | 31 const Extension* extension = |
30 loaded_extensions->GetExtensionOrAppByURL(ExtensionURLInfo(resource_url)); | 32 loaded_extensions->GetExtensionOrAppByURL(ExtensionURLInfo(resource_url)); |
31 if (!extension) { | 33 if (!extension) { |
32 // Allow the load in the case of a non-existent extension. We'll just get a | 34 // Allow the load in the case of a non-existent extension. We'll just get a |
33 // 404 from the browser process. | 35 // 404 from the browser process. |
34 return true; | 36 return true; |
35 } | 37 } |
(...skipping 23 matching lines...) Expand all Loading... |
59 // - empty origin (needed for some edge cases when we have empty origins) | 61 // - empty origin (needed for some edge cases when we have empty origins) |
60 bool is_empty_origin = frame_url.is_empty(); | 62 bool is_empty_origin = frame_url.is_empty(); |
61 // - extensions requesting their own resources (frame_url check is for | 63 // - extensions requesting their own resources (frame_url check is for |
62 // images, page_url check is for iframes) | 64 // images, page_url check is for iframes) |
63 bool is_own_resource = frame_url.GetOrigin() == extension->url() || | 65 bool is_own_resource = frame_url.GetOrigin() == extension->url() || |
64 page_url.GetOrigin() == extension->url(); | 66 page_url.GetOrigin() == extension->url(); |
65 // - devtools (chrome-extension:// URLs are loaded into frames of devtools | 67 // - devtools (chrome-extension:// URLs are loaded into frames of devtools |
66 // to support the devtools extension APIs) | 68 // to support the devtools extension APIs) |
67 bool is_dev_tools = page_url.SchemeIs(chrome::kChromeDevToolsScheme) && | 69 bool is_dev_tools = page_url.SchemeIs(chrome::kChromeDevToolsScheme) && |
68 !extension->devtools_url().is_empty(); | 70 !extension->devtools_url().is_empty(); |
| 71 bool transition_allowed = |
| 72 !content::PageTransitionIsWebTriggerable(transition_type); |
69 | 73 |
70 if (!is_empty_origin && !is_own_resource && !is_dev_tools) { | 74 if (!is_empty_origin && !is_own_resource && |
| 75 !is_dev_tools && !transition_allowed) { |
71 std::string message = base::StringPrintf( | 76 std::string message = base::StringPrintf( |
72 "Denying load of %s. Resources must be listed in the " | 77 "Denying load of %s. Resources must be listed in the " |
73 "web_accessible_resources manifest key in order to be loaded by " | 78 "web_accessible_resources manifest key in order to be loaded by " |
74 "pages outside the extension.", | 79 "pages outside the extension.", |
75 resource_url.spec().c_str()); | 80 resource_url.spec().c_str()); |
76 frame->addMessageToConsole( | 81 frame->addMessageToConsole( |
77 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError, | 82 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError, |
78 WebKit::WebString::fromUTF8(message))); | 83 WebKit::WebString::fromUTF8(message))); |
79 return false; | 84 return false; |
80 } | 85 } |
(...skipping 21 matching lines...) Expand all Loading... |
102 return false; | 107 return false; |
103 } | 108 } |
104 | 109 |
105 return true; | 110 return true; |
106 } | 111 } |
107 | 112 |
108 ResourceRequestPolicy::ResourceRequestPolicy() { | 113 ResourceRequestPolicy::ResourceRequestPolicy() { |
109 } | 114 } |
110 | 115 |
111 } // namespace extensions | 116 } // namespace extensions |
OLD | NEW |