| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ | 6 #define COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/proximity_auth/authenticator.h" | 10 #include "components/proximity_auth/authenticator.h" |
| 11 #include "components/proximity_auth/connection_observer.h" | 11 #include "components/proximity_auth/connection_observer.h" |
| 12 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | 12 #include "components/proximity_auth/cryptauth/cryptauth_client.h" |
| 13 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" | 13 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" |
| 14 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 14 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 15 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" | 15 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" |
| 16 #include "components/proximity_auth/logging/log_buffer.h" | 16 #include "components/proximity_auth/logging/log_buffer.h" |
| 17 #include "components/proximity_auth/messenger_observer.h" | 17 #include "components/proximity_auth/messenger_observer.h" |
| 18 #include "components/proximity_auth/proximity_auth_client.h" | 18 #include "components/proximity_auth/proximity_auth_client.h" |
| 19 #include "components/proximity_auth/remote_device_life_cycle.h" |
| 19 #include "content/public/browser/web_ui_message_handler.h" | 20 #include "content/public/browser/web_ui_message_handler.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class ListValue; | 23 class ListValue; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace cryptauth { | 26 namespace cryptauth { |
| 26 class ExternalDeviceInfo; | 27 class ExternalDeviceInfo; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace proximity_auth { | 30 namespace proximity_auth { |
| 30 | 31 |
| 31 class Authenticator; | |
| 32 class BluetoothConnection; | |
| 33 class BluetoothThrottler; | |
| 34 class BluetoothLowEnergyDeviceWhitelist; | |
| 35 class Connection; | |
| 36 class ConnectionFinder; | |
| 37 class MessengerImpl; | |
| 38 class ReachablePhoneFlow; | 32 class ReachablePhoneFlow; |
| 33 class RemoteDeviceLifeCycle; |
| 39 struct RemoteStatusUpdate; | 34 struct RemoteStatusUpdate; |
| 40 class SecureContext; | 35 class SecureContext; |
| 41 | 36 |
| 42 // Handles messages from the chrome://proximity-auth page. | 37 // Handles messages from the chrome://proximity-auth page. |
| 43 class ProximityAuthWebUIHandler : public content::WebUIMessageHandler, | 38 class ProximityAuthWebUIHandler : public content::WebUIMessageHandler, |
| 44 public LogBuffer::Observer, | 39 public LogBuffer::Observer, |
| 45 public CryptAuthEnrollmentManager::Observer, | 40 public CryptAuthEnrollmentManager::Observer, |
| 46 public CryptAuthDeviceManager::Observer, | 41 public CryptAuthDeviceManager::Observer, |
| 47 public ConnectionObserver, | 42 public RemoteDeviceLifeCycle::Observer, |
| 48 public MessengerObserver { | 43 public MessengerObserver { |
| 49 public: | 44 public: |
| 50 // |client_| is not owned and must outlive this instance. | 45 // |client_| is not owned and must outlive this instance. |
| 51 explicit ProximityAuthWebUIHandler( | 46 explicit ProximityAuthWebUIHandler( |
| 52 ProximityAuthClient* proximity_auth_client); | 47 ProximityAuthClient* proximity_auth_client); |
| 53 ~ProximityAuthWebUIHandler() override; | 48 ~ProximityAuthWebUIHandler() override; |
| 54 | 49 |
| 55 // content::WebUIMessageHandler: | 50 // content::WebUIMessageHandler: |
| 56 void RegisterMessages() override; | 51 void RegisterMessages() override; |
| 57 | 52 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const cryptauth::FindEligibleUnlockDevicesResponse& response); | 93 const cryptauth::FindEligibleUnlockDevicesResponse& response); |
| 99 | 94 |
| 100 // Callback when |reachable_phone_flow_| completes. | 95 // Callback when |reachable_phone_flow_| completes. |
| 101 void OnReachablePhonesFound( | 96 void OnReachablePhonesFound( |
| 102 const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones); | 97 const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones); |
| 103 | 98 |
| 104 // Called when the key agreement of PSK of the remote device completes. | 99 // Called when the key agreement of PSK of the remote device completes. |
| 105 void OnPSKDerived(const cryptauth::ExternalDeviceInfo& unlock_key, | 100 void OnPSKDerived(const cryptauth::ExternalDeviceInfo& unlock_key, |
| 106 const std::string& persistent_symmetric_key); | 101 const std::string& persistent_symmetric_key); |
| 107 | 102 |
| 108 // Tries to create a classic Bluetooth connection to the unlock key. | |
| 109 void FindBluetoothClassicConnection(const RemoteDevice& remote_device); | |
| 110 | |
| 111 // Tries to create a Bluetooth Low Energy connection to the unlock key. | |
| 112 void FindBluetoothLowEnergyConnection(const RemoteDevice& remote_device); | |
| 113 | |
| 114 // Called when |connection_finder_| finds a connection. | |
| 115 void OnConnectionFound(scoped_ptr<Connection> connection); | |
| 116 | |
| 117 // Callback when |authenticator_| completes authentication. | |
| 118 void OnAuthenticationResult(Authenticator::Result result, | |
| 119 scoped_ptr<SecureContext> secure_context); | |
| 120 | |
| 121 // Creates the client which parses status updates. | |
| 122 void CreateStatusUpdateMessenger(); | |
| 123 | |
| 124 // Returns the active connection, whether it's owned the |this| instance or | |
| 125 // |client_|. | |
| 126 Connection* GetConnection(); | |
| 127 | |
| 128 // Converts an ExternalDeviceInfo proto to a JSON dictionary used in | 103 // Converts an ExternalDeviceInfo proto to a JSON dictionary used in |
| 129 // JavaScript. | 104 // JavaScript. |
| 130 scoped_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary( | 105 scoped_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary( |
| 131 const cryptauth::ExternalDeviceInfo& device_info); | 106 const cryptauth::ExternalDeviceInfo& device_info); |
| 132 | 107 |
| 133 // Converts an IneligibleDevice proto to a JSON dictionary used in JavaScript. | 108 // Converts an IneligibleDevice proto to a JSON dictionary used in JavaScript. |
| 134 scoped_ptr<base::DictionaryValue> IneligibleDeviceToDictionary( | 109 scoped_ptr<base::DictionaryValue> IneligibleDeviceToDictionary( |
| 135 const cryptauth::IneligibleDevice& ineligible_device); | 110 const cryptauth::IneligibleDevice& ineligible_device); |
| 136 | 111 |
| 137 // ConnectionObserver: | 112 // Cleans up the connection to the selected remote device. |
| 138 void OnConnectionStatusChanged(Connection* connection, | 113 void CleanUpRemoteDeviceLifeCycle(); |
| 139 Connection::Status old_status, | 114 |
| 140 Connection::Status new_status) override; | 115 // RemoteDeviceLifeCycle::Observer: |
| 141 void OnMessageReceived(const Connection& connection, | 116 void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state, |
| 142 const WireMessage& message) override; | 117 RemoteDeviceLifeCycle::State new_state) override; |
| 143 | 118 |
| 144 // MessengerObserver: | 119 // MessengerObserver: |
| 145 void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; | 120 void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; |
| 146 | 121 |
| 147 // Returns the current enrollment state that can be used as a JSON object. | 122 // Returns the current enrollment state that can be used as a JSON object. |
| 148 scoped_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); | 123 scoped_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); |
| 149 | 124 |
| 150 // Returns the current device sync state that can be used as a JSON object. | 125 // Returns the current device sync state that can be used as a JSON object. |
| 151 scoped_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary(); | 126 scoped_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary(); |
| 152 | 127 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 165 // The flow for getting a list of reachable phones. | 140 // The flow for getting a list of reachable phones. |
| 166 scoped_ptr<ReachablePhoneFlow> reachable_phone_flow_; | 141 scoped_ptr<ReachablePhoneFlow> reachable_phone_flow_; |
| 167 | 142 |
| 168 // True if we get a message from the loaded WebContents to know that it is | 143 // True if we get a message from the loaded WebContents to know that it is |
| 169 // initialized, and we can inject JavaScript. | 144 // initialized, and we can inject JavaScript. |
| 170 bool web_contents_initialized_; | 145 bool web_contents_initialized_; |
| 171 | 146 |
| 172 // Member variables for connecting to and authenticating the remote device. | 147 // Member variables for connecting to and authenticating the remote device. |
| 173 // TODO(tengs): Support multiple simultaenous connections. | 148 // TODO(tengs): Support multiple simultaenous connections. |
| 174 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; | 149 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; |
| 175 scoped_ptr<BluetoothLowEnergyDeviceWhitelist> ble_device_whitelist_; | |
| 176 RemoteDevice selected_remote_device_; | 150 RemoteDevice selected_remote_device_; |
| 177 scoped_ptr<BluetoothThrottler> bluetooth_throttler_; | 151 scoped_ptr<RemoteDeviceLifeCycle> life_cycle_; |
| 178 scoped_ptr<ConnectionFinder> connection_finder_; | |
| 179 scoped_ptr<Connection> connection_; | |
| 180 scoped_ptr<Authenticator> authenticator_; | |
| 181 scoped_ptr<SecureContext> secure_context_; | |
| 182 scoped_ptr<MessengerImpl> messenger_; | |
| 183 scoped_ptr<RemoteStatusUpdate> last_remote_status_update_; | 152 scoped_ptr<RemoteStatusUpdate> last_remote_status_update_; |
| 184 | 153 |
| 185 base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_; | 154 base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_; |
| 186 | 155 |
| 187 DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler); | 156 DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler); |
| 188 }; | 157 }; |
| 189 | 158 |
| 190 } // namespace proximity_auth | 159 } // namespace proximity_auth |
| 191 | 160 |
| 192 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ | 161 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ |
| OLD | NEW |