[cros,de-hack] Get rid of singleton for the WebUILoginScreen.

After refactoring WebUILoginScreen is owned by ExistingUserController.
Also, all users of GetLoginWindow() switched
to use LoginDisplayHost::GetNativeWindow() instead.
Views code from BaseLoginDisplayHost was moved to ViewsLoginDisplayHost.

BUG=chromium-os:21054,chromium-os:20946
TEST=unit_tests,browser_tests


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108077 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f39afa8
......@@ -280,7 +280,7 @@ void TestingAutomationProvider::Login(DictionaryValue* args,
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWebUILogin)) {
// WebUI login.
chromeos::WebUILoginDisplay* webui_login_display =
chromeos::WebUILoginDisplay::GetInstance();
static_cast<chromeos::WebUILoginDisplay*>(controller->login_display());
webui_login_display->ShowSigninScreenForCreds(username, password);
} else {
// Native UI login.
......
......@@ -38,9 +38,6 @@
#include "ui/base/resource/resource_bundle.h"
#include "unicode/timezone.h"
// TODO(altimofeev): move to ViewsLoginDisplayHost
#include "chrome/browser/chromeos/login/views_oobe_display.h"
#if defined(TOOLKIT_USES_GTK)
#include "chrome/browser/chromeos/wm_ipc.h"
#endif
......@@ -132,16 +129,6 @@ void BaseLoginDisplayHost::OnSessionStart() {
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
WizardController* BaseLoginDisplayHost::CreateWizardController() {
// TODO(altimofeev): move this code to ViewsLoginDisplayHost when WebUI
// implementation will always be used with WebUILoginDisplayHost.
oobe_display_.reset(new ViewsOobeDisplay(background_bounds()));
WizardController* wizard_controller =
new WizardController(this, oobe_display_.get());
oobe_display_->SetScreenObserver(wizard_controller);
return wizard_controller;
}
void BaseLoginDisplayHost::StartWizard(
const std::string& first_screen_name,
const GURL& start_url) {
......@@ -151,13 +138,7 @@ void BaseLoginDisplayHost::StartWizard(
// new one, because "default_controller()" is updated there. So pure "reset()"
// is done before new controller creation.
wizard_controller_.reset();
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWebUILogin)) {
wizard_controller_.reset(CreateWizardController());
} else {
// Force views based implementation.
wizard_controller_.reset(BaseLoginDisplayHost::CreateWizardController());
}
wizard_controller_.reset(CreateWizardController());
wizard_controller_->set_start_url(start_url);
ShowBackground();
......@@ -167,8 +148,6 @@ void BaseLoginDisplayHost::StartWizard(
}
void BaseLoginDisplayHost::StartSignInScreen() {
oobe_display_.reset();
DVLOG(1) << "Starting sign in screen";
std::vector<chromeos::UserManager::User> users =
chromeos::UserManager::Get()->GetUsers();
......
......@@ -22,7 +22,6 @@ class Widget;
namespace chromeos {
class ExistingUserController;
class ViewsOobeDisplay;
class WizardController;
// An abstract base class that defines OOBE/login screen host.
......@@ -45,8 +44,8 @@ class BaseLoginDisplayHost : public LoginDisplayHost,
const GURL& start_url);
virtual void StartSignInScreen();
// Implementation specific WizardController creation method.
virtual WizardController* CreateWizardController();
// Creates specific WizardController.
virtual WizardController* CreateWizardController() = 0;
const gfx::Rect& background_bounds() const { return background_bounds_; }
......@@ -70,11 +69,6 @@ class BaseLoginDisplayHost : public LoginDisplayHost,
// OOBE and some screens (camera, recovery) controller.
scoped_ptr<WizardController> wizard_controller_;
// Keeps views based OobeDisplay implementation if any.
// TODO(altimofeev): move it to ViewsLoginDisplayHost. Also see comment in
// the CreateWizardController().
scoped_ptr<ViewsOobeDisplay> oobe_display_;
DISALLOW_COPY_AND_ASSIGN(BaseLoginDisplayHost);
};
......
......@@ -80,6 +80,7 @@ ExistingUserController* ExistingUserController::current_controller_ = NULL;
ExistingUserController::ExistingUserController(LoginDisplayHost* host)
: login_status_consumer_(NULL),
host_(host),
login_display_(host_->CreateLoginDisplay(this)),
num_login_attempts_(0),
user_settings_(new UserCrosSettingsProvider),
weak_factory_(this),
......@@ -87,8 +88,6 @@ ExistingUserController::ExistingUserController(LoginDisplayHost* host)
DCHECK(current_controller_ == NULL);
current_controller_ = this;
login_display_ = host_->CreateLoginDisplay(this);
registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
content::NotificationService::AllSources());
......@@ -144,9 +143,7 @@ ExistingUserController::~ExistingUserController() {
} else {
NOTREACHED() << "More than one controller are alive.";
}
DCHECK(login_display_ != NULL);
login_display_->Destroy();
login_display_ = NULL;
DCHECK(login_display_.get());
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -85,14 +85,13 @@ class ExistingUserController : public LoginDisplay::Delegate,
login_status_consumer_ = consumer;
}
// Returns the LoginDisplay instance created and owned by this controller.
// Returns the LoginDisplay created and owned by this controller.
// Used for testing.
LoginDisplay* login_display() {
return login_display_;
return login_display_.get();
}
// Returns the LoginDisplayHost for this controller.
// Used for testing.
LoginDisplayHost* login_display_host() {
return host_;
}
......@@ -154,9 +153,6 @@ class ExistingUserController : public LoginDisplay::Delegate,
// Used to execute login operations.
scoped_ptr<LoginPerformer> login_performer_;
// Login UI implementation instance.
LoginDisplay* login_display_;
// Delegate for login performer to be overridden by tests.
// |this| is used if |login_performer_delegate_| is NULL.
scoped_ptr<LoginPerformer::Delegate> login_performer_delegate_;
......@@ -171,6 +167,9 @@ class ExistingUserController : public LoginDisplay::Delegate,
// OOBE/login display host.
LoginDisplayHost* host_;
// Login UI implementation instance.
scoped_ptr<LoginDisplay> login_display_;
// Number of login attempts. Used to show help link when > 1 unsuccessful
// logins for the same user.
size_t num_login_attempts_;
......
......@@ -58,8 +58,7 @@ class MockLoginDisplayHost : public LoginDisplayHost {
MockLoginDisplayHost() {
}
MOCK_CONST_METHOD1(CreateLoginDisplay,
LoginDisplay*(LoginDisplay::Delegate*));
MOCK_METHOD1(CreateLoginDisplay, LoginDisplay*(LoginDisplay::Delegate*));
MOCK_CONST_METHOD0(GetNativeWindow, gfx::NativeWindow(void));
MOCK_METHOD0(OnSessionStart, void(void));
MOCK_METHOD1(SetOobeProgress, void(BackgroundView::LoginStep));
......
......@@ -17,8 +17,4 @@ LoginDisplay::LoginDisplay(Delegate* delegate,
LoginDisplay::~LoginDisplay() {}
void LoginDisplay::Destroy() {
delete this;
}
} // namespace chromeos
......@@ -69,10 +69,6 @@ class LoginDisplay : public RemoveUserDelegate {
LoginDisplay(Delegate* delegate, const gfx::Rect& background_bounds);
virtual ~LoginDisplay();
// Call for destroying a pointer of type LoginDisplay, since some subclasses
// are Singletons
virtual void Destroy();
// Initializes login UI with the user pods based on list of known users and
// guest, new user pods if those are enabled.
virtual void Init(const std::vector<UserManager::User>& users,
......
......@@ -24,8 +24,9 @@ class LoginDisplayHost {
virtual ~LoginDisplayHost() {}
// Creates UI implementation specific login display instance (views/WebUI).
// The caller takes ownership of the returned value.
virtual LoginDisplay* CreateLoginDisplay(
LoginDisplay::Delegate* delegate) const = 0;
LoginDisplay::Delegate* delegate) = 0;
// Returns corresponding native window.
// TODO(nkostylev): Might be refactored, move to views-specific code.
......
......@@ -137,8 +137,8 @@ class ScreenLockWebUI : public WebUILoginView {
explicit ScreenLockWebUI(ScreenLocker* screen_locker);
virtual ~ScreenLockWebUI();
// WebUILoginView overrides:
virtual void Init() OVERRIDE;
// Initializes ScreenLockWebUI.
void InitView();
// Clears and sets the focus to the password field.
void ClearAndSetFocusToPassword();
......@@ -157,10 +157,6 @@ class ScreenLockWebUI : public WebUILoginView {
virtual void HandleKeyboardEvent(
const NativeWebKeyboardEvent& event) OVERRIDE;
protected:
// WebUILoginView overrides:
virtual views::Widget* GetLoginWindow() OVERRIDE;
private:
friend class test::ScreenLockerTester;
......@@ -204,7 +200,7 @@ void ScreenLockerWebUI::Init(bool unlock_on_input) {
// GTK does not like zero width/height.
if (!unlock_on_input) {
screen_lock_webui_ = new ScreenLockWebUI(screen_locker_);
screen_lock_webui_->Init();
screen_lock_webui_->InitView();
screen_lock_webui_->SetEnabled(false);
} else {
input_event_observer_.reset(new InputEventObserver(screen_locker_));
......@@ -299,8 +295,9 @@ ScreenLockWebUI::ScreenLockWebUI(ScreenLocker* screen_locker)
ScreenLockWebUI::~ScreenLockWebUI() {
}
void ScreenLockWebUI::Init() {
WebUILoginView::Init();
void ScreenLockWebUI::InitView() {
DCHECK(screen_locker_webui_);
Init(screen_locker_webui_->lock_window_);
LoadURL(GURL(chrome::kChromeUILockScreenURL));
}
......@@ -345,9 +342,4 @@ void ScreenLockWebUI::HandleKeyboardEvent(
// screen WebUI is complete.
}
views::Widget* ScreenLockWebUI::GetLoginWindow() {
DCHECK(screen_locker_webui_);
return screen_locker_webui_->lock_window_;
}
} // namespace chromeos
......@@ -5,7 +5,10 @@
#include "chrome/browser/chromeos/login/views_login_display_host.h"
#include "chrome/browser/chromeos/login/views_login_display.h"
#include "chrome/browser/chromeos/login/views_oobe_display.h"
#include "chrome/browser/chromeos/login/wizard_accessibility_helper.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
namespace chromeos {
......@@ -25,7 +28,7 @@ ViewsLoginDisplayHost::~ViewsLoginDisplayHost() {
// LoginDisplayHost implementation -----------------------------------------
LoginDisplay* ViewsLoginDisplayHost::CreateLoginDisplay(
LoginDisplay::Delegate* delegate) const {
LoginDisplay::Delegate* delegate) {
chromeos::WizardAccessibilityHelper::GetInstance()->Init();
return new ViewsLoginDisplay(delegate, background_bounds());
}
......@@ -74,4 +77,17 @@ void ViewsLoginDisplayHost::ShowBackground() {
background_window_->Show();
}
void ViewsLoginDisplayHost::StartSignInScreen() {
oobe_display_.reset();
BaseLoginDisplayHost::StartSignInScreen();
}
WizardController* ViewsLoginDisplayHost::CreateWizardController() {
oobe_display_.reset(new ViewsOobeDisplay(background_bounds()));
WizardController* wizard_controller =
new WizardController(this, oobe_display_.get());
oobe_display_->SetScreenObserver(wizard_controller);
return wizard_controller;
}
} // namespace chromeos
......@@ -14,6 +14,8 @@
namespace chromeos {
class ViewsOobeDisplay;
// Views-specific implementation of the OOBE/login screen host.
// Uses ViewsLoginDisplay as the login screen UI implementation,
// BackgroundView as the background UI implementation.
......@@ -24,8 +26,7 @@ class ViewsLoginDisplayHost : public chromeos::BaseLoginDisplayHost {
virtual ~ViewsLoginDisplayHost();
// LoginDisplayHost implementation:
virtual LoginDisplay* CreateLoginDisplay(LoginDisplay::Delegate* delegate)
const;
virtual LoginDisplay* CreateLoginDisplay(LoginDisplay::Delegate* delegate);
virtual gfx::NativeWindow GetNativeWindow() const;
virtual void SetOobeProgress(BackgroundView::LoginStep step);
virtual void SetOobeProgressBarVisible(bool visible);
......@@ -33,12 +34,19 @@ class ViewsLoginDisplayHost : public chromeos::BaseLoginDisplayHost {
virtual void SetStatusAreaEnabled(bool enable);
virtual void SetStatusAreaVisible(bool visible);
virtual void ShowBackground();
virtual void StartSignInScreen();
// BaseLoginDisplayHost implementation:
virtual WizardController* CreateWizardController() OVERRIDE;
private:
// Background view/window.
BackgroundView* background_view_;
views::Widget* background_window_;
// Keeps views based OobeDisplay implementation.
scoped_ptr<ViewsOobeDisplay> oobe_display_;
DISALLOW_COPY_AND_ASSIGN(ViewsLoginDisplayHost);
};
......
......@@ -25,27 +25,13 @@ namespace chromeos {
WebUILoginDisplay::~WebUILoginDisplay() {
}
// WebUILoginDisplay, Singleton implementation: --------------------------------
// static
WebUILoginDisplay* WebUILoginDisplay::GetInstance() {
return Singleton<WebUILoginDisplay>::get();
}
// LoginDisplay implementation: ------------------------------------------------
// static
views::Widget* WebUILoginDisplay::GetLoginWindow() {
return WebUILoginDisplay::GetInstance()->LoginWindow();
}
views::Widget* WebUILoginDisplay::LoginWindow() {
return login_window_;
}
void WebUILoginDisplay::Destroy() {
background_bounds_ = gfx::Rect();
delegate_ = NULL;
WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate)
: LoginDisplay(delegate, gfx::Rect()),
show_guest_(false),
show_new_user_(false),
webui_handler_(NULL) {
}
void WebUILoginDisplay::Init(const std::vector<UserManager::User>& users,
......@@ -204,16 +190,17 @@ void WebUILoginDisplay::ShowSigninScreenForCreds(
webui_handler_->ShowSigninScreenForCreds(username, password);
}
// WebUILoginDisplay, private: -------------------------------------------------
// Singleton implementation: ---------------------------------------------------
const std::vector<UserManager::User>& WebUILoginDisplay::GetUsers() const {
return users_;
}
WebUILoginDisplay::WebUILoginDisplay()
: LoginDisplay(NULL, gfx::Rect()),
show_guest_(false),
show_new_user_(false),
login_window_(NULL),
webui_handler_(NULL) {
bool WebUILoginDisplay::IsShowGuest() const {
return show_guest_;
}
bool WebUILoginDisplay::IsShowNewUser() const {
return show_new_user_;
}
} // namespace chromeos
......@@ -10,7 +10,6 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "chrome/browser/chromeos/login/login_display.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
......@@ -22,39 +21,13 @@ class Rect;
namespace chromeos {
// WebUI-based login UI implementation.
// This class is a Singleton. It allows the LoginDisplayHost and LoginUIHandler
// to access it without having to be coupled with each other. It is created with
// NULL for the delegate and a 0-size rectangle for the background
// bounds. Before use these values should be set to a sane value. When done with
// the object, the ExistingUserController should call Destroy and not free the
// pointer, where as accessing classes should do nothing with the pointer.
//
// Expected order of commands to setup for LoginDisplayHost:
// WebUILoginDisplay::GetInstance();
// set_delegate(delegate);
// set_background_bounds(background_bounds());
// Init();
//
// Expected order of commands to setup for LoginUIHandler:
// WebUILoginDisplay::GetInstance();
// set_login_handler(this);
class WebUILoginDisplay : public LoginDisplay,
public SigninScreenHandlerDelegate {
public:
explicit WebUILoginDisplay(LoginDisplay::Delegate* delegate);
virtual ~WebUILoginDisplay();
// Singleton implementation:
static WebUILoginDisplay* GetInstance();
// Wrapper used to help in routing keyboard key presses into the login
// screen. This gets the Login Window widget from the Singleton, so that other
// classes don't need to know we are a Singleton
static views::Widget* GetLoginWindow();
views::Widget* LoginWindow();
// LoginDisplay implementation:
virtual void Destroy() OVERRIDE;
virtual void Init(const std::vector<UserManager::User>& users,
bool show_guest,
bool show_new_user) OVERRIDE;
......@@ -83,28 +56,11 @@ class WebUILoginDisplay : public LoginDisplay,
LoginDisplayWebUIHandler* webui_handler) OVERRIDE;
virtual void ShowSigninScreenForCreds(const std::string& username,
const std::string& password);
void set_login_window(views::Widget* login_window) {
login_window_ = login_window;
}
const std::vector<UserManager::User>& users() const {
return users_;
}
bool show_guest() const {
return show_guest_;
}
bool show_new_user() const {
return show_new_user_;
}
virtual const std::vector<UserManager::User>& GetUsers() const OVERRIDE;
virtual bool IsShowGuest() const OVERRIDE;
virtual bool IsShowNewUser() const OVERRIDE;
private:
// Singleton implementation:
friend struct DefaultSingletonTraits<WebUILoginDisplay>;
WebUILoginDisplay();
// Set of Users that are visible.
std::vector<UserManager::User> users_;
......@@ -114,9 +70,6 @@ class WebUILoginDisplay : public LoginDisplay,
// Whether to show add new user.
bool show_new_user_;
// Container of the screen we are displaying
views::Widget* login_window_;
// Reference to the WebUI handling layer for the login screen
LoginDisplayWebUIHandler* webui_handler_;
......
......@@ -34,7 +34,8 @@ const char kOobeURL[] = "chrome://oobe";
WebUILoginDisplayHost::WebUILoginDisplayHost(const gfx::Rect& background_bounds)
: BaseLoginDisplayHost(background_bounds),
login_window_(NULL),
login_view_(NULL) {
login_view_(NULL),
webui_login_display_(NULL) {
}
WebUILoginDisplayHost::~WebUILoginDisplayHost() {
......@@ -45,11 +46,10 @@ WebUILoginDisplayHost::~WebUILoginDisplayHost() {
// LoginDisplayHost implementation ---------------------------------------------
LoginDisplay* WebUILoginDisplayHost::CreateLoginDisplay(
LoginDisplay::Delegate* delegate) const {
WebUILoginDisplay* webui_login_display = WebUILoginDisplay::GetInstance();
webui_login_display->set_delegate(delegate);
webui_login_display->set_background_bounds(background_bounds());
return webui_login_display;
LoginDisplay::Delegate* delegate) {
webui_login_display_ = new WebUILoginDisplay(delegate);
webui_login_display_->set_background_bounds(background_bounds());
return webui_login_display_;
}
gfx::NativeWindow WebUILoginDisplayHost::GetNativeWindow() const {
......@@ -113,7 +113,7 @@ void WebUILoginDisplayHost::StartSignInScreen() {
LoadURL(GURL(kLoginURL));
BaseLoginDisplayHost::StartSignInScreen();
GetOobeUI()->ShowSigninScreen();
GetOobeUI()->ShowSigninScreen(webui_login_display_);
}
void WebUILoginDisplayHost::LoadURL(const GURL& url) {
......@@ -126,7 +126,7 @@ void WebUILoginDisplayHost::LoadURL(const GURL& url) {
login_window_->Init(params);
login_view_ = new WebUILoginView();
login_view_->Init();
login_view_->Init(login_window_);
#if defined(USE_AURA)
aura_shell::Shell::GetInstance()->GetContainer(
......@@ -141,7 +141,6 @@ void WebUILoginDisplayHost::LoadURL(const GURL& url) {
#if defined(USE_AURA)
login_window_->GetNativeView()->set_name("WebUILoginView");
#endif
WebUILoginDisplay::GetInstance()->set_login_window(login_window_);
login_view_->OnWindowCreated();
}
login_view_->LoadURL(url);
......
......@@ -17,6 +17,7 @@ class Rect;
namespace chromeos {
class OobeUI;
class WebUILoginDisplay;
class WebUILoginView;
// WebUI-specific implementation of the OOBE/login screen host. Uses
......@@ -27,8 +28,8 @@ class WebUILoginDisplayHost : public BaseLoginDisplayHost {
virtual ~WebUILoginDisplayHost();
// LoginDisplayHost implementation:
virtual LoginDisplay* CreateLoginDisplay(LoginDisplay::Delegate* delegate)
const OVERRIDE;
virtual LoginDisplay* CreateLoginDisplay(
LoginDisplay::Delegate* delegate) OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
virtual void SetOobeProgress(BackgroundView::LoginStep step) OVERRIDE;
virtual void SetOobeProgressBarVisible(bool visible) OVERRIDE;
......@@ -55,6 +56,9 @@ class WebUILoginDisplayHost : public BaseLoginDisplayHost {
// Container of the view we are displaying.
WebUILoginView* login_view_;
// Login display we are using.
WebUILoginDisplay* webui_login_display_;
DISALLOW_COPY_AND_ASSIGN(WebUILoginDisplayHost);
};
......
......@@ -113,6 +113,7 @@ const int WebUILoginView::kStatusAreaCornerPadding = 5;
WebUILoginView::WebUILoginView()
: status_area_(NULL),
webui_login_(NULL),
login_window_(NULL),
status_window_(NULL),
host_window_frozen_(false),
status_area_visibility_on_init_(true) {
......@@ -137,8 +138,8 @@ WebUILoginView::~WebUILoginView() {
status_window_ = NULL;
}
void WebUILoginView::Init() {
void WebUILoginView::Init(views::Widget* login_window) {
login_window_ = login_window;
webui_login_ = new DOMView();
AddChildView(webui_login_);
webui_login_->Init(ProfileManager::GetDefaultProfile(), NULL);
......@@ -337,7 +338,6 @@ void WebUILoginView::InitStatusArea() {
status_area_->Init();
status_area_->SetVisible(status_area_visibility_on_init_);
views::Widget* login_window = GetLoginWindow();
// Width of |status_window| is meant to be large enough.
// The current value of status_area_->GetPreferredSize().width()
// will be too small when button status is changed.
......@@ -361,7 +361,7 @@ void WebUILoginView::InitStatusArea() {
#endif
widget_params.bounds = widget_bounds;
widget_params.transparent = true;
widget_params.parent_widget = login_window;
widget_params.parent_widget = login_window_;
status_window_ = new views::Widget;
status_window_->Init(widget_params);
......@@ -422,8 +422,4 @@ void WebUILoginView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
web_ui->CallJavascriptFunction("cr.ui.Oobe.clearErrors");
}
views::Widget* WebUILoginView::GetLoginWindow() {
return WebUILoginDisplay::GetLoginWindow();
}
} // namespace chromeos
......@@ -43,7 +43,7 @@ class WebUILoginView : public views::WidgetDelegateView,
virtual ~WebUILoginView();
// Initializes the webui login view.
virtual void Init();
virtual void Init(views::Widget* login_window);
// Overridden from views::Views:
virtual bool AcceleratorPressed(
......@@ -99,9 +99,6 @@ class WebUILoginView : public views::WidgetDelegateView,
// Creates and adds the status area (separate window).
virtual void InitStatusArea();
// Get the views widget hosting this WebUILoginView.
virtual views::Widget* GetLoginWindow();
StatusAreaView* status_area_;
// DOMView for rendering a webpage as a webui login.
......@@ -122,6 +119,9 @@ class WebUILoginView : public views::WidgetDelegateView,
// |reverse| is true when focus is traversed backwards (using Shift-Tab).
void ReturnFocus(bool reverse);
// Login window which shows the view.
views::Widget* login_window_;
// Window that contains status area.
// TODO(nkostylev): Temporary solution till we have
// RenderWidgetHostViewViews working.
......
......@@ -7,7 +7,9 @@
#include <algorithm>
#include "chrome/browser/chromeos/login/background_view.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/login_display_host.h"
#include "chrome/browser/chromeos/login/webui_login_display.h"
#include "chrome/browser/chromeos/setting_level_bubble_view.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -74,15 +76,25 @@ static views::Widget* GetToplevelWidget() {
#else
// Otherwise, see if there's a background window that we can use.
BackgroundView* background = LoginUtils::Get()->GetBackgroundView();
if (background)
if (background) {
window = GTK_WINDOW(background->GetNativeWindow());
} else {
ExistingUserController* controller =
ExistingUserController::current_controller();
if (controller) {
window =
GTK_WINDOW(controller->login_display_host()->GetNativeWindow());
}
}
#endif
}
if (window)
if (window) {
return views::Widget::GetWidgetForNativeWindow(window);
else
return WebUILoginDisplay::GetLoginWindow();
} else {
NOTREACHED();
return NULL;
}
}
// SettingLevelBubbleDelegateView ----------------------------------------------
......
......@@ -2,6 +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/base_login_display_host.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
#include "base/values.h"
......@@ -30,4 +31,9 @@ void BaseScreenHandler::ShowScreen(const char* screen_name,
web_ui_->CallJavascriptFunction("cr.ui.Oobe.showScreen", screen_params);
}
gfx::NativeWindow BaseScreenHandler::GetNativeWindow() {
return BaseLoginDisplayHost::default_host()->GetNativeWindow();
}
} // namespace chromeos
......@@ -7,6 +7,7 @@
#pragma once
#include "content/browser/webui/web_ui.h"
#include "ui/gfx/native_widget_types.h"
namespace base {
class DictionaryValue;
......@@ -39,6 +40,9 @@ class BaseScreenHandler : public WebUIMessageHandler {
// Whether page is ready.
bool page_is_ready() const { return page_is_ready_; }
// Returns the window which shows us.
gfx::NativeWindow GetNativeWindow();
private:
// Keeps whether page is ready.
bool page_is_ready_;
......
......@@ -136,8 +136,7 @@ void EulaScreenHandler::HandleOnExit(const base::ListValue* args) {
void EulaScreenHandler::HandleOnLearnMore(const base::ListValue* args) {
if (!help_app_.get()) {
views::Widget* login_window = WebUILoginDisplay::GetLoginWindow();
help_app_ = new HelpAppLauncher(login_window->GetNativeWindow());
help_app_ = new HelpAppLauncher(GetNativeWindow());
}
help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE);
}
......
......@@ -71,8 +71,7 @@ void NetworkDropdownHandler::HandleNetworkDropdownShow(
if (!args->GetString(0, &element_id))
NOTREACHED();
dropdown_.reset(new NetworkDropdown(
web_ui_, WebUILoginDisplay::GetLoginWindow()->GetNativeWindow()));
dropdown_.reset(new NetworkDropdown(web_ui_, GetNativeWindow()));
}
void NetworkDropdownHandler::HandleNetworkDropdownHide(
......
......@@ -236,7 +236,8 @@ void OobeUI::ShowOobeUI(bool show) {
core_handler_->ShowOobeUI(show);
}
void OobeUI::ShowSigninScreen() {
void OobeUI::ShowSigninScreen(SigninScreenHandlerDelegate* delegate) {
signin_screen_handler_->SetDelegate(delegate);
signin_screen_handler_->Show(core_handler_->show_oobe_ui());
}
......
......@@ -17,6 +17,7 @@ namespace chromeos {
class BaseScreenHandler;
class CoreOobeHandler;
class SigninScreenHandler;
class SigninScreenHandlerDelegate;
}
namespace chromeos {
......@@ -52,7 +53,7 @@ class OobeUI : public OobeDisplay,
void ShowOobeUI(bool show);
// Shows the signin screen.
void ShowSigninScreen();
void ShowSigninScreen(SigninScreenHandlerDelegate* delegate);
// Called when the login main frame has been rendered.
void OnLoginPromptVisible();
......
......@@ -215,7 +215,7 @@ void NetworkStateInformer::SendStateToObservers(const std::string& reason) {
// SigninScreenHandler implementation ------------------------------------------
SigninScreenHandler::SigninScreenHandler()
: delegate_(WebUILoginDisplay::GetInstance()),
: delegate_(NULL),
show_on_init_(false),
oobe_ui_(false),
dns_cleared_(false),
......@@ -227,7 +227,6 @@ SigninScreenHandler::SigninScreenHandler()
cookie_remover_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
key_event_listener_(NULL) {
delegate_->SetWebUIHandler(this);
}
SigninScreenHandler::~SigninScreenHandler() {
......@@ -310,6 +309,12 @@ void SigninScreenHandler::Show(bool oobe_ui) {
}
}
void SigninScreenHandler::SetDelegate(SigninScreenHandlerDelegate* delegate) {
delegate_ = delegate;
DCHECK(delegate_);
delegate_->SetWebUIHandler(this);
}
// SigninScreenHandler, private: -----------------------------------------------
void SigninScreenHandler::Initialize() {
......@@ -548,20 +553,19 @@ void SigninScreenHandler::HandleLaunchHelpApp(const base::ListValue* args) {
}
if (!help_app_.get())
help_app_ = new HelpAppLauncher(
WebUILoginDisplay::GetLoginWindow()->GetNativeWindow());
help_app_ = new HelpAppLauncher(GetNativeWindow());
help_app_->ShowHelpTopic(
static_cast<HelpAppLauncher::HelpTopic>(help_topic_id));
}
void SigninScreenHandler::SendUserList(bool animated) {
bool show_guest = WebUILoginDisplay::GetInstance()->show_guest();
bool show_guest = delegate_->IsShowGuest();
size_t max_non_owner_users = show_guest ? kMaxUsers - 2 : kMaxUsers - 1;
size_t non_owner_count = 0;
ListValue users_list;
UserVector users = WebUILoginDisplay::GetInstance()->users();
UserVector users = delegate_->GetUsers();
bool single_user = users.size() == 1;
for (UserVector::const_iterator it = users.begin();
......
......@@ -13,6 +13,7 @@
#include "base/task.h"
#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/chromeos/login/help_app_launcher.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/system_key_event_listener.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
#include "content/browser/webui/web_ui.h"
......@@ -76,6 +77,15 @@ class SigninScreenHandlerDelegate {
// Let the delegate know about the handler it is supposed to be using.
virtual void SetWebUIHandler(LoginDisplayWebUIHandler* webui_handler) = 0;
// Returns users list to be shown.
virtual const std::vector<UserManager::User>& GetUsers() const = 0;
// Whether login as guest is available.
virtual bool IsShowGuest() const = 0;
// Whether new user pod is available.
virtual bool IsShowNewUser() const = 0;
protected:
virtual ~SigninScreenHandlerDelegate() {}
};
......@@ -94,6 +104,10 @@ class SigninScreenHandler : public BaseScreenHandler,
// screen is for OOBE or usual sign-in flow.
void Show(bool oobe_ui);
// Sets delegate to be used by the handler. It is guaranteed that valid
// delegate is set before Show() method will be called.
void SetDelegate(SigninScreenHandlerDelegate* delegate);
private:
friend class ReportDnsCacheClearedOnUIThread;
......
......@@ -162,9 +162,8 @@ void UserImageScreenHandler::OnPhotoAccepted(const SkBitmap& photo) {
void UserImageScreenHandler::HandleTakePhoto(const base::ListValue* args) {
DCHECK(args && args->empty());
TakePhotoDialog* take_photo_dialog = new TakePhotoDialog(this);
views::Widget* login_window = WebUILoginDisplay::GetLoginWindow();
views::Widget* window = browser::CreateViewsWindow(
login_window->GetNativeWindow(),
GetNativeWindow(),
take_photo_dialog);
window->SetAlwaysOnTop(true);
window->Show();
......
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