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

Unified Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 6894045: wip (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/extension_dispatcher.cc
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index c1f2a6e3e00d091d3501ca0e4281c9a130a41cf6..e9e469825a28fbf588ae0526b016e55cdce4b99c 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -17,15 +17,17 @@
#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/WebSecurityPolicy.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "v8/include/v8.h"
+using WebKit::WebSecurityPolicy;
+
namespace {
static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
}
-using WebKit::WebFrame;
-
ExtensionDispatcher::ExtensionDispatcher() {
std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType);
@@ -54,8 +56,7 @@ bool ExtensionDispatcher::OnControlMessageReceived(
IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist,
OnSetScriptingWhitelist)
IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePageActions, OnPageActionsUpdated)
- IPC_MESSAGE_HANDLER(ExtensionMsg_SetAPIPermissions, OnSetAPIPermissions)
- IPC_MESSAGE_HANDLER(ExtensionMsg_SetHostPermissions, OnSetHostPermissions)
+ IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension)
IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -78,8 +79,8 @@ void ExtensionDispatcher::WebKitInitialized() {
RegisterExtension(ExtensionProcessBindings::Get(this), true);
RegisterExtension(BaseJsV8Extension::Get(), true);
RegisterExtension(JsonSchemaJsV8Extension::Get(), true);
- RegisterExtension(EventBindings::Get(), true);
- RegisterExtension(RendererExtensionBindings::Get(), true);
+ RegisterExtension(EventBindings::Get(this), true);
+ RegisterExtension(RendererExtensionBindings::Get(this), true);
RegisterExtension(ExtensionApiTestV8Extension::Get(), true);
}
@@ -117,7 +118,7 @@ void ExtensionDispatcher::IdleNotification() {
void ExtensionDispatcher::OnSetFunctionNames(
const std::vector<std::string>& names) {
- ExtensionProcessBindings::SetFunctionNames(names);
+ function_names_ = names;
}
void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id,
@@ -160,13 +161,22 @@ void ExtensionDispatcher::OnSetScriptingWhitelist(
void ExtensionDispatcher::OnPageActionsUpdated(
const std::string& extension_id,
const std::vector<std::string>& page_actions) {
- ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
+ if (!page_actions.empty()) {
+ page_action_ids_[extension_id] = page_actions;
+ } else {
+ if (page_action_ids_.find(extension_id) != page_action_ids_.end())
+ page_action_ids_.erase(extension_id);
+ }
}
-void ExtensionDispatcher::OnSetAPIPermissions(
- const std::string& extension_id,
- const std::set<std::string>& permissions) {
- ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions);
+bool ExtensionDispatcher::IsExtensionActive(const std::string& extension_id) {
+ return active_extension_ids_.find(extension_id) !=
+ active_extension_ids_.end();
+}
+
+void ExtensionDispatcher::OnActivateExtension(
+ const std::string& extension_id) {
+ active_extension_ids_.insert(extension_id);
// This is called when starting a new extension page, so start the idle
// handler ticking.
@@ -174,11 +184,44 @@ void ExtensionDispatcher::OnSetAPIPermissions(
kInitialExtensionIdleHandlerDelayS);
UpdateActiveExtensions();
-}
-void ExtensionDispatcher::OnSetHostPermissions(
- const GURL& extension_url, const std::vector<URLPattern>& permissions) {
- ExtensionProcessBindings::SetHostPermissions(extension_url, permissions);
+ const Extension* extension =
+ extension_dispatcher_->extensions()->GetByID(extension_id);
+ if (!extension)
+ return;
+
+ if (extension->HasApiPermission(Extension::kManagementPermission)) {
+ WebSecurityPolicy::addOriginAccessWhitelistEntry(
+ extension->url(),
+ WebKit::WebString::fromUTF8(chrome::kChromeUIScheme),
+ WebKit::WebString::fromUTF8(chrome::kChromeUIExtensionIconHost),
+ false);
+ }
+
+ SetHostPermissions(extension->url(),
+ extension->host_permissions());
+}
+
+void ExtensionDispatcher::SetHostPermissions(
+ const GURL& extension_url,
+ const std::vector<URLPattern>& permissions) {
+ for (size_t i = 0; i < permissions.size(); ++i) {
+ const char* schemes[] = {
+ chrome::kHttpScheme,
+ chrome::kHttpsScheme,
+ chrome::kFileScheme,
+ chrome::kChromeUIScheme,
+ };
+ for (size_t j = 0; j < arraysize(schemes); ++j) {
+ if (permissions[i].MatchesScheme(schemes[j])) {
+ WebSecurityPolicy::addOriginAccessWhitelistEntry(
+ extension_url,
+ WebKit::WebString::fromUTF8(schemes[j]),
+ WebKit::WebString::fromUTF8(permissions[i].host()),
+ permissions[i].match_subdomains());
+ }
+ }
+ }
}
void ExtensionDispatcher::OnUpdateUserScripts(
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.h ('k') | chrome/renderer/extensions/extension_process_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698