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