| 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_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 5 #ifndef REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| 6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/timer/timer.h" | |
| 17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 18 #include "extensions/browser/api/messaging/native_message_host.h" | 17 #include "extensions/browser/api/messaging/native_message_host.h" |
| 19 #include "extensions/browser/api/messaging/native_messaging_channel.h" | |
| 20 #include "remoting/host/setup/daemon_controller.h" | 18 #include "remoting/host/setup/daemon_controller.h" |
| 21 #include "remoting/host/setup/oauth_client.h" | 19 #include "remoting/host/setup/oauth_client.h" |
| 22 | 20 |
| 23 namespace base { | 21 namespace base { |
| 24 class DictionaryValue; | 22 class DictionaryValue; |
| 25 class ListValue; | 23 class ListValue; |
| 26 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 25 class Value; |
| 27 } // namespace base | 26 } // namespace base |
| 28 | 27 |
| 29 namespace gaia { | 28 namespace gaia { |
| 30 class GaiaOAuthClient; | 29 class GaiaOAuthClient; |
| 31 } // namespace gaia | 30 } // namespace gaia |
| 32 | 31 |
| 33 namespace remoting { | 32 namespace remoting { |
| 34 | 33 |
| 35 namespace protocol { | 34 namespace protocol { |
| 36 class PairingRegistry; | 35 class PairingRegistry; |
| 37 } // namespace protocol | 36 } // namespace protocol |
| 38 | 37 |
| 39 class ChromotingHostContext; | 38 class ChromotingHostContext; |
| 39 class ElevatedNativeMessagingHost; |
| 40 class LogMessageHandler; | 40 class LogMessageHandler; |
| 41 | 41 |
| 42 // Implementation of the me2me native messaging host. | 42 // Implementation of the me2me native messaging host. |
| 43 class Me2MeNativeMessagingHost : public extensions::NativeMessageHost { | 43 class Me2MeNativeMessagingHost : public extensions::NativeMessageHost { |
| 44 public: | 44 public: |
| 45 Me2MeNativeMessagingHost( | 45 Me2MeNativeMessagingHost( |
| 46 bool needs_elevation, | 46 bool needs_elevation, |
| 47 intptr_t parent_window_handle, | 47 intptr_t parent_window_handle, |
| 48 std::unique_ptr<ChromotingHostContext> host_context, | 48 std::unique_ptr<ChromotingHostContext> host_context, |
| 49 scoped_refptr<DaemonController> daemon_controller, | 49 scoped_refptr<DaemonController> daemon_controller, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 DaemonController::AsyncResult result); | 113 DaemonController::AsyncResult result); |
| 114 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, | 114 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, |
| 115 bool result); | 115 bool result); |
| 116 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, | 116 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, |
| 117 const std::string& user_email, | 117 const std::string& user_email, |
| 118 const std::string& refresh_token); | 118 const std::string& refresh_token); |
| 119 void SendMessageToClient(std::unique_ptr<base::Value> message) const; | 119 void SendMessageToClient(std::unique_ptr<base::Value> message) const; |
| 120 | 120 |
| 121 void OnError(const std::string& error_message); | 121 void OnError(const std::string& error_message); |
| 122 | 122 |
| 123 // Returns true if the request was successfully delegated to the elevated | 123 // Returns whether the request was successfully sent to the elevated host. |
| 124 // host and false otherwise. | |
| 125 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); | 124 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); |
| 126 | 125 |
| 127 #if defined(OS_WIN) | |
| 128 class ElevatedChannelEventHandler | |
| 129 : public extensions::NativeMessagingChannel::EventHandler { | |
| 130 public: | |
| 131 ElevatedChannelEventHandler(extensions::NativeMessageHost::Client* client); | |
| 132 | |
| 133 // extensions::NativeMessagingChannel::EventHandler implementation. | |
| 134 void OnMessage(std::unique_ptr<base::Value> message) override; | |
| 135 void OnDisconnect() override; | |
| 136 | |
| 137 private: | |
| 138 extensions::NativeMessageHost::Client* client_; | |
| 139 | |
| 140 base::ThreadChecker thread_checker_; | |
| 141 }; | |
| 142 | |
| 143 // Create and connect to an elevated host process if necessary. | |
| 144 // |elevated_channel_| will contain the native messaging channel to the | |
| 145 // elevated host if the function succeeds. | |
| 146 void EnsureElevatedHostCreated(); | |
| 147 | |
| 148 // Disconnect and shut down the elevated host. | |
| 149 void DisconnectElevatedHost(); | |
| 150 | |
| 151 // Native messaging channel used to communicate with the elevated host. | |
| 152 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_; | |
| 153 | |
| 154 // Native messaging event handler used to process responses from the elevated | |
| 155 // host. | |
| 156 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; | |
| 157 | |
| 158 // Timer to control the lifetime of the elevated host. | |
| 159 base::OneShotTimer elevated_host_timer_; | |
| 160 #endif // defined(OS_WIN) | |
| 161 | |
| 162 bool needs_elevation_; | 126 bool needs_elevation_; |
| 163 | 127 |
| 164 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
| 129 // Controls the lifetime of the elevated native messaging host process. |
| 130 std::unique_ptr<ElevatedNativeMessagingHost> elevated_host_; |
| 131 |
| 165 // Handle of the parent window. | 132 // Handle of the parent window. |
| 166 intptr_t parent_window_handle_; | 133 intptr_t parent_window_handle_; |
| 167 #endif // defined(OS_WIN) | 134 #endif // defined(OS_WIN) |
| 168 | 135 |
| 169 extensions::NativeMessageHost::Client* client_; | 136 extensions::NativeMessageHost::Client* client_; |
| 170 std::unique_ptr<ChromotingHostContext> host_context_; | 137 std::unique_ptr<ChromotingHostContext> host_context_; |
| 171 | 138 |
| 172 std::unique_ptr<LogMessageHandler> log_message_handler_; | 139 std::unique_ptr<LogMessageHandler> log_message_handler_; |
| 173 | 140 |
| 174 scoped_refptr<DaemonController> daemon_controller_; | 141 scoped_refptr<DaemonController> daemon_controller_; |
| 175 | 142 |
| 176 // Used to load and update the paired clients for this host. | 143 // Used to load and update the paired clients for this host. |
| 177 scoped_refptr<protocol::PairingRegistry> pairing_registry_; | 144 scoped_refptr<protocol::PairingRegistry> pairing_registry_; |
| 178 | 145 |
| 179 // Used to exchange the service account authorization code for credentials. | 146 // Used to exchange the service account authorization code for credentials. |
| 180 std::unique_ptr<OAuthClient> oauth_client_; | 147 std::unique_ptr<OAuthClient> oauth_client_; |
| 181 | 148 |
| 182 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; | 149 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; |
| 183 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; | 150 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; |
| 184 | 151 |
| 185 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); | 152 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); |
| 186 }; | 153 }; |
| 187 | 154 |
| 188 } // namespace remoting | 155 } // namespace remoting |
| 189 | 156 |
| 190 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 157 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |