summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/dispatcher.cc2
-rw-r--r--chrome/renderer/extensions/dispatcher.h2
-rw-r--r--chrome/renderer/extensions/extension_helper.cc5
-rw-r--r--chrome/renderer/extensions/extension_helper.h2
-rw-r--r--chrome/renderer/extensions/miscellaneous_bindings.cc108
-rw-r--r--chrome/renderer/extensions/miscellaneous_bindings.h3
-rw-r--r--chrome/renderer/resources/extensions/miscellaneous_bindings.js12
7 files changed, 50 insertions, 84 deletions
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc
index 7d0d01f..ea89a3f 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -595,7 +595,7 @@ void Dispatcher::OnDispatchOnConnect(
}
void Dispatcher::OnDeliverMessage(int target_port_id,
- const base::ListValue& message) {
+ const std::string& message) {
MiscellaneousBindings::DeliverMessage(
v8_context_set_.GetAll(),
target_port_id,
diff --git a/chrome/renderer/extensions/dispatcher.h b/chrome/renderer/extensions/dispatcher.h
index 44e80bf..ec002ad 100644
--- a/chrome/renderer/extensions/dispatcher.h
+++ b/chrome/renderer/extensions/dispatcher.h
@@ -151,7 +151,7 @@ class Dispatcher : public content::RenderProcessObserver {
const std::string& channel_name,
const base::DictionaryValue& source_tab,
const ExtensionMsg_ExternalConnectionInfo& info);
- void OnDeliverMessage(int target_port_id, const base::ListValue& message);
+ void OnDeliverMessage(int target_port_id, const std::string& message);
void OnDispatchOnDisconnect(int port_id, const std::string& error_message);
void OnSetFunctionNames(const std::vector<std::string>& names);
void OnLoaded(
diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc
index a5e7ef4..c61221b 100644
--- a/chrome/renderer/extensions/extension_helper.cc
+++ b/chrome/renderer/extensions/extension_helper.cc
@@ -274,9 +274,8 @@ void ExtensionHelper::OnExtensionDispatchOnConnect(
render_view());
}
-void ExtensionHelper::OnExtensionDeliverMessage(
- int target_id,
- const base::ListValue& message) {
+void ExtensionHelper::OnExtensionDeliverMessage(int target_id,
+ const std::string& message) {
MiscellaneousBindings::DeliverMessage(dispatcher_->v8_context_set().GetAll(),
target_id,
message,
diff --git a/chrome/renderer/extensions/extension_helper.h b/chrome/renderer/extensions/extension_helper.h
index 6e8fc97..fcb82b1 100644
--- a/chrome/renderer/extensions/extension_helper.h
+++ b/chrome/renderer/extensions/extension_helper.h
@@ -80,7 +80,7 @@ class ExtensionHelper
const base::DictionaryValue& source_tab,
const ExtensionMsg_ExternalConnectionInfo& info);
void OnExtensionDeliverMessage(int target_port_id,
- const base::ListValue& message);
+ const std::string& message);
void OnExtensionDispatchOnDisconnect(int port_id,
const std::string& error_message);
void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params);
diff --git a/chrome/renderer/extensions/miscellaneous_bindings.cc b/chrome/renderer/extensions/miscellaneous_bindings.cc
index d7e591d..d40d517 100644
--- a/chrome/renderer/extensions/miscellaneous_bindings.cc
+++ b/chrome/renderer/extensions/miscellaneous_bindings.cc
@@ -95,65 +95,43 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
if (!renderview)
return v8::Undefined();
- // Arguments are (int32 port_id, object message).
- CHECK_EQ(2, args.Length());
- CHECK(args[0]->IsInt32());
-
- int port_id = args[0]->Int32Value();
- if (!HasPortData(port_id)) {
- return v8::ThrowException(v8::Exception::Error(
- v8::String::New(kPortClosedError)));
+ if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) {
+ int port_id = args[0]->Int32Value();
+ if (!HasPortData(port_id)) {
+ return v8::ThrowException(v8::Exception::Error(
+ v8::String::New(kPortClosedError)));
+ }
+ std::string message = *v8::String::Utf8Value(args[1]->ToString());
+ renderview->Send(new ExtensionHostMsg_PostMessage(
+ renderview->GetRoutingID(), port_id, message));
}
-
- // The message can be any base::Value but IPC can't serialize that, so we
- // give it a singleton base::ListValue instead, or an empty list if the
- // argument was undefined (v8 value converter will return NULL for this).
- scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
- scoped_ptr<base::Value> message(
- converter->FromV8Value(args[1], v8_context()));
- ListValue message_as_list;
- if (message)
- message_as_list.Append(message.release());
-
- renderview->Send(new ExtensionHostMsg_PostMessage(
- renderview->GetRoutingID(), port_id, message_as_list));
-
return v8::Undefined();
}
// Forcefully disconnects a port.
v8::Handle<v8::Value> CloseChannel(const v8::Arguments& args) {
- // Arguments are (int32 port_id, boolean notify_browser).
- CHECK_EQ(2, args.Length());
- CHECK(args[0]->IsInt32());
- CHECK(args[1]->IsBoolean());
-
- int port_id = args[0]->Int32Value();
- if (!HasPortData(port_id))
- return v8::Undefined();
-
- // Send via the RenderThread because the RenderView might be closing.
- bool notify_browser = args[1]->BooleanValue();
- if (notify_browser) {
- content::RenderThread::Get()->Send(
- new ExtensionHostMsg_CloseChannel(port_id, std::string()));
+ if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsBoolean()) {
+ int port_id = args[0]->Int32Value();
+ if (!HasPortData(port_id)) {
+ return v8::Undefined();
+ }
+ // Send via the RenderThread because the RenderView might be closing.
+ bool notify_browser = args[1]->BooleanValue();
+ if (notify_browser)
+ content::RenderThread::Get()->Send(
+ new ExtensionHostMsg_CloseChannel(port_id, std::string()));
+ ClearPortData(port_id);
}
-
- ClearPortData(port_id);
-
return v8::Undefined();
}
// A new port has been created for a context. This occurs both when script
// opens a connection, and when a connection is opened to this script.
v8::Handle<v8::Value> PortAddRef(const v8::Arguments& args) {
- // Arguments are (int32 port_id).
- CHECK_EQ(1, args.Length());
- CHECK(args[0]->IsInt32());
-
- int port_id = args[0]->Int32Value();
- ++GetPortData(port_id).ref_count;
-
+ if (args.Length() >= 1 && args[0]->IsInt32()) {
+ int port_id = args[0]->Int32Value();
+ ++GetPortData(port_id).ref_count;
+ }
return v8::Undefined();
}
@@ -161,18 +139,15 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
// frames with a reference to a given port, we will disconnect it and notify
// the other end of the channel.
v8::Handle<v8::Value> PortRelease(const v8::Arguments& args) {
- // Arguments are (int32 port_id).
- CHECK_EQ(1, args.Length());
- CHECK(args[0]->IsInt32());
-
- int port_id = args[0]->Int32Value();
- if (HasPortData(port_id) && --GetPortData(port_id).ref_count == 0) {
- // Send via the RenderThread because the RenderView might be closing.
- content::RenderThread::Get()->Send(
- new ExtensionHostMsg_CloseChannel(port_id, std::string()));
- ClearPortData(port_id);
+ if (args.Length() >= 1 && args[0]->IsInt32()) {
+ int port_id = args[0]->Int32Value();
+ if (HasPortData(port_id) && --GetPortData(port_id).ref_count == 0) {
+ // Send via the RenderThread because the RenderView might be closing.
+ content::RenderThread::Get()->Send(
+ new ExtensionHostMsg_CloseChannel(port_id, std::string()));
+ ClearPortData(port_id);
+ }
}
-
return v8::Undefined();
}
@@ -296,7 +271,7 @@ void MiscellaneousBindings::DispatchOnConnect(
void MiscellaneousBindings::DeliverMessage(
const ChromeV8ContextSet::ContextSet& contexts,
int target_port_id,
- const base::ListValue& message,
+ const std::string& message,
content::RenderView* restrict_to_render_view) {
v8::HandleScope handle_scope;
@@ -307,9 +282,6 @@ void MiscellaneousBindings::DeliverMessage(
continue;
}
- v8::Handle<v8::Context> context = (*it)->v8_context();
- v8::Context::Scope context_scope(context);
-
// Check to see whether the context has this port before bothering to create
// the message.
v8::Handle<v8::Value> port_id_handle = v8::Integer::New(target_port_id);
@@ -330,19 +302,7 @@ void MiscellaneousBindings::DeliverMessage(
continue;
std::vector<v8::Handle<v8::Value> > arguments;
-
- // Convert the message to a v8 object; either a value or undefined.
- // See PostMessage for more details.
- if (message.empty()) {
- arguments.push_back(v8::Undefined());
- } else {
- CHECK_EQ(1u, message.GetSize());
- const base::Value* message_value = NULL;
- message.Get(0, &message_value);
- scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
- arguments.push_back(converter->ToV8Value(message_value, context));
- }
-
+ arguments.push_back(v8::String::New(message.c_str(), message.size()));
arguments.push_back(port_id_handle);
CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage",
arguments.size(),
diff --git a/chrome/renderer/extensions/miscellaneous_bindings.h b/chrome/renderer/extensions/miscellaneous_bindings.h
index 0a769d2..33bb15e 100644
--- a/chrome/renderer/extensions/miscellaneous_bindings.h
+++ b/chrome/renderer/extensions/miscellaneous_bindings.h
@@ -11,7 +11,6 @@
namespace base {
class DictionaryValue;
-class ListValue;
}
namespace content {
@@ -56,7 +55,7 @@ class MiscellaneousBindings {
static void DeliverMessage(
const ChromeV8ContextSet::ContextSet& context_set,
int target_port_id,
- const base::ListValue& message,
+ const std::string& message,
content::RenderView* restrict_to_render_view);
// Dispatches the Port.onDisconnect event in response to the channel being
diff --git a/chrome/renderer/resources/extensions/miscellaneous_bindings.js b/chrome/renderer/resources/extensions/miscellaneous_bindings.js
index 7dbfe29..9a4937d 100644
--- a/chrome/renderer/resources/extensions/miscellaneous_bindings.js
+++ b/chrome/renderer/resources/extensions/miscellaneous_bindings.js
@@ -8,6 +8,7 @@
// content scripts only.
require('json_schema');
+ var json = require('json');
var lastError = require('lastError');
var miscNatives = requireNative('miscellaneous_bindings');
var chrome = requireNative('chrome').GetChrome();
@@ -54,7 +55,10 @@
// Sends a message asynchronously to the context on the other end of this
// port.
PortImpl.prototype.postMessage = function(msg) {
- PostMessage(this.portId_, msg);
+ // json.stringify doesn't support a root object which is undefined.
+ if (msg === undefined)
+ msg = null;
+ PostMessage(this.portId_, json.stringify(msg));
};
// Disconnects the port from the other end.
@@ -262,8 +266,12 @@
// Called by native code when a message has been sent to the given port.
chromeHidden.Port.dispatchOnMessage = function(msg, portId) {
var port = ports[portId];
- if (port)
+ if (port) {
+ if (msg) {
+ msg = json.parse(msg);
+ }
port.onMessage.dispatch(msg, port);
+ }
};
// Shared implementation used by tabs.sendMessage and runtime.sendMessage.