Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Unified Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 709933002: Add frameId to MessageSender (extension messaging API) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Generate frameId in browser Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/message_service.cc
diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc
index 68fa08626c5da3eff0e0bf84a630f88e16f384fd..f467f630473bf75f1ec4acdf21cd011dacd85a28 100644
--- a/chrome/browser/extensions/api/messaging/message_service.cc
+++ b/chrome/browser/extensions/api/messaging/message_service.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
@@ -119,6 +120,7 @@ struct MessageService::MessageChannel {
struct MessageService::OpenChannelParams {
content::RenderProcessHost* source;
base::DictionaryValue source_tab;
+ int source_frame_id;
scoped_ptr<MessagePort> receiver;
int receiver_port_id;
std::string source_extension_id;
@@ -131,6 +133,7 @@ struct MessageService::OpenChannelParams {
// Takes ownership of receiver.
OpenChannelParams(content::RenderProcessHost* source,
scoped_ptr<base::DictionaryValue> source_tab,
+ int source_frame_id,
MessagePort* receiver,
int receiver_port_id,
const std::string& source_extension_id,
@@ -139,6 +142,7 @@ struct MessageService::OpenChannelParams {
const std::string& channel_name,
bool include_tls_channel_id)
: source(source),
+ source_frame_id(source_frame_id),
receiver(receiver),
receiver_port_id(receiver_port_id),
source_extension_id(source_extension_id),
@@ -332,15 +336,21 @@ void MessageService::OpenChannelToExtension(
// Include info about the opener's tab (if it was a tab).
scoped_ptr<base::DictionaryValue> source_tab;
+ int source_frame_id = -1;
if (source_contents && ExtensionTabUtil::GetTabId(source_contents) >= 0) {
// 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));
+ int source_frame_id = source_routing_id;
not at google - send to devlin 2014/11/11 00:03:04 It looks like this declaration will shadow the dec
robwu 2014/11/11 00:34:26 Done.
+ RenderFrameHost* rfh = RenderFrameHost::FromID(source_frame_id,
+ source_routing_id);
+ // Main frame's frameId is 0.
+ source_frame_id = rfh && !rfh.GetParent() ? 0 : source_routing_id;
not at google - send to devlin 2014/11/11 00:03:04 I would find this a bit easier to read with parens
robwu 2014/11/11 00:34:26 Done.
}
OpenChannelParams* params = new OpenChannelParams(
- source, source_tab.Pass(), receiver, receiver_port_id,
+ source, source_tab.Pass(), source_frame_id, receiver, receiver_port_id,
source_extension_id, target_extension_id, source_url, channel_name,
include_tls_channel_id);
@@ -480,6 +490,7 @@ void MessageService::OpenChannelToTab(
source,
scoped_ptr<base::DictionaryValue>(), // Source tab doesn't make sense
// for opening to tabs.
+ -1, // If there is no tab, then there is no frame either.
receiver.release(),
receiver_port_id,
extension_id,
@@ -522,6 +533,7 @@ bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) {
channel->receiver->DispatchOnConnect(params->receiver_port_id,
params->channel_name,
params->source_tab,
+ params->source_frame_id,
params->source_extension_id,
params->target_extension_id,
params->source_url,

Powered by Google App Engine
This is Rietveld 408576698