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 then native messaging host is prohibited by system policies."; | |
Joao da Silva
2013/12/29 23:25:28
*the
We often blame these restrictions on the sys
Sergey Ulanov
2014/01/06 23:21:55
Done.
| |
66 #endif | 68 #endif |
67 | 69 |
68 struct MessageService::MessageChannel { | 70 struct MessageService::MessageChannel { |
69 scoped_ptr<MessagePort> opener; | 71 scoped_ptr<MessagePort> opener; |
70 scoped_ptr<MessagePort> receiver; | 72 scoped_ptr<MessagePort> receiver; |
71 }; | 73 }; |
72 | 74 |
73 struct MessageService::OpenChannelParams { | 75 struct MessageService::OpenChannelParams { |
74 content::RenderProcessHost* source; | 76 content::RenderProcessHost* source; |
75 base::DictionaryValue source_tab; | 77 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); | 353 extension_service->GetExtensionById(source_extension_id, false); |
352 has_permission = extension && extension->HasAPIPermission( | 354 has_permission = extension && extension->HasAPIPermission( |
353 APIPermission::kNativeMessaging); | 355 APIPermission::kNativeMessaging); |
354 } | 356 } |
355 | 357 |
356 if (!has_permission) { | 358 if (!has_permission) { |
357 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); | 359 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); |
358 return; | 360 return; |
359 } | 361 } |
360 | 362 |
363 // Verify that the host is not blocked by policies. | |
364 if (!NativeMessageProcessHost::IsHostAllowed(profile->GetPrefs(), | |
365 native_app_name)) { | |
366 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError); | |
367 return; | |
368 } | |
369 | |
361 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 370 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
362 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 371 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
363 source_extension_id)); | 372 source_extension_id)); |
364 | 373 |
365 // Get handle of the native view and pass it to the native messaging host. | 374 // Get handle of the native view and pass it to the native messaging host. |
366 gfx::NativeView native_view = | 375 gfx::NativeView native_view = |
367 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> | 376 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> |
368 GetView()->GetNativeView(); | 377 GetView()->GetNativeView(); |
369 | 378 |
370 scoped_ptr<NativeMessageProcessHost> native_process = | 379 scoped_ptr<NativeMessageProcessHost> native_process = |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 742 } |
734 | 743 |
735 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 744 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
736 int port_id, | 745 int port_id, |
737 const std::string& error_message) { | 746 const std::string& error_message) { |
738 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 747 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
739 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 748 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
740 } | 749 } |
741 | 750 |
742 } // namespace extensions | 751 } // namespace extensions |
OLD | NEW |