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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // Change even to odd and vice versa, to get the other side of a given channel. | 56 // Change even to odd and vice versa, to get the other side of a given channel. |
57 #define GET_OPPOSITE_PORT_ID(source_port_id) ((source_port_id) ^ 1) | 57 #define GET_OPPOSITE_PORT_ID(source_port_id) ((source_port_id) ^ 1) |
58 | 58 |
59 namespace extensions { | 59 namespace extensions { |
60 | 60 |
61 const char kReceivingEndDoesntExistError[] = | 61 const char kReceivingEndDoesntExistError[] = |
62 "Could not establish connection. Receiving end does not exist."; | 62 "Could not establish connection. Receiving end does not exist."; |
63 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 63 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
64 const char kMissingPermissionError[] = | 64 const char kMissingPermissionError[] = |
65 "Access to native messaging requires nativeMessaging permission."; | 65 "Access to native messaging requires nativeMessaging permission."; |
| 66 const char kProhibitedByPoliciesError[] = |
| 67 "Access to the native messaging host was disabled by the system " |
| 68 "administrator."; |
66 #endif | 69 #endif |
67 | 70 |
68 struct MessageService::MessageChannel { | 71 struct MessageService::MessageChannel { |
69 scoped_ptr<MessagePort> opener; | 72 scoped_ptr<MessagePort> opener; |
70 scoped_ptr<MessagePort> receiver; | 73 scoped_ptr<MessagePort> receiver; |
71 }; | 74 }; |
72 | 75 |
73 struct MessageService::OpenChannelParams { | 76 struct MessageService::OpenChannelParams { |
74 content::RenderProcessHost* source; | 77 content::RenderProcessHost* source; |
75 base::DictionaryValue source_tab; | 78 base::DictionaryValue source_tab; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 extension_service->GetExtensionById(source_extension_id, false); | 354 extension_service->GetExtensionById(source_extension_id, false); |
352 has_permission = extension && extension->HasAPIPermission( | 355 has_permission = extension && extension->HasAPIPermission( |
353 APIPermission::kNativeMessaging); | 356 APIPermission::kNativeMessaging); |
354 } | 357 } |
355 | 358 |
356 if (!has_permission) { | 359 if (!has_permission) { |
357 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); | 360 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); |
358 return; | 361 return; |
359 } | 362 } |
360 | 363 |
| 364 // Verify that the host is not blocked by policies. |
| 365 if (!NativeMessageProcessHost::IsHostAllowed(profile->GetPrefs(), |
| 366 native_app_name)) { |
| 367 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError); |
| 368 return; |
| 369 } |
| 370 |
361 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 371 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
362 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 372 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
363 source_extension_id)); | 373 source_extension_id)); |
364 | 374 |
365 // Get handle of the native view and pass it to the native messaging host. | 375 // Get handle of the native view and pass it to the native messaging host. |
366 gfx::NativeView native_view = | 376 gfx::NativeView native_view = |
367 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> | 377 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> |
368 GetView()->GetNativeView(); | 378 GetView()->GetNativeView(); |
369 | 379 |
370 scoped_ptr<NativeMessageProcessHost> native_process = | 380 scoped_ptr<NativeMessageProcessHost> native_process = |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 743 } |
734 | 744 |
735 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 745 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
736 int port_id, | 746 int port_id, |
737 const std::string& error_message) { | 747 const std::string& error_message) { |
738 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 748 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
739 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 749 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
740 } | 750 } |
741 | 751 |
742 } // namespace extensions | 752 } // namespace extensions |
OLD | NEW |