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

Side by Side Diff: chrome/browser/extensions/api/messaging/extension_message_port.cc

Issue 2540533002: [Extensions] Remove source/opener tab id from extension ports (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" 5 #include "chrome/browser/extensions/api/messaging/extension_message_port.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/interstitial_page.h" 10 #include "content/public/browser/interstitial_page.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ExtensionMessagePort::ExtensionMessagePort( 92 ExtensionMessagePort::ExtensionMessagePort(
93 base::WeakPtr<MessageService> message_service, 93 base::WeakPtr<MessageService> message_service,
94 int port_id, 94 int port_id,
95 const std::string& extension_id, 95 const std::string& extension_id,
96 content::RenderProcessHost* extension_process) 96 content::RenderProcessHost* extension_process)
97 : weak_message_service_(message_service), 97 : weak_message_service_(message_service),
98 port_id_(port_id), 98 port_id_(port_id),
99 extension_id_(extension_id), 99 extension_id_(extension_id),
100 browser_context_(extension_process->GetBrowserContext()), 100 browser_context_(extension_process->GetBrowserContext()),
101 extension_process_(extension_process), 101 extension_process_(extension_process),
102 opener_tab_id_(-1),
103 did_create_port_(false), 102 did_create_port_(false),
104 background_host_ptr_(nullptr), 103 background_host_ptr_(nullptr),
105 frame_tracker_(new FrameTracker(this)) { 104 frame_tracker_(new FrameTracker(this)) {
106 auto all_hosts = ProcessManager::Get(browser_context_) 105 auto all_hosts = ProcessManager::Get(browser_context_)
107 ->GetRenderFrameHostsForExtension(extension_id); 106 ->GetRenderFrameHostsForExtension(extension_id);
108 for (content::RenderFrameHost* rfh : all_hosts) 107 for (content::RenderFrameHost* rfh : all_hosts)
109 RegisterFrame(rfh); 108 RegisterFrame(rfh);
110 109
111 frame_tracker_->TrackExtensionProcessFrames(); 110 frame_tracker_->TrackExtensionProcessFrames();
112 } 111 }
113 112
114 ExtensionMessagePort::ExtensionMessagePort( 113 ExtensionMessagePort::ExtensionMessagePort(
115 base::WeakPtr<MessageService> message_service, 114 base::WeakPtr<MessageService> message_service,
116 int port_id, 115 int port_id,
117 const std::string& extension_id, 116 const std::string& extension_id,
118 content::RenderFrameHost* rfh, 117 content::RenderFrameHost* rfh,
119 bool include_child_frames) 118 bool include_child_frames)
120 : weak_message_service_(message_service), 119 : weak_message_service_(message_service),
121 port_id_(port_id), 120 port_id_(port_id),
122 extension_id_(extension_id), 121 extension_id_(extension_id),
123 browser_context_(rfh->GetProcess()->GetBrowserContext()), 122 browser_context_(rfh->GetProcess()->GetBrowserContext()),
124 extension_process_(nullptr), 123 extension_process_(nullptr),
125 opener_tab_id_(-1),
126 did_create_port_(false), 124 did_create_port_(false),
127 background_host_ptr_(nullptr), 125 background_host_ptr_(nullptr),
128 frame_tracker_(new FrameTracker(this)) { 126 frame_tracker_(new FrameTracker(this)) {
129 content::WebContents* tab = content::WebContents::FromRenderFrameHost(rfh); 127 content::WebContents* tab = content::WebContents::FromRenderFrameHost(rfh);
130 if (!tab) { 128 if (!tab) {
131 content::InterstitialPage* interstitial = 129 content::InterstitialPage* interstitial =
132 content::InterstitialPage::FromRenderFrameHost(rfh); 130 content::InterstitialPage::FromRenderFrameHost(rfh);
133 // A RenderFrameHost must be hosted in a WebContents or InterstitialPage. 131 // A RenderFrameHost must be hosted in a WebContents or InterstitialPage.
134 CHECK(interstitial); 132 CHECK(interstitial);
135 133
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const std::string& channel_name, 194 const std::string& channel_name,
197 std::unique_ptr<base::DictionaryValue> source_tab, 195 std::unique_ptr<base::DictionaryValue> source_tab,
198 int source_frame_id, 196 int source_frame_id,
199 int guest_process_id, 197 int guest_process_id,
200 int guest_render_frame_routing_id, 198 int guest_render_frame_routing_id,
201 const std::string& source_extension_id, 199 const std::string& source_extension_id,
202 const std::string& target_extension_id, 200 const std::string& target_extension_id,
203 const GURL& source_url, 201 const GURL& source_url,
204 const std::string& tls_channel_id) { 202 const std::string& tls_channel_id) {
205 ExtensionMsg_TabConnectionInfo source; 203 ExtensionMsg_TabConnectionInfo source;
206 if (source_tab) { 204 if (source_tab)
207 source.tab.Swap(source_tab.get()); 205 source.tab.Swap(source_tab.get());
208 source.tab.GetInteger("id", &opener_tab_id_);
209 }
210 source.frame_id = source_frame_id; 206 source.frame_id = source_frame_id;
211 207
212 ExtensionMsg_ExternalConnectionInfo info; 208 ExtensionMsg_ExternalConnectionInfo info;
213 info.target_id = target_extension_id; 209 info.target_id = target_extension_id;
214 info.source_id = source_extension_id; 210 info.source_id = source_extension_id;
215 info.source_url = source_url; 211 info.source_url = source_url;
216 info.guest_process_id = guest_process_id; 212 info.guest_process_id = guest_process_id;
217 info.guest_render_frame_routing_id = guest_render_frame_routing_id; 213 info.guest_render_frame_routing_id = guest_render_frame_routing_id;
218 214
219 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnConnect>( 215 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnConnect>(
220 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id)); 216 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id));
221 } 217 }
222 218
223 void ExtensionMessagePort::DispatchOnDisconnect( 219 void ExtensionMessagePort::DispatchOnDisconnect(
224 const std::string& error_message) { 220 const std::string& error_message) {
225 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnDisconnect>( 221 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnDisconnect>(
226 MSG_ROUTING_NONE, port_id_, error_message)); 222 MSG_ROUTING_NONE, port_id_, error_message));
227 } 223 }
228 224
229 void ExtensionMessagePort::DispatchOnMessage(const Message& message) { 225 void ExtensionMessagePort::DispatchOnMessage(const Message& message) {
230 SendToPort(base::MakeUnique<ExtensionMsg_DeliverMessage>( 226 SendToPort(base::MakeUnique<ExtensionMsg_DeliverMessage>(
231 MSG_ROUTING_NONE, port_id_, opener_tab_id_, message)); 227 MSG_ROUTING_NONE, port_id_, message));
232 } 228 }
233 229
234 void ExtensionMessagePort::IncrementLazyKeepaliveCount() { 230 void ExtensionMessagePort::IncrementLazyKeepaliveCount() {
235 ProcessManager* pm = ProcessManager::Get(browser_context_); 231 ProcessManager* pm = ProcessManager::Get(browser_context_);
236 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); 232 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_);
237 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension())) 233 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension()))
238 pm->IncrementLazyKeepaliveCount(host->extension()); 234 pm->IncrementLazyKeepaliveCount(host->extension());
239 235
240 // Keep track of the background host, so when we decrement, we only do so if 236 // Keep track of the background host, so when we decrement, we only do so if
241 // the host hasn't reloaded. 237 // the host hasn't reloaded.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return; 300 return;
305 } 301 }
306 for (content::RenderFrameHost* rfh : frames_) { 302 for (content::RenderFrameHost* rfh : frames_) {
307 IPC::Message* msg_copy = new IPC::Message(*msg); 303 IPC::Message* msg_copy = new IPC::Message(*msg);
308 msg_copy->set_routing_id(rfh->GetRoutingID()); 304 msg_copy->set_routing_id(rfh->GetRoutingID());
309 rfh->Send(msg_copy); 305 rfh->Send(msg_copy);
310 } 306 }
311 } 307 }
312 308
313 } // namespace extensions 309 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/messaging/extension_message_port.h ('k') | extensions/common/extension_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698