| 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" | |
| 35 #include "extensions/browser/extensions_browser_client.h" | 34 #include "extensions/browser/extensions_browser_client.h" |
| 36 #include "extensions/browser/lazy_background_task_queue.h" | 35 #include "extensions/browser/lazy_background_task_queue.h" |
| 37 #include "extensions/browser/process_manager.h" | 36 #include "extensions/browser/process_manager.h" |
| 38 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/extension_messages.h" | 38 #include "extensions/common/extension_messages.h" |
| 40 #include "extensions/common/manifest_constants.h" | 39 #include "extensions/common/manifest_constants.h" |
| 41 #include "extensions/common/manifest_handlers/background_info.h" | 40 #include "extensions/common/manifest_handlers/background_info.h" |
| 42 #include "extensions/common/manifest_handlers/externally_connectable.h" | 41 #include "extensions/common/manifest_handlers/externally_connectable.h" |
| 43 #include "extensions/common/manifest_handlers/incognito_info.h" | 42 #include "extensions/common/manifest_handlers/incognito_info.h" |
| 44 #include "extensions/common/permissions/permissions_data.h" | 43 #include "extensions/common/permissions/permissions_data.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ExtensionSystem* extension_system = ExtensionSystem::Get(context); | 208 ExtensionSystem* extension_system = ExtensionSystem::Get(context); |
| 210 DCHECK(extension_system); | 209 DCHECK(extension_system); |
| 211 const Extension* target_extension = extension_system->extension_service()-> | 210 const Extension* target_extension = extension_system->extension_service()-> |
| 212 extensions()->GetByID(target_extension_id); | 211 extensions()->GetByID(target_extension_id); |
| 213 if (!target_extension) { | 212 if (!target_extension) { |
| 214 DispatchOnDisconnect( | 213 DispatchOnDisconnect( |
| 215 source, receiver_port_id, kReceivingEndDoesntExistError); | 214 source, receiver_port_id, kReceivingEndDoesntExistError); |
| 216 return; | 215 return; |
| 217 } | 216 } |
| 218 | 217 |
| 219 // Only running ephemeral apps can receive messages. Idle cached ephemeral | |
| 220 // apps are invisible and should not be connectable. | |
| 221 if (util::IsEphemeralApp(target_extension_id, context) && | |
| 222 util::IsExtensionIdle(target_extension_id, context)) { | |
| 223 DispatchOnDisconnect( | |
| 224 source, receiver_port_id, kReceivingEndDoesntExistError); | |
| 225 return; | |
| 226 } | |
| 227 | |
| 228 bool is_web_connection = false; | 218 bool is_web_connection = false; |
| 229 | 219 |
| 230 if (source_extension_id != target_extension_id) { | 220 if (source_extension_id != target_extension_id) { |
| 231 // It's an external connection. Check the externally_connectable manifest | 221 // It's an external connection. Check the externally_connectable manifest |
| 232 // key if it's present. If it's not, we allow connection from any extension | 222 // key if it's present. If it's not, we allow connection from any extension |
| 233 // but not webpages. | 223 // but not webpages. |
| 234 ExternallyConnectableInfo* externally_connectable = | 224 ExternallyConnectableInfo* externally_connectable = |
| 235 static_cast<ExternallyConnectableInfo*>( | 225 static_cast<ExternallyConnectableInfo*>( |
| 236 target_extension->GetManifestData( | 226 target_extension->GetManifestData( |
| 237 manifest_keys::kExternallyConnectable)); | 227 manifest_keys::kExternallyConnectable)); |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 } | 756 } |
| 767 | 757 |
| 768 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 758 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
| 769 int port_id, | 759 int port_id, |
| 770 const std::string& error_message) { | 760 const std::string& error_message) { |
| 771 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 761 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
| 772 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 762 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
| 773 } | 763 } |
| 774 | 764 |
| 775 } // namespace extensions | 765 } // namespace extensions |
| OLD | NEW |