OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (!crypto_delegate_) | 130 if (!crypto_delegate_) |
131 crypto_delegate_ = EasyUnlockPrivateCryptoDelegate::Create(); | 131 crypto_delegate_ = EasyUnlockPrivateCryptoDelegate::Create(); |
132 return crypto_delegate_.get(); | 132 return crypto_delegate_.get(); |
133 } | 133 } |
134 | 134 |
135 EasyUnlockPrivateGetStringsFunction::EasyUnlockPrivateGetStringsFunction() { | 135 EasyUnlockPrivateGetStringsFunction::EasyUnlockPrivateGetStringsFunction() { |
136 } | 136 } |
137 EasyUnlockPrivateGetStringsFunction::~EasyUnlockPrivateGetStringsFunction() { | 137 EasyUnlockPrivateGetStringsFunction::~EasyUnlockPrivateGetStringsFunction() { |
138 } | 138 } |
139 | 139 |
140 bool EasyUnlockPrivateGetStringsFunction::RunSync() { | 140 ExtensionFunction::ResponseAction EasyUnlockPrivateGetStringsFunction::Run() { |
141 std::unique_ptr<base::DictionaryValue> strings(new base::DictionaryValue); | 141 std::unique_ptr<base::DictionaryValue> strings(new base::DictionaryValue); |
142 | 142 |
143 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
144 const base::string16 device_type = ash::GetChromeOSDeviceName(); | 144 const base::string16 device_type = ash::GetChromeOSDeviceName(); |
145 #else | 145 #else |
146 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices. | 146 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices. |
147 const base::string16 device_type = base::ASCIIToUTF16("Chromeschnozzle"); | 147 const base::string16 device_type = base::ASCIIToUTF16("Chromeschnozzle"); |
148 #endif // defined(OS_CHROMEOS) | 148 #endif // defined(OS_CHROMEOS) |
149 | 149 |
150 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 strings->SetString( | 352 strings->SetString( |
353 "setupErrorFindingPhone", | 353 "setupErrorFindingPhone", |
354 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_ERROR_FINDING_PHONE)); | 354 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_ERROR_FINDING_PHONE)); |
355 strings->SetString("setupErrorSyncPhoneState", | 355 strings->SetString("setupErrorSyncPhoneState", |
356 l10n_util::GetStringUTF16( | 356 l10n_util::GetStringUTF16( |
357 IDS_EASY_UNLOCK_SETUP_ERROR_SYNC_PHONE_STATE_FAILED)); | 357 IDS_EASY_UNLOCK_SETUP_ERROR_SYNC_PHONE_STATE_FAILED)); |
358 strings->SetString("setupErrorConnectingToPhone", | 358 strings->SetString("setupErrorConnectingToPhone", |
359 l10n_util::GetStringUTF16( | 359 l10n_util::GetStringUTF16( |
360 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECTING_TO_PHONE)); | 360 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECTING_TO_PHONE)); |
361 | 361 |
362 SetResult(std::move(strings)); | 362 return RespondNow(OneArgument(std::move(strings))); |
363 return true; | |
364 } | 363 } |
365 | 364 |
366 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: | 365 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: |
367 EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} | 366 EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} |
368 | 367 |
369 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: | 368 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: |
370 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} | 369 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} |
371 | 370 |
372 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { | 371 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { |
373 std::unique_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = | 372 std::unique_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 OnConnectError, | 526 OnConnectError, |
528 this)); | 527 this)); |
529 } | 528 } |
530 | 529 |
531 EasyUnlockPrivateUpdateScreenlockStateFunction:: | 530 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
532 EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 531 EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
533 | 532 |
534 EasyUnlockPrivateUpdateScreenlockStateFunction:: | 533 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
535 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 534 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
536 | 535 |
537 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { | 536 ExtensionFunction::ResponseAction |
| 537 EasyUnlockPrivateUpdateScreenlockStateFunction::Run() { |
538 std::unique_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( | 538 std::unique_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( |
539 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); | 539 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); |
540 EXTENSION_FUNCTION_VALIDATE(params.get()); | 540 EXTENSION_FUNCTION_VALIDATE(params.get()); |
541 | 541 |
542 Profile* profile = Profile::FromBrowserContext(browser_context()); | 542 Profile* profile = Profile::FromBrowserContext(browser_context()); |
543 if (EasyUnlockService::Get(profile)->UpdateScreenlockState( | 543 if (EasyUnlockService::Get(profile)->UpdateScreenlockState( |
544 ToScreenlockState(params->state))) | 544 ToScreenlockState(params->state))) { |
545 return true; | 545 return RespondNow(NoArguments()); |
546 | 546 } |
547 SetError("Not allowed"); | 547 return RespondNow(Error("Not allowed")); |
548 return false; | |
549 } | 548 } |
550 | 549 |
551 EasyUnlockPrivateSetPermitAccessFunction:: | 550 EasyUnlockPrivateSetPermitAccessFunction:: |
552 EasyUnlockPrivateSetPermitAccessFunction() { | 551 EasyUnlockPrivateSetPermitAccessFunction() { |
553 } | 552 } |
554 | 553 |
555 EasyUnlockPrivateSetPermitAccessFunction:: | 554 EasyUnlockPrivateSetPermitAccessFunction:: |
556 ~EasyUnlockPrivateSetPermitAccessFunction() { | 555 ~EasyUnlockPrivateSetPermitAccessFunction() { |
557 } | 556 } |
558 | 557 |
559 bool EasyUnlockPrivateSetPermitAccessFunction::RunSync() { | 558 ExtensionFunction::ResponseAction |
| 559 EasyUnlockPrivateSetPermitAccessFunction::Run() { |
560 std::unique_ptr<easy_unlock_private::SetPermitAccess::Params> params( | 560 std::unique_ptr<easy_unlock_private::SetPermitAccess::Params> params( |
561 easy_unlock_private::SetPermitAccess::Params::Create(*args_)); | 561 easy_unlock_private::SetPermitAccess::Params::Create(*args_)); |
562 EXTENSION_FUNCTION_VALIDATE(params.get()); | 562 EXTENSION_FUNCTION_VALIDATE(params.get()); |
563 | 563 |
564 Profile* profile = Profile::FromBrowserContext(browser_context()); | 564 Profile* profile = Profile::FromBrowserContext(browser_context()); |
565 EasyUnlockService::Get(profile) | 565 EasyUnlockService::Get(profile) |
566 ->SetPermitAccess(*params->permit_access.ToValue()); | 566 ->SetPermitAccess(*params->permit_access.ToValue()); |
567 | 567 return RespondNow(NoArguments()); |
568 return true; | |
569 } | 568 } |
570 | 569 |
571 EasyUnlockPrivateGetPermitAccessFunction:: | 570 EasyUnlockPrivateGetPermitAccessFunction:: |
572 EasyUnlockPrivateGetPermitAccessFunction() { | 571 EasyUnlockPrivateGetPermitAccessFunction() { |
573 } | 572 } |
574 | 573 |
575 EasyUnlockPrivateGetPermitAccessFunction:: | 574 EasyUnlockPrivateGetPermitAccessFunction:: |
576 ~EasyUnlockPrivateGetPermitAccessFunction() { | 575 ~EasyUnlockPrivateGetPermitAccessFunction() { |
577 } | 576 } |
578 | 577 |
579 bool EasyUnlockPrivateGetPermitAccessFunction::RunSync() { | 578 ExtensionFunction::ResponseAction |
| 579 EasyUnlockPrivateGetPermitAccessFunction::Run() { |
580 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 580 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
581 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { | 581 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { |
582 ReturnPermitAccessForExperiment(); | 582 return GetPermitAccessForExperiment(); |
583 return true; | |
584 } | 583 } |
585 | 584 |
586 Profile* profile = Profile::FromBrowserContext(browser_context()); | 585 Profile* profile = Profile::FromBrowserContext(browser_context()); |
587 const base::DictionaryValue* permit_value = | 586 const base::DictionaryValue* permit_value = |
588 EasyUnlockService::Get(profile)->GetPermitAccess(); | 587 EasyUnlockService::Get(profile)->GetPermitAccess(); |
| 588 |
589 if (permit_value) { | 589 if (permit_value) { |
590 std::unique_ptr<easy_unlock_private::PermitRecord> permit = | 590 std::unique_ptr<easy_unlock_private::PermitRecord> permit = |
591 easy_unlock_private::PermitRecord::FromValue(*permit_value); | 591 easy_unlock_private::PermitRecord::FromValue(*permit_value); |
592 results_ = easy_unlock_private::GetPermitAccess::Results::Create(*permit); | 592 return RespondNow(ArgumentList( |
| 593 easy_unlock_private::GetPermitAccess::Results::Create(*permit))); |
593 } | 594 } |
594 | 595 |
595 return true; | 596 return RespondNow(NoArguments()); |
596 } | 597 } |
597 | 598 |
598 void EasyUnlockPrivateGetPermitAccessFunction::GetKeyPairForExperiment( | 599 void EasyUnlockPrivateGetPermitAccessFunction::GetKeyPairForExperiment( |
599 std::string* user_public_key, | 600 std::string* user_public_key, |
600 std::string* user_private_key) { | 601 std::string* user_private_key) { |
601 Profile* profile = Profile::FromBrowserContext(browser_context()); | 602 Profile* profile = Profile::FromBrowserContext(browser_context()); |
602 proximity_auth::CryptAuthEnrollmentManager* enrollment_manager = | 603 proximity_auth::CryptAuthEnrollmentManager* enrollment_manager = |
603 EasyUnlockService::Get(profile) | 604 EasyUnlockService::Get(profile) |
604 ->proximity_auth_client() | 605 ->proximity_auth_client() |
605 ->GetCryptAuthEnrollmentManager(); | 606 ->GetCryptAuthEnrollmentManager(); |
606 base::Base64UrlEncode(enrollment_manager->GetUserPublicKey(), | 607 base::Base64UrlEncode(enrollment_manager->GetUserPublicKey(), |
607 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 608 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
608 user_public_key); | 609 user_public_key); |
609 base::Base64UrlEncode(enrollment_manager->GetUserPrivateKey(), | 610 base::Base64UrlEncode(enrollment_manager->GetUserPrivateKey(), |
610 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 611 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
611 user_private_key); | 612 user_private_key); |
612 } | 613 } |
613 | 614 |
614 void EasyUnlockPrivateGetPermitAccessFunction:: | 615 ExtensionFunction::ResponseAction |
615 ReturnPermitAccessForExperiment() { | 616 EasyUnlockPrivateGetPermitAccessFunction::GetPermitAccessForExperiment() { |
616 // Check that we are inside a user session. | 617 // Check that we are inside a user session. |
617 Profile* profile = Profile::FromBrowserContext(browser_context()); | 618 Profile* profile = Profile::FromBrowserContext(browser_context()); |
618 EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile); | 619 EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile); |
619 if (easy_unlock_service->GetType() != EasyUnlockService::TYPE_REGULAR) { | 620 if (easy_unlock_service->GetType() != EasyUnlockService::TYPE_REGULAR) { |
620 SetError("This function must be called inside a user session."); | 621 return RespondNow( |
621 SendResponse(true); | 622 Error("This function must be called inside a user session.")); |
622 return; | |
623 } | 623 } |
624 | 624 |
625 std::string b64_public_key, b64_private_key; | 625 std::string b64_public_key, b64_private_key; |
626 GetKeyPairForExperiment(&b64_public_key, &b64_private_key); | 626 GetKeyPairForExperiment(&b64_public_key, &b64_private_key); |
627 | 627 |
628 // Fill in the permit access JSON dictionary. | 628 // Fill in the permit access JSON dictionary. |
629 proximity_auth::ProximityAuthClient* client = | 629 proximity_auth::ProximityAuthClient* client = |
630 easy_unlock_service->proximity_auth_client(); | 630 easy_unlock_service->proximity_auth_client(); |
631 std::unique_ptr<base::DictionaryValue> permit_access( | 631 std::unique_ptr<base::DictionaryValue> permit_access( |
632 new base::DictionaryValue()); | 632 new base::DictionaryValue()); |
633 permit_access->SetString("permitId", | 633 permit_access->SetString("permitId", |
634 "permit://google.com/" + client->GetAccountId()); | 634 "permit://google.com/" + client->GetAccountId()); |
635 permit_access->SetString("id", b64_public_key); | 635 permit_access->SetString("id", b64_public_key); |
636 permit_access->SetString("type", "access"); | 636 permit_access->SetString("type", "access"); |
637 permit_access->SetString("data", b64_private_key); | 637 permit_access->SetString("data", b64_private_key); |
638 | 638 |
639 PA_LOG(INFO) << "Returning permit access for " | 639 PA_LOG(INFO) << "Returning permit access for " |
640 << "chrome.easyUnlockPrivate.getPermitAccess:\n" | 640 << "chrome.easyUnlockPrivate.getPermitAccess:\n" |
641 << " id: " << b64_public_key; | 641 << " id: " << b64_public_key; |
642 | 642 |
643 std::unique_ptr<easy_unlock_private::PermitRecord> result = | 643 return RespondNow(OneArgument(std::move(permit_access))); |
644 easy_unlock_private::PermitRecord::FromValue(*permit_access); | |
645 results_ = easy_unlock_private::GetPermitAccess::Results::Create(*result); | |
646 } | 644 } |
647 | 645 |
648 EasyUnlockPrivateClearPermitAccessFunction:: | 646 EasyUnlockPrivateClearPermitAccessFunction:: |
649 EasyUnlockPrivateClearPermitAccessFunction() { | 647 EasyUnlockPrivateClearPermitAccessFunction() { |
650 } | 648 } |
651 | 649 |
652 EasyUnlockPrivateClearPermitAccessFunction:: | 650 EasyUnlockPrivateClearPermitAccessFunction:: |
653 ~EasyUnlockPrivateClearPermitAccessFunction() { | 651 ~EasyUnlockPrivateClearPermitAccessFunction() { |
654 } | 652 } |
655 | 653 |
656 bool EasyUnlockPrivateClearPermitAccessFunction::RunSync() { | 654 ExtensionFunction::ResponseAction |
| 655 EasyUnlockPrivateClearPermitAccessFunction::Run() { |
657 Profile* profile = Profile::FromBrowserContext(browser_context()); | 656 Profile* profile = Profile::FromBrowserContext(browser_context()); |
658 EasyUnlockService::Get(profile)->ClearPermitAccess(); | 657 EasyUnlockService::Get(profile)->ClearPermitAccess(); |
659 return true; | 658 return RespondNow(NoArguments()); |
660 } | 659 } |
661 | 660 |
662 EasyUnlockPrivateSetRemoteDevicesFunction:: | 661 EasyUnlockPrivateSetRemoteDevicesFunction:: |
663 EasyUnlockPrivateSetRemoteDevicesFunction() { | 662 EasyUnlockPrivateSetRemoteDevicesFunction() { |
664 } | 663 } |
665 | 664 |
666 EasyUnlockPrivateSetRemoteDevicesFunction:: | 665 EasyUnlockPrivateSetRemoteDevicesFunction:: |
667 ~EasyUnlockPrivateSetRemoteDevicesFunction() { | 666 ~EasyUnlockPrivateSetRemoteDevicesFunction() { |
668 } | 667 } |
669 | 668 |
670 bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() { | 669 ExtensionFunction::ResponseAction |
| 670 EasyUnlockPrivateSetRemoteDevicesFunction::Run() { |
671 std::unique_ptr<easy_unlock_private::SetRemoteDevices::Params> params( | 671 std::unique_ptr<easy_unlock_private::SetRemoteDevices::Params> params( |
672 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); | 672 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); |
673 EXTENSION_FUNCTION_VALIDATE(params.get()); | 673 EXTENSION_FUNCTION_VALIDATE(params.get()); |
674 | 674 |
675 Profile* profile = Profile::FromBrowserContext(browser_context()); | 675 Profile* profile = Profile::FromBrowserContext(browser_context()); |
676 base::ListValue devices; | 676 base::ListValue devices; |
677 for (const easy_unlock_private::Device& device : params->devices) | 677 for (const easy_unlock_private::Device& device : params->devices) |
678 devices.Append(device.ToValue()); | 678 devices.Append(device.ToValue()); |
679 | 679 |
680 // Store the BLE device if we are trying out the BLE experiment. | 680 // Store the BLE device if we are trying out the BLE experiment. |
681 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 681 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
682 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { | 682 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { |
683 EasyUnlockService::Get(profile)->SetRemoteBleDevices(devices); | 683 EasyUnlockService::Get(profile)->SetRemoteBleDevices(devices); |
684 } else { | 684 } else { |
685 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); | 685 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); |
686 } | 686 } |
687 | 687 |
688 return true; | 688 return RespondNow(NoArguments()); |
689 } | 689 } |
690 | 690 |
691 EasyUnlockPrivateGetRemoteDevicesFunction:: | 691 EasyUnlockPrivateGetRemoteDevicesFunction:: |
692 EasyUnlockPrivateGetRemoteDevicesFunction() { | 692 EasyUnlockPrivateGetRemoteDevicesFunction() { |
693 } | 693 } |
694 | 694 |
695 EasyUnlockPrivateGetRemoteDevicesFunction:: | 695 EasyUnlockPrivateGetRemoteDevicesFunction:: |
696 ~EasyUnlockPrivateGetRemoteDevicesFunction() { | 696 ~EasyUnlockPrivateGetRemoteDevicesFunction() { |
697 } | 697 } |
698 | 698 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 } | 869 } |
870 | 870 |
871 EasyUnlockPrivateTrySignInSecretFunction:: | 871 EasyUnlockPrivateTrySignInSecretFunction:: |
872 EasyUnlockPrivateTrySignInSecretFunction() { | 872 EasyUnlockPrivateTrySignInSecretFunction() { |
873 } | 873 } |
874 | 874 |
875 EasyUnlockPrivateTrySignInSecretFunction:: | 875 EasyUnlockPrivateTrySignInSecretFunction:: |
876 ~EasyUnlockPrivateTrySignInSecretFunction() { | 876 ~EasyUnlockPrivateTrySignInSecretFunction() { |
877 } | 877 } |
878 | 878 |
879 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { | 879 ExtensionFunction::ResponseAction |
| 880 EasyUnlockPrivateTrySignInSecretFunction::Run() { |
880 std::unique_ptr<easy_unlock_private::TrySignInSecret::Params> params( | 881 std::unique_ptr<easy_unlock_private::TrySignInSecret::Params> params( |
881 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); | 882 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); |
882 EXTENSION_FUNCTION_VALIDATE(params.get()); | 883 EXTENSION_FUNCTION_VALIDATE(params.get()); |
883 | 884 |
884 Profile* profile = Profile::FromBrowserContext(browser_context()); | 885 Profile* profile = Profile::FromBrowserContext(browser_context()); |
885 EasyUnlockService::Get(profile)->FinalizeSignin(std::string( | 886 EasyUnlockService::Get(profile)->FinalizeSignin(std::string( |
886 params->sign_in_secret.begin(), params->sign_in_secret.end())); | 887 params->sign_in_secret.begin(), params->sign_in_secret.end())); |
887 return true; | 888 return RespondNow(NoArguments()); |
888 } | 889 } |
889 | 890 |
890 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { | 891 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { |
891 } | 892 } |
892 | 893 |
893 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { | 894 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { |
894 } | 895 } |
895 | 896 |
896 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { | 897 ExtensionFunction::ResponseAction EasyUnlockPrivateGetUserInfoFunction::Run() { |
897 EasyUnlockService* service = | 898 EasyUnlockService* service = |
898 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); | 899 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); |
899 std::vector<easy_unlock_private::UserInfo> users; | 900 std::vector<easy_unlock_private::UserInfo> users; |
900 const AccountId& account_id = service->GetAccountId(); | 901 const AccountId& account_id = service->GetAccountId(); |
901 if (account_id.is_valid()) { | 902 if (account_id.is_valid()) { |
902 easy_unlock_private::UserInfo user; | 903 easy_unlock_private::UserInfo user; |
903 user.user_id = account_id.GetUserEmail(); | 904 user.user_id = account_id.GetUserEmail(); |
904 user.logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; | 905 user.logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; |
905 user.data_ready = user.logged_in || service->GetRemoteDevices() != NULL; | 906 user.data_ready = user.logged_in || service->GetRemoteDevices() != NULL; |
906 | 907 |
907 EasyUnlockService::UserSettings user_settings = | 908 EasyUnlockService::UserSettings user_settings = |
908 EasyUnlockService::GetUserSettings(account_id); | 909 EasyUnlockService::GetUserSettings(account_id); |
909 user.require_close_proximity = user_settings.require_close_proximity; | 910 user.require_close_proximity = user_settings.require_close_proximity; |
910 | 911 |
911 user.device_user_id = proximity_auth::CalculateDeviceUserId( | 912 user.device_user_id = proximity_auth::CalculateDeviceUserId( |
912 EasyUnlockService::GetDeviceId(), account_id.GetUserEmail()); | 913 EasyUnlockService::GetDeviceId(), account_id.GetUserEmail()); |
913 | 914 |
914 user.ble_discovery_enabled = | 915 user.ble_discovery_enabled = |
915 base::CommandLine::ForCurrentProcess()->HasSwitch( | 916 base::CommandLine::ForCurrentProcess()->HasSwitch( |
916 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); | 917 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); |
917 users.push_back(std::move(user)); | 918 users.push_back(std::move(user)); |
918 } | 919 } |
919 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); | 920 return RespondNow( |
920 return true; | 921 ArgumentList(easy_unlock_private::GetUserInfo::Results::Create(users))); |
921 } | 922 } |
922 | 923 |
923 EasyUnlockPrivateGetConnectionInfoFunction:: | 924 EasyUnlockPrivateGetConnectionInfoFunction:: |
924 EasyUnlockPrivateGetConnectionInfoFunction() { | 925 EasyUnlockPrivateGetConnectionInfoFunction() { |
925 } | 926 } |
926 | 927 |
927 EasyUnlockPrivateGetConnectionInfoFunction:: | 928 EasyUnlockPrivateGetConnectionInfoFunction:: |
928 ~EasyUnlockPrivateGetConnectionInfoFunction() { | 929 ~EasyUnlockPrivateGetConnectionInfoFunction() { |
929 } | 930 } |
930 | 931 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 } | 965 } |
965 | 966 |
966 EasyUnlockPrivateShowErrorBubbleFunction:: | 967 EasyUnlockPrivateShowErrorBubbleFunction:: |
967 EasyUnlockPrivateShowErrorBubbleFunction() { | 968 EasyUnlockPrivateShowErrorBubbleFunction() { |
968 } | 969 } |
969 | 970 |
970 EasyUnlockPrivateShowErrorBubbleFunction:: | 971 EasyUnlockPrivateShowErrorBubbleFunction:: |
971 ~EasyUnlockPrivateShowErrorBubbleFunction() { | 972 ~EasyUnlockPrivateShowErrorBubbleFunction() { |
972 } | 973 } |
973 | 974 |
974 bool EasyUnlockPrivateShowErrorBubbleFunction::RunSync() { | 975 ExtensionFunction::ResponseAction |
| 976 EasyUnlockPrivateShowErrorBubbleFunction::Run() { |
975 content::WebContents* web_contents = GetAssociatedWebContents(); | 977 content::WebContents* web_contents = GetAssociatedWebContents(); |
976 if (!web_contents) { | 978 if (!web_contents) |
977 SetError("A foreground app window is required."); | 979 return RespondNow(Error("A foreground app window is required.")); |
978 return true; | |
979 } | |
980 | 980 |
981 std::unique_ptr<easy_unlock_private::ShowErrorBubble::Params> params( | 981 std::unique_ptr<easy_unlock_private::ShowErrorBubble::Params> params( |
982 easy_unlock_private::ShowErrorBubble::Params::Create(*args_)); | 982 easy_unlock_private::ShowErrorBubble::Params::Create(*args_)); |
983 EXTENSION_FUNCTION_VALIDATE(params.get()); | 983 EXTENSION_FUNCTION_VALIDATE(params.get()); |
984 | 984 |
985 if (params->link_range.start < 0 || | 985 if (params->link_range.start < 0 || |
986 params->link_range.end < 0 || | 986 params->link_range.end < 0 || |
987 base::saturated_cast<size_t>(params->link_range.end) > | 987 base::saturated_cast<size_t>(params->link_range.end) > |
988 params->message.size()) { | 988 params->message.size()) { |
989 SetError("Invalid link range."); | 989 return RespondNow(Error("Invalid link range.")); |
990 return true; | |
991 } | 990 } |
992 | 991 |
993 #if defined(TOOLKIT_VIEWS) | 992 #if defined(TOOLKIT_VIEWS) |
994 gfx::Rect anchor_rect( | 993 gfx::Rect anchor_rect( |
995 params->anchor_rect.left, params->anchor_rect.top, | 994 params->anchor_rect.left, params->anchor_rect.top, |
996 params->anchor_rect.width, params->anchor_rect.height); | 995 params->anchor_rect.width, params->anchor_rect.height); |
997 anchor_rect += | 996 anchor_rect += |
998 web_contents->GetContainerBounds().OffsetFromOrigin(); | 997 web_contents->GetContainerBounds().OffsetFromOrigin(); |
999 ShowProximityAuthErrorBubble( | 998 ShowProximityAuthErrorBubble( |
1000 base::UTF8ToUTF16(params->message), | 999 base::UTF8ToUTF16(params->message), |
1001 gfx::Range(params->link_range.start, params->link_range.end), | 1000 gfx::Range(params->link_range.start, params->link_range.end), |
1002 GURL(params->link_target), anchor_rect, web_contents); | 1001 GURL(params->link_target), anchor_rect, web_contents); |
| 1002 return RespondNow(NoArguments()); |
1003 #else | 1003 #else |
1004 SetError("Not supported on non-Views platforms."); | 1004 return RespondNow(Error("Not supported on non-Views platforms.")); |
1005 #endif | 1005 #endif |
1006 return true; | |
1007 } | 1006 } |
1008 | 1007 |
1009 EasyUnlockPrivateHideErrorBubbleFunction:: | 1008 EasyUnlockPrivateHideErrorBubbleFunction:: |
1010 EasyUnlockPrivateHideErrorBubbleFunction() { | 1009 EasyUnlockPrivateHideErrorBubbleFunction() { |
1011 } | 1010 } |
1012 | 1011 |
1013 EasyUnlockPrivateHideErrorBubbleFunction:: | 1012 EasyUnlockPrivateHideErrorBubbleFunction:: |
1014 ~EasyUnlockPrivateHideErrorBubbleFunction() { | 1013 ~EasyUnlockPrivateHideErrorBubbleFunction() { |
1015 } | 1014 } |
1016 | 1015 |
1017 bool EasyUnlockPrivateHideErrorBubbleFunction::RunSync() { | 1016 ExtensionFunction::ResponseAction |
| 1017 EasyUnlockPrivateHideErrorBubbleFunction::Run() { |
1018 #if defined(TOOLKIT_VIEWS) | 1018 #if defined(TOOLKIT_VIEWS) |
1019 HideProximityAuthErrorBubble(); | 1019 HideProximityAuthErrorBubble(); |
| 1020 return RespondNow(NoArguments()); |
1020 #else | 1021 #else |
1021 SetError("Not supported on non-Views platforms."); | 1022 return RespondNow(Error("Not supported on non-Views platforms.")); |
1022 #endif | 1023 #endif |
1023 return true; | |
1024 } | 1024 } |
1025 | 1025 |
1026 EasyUnlockPrivateSetAutoPairingResultFunction:: | 1026 EasyUnlockPrivateSetAutoPairingResultFunction:: |
1027 EasyUnlockPrivateSetAutoPairingResultFunction() { | 1027 EasyUnlockPrivateSetAutoPairingResultFunction() { |
1028 } | 1028 } |
1029 | 1029 |
1030 EasyUnlockPrivateSetAutoPairingResultFunction:: | 1030 EasyUnlockPrivateSetAutoPairingResultFunction:: |
1031 ~EasyUnlockPrivateSetAutoPairingResultFunction() { | 1031 ~EasyUnlockPrivateSetAutoPairingResultFunction() { |
1032 } | 1032 } |
1033 | 1033 |
1034 bool EasyUnlockPrivateSetAutoPairingResultFunction::RunSync() { | 1034 ExtensionFunction::ResponseAction |
| 1035 EasyUnlockPrivateSetAutoPairingResultFunction::Run() { |
1035 std::unique_ptr<easy_unlock_private::SetAutoPairingResult::Params> params = | 1036 std::unique_ptr<easy_unlock_private::SetAutoPairingResult::Params> params = |
1036 easy_unlock_private::SetAutoPairingResult::Params::Create(*args_); | 1037 easy_unlock_private::SetAutoPairingResult::Params::Create(*args_); |
1037 EXTENSION_FUNCTION_VALIDATE(params); | 1038 EXTENSION_FUNCTION_VALIDATE(params); |
1038 | 1039 |
1039 std::string error_message; | 1040 std::string error_message; |
1040 if (params->result.error_message) | 1041 if (params->result.error_message) |
1041 error_message = *params->result.error_message; | 1042 error_message = *params->result.error_message; |
1042 | 1043 |
1043 Profile* profile = Profile::FromBrowserContext(browser_context()); | 1044 Profile* profile = Profile::FromBrowserContext(browser_context()); |
1044 EasyUnlockService::Get(profile) | 1045 EasyUnlockService::Get(profile) |
1045 ->SetAutoPairingResult(params->result.success, error_message); | 1046 ->SetAutoPairingResult(params->result.success, error_message); |
1046 | 1047 |
1047 return true; | 1048 return RespondNow(NoArguments()); |
1048 } | 1049 } |
1049 | 1050 |
1050 EasyUnlockPrivateFindSetupConnectionFunction:: | 1051 EasyUnlockPrivateFindSetupConnectionFunction:: |
1051 EasyUnlockPrivateFindSetupConnectionFunction() | 1052 EasyUnlockPrivateFindSetupConnectionFunction() |
1052 : bluetooth_throttler_(new proximity_auth::BluetoothThrottlerImpl( | 1053 : bluetooth_throttler_(new proximity_auth::BluetoothThrottlerImpl( |
1053 base::WrapUnique(new base::DefaultTickClock()))) {} | 1054 base::WrapUnique(new base::DefaultTickClock()))) {} |
1054 | 1055 |
1055 EasyUnlockPrivateFindSetupConnectionFunction:: | 1056 EasyUnlockPrivateFindSetupConnectionFunction:: |
1056 ~EasyUnlockPrivateFindSetupConnectionFunction() { | 1057 ~EasyUnlockPrivateFindSetupConnectionFunction() { |
1057 // |connection_finder_| has a raw pointer to |bluetooth_throttler_|, so it | 1058 // |connection_finder_| has a raw pointer to |bluetooth_throttler_|, so it |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 | 1105 |
1105 return true; | 1106 return true; |
1106 } | 1107 } |
1107 | 1108 |
1108 EasyUnlockPrivateSetupConnectionStatusFunction:: | 1109 EasyUnlockPrivateSetupConnectionStatusFunction:: |
1109 EasyUnlockPrivateSetupConnectionStatusFunction() {} | 1110 EasyUnlockPrivateSetupConnectionStatusFunction() {} |
1110 | 1111 |
1111 EasyUnlockPrivateSetupConnectionStatusFunction:: | 1112 EasyUnlockPrivateSetupConnectionStatusFunction:: |
1112 ~EasyUnlockPrivateSetupConnectionStatusFunction() {} | 1113 ~EasyUnlockPrivateSetupConnectionStatusFunction() {} |
1113 | 1114 |
1114 bool EasyUnlockPrivateSetupConnectionStatusFunction::RunSync() { | 1115 ExtensionFunction::ResponseAction |
| 1116 EasyUnlockPrivateSetupConnectionStatusFunction::Run() { |
1115 std::unique_ptr<easy_unlock_private::SetupConnectionStatus::Params> params = | 1117 std::unique_ptr<easy_unlock_private::SetupConnectionStatus::Params> params = |
1116 easy_unlock_private::SetupConnectionStatus::Params::Create(*args_); | 1118 easy_unlock_private::SetupConnectionStatus::Params::Create(*args_); |
1117 EXTENSION_FUNCTION_VALIDATE(params); | 1119 EXTENSION_FUNCTION_VALIDATE(params); |
1118 api::easy_unlock_private::ConnectionStatus status = | 1120 api::easy_unlock_private::ConnectionStatus status = |
1119 GetConnectionManager(browser_context()) | 1121 GetConnectionManager(browser_context()) |
1120 ->ConnectionStatus(extension(), params->connection_id); | 1122 ->ConnectionStatus(extension(), params->connection_id); |
1121 results_ = | |
1122 easy_unlock_private::SetupConnectionStatus::Results::Create(status); | |
1123 if (status == api::easy_unlock_private::CONNECTION_STATUS_NONE) | 1123 if (status == api::easy_unlock_private::CONNECTION_STATUS_NONE) |
1124 SetError("Invalid connectionId"); | 1124 return RespondNow(Error("Invalid connectionId")); |
1125 return true; | 1125 return RespondNow(ArgumentList( |
| 1126 easy_unlock_private::SetupConnectionStatus::Results::Create(status))); |
1126 } | 1127 } |
1127 | 1128 |
1128 EasyUnlockPrivateSetupConnectionDisconnectFunction:: | 1129 EasyUnlockPrivateSetupConnectionDisconnectFunction:: |
1129 EasyUnlockPrivateSetupConnectionDisconnectFunction() {} | 1130 EasyUnlockPrivateSetupConnectionDisconnectFunction() {} |
1130 | 1131 |
1131 EasyUnlockPrivateSetupConnectionDisconnectFunction:: | 1132 EasyUnlockPrivateSetupConnectionDisconnectFunction:: |
1132 ~EasyUnlockPrivateSetupConnectionDisconnectFunction() {} | 1133 ~EasyUnlockPrivateSetupConnectionDisconnectFunction() {} |
1133 | 1134 |
1134 bool EasyUnlockPrivateSetupConnectionDisconnectFunction::RunSync() { | 1135 ExtensionFunction::ResponseAction |
| 1136 EasyUnlockPrivateSetupConnectionDisconnectFunction::Run() { |
1135 std::unique_ptr<easy_unlock_private::SetupConnectionDisconnect::Params> | 1137 std::unique_ptr<easy_unlock_private::SetupConnectionDisconnect::Params> |
1136 params = easy_unlock_private::SetupConnectionDisconnect::Params::Create( | 1138 params = easy_unlock_private::SetupConnectionDisconnect::Params::Create( |
1137 *args_); | 1139 *args_); |
1138 EXTENSION_FUNCTION_VALIDATE(params); | 1140 EXTENSION_FUNCTION_VALIDATE(params); |
1139 bool success = GetConnectionManager(browser_context()) | 1141 if (!GetConnectionManager(browser_context()) |
1140 ->Disconnect(extension(), params->connection_id); | 1142 ->Disconnect(extension(), params->connection_id)) { |
1141 if (!success) | 1143 return RespondNow(Error("Invalid connectionId.")); |
1142 SetError("Invalid connectionId."); | 1144 } |
1143 return true; | 1145 return RespondNow(NoArguments()); |
1144 } | 1146 } |
1145 | 1147 |
1146 EasyUnlockPrivateSetupConnectionSendFunction:: | 1148 EasyUnlockPrivateSetupConnectionSendFunction:: |
1147 EasyUnlockPrivateSetupConnectionSendFunction() {} | 1149 EasyUnlockPrivateSetupConnectionSendFunction() {} |
1148 | 1150 |
1149 EasyUnlockPrivateSetupConnectionSendFunction:: | 1151 EasyUnlockPrivateSetupConnectionSendFunction:: |
1150 ~EasyUnlockPrivateSetupConnectionSendFunction() {} | 1152 ~EasyUnlockPrivateSetupConnectionSendFunction() {} |
1151 | 1153 |
1152 bool EasyUnlockPrivateSetupConnectionSendFunction::RunSync() { | 1154 ExtensionFunction::ResponseAction |
| 1155 EasyUnlockPrivateSetupConnectionSendFunction::Run() { |
1153 std::unique_ptr<easy_unlock_private::SetupConnectionSend::Params> params = | 1156 std::unique_ptr<easy_unlock_private::SetupConnectionSend::Params> params = |
1154 easy_unlock_private::SetupConnectionSend::Params::Create(*args_); | 1157 easy_unlock_private::SetupConnectionSend::Params::Create(*args_); |
1155 EXTENSION_FUNCTION_VALIDATE(params); | 1158 EXTENSION_FUNCTION_VALIDATE(params); |
1156 std::string payload(params->data.begin(), params->data.end()); | 1159 std::string payload(params->data.begin(), params->data.end()); |
1157 bool success = GetConnectionManager(browser_context()) | 1160 if (!GetConnectionManager(browser_context()) |
1158 ->SendMessage(extension(), params->connection_id, payload); | 1161 ->SendMessage(extension(), params->connection_id, payload)) { |
1159 if (!success) | 1162 return RespondNow(Error("Invalid connectionId.")); |
1160 SetError("Invalid connectionId."); | 1163 } |
1161 return true; | 1164 return RespondNow(NoArguments()); |
1162 } | 1165 } |
1163 | 1166 |
1164 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction:: | 1167 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction:: |
1165 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() {} | 1168 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() {} |
1166 | 1169 |
1167 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction:: | 1170 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction:: |
1168 ~EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() {} | 1171 ~EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() {} |
1169 | 1172 |
1170 bool EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction::RunSync() { | 1173 ExtensionFunction::ResponseAction |
| 1174 EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction::Run() { |
1171 std::unique_ptr<easy_unlock_private::SetupConnectionGetDeviceAddress::Params> | 1175 std::unique_ptr<easy_unlock_private::SetupConnectionGetDeviceAddress::Params> |
1172 params = | 1176 params = |
1173 easy_unlock_private::SetupConnectionGetDeviceAddress::Params::Create( | 1177 easy_unlock_private::SetupConnectionGetDeviceAddress::Params::Create( |
1174 *args_); | 1178 *args_); |
1175 EXTENSION_FUNCTION_VALIDATE(params); | 1179 EXTENSION_FUNCTION_VALIDATE(params); |
1176 std::string device_address = | 1180 std::string device_address = |
1177 GetConnectionManager(browser_context()) | 1181 GetConnectionManager(browser_context()) |
1178 ->GetDeviceAddress(extension(), params->connection_id); | 1182 ->GetDeviceAddress(extension(), params->connection_id); |
1179 results_ = | 1183 if (device_address.empty()) |
| 1184 return RespondNow(Error("Invalid connectionId.")); |
| 1185 return RespondNow(ArgumentList( |
1180 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( | 1186 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( |
1181 device_address); | 1187 device_address))); |
1182 if (device_address.empty()) | |
1183 SetError("Invalid connectionId."); | |
1184 return true; | |
1185 } | 1188 } |
1186 | 1189 |
1187 } // namespace extensions | 1190 } // namespace extensions |
OLD | NEW |