blob: 664305ed81c6849ae95e693e991fb84fd261799b [file] [log] [blame]
// Copyright 2017 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 <vector>
#include "ash/ash_export.h"
#include "ash/public/cpp/login_types.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/tray_action/tray_action.h"
#include "ash/tray_action/tray_action_observer.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "ui/base/clipboard/clipboard.h"
namespace views {
class View;
class Widget;
namespace ash {
class LockContentsView;
class ASH_EXPORT LockScreen : public TrayActionObserver,
public SessionObserver {
// TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi {
explicit TestApi(LockScreen* lock_screen);
LockContentsView* contents_view() const;
void AddOnShownCallback(base::OnceClosure on_shown);
LockScreen* const lock_screen_;
// The UI that this instance is displaying.
enum class ScreenType { kLogin, kLock };
// Fetch the global lock screen instance. |Show()| must have been called
// before this.
static LockScreen* Get();
// Creates and displays the lock screen. The lock screen communicates with the
// backend C++ via a mojo API.
static void Show(ScreenType type);
// Returns true if the instance has been instantiated.
static bool HasInstance();
views::Widget* widget() { return widget_.get(); }
// Destroys an existing lock screen instance.
void Destroy();
ScreenType screen_type() const { return type_; }
// Returns if the screen has been shown (i.e. |LockWindow::Show| was called).
bool is_shown() const { return is_shown_; }
void FocusNextUser();
void FocusPreviousUser();
void ShowParentAccessDialog();
// TrayActionObserver:
void OnLockScreenNoteStateChanged(mojom::TrayActionState state) override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
void OnLockStateChanged(bool locked) override;
void OnChromeTerminating() override;
explicit LockScreen(ScreenType type);
~LockScreen() override;
std::unique_ptr<views::View> MakeContentsView();
// Shows the lock screen widget, unless the global instance was already
// destroyed. Called after the first wallpaper becomes ready.
static void ShowWidgetUponWallpaperReady();
// The type of screen shown. Controls how the screen is dismissed.
const ScreenType type_;
// The lock screen widget.
std::unique_ptr<views::Widget> widget_;
// Unowned pointer to the LockContentsView hosted in lock window.
LockContentsView* contents_view_ = nullptr;
bool is_shown_ = false;
std::unique_ptr<ui::Clipboard> saved_clipboard_;
ScopedObserver<TrayAction, TrayActionObserver> tray_action_observer_{this};
ScopedSessionObserver session_observer_{this};
std::vector<base::OnceClosure> on_shown_callbacks_;
} // namespace ash