Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: components/proximity_auth/webui/proximity_auth_webui_handler.cc

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/proximity_auth/webui/proximity_auth_webui_handler.h" 5 #include "components/proximity_auth/webui/proximity_auth_webui_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64url.h" 10 #include "base/base64url.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 web_ui()->RegisterMessageCallback( 158 web_ui()->RegisterMessageCallback(
159 "toggleConnection", 159 "toggleConnection",
160 base::Bind(&ProximityAuthWebUIHandler::ToggleConnection, 160 base::Bind(&ProximityAuthWebUIHandler::ToggleConnection,
161 base::Unretained(this))); 161 base::Unretained(this)));
162 } 162 }
163 163
164 void ProximityAuthWebUIHandler::OnLogMessageAdded( 164 void ProximityAuthWebUIHandler::OnLogMessageAdded(
165 const LogBuffer::LogMessage& log_message) { 165 const LogBuffer::LogMessage& log_message) {
166 std::unique_ptr<base::DictionaryValue> dictionary = 166 std::unique_ptr<base::DictionaryValue> dictionary =
167 LogMessageToDictionary(log_message); 167 LogMessageToDictionary(log_message);
168 web_ui()->CallJavascriptFunction("LogBufferInterface.onLogMessageAdded", 168 web_ui()->CallJavascriptFunctionUnsafe("LogBufferInterface.onLogMessageAdded",
169 *dictionary); 169 *dictionary);
170 } 170 }
171 171
172 void ProximityAuthWebUIHandler::OnLogBufferCleared() { 172 void ProximityAuthWebUIHandler::OnLogBufferCleared() {
173 web_ui()->CallJavascriptFunction("LogBufferInterface.onLogBufferCleared"); 173 web_ui()->CallJavascriptFunctionUnsafe(
174 "LogBufferInterface.onLogBufferCleared");
174 } 175 }
175 176
176 void ProximityAuthWebUIHandler::OnEnrollmentStarted() { 177 void ProximityAuthWebUIHandler::OnEnrollmentStarted() {
177 web_ui()->CallJavascriptFunction( 178 web_ui()->CallJavascriptFunctionUnsafe(
178 "LocalStateInterface.onEnrollmentStateChanged", 179 "LocalStateInterface.onEnrollmentStateChanged",
179 *GetEnrollmentStateDictionary()); 180 *GetEnrollmentStateDictionary());
180 } 181 }
181 182
182 void ProximityAuthWebUIHandler::OnEnrollmentFinished(bool success) { 183 void ProximityAuthWebUIHandler::OnEnrollmentFinished(bool success) {
183 std::unique_ptr<base::DictionaryValue> enrollment_state = 184 std::unique_ptr<base::DictionaryValue> enrollment_state =
184 GetEnrollmentStateDictionary(); 185 GetEnrollmentStateDictionary();
185 PA_LOG(INFO) << "Enrollment attempt completed with success=" << success 186 PA_LOG(INFO) << "Enrollment attempt completed with success=" << success
186 << ":\n" << *enrollment_state; 187 << ":\n" << *enrollment_state;
187 web_ui()->CallJavascriptFunction( 188 web_ui()->CallJavascriptFunctionUnsafe(
188 "LocalStateInterface.onEnrollmentStateChanged", *enrollment_state); 189 "LocalStateInterface.onEnrollmentStateChanged", *enrollment_state);
189 } 190 }
190 191
191 void ProximityAuthWebUIHandler::OnSyncStarted() { 192 void ProximityAuthWebUIHandler::OnSyncStarted() {
192 web_ui()->CallJavascriptFunction( 193 web_ui()->CallJavascriptFunctionUnsafe(
193 "LocalStateInterface.onDeviceSyncStateChanged", 194 "LocalStateInterface.onDeviceSyncStateChanged",
194 *GetDeviceSyncStateDictionary()); 195 *GetDeviceSyncStateDictionary());
195 } 196 }
196 197
197 void ProximityAuthWebUIHandler::OnSyncFinished( 198 void ProximityAuthWebUIHandler::OnSyncFinished(
198 CryptAuthDeviceManager::SyncResult sync_result, 199 CryptAuthDeviceManager::SyncResult sync_result,
199 CryptAuthDeviceManager::DeviceChangeResult device_change_result) { 200 CryptAuthDeviceManager::DeviceChangeResult device_change_result) {
200 std::unique_ptr<base::DictionaryValue> device_sync_state = 201 std::unique_ptr<base::DictionaryValue> device_sync_state =
201 GetDeviceSyncStateDictionary(); 202 GetDeviceSyncStateDictionary();
202 PA_LOG(INFO) << "Device sync completed with result=" 203 PA_LOG(INFO) << "Device sync completed with result="
203 << static_cast<int>(sync_result) << ":\n" << *device_sync_state; 204 << static_cast<int>(sync_result) << ":\n" << *device_sync_state;
204 web_ui()->CallJavascriptFunction( 205 web_ui()->CallJavascriptFunctionUnsafe(
205 "LocalStateInterface.onDeviceSyncStateChanged", *device_sync_state); 206 "LocalStateInterface.onDeviceSyncStateChanged", *device_sync_state);
206 207
207 if (device_change_result == 208 if (device_change_result ==
208 CryptAuthDeviceManager::DeviceChangeResult::CHANGED) { 209 CryptAuthDeviceManager::DeviceChangeResult::CHANGED) {
209 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 210 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
210 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n" 211 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n"
211 << *unlock_keys; 212 << *unlock_keys;
212 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 213 web_ui()->CallJavascriptFunctionUnsafe(
213 *unlock_keys); 214 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys);
214 } 215 }
215 } 216 }
216 217
217 void ProximityAuthWebUIHandler::OnWebContentsInitialized( 218 void ProximityAuthWebUIHandler::OnWebContentsInitialized(
218 const base::ListValue* args) { 219 const base::ListValue* args) {
219 if (!web_contents_initialized_) { 220 if (!web_contents_initialized_) {
220 CryptAuthEnrollmentManager* enrollment_manager = 221 CryptAuthEnrollmentManager* enrollment_manager =
221 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 222 proximity_auth_client_->GetCryptAuthEnrollmentManager();
222 if (enrollment_manager) 223 if (enrollment_manager)
223 enrollment_manager->AddObserver(this); 224 enrollment_manager->AddObserver(this);
224 225
225 CryptAuthDeviceManager* device_manager = 226 CryptAuthDeviceManager* device_manager =
226 proximity_auth_client_->GetCryptAuthDeviceManager(); 227 proximity_auth_client_->GetCryptAuthDeviceManager();
227 if (device_manager) 228 if (device_manager)
228 device_manager->AddObserver(this); 229 device_manager->AddObserver(this);
229 230
230 LogBuffer::GetInstance()->AddObserver(this); 231 LogBuffer::GetInstance()->AddObserver(this);
231 232
232 web_contents_initialized_ = true; 233 web_contents_initialized_ = true;
233 } 234 }
234 } 235 }
235 236
236 void ProximityAuthWebUIHandler::GetLogMessages(const base::ListValue* args) { 237 void ProximityAuthWebUIHandler::GetLogMessages(const base::ListValue* args) {
237 base::ListValue json_logs; 238 base::ListValue json_logs;
238 for (const auto& log : *LogBuffer::GetInstance()->logs()) { 239 for (const auto& log : *LogBuffer::GetInstance()->logs()) {
239 json_logs.Append(LogMessageToDictionary(log).release()); 240 json_logs.Append(LogMessageToDictionary(log).release());
240 } 241 }
241 web_ui()->CallJavascriptFunction("LogBufferInterface.onGotLogMessages", 242 web_ui()->CallJavascriptFunctionUnsafe("LogBufferInterface.onGotLogMessages",
242 json_logs); 243 json_logs);
243 } 244 }
244 245
245 void ProximityAuthWebUIHandler::ClearLogBuffer(const base::ListValue* args) { 246 void ProximityAuthWebUIHandler::ClearLogBuffer(const base::ListValue* args) {
246 // The OnLogBufferCleared() observer function will be called after the buffer 247 // The OnLogBufferCleared() observer function will be called after the buffer
247 // is cleared. 248 // is cleared.
248 LogBuffer::GetInstance()->Clear(); 249 LogBuffer::GetInstance()->Clear();
249 } 250 }
250 251
251 void ProximityAuthWebUIHandler::ToggleUnlockKey(const base::ListValue* args) { 252 void ProximityAuthWebUIHandler::ToggleUnlockKey(const base::ListValue* args) {
252 std::string public_key_b64, public_key; 253 std::string public_key_b64, public_key;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 361 }
361 } 362 }
362 363
363 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found"; 364 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found";
364 } 365 }
365 366
366 void ProximityAuthWebUIHandler::OnCryptAuthClientError( 367 void ProximityAuthWebUIHandler::OnCryptAuthClientError(
367 const std::string& error_message) { 368 const std::string& error_message) {
368 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message; 369 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message;
369 base::StringValue error_string(error_message); 370 base::StringValue error_string(error_message);
370 web_ui()->CallJavascriptFunction("CryptAuthInterface.onError", error_string); 371 web_ui()->CallJavascriptFunctionUnsafe("CryptAuthInterface.onError",
372 error_string);
371 } 373 }
372 374
373 void ProximityAuthWebUIHandler::OnEasyUnlockToggled( 375 void ProximityAuthWebUIHandler::OnEasyUnlockToggled(
374 const cryptauth::ToggleEasyUnlockResponse& response) { 376 const cryptauth::ToggleEasyUnlockResponse& response) {
375 web_ui()->CallJavascriptFunction("CryptAuthInterface.onUnlockKeyToggled"); 377 web_ui()->CallJavascriptFunctionUnsafe(
378 "CryptAuthInterface.onUnlockKeyToggled");
376 // TODO(tengs): Update the local state to reflect the toggle. 379 // TODO(tengs): Update the local state to reflect the toggle.
377 } 380 }
378 381
379 void ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices( 382 void ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices(
380 const cryptauth::FindEligibleUnlockDevicesResponse& response) { 383 const cryptauth::FindEligibleUnlockDevicesResponse& response) {
381 base::ListValue eligible_devices; 384 base::ListValue eligible_devices;
382 for (const auto& external_device : response.eligible_devices()) { 385 for (const auto& external_device : response.eligible_devices()) {
383 eligible_devices.Append(ExternalDeviceInfoToDictionary(external_device)); 386 eligible_devices.Append(ExternalDeviceInfoToDictionary(external_device));
384 } 387 }
385 388
386 base::ListValue ineligible_devices; 389 base::ListValue ineligible_devices;
387 for (const auto& ineligible_device : response.ineligible_devices()) { 390 for (const auto& ineligible_device : response.ineligible_devices()) {
388 ineligible_devices.Append(IneligibleDeviceToDictionary(ineligible_device)); 391 ineligible_devices.Append(IneligibleDeviceToDictionary(ineligible_device));
389 } 392 }
390 393
391 PA_LOG(INFO) << "Found " << eligible_devices.GetSize() 394 PA_LOG(INFO) << "Found " << eligible_devices.GetSize()
392 << " eligible devices and " << ineligible_devices.GetSize() 395 << " eligible devices and " << ineligible_devices.GetSize()
393 << " ineligible devices."; 396 << " ineligible devices.";
394 web_ui()->CallJavascriptFunction("CryptAuthInterface.onGotEligibleDevices", 397 web_ui()->CallJavascriptFunctionUnsafe(
395 eligible_devices, ineligible_devices); 398 "CryptAuthInterface.onGotEligibleDevices", eligible_devices,
399 ineligible_devices);
396 } 400 }
397 401
398 void ProximityAuthWebUIHandler::OnReachablePhonesFound( 402 void ProximityAuthWebUIHandler::OnReachablePhonesFound(
399 const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones) { 403 const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones) {
400 reachable_phone_flow_.reset(); 404 reachable_phone_flow_.reset();
401 base::ListValue device_list; 405 base::ListValue device_list;
402 for (const auto& external_device : reachable_phones) { 406 for (const auto& external_device : reachable_phones) {
403 device_list.Append(ExternalDeviceInfoToDictionary(external_device)); 407 device_list.Append(ExternalDeviceInfoToDictionary(external_device));
404 } 408 }
405 web_ui()->CallJavascriptFunction("CryptAuthInterface.onGotReachableDevices", 409 web_ui()->CallJavascriptFunctionUnsafe(
406 device_list); 410 "CryptAuthInterface.onGotReachableDevices", device_list);
407 } 411 }
408 412
409 void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) { 413 void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) {
410 std::unique_ptr<base::DictionaryValue> enrollment_state = 414 std::unique_ptr<base::DictionaryValue> enrollment_state =
411 GetEnrollmentStateDictionary(); 415 GetEnrollmentStateDictionary();
412 std::unique_ptr<base::DictionaryValue> device_sync_state = 416 std::unique_ptr<base::DictionaryValue> device_sync_state =
413 GetDeviceSyncStateDictionary(); 417 GetDeviceSyncStateDictionary();
414 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 418 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
415 419
416 PA_LOG(INFO) << "==== Got Local State ====\n" 420 PA_LOG(INFO) << "==== Got Local State ====\n"
417 << "Enrollment State: \n" << *enrollment_state 421 << "Enrollment State: \n" << *enrollment_state
418 << "Device Sync State: \n" << *device_sync_state 422 << "Device Sync State: \n" << *device_sync_state
419 << "Unlock Keys: \n" << *unlock_keys; 423 << "Unlock Keys: \n" << *unlock_keys;
420 web_ui()->CallJavascriptFunction("LocalStateInterface.onGotLocalState", 424 web_ui()->CallJavascriptFunctionUnsafe("LocalStateInterface.onGotLocalState",
421 *enrollment_state, *device_sync_state, 425 *enrollment_state, *device_sync_state,
422 *unlock_keys); 426 *unlock_keys);
423 } 427 }
424 428
425 std::unique_ptr<base::DictionaryValue> 429 std::unique_ptr<base::DictionaryValue>
426 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() { 430 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() {
427 CryptAuthEnrollmentManager* enrollment_manager = 431 CryptAuthEnrollmentManager* enrollment_manager =
428 proximity_auth_client_->GetCryptAuthEnrollmentManager(); 432 proximity_auth_client_->GetCryptAuthEnrollmentManager();
429 if (!enrollment_manager) 433 if (!enrollment_manager)
430 return base::WrapUnique(new base::DictionaryValue()); 434 return base::WrapUnique(new base::DictionaryValue());
431 435
432 return CreateSyncStateDictionary( 436 return CreateSyncStateDictionary(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 std::move(ineligibility_reasons)); 565 std::move(ineligibility_reasons));
562 return device_dictionary; 566 return device_dictionary;
563 } 567 }
564 568
565 void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() { 569 void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() {
566 PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name 570 PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name
567 << " [" << selected_remote_device_.bluetooth_address << "]"; 571 << " [" << selected_remote_device_.bluetooth_address << "]";
568 life_cycle_.reset(); 572 life_cycle_.reset();
569 selected_remote_device_ = RemoteDevice(); 573 selected_remote_device_ = RemoteDevice();
570 last_remote_status_update_.reset(); 574 last_remote_status_update_.reset();
571 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 575 web_ui()->CallJavascriptFunctionUnsafe(
572 *GetUnlockKeysList()); 576 "LocalStateInterface.onUnlockKeysChanged", *GetUnlockKeysList());
573 } 577 }
574 578
575 void ProximityAuthWebUIHandler::OnLifeCycleStateChanged( 579 void ProximityAuthWebUIHandler::OnLifeCycleStateChanged(
576 RemoteDeviceLifeCycle::State old_state, 580 RemoteDeviceLifeCycle::State old_state,
577 RemoteDeviceLifeCycle::State new_state) { 581 RemoteDeviceLifeCycle::State new_state) {
578 // Do not re-attempt to find a connection after the first one fails--just 582 // Do not re-attempt to find a connection after the first one fails--just
579 // abort. 583 // abort.
580 if ((old_state != RemoteDeviceLifeCycle::State::STOPPED && 584 if ((old_state != RemoteDeviceLifeCycle::State::STOPPED &&
581 new_state == RemoteDeviceLifeCycle::State::FINDING_CONNECTION) || 585 new_state == RemoteDeviceLifeCycle::State::FINDING_CONNECTION) ||
582 new_state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) { 586 new_state == RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED) {
583 // Clean up the life cycle asynchronously, because we are currently in the 587 // Clean up the life cycle asynchronously, because we are currently in the
584 // call stack of |life_cycle_|. 588 // call stack of |life_cycle_|.
585 base::ThreadTaskRunnerHandle::Get()->PostTask( 589 base::ThreadTaskRunnerHandle::Get()->PostTask(
586 FROM_HERE, 590 FROM_HERE,
587 base::Bind(&ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle, 591 base::Bind(&ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle,
588 weak_ptr_factory_.GetWeakPtr())); 592 weak_ptr_factory_.GetWeakPtr()));
589 } else if (new_state == 593 } else if (new_state ==
590 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { 594 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
591 life_cycle_->GetMessenger()->AddObserver(this); 595 life_cycle_->GetMessenger()->AddObserver(this);
592 } 596 }
593 597
594 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 598 web_ui()->CallJavascriptFunctionUnsafe(
595 *GetUnlockKeysList()); 599 "LocalStateInterface.onUnlockKeysChanged", *GetUnlockKeysList());
596 } 600 }
597 601
598 void ProximityAuthWebUIHandler::OnRemoteStatusUpdate( 602 void ProximityAuthWebUIHandler::OnRemoteStatusUpdate(
599 const RemoteStatusUpdate& status_update) { 603 const RemoteStatusUpdate& status_update) {
600 PA_LOG(INFO) << "Remote status update:" 604 PA_LOG(INFO) << "Remote status update:"
601 << "\n user_presence: " 605 << "\n user_presence: "
602 << static_cast<int>(status_update.user_presence) 606 << static_cast<int>(status_update.user_presence)
603 << "\n secure_screen_lock_state: " 607 << "\n secure_screen_lock_state: "
604 << static_cast<int>(status_update.secure_screen_lock_state) 608 << static_cast<int>(status_update.secure_screen_lock_state)
605 << "\n trust_agent_state: " 609 << "\n trust_agent_state: "
606 << static_cast<int>(status_update.trust_agent_state); 610 << static_cast<int>(status_update.trust_agent_state);
607 611
608 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); 612 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update));
609 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 613 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
610 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 614 web_ui()->CallJavascriptFunctionUnsafe(
611 *unlock_keys); 615 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys);
612 } 616 }
613 617
614 } // namespace proximity_auth 618 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/dom_distiller/webui/dom_distiller_handler.cc ('k') | content/browser/accessibility/accessibility_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698