Index: chrome/browser/renderer_host/chrome_extension_message_filter.cc |
diff --git a/chrome/browser/renderer_host/chrome_extension_message_filter.cc b/chrome/browser/renderer_host/chrome_extension_message_filter.cc |
index 3b1ef45bc0bb4594811b9f068d4d4814e19db217..74542bff22210b2b2cc4aba467a5f79844bc4ad8 100644 |
--- a/chrome/browser/renderer_host/chrome_extension_message_filter.cc |
+++ b/chrome/browser/renderer_host/chrome_extension_message_filter.cc |
@@ -9,6 +9,8 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
#include "base/files/file_path.h" |
+#include "base/guid.h" |
+#include "base/logging.h" |
#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/utf_string_conversions.h" |
@@ -33,6 +35,12 @@ |
using content::BrowserThread; |
+#define VALIDATE_PORT_ID(port_id) \ |
+ if (!base::IsValidGUID(port_id.context_id)) { \ |
+ NOTREACHED(); \ |
+ return; \ |
+ } |
+ |
namespace { |
const uint32_t kFilteredMessageClasses[] = { |
@@ -80,8 +88,6 @@ bool ChromeExtensionMessageFilter::OnMessageReceived( |
IPC_BEGIN_MESSAGE_MAP(ChromeExtensionMessageFilter, message) |
IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, |
OnOpenChannelToExtension) |
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtensionSync, |
- OnOpenChannelToExtensionSync) |
IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab) |
IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp, |
OnOpenChannelToNativeApp) |
@@ -105,6 +111,9 @@ bool ChromeExtensionMessageFilter::OnMessageReceived( |
void ChromeExtensionMessageFilter::OverrideThreadForMessage( |
const IPC::Message& message, BrowserThread::ID* thread) { |
switch (message.type()) { |
+ case ExtensionHostMsg_OpenChannelToExtension::ID: |
+ case ExtensionHostMsg_OpenChannelToTab::ID: |
+ case ExtensionHostMsg_OpenChannelToNativeApp::ID: |
case ExtensionHostMsg_OpenMessagePort::ID: |
case ExtensionHostMsg_CloseMessagePort::ID: |
case ExtensionHostMsg_PostMessage::ID: |
@@ -131,84 +140,25 @@ void ChromeExtensionMessageFilter::OnOpenChannelToExtension( |
const ExtensionMsg_ExternalConnectionInfo& info, |
const std::string& channel_name, |
bool include_tls_channel_id, |
- int request_id) { |
- int port1_id = 0; |
- int port2_id = 0; |
- extensions::MessageService::AllocatePortIdPair(&port1_id, &port2_id); |
- Send(new ExtensionMsg_AssignPortId(routing_id, port1_id, request_id)); |
- |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::Bind( |
- &ChromeExtensionMessageFilter::OpenChannelToExtensionOnUIThread, this, |
- render_process_id_, routing_id, port2_id, info, channel_name, |
- include_tls_channel_id)); |
-} |
- |
-void ChromeExtensionMessageFilter::OnOpenChannelToExtensionSync( |
- int routing_id, |
- const ExtensionMsg_ExternalConnectionInfo& info, |
- const std::string& channel_name, |
- bool include_tls_channel_id, |
- int* port_id) { |
- int port2_id = 0; |
- extensions::MessageService::AllocatePortIdPair(port_id, &port2_id); |
- |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::Bind( |
- &ChromeExtensionMessageFilter::OpenChannelToExtensionOnUIThread, this, |
- render_process_id_, routing_id, port2_id, info, channel_name, |
- include_tls_channel_id)); |
-} |
- |
-void ChromeExtensionMessageFilter::OpenChannelToExtensionOnUIThread( |
- int source_process_id, int source_routing_id, |
- int receiver_port_id, |
- const ExtensionMsg_ExternalConnectionInfo& info, |
- const std::string& channel_name, |
- bool include_tls_channel_id) { |
+ const extensions::PortId& port_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ VALIDATE_PORT_ID(port_id); |
if (profile_) { |
- extensions::MessageService::Get(profile_) |
- ->OpenChannelToExtension(source_process_id, |
- source_routing_id, |
- receiver_port_id, |
- info.source_id, |
- info.target_id, |
- info.source_url, |
- channel_name, |
- include_tls_channel_id); |
+ extensions::MessageService::Get(profile_)->OpenChannelToExtension( |
+ render_process_id_, routing_id, port_id, info.source_id, |
+ info.target_id, info.source_url, channel_name, include_tls_channel_id); |
} |
} |
void ChromeExtensionMessageFilter::OnOpenChannelToNativeApp( |
int routing_id, |
const std::string& native_app_name, |
- int request_id) { |
- int port1_id = 0; |
- int port2_id = 0; |
- extensions::MessageService::AllocatePortIdPair(&port1_id, &port2_id); |
- Send(new ExtensionMsg_AssignPortId(routing_id, port1_id, request_id)); |
- |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::Bind( |
- &ChromeExtensionMessageFilter::OpenChannelToNativeAppOnUIThread, |
- this, routing_id, port2_id, native_app_name)); |
-} |
- |
-void ChromeExtensionMessageFilter::OpenChannelToNativeAppOnUIThread( |
- int source_routing_id, |
- int receiver_port_id, |
- const std::string& native_app_name) { |
+ const extensions::PortId& port_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ VALIDATE_PORT_ID(port_id); |
if (profile_) { |
- extensions::MessageService::Get(profile_) |
- ->OpenChannelToNativeApp(render_process_id_, |
- source_routing_id, |
- receiver_port_id, |
- native_app_name); |
+ extensions::MessageService::Get(profile_)->OpenChannelToNativeApp( |
+ render_process_id_, routing_id, port_id, native_app_name); |
} |
} |
@@ -217,41 +167,20 @@ void ChromeExtensionMessageFilter::OnOpenChannelToTab( |
const ExtensionMsg_TabTargetConnectionInfo& info, |
const std::string& extension_id, |
const std::string& channel_name, |
- int request_id) { |
- int port1_id = 0; |
- int port2_id = 0; |
- extensions::MessageService::AllocatePortIdPair(&port1_id, &port2_id); |
- Send(new ExtensionMsg_AssignPortId(routing_id, port1_id, request_id)); |
- |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::Bind(&ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread, |
- this, render_process_id_, routing_id, port2_id, info, |
- extension_id, channel_name)); |
-} |
- |
-void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread( |
- int source_process_id, |
- int source_routing_id, |
- int receiver_port_id, |
- const ExtensionMsg_TabTargetConnectionInfo& info, |
- const std::string& extension_id, |
- const std::string& channel_name) { |
+ const extensions::PortId& port_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ VALIDATE_PORT_ID(port_id); |
if (profile_) { |
- extensions::MessageService::Get(profile_) |
- ->OpenChannelToTab(source_process_id, |
- source_routing_id, |
- receiver_port_id, |
- info.tab_id, |
- info.frame_id, |
- extension_id, |
- channel_name); |
+ extensions::MessageService::Get(profile_)->OpenChannelToTab( |
+ render_process_id_, routing_id, port_id, info.tab_id, |
+ info.frame_id, extension_id, channel_name); |
} |
} |
-void ChromeExtensionMessageFilter::OnOpenMessagePort(int routing_id, |
- int port_id) { |
+void ChromeExtensionMessageFilter::OnOpenMessagePort( |
+ int routing_id, |
+ const extensions::PortId& port_id) { |
+ VALIDATE_PORT_ID(port_id); |
if (!profile_) |
return; |
@@ -259,9 +188,11 @@ void ChromeExtensionMessageFilter::OnOpenMessagePort(int routing_id, |
port_id, render_process_id_, routing_id); |
} |
-void ChromeExtensionMessageFilter::OnCloseMessagePort(int routing_id, |
- int port_id, |
- bool force_close) { |
+void ChromeExtensionMessageFilter::OnCloseMessagePort( |
+ int routing_id, |
+ const extensions::PortId& port_id, |
+ bool force_close) { |
+ VALIDATE_PORT_ID(port_id); |
if (!profile_) |
return; |
@@ -270,8 +201,9 @@ void ChromeExtensionMessageFilter::OnCloseMessagePort(int routing_id, |
} |
void ChromeExtensionMessageFilter::OnPostMessage( |
- int port_id, |
+ const extensions::PortId& port_id, |
const extensions::Message& message) { |
+ VALIDATE_PORT_ID(port_id); |
if (!profile_) |
return; |
@@ -374,3 +306,5 @@ bool ChromeExtensionMessageFilter::ShouldLogExtensionAction( |
g_browser_process->profile_manager()->IsValidProfile(profile_) && |
activity_log_ && activity_log_->ShouldLog(extension_id); |
} |
+ |
+#undef VALIDATE_PORT_ID |