| 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" |
| 11 #include "components/proximity_auth/client_observer.h" |
| 12 #include "components/proximity_auth/connection_observer.h" |
| 10 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | 13 #include "components/proximity_auth/cryptauth/cryptauth_client.h" |
| 11 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" | 14 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" |
| 12 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 15 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 13 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" | 16 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" |
| 14 #include "components/proximity_auth/logging/log_buffer.h" | 17 #include "components/proximity_auth/logging/log_buffer.h" |
| 15 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h" | 18 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" | 19 #include "content/public/browser/web_ui_message_handler.h" |
| 17 | 20 |
| 18 namespace base { | 21 namespace base { |
| 19 class ListValue; | 22 class ListValue; |
| 20 } | 23 } |
| 21 | 24 |
| 22 namespace proximity_auth { | 25 namespace proximity_auth { |
| 23 | 26 |
| 27 class Authenticator; |
| 28 class BluetoothConnection; |
| 29 class ClientImpl; |
| 30 struct RemoteStatusUpdate; |
| 31 class SecureContext; |
| 32 |
| 24 // Handles messages from the chrome://proximity-auth page. | 33 // Handles messages from the chrome://proximity-auth page. |
| 25 class ProximityAuthWebUIHandler : public content::WebUIMessageHandler, | 34 class ProximityAuthWebUIHandler : public content::WebUIMessageHandler, |
| 26 public LogBuffer::Observer, | 35 public LogBuffer::Observer, |
| 27 public CryptAuthEnrollmentManager::Observer, | 36 public CryptAuthEnrollmentManager::Observer, |
| 28 public CryptAuthDeviceManager::Observer { | 37 public CryptAuthDeviceManager::Observer, |
| 38 public ConnectionObserver, |
| 39 public ClientObserver { |
| 29 public: | 40 public: |
| 30 // |delegate| is not owned and must outlive this instance. | 41 // |delegate| is not owned and must outlive this instance. |
| 31 explicit ProximityAuthWebUIHandler(ProximityAuthUIDelegate* delegate); | 42 explicit ProximityAuthWebUIHandler(ProximityAuthUIDelegate* delegate); |
| 32 ~ProximityAuthWebUIHandler() override; | 43 ~ProximityAuthWebUIHandler() override; |
| 33 | 44 |
| 34 // content::WebUIMessageHandler: | 45 // content::WebUIMessageHandler: |
| 35 void RegisterMessages() override; | 46 void RegisterMessages() override; |
| 36 | 47 |
| 37 private: | 48 private: |
| 38 // LogBuffer::Observer: | 49 // LogBuffer::Observer: |
| 39 void OnLogMessageAdded(const LogBuffer::LogMessage& log_message) override; | 50 void OnLogMessageAdded(const LogBuffer::LogMessage& log_message) override; |
| 40 void OnLogBufferCleared() override; | 51 void OnLogBufferCleared() override; |
| 41 | 52 |
| 42 // CryptAuthEnrollmentManager::Observer: | 53 // CryptAuthEnrollmentManager::Observer: |
| 43 void OnEnrollmentStarted() override; | 54 void OnEnrollmentStarted() override; |
| 44 void OnEnrollmentFinished(bool success) override; | 55 void OnEnrollmentFinished(bool success) override; |
| 45 | 56 |
| 46 // CryptAuthDeviceManager::Observer: | 57 // CryptAuthDeviceManager::Observer: |
| 47 void OnSyncStarted() override; | 58 void OnSyncStarted() override; |
| 48 void OnSyncFinished( | 59 void OnSyncFinished( |
| 49 CryptAuthDeviceManager::SyncResult sync_result, | 60 CryptAuthDeviceManager::SyncResult sync_result, |
| 50 CryptAuthDeviceManager::DeviceChangeResult device_change_result) override; | 61 CryptAuthDeviceManager::DeviceChangeResult device_change_result) override; |
| 51 | 62 |
| 52 // Message handler callbacks. | 63 // Message handler callbacks. |
| 53 void GetLogMessages(const base::ListValue* args); | 64 void GetLogMessages(const base::ListValue* args); |
| 54 void ClearLogBuffer(const base::ListValue* args); | 65 void ClearLogBuffer(const base::ListValue* args); |
| 55 void FindEligibleUnlockDevices(const base::ListValue* args); | 66 void FindEligibleUnlockDevices(const base::ListValue* args); |
| 56 void GetSyncStates(const base::ListValue* args); | 67 void GetLocalState(const base::ListValue* args); |
| 57 void ForceEnrollment(const base::ListValue* args); | 68 void ForceEnrollment(const base::ListValue* args); |
| 58 void ForceDeviceSync(const base::ListValue* args); | 69 void ForceDeviceSync(const base::ListValue* args); |
| 70 void ToggleConnection(const base::ListValue* args); |
| 59 | 71 |
| 60 // Initializes CryptAuth managers, used for development purposes. | 72 // Initializes CryptAuth managers, used for development purposes. |
| 61 void InitGCMManager(); | 73 void InitGCMManager(); |
| 62 void InitEnrollmentManager(); | 74 void InitEnrollmentManager(); |
| 63 void InitDeviceManager(); | 75 void InitDeviceManager(); |
| 64 | 76 |
| 65 // Called when a CryptAuth request fails. | 77 // Called when a CryptAuth request fails. |
| 66 void OnCryptAuthClientError(const std::string& error_message); | 78 void OnCryptAuthClientError(const std::string& error_message); |
| 67 | 79 |
| 68 // Called when the findEligibleUnlockDevices request succeeds. | 80 // Called when the findEligibleUnlockDevices request succeeds. |
| 69 void OnFoundEligibleUnlockDevices( | 81 void OnFoundEligibleUnlockDevices( |
| 70 const cryptauth::FindEligibleUnlockDevicesResponse& response); | 82 const cryptauth::FindEligibleUnlockDevicesResponse& response); |
| 71 | 83 |
| 84 // Called when the key agreement of PSK of the remote device completes. |
| 85 void OnPSKDerived(const cryptauth::ExternalDeviceInfo& unlock_key, |
| 86 const std::string& persistent_symmetric_key); |
| 87 |
| 88 // Callbacks for bluetooth_util::SeekDeviceByAddress(). |
| 89 void OnSeekedDeviceByAddress(); |
| 90 void OnSeekedDeviceByAddressError(const std::string& error_message); |
| 91 |
| 92 // Callback when |authenticator_| completes authentication. |
| 93 void OnAuthenticationResult(Authenticator::Result result, |
| 94 scoped_ptr<SecureContext> secure_context); |
| 95 |
| 96 // Creates the client which parses status updates. |
| 97 void CreateStatusUpdateClient(); |
| 98 |
| 99 // Converts an ExternalDeviceInfo proto to a JSON dictionary used in |
| 100 // JavaScript. |
| 101 scoped_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary( |
| 102 const cryptauth::ExternalDeviceInfo& device_info); |
| 103 |
| 104 // Converts an IneligibleDevice proto to a JSON dictionary used in JavaScript. |
| 105 scoped_ptr<base::DictionaryValue> IneligibleDeviceToDictionary( |
| 106 const cryptauth::IneligibleDevice& ineligible_device); |
| 107 |
| 108 // ConnectionObserver: |
| 109 void OnConnectionStatusChanged(Connection* connection, |
| 110 Connection::Status old_status, |
| 111 Connection::Status new_status) override; |
| 112 void OnMessageReceived(const Connection& connection, |
| 113 const WireMessage& message) override; |
| 114 |
| 115 // ClientObserver: |
| 116 void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; |
| 117 |
| 72 // Returns the current enrollment state that can be used as a JSON object. | 118 // Returns the current enrollment state that can be used as a JSON object. |
| 73 scoped_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); | 119 scoped_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); |
| 74 | 120 |
| 75 // Returns the current device sync state that can be used as a JSON object. | 121 // Returns the current device sync state that can be used as a JSON object. |
| 76 scoped_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary(); | 122 scoped_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary(); |
| 77 | 123 |
| 124 // Returns the current unlock keys that can be used as a JSON object. |
| 125 scoped_ptr<base::ListValue> GetUnlockKeysList(); |
| 126 |
| 78 // The delegate used to fetch dependencies. Must outlive this instance. | 127 // The delegate used to fetch dependencies. Must outlive this instance. |
| 79 ProximityAuthUIDelegate* delegate_; | 128 ProximityAuthUIDelegate* delegate_; |
| 80 | 129 |
| 81 // Creates CryptAuth client instances to make API calls. | 130 // Creates CryptAuth client instances to make API calls. |
| 82 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory_; | 131 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory_; |
| 83 | 132 |
| 84 // We only support one concurrent API call. | 133 // We only support one concurrent API call. |
| 85 scoped_ptr<CryptAuthClient> cryptauth_client_; | 134 scoped_ptr<CryptAuthClient> cryptauth_client_; |
| 86 | 135 |
| 136 // Member variables related to CryptAuth debugging. |
| 87 // TODO(tengs): These members are temporarily used for development. | 137 // TODO(tengs): These members are temporarily used for development. |
| 88 scoped_ptr<PrefService> pref_service; | 138 scoped_ptr<PrefService> pref_service; |
| 89 scoped_ptr<CryptAuthGCMManager> gcm_manager_; | 139 scoped_ptr<CryptAuthGCMManager> gcm_manager_; |
| 90 scoped_ptr<CryptAuthEnrollmentManager> enrollment_manager_; | 140 scoped_ptr<CryptAuthEnrollmentManager> enrollment_manager_; |
| 91 scoped_ptr<CryptAuthDeviceManager> device_manager_; | 141 scoped_ptr<CryptAuthDeviceManager> device_manager_; |
| 142 std::string user_public_key_; |
| 143 std::string user_private_key_; |
| 144 |
| 145 // Member variables for connecting to and authenticating the remote device. |
| 146 // TODO(tengs): Support multiple simultaenous connections. |
| 147 scoped_ptr<SecureMessageDelegate> secure_message_delegate_; |
| 148 scoped_ptr<BluetoothConnection> bluetooth_connection_; |
| 149 scoped_ptr<Authenticator> authenticator_; |
| 150 scoped_ptr<SecureContext> secure_context_; |
| 151 scoped_ptr<ClientImpl> client_; |
| 152 scoped_ptr<RemoteStatusUpdate> last_remote_status_update_; |
| 92 | 153 |
| 93 base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_; | 154 base::WeakPtrFactory<ProximityAuthWebUIHandler> weak_ptr_factory_; |
| 94 | 155 |
| 95 DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler); | 156 DISALLOW_COPY_AND_ASSIGN(ProximityAuthWebUIHandler); |
| 96 }; | 157 }; |
| 97 | 158 |
| 98 } // namespace proximity_auth | 159 } // namespace proximity_auth |
| 99 | 160 |
| 100 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ | 161 #endif // COMPONENTS_PROXIMITY_AUTH_WEBUI_PROXIMITY_AUTH_WEBUI_HANDLER_H_ |
| OLD | NEW |