| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 "Native Messaging is not supported on this platform."; | 63 "Native Messaging is not supported on this platform."; |
| 64 } | 64 } |
| 65 | 65 |
| 66 struct MessageService::MessageChannel { | 66 struct MessageService::MessageChannel { |
| 67 scoped_ptr<MessagePort> opener; | 67 scoped_ptr<MessagePort> opener; |
| 68 scoped_ptr<MessagePort> receiver; | 68 scoped_ptr<MessagePort> receiver; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 struct MessageService::OpenChannelParams { | 71 struct MessageService::OpenChannelParams { |
| 72 content::RenderProcessHost* source; | 72 content::RenderProcessHost* source; |
| 73 DictionaryValue source_tab; | 73 base::DictionaryValue source_tab; |
| 74 scoped_ptr<MessagePort> receiver; | 74 scoped_ptr<MessagePort> receiver; |
| 75 int receiver_port_id; | 75 int receiver_port_id; |
| 76 std::string source_extension_id; | 76 std::string source_extension_id; |
| 77 std::string target_extension_id; | 77 std::string target_extension_id; |
| 78 GURL source_url; | 78 GURL source_url; |
| 79 std::string channel_name; | 79 std::string channel_name; |
| 80 | 80 |
| 81 // Takes ownership of receiver. | 81 // Takes ownership of receiver. |
| 82 OpenChannelParams(content::RenderProcessHost* source, | 82 OpenChannelParams(content::RenderProcessHost* source, |
| 83 scoped_ptr<DictionaryValue> source_tab, | 83 scoped_ptr<base::DictionaryValue> source_tab, |
| 84 MessagePort* receiver, | 84 MessagePort* receiver, |
| 85 int receiver_port_id, | 85 int receiver_port_id, |
| 86 const std::string& source_extension_id, | 86 const std::string& source_extension_id, |
| 87 const std::string& target_extension_id, | 87 const std::string& target_extension_id, |
| 88 const GURL& source_url, | 88 const GURL& source_url, |
| 89 const std::string& channel_name) | 89 const std::string& channel_name) |
| 90 : source(source), | 90 : source(source), |
| 91 receiver(receiver), | 91 receiver(receiver), |
| 92 receiver_port_id(receiver_port_id), | 92 receiver_port_id(receiver_port_id), |
| 93 source_extension_id(source_extension_id), | 93 source_extension_id(source_extension_id), |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Note: we use the source's profile here. If the source is an incognito | 233 // Note: we use the source's profile here. If the source is an incognito |
| 234 // process, we will use the incognito EPM to find the right extension process, | 234 // process, we will use the incognito EPM to find the right extension process, |
| 235 // which depends on whether the extension uses spanning or split mode. | 235 // which depends on whether the extension uses spanning or split mode. |
| 236 MessagePort* receiver = new ExtensionMessagePort( | 236 MessagePort* receiver = new ExtensionMessagePort( |
| 237 GetExtensionProcess(profile, target_extension_id), MSG_ROUTING_CONTROL, | 237 GetExtensionProcess(profile, target_extension_id), MSG_ROUTING_CONTROL, |
| 238 target_extension_id); | 238 target_extension_id); |
| 239 WebContents* source_contents = tab_util::GetWebContentsByID( | 239 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 240 source_process_id, source_routing_id); | 240 source_process_id, source_routing_id); |
| 241 | 241 |
| 242 // Include info about the opener's tab (if it was a tab). | 242 // Include info about the opener's tab (if it was a tab). |
| 243 scoped_ptr<DictionaryValue> source_tab; | 243 scoped_ptr<base::DictionaryValue> source_tab; |
| 244 GURL source_url_for_tab; | 244 GURL source_url_for_tab; |
| 245 | 245 |
| 246 if (source_contents && ExtensionTabUtil::GetTabId(source_contents) >= 0) { | 246 if (source_contents && ExtensionTabUtil::GetTabId(source_contents) >= 0) { |
| 247 // Platform apps can be sent messages, but don't have a Tab concept. | 247 // Platform apps can be sent messages, but don't have a Tab concept. |
| 248 if (!target_extension->is_platform_app()) | 248 if (!target_extension->is_platform_app()) |
| 249 source_tab.reset(ExtensionTabUtil::CreateTabValue(source_contents)); | 249 source_tab.reset(ExtensionTabUtil::CreateTabValue(source_contents)); |
| 250 source_url_for_tab = source_url; | 250 source_url_for_tab = source_url; |
| 251 } | 251 } |
| 252 | 252 |
| 253 OpenChannelParams* params = new OpenChannelParams(source, | 253 OpenChannelParams* params = new OpenChannelParams(source, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 if (contents && contents->GetController().NeedsReload()) { | 349 if (contents && contents->GetController().NeedsReload()) { |
| 350 // The tab isn't loaded yet. Don't attempt to connect. | 350 // The tab isn't loaded yet. Don't attempt to connect. |
| 351 DispatchOnDisconnect( | 351 DispatchOnDisconnect( |
| 352 source, receiver_port_id, kReceivingEndDoesntExistError); | 352 source, receiver_port_id, kReceivingEndDoesntExistError); |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 | 355 |
| 356 scoped_ptr<OpenChannelParams> params(new OpenChannelParams( | 356 scoped_ptr<OpenChannelParams> params(new OpenChannelParams( |
| 357 source, | 357 source, |
| 358 scoped_ptr<DictionaryValue>(), // Source tab doesn't make sense for | 358 scoped_ptr<base::DictionaryValue>(), // Source tab doesn't make sense |
| 359 // opening to tabs. | 359 // for opening to tabs. |
| 360 receiver.release(), | 360 receiver.release(), |
| 361 receiver_port_id, | 361 receiver_port_id, |
| 362 extension_id, | 362 extension_id, |
| 363 extension_id, | 363 extension_id, |
| 364 GURL(), // Source URL doesn't make sense for opening to tabs. | 364 GURL(), // Source URL doesn't make sense for opening to tabs. |
| 365 channel_name)); | 365 channel_name)); |
| 366 OpenChannelImpl(params.Pass()); | 366 OpenChannelImpl(params.Pass()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) { | 369 bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 575 } |
| 576 | 576 |
| 577 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 577 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
| 578 int port_id, | 578 int port_id, |
| 579 const std::string& error_message) { | 579 const std::string& error_message) { |
| 580 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 580 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
| 581 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 581 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace extensions | 584 } // namespace extensions |
| OLD | NEW |