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

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

Issue 10827107: Allow transitions to WebUI pages which are extension urls (new tab page is the relevant example). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
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 "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 using extensions::Extension; 21 using extensions::Extension;
21 22
22 // static 23 // static
23 bool ExtensionResourceRequestPolicy::CanRequestResource( 24 bool ExtensionResourceRequestPolicy::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
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();
69 71 bool transition_allowed =
70 if (!is_empty_origin && !is_own_resource && !is_dev_tools) { 72 !content::PageTransitionIsWebTriggerable(transition_type);
73 if (!is_empty_origin && !is_own_resource &&
74 !is_dev_tools && !transition_allowed) {
71 std::string message = base::StringPrintf( 75 std::string message = base::StringPrintf(
72 "Denying load of %s. Resources must be listed in the " 76 "Denying load of %s. Resources must be listed in the "
73 "web_accessible_resources manifest key in order to be loaded by " 77 "web_accessible_resources manifest key in order to be loaded by "
74 "pages outside the extension.", 78 "pages outside the extension.",
75 resource_url.spec().c_str()); 79 resource_url.spec().c_str());
76 frame->addMessageToConsole( 80 frame->addMessageToConsole(
77 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError, 81 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError,
78 WebKit::WebString::fromUTF8(message))); 82 WebKit::WebString::fromUTF8(message)));
79 return false; 83 return false;
80 } 84 }
(...skipping 19 matching lines...) Expand all
100 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError, 104 WebKit::WebConsoleMessage(WebKit::WebConsoleMessage::LevelError,
101 WebKit::WebString::fromUTF8(message))); 105 WebKit::WebString::fromUTF8(message)));
102 return false; 106 return false;
103 } 107 }
104 108
105 return true; 109 return true;
106 } 110 }
107 111
108 ExtensionResourceRequestPolicy::ExtensionResourceRequestPolicy() { 112 ExtensionResourceRequestPolicy::ExtensionResourceRequestPolicy() {
109 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698