diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-30 17:03:43 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-30 17:03:43 +0000 |
commit | c6e27b9e28d46db4516fb38a9db1cecef19f5a94 (patch) | |
tree | d6ec9d9a2c409ae57ad96ac9079f39376f75bbbb /chrome/renderer/extensions | |
parent | 4d46aaaa5528cbcfd76e1c4c86f02f63bee8848b (diff) | |
download | chromium_src-c6e27b9e28d46db4516fb38a9db1cecef19f5a94.zip chromium_src-c6e27b9e28d46db4516fb38a9db1cecef19f5a94.tar.gz chromium_src-c6e27b9e28d46db4516fb38a9db1cecef19f5a94.tar.bz2 |
Implement the new WebPermissionClient interface in Chrome code to get rid of all the awkward calls to ContentRendererClient.
Review URL: http://codereview.chromium.org/6905117
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.cc | 66 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.h | 8 |
2 files changed, 49 insertions, 25 deletions
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index 9cb1c9c..fa3bc54 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -18,8 +18,11 @@ #include "chrome/renderer/extensions/renderer_extension_bindings.h" #include "chrome/renderer/extensions/user_script_slave.h" #include "content/renderer/render_thread.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" #include "v8/include/v8.h" namespace { @@ -27,7 +30,10 @@ static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; } +using WebKit::WebDataSource; +using WebKit::WebFrame; using WebKit::WebSecurityPolicy; +using WebKit::WebString; ExtensionDispatcher::ExtensionDispatcher() { std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( @@ -85,24 +91,6 @@ void ExtensionDispatcher::WebKitInitialized() { RegisterExtension(ExtensionApiTestV8Extension::Get(), true); } -bool ExtensionDispatcher::AllowScriptExtension( - const std::string& v8_extension_name, - const GURL& url, - int extension_group) { - // If the V8 extension is not restricted, allow it to run anywhere. - if (!restricted_v8_extensions_.count(v8_extension_name)) - return true; - - // Extension-only bindings should be restricted to content scripts and - // extension-blessed URLs. - if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || - extensions_.ExtensionBindingsAllowed(url)) { - return true; - } - - return false; -} - void ExtensionDispatcher::IdleNotification() { if (is_extension_process_) { // Dampen the forced delay as well if the extension stays idle for long @@ -177,6 +165,40 @@ bool ExtensionDispatcher::IsExtensionActive(const std::string& extension_id) { active_extension_ids_.end(); } +bool ExtensionDispatcher::AllowScriptExtension( + WebFrame* frame, + const std::string& v8_extension_name, + int extension_group) { + // NULL in unit tests. + if (!RenderThread::current()) + return true; + + // If we don't know about it, it was added by WebCore, so we should allow it. + if (!RenderThread::current()->IsRegisteredExtension(v8_extension_name)) + return true; + + // If the V8 extension is not restricted, allow it to run anywhere. + if (!restricted_v8_extensions_.count(v8_extension_name)) + return true; + + // Note: we prefer the provisional URL here instead of the document URL + // because we might be currently loading an URL into a blank page. + // See http://code.google.com/p/chromium/issues/detail?id=10924 + WebDataSource* ds = frame->provisionalDataSource(); + if (!ds) + ds = frame->dataSource(); + + // Extension-only bindings should be restricted to content scripts and + // extension-blessed URLs. + if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || + extensions_.ExtensionBindingsAllowed(ds->request().url())) { + return true; + } + + return false; + +} + void ExtensionDispatcher::OnActivateExtension( const std::string& extension_id) { active_extension_ids_.insert(extension_id); @@ -195,8 +217,8 @@ void ExtensionDispatcher::OnActivateExtension( if (extension->HasApiPermission(Extension::kManagementPermission)) { WebSecurityPolicy::addOriginAccessWhitelistEntry( extension->url(), - WebKit::WebString::fromUTF8(chrome::kChromeUIScheme), - WebKit::WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), + WebString::fromUTF8(chrome::kChromeUIScheme), + WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), false); } @@ -218,8 +240,8 @@ void ExtensionDispatcher::SetHostPermissions( if (permissions[i].MatchesScheme(schemes[j])) { WebSecurityPolicy::addOriginAccessWhitelistEntry( extension_url, - WebKit::WebString::fromUTF8(schemes[j]), - WebKit::WebString::fromUTF8(permissions[i].host()), + WebString::fromUTF8(schemes[j]), + WebString::fromUTF8(permissions[i].host()), permissions[i].match_subdomains()); } } diff --git a/chrome/renderer/extensions/extension_dispatcher.h b/chrome/renderer/extensions/extension_dispatcher.h index 282cab2..1710745 100644 --- a/chrome/renderer/extensions/extension_dispatcher.h +++ b/chrome/renderer/extensions/extension_dispatcher.h @@ -53,15 +53,17 @@ class ExtensionDispatcher : public RenderProcessObserver { bool IsExtensionActive(const std::string& extension_id); + // See WebKit::WebPermissionClient::allowScriptExtension + bool AllowScriptExtension(WebKit::WebFrame* frame, + const std::string& v8_extension_name, + int extension_group); + private: friend class RenderViewTest; // RenderProcessObserver implementation: virtual bool OnControlMessageReceived(const IPC::Message& message); virtual void WebKitInitialized(); - virtual bool AllowScriptExtension(const std::string& v8_extension_name, - const GURL& url, - int extension_group); virtual void IdleNotification(); void OnMessageInvoke(const std::string& extension_id, |