diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 21:17:49 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 21:17:49 +0000 |
commit | 4b5d64ff3d7d95247ed4f078d8bf585a1726794d (patch) | |
tree | 050a523a5bbccf28ade0814b38bcc9bee187cd04 /chrome/renderer/extensions/renderer_extension_bindings.cc | |
parent | 912445b6db66140aecb3bc822075a6e9bb9d7e33 (diff) | |
download | chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.zip chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.tar.gz chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.tar.bz2 |
Pass down the opener tab when a message channel is opened to an extension.
Also did a bunch of cleanup of ExtensionMessageService. I converted it to
primarily UI-thread habitation, with one function that needs to be on the IO
thread so it can handle a synchronous IPC message.
TEST=N/A
Review URL: http://codereview.chromium.org/99261
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15097 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions/renderer_extension_bindings.cc')
-rwxr-xr-x | chrome/renderer/extensions/renderer_extension_bindings.cc | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/chrome/renderer/extensions/renderer_extension_bindings.cc b/chrome/renderer/extensions/renderer_extension_bindings.cc index 63214d73..28b5c47 100755 --- a/chrome/renderer/extensions/renderer_extension_bindings.cc +++ b/chrome/renderer/extensions/renderer_extension_bindings.cc @@ -10,6 +10,7 @@ #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/render_thread.h" +#include "chrome/renderer/render_view.h" #include "grit/renderer_resources.h" // Message passing API example (in a content script): @@ -24,9 +25,6 @@ namespace { -// We use the generic interface so that unit tests can inject a mock. -RenderThreadBase* render_thread_ = NULL; - const char* kExtensionDeps[] = { EventBindings::kName }; class ExtensionImpl : public v8::Extension { @@ -51,11 +49,15 @@ class ExtensionImpl : public v8::Extension { // Creates a new messaging channel to the given extension. static v8::Handle<v8::Value> OpenChannelToExtension( const v8::Arguments& args) { + RenderView* renderview = GetActiveRenderView(); + if (!renderview) + return v8::Undefined(); + if (args.Length() >= 1 && args[0]->IsString()) { std::string id = *v8::String::Utf8Value(args[0]->ToString()); int port_id = -1; - render_thread_->Send( - new ViewHostMsg_OpenChannelToExtension(id, &port_id)); + renderview->Send(new ViewHostMsg_OpenChannelToExtension( + renderview->routing_id(), id, &port_id)); return v8::Integer::New(port_id); } return v8::Undefined(); @@ -63,11 +65,15 @@ class ExtensionImpl : public v8::Extension { // Sends a message along the given channel. static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { + RenderView* renderview = GetActiveRenderView(); + if (!renderview) + return v8::Undefined(); + if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { int port_id = args[0]->Int32Value(); std::string message = *v8::String::Utf8Value(args[1]->ToString()); - render_thread_->Send( - new ViewHostMsg_ExtensionPostMessage(port_id, message)); + renderview->Send(new ViewHostMsg_ExtensionPostMessage( + renderview->routing_id(), port_id, message)); } return v8::Undefined(); } @@ -78,15 +84,16 @@ class ExtensionImpl : public v8::Extension { const char* RendererExtensionBindings::kName = "chrome/RendererExtensionBindings"; -v8::Extension* RendererExtensionBindings::Get(RenderThreadBase* render_thread) { - render_thread_ = render_thread; +v8::Extension* RendererExtensionBindings::Get() { return new ExtensionImpl(); } -void RendererExtensionBindings::HandleConnect(int port_id) { +void RendererExtensionBindings::HandleConnect(int port_id, + const std::string& tab_json) { v8::HandleScope handle_scope; - v8::Handle<v8::Value> argv[1]; + v8::Handle<v8::Value> argv[2]; argv[0] = v8::Integer::New(port_id); + argv[1] = v8::String::New(tab_json.c_str()); EventBindings::CallFunction("chromium.Port.dispatchOnConnect_", arraysize(argv), argv); } |