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

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

Issue 9460002: Convert app_bindings.js to the schema_generated_bindings.js infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 01a5af374bb87eddf182cf61f93e76b9a06644e9..982616c41d75f7433cbb8e9602ffa98a8a1b55fb 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -7,12 +7,12 @@
#include "base/command_line.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/extension_api.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_permission_set.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/chrome_render_process_observer.h"
-#include "chrome/renderer/extensions/app_bindings.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/chrome_v8_extension.h"
#include "chrome/renderer/extensions/custom_bindings_util.h"
@@ -39,12 +39,6 @@ namespace {
static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000;
static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000;
-ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) {
- if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS)
- return ChromeV8Context::CONTENT_SCRIPT;
- return ChromeV8Context::OTHER;
-}
-
}
using namespace extensions;
@@ -110,15 +104,16 @@ void ExtensionDispatcher::WebKitInitialized() {
RenderThread::Get(), &RenderThread::IdleHandler);
}
- RegisterExtension(new AppBindings(this), false);
+ // Unrestricted extension-related v8-extensions.
+ RegisterExtension(EventBindings::Get(this), false);
+ RegisterExtension(SchemaGeneratedBindings::Get(this), false);
+ RegisterExtension(new ChromeV8Extension(
+ "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), false);
+ // TODO(kalman): move this to the custom_bindings infrastructure.
RegisterExtension(new WebstoreBindings(this), false);
- // Add v8 extensions related to chrome extensions.
- RegisterExtension(new ChromeV8Extension(
- "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true);
- RegisterExtension(EventBindings::Get(this), true);
+ // Permissions-checked extension-related v8-extensions.
RegisterExtension(MiscellaneousBindings::Get(this), true);
- RegisterExtension(SchemaGeneratedBindings::Get(this), true);
RegisterExtension(new ChromeV8Extension(
"extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL), true);
@@ -311,20 +306,18 @@ bool ExtensionDispatcher::AllowScriptExtension(
if (!restricted_v8_extensions_.count(v8_extension_name))
return true;
- // Extension-only bindings should be restricted to content scripts and
- // extension-blessed URLs.
ChromeV8Context::ContextType context_type =
- ExtensionGroupToContextType(extension_group);
-
- if (context_type == ChromeV8Context::CONTENT_SCRIPT ||
- extensions_.ExtensionBindingsAllowed(ExtensionURLInfo(
- frame->document().securityOrigin(),
- UserScriptSlave::GetDataSourceURLForFrame(frame)))) {
- // If the extension is a custom API binding, only allow if the extension
- // has permission to use the API.
- std::string custom_binding_api_name =
- custom_bindings_util::GetAPIName(v8_extension_name);
- if (!custom_binding_api_name.empty()) {
+ GetContextType(extension_group, frame);
+
+ std::string custom_binding_api_name =
+ custom_bindings_util::GetAPIName(v8_extension_name);
+ if (!custom_binding_api_name.empty()) {
+ // Extension is a custom API binding, so do API-based permissions checking.
+ if (context_type == ChromeV8Context::UNPRIVILEGED) {
+ GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame);
+ return ExtensionAPI::GetInstance()->MatchesURL(
+ custom_binding_api_name, frame_url);
+ } else {
std::string extension_id = GetExtensionID(frame, world_id);
const Extension* extension = extensions_.GetByID(extension_id);
if (!extension) {
@@ -342,11 +335,11 @@ bool ExtensionDispatcher::AllowScriptExtension(
return custom_bindings_util::AllowAPIInjection(
custom_binding_api_name, *extension, this);
}
-
- return true;
}
- return false;
+ // Extension-only bindings should be restricted to content scripts and
+ // extension-blessed URLs.
+ return context_type != ChromeV8Context::UNPRIVILEGED;
koz (OOO until 15th September) 2012/02/27 03:04:11 Invert this conditional and remove this comment?
not at google - send to devlin 2012/02/27 04:44:24 Right. Good point.
}
void ExtensionDispatcher::DidCreateScriptContext(
@@ -356,8 +349,7 @@ void ExtensionDispatcher::DidCreateScriptContext(
v8_context,
frame,
GetExtensionID(frame, world_id),
- ExtensionGroupToContextType(
- hack_DidCreateScriptContext_extension_group));
+ GetContextType(hack_DidCreateScriptContext_extension_group, frame));
v8_context_set_.Add(context);
const Extension* extension = extensions_.GetByID(context->extension_id());
@@ -539,3 +531,17 @@ void ExtensionDispatcher::OnUsingWebRequestAPI(
webrequest_adblock_plus_ = adblock_plus;
webrequest_other_ = other;
}
+
+ChromeV8Context::ContextType ExtensionDispatcher::GetContextType(
+ int extension_group, WebFrame* frame) {
+ if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS)
+ return ChromeV8Context::CONTENT_SCRIPT;
+
+ if (extensions_.ExtensionBindingsAllowed(ExtensionURLInfo(
+ frame->document().securityOrigin(),
+ UserScriptSlave::GetDataSourceURLForFrame(frame)))) {
+ return ChromeV8Context::BLESSED;
koz (OOO until 15th September) 2012/02/27 03:04:11 Nice.
not at google - send to devlin 2012/02/27 04:44:24 Cheers.
+ }
+
+ return ChromeV8Context::UNPRIVILEGED;
+}

Powered by Google App Engine
This is Rietveld 408576698