summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 21:17:49 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 21:17:49 +0000
commit4b5d64ff3d7d95247ed4f078d8bf585a1726794d (patch)
tree050a523a5bbccf28ade0814b38bcc9bee187cd04 /chrome/browser
parent912445b6db66140aecb3bc822075a6e9bb9d7e33 (diff)
downloadchromium_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/browser')
-rwxr-xr-xchrome/browser/extensions/extension_message_service.cc164
-rwxr-xr-xchrome/browser/extensions/extension_message_service.h73
-rw-r--r--chrome/browser/extensions/extension_messages_unittest.cc7
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc67
-rw-r--r--chrome/browser/extensions/extension_tabs_module.h5
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc18
-rw-r--r--chrome/browser/renderer_host/render_view_host.h1
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc16
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h4
9 files changed, 196 insertions, 159 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index 4e9daba..95dd221 100755
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -4,14 +4,18 @@
#include "chrome/browser/extensions/extension_message_service.h"
+#include "base/json_writer.h"
#include "base/singleton.h"
#include "base/values.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension.h"
+#include "chrome/browser/extensions/extension_tabs_module.h"
#include "chrome/browser/extensions/extension_view.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
+#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/stl_util-inl.h"
@@ -59,12 +63,35 @@ ExtensionMessageService* ExtensionMessageService::GetInstance(
}
ExtensionMessageService::ExtensionMessageService()
- : next_port_id_(0), observing_renderer_shutdown_(false) {
+ : ui_loop_(NULL), initialized_(false), next_port_id_(0) {
+}
+
+void ExtensionMessageService::Init() {
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
+
+ if (initialized_)
+ return;
+ initialized_ = true;
+
+ ui_loop_ = MessageLoop::current();
+
+ // Note: we never stop observing because we live longer than
+ // NotificationService.
+ NotificationService::current()->AddObserver(this,
+ NotificationType::RENDERER_PROCESS_TERMINATED,
+ NotificationService::AllSources());
+ NotificationService::current()->AddObserver(this,
+ NotificationType::RENDERER_PROCESS_CRASHED,
+ NotificationService::AllSources());
}
void ExtensionMessageService::RegisterExtension(
const std::string& extension_id, int render_process_id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
+
+ // Make sure we're initialized.
+ Init();
+
AutoLock lock(process_ids_lock_);
DCHECK(process_ids_.find(extension_id) == process_ids_.end() ||
process_ids_[extension_id] == render_process_id);
@@ -73,24 +100,23 @@ void ExtensionMessageService::RegisterExtension(
void ExtensionMessageService::AddEventListener(std::string event_name,
int render_process_id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
- AutoLock lock(listener_lock_);
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
DCHECK(listeners_[event_name].count(render_process_id) == 0);
listeners_[event_name].insert(render_process_id);
}
void ExtensionMessageService::RemoveEventListener(std::string event_name,
int render_process_id) {
- DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
- AutoLock lock(listener_lock_);
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
DCHECK(listeners_[event_name].count(render_process_id) == 1);
listeners_[event_name].erase(render_process_id);
}
int ExtensionMessageService::OpenChannelToExtension(
- const std::string& extension_id, ResourceMessageFilter* source) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
+ int routing_id, const std::string& extension_id,
+ ResourceMessageFilter* source) {
+ DCHECK_EQ(MessageLoop::current(),
+ ChromeThread::GetMessageLoop(ChromeThread::IO));
// Lookup the targeted extension process.
int process_id;
@@ -103,13 +129,10 @@ int ExtensionMessageService::OpenChannelToExtension(
process_id = process_id_it->second;
}
- RendererMap::iterator renderer = renderers_.find(process_id);
- if (renderer == renderers_.end())
- return -1;
-
- ResourceMessageFilter* dest = renderer->second;
+ DCHECK(initialized_);
// Create a channel ID for both sides of the channel.
+ // TODO(mpcomplete): what happens when this wraps?
int port1_id = next_port_id_++;
int port2_id = next_port_id_++;
DCHECK(IS_PORT1_ID(port1_id));
@@ -117,22 +140,45 @@ int ExtensionMessageService::OpenChannelToExtension(
DCHECK(GET_OPPOSITE_PORT_ID(port2_id) == port1_id);
DCHECK(GET_CHANNEL_ID(port1_id) == GET_CHANNEL_ID(port2_id));
+ ui_loop_->PostTask(FROM_HERE,
+ NewRunnableMethod(this, &ExtensionMessageService::OpenChannelOnUIThread,
+ routing_id, port1_id, source->GetProcessId(), port2_id, process_id));
+
+ return port2_id;
+}
+
+void ExtensionMessageService::OpenChannelOnUIThread(
+ int source_routing_id, int source_port_id, int source_process_id,
+ int dest_port_id, int dest_process_id) {
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
+
MessageChannel channel;
- channel.port1 = source;
- channel.port2 = dest;
- channels_[GET_CHANNEL_ID(port1_id)] = channel;
+ channel.port1 = RenderProcessHost::FromID(source_process_id);
+ channel.port2 = RenderProcessHost::FromID(dest_process_id);
+ if (!channel.port1 || !channel.port2) {
+ // One of the processes could have been closed while posting this task.
+ return;
+ }
+
+ channels_[GET_CHANNEL_ID(source_port_id)] = channel;
+
+ std::string tab_json = "null";
+ WebContents* contents = tab_util::GetWebContentsByID(source_process_id,
+ source_routing_id);
+ if (contents) {
+ DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue(contents);
+ JSONWriter::Write(tab_value, false, &tab_json);
+ }
// Send each process the id for the opposite port.
- dest->Send(new ViewMsg_ExtensionHandleConnect(port1_id));
- return port2_id;
+ channel.port2->Send(new ViewMsg_ExtensionHandleConnect(source_port_id,
+ tab_json));
}
void ExtensionMessageService::PostMessageFromRenderer(
- int port_id, const std::string& message, ResourceMessageFilter* source) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
+ int port_id, const std::string& message) {
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
- // Look up the channel by port1's ID.
MessageChannelMap::iterator iter =
channels_.find(GET_CHANNEL_ID(port_id));
if (iter == channels_.end())
@@ -140,14 +186,8 @@ void ExtensionMessageService::PostMessageFromRenderer(
MessageChannel& channel = iter->second;
// Figure out which port the ID corresponds to.
- ResourceMessageFilter* dest = NULL;
- if (IS_PORT1_ID(port_id)) {
- dest = channel.port1;
- DCHECK(source == channel.port2);
- } else {
- dest = channel.port2;
- DCHECK(source == channel.port1);
- }
+ RenderProcessHost* dest =
+ IS_PORT1_ID(port_id) ? channel.port1 : channel.port2;
int source_port_id = GET_OPPOSITE_PORT_ID(port_id);
dest->Send(new ViewMsg_ExtensionHandleMessage(message, source_port_id));
@@ -155,60 +195,38 @@ void ExtensionMessageService::PostMessageFromRenderer(
void ExtensionMessageService::DispatchEventToRenderers(
const std::string& event_name, const std::string& event_args) {
- std::set<int> pids;
- {
- AutoLock lock(listener_lock_);
- pids = listeners_[event_name];
- if (pids.empty())
- return;
- }
- MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO);
- if (MessageLoop::current() != io_thread) {
- // Do the actual work on the IO thread.
- io_thread->PostTask(FROM_HERE, NewRunnableMethod(this,
- &ExtensionMessageService::DispatchEventToRenderers,
- event_name, event_args));
- return;
- }
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
+
+ std::set<int>& pids = listeners_[event_name];
// Send the event only to renderers that are listening for it.
for (std::set<int>::iterator pid = pids.begin(); pid != pids.end(); ++pid) {
- RendererMap::iterator renderer = renderers_.find(*pid);
- if (renderer == renderers_.end())
+ RenderProcessHost* renderer = RenderProcessHost::FromID(*pid);
+ if (!renderer)
continue;
- ResourceMessageFilter* filter = renderer->second;
- filter->Send(new ViewMsg_ExtensionHandleEvent(event_name, event_args));
- }
-}
-
-void ExtensionMessageService::RendererReady(ResourceMessageFilter* renderer) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
-
- DCHECK(renderers_.find(renderer->GetProcessId()) == renderers_.end());
- renderers_[renderer->GetProcessId()] = renderer;
- renderers_unique_.insert(renderer);
-
- if (!observing_renderer_shutdown_) {
- observing_renderer_shutdown_ = true;
- NotificationService::current()->AddObserver(
- this,
- NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
- NotificationService::AllSources());
+ renderer->Send(new ViewMsg_ExtensionHandleEvent(event_name, event_args));
}
}
void ExtensionMessageService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- DCHECK(MessageLoop::current() ==
- ChromeThread::GetMessageLoop(ChromeThread::IO));
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
- DCHECK(type.value == NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN);
- ResourceMessageFilter* renderer = Source<ResourceMessageFilter>(source).ptr();
+ DCHECK(type.value == NotificationType::RENDERER_PROCESS_TERMINATED ||
+ type.value == NotificationType::RENDERER_PROCESS_CRASHED);
+ RenderProcessHost* renderer = Source<RenderProcessHost>(source).ptr();
- renderers_.erase(renderer->GetProcessId());
- renderers_unique_.erase(renderer);
+ {
+ AutoLock lock(process_ids_lock_);
+ for (ProcessIDMap::iterator it = process_ids_.begin();
+ it != process_ids_.end(); ) {
+ ProcessIDMap::iterator current = it++;
+ if (current->second == renderer->pid()) {
+ process_ids_.erase(current);
+ }
+ }
+ }
// Close any channels that share this renderer.
// TODO(mpcomplete): should we notify the other side of the port?
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h
index 52b1682..343c632 100755
--- a/chrome/browser/extensions/extension_message_service.h
+++ b/chrome/browser/extensions/extension_message_service.h
@@ -12,8 +12,8 @@
#include "base/lock.h"
#include "chrome/common/notification_observer.h"
-class ExtensionView;
-class ListValue;
+class MessageLoop;
+class RenderProcessHost;
class ResourceMessageFilter;
class URLRequestContext;
@@ -44,33 +44,33 @@ class ExtensionMessageService : public NotificationObserver {
void AddEventListener(std::string event_name, int render_process_id);
void RemoveEventListener(std::string event_name, int render_process_id);
- // --- IO thread only:
-
- // Given an extension's ID, opens a channel between the given renderer "port"
- // and that extension. Returns a channel ID to be used for posting messages
- // between the processes, or -1 if the extension doesn't exist.
- int OpenChannelToExtension(const std::string& extension_id,
- ResourceMessageFilter* source);
-
// Sends a message from a renderer to the given port.
- void PostMessageFromRenderer(int port_id, const std::string& message,
- ResourceMessageFilter* source);
+ // TODO(mpcomplete): include the source tab.
+ void PostMessageFromRenderer(int port_id, const std::string& message);
- // Called to let us know that a renderer has been started.
- void RendererReady(ResourceMessageFilter* renderer);
+ // Send an event to every registered extension renderer.
+ void DispatchEventToRenderers(
+ const std::string& event_name, const std::string& event_args);
// NotificationObserver interface.
void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
- // --- UI or IO thread:
+ // --- IO thread only:
- // Send an event to every registered extension renderer.
- void DispatchEventToRenderers(
- const std::string& event_name, const std::string& event_args);
+ // Given an extension's ID, opens a channel between the given renderer "port"
+ // and that extension. Returns a channel ID to be used for posting messages
+ // between the processes, or -1 if the extension doesn't exist.
+ // 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,
+ ResourceMessageFilter* source);
private:
+ // The UI message loop, used for posting tasks.
+ MessageLoop* ui_loop_;
+
// A map of extension ID to the render_process_id that the extension lives in.
typedef std::map<std::string, int> ProcessIDMap;
ProcessIDMap process_ids_;
@@ -85,36 +85,35 @@ class ExtensionMessageService : public NotificationObserver {
typedef std::map<std::string, std::set<int> > ListenerMap;
ListenerMap listeners_;
- // Protects listeners_ map, since it can be accessed from either the IO or
- // UI thread. Be careful not to hold this lock when calling external code
- // (especially sending messages) to avoid deadlock.
- Lock listener_lock_;
+ // --- UI thread only:
- // --- IO thread only:
+ // UI-thread specific initialization. Does nothing if called more than once.
+ void Init();
- // The connection between two renderers.
+ // Handles channel creation and notifies the destination that a channel was
+ // opened.
+ void OpenChannelOnUIThread(int source_routing_id,
+ int source_port_id, int source_process_id,
+ int dest_port_id, int dest_process_id);
+
+ // The connection between two renderers. It is possible that both ports
+ // refer to the same renderer.
struct MessageChannel {
- ResourceMessageFilter* port1;
- ResourceMessageFilter* port2;
+ RenderProcessHost* port1;
+ RenderProcessHost* port2;
};
// A map of channel ID to its channel object.
typedef std::map<int, MessageChannel> MessageChannelMap;
MessageChannelMap channels_;
- // For generating unique channel IDs.
- int next_port_id_;
-
- // A map of render_process_id to its corresponding message filter, which we
- // use for sending messages.
- typedef std::map<int, ResourceMessageFilter*> RendererMap;
- RendererMap renderers_;
+ // True if Init has been called.
+ bool initialized_;
- // A unique list of renderers that we are aware of.
- std::set<ResourceMessageFilter*> renderers_unique_;
+ // --- IO thread only:
- // Set to true when we start observing this notification.
- bool observing_renderer_shutdown_;
+ // For generating unique channel IDs.
+ int next_port_id_;
DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService);
};
diff --git a/chrome/browser/extensions/extension_messages_unittest.cc b/chrome/browser/extensions/extension_messages_unittest.cc
index 1ef9f43..606c301 100644
--- a/chrome/browser/extensions/extension_messages_unittest.cc
+++ b/chrome/browser/extensions/extension_messages_unittest.cc
@@ -59,7 +59,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) {
ExecuteJavaScript(
"chromium.self.onConnect.addListener(function (port) {"
" port.onMessage.addListener(doOnMessage);"
- " port.postMessage({message: 'onconnect'});"
+ " port.postMessage({message: 'onconnect from ' + port.tab.url});"
"});"
"function doOnMessage(msg, port) {"
" alert('got: ' + msg.val);"
@@ -69,7 +69,8 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) {
// Simulate a new connection being opened.
const int kPortId = 0;
- RendererExtensionBindings::HandleConnect(kPortId);
+ RendererExtensionBindings::HandleConnect(kPortId,
+ "{\"url\":\"foo://bar\"}");
// Verify that we handled the new connection by posting a message.
const IPC::Message* post_msg =
@@ -78,7 +79,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) {
ASSERT_TRUE(post_msg);
ViewHostMsg_ExtensionPostMessage::Param post_params;
ViewHostMsg_ExtensionPostMessage::Read(post_msg, &post_params);
- EXPECT_EQ("{\"message\":\"onconnect\"}", post_params.b);
+ EXPECT_EQ("{\"message\":\"onconnect from foo://bar\"}", post_params.b);
// Now simulate getting a message back from the channel opener.
render_thread_.sink().ClearMessages();
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 069110e..41663dd 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -21,8 +21,6 @@
// Forward declare static helper functions defined below.
static DictionaryValue* CreateWindowValue(Browser* browser);
static ListValue* CreateTabList(Browser* browser);
-static DictionaryValue* CreateTabValue(TabStripModel* tab_strip_model,
- int tab_index);
static bool GetIndexOfTabId(const TabStripModel* tab_strip, int tab_id,
int* tab_index);
@@ -39,6 +37,42 @@ int ExtensionTabUtil::GetWindowIdOfTab(const TabContents* tab_contents) {
return tab_contents->controller().window_id().id();
}
+DictionaryValue* ExtensionTabUtil::CreateTabValue(
+ const TabContents* contents) {
+ // Find the tab strip and index of this guy.
+ for (BrowserList::const_iterator it = BrowserList::begin();
+ it != BrowserList::end(); ++it) {
+ TabStripModel* tab_strip = (*it)->tabstrip_model();
+ int tab_index = tab_strip->GetIndexOfTabContents(contents);
+ if (tab_index != -1) {
+ return ExtensionTabUtil::CreateTabValue(contents, tab_strip, tab_index);
+ }
+ }
+
+ // Couldn't find it. This can happen if the tab is being dragged.
+ return ExtensionTabUtil::CreateTabValue(contents, NULL, -1);
+}
+
+DictionaryValue* ExtensionTabUtil::CreateTabValue(
+ const TabContents* contents, TabStripModel* tab_strip, int tab_index) {
+ DictionaryValue* result = new DictionaryValue();
+ result->SetInteger(L"id", ExtensionTabUtil::GetTabId(contents));
+ result->SetInteger(L"index", tab_index);
+ result->SetInteger(L"windowId", ExtensionTabUtil::GetWindowIdOfTab(contents));
+ result->SetString(L"url", contents->GetURL().spec());
+ result->SetString(L"title", UTF16ToWide(contents->GetTitle()));
+ result->SetBoolean(L"selected",
+ tab_strip && tab_index == tab_strip->selected_index());
+
+ NavigationEntry* entry = contents->controller().GetActiveEntry();
+ if (entry) {
+ if (entry->favicon().is_valid())
+ result->SetString(L"favIconUrl", entry->favicon().url().spec());
+ }
+
+ return result;
+}
+
bool GetWindowsFunction::RunImpl() {
std::set<int> window_ids;
@@ -220,7 +254,7 @@ bool CreateTabFunction::RunImpl() {
// Return data about the newly created tab.
if (has_callback())
- result_.reset(CreateTabValue(tab_strip, index));
+ result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, index));
return true;
}
@@ -239,7 +273,8 @@ bool GetTabFunction::RunImpl() {
if (!GetIndexOfTabId(tab_strip, tab_id, &tab_index))
return false;
- result_.reset(CreateTabValue(tab_strip, tab_index));
+ result_.reset(ExtensionTabUtil::CreateTabValue(
+ tab_strip->GetTabContentsAt(tab_index), tab_strip, tab_index));
return true;
}
@@ -366,33 +401,13 @@ static ListValue* CreateTabList(Browser* browser) {
ListValue *tab_list = new ListValue();
TabStripModel* tab_strip = browser->tabstrip_model();
for (int i = 0; i < tab_strip->count(); ++i) {
- tab_list->Append(CreateTabValue(tab_strip, i));
+ tab_list->Append(ExtensionTabUtil::CreateTabValue(
+ tab_strip->GetTabContentsAt(i), tab_strip, i));
}
return tab_list;
}
-static DictionaryValue* CreateTabValue(TabStripModel* tab_strip,
- int tab_index) {
- TabContents* contents = tab_strip->GetTabContentsAt(tab_index);
-
- DictionaryValue* result = new DictionaryValue();
- result->SetInteger(L"id", ExtensionTabUtil::GetTabId(contents));
- result->SetInteger(L"index", tab_index);
- result->SetInteger(L"windowId", ExtensionTabUtil::GetWindowIdOfTab(contents));
- result->SetString(L"url", contents->GetURL().spec());
- result->SetString(L"title", UTF16ToWide(contents->GetTitle()));
- result->SetBoolean(L"selected", tab_index == tab_strip->selected_index());
-
- NavigationEntry* entry = contents->controller().GetActiveEntry();
- if (entry) {
- if (entry->favicon().is_valid())
- result->SetString(L"favIconUrl", entry->favicon().url().spec());
- }
-
- return result;
-}
-
static bool GetIndexOfTabId(const TabStripModel* tab_strip, int tab_id,
int* tab_index) {
for (int i = 0; i < tab_strip->count(); ++i) {
diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h
index 90c8647..c139f6a 100644
--- a/chrome/browser/extensions/extension_tabs_module.h
+++ b/chrome/browser/extensions/extension_tabs_module.h
@@ -8,13 +8,18 @@
#include "chrome/browser/extensions/extension_function.h"
class Browser;
+class DictionaryValue;
class TabContents;
+class TabStripModel;
class ExtensionTabUtil {
public:
static int GetWindowId(const Browser* browser);
static int GetTabId(const TabContents* tab_contents);
static int GetWindowIdOfTab(const TabContents* tab_contents);
+ static DictionaryValue* CreateTabValue(const TabContents* tab_contents);
+ static DictionaryValue* CreateTabValue(
+ const TabContents* tab_contents, TabStripModel* tab_strip, int tab_index);
};
class GetWindowsFunction : public SyncExtensionFunction {
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 3646358..c3d7aeb 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -15,8 +15,9 @@
#include "chrome/browser/cross_site_request_manager.h"
#include "chrome/browser/debugger/debugger_wrapper.h"
#include "chrome/browser/debugger/devtools_manager.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/renderer_security_policy.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
@@ -26,13 +27,13 @@
#include "chrome/browser/tab_contents/site_instance.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/common/bindings_policy.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/common/resource_bundle.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/common/resource_bundle.h"
#include "chrome/common/result_codes.h"
-#include "chrome/common/url_constants.h"
#include "chrome/common/thumbnail_score.h"
+#include "chrome/common/url_constants.h"
#include "net/base/net_util.h"
#include "skia/include/SkBitmap.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
@@ -775,6 +776,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged)
IPC_MESSAGE_HANDLER(ViewHostMsg_PasteFromSelectionClipboard,
OnMsgPasteFromSelectionClipboard)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionPostMessage,
+ OnExtensionPostMessage)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg))
IPC_END_MESSAGE_MAP_EX()
@@ -1368,3 +1371,10 @@ void RenderViewHost::SendExtensionResponse(int callback_id,
const std::string& response) {
Send(new ViewMsg_ExtensionResponse(routing_id(), callback_id, response));
}
+
+void RenderViewHost::OnExtensionPostMessage(
+ int port_id, const std::string& message) {
+ URLRequestContext* context = process()->profile()->GetRequestContext();
+ ExtensionMessageService::GetInstance(context)->
+ PostMessageFromRenderer(port_id, message);
+}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 0125b50..b86b5f5 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -543,6 +543,7 @@ class RenderViewHost : public RenderWidgetHost {
void OnExtensionRequest(const std::string& name, const std::string& args,
int callback_id);
+ void OnExtensionPostMessage(int port_id, const std::string& message);
// Helper function to send a navigation message. If a cross-site request is
// in progress, we may be suspended while waiting for the onbeforeunload
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 804042f..3fc0602 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -193,10 +193,6 @@ void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) {
// Hook AudioRendererHost to this object after channel is connected so it can
// this object for sending messages.
audio_renderer_host_->IPCChannelConnected(render_process_id_, handle(), this);
-
- // Ditto for the ExtensionMessageService.
- ExtensionMessageService::GetInstance(request_context_.get())->
- RendererReady(this);
}
// Called on the IPC thread:
@@ -299,8 +295,6 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension,
OnOpenChannelToExtension)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionPostMessage,
- OnExtensionPostMessage)
IPC_MESSAGE_UNHANDLED(
handled = false)
IPC_END_MESSAGE_MAP_EX()
@@ -829,13 +823,7 @@ void ResourceMessageFilter::OnFreeTransportDIB(
#endif
void ResourceMessageFilter::OnOpenChannelToExtension(
- const std::string& extension_id, int* port_id) {
+ int routing_id, const std::string& extension_id, int* port_id) {
*port_id = ExtensionMessageService::GetInstance(request_context_.get())->
- OpenChannelToExtension(extension_id, this);
-}
-
-void ResourceMessageFilter::OnExtensionPostMessage(
- int port_id, const std::string& message) {
- ExtensionMessageService::GetInstance(request_context_.get())->
- PostMessageFromRenderer(port_id, message, this);
+ OpenChannelToExtension(routing_id, extension_id, this);
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 74181bf..e16ac8d 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -202,8 +202,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
TransportDIB::Handle* result);
void OnFreeTransportDIB(TransportDIB::Id dib_id);
- void OnOpenChannelToExtension(const std::string& extension_id, int* port_id);
- void OnExtensionPostMessage(int port_id, const std::string& message);
+ void OnOpenChannelToExtension(int routing_id,
+ const std::string& extension_id, int* port_id);
#if defined(OS_LINUX)
void SendDelayedReply(IPC::Message* reply_msg);