summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 18:13:27 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 18:13:27 +0000
commitea4d0790da2db4aae00e07af25feffd7e3857377 (patch)
tree44af49f6bd1432124069d2bba095ac49f9fc2af3 /chrome/browser/extensions
parent76624fdeda4c8409a6bfd8a5f48de00dbceb0760 (diff)
downloadchromium_src-ea4d0790da2db4aae00e07af25feffd7e3857377.zip
chromium_src-ea4d0790da2db4aae00e07af25feffd7e3857377.tar.gz
chromium_src-ea4d0790da2db4aae00e07af25feffd7e3857377.tar.bz2
Implement chrome.extension.connectExternal and fix various API inconsistencies.
BUG=23583 BUG=17910 TEST=no Review URL: http://codereview.chromium.org/262016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_message_service.cc35
-rw-r--r--chrome/browser/extensions/extension_message_service.h12
-rwxr-xr-xchrome/browser/extensions/extension_messages_apitest.cc16
-rw-r--r--chrome/browser/extensions/extension_messages_unittest.cc6
4 files changed, 51 insertions, 18 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index d23576bc..66587b7 100644
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -60,12 +60,14 @@ static void DispatchOnConnect(const ExtensionMessageService::MessagePort& port,
int dest_port_id,
const std::string& channel_name,
const std::string& tab_json,
- const std::string& extension_id) {
+ const std::string& source_extension_id,
+ const std::string& target_extension_id) {
ListValue args;
args.Set(0, Value::CreateIntegerValue(dest_port_id));
args.Set(1, Value::CreateStringValue(channel_name));
args.Set(2, Value::CreateStringValue(tab_json));
- args.Set(3, Value::CreateStringValue(extension_id));
+ args.Set(3, Value::CreateStringValue(source_extension_id));
+ args.Set(4, Value::CreateStringValue(target_extension_id));
CHECK(port.sender);
port.sender->Send(new ViewMsg_ExtensionMessageInvoke(
port.routing_id, ExtensionMessageService::kDispatchOnConnect, args));
@@ -193,7 +195,8 @@ void ExtensionMessageService::AllocatePortIdPair(int* port1, int* port2) {
}
int ExtensionMessageService::OpenChannelToExtension(
- int routing_id, const std::string& extension_id,
+ int routing_id, const std::string& source_extension_id,
+ const std::string& target_extension_id,
const std::string& channel_name, ResourceMessageFilter* source) {
DCHECK_EQ(MessageLoop::current(),
ChromeThread::GetMessageLoop(ChromeThread::IO));
@@ -208,7 +211,8 @@ int ExtensionMessageService::OpenChannelToExtension(
ui_loop_->PostTask(FROM_HERE,
NewRunnableMethod(this,
&ExtensionMessageService::OpenChannelToExtensionOnUIThread,
- source->id(), routing_id, port2_id, extension_id, channel_name));
+ source->id(), routing_id, port2_id, source_extension_id,
+ target_extension_id, channel_name));
return port1_id;
}
@@ -239,20 +243,24 @@ int ExtensionMessageService::OpenChannelToTab(int routing_id,
void ExtensionMessageService::OpenChannelToExtensionOnUIThread(
int source_process_id, int source_routing_id, int receiver_port_id,
- const std::string& extension_id, const std::string& channel_name) {
+ const std::string& source_extension_id,
+ const std::string& target_extension_id,
+ const std::string& channel_name) {
if (!profile_)
return;
RenderProcessHost* source = RenderProcessHost::FromID(source_process_id);
MessagePort receiver(
- profile_->GetExtensionProcessManager()->GetExtensionProcess(extension_id),
+ profile_->GetExtensionProcessManager()->GetExtensionProcess(
+ target_extension_id),
MSG_ROUTING_CONTROL);
receiver.debug_info = 1;
TabContents* source_contents = tab_util::GetTabContentsByID(
source_process_id, source_routing_id);
OpenChannelOnUIThreadImpl(source, source_contents,
receiver, receiver_port_id,
- extension_id, channel_name);
+ source_extension_id, target_extension_id,
+ channel_name);
}
void ExtensionMessageService::OpenChannelToTabOnUIThread(
@@ -273,13 +281,15 @@ void ExtensionMessageService::OpenChannelToTabOnUIThread(
source_process_id, source_routing_id);
OpenChannelOnUIThreadImpl(source, source_contents,
receiver, receiver_port_id,
- extension_id, channel_name);
+ extension_id, extension_id, channel_name);
}
bool ExtensionMessageService::OpenChannelOnUIThreadImpl(
IPC::Message::Sender* source, TabContents* source_contents,
const MessagePort& receiver, int receiver_port_id,
- const std::string& extension_id, const std::string& channel_name) {
+ const std::string& source_extension_id,
+ const std::string& target_extension_id,
+ const std::string& channel_name) {
DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
// TODO(mpcomplete): notify source if reciever doesn't exist
@@ -320,7 +330,7 @@ bool ExtensionMessageService::OpenChannelOnUIThreadImpl(
// Send the connect event to the receiver. Give it the opener's port ID (the
// opener has the opposite port ID).
DispatchOnConnect(receiver, receiver_port_id, channel_name, tab_json,
- extension_id);
+ source_extension_id, target_extension_id);
return true;
}
@@ -342,7 +352,8 @@ int ExtensionMessageService::OpenSpecialChannelToExtension(
MSG_ROUTING_CONTROL);
receiver.debug_info = 4;
if (!OpenChannelOnUIThreadImpl(
- source, NULL, receiver, port2_id, extension_id, channel_name))
+ source, NULL, receiver, port2_id, extension_id, extension_id,
+ channel_name))
return -1;
return port1_id;
@@ -365,7 +376,7 @@ int ExtensionMessageService::OpenSpecialChannelToTab(
receiver.debug_info = 5;
if (!OpenChannelOnUIThreadImpl(source, NULL,
receiver, port2_id,
- extension_id, channel_name))
+ extension_id, extension_id, channel_name))
return -1;
return port1_id;
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h
index 10c579f..eb66bb6 100644
--- a/chrome/browser/extensions/extension_message_service.h
+++ b/chrome/browser/extensions/extension_message_service.h
@@ -114,7 +114,9 @@ class ExtensionMessageService
// an optional identifier for use by extension developers.
// This runs on the IO thread so that it can be used in a synchronous IPC
// message.
- int OpenChannelToExtension(int routing_id, const std::string& extension_id,
+ int OpenChannelToExtension(int routing_id,
+ const std::string& source_extension_id,
+ const std::string& target_extension_id,
const std::string& channel_name,
ResourceMessageFilter* source);
@@ -146,7 +148,9 @@ class ExtensionMessageService
// opened.
void OpenChannelToExtensionOnUIThread(
int source_process_id, int source_routing_id, int receiver_port_id,
- const std::string& extension_id, const std::string& channel_name);
+ const std::string& source_extension_id,
+ const std::string& target_extension_id,
+ const std::string& channel_name);
void OpenChannelToTabOnUIThread(
int source_process_id, int source_routing_id, int receiver_port_id,
@@ -157,7 +161,9 @@ class ExtensionMessageService
bool OpenChannelOnUIThreadImpl(
IPC::Message::Sender* source, TabContents* source_contents,
const MessagePort& receiver, int receiver_port_id,
- const std::string& extension_id, const std::string& channel_name);
+ const std::string& source_extension_id,
+ const std::string& target_extension_id,
+ const std::string& channel_name);
// NotificationObserver interface.
void Observe(NotificationType type,
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc
new file mode 100755
index 0000000..5b061af
--- /dev/null
+++ b/chrome/browser/extensions/extension_messages_apitest.cc
@@ -0,0 +1,16 @@
+// 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/browser/extensions/extension_apitest.h"
+
+// Tests that message passing between extensions and content scripts works.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingExternal) {
+ ASSERT_TRUE(LoadExtension(
+ test_data_dir_.AppendASCII("..").AppendASCII("good")
+ .AppendASCII("Extensions")
+ .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
+ .AppendASCII("1.0")));
+
+ ASSERT_TRUE(RunExtensionTest("connect_external")) << message_;
+}
diff --git a/chrome/browser/extensions/extension_messages_unittest.cc b/chrome/browser/extensions/extension_messages_unittest.cc
index 8246097..cdb78cc 100644
--- a/chrome/browser/extensions/extension_messages_unittest.cc
+++ b/chrome/browser/extensions/extension_messages_unittest.cc
@@ -16,6 +16,7 @@ static void DispatchOnConnect(int source_port_id, const std::string& name,
args.Set(1, Value::CreateStringValue(name));
args.Set(2, Value::CreateStringValue(tab_json));
args.Set(3, Value::CreateStringValue("")); // extension ID is empty for tests
+ args.Set(4, Value::CreateStringValue("")); // extension ID is empty for tests
RendererExtensionBindings::Invoke(
ExtensionMessageService::kDispatchOnConnect, args, NULL);
}
@@ -41,8 +42,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) {
render_thread_.sink().ClearMessages();
LoadHTML("<body></body>");
ExecuteJavaScript(
- "var e = new chrome.Extension('foobar');"
- "var port = e.connect({name:'testName'});"
+ "var port = chrome.extension.connect({name:'testName'});"
"port.onMessage.addListener(doOnMessage);"
"port.postMessage({message: 'content ready'});"
"function doOnMessage(msg, port) {"
@@ -57,7 +57,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) {
void* iter = IPC::SyncMessage::GetDataIterator(open_channel_msg);
ViewHostMsg_OpenChannelToExtension::SendParam open_params;
ASSERT_TRUE(IPC::ReadParam(open_channel_msg, &iter, &open_params));
- EXPECT_EQ("testName", open_params.c);
+ EXPECT_EQ("testName", open_params.d);
const IPC::Message* post_msg =
render_thread_.sink().GetUniqueMessageMatching(