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

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

Issue 9903010: Extract ExtensionRequestSender from SchemaGeneratedBindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 years, 9 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 aae2e68d20db774d14649a2c576232337fca4089..9966e9f87e5e65889ff3d25bf5f971186c78a34b 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -24,6 +24,7 @@
#include "chrome/renderer/extensions/experimental.socket_custom_bindings.h"
#include "chrome/renderer/extensions/extension_custom_bindings.h"
#include "chrome/renderer/extensions/extension_groups.h"
+#include "chrome/renderer/extensions/extension_request_sender.h"
#include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
#include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
#include "chrome/renderer/extensions/i18n_custom_bindings.h"
@@ -153,6 +154,7 @@ ExtensionDispatcher::ExtensionDispatcher()
}
user_script_slave_.reset(new UserScriptSlave(&extensions_));
+ request_sender_.reset(new ExtensionRequestSender(this, &v8_context_set_));
PopulateSourceMap();
PopulateLazyBindingsMap();
}
@@ -361,7 +363,8 @@ void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
module_system->RegisterNativeHandler("miscellaneous_bindings",
scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
module_system->RegisterNativeHandler("schema_generated_bindings",
- scoped_ptr<NativeHandler>(new SchemaGeneratedBindings(this)));
+ scoped_ptr<NativeHandler>(
+ new SchemaGeneratedBindings(this, request_sender_.get())));
// Custom bindings.
module_system->RegisterNativeHandler("app",
@@ -756,3 +759,46 @@ Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext(
return Feature::UNSPECIFIED_CONTEXT;
}
+
+void ExtensionDispatcher::OnExtensionResponse(int request_id,
+ bool success,
+ const std::string& response,
+ const std::string& error) {
+ request_sender_->HandleResponse(request_id, success, response, error);
+}
+
+bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI(
+ const std::string& function_name) const {
+ ChromeV8Context* context = v8_context_set().GetCurrent();
+ if (!context) {
+ DLOG(ERROR) << "Not in a v8::Context";
+ return false;
+ }
+
+ const ::Extension* extension = NULL;
+ if (!context->extension_id().empty()) {
+ extension = extensions()->GetByID(context->extension_id());
+ }
+
+ if (!extension || !extension->HasAPIPermission(function_name)) {
+ static const char kMessage[] =
+ "You do not have permission to use '%s'. Be sure to declare"
+ " in your manifest what permissions you need.";
+ std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
+ v8::ThrowException(
+ v8::Exception::Error(v8::String::New(error_msg.c_str())));
+ return false;
+ }
+
+ if (!IsExtensionActive(extension->id()) &&
+ ExtensionAPI::GetInstance()->IsPrivileged(function_name)) {
+ static const char kMessage[] =
+ "%s can only be used in an extension process.";
+ std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
+ v8::ThrowException(
+ v8::Exception::Error(v8::String::New(error_msg.c_str())));
+ return false;
+ }
+
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698