| 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/message_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 MessagePort* receiver = new ExtensionMessagePort( | 155 MessagePort* receiver = new ExtensionMessagePort( |
| 156 GetExtensionProcess(profile, target_extension_id), MSG_ROUTING_CONTROL, | 156 GetExtensionProcess(profile, target_extension_id), MSG_ROUTING_CONTROL, |
| 157 target_extension_id); | 157 target_extension_id); |
| 158 WebContents* source_contents = tab_util::GetWebContentsByID( | 158 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 159 source_process_id, source_routing_id); | 159 source_process_id, source_routing_id); |
| 160 | 160 |
| 161 // Include info about the opener's tab (if it was a tab). | 161 // Include info about the opener's tab (if it was a tab). |
| 162 std::string tab_json = "null"; | 162 std::string tab_json = "null"; |
| 163 if (source_contents) { | 163 if (source_contents) { |
| 164 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 164 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 165 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); | 165 source_contents)); |
| 166 base::JSONWriter::Write(tab_value.get(), &tab_json); | 166 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 167 } | 167 } |
| 168 | 168 |
| 169 OpenChannelParams* params = new OpenChannelParams(source, tab_json, receiver, | 169 OpenChannelParams* params = new OpenChannelParams(source, tab_json, receiver, |
| 170 receiver_port_id, | 170 receiver_port_id, |
| 171 source_extension_id, | 171 source_extension_id, |
| 172 target_extension_id, | 172 target_extension_id, |
| 173 channel_name); | 173 channel_name); |
| 174 | 174 |
| 175 // The target might be a lazy background page. In that case, we have to check | 175 // The target might be a lazy background page. In that case, we have to check |
| (...skipping 19 matching lines...) Expand all Loading... |
| 195 if (!source) | 195 if (!source) |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 WebContents* source_contents = tab_util::GetWebContentsByID( | 198 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 199 source_process_id, source_routing_id); | 199 source_process_id, source_routing_id); |
| 200 | 200 |
| 201 // Include info about the opener's tab (if it was a tab). | 201 // Include info about the opener's tab (if it was a tab). |
| 202 std::string tab_json = "null"; | 202 std::string tab_json = "null"; |
| 203 if (source_contents) { | 203 if (source_contents) { |
| 204 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 204 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 205 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); | 205 source_contents)); |
| 206 base::JSONWriter::Write(tab_value.get(), &tab_json); | 206 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 207 } | 207 } |
| 208 | 208 |
| 209 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 209 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
| 210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
| 211 source_extension_id)); | 211 source_extension_id)); |
| 212 | 212 |
| 213 NativeMessageProcessHost::MessageType type = | 213 NativeMessageProcessHost::MessageType type = |
| 214 channel_name == "chrome.runtime.sendNativeMessage" ? | 214 channel_name == "chrome.runtime.sendNativeMessage" ? |
| 215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : | 215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 WebContents* source_contents = tab_util::GetWebContentsByID( | 283 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 284 source_process_id, source_routing_id); | 284 source_process_id, source_routing_id); |
| 285 | 285 |
| 286 // Include info about the opener's tab (if it was a tab). | 286 // Include info about the opener's tab (if it was a tab). |
| 287 std::string tab_json = "null"; | 287 std::string tab_json = "null"; |
| 288 if (source_contents) { | 288 if (source_contents) { |
| 289 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 289 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 290 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); | 290 source_contents)); |
| 291 base::JSONWriter::Write(tab_value.get(), &tab_json); | 291 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 292 } | 292 } |
| 293 | 293 |
| 294 scoped_ptr<OpenChannelParams> params(new OpenChannelParams(source, tab_json, | 294 scoped_ptr<OpenChannelParams> params(new OpenChannelParams(source, tab_json, |
| 295 receiver.release(), | 295 receiver.release(), |
| 296 receiver_port_id, | 296 receiver_port_id, |
| 297 extension_id, | 297 extension_id, |
| 298 extension_id, | 298 extension_id, |
| 299 channel_name)); | 299 channel_name)); |
| 300 OpenChannelImpl(params.Pass()); | 300 OpenChannelImpl(params.Pass()); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return; | 500 return; |
| 501 | 501 |
| 502 params->source = source; | 502 params->source = source; |
| 503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 504 MSG_ROUTING_CONTROL, | 504 MSG_ROUTING_CONTROL, |
| 505 params->target_extension_id)); | 505 params->target_extension_id)); |
| 506 OpenChannelImpl(params.Pass()); | 506 OpenChannelImpl(params.Pass()); |
| 507 } | 507 } |
| 508 | 508 |
| 509 } // namespace extensions | 509 } // namespace extensions |
| OLD | NEW |