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) |
@@ -119,14 +119,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 +147,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; |
@@ -301,10 +296,26 @@ |
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)); |
+ if (source_contents) { |
not at google - send to devlin
2014/01/23 16:41:59
Maybe we should just always send the tab data and
Lei Zhang
2014/01/23 20:53:12
Again, I'm doing the filter on the browser side be
not at google - send to devlin
2014/01/23 21:07:43
I don't think accidentally giving the tab info to
|
+ int tab_id = ExtensionTabUtil::GetTabId(source_contents); |
+ if (tab_id >= 0) { |
+ if (target_extension->is_platform_app()) { |
+ // Platform apps can be sent messages, but don't have a Tab concept. |
+ // Send this only so that mediaGalleries.addUserSelectedFolder() can |
+ // figure out the context for the call when there is no app window open. |
+ source_tab.reset( |
+ ExtensionTabUtil::CreateTabValueForPlatformApp(source_contents)); |
+ |
+ // Record this so it is possible to verify |target_extension_id| has |
+ // access to the tab with |tab_id|. |
+ int channel_id = GET_CHANNEL_ID(receiver_port_id); |
+ DCHECK(!ContainsKey(pending_dispatches_to_platform_apps_, channel_id)); |
+ pending_dispatches_to_platform_apps_[channel_id] = |
+ std::make_pair(target_extension_id, tab_id); |
+ } else { |
+ source_tab.reset(ExtensionTabUtil::CreateTabValue(source_contents)); |
+ } |
+ } |
source_url_for_tab = source_url; |
} |
@@ -511,6 +522,8 @@ |
const std::string& error_message) { |
// Note: The channel might be gone already, if the other side closed first. |
int channel_id = GET_CHANNEL_ID(port_id); |
+ pending_dispatches_to_platform_apps_.erase(channel_id); |
+ |
MessageChannelMap::iterator it = channels_.find(channel_id); |
if (it == channels_.end()) { |
PendingLazyBackgroundPageChannelMap::iterator pending = |
@@ -549,8 +562,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()) { |
@@ -568,6 +580,18 @@ |
PostMessage(port_id, Message(message, false /* user_gesture */)); |
} |
+bool MessageService::CanPlatformAppAccessTab(const std::string app_id, |
+ int tab_id) const { |
+ for (PendingDispatchesToPlatformAppsMap::const_iterator it = |
+ pending_dispatches_to_platform_apps_.begin(); |
+ it != pending_dispatches_to_platform_apps_.end(); ++it) { |
+ const std::pair<std::string, int>& entry = it->second; |
+ if (entry.first == app_id && entry.second == tab_id) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
void MessageService::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |