#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.h"
+#include <vector>
+
#include "base/bind.h"
#include "base/lazy_instance.h"
+#include "base/memory/linked_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_bluetooth_util.h"
#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_crypto_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
#include "chrome/browser/signin/easy_unlock_service.h"
+#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/common/extensions/api/easy_unlock_private.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/proximity_auth/bluetooth_util.h"
+#include "content/public/browser/browser_thread.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
-#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/chromeos_utils.h"
+#include "components/user_manager/user.h"
+#include "components/user_manager/user_manager.h"
#endif
namespace extensions {
->crypto_delegate();
}
-EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler(
- content::BrowserContext* context) {
- return EasyUnlockService::Get(Profile::FromBrowserContext(context))
- ->GetScreenlockStateHandler();
-}
-
EasyUnlockScreenlockStateHandler::State ToScreenlockStateHandlerState(
easy_unlock_private::State state) {
switch (state) {
return EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE;
case easy_unlock_private::STATE_PHONE_NOT_NEARBY:
return EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY;
+ case easy_unlock_private::STATE_PHONE_UNSUPPORTED:
+ return EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED;
case easy_unlock_private::STATE_AUTHENTICATED:
return EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED;
default:
const base::string16 device_type = base::ASCIIToUTF16("Chromeschnozzle");
#endif // defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS)
+ const user_manager::UserManager* manager = user_manager::UserManager::Get();
+ const user_manager::User* user = manager ? manager->GetActiveUser() : NULL;
+ const std::string user_email_utf8 =
+ user ? user->display_email() : std::string();
+ const base::string16 user_email = base::UTF8ToUTF16(user_email_utf8);
+#else
+ // TODO(isherman): Set an appropriate user display email for non-ChromeOS
+ // platforms.
+ const base::string16 user_email = base::UTF8ToUTF16("superman@example.com");
+#endif // defined(OS_CHROMEOS)
+
// Common strings.
strings->SetString(
"learnMoreLinkTitle",
l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_LEARN_MORE_LINK_TITLE));
+ strings->SetString("deviceType", device_type);
// Setup notification strings.
strings->SetString(
l10n_util::GetStringUTF16(
IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_TITLE));
strings->SetString(
- "chromebookAddedNotificationMessage",
- l10n_util::GetStringFUTF16(
+ "chromebookAddedNotificationMessage",
+ l10n_util::GetStringFUTF16(
IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_MESSAGE,
device_type));
+ strings->SetString(
+ "chromebookAddedNotificationAboutButton",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON));
+
+ // Shared "Learn more" button for the pairing changed and pairing change
+ // applied notification.
+ strings->SetString(
+ "phoneChangedNotificationLearnMoreButton",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_NOTIFICATION_LEARN_MORE_BUTTON));
+
+ // Pairing changed notification strings.
+ strings->SetString(
+ "phoneChangedNotificationTitle",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_TITLE));
+ strings->SetString(
+ "phoneChangedNotificationMessage",
+ l10n_util::GetStringFUTF16(
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_MESSAGE,
+ device_type));
+ strings->SetString(
+ "phoneChangedNotificationUpdateButton",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_UPDATE_BUTTON));
+
+ // Phone change applied notification strings.
+ strings->SetString(
+ "phoneChangeAppliedNotificationTitle",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_TITLE));
+ strings->SetString(
+ "phoneChangeAppliedNotificationMessage",
+ l10n_util::GetStringUTF16(
+ IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_MESSAGE));
// Setup dialog strings.
// Step 1: Intro.
IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_TITLE, device_type));
strings->SetString(
"setupIntroHeaderText",
- l10n_util::GetStringFUTF16(
- IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_TEXT, device_type));
- strings->SetString(
- "setupIntroHeaderFootnote",
- l10n_util::GetStringUTF16(
- IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_FOOTNOTE));
+ l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_TEXT,
+ device_type,
+ user_email));
strings->SetString(
"setupIntroFindPhoneButtonLabel",
l10n_util::GetStringUTF16(
l10n_util::GetStringFUTF16(
IDS_EASY_UNLOCK_SETUP_ERROR_CONNECTING_TO_PHONE, device_type));
- // TODO(isherman): Remove these strings once the app has been updated.
- strings->SetString(
- "notificationTitle",
- l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_TITLE,
- device_type));
- strings->SetString(
- "notificationMessage",
- l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_MESSAGE,
- device_type));
- strings->SetString(
- "notificationButtonTitle",
- l10n_util::GetStringUTF16(
- IDS_EASY_UNLOCK_SETUP_NOTIFICATION_BUTTON_TITLE));
+ // TODO(isherman): Remove this string once the app has been updated.
+ strings->SetString("setupIntroHeaderFootnote", base::string16());
SetResult(strings.release());
return true;
EXTENSION_FUNCTION_VALIDATE(params);
GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement(
- params->private_key,
- params->public_key,
+ *params,
base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData,
this));
return true;
EXTENSION_FUNCTION_VALIDATE(params);
GetCryptoDelegate(browser_context())->CreateSecureMessage(
- params->payload,
- params->key,
- params->options.associated_data ?
- *params->options.associated_data : std::string(),
- params->options.public_metadata ?
- *params->options.public_metadata : std::string(),
- params->options.verification_key_id ?
- *params->options.verification_key_id : std::string(),
- params->options.encrypt_type,
- params->options.sign_type,
+ *params,
base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData,
this));
return true;
EXTENSION_FUNCTION_VALIDATE(params);
GetCryptoDelegate(browser_context())->UnwrapSecureMessage(
- params->secure_message,
- params->key,
- params->options.associated_data ?
- *params->options.associated_data : std::string(),
- params->options.encrypt_type,
- params->options.sign_type,
+ *params,
base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData,
this));
return true;
*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- easy_unlock::SeekBluetoothDeviceByAddress(
+ proximity_auth::bluetooth_util::SeekDeviceByAddress(
params->device_address,
base::Bind(
- &EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::
- OnSeekCompleted,
- this));
+ &EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekSuccess,
+ this),
+ base::Bind(
+ &EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekFailure,
+ this),
+ content::BrowserThread::GetBlockingPool());
return true;
}
-void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted(
- const easy_unlock::SeekDeviceResult& seek_result) {
- if (seek_result.success) {
- SendResponse(true);
- } else {
- SetError(seek_result.error_message);
- SendResponse(false);
- }
+void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekSuccess() {
+ SendResponse(true);
+}
+
+void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekFailure(
+ const std::string& error_message) {
+ SetError(error_message);
+ SendResponse(false);
+}
+
+EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction::
+ EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {}
+
+EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction::
+ ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {}
+
+void EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction::
+ ConnectToService(device::BluetoothDevice* device,
+ const device::BluetoothUUID& uuid) {
+ proximity_auth::bluetooth_util::ConnectToServiceInsecurely(
+ device,
+ uuid,
+ base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction::
+ OnConnect,
+ this),
+ base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction::
+ OnConnectError,
+ this));
}
EasyUnlockPrivateUpdateScreenlockStateFunction::
easy_unlock_private::UpdateScreenlockState::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- EasyUnlockScreenlockStateHandler* screenlock_state_handler =
- GetScreenlockStateHandler(browser_context());
- if (screenlock_state_handler) {
- screenlock_state_handler->ChangeState(
- ToScreenlockStateHandlerState(params->state));
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ if (EasyUnlockService::Get(profile)->UpdateScreenlockState(
+ ToScreenlockStateHandlerState(params->state)))
return true;
- }
SetError("Not allowed");
return false;
return true;
}
+EasyUnlockPrivateGetSignInChallengeFunction::
+ EasyUnlockPrivateGetSignInChallengeFunction() {
+}
+
+EasyUnlockPrivateGetSignInChallengeFunction::
+ ~EasyUnlockPrivateGetSignInChallengeFunction() {
+}
+
+bool EasyUnlockPrivateGetSignInChallengeFunction::RunSync() {
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ const std::string challenge =
+ EasyUnlockService::Get(profile)->GetChallenge();
+ if (!challenge.empty()) {
+ results_ =
+ easy_unlock_private::GetSignInChallenge::Results::Create(challenge);
+ }
+ return true;
+}
+
+EasyUnlockPrivateTrySignInSecretFunction::
+ EasyUnlockPrivateTrySignInSecretFunction() {
+}
+
+EasyUnlockPrivateTrySignInSecretFunction::
+ ~EasyUnlockPrivateTrySignInSecretFunction() {
+}
+
+bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() {
+ scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params(
+ easy_unlock_private::TrySignInSecret::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ EasyUnlockService::Get(profile)->FinalizeSignin(params->sign_in_secret);
+ return true;
+}
+
+EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() {
+}
+
+EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() {
+}
+
+bool EasyUnlockPrivateGetUserInfoFunction::RunSync() {
+ EasyUnlockService* service =
+ EasyUnlockService::Get(Profile::FromBrowserContext(browser_context()));
+ std::vector<linked_ptr<easy_unlock_private::UserInfo> > users;
+ std::string user_id = service->GetUserEmail();
+ if (!user_id.empty()) {
+ users.push_back(
+ linked_ptr<easy_unlock_private::UserInfo>(
+ new easy_unlock_private::UserInfo()));
+ users[0]->user_id = user_id;
+ users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR;
+ users[0]->data_ready = users[0]->logged_in ||
+ service->GetRemoteDevices() != NULL;
+ }
+ results_ = easy_unlock_private::GetUserInfo::Results::Create(users);
+ return true;
+}
+
} // namespace api
} // namespace extensions