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

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

Issue 1588533002: Never connect a port to the same frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also rename invocation of WillConnectToPort Created 4 years, 11 months 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/scoped_observer.h" 7 #include "base/scoped_observer.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/navigation_details.h" 9 #include "content/public/browser/navigation_details.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (include_child_frames) { 107 if (include_child_frames) {
108 tab->ForEachFrame(base::Bind(&ExtensionMessagePort::RegisterFrame, 108 tab->ForEachFrame(base::Bind(&ExtensionMessagePort::RegisterFrame,
109 base::Unretained(this))); 109 base::Unretained(this)));
110 } else { 110 } else {
111 RegisterFrame(rfh); 111 RegisterFrame(rfh);
112 } 112 }
113 } 113 }
114 114
115 ExtensionMessagePort::~ExtensionMessagePort() {} 115 ExtensionMessagePort::~ExtensionMessagePort() {}
116 116
117 void ExtensionMessagePort::RemoveCommonFrames(const MessagePort& port) {
118 // Avoid overlap in the set of frames to make sure that it does not matter
119 // when UnregisterFrame is called.
120 for (std::set<content::RenderFrameHost*>::iterator it = frames_.begin();
121 it != frames_.end(); ) {
122 if (port.HasFrame(*it)) {
123 frames_.erase(it++);
124 } else {
125 ++it;
126 }
127 }
128 }
129
130 bool ExtensionMessagePort::HasFrame(content::RenderFrameHost* rfh) const {
131 return frames_.find(rfh) != frames_.end();
132 }
133
117 bool ExtensionMessagePort::IsValidPort() { 134 bool ExtensionMessagePort::IsValidPort() {
118 return !frames_.empty(); 135 return !frames_.empty();
119 } 136 }
120 137
121 void ExtensionMessagePort::DispatchOnConnect( 138 void ExtensionMessagePort::DispatchOnConnect(
122 const std::string& channel_name, 139 const std::string& channel_name,
123 scoped_ptr<base::DictionaryValue> source_tab, 140 scoped_ptr<base::DictionaryValue> source_tab,
124 int source_frame_id, 141 int source_frame_id,
125 int guest_process_id, 142 int guest_process_id,
126 int guest_render_frame_routing_id, 143 int guest_render_frame_routing_id,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 return; 245 return;
229 } 246 }
230 for (content::RenderFrameHost* rfh : frames_) { 247 for (content::RenderFrameHost* rfh : frames_) {
231 IPC::Message* msg_copy = new IPC::Message(*msg.get()); 248 IPC::Message* msg_copy = new IPC::Message(*msg.get());
232 msg_copy->set_routing_id(rfh->GetRoutingID()); 249 msg_copy->set_routing_id(rfh->GetRoutingID());
233 rfh->Send(msg_copy); 250 rfh->Send(msg_copy);
234 } 251 }
235 } 252 }
236 253
237 } // namespace extensions 254 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698