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 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/tab_contents/tab_util.h" | 24 #include "chrome/browser/tab_contents/tab_util.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/render_widget_host.h" | 28 #include "content/public/browser/render_widget_host.h" |
29 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
30 #include "content/public/browser/site_instance.h" | 30 #include "content/public/browser/site_instance.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "extensions/browser/extension_host.h" | 32 #include "extensions/browser/extension_host.h" |
33 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 34 #include "extensions/browser/extension_util.h" |
34 #include "extensions/browser/extensions_browser_client.h" | 35 #include "extensions/browser/extensions_browser_client.h" |
35 #include "extensions/browser/lazy_background_task_queue.h" | 36 #include "extensions/browser/lazy_background_task_queue.h" |
36 #include "extensions/browser/process_manager.h" | 37 #include "extensions/browser/process_manager.h" |
37 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
38 #include "extensions/common/extension_messages.h" | 39 #include "extensions/common/extension_messages.h" |
39 #include "extensions/common/manifest_constants.h" | 40 #include "extensions/common/manifest_constants.h" |
40 #include "extensions/common/manifest_handlers/background_info.h" | 41 #include "extensions/common/manifest_handlers/background_info.h" |
41 #include "extensions/common/manifest_handlers/externally_connectable.h" | 42 #include "extensions/common/manifest_handlers/externally_connectable.h" |
42 #include "extensions/common/manifest_handlers/incognito_info.h" | 43 #include "extensions/common/manifest_handlers/incognito_info.h" |
43 #include "net/base/completion_callback.h" | 44 #include "net/base/completion_callback.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 const Extension* target_extension = extension_system->extension_service()-> | 210 const Extension* target_extension = extension_system->extension_service()-> |
210 extensions()->GetByID(target_extension_id); | 211 extensions()->GetByID(target_extension_id); |
211 if (!target_extension) { | 212 if (!target_extension) { |
212 DispatchOnDisconnect( | 213 DispatchOnDisconnect( |
213 source, receiver_port_id, kReceivingEndDoesntExistError); | 214 source, receiver_port_id, kReceivingEndDoesntExistError); |
214 return; | 215 return; |
215 } | 216 } |
216 | 217 |
217 // Only running ephemeral apps can receive messages. Idle cached ephemeral | 218 // Only running ephemeral apps can receive messages. Idle cached ephemeral |
218 // apps are invisible and should not be connectable. | 219 // apps are invisible and should not be connectable. |
219 if (target_extension->is_ephemeral() && | 220 if (util::IsEphemeralApp(target_extension_id, context) && |
220 util::IsExtensionIdle(target_extension_id, context)) { | 221 util::IsExtensionIdle(target_extension_id, context)) { |
221 DispatchOnDisconnect( | 222 DispatchOnDisconnect( |
222 source, receiver_port_id, kReceivingEndDoesntExistError); | 223 source, receiver_port_id, kReceivingEndDoesntExistError); |
223 return; | 224 return; |
224 } | 225 } |
225 | 226 |
226 bool is_web_connection = false; | 227 bool is_web_connection = false; |
227 | 228 |
228 if (source_extension_id != target_extension_id) { | 229 if (source_extension_id != target_extension_id) { |
229 // It's an external connection. Check the externally_connectable manifest | 230 // It's an external connection. Check the externally_connectable manifest |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 764 } |
764 | 765 |
765 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 766 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
766 int port_id, | 767 int port_id, |
767 const std::string& error_message) { | 768 const std::string& error_message) { |
768 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 769 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
769 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 770 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
770 } | 771 } |
771 | 772 |
772 } // namespace extensions | 773 } // namespace extensions |
OLD | NEW |