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

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: aa comments 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..34dfc8d7962010f3a9c7f01f82a7038cd9d5e858 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;
@@ -91,7 +85,6 @@ bool ExtensionDispatcher::OnControlMessageReceived(
IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist,
OnSetScriptingWhitelist)
IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension)
- IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication)
IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions)
IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts)
IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI)
@@ -110,15 +103,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);
@@ -261,12 +255,6 @@ void ExtensionDispatcher::OnSetScriptingWhitelist(
Extension::SetScriptingWhitelist(extension_ids);
}
-bool ExtensionDispatcher::IsApplicationActive(
- const std::string& extension_id) const {
- return active_application_ids_.find(extension_id) !=
- active_application_ids_.end();
-}
-
bool ExtensionDispatcher::IsExtensionActive(
const std::string& extension_id) const {
return active_extension_ids_.find(extension_id) !=
@@ -311,42 +299,42 @@ 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()) {
- std::string extension_id = GetExtensionID(frame, world_id);
- const Extension* extension = extensions_.GetByID(extension_id);
- if (!extension) {
- // This can happen when a resource is blocked due to CSP; a valid
- // chrome-extension:// URL is navigated to, so it passes the initial
- // checks, but the URL gets changed to "chrome-extension://invalid"
- // afterwards (see chrome_content_renderer_client.cc). An extension
- // page still gets loaded, just for the extension with ID "invalid",
- // which of course isn't found so GetById extension will be NULL.
- //
- // Reference: http://crbug.com/111614.
- CHECK_EQ("invalid", extension_id);
- return false;
+ GetContextType(extension_group, frame);
+
+ std::string custom_binding_api_name =
Aaron Boodman 2012/02/29 01:03:58 If you make the change I suggested in schema_gener
not at google - send to devlin 2012/03/05 07:46:54 Done... kinda. I consolidated all the logic in Ex
+ custom_bindings_util::GetAPIName(v8_extension_name);
+ if (!custom_binding_api_name.empty()) {
+ switch (context_type) {
+ case ChromeV8Context::PRIVILEGED:
+ case ChromeV8Context::CONTENT_SCRIPT:
+ case ChromeV8Context::UNPRIVILEGED: {
+ std::string extension_id = GetExtensionID(frame, world_id);
+ const Extension* extension = extensions_.GetByID(extension_id);
+ if (!extension) {
+ // This can happen when a resource is blocked due to CSP; a valid
+ // chrome-extension:// URL is navigated to, so it passes the initial
+ // checks, but the URL gets changed to "chrome-extension://invalid"
+ // afterwards (see chrome_content_renderer_client.cc). An extension
+ // page still gets loaded, just for the extension with ID "invalid",
+ // which of course isn't found so GetById extension will be NULL.
+ //
+ // Reference: http://crbug.com/111614.
+ CHECK_EQ("invalid", extension_id);
+ return false;
+ }
+ return custom_bindings_util::AllowAPIInjection(
+ custom_binding_api_name, *extension, context_type);
}
- return custom_bindings_util::AllowAPIInjection(
- custom_binding_api_name, *extension, this);
- }
- return true;
+ case ChromeV8Context::WEB_PAGE:
+ return ExtensionAPI::GetInstance()->MatchesURL(
+ custom_binding_api_name,
+ UserScriptSlave::GetDataSourceURLForFrame(frame));
+ }
}
- return false;
+ return context_type != ChromeV8Context::WEB_PAGE;
}
void ExtensionDispatcher::DidCreateScriptContext(
@@ -356,8 +344,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());
@@ -413,11 +400,6 @@ bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) {
return id == test_extension_id_;
}
-void ExtensionDispatcher::OnActivateApplication(
- const std::string& extension_id) {
- active_application_ids_.insert(extension_id);
-}
-
void ExtensionDispatcher::OnActivateExtension(
const std::string& extension_id) {
active_extension_ids_.insert(extension_id);
@@ -539,3 +521,21 @@ void ExtensionDispatcher::OnUsingWebRequestAPI(
webrequest_adblock_plus_ = adblock_plus;
webrequest_other_ = other;
}
+
+ChromeV8Context::ContextType ExtensionDispatcher::GetContextType(
Aaron Boodman 2012/02/29 01:03:58 Naming suggestion: ClassifyJavaScriptContext ?
not at google - send to devlin 2012/03/05 07:46:54 Done.
+ int extension_group, WebFrame* frame) {
+ if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS)
+ return ChromeV8Context::CONTENT_SCRIPT;
+
+ ExtensionURLInfo url_info(frame->document().securityOrigin(),
+ UserScriptSlave::GetDataSourceURLForFrame(frame));
+
+ const Extension* extension = extensions_.GetExtensionOrAppByURL(url_info);
+ if (extension && IsExtensionActive(extension->id()))
+ return ChromeV8Context::PRIVILEGED;
+
+ if (extensions_.ExtensionBindingsAllowed(url_info))
+ return ChromeV8Context::UNPRIVILEGED;
+
+ return ChromeV8Context::WEB_PAGE;
+}

Powered by Google App Engine
This is Rietveld 408576698