| 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/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_constants.h" |
| 14 #include "extensions/common/manifest_handlers/icons_handler.h" | 14 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 15 #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" | 16 #include "extensions/common/manifest_handlers/webview_info.h" |
| 17 #include "extensions/renderer/dispatcher.h" | 17 #include "extensions/renderer/dispatcher.h" |
| 18 #include "extensions/renderer/renderer_extension_registry.h" | 18 #include "extensions/renderer/renderer_extension_registry.h" |
| 19 #include "third_party/WebKit/public/platform/URLConversion.h" | 19 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 21 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
| 22 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 22 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 24 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 #include "ui/base/page_transition_types.h" | 25 #include "ui/base/page_transition_types.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 #include "url/origin.h" | 27 #include "url/origin.h" |
| 28 | 28 |
| 29 namespace extensions { | 29 namespace extensions { |
| 30 | 30 |
| 31 ResourceRequestPolicy::ResourceRequestPolicy(Dispatcher* dispatcher) | 31 ResourceRequestPolicy::ResourceRequestPolicy(Dispatcher* dispatcher) |
| 32 : dispatcher_(dispatcher) {} | 32 : dispatcher_(dispatcher) {} |
| 33 | 33 |
| 34 // This method does a security check whether chrome-extension:// URLs can be | 34 // This method does a security check whether chrome-extension:// URLs can be |
| 35 // requested by the renderer. Since this is in an untrusted process, the browser | 35 // requested by the renderer. Since this is in an untrusted process, the browser |
| 36 // has a similar check to enforce the policy, in case this process is exploited. | 36 // has a similar check to enforce the policy, in case this process is exploited. |
| 37 // If you are changing this function, ensure equivalent checks are added to | 37 // If you are changing this function, ensure equivalent checks are added to |
| 38 // extension_protocols.cc's AllowExtensionResourceLoad. | 38 // extension_protocols.cc's AllowExtensionResourceLoad. |
| 39 bool ResourceRequestPolicy::CanRequestResource( | 39 bool ResourceRequestPolicy::CanRequestResource( |
| 40 const GURL& resource_url, | 40 const GURL& resource_url, |
| 41 blink::WebFrame* frame, | 41 blink::WebLocalFrame* frame, |
| 42 ui::PageTransition transition_type) { | 42 ui::PageTransition transition_type) { |
| 43 CHECK(resource_url.SchemeIs(kExtensionScheme)); | 43 CHECK(resource_url.SchemeIs(kExtensionScheme)); |
| 44 | 44 |
| 45 const Extension* extension = | 45 const Extension* extension = |
| 46 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(resource_url); | 46 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(resource_url); |
| 47 if (!extension) { | 47 if (!extension) { |
| 48 // Allow the load in the case of a non-existent extension. We'll just get a | 48 // Allow the load in the case of a non-existent extension. We'll just get a |
| 49 // 404 from the browser process. | 49 // 404 from the browser process. |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError, | 108 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError, |
| 109 blink::WebString::fromUTF8(message))); | 109 blink::WebString::fromUTF8(message))); |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace extensions | 117 } // namespace extensions |
| OLD | NEW |