OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 5 #ifndef REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
6 #define REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 6 #define REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class DictionaryValue; | 23 class DictionaryValue; |
24 class Value; | 24 class Value; |
25 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
26 } // namespace base | 26 } // namespace base |
27 | 27 |
28 namespace remoting { | 28 namespace remoting { |
29 | 29 |
30 class ChromotingHostContext; | 30 class ChromotingHostContext; |
| 31 class ElevatedNativeMessagingHost; |
| 32 class PolicyWatcher; |
31 | 33 |
32 // Implementation of the native messaging host process. | 34 // Implementation of the native messaging host process. |
33 class It2MeNativeMessagingHost : public It2MeHost::Observer, | 35 class It2MeNativeMessagingHost : public It2MeHost::Observer, |
34 public extensions::NativeMessageHost { | 36 public extensions::NativeMessageHost { |
35 public: | 37 public: |
36 It2MeNativeMessagingHost(std::unique_ptr<ChromotingHostContext> host_context, | 38 It2MeNativeMessagingHost(bool needs_elevation, |
| 39 std::unique_ptr<ChromotingHostContext> host_context, |
37 std::unique_ptr<It2MeHostFactory> host_factory); | 40 std::unique_ptr<It2MeHostFactory> host_factory); |
38 ~It2MeNativeMessagingHost() override; | 41 ~It2MeNativeMessagingHost() override; |
39 | 42 |
40 // extensions::NativeMessageHost implementation. | 43 // extensions::NativeMessageHost implementation. |
41 void OnMessage(const std::string& message) override; | 44 void OnMessage(const std::string& message) override; |
42 void Start(Client* client) override; | 45 void Start(Client* client) override; |
43 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override; | 46 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override; |
44 | 47 |
45 // It2MeHost::Observer implementation. | 48 // It2MeHost::Observer implementation. |
46 void OnClientAuthenticated(const std::string& client_username) | 49 void OnClientAuthenticated(const std::string& client_username) |
47 override; | 50 override; |
48 void OnStoreAccessCode(const std::string& access_code, | 51 void OnStoreAccessCode(const std::string& access_code, |
49 base::TimeDelta access_code_lifetime) override; | 52 base::TimeDelta access_code_lifetime) override; |
50 void OnNatPolicyChanged(bool nat_traversal_enabled) override; | 53 void OnNatPolicyChanged(bool nat_traversal_enabled) override; |
51 void OnStateChanged(It2MeHostState state, | 54 void OnStateChanged(It2MeHostState state, |
52 const std::string& error_message) override; | 55 const std::string& error_message) override; |
53 | 56 |
54 static std::string HostStateToString(It2MeHostState host_state); | 57 static std::string HostStateToString(It2MeHostState host_state); |
55 | 58 |
56 private: | 59 private: |
57 // These "Process.." methods handle specific request types. The |response| | 60 // These "Process.." methods handle specific request types. The |response| |
58 // dictionary is pre-filled by ProcessMessage() with the parts of the | 61 // dictionary is pre-filled by ProcessMessage() with the parts of the |
59 // response already known ("id" and "type" fields). | 62 // response already known ("id" and "type" fields). |
60 void ProcessHello(const base::DictionaryValue& message, | 63 void ProcessHello(std::unique_ptr<base::DictionaryValue> message, |
61 std::unique_ptr<base::DictionaryValue> response) const; | 64 std::unique_ptr<base::DictionaryValue> response) const; |
62 void ProcessConnect(const base::DictionaryValue& message, | 65 void ProcessConnect(std::unique_ptr<base::DictionaryValue> message, |
63 std::unique_ptr<base::DictionaryValue> response); | 66 std::unique_ptr<base::DictionaryValue> response); |
64 void ProcessDisconnect(const base::DictionaryValue& message, | 67 void ProcessDisconnect(std::unique_ptr<base::DictionaryValue> message, |
65 std::unique_ptr<base::DictionaryValue> response); | 68 std::unique_ptr<base::DictionaryValue> response); |
66 void SendErrorAndExit(std::unique_ptr<base::DictionaryValue> response, | 69 void SendErrorAndExit(std::unique_ptr<base::DictionaryValue> response, |
67 const std::string& description) const; | 70 const std::string& description) const; |
68 void SendMessageToClient(std::unique_ptr<base::Value> message) const; | 71 void SendMessageToClient(std::unique_ptr<base::Value> message) const; |
69 | 72 |
70 Client* client_; | 73 // Called when initial policies are read, and when they change. |
| 74 void OnPolicyUpdate(std::unique_ptr<base::DictionaryValue> policies); |
| 75 |
| 76 // Called when malformed policies are detected. |
| 77 void OnPolicyError(); |
| 78 |
| 79 // Returns whether the request was successfully sent to the elevated host. |
| 80 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); |
| 81 |
| 82 // Used to determine whether to create and pass messages to an elevated host. |
| 83 bool needs_elevation_ = false; |
| 84 |
| 85 // Set via Chrome Policy on whether to allow the host to run elevated. |
| 86 bool allow_elevated_host_ = false; |
| 87 |
| 88 #if defined(OS_WIN) |
| 89 // Controls the lifetime of the elevated native messaging host process. |
| 90 // Note: 'elevated' in this instance means having the UiAccess privilege, not |
| 91 // being run as a higher privilege user. |
| 92 std::unique_ptr<ElevatedNativeMessagingHost> elevated_host_; |
| 93 #endif // defined(OS_WIN) |
| 94 |
| 95 Client* client_ = nullptr; |
71 std::unique_ptr<ChromotingHostContext> host_context_; | 96 std::unique_ptr<ChromotingHostContext> host_context_; |
72 std::unique_ptr<It2MeHostFactory> factory_; | 97 std::unique_ptr<It2MeHostFactory> factory_; |
73 scoped_refptr<It2MeHost> it2me_host_; | 98 scoped_refptr<It2MeHost> it2me_host_; |
74 | 99 |
75 #if !defined(OS_CHROMEOS) | 100 #if !defined(OS_CHROMEOS) |
76 // Don't install a log message handler on ChromeOS because we run in the | 101 // Don't install a log message handler on ChromeOS because we run in the |
77 // browser process and don't want to intercept all its log messages. | 102 // browser process and don't want to intercept all its log messages. |
78 std::unique_ptr<LogMessageHandler> log_message_handler_; | 103 std::unique_ptr<LogMessageHandler> log_message_handler_; |
79 #endif | 104 #endif |
80 | 105 |
81 // Cached, read-only copies of |it2me_host_| session state. | 106 // Cached, read-only copies of |it2me_host_| session state. |
82 It2MeHostState state_; | 107 It2MeHostState state_; |
83 std::string access_code_; | 108 std::string access_code_; |
84 base::TimeDelta access_code_lifetime_; | 109 base::TimeDelta access_code_lifetime_; |
85 std::string client_username_; | 110 std::string client_username_; |
86 | 111 |
87 // IT2Me Talk server configuration used by |it2me_host_| to connect. | 112 // IT2Me Talk server configuration used by |it2me_host_| to connect. |
88 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 113 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
89 | 114 |
90 // Chromoting Bot JID used by |it2me_host_| to register the host. | 115 // Chromoting Bot JID used by |it2me_host_| to register the host. |
91 std::string directory_bot_jid_; | 116 std::string directory_bot_jid_; |
92 | 117 |
| 118 // Indicates whether or not a policy has ever been read. This is to ensure |
| 119 // that on startup, we do not accidentally start a connection before we have |
| 120 // queried our policy restrictions. |
| 121 bool policy_received_ = false; |
| 122 |
| 123 // Used to retrieve Chrome policies set for the local machine. |
| 124 std::unique_ptr<PolicyWatcher> policy_watcher_; |
| 125 |
| 126 // On startup, it is possible to have Connect() called before the policy read |
| 127 // is completed. Rather than just failing, we thunk the connection call so |
| 128 // it can be executed after at least one successful policy read. This |
| 129 // variable contains the thunk if it is necessary. |
| 130 base::Closure pending_connect_; |
| 131 |
93 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; | 132 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; |
94 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; | 133 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; |
95 | 134 |
96 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); | 135 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); |
97 }; | 136 }; |
98 | 137 |
99 } // namespace remoting | 138 } // namespace remoting |
100 | 139 |
101 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 140 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
OLD | NEW |