| 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, | 165 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); |
| 166 profile->GetExtensionService()->extensions()->GetByID( | |
| 167 source_extension_id))); | |
| 168 base::JSONWriter::Write(tab_value.get(), &tab_json); | 166 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 169 } | 167 } |
| 170 | 168 |
| 171 OpenChannelParams* params = new OpenChannelParams(source, tab_json, receiver, | 169 OpenChannelParams* params = new OpenChannelParams(source, tab_json, receiver, |
| 172 receiver_port_id, | 170 receiver_port_id, |
| 173 source_extension_id, | 171 source_extension_id, |
| 174 target_extension_id, | 172 target_extension_id, |
| 175 channel_name); | 173 channel_name); |
| 176 | 174 |
| 177 // 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 11 matching lines...) Expand all Loading... |
| 189 int source_routing_id, | 187 int source_routing_id, |
| 190 int receiver_port_id, | 188 int receiver_port_id, |
| 191 const std::string& source_extension_id, | 189 const std::string& source_extension_id, |
| 192 const std::string& native_app_name, | 190 const std::string& native_app_name, |
| 193 const std::string& channel_name, | 191 const std::string& channel_name, |
| 194 const std::string& connect_message) { | 192 const std::string& connect_message) { |
| 195 content::RenderProcessHost* source = | 193 content::RenderProcessHost* source = |
| 196 content::RenderProcessHost::FromID(source_process_id); | 194 content::RenderProcessHost::FromID(source_process_id); |
| 197 if (!source) | 195 if (!source) |
| 198 return; | 196 return; |
| 199 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); | |
| 200 | 197 |
| 201 WebContents* source_contents = tab_util::GetWebContentsByID( | 198 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 202 source_process_id, source_routing_id); | 199 source_process_id, source_routing_id); |
| 203 | 200 |
| 204 // 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). |
| 205 std::string tab_json = "null"; | 202 std::string tab_json = "null"; |
| 206 if (source_contents) { | 203 if (source_contents) { |
| 207 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 204 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 208 source_contents, | 205 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); |
| 209 profile->GetExtensionService()->extensions()->GetByID( | |
| 210 source_extension_id))); | |
| 211 base::JSONWriter::Write(tab_value.get(), &tab_json); | 206 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 212 } | 207 } |
| 213 | 208 |
| 214 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 209 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
| 215 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
| 216 source_extension_id)); | 211 source_extension_id)); |
| 217 | 212 |
| 218 NativeMessageProcessHost::MessageType type = | 213 NativeMessageProcessHost::MessageType type = |
| 219 channel_name == "chrome.extension.sendNativeMessage" ? | 214 channel_name == "chrome.extension.sendNativeMessage" ? |
| 220 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : | 215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return; | 280 return; |
| 286 } | 281 } |
| 287 | 282 |
| 288 WebContents* source_contents = tab_util::GetWebContentsByID( | 283 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 289 source_process_id, source_routing_id); | 284 source_process_id, source_routing_id); |
| 290 | 285 |
| 291 // 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). |
| 292 std::string tab_json = "null"; | 287 std::string tab_json = "null"; |
| 293 if (source_contents) { | 288 if (source_contents) { |
| 294 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 289 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 295 source_contents, | 290 source_contents, ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS)); |
| 296 profile->GetExtensionService()->extensions()->GetByID( | |
| 297 extension_id))); | |
| 298 base::JSONWriter::Write(tab_value.get(), &tab_json); | 291 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 299 } | 292 } |
| 300 | 293 |
| 301 scoped_ptr<OpenChannelParams> params(new OpenChannelParams(source, tab_json, | 294 scoped_ptr<OpenChannelParams> params(new OpenChannelParams(source, tab_json, |
| 302 receiver.release(), | 295 receiver.release(), |
| 303 receiver_port_id, | 296 receiver_port_id, |
| 304 extension_id, | 297 extension_id, |
| 305 extension_id, | 298 extension_id, |
| 306 channel_name)); | 299 channel_name)); |
| 307 OpenChannelImpl(params.Pass()); | 300 OpenChannelImpl(params.Pass()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 return; | 499 return; |
| 507 | 500 |
| 508 params->source = source; | 501 params->source = source; |
| 509 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 502 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 510 MSG_ROUTING_CONTROL, | 503 MSG_ROUTING_CONTROL, |
| 511 params->target_extension_id)); | 504 params->target_extension_id)); |
| 512 OpenChannelImpl(params.Pass()); | 505 OpenChannelImpl(params.Pass()); |
| 513 } | 506 } |
| 514 | 507 |
| 515 } // namespace extensions | 508 } // namespace extensions |
| OLD | NEW |