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

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: User scoped_ptr instead of ref, refactor test 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..b1bac33b3d5462576c34d0149a09d64fc15f8fe0 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"
@@ -118,7 +119,8 @@ struct MessageService::MessageChannel {
struct MessageService::OpenChannelParams {
content::RenderProcessHost* source;
- base::DictionaryValue source_tab;
+ scoped_ptr<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),
@@ -147,7 +151,7 @@ struct MessageService::OpenChannelParams {
channel_name(channel_name),
include_tls_channel_id(include_tls_channel_id) {
if (source_tab)
- this->source_tab.Swap(source_tab.get());
+ this->source_tab.reset(source_tab.Pass());
not at google - send to devlin 2014/11/12 01:02:46 you can just use = (not .reset())
robwu 2014/11/12 10:00:21 Done.
}
private:
@@ -332,15 +336,20 @@ 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));
+ content::RenderFrameHost* rfh =
+ content::RenderFrameHost::FromID(source_process_id, source_routing_id);
+ // Main frame's frameId is 0.
+ source_frame_id = (rfh && !rfh->GetParent()) ? 0 : source_routing_id;
}
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 +489,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,
@@ -521,7 +531,8 @@ bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) {
// opener has the opposite port ID).
channel->receiver->DispatchOnConnect(params->receiver_port_id,
params->channel_name,
- params->source_tab,
+ params->source_tab.Pass(),
+ params->source_frame_id,
params->source_extension_id,
params->target_extension_id,
params->source_url,

Powered by Google App Engine
This is Rietveld 408576698