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