Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/screenlock_private_api.cc |
| diff --git a/chrome/browser/chromeos/extensions/screenlock_private_api.cc b/chrome/browser/chromeos/extensions/screenlock_private_api.cc |
| index c009fce65dd2142f6260c1ac887a017abaa431a0..5a6cfa4ec4e8c0e8b0af46ed97caffa5fe181ce6 100644 |
| --- a/chrome/browser/chromeos/extensions/screenlock_private_api.cc |
| +++ b/chrome/browser/chromeos/extensions/screenlock_private_api.cc |
| @@ -17,6 +17,45 @@ namespace screenlock = extensions::api::screenlock_private; |
| namespace extensions { |
| +namespace { |
| + |
| +const char kNotLockedError[] = "Screen is not currently locked."; |
| + |
| +chromeos::LoginDisplay::AuthType ToLoginDisplayAuthType( |
| + screenlock::AuthType auth_type) { |
| + switch (auth_type) { |
| + case screenlock::AUTH_TYPE_SYSTEMPASSWORD: |
| + return chromeos::LoginDisplay::OFFLINE_PASSWORD; |
| + case screenlock::AUTH_TYPE_NUMERICPIN: |
| + return chromeos::LoginDisplay::NUMERIC_PIN; |
| + case screenlock::AUTH_TYPE_USERCLICK: |
| + return chromeos::LoginDisplay::USER_CLICK; |
| + default: |
| + NOTREACHED(); |
| + return chromeos::LoginDisplay::OFFLINE_PASSWORD; |
| + } |
| +} |
| + |
| +screenlock::AuthType ToScreenlockPrivateAuthType( |
| + chromeos::LoginDisplay::AuthType auth_type) { |
| + switch (auth_type) { |
| + case chromeos::LoginDisplay::OFFLINE_PASSWORD: |
| + return screenlock::AUTH_TYPE_SYSTEMPASSWORD; |
| + case chromeos::LoginDisplay::NUMERIC_PIN: |
| + return screenlock::AUTH_TYPE_NUMERICPIN; |
| + case chromeos::LoginDisplay::USER_CLICK: |
| + return screenlock::AUTH_TYPE_USERCLICK; |
| + case chromeos::LoginDisplay::ONLINE_SIGN_IN: |
| + // Apps should treat forced online sign in same as system password. |
| + return screenlock::AUTH_TYPE_SYSTEMPASSWORD; |
| + default: |
| + NOTREACHED(); |
| + return screenlock::AUTH_TYPE_SYSTEMPASSWORD; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} |
| ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} |
| @@ -85,7 +124,8 @@ bool ScreenlockPrivateShowButtonFunction::RunImpl() { |
| chromeos::ScreenLocker* locker = |
| chromeos::ScreenLocker::default_screen_locker(); |
| if (!locker) { |
| - SendResponse(error_.empty()); |
| + SetError(kNotLockedError); |
| + SendResponse(false); |
| return true; |
| } |
| extensions::ImageLoader* loader = extensions::ImageLoader::Get(GetProfile()); |
| @@ -103,13 +143,107 @@ void ScreenlockPrivateShowButtonFunction::OnImageLoaded( |
| ScreenlockPrivateEventRouter* router = |
| ScreenlockPrivateEventRouter::GetFactoryInstance()->GetForProfile( |
| GetProfile()); |
| + const chromeos::User* user = |
| + chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
| locker->ShowUserPodButton( |
| - GetProfile()->GetProfileName(), image, |
| + user->email(), |
| + image, |
| base::Bind(&ScreenlockPrivateEventRouter::OnButtonClicked, |
| base::Unretained(router))); |
| SendResponse(error_.empty()); |
| } |
| +ScreenlockPrivateHideButtonFunction::ScreenlockPrivateHideButtonFunction() {} |
| + |
| +ScreenlockPrivateHideButtonFunction::~ScreenlockPrivateHideButtonFunction() {} |
| + |
| +bool ScreenlockPrivateHideButtonFunction::RunImpl() { |
| + chromeos::ScreenLocker* locker = |
| + chromeos::ScreenLocker::default_screen_locker(); |
| + if (locker) { |
| + const chromeos::User* user = |
| + chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
| + locker->HideUserPodButton(user->email()); |
| + } else { |
| + SetError(kNotLockedError); |
| + } |
| + SendResponse(error_.empty()); |
| + return true; |
| +} |
| + |
| +ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {} |
| + |
| +ScreenlockPrivateSetAuthTypeFunction::~ScreenlockPrivateSetAuthTypeFunction() {} |
| + |
| +bool ScreenlockPrivateSetAuthTypeFunction::RunImpl() { |
| + scoped_ptr<screenlock::SetAuthType::Params> params( |
| + screenlock::SetAuthType::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + chromeos::ScreenLocker* locker = |
| + chromeos::ScreenLocker::default_screen_locker(); |
| + if (locker) { |
| + std::string initial_value = |
| + params->initial_value.get() ? *(params->initial_value.get()) : ""; |
| + const chromeos::User* user = |
| + chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
| + locker->SetAuthType(user->email(), |
| + ToLoginDisplayAuthType(params->auth_type), |
| + initial_value); |
| + } else { |
| + SetError(kNotLockedError); |
| + } |
| + SendResponse(error_.empty()); |
| + return true; |
| +} |
| + |
| +ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {} |
| + |
| +ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {} |
| + |
| +bool ScreenlockPrivateGetAuthTypeFunction::RunImpl() { |
| + chromeos::ScreenLocker* locker = |
| + chromeos::ScreenLocker::default_screen_locker(); |
| + if (locker) { |
| + const chromeos::User* user = |
| + chromeos::UserManager::Get()->GetUserByProfile(GetProfile()); |
| + chromeos::LoginDisplay::AuthType auth_type = |
| + locker->GetAuthType(user->email()); |
| + std::string auth_type_name = |
| + screenlock::ToString(ToScreenlockPrivateAuthType(auth_type)); |
| + SetResult(new base::StringValue(auth_type_name)); |
| + } else { |
| + SetError(kNotLockedError); |
| + } |
| + SendResponse(error_.empty()); |
| + return true; |
| +} |
| + |
| +ScreenlockPrivateAcceptAuthAttemptFunction:: |
| + ScreenlockPrivateAcceptAuthAttemptFunction() {} |
| + |
| +ScreenlockPrivateAcceptAuthAttemptFunction:: |
| + ~ScreenlockPrivateAcceptAuthAttemptFunction() {} |
| + |
| +bool ScreenlockPrivateAcceptAuthAttemptFunction::RunImpl() { |
| + scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( |
| + screenlock::AcceptAuthAttempt::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + chromeos::ScreenLocker* locker = |
| + chromeos::ScreenLocker::default_screen_locker(); |
| + if (locker) { |
| + if (params->accept) |
| + locker->Hide(); |
|
xiyuan
2014/02/20 17:44:44
Isn't Hide() a static method?
Tim Song
2014/02/20 21:06:08
Done.
|
| + else |
| + locker->EnableInput(); |
| + } else { |
| + SetError(kNotLockedError); |
| + } |
| + SendResponse(error_.empty()); |
| + return true; |
| +} |
| + |
| ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(Profile* profile) |
| : profile_(profile) { |
| chromeos::SessionManagerClient* session_manager = |
| @@ -163,4 +297,18 @@ void ScreenlockPrivateEventRouter::OnButtonClicked() { |
| DispatchEvent(screenlock::OnButtonClicked::kEventName, NULL); |
| } |
| +void ScreenlockPrivateEventRouter::OnAuthAttempted( |
| + chromeos::LoginDisplay::AuthType auth_type, |
| + const std::string& value) { |
| + scoped_ptr<base::ListValue> args(new base::ListValue()); |
| + args->AppendString( |
| + screenlock::ToString(ToScreenlockPrivateAuthType(auth_type))); |
| + args->AppendString(value); |
| + |
| + scoped_ptr<extensions::Event> event(new extensions::Event( |
| + screenlock::OnAuthAttempted::kEventName, args.Pass())); |
| + extensions::ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent( |
| + event.Pass()); |
| +} |
| + |
| } // namespace extensions |