OLD | NEW |
---|---|
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" |
11 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/common/child_process_host.h" | |
16 #include "extensions/browser/extension_host.h" | 17 #include "extensions/browser/extension_host.h" |
17 #include "extensions/browser/process_manager.h" | 18 #include "extensions/browser/process_manager.h" |
18 #include "extensions/browser/process_manager_observer.h" | 19 #include "extensions/browser/process_manager_observer.h" |
19 #include "extensions/common/extension_messages.h" | 20 #include "extensions/common/extension_messages.h" |
20 #include "extensions/common/manifest_handlers/background_info.h" | 21 #include "extensions/common/manifest_handlers/background_info.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 const char kReceivingEndDoesntExistError[] = | 25 const char kReceivingEndDoesntExistError[] = |
25 "Could not establish connection. Receiving end does not exist."; | 26 "Could not establish connection. Receiving end does not exist."; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } | 190 } |
190 | 191 |
191 bool ExtensionMessagePort::IsValidPort() { | 192 bool ExtensionMessagePort::IsValidPort() { |
192 return !frames_.empty(); | 193 return !frames_.empty(); |
193 } | 194 } |
194 | 195 |
195 void ExtensionMessagePort::DispatchOnConnect( | 196 void ExtensionMessagePort::DispatchOnConnect( |
196 const std::string& channel_name, | 197 const std::string& channel_name, |
197 std::unique_ptr<base::DictionaryValue> source_tab, | 198 std::unique_ptr<base::DictionaryValue> source_tab, |
198 int source_frame_id, | 199 int source_frame_id, |
199 int guest_process_id, | 200 bool include_guest_process_info, |
200 int guest_render_frame_routing_id, | 201 int source_process_id, |
202 int source_render_frame_routing_id, | |
201 const std::string& source_extension_id, | 203 const std::string& source_extension_id, |
202 const std::string& target_extension_id, | 204 const std::string& target_extension_id, |
203 const GURL& source_url, | 205 const GURL& source_url, |
204 const std::string& tls_channel_id) { | 206 const std::string& tls_channel_id) { |
205 ExtensionMsg_TabConnectionInfo source; | 207 ExtensionMsg_TabConnectionInfo source; |
206 if (source_tab) { | 208 if (source_tab) { |
207 source.tab.Swap(source_tab.get()); | 209 source.tab.Swap(source_tab.get()); |
208 source.tab.GetInteger("id", &opener_tab_id_); | 210 source.tab.GetInteger("id", &opener_tab_id_); |
209 } | 211 } |
210 source.frame_id = source_frame_id; | 212 source.frame_id = source_frame_id; |
211 | 213 |
212 ExtensionMsg_ExternalConnectionInfo info; | 214 ExtensionMsg_ExternalConnectionInfo info; |
213 info.target_id = target_extension_id; | 215 info.target_id = target_extension_id; |
214 info.source_id = source_extension_id; | 216 info.source_id = source_extension_id; |
215 info.source_url = source_url; | 217 info.source_url = source_url; |
216 info.guest_process_id = guest_process_id; | 218 info.guest_process_id = include_guest_process_info |
dcheng
2016/11/27 01:08:18
I thought we try not to plumb process ID informati
| |
217 info.guest_render_frame_routing_id = guest_render_frame_routing_id; | 219 ? source_process_id |
220 : content::ChildProcessHost::kInvalidUniqueID; | |
221 info.source_render_frame_routing_id = source_render_frame_routing_id; | |
222 // As an optimization, SendToPort will broadcast messages targeting extensions | |
223 // to the extension process instead of its individual frames. As a result, if | |
224 // the sender is also in the extension process, it will also be notified. This | |
225 // flag (together with |source_render_frame_routing_id|) is used to avoid | |
226 // unnecessarily dispatching onConnect to the sending frame in this case. | |
227 info.source_is_in_same_process = | |
228 extension_process_ && extension_process_->GetID() == source_process_id; | |
218 | 229 |
219 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnConnect>( | 230 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnConnect>( |
220 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id)); | 231 MSG_ROUTING_NONE, port_id_, channel_name, source, info, tls_channel_id)); |
221 } | 232 } |
222 | 233 |
223 void ExtensionMessagePort::DispatchOnDisconnect( | 234 void ExtensionMessagePort::DispatchOnDisconnect( |
224 const std::string& error_message) { | 235 const std::string& error_message) { |
225 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnDisconnect>( | 236 SendToPort(base::MakeUnique<ExtensionMsg_DispatchOnDisconnect>( |
226 MSG_ROUTING_NONE, port_id_, error_message)); | 237 MSG_ROUTING_NONE, port_id_, error_message)); |
227 } | 238 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 return; | 315 return; |
305 } | 316 } |
306 for (content::RenderFrameHost* rfh : frames_) { | 317 for (content::RenderFrameHost* rfh : frames_) { |
307 IPC::Message* msg_copy = new IPC::Message(*msg); | 318 IPC::Message* msg_copy = new IPC::Message(*msg); |
308 msg_copy->set_routing_id(rfh->GetRoutingID()); | 319 msg_copy->set_routing_id(rfh->GetRoutingID()); |
309 rfh->Send(msg_copy); | 320 rfh->Send(msg_copy); |
310 } | 321 } |
311 } | 322 } |
312 | 323 |
313 } // namespace extensions | 324 } // namespace extensions |
OLD | NEW |