summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r--chrome/renderer/extensions/bindings_utils.cc23
-rwxr-xr-xchrome/renderer/extensions/bindings_utils.h6
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc13
-rwxr-xr-xchrome/renderer/extensions/renderer_extension_bindings.cc29
-rwxr-xr-xchrome/renderer/extensions/renderer_extension_bindings.h7
5 files changed, 54 insertions, 24 deletions
diff --git a/chrome/renderer/extensions/bindings_utils.cc b/chrome/renderer/extensions/bindings_utils.cc
new file mode 100644
index 0000000..ee4688d
--- /dev/null
+++ b/chrome/renderer/extensions/bindings_utils.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/extensions/bindings_utils.h"
+
+#include "chrome/renderer/render_view.h"
+#include "webkit/glue/webframe.h"
+
+RenderView* GetActiveRenderView() {
+ WebFrame* webframe = WebFrame::RetrieveActiveFrame();
+ DCHECK(webframe) << "GetActiveRenderView called when not in a V8 context.";
+ if (!webframe)
+ return NULL;
+
+ WebView* webview = webframe->GetView();
+ if (!webview)
+ return NULL; // can happen during closing
+
+ RenderView* renderview = static_cast<RenderView*>(webview->GetDelegate());
+ DCHECK(renderview) << "Encountered a WebView without a WebViewDelegate";
+ return renderview;
+}
diff --git a/chrome/renderer/extensions/bindings_utils.h b/chrome/renderer/extensions/bindings_utils.h
index 9e7d213..84fb32f 100755
--- a/chrome/renderer/extensions/bindings_utils.h
+++ b/chrome/renderer/extensions/bindings_utils.h
@@ -10,6 +10,8 @@
#include <string>
+class RenderView;
+
template<int kResourceId>
struct StringResourceTemplate {
StringResourceTemplate()
@@ -25,4 +27,8 @@ const char* GetStringResource() {
Singleton< StringResourceTemplate<kResourceId> >::get()->resource.c_str();
}
+// Returns the active RenderView, based on which V8 context is active. It is
+// an error to call this when not in a V8 context.
+RenderView* GetActiveRenderView();
+
#endif // CHROME_RENDERER_EXTENSIONS_BINDINGS_UTILS_H_
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index fcf9710..1c1ac79 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -70,16 +70,9 @@ class ExtensionImpl : public v8::Extension {
static v8::Handle<v8::Value> StartRequest(const v8::Arguments& args) {
WebFrame* webframe = WebFrame::RetrieveActiveFrame();
- DCHECK(webframe) << "There should be an active frame since we just got "
- "a native function called.";
- if (!webframe) return v8::Undefined();
-
- WebView* webview = webframe->GetView();
- if (!webview) return v8::Undefined(); // can happen during closing
-
- RenderView* renderview = static_cast<RenderView*>(webview->GetDelegate());
- DCHECK(renderview) << "Encountered a WebView without a WebViewDelegate";
- if (!renderview) return v8::Undefined();
+ RenderView* renderview = GetActiveRenderView();
+ if (!webframe || !renderview)
+ return v8::Undefined();
if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsInt32())
return v8::Undefined();
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);
}
diff --git a/chrome/renderer/extensions/renderer_extension_bindings.h b/chrome/renderer/extensions/renderer_extension_bindings.h
index 374dfb6..ad370af 100755
--- a/chrome/renderer/extensions/renderer_extension_bindings.h
+++ b/chrome/renderer/extensions/renderer_extension_bindings.h
@@ -19,11 +19,12 @@ class RendererExtensionBindings {
static const char* kName;
// Creates an instance of the extension.
- static v8::Extension* Get(RenderThreadBase* render_thread);
+ static v8::Extension* Get();
// Notify any listeners that a message channel has been opened to this
- // process.
- static void HandleConnect(int port_id);
+ // process. |tab_json| is the info for the tab that initiated this
+ // connection, or "null" if the initiator was not a tab.
+ static void HandleConnect(int port_id, const std::string& tab_json);
// Dispatch the given message sent on this channel.
static void HandleMessage(const std::string& message, int port_id);