summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-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
-rw-r--r--chrome/renderer/mock_render_thread.cc2
-rw-r--r--chrome/renderer/mock_render_thread.h3
-rw-r--r--chrome/renderer/render_thread.cc7
-rw-r--r--chrome/renderer/render_thread.h2
-rw-r--r--chrome/renderer/renderer.vcproj4
-rwxr-xr-xchrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/renderer_extension_bindings.js6
12 files changed, 72 insertions, 32 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);
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc
index b133238..7812b31 100644
--- a/chrome/renderer/mock_render_thread.cc
+++ b/chrome/renderer/mock_render_thread.cc
@@ -92,7 +92,7 @@ void MockRenderThread::OnMsgCreateWidget(int opener_id,
}
void MockRenderThread::OnMsgOpenChannelToExtension(
- const std::string& extension_id, int* channel_id) {
+ int routing_id, const std::string& extension_id, int* channel_id) {
*channel_id = 0;
}
diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h
index f88543b..e4f2403 100644
--- a/chrome/renderer/mock_render_thread.h
+++ b/chrome/renderer/mock_render_thread.h
@@ -74,7 +74,8 @@ class MockRenderThread : public RenderThreadBase {
int* route_id);
// The callee expects to be returned a valid channel_id.
- void OnMsgOpenChannelToExtension(const std::string& extension_id,
+ void OnMsgOpenChannelToExtension(int routing_id,
+ const std::string& extension_id,
int* channel_id);
// The RenderView expects default print settings.
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 26836ca..afe3f38 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -314,7 +314,7 @@ void RenderThread::EnsureWebKitInitialized() {
WebKit::registerExtension(JsonJsV8Extension::Get());
WebKit::registerExtension(JsonSchemaJsV8Extension::Get());
WebKit::registerExtension(EventBindings::Get());
- WebKit::registerExtension(RendererExtensionBindings::Get(this));
+ WebKit::registerExtension(RendererExtensionBindings::Get());
}
if (command_line.HasSwitch(switches::kPlaybackMode) ||
@@ -328,8 +328,9 @@ void RenderThread::EnsureWebKitInitialized() {
}
}
-void RenderThread::OnExtensionHandleConnect(int port_id) {
- RendererExtensionBindings::HandleConnect(port_id);
+void RenderThread::OnExtensionHandleConnect(int port_id,
+ const std::string& tab_json) {
+ RendererExtensionBindings::HandleConnect(port_id, tab_json);
}
void RenderThread::OnExtensionHandleMessage(const std::string& message,
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index d50fd96..24b4574 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -127,7 +127,7 @@ class RenderThread : public RenderThreadBase,
// Send all histograms to browser.
void OnGetRendererHistograms();
- void OnExtensionHandleConnect(int channel_id);
+ void OnExtensionHandleConnect(int channel_id, const std::string& tab_json);
void OnExtensionHandleMessage(const std::string& message, int channel_id);
void OnExtensionHandleEvent(const std::string event_name,
const std::string event_data);
diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj
index d0c9de4..249f133 100644
--- a/chrome/renderer/renderer.vcproj
+++ b/chrome/renderer/renderer.vcproj
@@ -193,6 +193,10 @@
Name="extensions"
>
<File
+ RelativePath=".\extensions\bindings_utils.cc"
+ >
+ </File>
+ <File
RelativePath=".\extensions\bindings_utils.h"
>
</File>
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index c59e98c..beb23b7 100755
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. -->
+without changes to the corresponding grd file. 1 -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/renderer_resources.h" type="rc_header">
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index 19518db..11494e3 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -30,8 +30,12 @@ var chromium = chromium || {};
chromium.Port.ports_ = {};
// Called by native code when a channel has been opened to this context.
- chromium.Port.dispatchOnConnect_ = function(portId) {
+ chromium.Port.dispatchOnConnect_ = function(portId, tab) {
var port = new chromium.Port(portId);
+ if (tab) {
+ tab = goog.json.parse(tab);
+ }
+ port.tab = tab;
chromium.Event.dispatch_("channel-connect", [port]);
};