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

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

Issue 159067: Add API: getBackgroundPageView and getToolstripViews (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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_process_bindings.cc
===================================================================
--- chrome/renderer/extensions/extension_process_bindings.cc (revision 24584)
+++ chrome/renderer/extensions/extension_process_bindings.cc (working copy)
@@ -9,6 +9,7 @@
#include "chrome/common/extensions/url_pattern.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
+#include "chrome/renderer/extension_groups.h"
#include "chrome/renderer/extensions/bindings_utils.h"
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/js_only_v8_extensions.h"
@@ -17,6 +18,7 @@
#include "grit/common_resources.h"
#include "grit/renderer_resources.h"
#include "webkit/api/public/WebFrame.h"
+#include "webkit/api/public/WebScriptSource.h"
#include "webkit/api/public/WebURL.h"
#include "webkit/api/public/WebKit.h"
@@ -28,6 +30,8 @@
using bindings_utils::PendingRequest;
using bindings_utils::PendingRequestMap;
using bindings_utils::ExtensionBase;
+using WebKit::WebScriptSource;
+using WebKit::WebString;
namespace {
@@ -105,12 +109,46 @@
return v8::FunctionTemplate::New(GetCurrentPageActions);
} else if (name->Equals(v8::String::New("StartRequest"))) {
return v8::FunctionTemplate::New(StartRequest);
+ } else if (name->Equals(v8::String::New("ExecuteScript"))) {
+ return v8::FunctionTemplate::New(ExecuteScript);
+ } else if (name->Equals(v8::String::New("ExecuteScriptWithUrl"))) {
+ return v8::FunctionTemplate::New(ExecuteScriptWithUrl);
}
return ExtensionBase::GetNativeFunction(name);
}
private:
+ static v8::Handle<v8::Value> ExecuteScript(const v8::Arguments& args) {
+ if (args.Length() != 1 || !args[0]->IsString())
+ return v8::Boolean::New(false);
+
+ std::string script_source = *v8::String::Utf8Value(args[0]->ToString());
+ WebScriptSource web_script = WebScriptSource(
+ WebString::fromUTF8(script_source));
+ RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
+ if (!renderview)
+ return v8::Boolean::New(false);
+
+ renderview->webview()->GetMainFrame()->executeScriptInNewWorld(
+ &web_script, 1, EXTENSION_GROUP_CONTENT_SCRIPTS);
+ return v8::Boolean::New(true);
+ }
+
+ static v8::Handle<v8::Value> ExecuteScriptWithUrl(const v8::Arguments& args) {
+ if (args.Length() != 2)
+ return v8::Undefined();
+
+ if (!args[0]->IsInt32() || !args[1]->IsString())
+ return v8::Undefined();
+
+ int request_id = args[0]->Int32Value();
+ std::string script_url = *v8::String::Utf8Value(args[1]->ToString());
+ SendExtensionRequest("extension.executeScriptWithUrl", script_url,
+ request_id, true);
+ return v8::Boolean::New(true);
+ }
+
static v8::Handle<v8::Value> GetExtensionAPIDefinition(
const v8::Arguments& args) {
return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>());
@@ -233,12 +271,6 @@
// Starts an API request to the browser, with an optional callback. The
// callback will be dispatched to EventBindings::HandleResponse.
static v8::Handle<v8::Value> StartRequest(const v8::Arguments& args) {
- // Get the current RenderView so that we can send a routed IPC message from
- // the correct source.
- RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
- if (!renderview)
- return v8::Undefined();
-
if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() ||
!args[2]->IsInt32() || !args[3]->IsBoolean())
return v8::Undefined();
@@ -260,7 +292,20 @@
std::string json_args = *v8::String::Utf8Value(args[1]);
int request_id = args[2]->Int32Value();
bool has_callback = args[3]->BooleanValue();
+ SendExtensionRequest(name, json_args, request_id, has_callback);
+ return v8::Undefined();
+ }
+
+ static bool SendExtensionRequest(std::string name,
+ std::string json_args,
+ int request_id,
+ bool has_callback) {
+ // Get the current RenderView so that we can send a routed IPC message from
+ // the correct source.
+ RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
+ if (!renderview)
+ return false;
v8::Persistent<v8::Context> current_context =
v8::Persistent<v8::Context>::New(v8::Context::GetCurrent());
DCHECK(!current_context.IsEmpty());
@@ -268,8 +313,7 @@
current_context, name));
renderview->SendExtensionRequest(name, json_args, request_id, has_callback);
-
- return v8::Undefined();
+ return true;
}
};
« no previous file with comments | « chrome/common/extensions/api/extension_api.json ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698