Commit 5b584d51 authored by dpolukhin's avatar dpolukhin Committed by Commit bot

Lock screen for Chrome-Athena

Screen lock activates with keyboard accelerator Ctrl+Shift+L and bower button.

BUG=413926
TEST=manual

Review URL: https://codereview.chromium.org/620663005

Cr-Commit-Position: refs/heads/master@{#299878}
parent c2792b84
......@@ -180,6 +180,9 @@
'extensions/pubilc/apps_search_controller_factory.h',
'extensions/public/extension_app_model_builder.h',
'extensions/public/extensions_delegate.h',
'screen_lock/public/screen_lock_manager.h',
'screen_lock/screen_lock_manager_base.cc',
'screen_lock/screen_lock_manager_base.h',
'virtual_keyboard/public/virtual_keyboard_manager.h',
'virtual_keyboard/virtual_keyboard_manager_impl.cc',
],
......@@ -189,6 +192,7 @@
'type': 'static_library',
'dependencies': [
'../components/components.gyp:component_metrics_proto',
'../chrome/chrome.gyp:browser_chromeos',
'../chrome/chrome.gyp:browser_extensions',
'../components/components.gyp:omnibox',
],
......@@ -205,6 +209,7 @@
'extensions/chrome/chrome_search_controller_factory.cc',
'extensions/chrome/chrome_search_controller_factory.h',
'extensions/chrome/extensions_delegate_impl.cc',
'screen_lock/chrome/chrome_screen_lock_manager.cc',
],
},
{
......@@ -232,6 +237,7 @@
'extensions/shell/shell_search_controller_factory.h',
'extensions/shell/url_search_provider.cc',
'extensions/shell/url_search_provider.h',
'screen_lock/shell/shell_screen_lock_manager.cc',
],
},
{
......
......@@ -8,6 +8,7 @@ include_rules = [
"+athena/resource_manager/public",
"+athena/resources/grit/athena_resources.h",
"+athena/screen/public",
"+athena/screen_lock/public",
"+athena/system/public",
"+athena/task/public",
"+athena/virtual_keyboard/public",
......
......@@ -20,6 +20,7 @@
#include "athena/main/placeholder.h"
#include "athena/resource_manager/public/resource_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/screen_lock/public/screen_lock_manager.h"
#include "athena/system/public/system_ui.h"
#include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
#include "athena/wm/public/window_manager.h"
......@@ -128,6 +129,7 @@ void CreateVirtualKeyboardWithContext(content::BrowserContext* context) {
}
void StartAthenaSessionWithContext(content::BrowserContext* context) {
athena::ScreenLockManager::Create();
athena::ExtensionsDelegate::CreateExtensionsDelegate(context);
StartAthenaSession(
athena::CreateContentActivityFactory(),
......@@ -160,6 +162,7 @@ void ShutdownAthena() {
athena::ActivityManager::Shutdown();
athena::HomeCard::Shutdown();
athena::ExtensionsDelegate::Shutdown();
athena::ScreenLockManager::Shutdown();
session_started = false;
}
athena::AppRegistry::ShutDown();
......
......@@ -154,6 +154,10 @@ class AthenaEventTargeter : public aura::WindowTargeter,
container_->RemoveObserver(this);
}
void SetPreviousEventTargeter(scoped_ptr<ui::EventTargeter> targeter) {
previous_root_event_targeter_ = targeter.Pass();
}
private:
// aura::WindowTargeter:
virtual bool SubtreeCanAcceptEvent(
......@@ -183,10 +187,11 @@ class AthenaEventTargeter : public aura::WindowTargeter,
container_ = NULL;
// This will remove myself.
root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>());
root_window->SetEventTargeter(previous_root_event_targeter_.Pass());
}
aura::Window* container_;
scoped_ptr<ui::EventTargeter> previous_root_event_targeter_;
DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter);
};
......@@ -325,8 +330,11 @@ aura::Window* ScreenManagerImpl::CreateContainer(
DCHECK(std::find_if(children.begin(), children.end(), &GrabsInput)
== children.end())
<< "input has already been grabbed by another container";
root_window_->SetEventTargeter(
scoped_ptr<ui::EventTargeter>(new AthenaEventTargeter(container)));
AthenaEventTargeter* athena_event_targeter =
new AthenaEventTargeter(container);
athena_event_targeter->SetPreviousEventTargeter(
root_window_->SetEventTargeter(
scoped_ptr<ui::EventTargeter>(athena_event_targeter)));
}
root_window_->AddChild(container);
......
include_rules = [
"+athena/input/public",
"+base",
# TODO(dpolukhin): move lock screen to component, see crbug.com/370175
"+chrome/browser/chromeos/login/lock",
]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/input/public/accelerator_manager.h"
#include "athena/input/public/input_manager.h"
#include "athena/screen_lock/screen_lock_manager_base.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
namespace athena {
namespace {
enum Command {
CMD_LOCK_SCREEN
};
const AcceleratorData accelerator_data[] = {
{ TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
CMD_LOCK_SCREEN, AF_NONE }};
class ChromeScreenLockManager : public ScreenLockManagerBase,
public AcceleratorHandler,
public PowerButtonObserver {
public:
ChromeScreenLockManager() {}
void Init();
protected:
virtual ~ChromeScreenLockManager();
private:
// ScreenLockManager:
virtual void LockScreen() override;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const override;
virtual bool OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) override;
// PowerButtonObserver:
virtual void OnPowerButtonStateChanged(State state) override;
DISALLOW_COPY_AND_ASSIGN(ChromeScreenLockManager);
};
ChromeScreenLockManager::~ChromeScreenLockManager() {
InputManager::Get()->RemovePowerButtonObserver(this);
}
void ChromeScreenLockManager::Init() {
AcceleratorManager::Get()->RegisterAccelerators(
accelerator_data, arraysize(accelerator_data), this);
InputManager::Get()->AddPowerButtonObserver(this);
}
void ChromeScreenLockManager::LockScreen() {
chromeos::ScreenLocker::HandleLockScreenRequest();
}
bool ChromeScreenLockManager::IsCommandEnabled(int command_id) const {
return true;
}
bool ChromeScreenLockManager::OnAcceleratorFired(
int command_id,
const ui::Accelerator& accelerator) {
switch (command_id) {
case CMD_LOCK_SCREEN:
LockScreen();
return true;
default:
NOTREACHED();
}
return false;
}
void ChromeScreenLockManager::OnPowerButtonStateChanged(State state) {
if (state == PRESSED)
LockScreen();
}
} // namespace
// static
ScreenLockManager* ScreenLockManager::Create() {
ChromeScreenLockManager* instance = new ChromeScreenLockManager();
instance->Init();
return instance;
}
} // namespace athena
include_rules = [
"-athena/screen_lock",
"+athena/athena_export.h",
]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_SCREEN_LOCK_PUBLIC_SCREEN_LOCK_MANAGER_H_
#define ATHENA_SCREEN_LOCK_PUBLIC_SCREEN_LOCK_MANAGER_H_
namespace athena {
// Manages screen lock and register keyboard shortcuts.
class ScreenLockManager {
public:
// Creates, returns and deletes the singleton object of the ScreenLockManager
// implementation.
static ScreenLockManager* Create();
static ScreenLockManager* Get();
static void Shutdown();
virtual void LockScreen() = 0;
protected:
// Make d-tor protected to prevent destruction without calling Shutdown.
virtual ~ScreenLockManager() {}
};
} // namespace athena
#endif // ATHENA_SCREEN_LOCK_PUBLIC_SCREEN_LOCK_MANAGER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/screen_lock/screen_lock_manager_base.h"
#include "base/logging.h"
namespace athena {
namespace {
ScreenLockManager* instance = NULL;
} // namespace
ScreenLockManagerBase::ScreenLockManagerBase() {
DCHECK(!instance);
instance = this;
}
ScreenLockManagerBase::~ScreenLockManagerBase() {
DCHECK_EQ(instance, this);
instance = NULL;
}
// static
ScreenLockManager* ScreenLockManager::Get() {
return instance;
}
// static
void ScreenLockManager::Shutdown() {
if (instance) {
delete instance;
DCHECK(!instance);
}
}
} // namespace athena
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_SCREEN_LOCK_SCREEN_LOCK_MANAGER_BASE_H_
#define ATHENA_SCREEN_LOCK_SCREEN_LOCK_MANAGER_BASE_H_
#include "athena/screen_lock/public/screen_lock_manager.h"
#include "base/macros.h"
namespace athena {
// Base class for ScreenLockManager implementations. Its c-tors remembers
// instance pointer in global static variable for ScreenLockManager::Get
// implementation and d-tor clears that global variable.
class ScreenLockManagerBase : public ScreenLockManager {
public:
ScreenLockManagerBase();
protected:
virtual ~ScreenLockManagerBase();
private:
DISALLOW_COPY_AND_ASSIGN(ScreenLockManagerBase);
};
} // namespace athena
#endif // ATHENA_SCREEN_LOCK_SCREEN_LOCK_MANAGER_BASE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/screen_lock/screen_lock_manager_base.h"
#include "base/macros.h"
namespace athena {
ScreenLockManager* ScreenLockManager::Create() {
return NULL;
}
} // namespace athena
\ No newline at end of file
include_rules = [
"+athena/resources",
"+athena/screen/public",
"+athena/screen_lock/public",
"+athena/strings/grit/athena_strings.h",
"+athena/system/public",
"+athena/input/public",
......
......@@ -364,7 +364,10 @@ void ScreenLocker::HandleLockScreenRequest() {
if (g_screen_lock_observer->session_started() &&
user_manager::UserManager::Get()->CanCurrentUserLock()) {
ScreenLocker::Show();
#if !defined(USE_ATHENA)
// TOOD(dpolukhin): crbug.com/413926.
ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock();
#endif
} else {
// If the current user's session cannot be locked or the user has not
// completed all sign-in steps yet, log out instead. The latter is done to
......@@ -378,11 +381,6 @@ void ScreenLocker::HandleLockScreenRequest() {
// static
void ScreenLocker::Show() {
#if defined(USE_ATHENA)
// crbug.com/413926
return;
#endif
content::RecordAction(UserMetricsAction("ScreenLocker_Show"));
DCHECK(base::MessageLoopForUI::IsCurrent());
......@@ -395,6 +393,7 @@ void ScreenLocker::Show() {
return;
}
#if !defined(USE_ATHENA)
// If the active window is fullscreen, exit fullscreen to avoid the web page
// or app mimicking the lock screen. Do not exit fullscreen if the shelf is
// visible while in fullscreen because the shelf makes it harder for a web
......@@ -406,6 +405,7 @@ void ScreenLocker::Show() {
const ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
active_window_state->OnWMEvent(&event);
}
#endif
if (!screen_locker_) {
ScreenLocker* locker =
......@@ -422,11 +422,6 @@ void ScreenLocker::Show() {
// static
void ScreenLocker::Hide() {
#if defined(USE_ATHENA)
// crbug.com/413926
return;
#endif
DCHECK(base::MessageLoopForUI::IsCurrent());
// For a guest/demo user, screen_locker_ would have never been initialized.
if (user_manager::UserManager::Get()->IsLoggedInAsGuest() ||
......@@ -438,8 +433,12 @@ void ScreenLocker::Hide() {
DCHECK(screen_locker_);
base::Callback<void(void)> callback =
base::Bind(&ScreenLocker::ScheduleDeletion);
#if !defined(USE_ATHENA)
ash::Shell::GetInstance()->lock_state_controller()->
OnLockScreenHide(callback);
#else
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
#endif
}
void ScreenLocker::ScheduleDeletion() {
......@@ -448,7 +447,9 @@ void ScreenLocker::ScheduleDeletion() {
return;
VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
#if !defined(USE_ATHENA)
ash::PlaySystemSoundIfSpokenFeedback(SOUND_UNLOCK);
#endif
delete screen_locker_;
screen_locker_ = NULL;
......@@ -465,9 +466,12 @@ ScreenLocker::~ScreenLocker() {
authenticator_->SetConsumer(NULL);
ClearErrors();
#if !defined(USE_ATHENA)
// TOOD(dpolukhin): we need to to something similar for Athena.
VLOG(1) << "Moving desktop background to unlocked container";
ash::Shell::GetInstance()->
desktop_background_controller()->MoveDesktopToUnlockedContainer();
#endif
screen_locker_ = NULL;
bool state = false;
......@@ -498,8 +502,10 @@ void ScreenLocker::ScreenLockReady() {
UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta);
VLOG(1) << "Moving desktop background to locked container";
#if !defined(USE_ATHENA)
ash::Shell::GetInstance()->
desktop_background_controller()->MoveDesktopToLockedContainer();
#endif
input_method::InputMethodManager::Get()
->GetActiveIMEState()
......
......@@ -67,15 +67,16 @@ WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker)
is_observing_keyboard_(false),
weak_factory_(this) {
set_should_emit_login_prompt_visible(false);
#if !defined(USE_ATHENA)
ash::Shell::GetInstance()->lock_state_controller()->AddObserver(this);
ash::Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this);
#endif
DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
if (keyboard::KeyboardController::GetInstance()) {
keyboard::KeyboardController::GetInstance()->AddObserver(this);
is_observing_keyboard_ = true;
}
ash::Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this);
}
void WebUIScreenLocker::LockScreen() {
......@@ -89,6 +90,7 @@ void WebUIScreenLocker::LockScreen() {
lock_window_->AddObserver(this);
WebUILoginView::Init();
lock_window_->SetContentsView(this);
lock_window_->SetBounds(bounds);
lock_window_->Show();
LoadURL(GURL(kLoginURL));
lock_window->Grab();
......@@ -156,8 +158,13 @@ void WebUIScreenLocker::FocusUserPod() {
WebUIScreenLocker::~WebUIScreenLocker() {
DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
#if !defined(USE_ATHENA)
ash::Shell::GetInstance()->
lock_state_controller()->RemoveObserver(this);
ash::Shell::GetInstance()->delegate()->
RemoveVirtualKeyboardStateObserver(this);
#endif
// In case of shutdown, lock_window_ may be deleted before WebUIScreenLocker.
if (lock_window_) {
lock_window_->RemoveObserver(this);
......@@ -175,9 +182,6 @@ WebUIScreenLocker::~WebUIScreenLocker() {
is_observing_keyboard_ = false;
}
ash::Shell::GetInstance()->delegate()->
RemoveVirtualKeyboardStateObserver(this);
if (login::LoginScrollIntoViewEnabled())
ResetKeyboardOverscrollOverride();
}
......
......@@ -11,6 +11,12 @@
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#if defined(USE_ATHENA)
#include "athena/screen/public/screen_manager.h"
#include "athena/util/container_priorities.h"
#include "athena/util/fill_layout_manager.h"
#endif
namespace chromeos {
LockWindow* LockWindow::Create() {
......@@ -58,11 +64,25 @@ void LockWindowAura::Init() {
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.delegate = this;
params.show_state = ui::SHOW_STATE_FULLSCREEN;
#if defined(USE_ATHENA)
// Don't set TRANSLUCENT_WINDOW because we don't have wallpaper manager yet.
// TODO(dpolukhin): fix this code when crbug.com/408734 fixed.
athena::ScreenManager::ContainerParams container_params(
"LoginScreen", athena::CP_LOGIN_SCREEN);
container_params.can_activate_children = true;
container_params.grab_inputs = true;
lock_screen_container_.reset(
athena::ScreenManager::Get()->CreateContainer(container_params));
params.parent = lock_screen_container_.get();
lock_screen_container_->SetLayoutManager(
new athena::FillLayoutManager(lock_screen_container_.get()));
#else
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
// TODO(oshima): move the lock screen harness to ash.
params.parent =
ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
ash::kShellWindowId_LockScreenContainer);
#endif
views::Widget::Init(params);
wm::SetWindowVisibilityAnimationTransition(
GetNativeView(), wm::ANIMATE_NONE);
......
......@@ -33,6 +33,10 @@ class LockWindowAura : public views::Widget,
// Initialize the Aura lock window.
void Init();
#if defined(USE_ATHENA)
scoped_ptr<aura::Window> lock_screen_container_;
#endif
DISALLOW_COPY_AND_ASSIGN(LockWindowAura);
};
......
......@@ -82,8 +82,10 @@ const char kNewWallpaperLayoutNodeName[] = "layout";
const char kNewWallpaperLocationNodeName[] = "file";
const char kNewWallpaperTypeNodeName[] = "type";
#if !defined(USE_ATHENA)
// Maximum number of wallpapers cached by CacheUsersWallpapers().
const int kMaxWallpapersToCache = 3;
#endif
// Maximum number of entries in WallpaperManager::last_load_times_ .
const size_t kLastLoadsStatsMsMaxSize = 4;
......@@ -1301,6 +1303,8 @@ bool WallpaperManager::GetWallpaperFromCache(const std::string& user_id,
}
void WallpaperManager::CacheUsersWallpapers() {
#if !defined(USE_ATHENA)
// TODO(dpolukhin): crbug.com/408734.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
user_manager::UserList users = user_manager::UserManager::Get()->GetUsers();
......@@ -1315,6 +1319,7 @@ void WallpaperManager::CacheUsersWallpapers() {
CacheUserWallpaper(user_id);
}
}
#endif
}
void WallpaperManager::CacheUserWallpaper(const std::string& user_id) {
......
......@@ -25,8 +25,6 @@ using core_api::system_display::Insets;
namespace {
// TODO(hshi): determine the DPI of the screen.
const float kDpi96 = 96.0;
// Maximum allowed bounds origin absolute value.
const int kMaxBoundsOrigin = 200 * 1000;
......@@ -360,6 +358,9 @@ bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform(
const gfx::Display& display,
extensions::core_api::system_display::DisplayUnitInfo* unit) {
#if !defined(USE_ATHENA)
// TODO(dpolukhin): put something reasonable to the unit without ash::Shell.
// crbug.com/416961
ash::DisplayManager* display_manager =
ash::Shell::GetInstance()->display_manager();
unit->name = display_manager->GetDisplayNameForId(display.id());
......@@ -368,6 +369,9 @@ void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform(
base::Int64ToString(display_manager->mirrored_display_id());
}
// TODO(hshi): determine the DPI of the screen.
const float kDpi96 = 96.0;
const float dpi = display.device_scale_factor() * kDpi96;
unit->dpi_x = dpi;
unit->dpi_y = dpi;
......@@ -378,6 +382,7 @@ void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform(
unit->overscan.top = overscan_insets.top();
unit->overscan.right = overscan_insets.right();
unit->overscan.bottom = overscan_insets.bottom();
#endif
}
gfx::Screen* DisplayInfoProviderChromeOS::GetActiveScreen() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment