Chromium Code Reviews| Index: chrome/browser/chromeos/login/lock/screen_locker.cc |
| diff --git a/chrome/browser/chromeos/login/lock/screen_locker.cc b/chrome/browser/chromeos/login/lock/screen_locker.cc |
| index 0d9296ce33eda594101d2791217aef32c7308818..2d4c6931fe358e61b1ea509cd45f8290d5bd53ce 100644 |
| --- a/chrome/browser/chromeos/login/lock/screen_locker.cc |
| +++ b/chrome/browser/chromeos/login/lock/screen_locker.cc |
| @@ -7,6 +7,9 @@ |
| #include <string> |
| #include <vector> |
| +#include "ash/login/views/lock_screen.h" |
| +#include "ash/public/interfaces/constants.mojom.h" |
| +#include "ash/public/interfaces/session_controller.mojom.h" |
| #include "ash/shell.h" |
| #include "ash/wm/window_state.h" |
| #include "ash/wm/window_state_aura.h" |
| @@ -46,6 +49,7 @@ |
| #include "chrome/grit/browser_resources.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chromeos/audio/chromeos_sounds.h" |
| +#include "chromeos/chromeos_switches.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/session_manager_client.h" |
| #include "chromeos/login/auth/authenticator.h" |
| @@ -65,6 +69,8 @@ |
| #include "services/device/public/interfaces/constants.mojom.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/screen.h" |
| #include "ui/gfx/image/image.h" |
| #include "url/gurl.h" |
| @@ -80,6 +86,12 @@ namespace { |
| // unlock happens even if animations are broken. |
| const int kUnlockGuardTimeoutMs = 400; |
| +// Returns true if we are using md-based login/lock. |
| +bool IsUsingMdLogin() { |
| + return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + chromeos::switches::kShowMdLogin); |
| +} |
| + |
| // Returns true if fingerprint authentication is available for one of the |
| // |users|. |
| bool IsFingerprintAuthenticationAvailableForUsers( |
| @@ -110,7 +122,7 @@ class ScreenLockObserver : public SessionManagerClient::StubDelegate, |
| ~ScreenLockObserver() override { |
| if (DBusThreadManager::IsInitialized()) { |
| DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate( |
| - NULL); |
| + nullptr); |
| } |
| } |
| @@ -152,12 +164,47 @@ class ScreenLockObserver : public SessionManagerClient::StubDelegate, |
| DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
| }; |
| -ScreenLockObserver* g_screen_lock_observer = NULL; |
| +// Stubbed delegate that will eventually be replaced by mojo calls. |
| +class StubDelegate : public ScreenLocker::Delegate { |
| + public: |
| + StubDelegate() {} |
| + ~StubDelegate() override {} |
| + |
| + // ScreenLocker::Delegate: |
| + void SetInputEnabled(bool enabled) override { NOTIMPLEMENTED(); } |
| + void ShowErrorMessage(int error_msg_id, |
| + HelpAppLauncher::HelpTopic help_topic_id) override { |
| + NOTIMPLEMENTED(); |
| + } |
| + void ClearErrors() override { NOTIMPLEMENTED(); } |
| + void AnimateAuthenticationSuccess() override { NOTIMPLEMENTED(); } |
| + void OnLockWebUIReady() override { NOTIMPLEMENTED(); } |
| + void OnLockBackgroundDisplayed() override { NOTIMPLEMENTED(); } |
| + void OnHeaderBarVisible() override { NOTIMPLEMENTED(); } |
| + void OnAshLockAnimationFinished() override { NOTIMPLEMENTED(); } |
| + void SetFingerprintState(const AccountId& account_id, |
| + ScreenLocker::FingerprintState state) override { |
| + NOTIMPLEMENTED(); |
| + } |
| + content::WebContents* GetWebContents() override { return nullptr; } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(StubDelegate); |
| +}; |
| + |
| +ScreenLockObserver* g_screen_lock_observer = nullptr; |
| } // namespace |
| // static |
| -ScreenLocker* ScreenLocker::screen_locker_ = NULL; |
| +ScreenLocker* ScreenLocker::screen_locker_ = nullptr; |
| + |
| +////////////////////////////////////////////////////////////////////////////// |
| +// ScreenLocker::Delegate, public: |
| + |
| +ScreenLocker::Delegate::Delegate() {} |
|
James Cook
2017/05/08 22:04:20
nit: = default where you can (and above)
jdufault
2017/05/08 23:02:34
Done.
|
| + |
| +ScreenLocker::Delegate::~Delegate() {} |
| ////////////////////////////////////////////////////////////////////////////// |
| // ScreenLocker, public: |
| @@ -187,15 +234,36 @@ void ScreenLocker::Init() { |
| authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); |
| extended_authenticator_ = ExtendedAuthenticator::Create(this); |
| - web_ui_.reset(new WebUIScreenLocker(this)); |
| - web_ui()->LockScreen(); |
| - |
| - // Ownership of |icon_image_source| is passed. |
| - screenlock_icon_provider_.reset(new ScreenlockIconProvider); |
| - ScreenlockIconSource* screenlock_icon_source = |
| - new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
| - content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), |
| - screenlock_icon_source); |
| + if (IsUsingMdLogin()) { |
| + // Create delegate that will eventually call into the views-based lock |
| + // screen via mojo. |
| + delegate_ = new StubDelegate(); |
| + owns_delegate_ = true; |
| + |
| + // Create and display lock screen. |
| + // TODO(jdufualt): LockWindow should live in ash. |
| + // TODO(jdufault): Calling ash::ShowLockScreenInWidget should be a mojo |
| + // call. We should only set the session state to locked after the mojo call |
| + // has completed. |
| + LockWindow* lock_window = new LockWindow(); |
| + lock_window->SetBounds( |
| + display::Screen::GetScreen()->GetPrimaryDisplay().bounds()); |
| + ash::ShowLockScreenInWidget(lock_window); |
|
James Cook
2017/05/08 22:04:20
This is pretty weird (injecting ash-based views in
jdufault
2017/05/08 23:02:35
LockWindow will move into ash/ soon. I want to get
|
| + session_manager::SessionManager::Get()->SetSessionState( |
| + session_manager::SessionState::LOCKED); |
| + } else { |
| + web_ui_.reset(new WebUIScreenLocker(this)); |
| + delegate_ = web_ui_.get(); |
| + owns_delegate_ = false; |
| + web_ui_->LockScreen(); |
| + |
| + // Ownership of |icon_image_source| is passed. |
| + screenlock_icon_provider_.reset(new ScreenlockIconProvider); |
|
James Cook
2017/05/08 22:04:20
nit: MakeUnique while you're here
jdufault
2017/05/08 23:02:34
Done.
|
| + ScreenlockIconSource* screenlock_icon_source = |
| + new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
| + content::URLDataSource::Add(web_ui_->web_contents()->GetBrowserContext(), |
| + screenlock_icon_source); |
| + } |
| // Start locking on ash side. |
| SessionControllerClient::Get()->StartLock(base::Bind( |
| @@ -219,10 +287,10 @@ void ScreenLocker::OnAuthFailure(const AuthFailure& error) { |
| // Don't enable signout button here as we're showing |
| // MessageBubble. |
| - web_ui()->ShowErrorMessage(incorrect_passwords_count_++ |
| - ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME |
| - : IDS_LOGIN_ERROR_AUTHENTICATING, |
| - HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| + delegate_->ShowErrorMessage(incorrect_passwords_count_++ |
| + ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME |
| + : IDS_LOGIN_ERROR_AUTHENTICATING, |
| + HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| if (auth_status_consumer_) |
| auth_status_consumer_->OnAuthFailure(error); |
| @@ -246,7 +314,7 @@ void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
| user_manager::UserManager::Get()->FindUser(user_context.GetAccountId()); |
| if (user) { |
| if (!user->is_active()) { |
| - saved_ime_state_ = NULL; |
| + saved_ime_state_ = nullptr; |
| user_manager::UserManager::Get()->SwitchActiveUser( |
| user_context.GetAccountId()); |
| } |
| @@ -279,7 +347,7 @@ void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
| FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, |
| weak_factory_.GetWeakPtr()), |
| base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); |
| - web_ui()->AnimateAuthenticationSuccess(); |
| + delegate_->AnimateAuthenticationSuccess(); |
| } |
| void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { |
| @@ -314,7 +382,7 @@ void ScreenLocker::Authenticate(const UserContext& user_context) { |
| << "Invalid user trying to unlock."; |
| authentication_start_time_ = base::Time::Now(); |
| - web_ui()->SetInputEnabled(false); |
| + delegate_->SetInputEnabled(false); |
| if (user_context.IsUsingPin()) |
| unlock_attempt_type_ = AUTH_PIN; |
| @@ -378,18 +446,18 @@ void ScreenLocker::OnStartLockCallback(bool locked) { |
| if (!locked) |
| return; |
| - web_ui()->OnAshLockAnimationFinished(); |
| + delegate_->OnAshLockAnimationFinished(); |
| AccessibilityManager::Get()->PlayEarcon( |
| chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); |
| } |
| void ScreenLocker::ClearErrors() { |
| - web_ui()->ClearErrors(); |
| + delegate_->ClearErrors(); |
| } |
| void ScreenLocker::Signout() { |
| - web_ui()->ClearErrors(); |
| + delegate_->ClearErrors(); |
| base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| // We expect that this call will not wait for any user input. |
| // If it changes at some point, we will need to force exit. |
| @@ -400,14 +468,14 @@ void ScreenLocker::Signout() { |
| } |
| void ScreenLocker::EnableInput() { |
| - web_ui()->SetInputEnabled(true); |
| + delegate_->SetInputEnabled(true); |
| } |
| void ScreenLocker::ShowErrorMessage(int error_msg_id, |
| HelpAppLauncher::HelpTopic help_topic_id, |
| bool sign_out_only) { |
| - web_ui()->SetInputEnabled(!sign_out_only); |
| - web_ui()->ShowErrorMessage(error_msg_id, help_topic_id); |
| + delegate_->SetInputEnabled(!sign_out_only); |
| + delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
| } |
| void ScreenLocker::SetLoginStatusConsumer( |
| @@ -425,7 +493,7 @@ void ScreenLocker::InitClass() { |
| void ScreenLocker::ShutDownClass() { |
| DCHECK(g_screen_lock_observer); |
| delete g_screen_lock_observer; |
| - g_screen_lock_observer = NULL; |
| + g_screen_lock_observer = nullptr; |
| } |
| // static |
| @@ -511,7 +579,7 @@ void ScreenLocker::Hide() { |
| // static |
| void ScreenLocker::ScheduleDeletion() { |
| // Avoid possible multiple calls. |
| - if (screen_locker_ == NULL) |
| + if (screen_locker_ == nullptr) |
| return; |
| VLOG(1) << "Deleting ScreenLocker " << screen_locker_; |
| @@ -519,7 +587,7 @@ void ScreenLocker::ScheduleDeletion() { |
| SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); |
| delete screen_locker_; |
| - screen_locker_ = NULL; |
| + screen_locker_ = nullptr; |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -530,10 +598,10 @@ ScreenLocker::~ScreenLocker() { |
| DCHECK(base::MessageLoopForUI::IsCurrent()); |
| if (authenticator_.get()) |
| - authenticator_->SetConsumer(NULL); |
| + authenticator_->SetConsumer(nullptr); |
| ClearErrors(); |
| - screen_locker_ = NULL; |
| + screen_locker_ = nullptr; |
| bool state = false; |
| VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
| content::NotificationService::current()->Notify( |
| @@ -551,6 +619,12 @@ ScreenLocker::~ScreenLocker() { |
| if (saved_ime_state_.get()) { |
| input_method::InputMethodManager::Get()->SetState(saved_ime_state_); |
| } |
| + |
| + if (owns_delegate_) { |
| + owns_delegate_ = false; |
| + delete delegate_; |
| + delegate_ = nullptr; |
| + } |
| } |
| void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { |
| @@ -615,8 +689,8 @@ void ScreenLocker::OnAuthScanDone( |
| OnFingerprintAuthFailure(*active_user); |
| return; |
| } |
| - web_ui()->SetFingerprintState(active_user->GetAccountId(), |
| - WebUIScreenLocker::FingerprintState::kSignin); |
| + delegate_->SetFingerprintState(active_user->GetAccountId(), |
| + FingerprintState::kSignin); |
| OnAuthSuccess(user_context); |
| } |
| @@ -628,8 +702,8 @@ void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) { |
| UMA_HISTOGRAM_ENUMERATION("ScreenLocker.AuthenticationFailure", |
| unlock_attempt_type_, UnlockType::AUTH_COUNT); |
| - web_ui()->SetFingerprintState(user.GetAccountId(), |
| - WebUIScreenLocker::FingerprintState::kFailed); |
| + delegate_->SetFingerprintState(user.GetAccountId(), |
| + FingerprintState::kFailed); |
| quick_unlock::QuickUnlockStorage* quick_unlock_storage = |
| quick_unlock::QuickUnlockFactory::GetForUser(&user); |
| @@ -637,10 +711,10 @@ void ScreenLocker::OnFingerprintAuthFailure(const user_manager::User& user) { |
| quick_unlock_storage->IsFingerprintAuthenticationAvailable()) { |
| quick_unlock_storage->fingerprint_storage()->AddUnlockAttempt(); |
| if (quick_unlock_storage->fingerprint_storage()->ExceededUnlockAttempts()) { |
| - web_ui()->SetFingerprintState( |
| - user.GetAccountId(), WebUIScreenLocker::FingerprintState::kRemoved); |
| - web_ui()->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT, |
| - HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| + delegate_->SetFingerprintState(user.GetAccountId(), |
| + FingerprintState::kRemoved); |
| + delegate_->ShowErrorMessage(IDS_LOGIN_ERROR_FINGERPRINT_MAX_ATTEMPT, |
| + HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| } |
| } |