Commit 59de2f5c authored by flackr@chromium.org's avatar flackr@chromium.org

Enable WebUI ScreenLocker for aura by abstracting lock window.

This CL abstracts the actual lock window allowing for a GTK implementation and an aura implementation. The aura screenlocker stubs are removed and the screenlocker is enabled on aura using the aura lock window.

BUG=100723
TEST=Build chrome with use_aura=1, trigger screen lock and test unlocking screen.


Review URL: http://codereview.chromium.org/8711003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112709 0039d316-1c4b-4281-b951-d872f2087c98
parent 919bd435
......@@ -2,12 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/notifications/system_notification.h"
#include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
#include "chrome/browser/notifications/balloon_collection.h"
namespace chromeos {
......@@ -79,87 +74,4 @@ std::string SystemNotification::Delegate::id() const {
return id_;
}
//////////////////////////////////////////////////////////////////////////////
// ScreenLocker
ScreenLocker::ScreenLocker(const chromeos::User& user) : user_(user) {
NOTIMPLEMENTED();
}
ScreenLocker::~ScreenLocker() {
NOTIMPLEMENTED();
}
void ScreenLocker::Init() {
NOTIMPLEMENTED();
}
void ScreenLocker::OnLoginFailure(const LoginFailure& error) {
NOTIMPLEMENTED();
}
void ScreenLocker::OnLoginSuccess(
const std::string&,
const std::string&,
const GaiaAuthConsumer::ClientLoginResult&,
bool,
bool) {
NOTIMPLEMENTED();
}
void ScreenLocker::Authenticate(const string16& password) {
NOTIMPLEMENTED();
}
void ScreenLocker::ClearErrors() {
NOTIMPLEMENTED();
}
void ScreenLocker::EnableInput() {
NOTIMPLEMENTED();
}
void ScreenLocker::Signout() {
NOTIMPLEMENTED();
}
void ScreenLocker::ShowCaptchaAndErrorMessage(const GURL& captcha_url,
const string16& message) {
NOTIMPLEMENTED();
}
void ScreenLocker::ShowErrorMessage(const string16& message,
bool sign_out_only) {
NOTIMPLEMENTED();
}
void ScreenLocker::SetLoginStatusConsumer(
chromeos::LoginStatusConsumer* consumer) {
NOTIMPLEMENTED();
}
// static
void ScreenLocker::Show() {
NOTIMPLEMENTED();
}
// static
void ScreenLocker::Hide() {
NOTIMPLEMENTED();
}
// static
void ScreenLocker::UnlockScreenFailed() {
NOTIMPLEMENTED();
}
// static
void ScreenLocker::InitClass() {
NOTIMPLEMENTED();
}
void ScreenLocker::ScreenLockReady() {
NOTIMPLEMENTED();
}
} // namespace chromeos
// Copyright (c) 2011 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 "chrome/browser/chromeos/login/lock_window.h"
#include <cstddef>
namespace chromeos {
LockWindow::LockWindow() : observer_(NULL) {
}
} // namespace chromeos
// Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_H_
#pragma once
#include "base/basictypes.h"
class DOMView;
namespace views {
class Widget;
}
namespace chromeos {
// This is the interface which lock windows used for the WebUI screen locker
// implement.
class LockWindow {
public:
// This class provides an interface for the lock window to notify an observer
// about its status.
class Observer {
public:
// This method will be called when the lock window has finished all
// initialization.
virtual void OnLockWindowReady() = 0;
};
LockWindow();
// Attempt to grab inputs on |dom_view|, the actual view displaying the lock
// screen DOM.
virtual void Grab(DOMView* dom_view) = 0;
// Returns the actual widget for the lock window.
virtual views::Widget* GetWidget() = 0;
// Sets the observer class which is notified on lock window events.
void set_observer(Observer* observer) {
observer_ = observer;
}
// Creates an instance of the platform specific lock window.
static LockWindow* Create();
protected:
// The observer's OnLockWindowReady method will be called when the lock
// window has finished all initialization.
Observer* observer_;
DISALLOW_COPY_AND_ASSIGN(LockWindow);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_H_
// Copyright (c) 2011 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 "chrome/browser/chromeos/login/lock_window_aura.h"
#include "ui/aura/desktop.h"
#include "ui/aura/window.h"
#include "ui/aura_shell/shell.h"
#include "ui/aura_shell/shell_window_ids.h"
namespace chromeos {
LockWindow* LockWindow::Create() {
return new LockWindowAura();
}
////////////////////////////////////////////////////////////////////////////////
// LockWindow implementation:
void LockWindowAura::Grab(DOMView* dom_view) {
// We already have grab from the lock screen container, just call the ready
// callback immediately.
if (observer_)
observer_->OnLockWindowReady();
}
views::Widget* LockWindowAura::GetWidget() {
return this;
}
////////////////////////////////////////////////////////////////////////////////
// LockWindowAura private:
LockWindowAura::LockWindowAura() {
Init();
}
LockWindowAura::~LockWindowAura() {
}
void LockWindowAura::Init() {
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.bounds = gfx::Rect(aura::Desktop::GetInstance()->GetHostSize());
// TODO(flackr): Use a property to specify this container rather than
// depending on shell implementation.
params.parent = aura_shell::Shell::GetInstance()->GetContainer(
aura_shell::internal::kShellWindowId_LockScreenContainer);
views::Widget::Init(params);
}
} // namespace chromeos
// Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_AURA_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_AURA_H_
#pragma once
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/login/lock_window.h"
#include "ui/views/widget/widget.h"
namespace chromeos {
class LockWindowAura : public views::Widget,
public LockWindow {
public:
// LockWindow implementation:
virtual void Grab(DOMView* dom_view) OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
private:
friend class LockWindow;
LockWindowAura();
virtual ~LockWindowAura();
// Initialize the Aura lock window.
void Init();
DISALLOW_COPY_AND_ASSIGN(LockWindowAura);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_AURA_H_
This diff is collapsed.
// Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_GTK_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_GTK_H_
#pragma once
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/lock_window.h"
#include "chrome/browser/chromeos/login/screen_locker_delegate.h"
#include "ui/views/widget/native_widget_gtk.h"
namespace chromeos {
// A ScreenLock window that covers entire screen to keep the keyboard
// focus/events inside the grab widget.
class LockWindowGtk : public views::NativeWidgetGtk,
public LockWindow {
public:
// LockWindow implementation:
virtual void Grab(DOMView* dom_view) OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
protected:
// NativeWidgetGtk overrides:
virtual gboolean OnButtonPress(GtkWidget* widget,
GdkEventButton* event) OVERRIDE;
virtual void OnDestroy(GtkWidget* object) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void HandleGtkGrabBroke() OVERRIDE;
private:
friend class LockWindow;
LockWindowGtk();
virtual ~LockWindowGtk();
// Initialize the lock window.
void Init();
// Called when the window manager is ready to handle locked state.
void OnWindowManagerReady();
// Called when the all inputs are grabbed.
void OnGrabInputs();
// Clear current GTK grab.
void ClearGtkGrab();
// Try to grab all inputs. It initiates another try if it fails to
// grab and the retry count is within a limit, or fails with CHECK.
void TryGrabAllInputs();
// This method tries to steal pointer/keyboard grab from other
// client by sending events that will hopefully close menus or windows
// that have the grab.
void TryUngrabOtherClients();
// Event handler for client-event.
CHROMEGTK_CALLBACK_1(LockWindowGtk, void, OnClientEvent, GdkEventClient*)
// The screen locker window.
views::Widget* lock_window_;
// The widget to grab inputs on. This is initialized by Grab to be the
// RenderHostView displaying the WebUI.
GtkWidget* grab_widget_;
// True if the screen locker's window has been drawn.
bool drawn_;
// True if both mouse input and keyboard input are grabbed.
bool input_grabbed_;
base::WeakPtrFactory<LockWindowGtk> weak_factory_;
// The number times the widget tried to grab all focus.
int grab_failure_count_;
// Status of keyboard and mouse grab.
GdkGrabStatus kbd_grab_status_;
GdkGrabStatus mouse_grab_status_;
DISALLOW_COPY_AND_ASSIGN(LockWindowGtk);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WINDOW_GTK_H_
......@@ -27,7 +27,6 @@
#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/login_performer.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/screen_locker_views.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/webui_screen_locker.h"
#include "chrome/browser/profiles/profile.h"
......@@ -50,6 +49,10 @@
#include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h"
#endif
#if !defined(USE_AURA)
#include "chrome/browser/chromeos/login/screen_locker_views.h"
#endif
using content::BrowserThread;
namespace {
......@@ -201,10 +204,14 @@ ScreenLocker::ScreenLocker(const User& user)
void ScreenLocker::Init() {
authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
#if defined(USE_AURA)
delegate_.reset(new WebUIScreenLocker(this));
#else
if (UseWebUILockScreen())
delegate_.reset(new WebUIScreenLocker(this));
else
delegate_.reset(new ScreenLockerViews(this));
#endif
delegate_->LockScreen(unlock_on_input_);
}
......@@ -392,11 +399,13 @@ void ScreenLocker::UnlockScreenFailed() {
}
}
#if !defined(USE_AURA)
// static
bool ScreenLocker::UseWebUILockScreen() {
return !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableWebUILockScreen);
}
#endif
// static
void ScreenLocker::InitClass() {
......
......@@ -34,12 +34,7 @@ class ScreenLocker : public LoginStatusConsumer {
// Returns the default instance if it has been created.
static ScreenLocker* default_screen_locker() {
#if defined(TOOLKIT_USES_GTK)
return screen_locker_;
#else
NOTIMPLEMENTED();
return NULL;
#endif
}
// Initialize and show the screen locker.
......@@ -125,10 +120,8 @@ class ScreenLocker : public LoginStatusConsumer {
// Logged in user.
const User& user_;
#if defined(TOOLKIT_USES_GTK)
// Used to authenticate the user to unlock.
scoped_refptr<Authenticator> authenticator_;
#endif
// Unlock the screen when it detects key/mouse event without asking
// password. True when chrome is in BWSI or auto login mode.
......
......@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/lock_window.h"
#include "chrome/browser/chromeos/login/login_display.h"
#include "chrome/browser/chromeos/login/screen_locker_delegate.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
......@@ -17,10 +18,6 @@
#include "content/public/browser/notification_registrar.h"
#include "ui/views/widget/widget.h"
#if defined(TOOLKIT_USES_GTK)
#include "ui/views/widget/native_widget_gtk.h"
#endif
namespace chromeos {
class ScreenLocker;
......@@ -31,13 +28,11 @@ class WebUILoginDisplay;
class WebUIScreenLocker : public WebUILoginView,
public LoginDisplay::Delegate,
public content::NotificationObserver,
public ScreenLockerDelegate {
public ScreenLockerDelegate,
public LockWindow::Observer {
public:
explicit WebUIScreenLocker(ScreenLocker* screen_locker);
// Called when the GTK grab breaks.
void HandleGtkGrabBroke();
// ScreenLockerDelegate implementation:
virtual void LockScreen(bool unlock_on_input) OVERRIDE;
virtual void ScreenLockReady() OVERRIDE;
......@@ -67,29 +62,14 @@ class WebUIScreenLocker : public WebUILoginView,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
virtual ~WebUIScreenLocker();
// Called when the window manager is ready to handle locked state.
void OnWindowManagerReady();
// Called when the all inputs are grabbed.
void OnGrabInputs();
// Clear current GTK grab.
void ClearGtkGrab();
// LockWindow::Observer implementation.
virtual void OnLockWindowReady() OVERRIDE;
// Try to grab all inputs. It initiates another try if it fails to
// grab and the retry count is within a limit, or fails with CHECK.
void TryGrabAllInputs();
// Overridden from WebUILoginView.
virtual void OnTabMainFrameFirstRender() OVERRIDE;
// This method tries to steal pointer/keyboard grab from other
// client by sending events that will hopefully close menus or windows
// that have the grab.
void TryUngrabOtherClients();
// Event handler for client-event.
CHROMEGTK_CALLBACK_1(WebUIScreenLocker, void, OnClientEvent, GdkEventClient*)
private:
virtual ~WebUIScreenLocker();
// The screen locker window.
views::Widget* lock_window_;
......@@ -100,20 +80,11 @@ class WebUIScreenLocker : public WebUILoginView,
// Used for user image changed notifications.
content::NotificationRegistrar registrar_;
// True if the screen locker's window has been drawn.
bool drawn_;
// True if both mouse input and keyboard input are grabbed.
bool input_grabbed_;
base::WeakPtrFactory<WebUIScreenLocker> weak_factory_;
// The number times the widget tried to grab all focus.
int grab_failure_count_;
// Tracks when the lock window is displayed and ready.
bool lock_ready_;
// Status of keyboard and mouse grab.
GdkGrabStatus kbd_grab_status_;
GdkGrabStatus mouse_grab_status_;
// Tracks when the WebUI finishes loading.
bool webui_ready_;
DISALLOW_COPY_AND_ASSIGN(WebUIScreenLocker);
};
......
......@@ -582,6 +582,12 @@
'browser/chromeos/login/language_switch_menu.h',
'browser/chromeos/login/session_manager_observer.cc',
'browser/chromeos/login/session_manager_observer.h',
'browser/chromeos/login/lock_window.cc',
'browser/chromeos/login/lock_window.h',
'browser/chromeos/login/lock_window_aura.cc',
'browser/chromeos/login/lock_window_aura.h',
'browser/chromeos/login/lock_window_gtk.cc',
'browser/chromeos/login/lock_window_gtk.h',
'browser/chromeos/login/login_display.cc',
'browser/chromeos/login/login_display.h',
'browser/chromeos/login/login_display_host.h',
......@@ -5114,21 +5120,18 @@
# Build Aura with ChromeOS.
['use_aura==1 and chromeos==1', {
'sources/': [
['exclude', '^browser/chromeos/browser/chromeos/login/screen_locker.cc'],
['exclude', '^browser/chromeos/frame/'],
['exclude', '^browser/chromeos/legacy_window_manager/wm_ipc.cc'],
['exclude', '^browser/chromeos/legacy_window_manager/wm_message_listener.cc'],
['exclude', '^browser/chromeos/login/background_view.cc'],
['exclude', '^browser/chromeos/login/screen_locker_browsertest.cc'],
['exclude', '^browser/chromeos/login/screen_locker_views.cc'],
['exclude', '^browser/chromeos/login/screen_locker.cc'],
['exclude', '^browser/chromeos/login/screen_lock_view.cc'],
['exclude', '^browser/chromeos/login/shutdown_button.cc'],
['exclude', '^browser/chromeos/login/username_view.cc'],
['exclude', '^browser/chromeos/login/user_view.cc'],
['exclude', '^browser/chromeos/login/views_login_display.cc'],
['exclude', '^browser/chromeos/login/views_login_display_host.cc'],
['exclude', '^browser/chromeos/login/webui_screen_locker.cc'],
['exclude', '^browser/chromeos/login/wizard_in_process_browser_test.cc'],
['exclude', '^browser/chromeos/notifications/'],
['include', '^browser/ui/views/handle_web_keyboard_event_aura.cc'],
......
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