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