Index: chrome/browser/extensions/api/messaging/message_service.cc |
=================================================================== |
--- chrome/browser/extensions/api/messaging/message_service.cc (revision 246091) |
+++ chrome/browser/extensions/api/messaging/message_service.cc (working copy) |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/extensions/api/messaging/extension_message_port.h" |
#include "chrome/browser/extensions/api/messaging/incognito_connectability.h" |
#include "chrome/browser/extensions/api/messaging/native_message_port.h" |
+#include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
#include "chrome/browser/extensions/extension_host.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extension_system.h" |
@@ -80,7 +81,6 @@ |
int receiver_port_id; |
std::string source_extension_id; |
std::string target_extension_id; |
- GURL source_url; |
std::string channel_name; |
bool include_tls_channel_id; |
std::string tls_channel_id; |
@@ -92,7 +92,6 @@ |
int receiver_port_id, |
const std::string& source_extension_id, |
const std::string& target_extension_id, |
- const GURL& source_url, |
const std::string& channel_name, |
bool include_tls_channel_id) |
: source(source), |
@@ -100,7 +99,6 @@ |
receiver_port_id(receiver_port_id), |
source_extension_id(source_extension_id), |
target_extension_id(target_extension_id), |
- source_url(source_url), |
channel_name(channel_name), |
include_tls_channel_id(include_tls_channel_id) { |
if (source_tab) |
@@ -119,14 +117,9 @@ |
static content::RenderProcessHost* GetExtensionProcess( |
Profile* profile, const std::string& extension_id) { |
SiteInstance* site_instance = |
- ExtensionSystem::Get(profile)->process_manager()-> |
- GetSiteInstanceForURL( |
- Extension::GetBaseURLFromExtensionId(extension_id)); |
- |
- if (!site_instance->HasProcess()) |
- return NULL; |
- |
- return site_instance->GetProcess(); |
+ ExtensionSystem::Get(profile)->process_manager()->GetSiteInstanceForURL( |
+ Extension::GetBaseURLFromExtensionId(extension_id)); |
+ return site_instance->HasProcess() ? site_instance->GetProcess() : NULL; |
} |
} // namespace |
@@ -152,12 +145,12 @@ |
// Sanity checks to make sure our channel<->port converters are correct. |
DCHECK(IS_OPENER_PORT_ID(port1_id)); |
- DCHECK(GET_OPPOSITE_PORT_ID(port1_id) == port2_id); |
- DCHECK(GET_OPPOSITE_PORT_ID(port2_id) == port1_id); |
- DCHECK(GET_CHANNEL_ID(port1_id) == GET_CHANNEL_ID(port2_id)); |
- DCHECK(GET_CHANNEL_ID(port1_id) == channel_id); |
- DCHECK(GET_CHANNEL_OPENER_ID(channel_id) == port1_id); |
- DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id); |
+ DCHECK_EQ(GET_OPPOSITE_PORT_ID(port1_id), port2_id); |
+ DCHECK_EQ(GET_OPPOSITE_PORT_ID(port2_id), port1_id); |
+ DCHECK_EQ(GET_CHANNEL_ID(port1_id), GET_CHANNEL_ID(port2_id)); |
+ DCHECK_EQ(GET_CHANNEL_ID(port1_id), channel_id); |
+ DCHECK_EQ(GET_CHANNEL_OPENER_ID(channel_id), port1_id); |
+ DCHECK_EQ(GET_CHANNEL_RECEIVERS_ID(channel_id), port2_id); |
*port1 = port1_id; |
*port2 = port2_id; |
@@ -299,13 +292,12 @@ |
// Include info about the opener's tab (if it was a tab). |
scoped_ptr<base::DictionaryValue> source_tab; |
- GURL source_url_for_tab; |
- |
if (source_contents && ExtensionTabUtil::GetTabId(source_contents) >= 0) { |
// Platform apps can be sent messages, but don't have a Tab concept. |
- if (!target_extension->is_platform_app()) |
- source_tab.reset(ExtensionTabUtil::CreateTabValue(source_contents)); |
- source_url_for_tab = source_url; |
+ // Only the tab id is useful to platform apps for internal use. The |
+ // unnecessary bits will be stripped out in |
+ // MessagingBindings::DispatchOnConnect(). |
+ source_tab.reset(ExtensionTabUtil::CreateTabValue(source_contents)); |
} |
OpenChannelParams* params = new OpenChannelParams(source, |
@@ -314,7 +306,6 @@ |
receiver_port_id, |
source_extension_id, |
target_extension_id, |
- source_url_for_tab, |
channel_name, |
include_tls_channel_id); |
@@ -325,7 +316,9 @@ |
if (include_tls_channel_id) { |
pending_tls_channel_id_channels_[GET_CHANNEL_ID(params->receiver_port_id)] |
= PendingMessagesQueue(); |
- property_provider_.GetDomainBoundCert(profile, params->source_url, |
+ property_provider_.GetDomainBoundCert( |
+ profile, |
+ source_url, |
base::Bind(&MessageService::GotDomainBoundCert, |
weak_factory_.GetWeakPtr(), |
base::Passed(make_scoped_ptr(params)))); |
@@ -451,7 +444,6 @@ |
receiver_port_id, |
extension_id, |
extension_id, |
- GURL(), // Source URL doesn't make sense for opening to tabs. |
channel_name, |
false)); // Connections to tabs don't get TLS channel IDs. |
OpenChannelImpl(params.Pass()); |
@@ -486,12 +478,16 @@ |
// Send the connect event to the receiver. Give it the opener's port ID (the |
// opener has the opposite port ID). |
+ // TODO(thestig) It is likely possible to get rid of |source_url| here and |
+ // pull it out of |params| further down the call path. |
+ std::string source_url; |
+ params->source_tab.GetString(tabs_constants::kUrlKey, &source_url); |
channel->receiver->DispatchOnConnect(params->receiver_port_id, |
params->channel_name, |
params->source_tab, |
params->source_extension_id, |
params->target_extension_id, |
- params->source_url, |
+ GURL(source_url), |
params->tls_channel_id); |
// Keep both ends of the channel alive until the channel is closed. |
@@ -549,8 +545,7 @@ |
channels_.erase(channel_iter); |
} |
-void MessageService::PostMessage( |
- int source_port_id, const Message& message) { |
+void MessageService::PostMessage(int source_port_id, const Message& message) { |
int channel_id = GET_CHANNEL_ID(source_port_id); |
MessageChannelMap::iterator iter = channels_.find(channel_id); |
if (iter == channels_.end()) { |