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/extension_message_service.h" | 5 #include "chrome/browser/extensions/extension_message_service.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (!source) | 192 if (!source) |
193 return; | 193 return; |
194 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); | 194 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); |
195 | 195 |
196 TabContentsWrapper* contents = NULL; | 196 TabContentsWrapper* contents = NULL; |
197 MessagePort receiver; | 197 MessagePort receiver; |
198 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, | 198 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, |
199 NULL, NULL, &contents, NULL)) { | 199 NULL, NULL, &contents, NULL)) { |
200 receiver.sender = contents->web_contents()->GetRenderViewHost(); | 200 receiver.sender = contents->web_contents()->GetRenderViewHost(); |
201 receiver.routing_id = | 201 receiver.routing_id = |
202 contents->web_contents()->GetRenderViewHost()->routing_id(); | 202 contents->web_contents()->GetRenderViewHost()->GetRoutingID(); |
203 } | 203 } |
204 | 204 |
205 if (contents && contents->web_contents()->GetController().NeedsReload()) { | 205 if (contents && contents->web_contents()->GetController().NeedsReload()) { |
206 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a | 206 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a |
207 // disconnect. | 207 // disconnect. |
208 DispatchOnDisconnect(MessagePort(source, MSG_ROUTING_CONTROL), | 208 DispatchOnDisconnect(MessagePort(source, MSG_ROUTING_CONTROL), |
209 GET_OPPOSITE_PORT_ID(receiver_port_id), true); | 209 GET_OPPOSITE_PORT_ID(receiver_port_id), true); |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return -1; | 295 return -1; |
296 } | 296 } |
297 | 297 |
298 int port1_id = -1; | 298 int port1_id = -1; |
299 int port2_id = -1; | 299 int port2_id = -1; |
300 // Create a channel ID for both sides of the channel. | 300 // Create a channel ID for both sides of the channel. |
301 AllocatePortIdPair(&port1_id, &port2_id); | 301 AllocatePortIdPair(&port1_id, &port2_id); |
302 | 302 |
303 MessagePort receiver( | 303 MessagePort receiver( |
304 target_web_contents->GetRenderViewHost(), | 304 target_web_contents->GetRenderViewHost(), |
305 target_web_contents->GetRenderViewHost()->routing_id()); | 305 target_web_contents->GetRenderViewHost()->GetRoutingID()); |
306 if (!OpenChannelImpl(source, "null", receiver, port2_id, | 306 if (!OpenChannelImpl(source, "null", receiver, port2_id, |
307 extension_id, extension_id, channel_name)) | 307 extension_id, extension_id, channel_name)) |
308 return -1; | 308 return -1; |
309 | 309 |
310 return port1_id; | 310 return port1_id; |
311 } | 311 } |
312 | 312 |
313 void ExtensionMessageService::CloseChannel(int port_id) { | 313 void ExtensionMessageService::CloseChannel(int port_id) { |
314 // Note: The channel might be gone already, if the other side closed first. | 314 // Note: The channel might be gone already, if the other side closed first. |
315 MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id)); | 315 MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 if (current->second->opener.sender == sender) { | 379 if (current->second->opener.sender == sender) { |
380 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), | 380 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), |
381 notify_other_port); | 381 notify_other_port); |
382 } else if (current->second->receiver.sender == sender) { | 382 } else if (current->second->receiver.sender == sender) { |
383 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), | 383 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), |
384 notify_other_port); | 384 notify_other_port); |
385 } | 385 } |
386 } | 386 } |
387 } | 387 } |
OLD | NEW |