login_shelf_view.cc 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/shelf/login_shelf_view.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include "ash/constants/ash_features.h"
  10. #include "ash/constants/ash_switches.h"
  11. #include "ash/focus_cycler.h"
  12. #include "ash/keyboard/ui/keyboard_ui_controller.h"
  13. #include "ash/lock_screen_action/lock_screen_action_background_state.h"
  14. #include "ash/login/login_screen_controller.h"
  15. #include "ash/login/ui/lock_screen.h"
  16. #include "ash/metrics/login_metrics_recorder.h"
  17. #include "ash/metrics/user_metrics_recorder.h"
  18. #include "ash/public/cpp/login_accelerators.h"
  19. #include "ash/public/cpp/login_types.h"
  20. #include "ash/public/cpp/shelf_config.h"
  21. #include "ash/resources/vector_icons/vector_icons.h"
  22. #include "ash/root_window_controller.h"
  23. #include "ash/session/session_controller_impl.h"
  24. #include "ash/shelf/kiosk_app_instruction_bubble.h"
  25. #include "ash/shelf/shelf.h"
  26. #include "ash/shelf/shelf_shutdown_confirmation_bubble.h"
  27. #include "ash/shelf/shelf_widget.h"
  28. #include "ash/shell.h"
  29. #include "ash/strings/grit/ash_strings.h"
  30. #include "ash/style/ash_color_provider.h"
  31. #include "ash/style/default_color_constants.h"
  32. #include "ash/style/default_colors.h"
  33. #include "ash/style/pill_button.h"
  34. #include "ash/style/style_util.h"
  35. #include "ash/system/model/enterprise_domain_model.h"
  36. #include "ash/system/model/system_tray_model.h"
  37. #include "ash/system/status_area_widget.h"
  38. #include "ash/system/status_area_widget_delegate.h"
  39. #include "ash/system/tray/system_tray_notifier.h"
  40. #include "ash/system/tray/tray_background_view.h"
  41. #include "ash/system/tray/tray_popup_utils.h"
  42. #include "ash/wm/lock_state_controller.h"
  43. #include "base/bind.h"
  44. #include "base/callback_helpers.h"
  45. #include "base/metrics/user_metrics.h"
  46. #include "base/sequence_checker.h"
  47. #include "base/threading/thread_task_runner_handle.h"
  48. #include "chromeos/strings/grit/chromeos_strings.h"
  49. #include "chromeos/ui/vector_icons/vector_icons.h"
  50. #include "skia/ext/image_operations.h"
  51. #include "ui/accessibility/ax_node_data.h"
  52. #include "ui/base/l10n/l10n_util.h"
  53. #include "ui/base/models/image_model.h"
  54. #include "ui/base/models/menu_model.h"
  55. #include "ui/base/models/simple_menu_model.h"
  56. #include "ui/compositor/scoped_layer_animation_settings.h"
  57. #include "ui/display/manager/display_configurator.h"
  58. #include "ui/events/types/event_type.h"
  59. #include "ui/gfx/canvas.h"
  60. #include "ui/gfx/color_palette.h"
  61. #include "ui/gfx/geometry/rect.h"
  62. #include "ui/gfx/geometry/size.h"
  63. #include "ui/gfx/image/image_skia_operations.h"
  64. #include "ui/gfx/paint_vector_icon.h"
  65. #include "ui/gfx/vector_icon_types.h"
  66. #include "ui/views/accessibility/view_accessibility.h"
  67. #include "ui/views/animation/ink_drop.h"
  68. #include "ui/views/animation/ink_drop_impl.h"
  69. #include "ui/views/animation/ink_drop_mask.h"
  70. #include "ui/views/controls/button/menu_button.h"
  71. #include "ui/views/controls/focus_ring.h"
  72. #include "ui/views/controls/highlight_path_generator.h"
  73. #include "ui/views/controls/menu/menu_runner.h"
  74. #include "ui/views/controls/menu/menu_types.h"
  75. #include "ui/views/focus/focus_search.h"
  76. #include "ui/views/layout/box_layout.h"
  77. #include "ui/views/view_class_properties.h"
  78. #include "ui/views/widget/widget.h"
  79. using session_manager::SessionState;
  80. namespace ash {
  81. namespace {
  82. const char* kLoginShelfButtonClassName = "LoginShelfButton";
  83. // Skip only that many to avoid blocking users in case of any subtle bugs.
  84. const int kMaxDroppedCallsWhenDisplaysOff = 3;
  85. constexpr LoginShelfView::ButtonId kButtonIds[] = {
  86. LoginShelfView::kShutdown,
  87. LoginShelfView::kRestart,
  88. LoginShelfView::kSignOut,
  89. LoginShelfView::kCloseNote,
  90. LoginShelfView::kCancel,
  91. LoginShelfView::kParentAccess,
  92. LoginShelfView::kBrowseAsGuest,
  93. LoginShelfView::kAddUser,
  94. LoginShelfView::kEnterpriseEnrollment,
  95. LoginShelfView::kSignIn,
  96. LoginShelfView::kOsInstall,
  97. };
  98. // The color of the button text and icon in light mode. This is
  99. // the mode used during OOBE, but color mode is under feature flag
  100. // at the moment so only dark mode is available.
  101. constexpr SkColor kButtonTextAndIconColorLight = gfx::kGoogleGrey700;
  102. // TODO(1190978): Remove this check once light mode is the default mode.
  103. bool IsOobe() {
  104. return Shell::Get()->session_controller()->GetSessionState() ==
  105. SessionState::OOBE;
  106. }
  107. SkColor GetButtonTextColor() {
  108. if (IsOobe())
  109. return kButtonTextAndIconColorLight;
  110. return AshColorProvider::Get()->GetContentLayerColor(
  111. AshColorProvider::ContentLayerType::kButtonLabelColor);
  112. }
  113. SkColor GetButtonIconColor() {
  114. if (IsOobe())
  115. return kButtonTextAndIconColorLight;
  116. return AshColorProvider::Get()->GetContentLayerColor(
  117. AshColorProvider::ContentLayerType::kButtonIconColor);
  118. }
  119. LoginMetricsRecorder::ShelfButtonClickTarget GetUserClickTarget(int button_id) {
  120. switch (button_id) {
  121. case LoginShelfView::kShutdown:
  122. return LoginMetricsRecorder::ShelfButtonClickTarget::kShutDownButton;
  123. case LoginShelfView::kRestart:
  124. return LoginMetricsRecorder::ShelfButtonClickTarget::kRestartButton;
  125. case LoginShelfView::kSignOut:
  126. return LoginMetricsRecorder::ShelfButtonClickTarget::kSignOutButton;
  127. case LoginShelfView::kCloseNote:
  128. return LoginMetricsRecorder::ShelfButtonClickTarget::kCloseNoteButton;
  129. case LoginShelfView::kBrowseAsGuest:
  130. return LoginMetricsRecorder::ShelfButtonClickTarget::kBrowseAsGuestButton;
  131. case LoginShelfView::kAddUser:
  132. return LoginMetricsRecorder::ShelfButtonClickTarget::kAddUserButton;
  133. case LoginShelfView::kCancel:
  134. return LoginMetricsRecorder::ShelfButtonClickTarget::kCancelButton;
  135. case LoginShelfView::kParentAccess:
  136. return LoginMetricsRecorder::ShelfButtonClickTarget::kParentAccessButton;
  137. case LoginShelfView::kEnterpriseEnrollment:
  138. return LoginMetricsRecorder::ShelfButtonClickTarget::
  139. kEnterpriseEnrollmentButton;
  140. case LoginShelfView::kSignIn:
  141. return LoginMetricsRecorder::ShelfButtonClickTarget::kSignIn;
  142. case LoginShelfView::kOsInstall:
  143. return LoginMetricsRecorder::ShelfButtonClickTarget::kOsInstallButton;
  144. }
  145. return LoginMetricsRecorder::ShelfButtonClickTarget::kTargetCount;
  146. }
  147. void ButtonPressed(int id, base::RepeatingClosure callback) {
  148. UserMetricsRecorder::RecordUserClickOnShelfButton(GetUserClickTarget(id));
  149. std::move(callback).Run();
  150. }
  151. // The margins of the button contents.
  152. constexpr int kButtonMarginRightDp = PillButton::kPillButtonHorizontalSpacing;
  153. constexpr int kButtonMarginLeftDp = kButtonMarginRightDp - 4;
  154. // Spacing between the button image and label.
  155. constexpr int kImageLabelSpacingDp = 8;
  156. void AnimateButtonOpacity(ui::Layer* layer,
  157. float target_opacity,
  158. base::TimeDelta animation_duration,
  159. gfx::Tween::Type type) {
  160. ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator());
  161. animation_setter.SetTransitionDuration(animation_duration);
  162. animation_setter.SetTweenType(type);
  163. animation_setter.SetPreemptionStrategy(
  164. ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
  165. layer->SetOpacity(target_opacity);
  166. }
  167. } // namespace
  168. class LoginShelfButton : public PillButton {
  169. public:
  170. LoginShelfButton(PressedCallback callback,
  171. int text_resource_id,
  172. const gfx::VectorIcon& icon)
  173. : PillButton(std::move(callback),
  174. l10n_util::GetStringUTF16(text_resource_id),
  175. PillButton::Type::kIconLarge,
  176. &icon,
  177. PillButton::kPillButtonHorizontalSpacing),
  178. text_resource_id_(text_resource_id),
  179. icon_(icon) {
  180. SetFocusBehavior(FocusBehavior::ALWAYS);
  181. set_suppress_default_focus_handling();
  182. SetFocusPainter(nullptr);
  183. views::InkDrop::Get(this)->SetMode(views::InkDropHost::InkDropMode::ON);
  184. }
  185. LoginShelfButton(const LoginShelfButton&) = delete;
  186. LoginShelfButton& operator=(const LoginShelfButton&) = delete;
  187. ~LoginShelfButton() override = default;
  188. int text_resource_id() const { return text_resource_id_; }
  189. const char* GetClassName() const override {
  190. return kLoginShelfButtonClassName;
  191. }
  192. std::u16string GetTooltipText(const gfx::Point& p) const override {
  193. if (label()->IsDisplayTextTruncated())
  194. return label()->GetText();
  195. return std::u16string();
  196. }
  197. void UpdateButtonColors() {
  198. SetEnabledTextColors(GetButtonTextColor());
  199. SetImage(views::Button::STATE_NORMAL,
  200. gfx::CreateVectorIcon(icon_, GetButtonIconColor()));
  201. }
  202. void OnFocus() override {
  203. auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
  204. keyboard_controller->set_keyboard_locked(false /*lock*/);
  205. keyboard_controller->HideKeyboardImplicitlyByUser();
  206. }
  207. private:
  208. const int text_resource_id_;
  209. const gfx::VectorIcon& icon_;
  210. };
  211. class KioskAppsButton : public views::MenuButton,
  212. public ui::SimpleMenuModel,
  213. public ui::SimpleMenuModel::Delegate {
  214. public:
  215. KioskAppsButton()
  216. : MenuButton(base::BindRepeating(
  217. [](KioskAppsButton* button) {
  218. if (button->is_launch_enabled_)
  219. button->DisplayMenu();
  220. },
  221. this),
  222. l10n_util::GetStringUTF16(IDS_ASH_SHELF_APPS_BUTTON)),
  223. ui::SimpleMenuModel(this) {
  224. SetFocusBehavior(FocusBehavior::ALWAYS);
  225. set_suppress_default_focus_handling();
  226. SetInstallFocusRingOnFocus(true);
  227. views::FocusRing::Get(this)->SetColorId(ui::kColorAshFocusRing);
  228. views::InstallRoundRectHighlightPathGenerator(
  229. this, gfx::Insets(), ShelfConfig::Get()->control_border_radius());
  230. SetFocusPainter(nullptr);
  231. views::InkDrop::Get(this)->SetMode(views::InkDropHost::InkDropMode::ON);
  232. SetHasInkDropActionOnClick(true);
  233. views::InkDrop::UseInkDropWithoutAutoHighlight(
  234. views::InkDrop::Get(this), /*highlight_on_hover=*/false);
  235. StyleUtil::ConfigureInkDropAttributes(
  236. this, StyleUtil::kBaseColor | StyleUtil::kInkDropOpacity);
  237. // Layer rendering is required when the shelf background is visible, which
  238. // happens when the wallpaper is not blurred.
  239. SetPaintToLayer();
  240. layer()->SetFillsBoundsOpaquely(false);
  241. SetTextSubpixelRenderingEnabled(false);
  242. SetImageLabelSpacing(kImageLabelSpacingDp);
  243. label()->SetFontList(views::Label::GetDefaultFontList().Derive(
  244. 1, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
  245. }
  246. KioskAppsButton(const KioskAppsButton&) = delete;
  247. KioskAppsButton& operator=(const KioskAppsButton&) = delete;
  248. bool LaunchAppForTesting(const std::string& app_id) {
  249. for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
  250. if (kiosk_apps_[i].app_id == app_id) {
  251. ExecuteCommand(i, 0);
  252. return true;
  253. }
  254. }
  255. return false;
  256. }
  257. // Replace the existing items list with a new list of kiosk app menu items.
  258. void SetApps(const std::vector<KioskAppMenuEntry>& kiosk_apps) {
  259. kiosk_apps_ = kiosk_apps;
  260. Clear();
  261. const gfx::Size kAppIconSize(16, 16);
  262. for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
  263. gfx::ImageSkia icon = gfx::ImageSkiaOperations::CreateResizedImage(
  264. kiosk_apps_[i].icon, skia::ImageOperations::RESIZE_GOOD,
  265. kAppIconSize);
  266. AddItemWithIcon(i, kiosk_apps_[i].name,
  267. ui::ImageModel::FromImageSkia(icon));
  268. }
  269. // If the menu is being shown, update it.
  270. if (menu_runner_ && menu_runner_->IsRunning()) {
  271. DisplayMenu();
  272. }
  273. }
  274. void ConfigureKioskCallbacks(
  275. const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
  276. const base::RepeatingClosure& on_show_menu,
  277. const base::RepeatingClosure& on_close_menu) {
  278. launch_app_callback_ = launch_app;
  279. on_show_menu_ = on_show_menu;
  280. on_close_menu_ = on_close_menu;
  281. }
  282. bool HasApps() const { return !kiosk_apps_.empty(); }
  283. int GetHeightForWidth(int width) const override {
  284. return ShelfConfig::Get()->control_size();
  285. }
  286. // views::MenuButton:
  287. gfx::Insets GetInsets() const override {
  288. return gfx::Insets::TLBR(0, kButtonMarginLeftDp, 0, kButtonMarginRightDp);
  289. }
  290. SkPath GetButtonHighlightPath(const views::View* view) {
  291. gfx::Rect rect(view->GetLocalBounds());
  292. const int border_radius = ShelfConfig::Get()->control_border_radius();
  293. return SkPath().addRoundRect(gfx::RectToSkRect(rect), border_radius,
  294. border_radius);
  295. }
  296. void PaintButtonContents(gfx::Canvas* canvas) override {
  297. cc::PaintFlags flags;
  298. flags.setAntiAlias(true);
  299. flags.setColor(ShelfConfig::Get()->GetShelfControlButtonColor());
  300. flags.setStyle(cc::PaintFlags::kFill_Style);
  301. canvas->DrawPath(GetButtonHighlightPath(this), flags);
  302. }
  303. void SetVisible(bool visible) override {
  304. MenuButton::SetVisible(visible);
  305. if (visible)
  306. is_launch_enabled_ = true;
  307. }
  308. void UpdateButtonColors() {
  309. SetEnabledTextColors(GetButtonTextColor());
  310. SetImage(views::Button::STATE_NORMAL,
  311. CreateVectorIcon(kShelfAppsButtonIcon, GetButtonIconColor()));
  312. }
  313. void DisplayMenu() {
  314. const gfx::Point point = GetMenuPosition();
  315. const gfx::Point origin(point.x() - width(), point.y() - height());
  316. menu_runner_ = std::make_unique<views::MenuRunner>(
  317. this, views::MenuRunner::HAS_MNEMONICS);
  318. menu_runner_->RunMenuAt(GetWidget()->GetTopLevelWidget(),
  319. button_controller(), gfx::Rect(origin, gfx::Size()),
  320. views::MenuAnchorPosition::kTopLeft,
  321. ui::MENU_SOURCE_NONE);
  322. }
  323. // ui::SimpleMenuModel:
  324. void ExecuteCommand(int command_id, int event_flags) override {
  325. DCHECK(command_id >= 0 &&
  326. base::checked_cast<size_t>(command_id) < kiosk_apps_.size());
  327. // Once an app is clicked on, don't allow any additional clicks until
  328. // the state is reset (when login screen reappears).
  329. is_launch_enabled_ = false;
  330. launch_app_callback_.Run(kiosk_apps_[command_id]);
  331. }
  332. void OnMenuWillShow(SimpleMenuModel* source) override {
  333. is_menu_opened_ = true;
  334. on_show_menu_.Run();
  335. }
  336. void MenuClosed(SimpleMenuModel* source) override {
  337. on_close_menu_.Run();
  338. is_menu_opened_ = false;
  339. }
  340. bool IsCommandIdChecked(int command_id) const override { return false; }
  341. bool IsCommandIdEnabled(int command_id) const override { return true; }
  342. bool IsMenuOpened() { return is_menu_opened_; }
  343. private:
  344. base::RepeatingCallback<void(const KioskAppMenuEntry&)> launch_app_callback_;
  345. base::RepeatingClosure on_show_menu_;
  346. base::RepeatingClosure on_close_menu_;
  347. std::unique_ptr<views::MenuRunner> menu_runner_;
  348. std::vector<KioskAppMenuEntry> kiosk_apps_;
  349. bool is_launch_enabled_ = true;
  350. bool is_menu_opened_ = false;
  351. };
  352. // Class that temporarily disables Guest login buttin on shelf.
  353. class LoginShelfView::ScopedGuestButtonBlockerImpl
  354. : public ScopedGuestButtonBlocker {
  355. public:
  356. explicit ScopedGuestButtonBlockerImpl(
  357. base::WeakPtr<LoginShelfView> shelf_view)
  358. : shelf_view_(shelf_view) {
  359. ++(shelf_view_->scoped_guest_button_blockers_);
  360. if (shelf_view_->scoped_guest_button_blockers_ == 1)
  361. shelf_view_->UpdateUi();
  362. }
  363. ~ScopedGuestButtonBlockerImpl() override {
  364. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  365. if (!shelf_view_)
  366. return;
  367. DCHECK_GT(shelf_view_->scoped_guest_button_blockers_, 0);
  368. --(shelf_view_->scoped_guest_button_blockers_);
  369. if (!shelf_view_->scoped_guest_button_blockers_)
  370. shelf_view_->UpdateUi();
  371. }
  372. private:
  373. SEQUENCE_CHECKER(sequence_checker_);
  374. // ScopedGuestButtonBlockerImpl is not owned by the LoginShelfView,
  375. // so they could be independently destroyed.
  376. base::WeakPtr<LoginShelfView> shelf_view_;
  377. };
  378. LoginShelfView::TestUiUpdateDelegate::~TestUiUpdateDelegate() = default;
  379. void LoginShelfView::CallIfDisplayIsOn(const base::RepeatingClosure& closure) {
  380. if (!Shell::Get()->display_configurator()->IsDisplayOn() &&
  381. dropped_calls_when_displays_off_ < kMaxDroppedCallsWhenDisplaysOff) {
  382. ++dropped_calls_when_displays_off_;
  383. return;
  384. }
  385. dropped_calls_when_displays_off_ = 0;
  386. closure.Run();
  387. }
  388. void LoginShelfView::OnRequestShutdownConfirmed() {
  389. test_shutdown_confirmation_bubble_ = nullptr;
  390. Shell::Get()->lock_state_controller()->RequestShutdown(
  391. ShutdownReason::LOGIN_SHUT_DOWN_BUTTON);
  392. }
  393. void LoginShelfView::OnRequestShutdownCancelled() {
  394. test_shutdown_confirmation_bubble_ = nullptr;
  395. }
  396. void LoginShelfView::RequestShutdown() {
  397. base::RecordAction(base::UserMetricsAction("Shelf_ShutDown"));
  398. if (base::FeatureList::IsEnabled(features::kShutdownConfirmationBubble)) {
  399. Shelf* shelf = Shelf::ForWindow(GetWidget()->GetNativeWindow());
  400. // When the created ShelfShutdownConfirmationBubble is destroyed, it would
  401. // call LoginShelfView::OnRequestShutdownCancelled() in the destructor to
  402. // ensure that the pointer test_shutdown_confirmation_bubble_ here is
  403. // cleaned up.
  404. // And ShelfShutdownConfirmationBubble would be destroyed when it's
  405. // dismissed or its buttons were presses.
  406. test_shutdown_confirmation_bubble_ = new ShelfShutdownConfirmationBubble(
  407. GetViewByID(kShutdown), shelf->alignment(),
  408. base::BindOnce(&LoginShelfView::OnRequestShutdownConfirmed,
  409. weak_ptr_factory_.GetWeakPtr()),
  410. base::BindOnce(&LoginShelfView::OnRequestShutdownCancelled,
  411. weak_ptr_factory_.GetWeakPtr()));
  412. } else {
  413. OnRequestShutdownConfirmed();
  414. }
  415. }
  416. LoginShelfView::LoginShelfView(
  417. LockScreenActionBackgroundController* lock_screen_action_background)
  418. : lock_screen_action_background_(lock_screen_action_background) {
  419. ShelfConfig::Get()->AddObserver(this);
  420. // We reuse the focusable state on this view as a signal that focus should
  421. // switch to the lock screen or status area. This view should otherwise not
  422. // be focusable.
  423. SetFocusBehavior(FocusBehavior::ALWAYS);
  424. std::unique_ptr<views::BoxLayout> box_layout =
  425. std::make_unique<views::BoxLayout>(
  426. views::BoxLayout::Orientation::kHorizontal);
  427. box_layout->set_cross_axis_alignment(
  428. views::BoxLayout::CrossAxisAlignment::kCenter);
  429. box_layout->set_between_child_spacing(ShelfConfig::Get()->button_spacing());
  430. box_layout->set_inside_border_insets(
  431. gfx::Insets::TLBR(0, ShelfConfig::Get()->button_spacing(), 0, 0));
  432. SetLayoutManager(std::move(box_layout));
  433. auto add_button = [this](ButtonId id, base::RepeatingClosure callback,
  434. int text_resource_id, const gfx::VectorIcon& icon) {
  435. LoginShelfButton* button = new LoginShelfButton(
  436. base::BindRepeating(&ButtonPressed, id, std::move(callback)),
  437. text_resource_id, icon);
  438. button->SetID(id);
  439. AddChildView(button);
  440. login_shelf_buttons_.push_back(button);
  441. };
  442. const auto shutdown_callback = base::BindRepeating(
  443. &LoginShelfView::RequestShutdown, weak_ptr_factory_.GetWeakPtr());
  444. add_button(
  445. kShutdown,
  446. base::BindRepeating(&LoginShelfView::CallIfDisplayIsOn,
  447. weak_ptr_factory_.GetWeakPtr(), shutdown_callback),
  448. IDS_ASH_SHELF_SHUTDOWN_BUTTON, kShelfShutdownButtonIcon);
  449. const auto restart_callback = base::BindRepeating(
  450. &LockStateController::RequestShutdown,
  451. base::Unretained(Shell::Get()->lock_state_controller()),
  452. ShutdownReason::LOGIN_SHUT_DOWN_BUTTON);
  453. add_button(kRestart, std::move(restart_callback),
  454. IDS_ASH_SHELF_RESTART_BUTTON, kShelfShutdownButtonIcon);
  455. add_button(
  456. kSignOut,
  457. base::BindRepeating(
  458. &LoginShelfView::CallIfDisplayIsOn, weak_ptr_factory_.GetWeakPtr(),
  459. base::BindRepeating([]() {
  460. base::RecordAction(base::UserMetricsAction("ScreenLocker_Signout"));
  461. Shell::Get()->session_controller()->RequestSignOut();
  462. })),
  463. IDS_ASH_SHELF_SIGN_OUT_BUTTON, kShelfSignOutButtonIcon);
  464. kiosk_apps_button_ = new KioskAppsButton();
  465. kiosk_apps_button_->SetID(kApps);
  466. AddChildView(kiosk_apps_button_);
  467. add_button(kCloseNote,
  468. base::BindRepeating(
  469. &TrayAction::CloseLockScreenNote,
  470. base::Unretained(Shell::Get()->tray_action()),
  471. mojom::CloseLockScreenNoteReason::kUnlockButtonPressed),
  472. IDS_ASH_SHELF_UNLOCK_BUTTON, kShelfUnlockButtonIcon);
  473. add_button(kCancel,
  474. base::BindRepeating(
  475. [](LoginShelfView* shelf) {
  476. // If the Cancel button has focus, clear it. Otherwise the
  477. // shelf within active session may still be focused.
  478. shelf->GetFocusManager()->ClearFocus();
  479. Shell::Get()->login_screen_controller()->CancelAddUser();
  480. },
  481. this),
  482. IDS_ASH_SHELF_CANCEL_BUTTON, kShelfCancelButtonIcon);
  483. if (chromeos::features::IsOobeConsolidatedConsentEnabled()) {
  484. add_button(kBrowseAsGuest,
  485. base::BindRepeating(
  486. &LoginScreenController::ShowGuestTosScreen,
  487. base::Unretained(Shell::Get()->login_screen_controller())),
  488. IDS_ASH_BROWSE_AS_GUEST_BUTTON, kShelfBrowseAsGuestButtonIcon);
  489. } else {
  490. add_button(kBrowseAsGuest,
  491. base::BindRepeating(
  492. &LoginScreenController::LoginAsGuest,
  493. base::Unretained(Shell::Get()->login_screen_controller())),
  494. IDS_ASH_BROWSE_AS_GUEST_BUTTON, kShelfBrowseAsGuestButtonIcon);
  495. }
  496. add_button(kAddUser,
  497. base::BindRepeating(
  498. &LoginScreenController::ShowGaiaSignin,
  499. base::Unretained(Shell::Get()->login_screen_controller()),
  500. EmptyAccountId()),
  501. IDS_ASH_ADD_USER_BUTTON, kShelfAddPersonButtonIcon);
  502. add_button(kParentAccess, base::BindRepeating([]() {
  503. // TODO(https://crbug.com/999387): Remove this when handling
  504. // touch cancellation is fixed for system modal windows.
  505. base::ThreadTaskRunnerHandle::Get()->PostTask(
  506. FROM_HERE, base::BindOnce([]() {
  507. LockScreen::Get()->ShowParentAccessDialog();
  508. }));
  509. }),
  510. IDS_ASH_PARENT_ACCESS_BUTTON, kPinRequestLockIcon);
  511. add_button(kEnterpriseEnrollment,
  512. base::BindRepeating(
  513. &LoginScreenController::HandleAccelerator,
  514. base::Unretained(Shell::Get()->login_screen_controller()),
  515. ash::LoginAcceleratorAction::kStartEnrollment),
  516. IDS_ASH_ENTERPRISE_ENROLLMENT_BUTTON, chromeos::kEnterpriseIcon);
  517. add_button(kSignIn,
  518. base::BindRepeating(
  519. &LoginScreenController::HandleAccelerator,
  520. base::Unretained(Shell::Get()->login_screen_controller()),
  521. ash::LoginAcceleratorAction::kCancelScreenAction),
  522. IDS_ASH_SHELF_SIGNIN_BUTTON, kShelfAddPersonButtonIcon);
  523. add_button(kOsInstall,
  524. base::BindRepeating(
  525. &LoginScreenController::ShowOsInstallScreen,
  526. base::Unretained(Shell::Get()->login_screen_controller())),
  527. IDS_ASH_SHELF_OS_INSTALL_BUTTON, kShelfOsInstallButtonIcon);
  528. // Adds observers for states that affect the visibility of different buttons.
  529. tray_action_observation_.Observe(Shell::Get()->tray_action());
  530. shutdown_controller_observation_.Observe(Shell::Get()->shutdown_controller());
  531. lock_screen_action_background_observation_.Observe(
  532. lock_screen_action_background);
  533. login_data_dispatcher_observation_.Observe(
  534. Shell::Get()->login_screen_controller()->data_dispatcher());
  535. enterprise_domain_model_observation_.Observe(
  536. Shell::Get()->system_tray_model()->enterprise_domain());
  537. }
  538. LoginShelfView::~LoginShelfView() {
  539. ShelfConfig::Get()->RemoveObserver(this);
  540. }
  541. void LoginShelfView::UpdateAfterSessionChange() {
  542. UpdateUi();
  543. }
  544. void LoginShelfView::AddedToWidget() {
  545. UpdateUi();
  546. }
  547. const char* LoginShelfView::GetClassName() const {
  548. return "LoginShelfView";
  549. }
  550. void LoginShelfView::OnFocus() {
  551. LOG(WARNING) << "LoginShelfView was focused, but this should never happen. "
  552. "Forwarded focus to shelf widget with an unknown direction.";
  553. Shell::Get()->focus_cycler()->FocusWidget(
  554. Shelf::ForWindow(GetWidget()->GetNativeWindow())->shelf_widget());
  555. }
  556. void LoginShelfView::AboutToRequestFocusFromTabTraversal(bool reverse) {
  557. if (reverse) {
  558. // Focus should leave the system tray.
  559. Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse);
  560. } else {
  561. StatusAreaWidget* status_area_widget =
  562. Shelf::ForWindow(GetWidget()->GetNativeWindow())->GetStatusAreaWidget();
  563. // Focus goes to status area if it is visible.
  564. if (status_area_widget->IsVisible()) {
  565. status_area_widget->status_area_widget_delegate()
  566. ->set_default_last_focusable_child(reverse);
  567. Shell::Get()->focus_cycler()->FocusWidget(status_area_widget);
  568. } else {
  569. Shell::Get()->system_tray_notifier()->NotifyFocusOut(reverse);
  570. }
  571. }
  572. }
  573. void LoginShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
  574. if (LockScreen::HasInstance()) {
  575. GetViewAccessibility().OverridePreviousFocus(LockScreen::Get()->widget());
  576. }
  577. Shelf* shelf = Shelf::ForWindow(GetWidget()->GetNativeWindow());
  578. GetViewAccessibility().OverrideNextFocus(shelf->GetStatusAreaWidget());
  579. node_data->role = ax::mojom::Role::kToolbar;
  580. node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME));
  581. }
  582. void LoginShelfView::Layout() {
  583. views::View::Layout();
  584. UpdateButtonUnionBounds();
  585. }
  586. void LoginShelfView::OnThemeChanged() {
  587. views::View::OnThemeChanged();
  588. UpdateButtonsColors();
  589. }
  590. void LoginShelfView::OnShelfConfigUpdated() {
  591. views::InstallRoundRectHighlightPathGenerator(
  592. kiosk_apps_button_, gfx::Insets(),
  593. ShelfConfig::Get()->control_border_radius());
  594. }
  595. bool LoginShelfView::LaunchAppForTesting(const std::string& app_id) {
  596. return kiosk_apps_button_->GetEnabled() &&
  597. kiosk_apps_button_->LaunchAppForTesting(app_id);
  598. }
  599. void LoginShelfView::InstallTestUiUpdateDelegate(
  600. std::unique_ptr<TestUiUpdateDelegate> delegate) {
  601. DCHECK(!test_ui_update_delegate_.get());
  602. test_ui_update_delegate_ = std::move(delegate);
  603. }
  604. void LoginShelfView::OnKioskMenuShown(
  605. const base::RepeatingClosure& on_kiosk_menu_shown) {
  606. if (kiosk_instruction_bubble_)
  607. kiosk_instruction_bubble_->GetWidget()->Hide();
  608. on_kiosk_menu_shown.Run();
  609. }
  610. void LoginShelfView::OnKioskMenuclosed() {
  611. if (kiosk_instruction_bubble_)
  612. kiosk_instruction_bubble_->GetWidget()->Show();
  613. }
  614. void LoginShelfView::SetKioskApps(
  615. const std::vector<KioskAppMenuEntry>& kiosk_apps) {
  616. kiosk_apps_button_->SetApps(kiosk_apps);
  617. UpdateUi();
  618. if (LockScreen::HasInstance()) {
  619. LockScreen::Get()->SetHasKioskApp(kiosk_apps_button_->HasApps());
  620. }
  621. }
  622. void LoginShelfView::ConfigureKioskCallbacks(
  623. const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app,
  624. const base::RepeatingClosure& on_show_menu) {
  625. const auto show_kiosk_menu_callback =
  626. base::BindRepeating(&LoginShelfView::OnKioskMenuShown,
  627. weak_ptr_factory_.GetWeakPtr(), on_show_menu);
  628. const auto close_kiosk_menu_callback = base::BindRepeating(
  629. &LoginShelfView::OnKioskMenuclosed, weak_ptr_factory_.GetWeakPtr());
  630. kiosk_apps_button_->ConfigureKioskCallbacks(
  631. launch_app, show_kiosk_menu_callback, close_kiosk_menu_callback);
  632. }
  633. void LoginShelfView::SetLoginDialogState(OobeDialogState state) {
  634. dialog_state_ = state;
  635. UpdateUi();
  636. }
  637. void LoginShelfView::SetAllowLoginAsGuest(bool allow_guest) {
  638. allow_guest_ = allow_guest;
  639. UpdateUi();
  640. }
  641. void LoginShelfView::ShowParentAccessButton(bool show) {
  642. show_parent_access_ = show;
  643. UpdateUi();
  644. }
  645. void LoginShelfView::SetIsFirstSigninStep(bool is_first) {
  646. is_first_signin_step_ = is_first;
  647. UpdateUi();
  648. }
  649. void LoginShelfView::SetAddUserButtonEnabled(bool enable_add_user) {
  650. GetViewByID(kAddUser)->SetEnabled(enable_add_user);
  651. }
  652. void LoginShelfView::SetShutdownButtonEnabled(bool enable_shutdown_button) {
  653. GetViewByID(kShutdown)->SetEnabled(enable_shutdown_button);
  654. }
  655. void LoginShelfView::SetButtonEnabled(bool enabled) {
  656. // Only allow enabling shelf buttons when shelf is temporarily disabled and
  657. // only allow temporarily disabling shelf buttons when shelf is not already
  658. // disabled.
  659. if (enabled != is_shelf_temp_disabled_)
  660. return;
  661. is_shelf_temp_disabled_ = !enabled;
  662. for (const auto& button_id : kButtonIds) {
  663. GetViewByID(button_id)->SetEnabled(enabled);
  664. }
  665. StatusAreaWidget* status_area_widget =
  666. Shelf::ForWindow(GetWidget()->GetNativeWindow())->GetStatusAreaWidget();
  667. if (enabled) {
  668. for (TrayBackgroundView* tray_button : status_area_widget->tray_buttons()) {
  669. // Do not enable the button if it is already in disabled state before we
  670. // temporarily disable it.
  671. if (disabled_tray_buttons_.count(tray_button))
  672. continue;
  673. tray_button->SetEnabled(true);
  674. }
  675. disabled_tray_buttons_.clear();
  676. } else {
  677. for (TrayBackgroundView* tray_button : status_area_widget->tray_buttons()) {
  678. // Record the tray button if it is already in disabled state before we
  679. // temporarily disable it.
  680. if (!tray_button->GetEnabled())
  681. disabled_tray_buttons_.insert(tray_button);
  682. tray_button->SetEnabled(false);
  683. }
  684. }
  685. }
  686. void LoginShelfView::SetButtonOpacity(float target_opacity) {
  687. for (const auto& button_id : kButtonIds) {
  688. AnimateButtonOpacity(GetViewByID(button_id)->layer(), target_opacity,
  689. ShelfConfig::Get()->DimAnimationDuration(),
  690. ShelfConfig::Get()->DimAnimationTween());
  691. }
  692. AnimateButtonOpacity(kiosk_apps_button_->layer(), target_opacity,
  693. ShelfConfig::Get()->DimAnimationDuration(),
  694. ShelfConfig::Get()->DimAnimationTween());
  695. }
  696. void LoginShelfView::SetKioskLicenseModeForTesting(bool is_kiosk_license_mode) {
  697. kiosk_license_mode_ = is_kiosk_license_mode;
  698. }
  699. std::unique_ptr<ScopedGuestButtonBlocker>
  700. LoginShelfView::GetScopedGuestButtonBlocker() {
  701. return std::make_unique<LoginShelfView::ScopedGuestButtonBlockerImpl>(
  702. weak_ptr_factory_.GetWeakPtr());
  703. }
  704. void LoginShelfView::OnLockScreenNoteStateChanged(
  705. mojom::TrayActionState state) {
  706. UpdateUi();
  707. }
  708. void LoginShelfView::OnLockScreenActionBackgroundStateChanged(
  709. LockScreenActionBackgroundState state) {
  710. UpdateUi();
  711. }
  712. void LoginShelfView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
  713. UpdateUi();
  714. }
  715. void LoginShelfView::OnUsersChanged(const std::vector<LoginUserInfo>& users) {
  716. login_screen_has_users_ = !users.empty();
  717. UpdateUi();
  718. }
  719. void LoginShelfView::OnOobeDialogStateChanged(OobeDialogState state) {
  720. SetLoginDialogState(state);
  721. }
  722. void LoginShelfView::OnDeviceEnterpriseInfoChanged() {
  723. // If feature is enabled, update the boolean kiosk_license_mode_. Otherwise,
  724. // it's false by default.
  725. if (features::IsKioskLoginScreenEnabled()) {
  726. kiosk_license_mode_ =
  727. Shell::Get()
  728. ->system_tray_model()
  729. ->enterprise_domain()
  730. ->management_device_mode() == ManagementDeviceMode::kKioskSku;
  731. UpdateUi();
  732. }
  733. }
  734. void LoginShelfView::OnEnterpriseAccountDomainChanged() {}
  735. void LoginShelfView::HandleLocaleChange() {
  736. for (views::View* child : children()) {
  737. if (child->GetClassName() == kLoginShelfButtonClassName) {
  738. auto* button = static_cast<LoginShelfButton*>(child);
  739. button->SetText(l10n_util::GetStringUTF16(button->text_resource_id()));
  740. button->SetAccessibleName(button->GetText());
  741. }
  742. }
  743. }
  744. KioskAppInstructionBubble*
  745. LoginShelfView::GetKioskInstructionBubbleForTesting() {
  746. return kiosk_instruction_bubble_;
  747. }
  748. ShelfShutdownConfirmationBubble*
  749. LoginShelfView::GetShutdownConfirmationBubbleForTesting() {
  750. return test_shutdown_confirmation_bubble_;
  751. }
  752. bool LoginShelfView::LockScreenActionBackgroundAnimating() const {
  753. return lock_screen_action_background_->state() ==
  754. LockScreenActionBackgroundState::kShowing ||
  755. lock_screen_action_background_->state() ==
  756. LockScreenActionBackgroundState::kHiding;
  757. }
  758. void LoginShelfView::UpdateUi() {
  759. // Make sure observers are notified.
  760. base::ScopedClosureRunner fire_observer(base::BindOnce(
  761. [](LoginShelfView* self) {
  762. if (self->test_ui_update_delegate())
  763. self->test_ui_update_delegate()->OnUiUpdate();
  764. },
  765. base::Unretained(this)));
  766. SessionState session_state =
  767. Shell::Get()->session_controller()->GetSessionState();
  768. if (session_state == SessionState::ACTIVE ||
  769. session_state == SessionState::RMA) {
  770. // The entire view was set invisible. The buttons are also set invisible
  771. // to avoid affecting calculation of the shelf size.
  772. for (auto* child : children())
  773. child->SetVisible(false);
  774. return;
  775. }
  776. const gfx::Size old_preferred_size = GetPreferredSize();
  777. bool show_reboot = Shell::Get()->shutdown_controller()->reboot_on_shutdown();
  778. mojom::TrayActionState tray_action_state =
  779. Shell::Get()->tray_action()->GetLockScreenNoteState();
  780. bool is_locked = (session_state == SessionState::LOCKED);
  781. bool is_lock_screen_note_in_foreground =
  782. (tray_action_state == mojom::TrayActionState::kActive ||
  783. tray_action_state == mojom::TrayActionState::kLaunching) &&
  784. !LockScreenActionBackgroundAnimating();
  785. GetViewByID(kShutdown)->SetVisible(!show_reboot &&
  786. !is_lock_screen_note_in_foreground &&
  787. ShouldShowShutdownButton());
  788. GetViewByID(kRestart)->SetVisible(show_reboot &&
  789. !is_lock_screen_note_in_foreground &&
  790. ShouldShowShutdownButton());
  791. GetViewByID(kSignOut)->SetVisible(is_locked &&
  792. !is_lock_screen_note_in_foreground);
  793. GetViewByID(kCloseNote)
  794. ->SetVisible(is_locked && is_lock_screen_note_in_foreground);
  795. GetViewByID(kCancel)->SetVisible(session_state ==
  796. SessionState::LOGIN_SECONDARY);
  797. GetViewByID(kParentAccess)->SetVisible(is_locked && show_parent_access_);
  798. bool is_login_primary = (session_state == SessionState::LOGIN_PRIMARY);
  799. bool dialog_visible = dialog_state_ != OobeDialogState::HIDDEN;
  800. GetViewByID(kBrowseAsGuest)->SetVisible(ShouldShowGuestButton());
  801. GetViewByID(kEnterpriseEnrollment)
  802. ->SetVisible(ShouldShowEnterpriseEnrollmentButton());
  803. GetViewByID(kSignIn)->SetVisible(ShouldShowSignInButton());
  804. // Show add user button when it's in login screen and Oobe UI dialog is not
  805. // visible. The button should not appear if the device is not connected to a
  806. // network.
  807. GetViewByID(kAddUser)->SetVisible(!kiosk_license_mode_ && !dialog_visible &&
  808. is_login_primary);
  809. kiosk_apps_button_->SetVisible(kiosk_apps_button_->HasApps() &&
  810. ShouldShowAppsButton());
  811. if (kiosk_license_mode_) {
  812. // Create the bubble once the login shelf view is available for anchoring.
  813. if (!kiosk_instruction_bubble_) {
  814. Shelf* shelf = Shelf::ForWindow(GetWidget()->GetNativeWindow());
  815. kiosk_instruction_bubble_ =
  816. new KioskAppInstructionBubble(GetViewByID(kApps), shelf->alignment());
  817. }
  818. if (kiosk_instruction_bubble_) {
  819. // Show kiosk instructions if the kiosk app button is visible and the menu
  820. // is not opened.
  821. if (kiosk_apps_button_->GetVisible() &&
  822. !kiosk_apps_button_->IsMenuOpened()) {
  823. kiosk_instruction_bubble_->GetWidget()->Show();
  824. } else {
  825. kiosk_instruction_bubble_->GetWidget()->Hide();
  826. }
  827. }
  828. }
  829. GetViewByID(kOsInstall)->SetVisible(ShouldShowOsInstallButton());
  830. // If there is no visible (and thus focusable) buttons, we shouldn't focus
  831. // LoginShelfView. We update it here, so we don't need to check visibility
  832. // every time we move focus to system tray.
  833. bool is_anything_focusable = false;
  834. for (auto* child : login_shelf_buttons_) {
  835. if (child->IsFocusable()) {
  836. is_anything_focusable = true;
  837. break;
  838. }
  839. }
  840. SetFocusBehavior(is_anything_focusable ? views::View::FocusBehavior::ALWAYS
  841. : views::View::FocusBehavior::NEVER);
  842. UpdateButtonsColors();
  843. // When the login shelf view is moved to its own widget, the login shelf
  844. // widget needs to change the size according to the login shelf view's
  845. // preferred size.
  846. if (old_preferred_size != GetPreferredSize() &&
  847. features::IsUseLoginShelfWidgetEnabled()) {
  848. PreferredSizeChanged();
  849. } else {
  850. Layout();
  851. }
  852. }
  853. void LoginShelfView::UpdateButtonsColors() {
  854. static_cast<LoginShelfButton*>(GetViewByID(kShutdown))->UpdateButtonColors();
  855. static_cast<LoginShelfButton*>(GetViewByID(kRestart))->UpdateButtonColors();
  856. static_cast<LoginShelfButton*>(GetViewByID(kSignOut))->UpdateButtonColors();
  857. static_cast<LoginShelfButton*>(GetViewByID(kCloseNote))->UpdateButtonColors();
  858. static_cast<LoginShelfButton*>(GetViewByID(kCancel))->UpdateButtonColors();
  859. static_cast<LoginShelfButton*>(GetViewByID(kParentAccess))
  860. ->UpdateButtonColors();
  861. static_cast<LoginShelfButton*>(GetViewByID(kBrowseAsGuest))
  862. ->UpdateButtonColors();
  863. static_cast<LoginShelfButton*>(GetViewByID(kAddUser))->UpdateButtonColors();
  864. static_cast<LoginShelfButton*>(GetViewByID(kEnterpriseEnrollment))
  865. ->UpdateButtonColors();
  866. static_cast<LoginShelfButton*>(GetViewByID(kSignIn))->UpdateButtonColors();
  867. static_cast<LoginShelfButton*>(GetViewByID(kOsInstall))->UpdateButtonColors();
  868. kiosk_apps_button_->UpdateButtonColors();
  869. }
  870. void LoginShelfView::UpdateButtonUnionBounds() {
  871. button_union_bounds_ = gfx::Rect();
  872. View::Views children = GetChildrenInZOrder();
  873. for (auto* child : children) {
  874. if (child->GetVisible())
  875. button_union_bounds_.Union(child->bounds());
  876. }
  877. }
  878. bool LoginShelfView::ShouldShowGuestAndAppsButtons() const {
  879. bool dialog_state_allowed = false;
  880. if (dialog_state_ == OobeDialogState::USER_CREATION ||
  881. dialog_state_ == OobeDialogState::GAIA_SIGNIN) {
  882. dialog_state_allowed = !login_screen_has_users_ && is_first_signin_step_;
  883. } else if (dialog_state_ == OobeDialogState::ERROR ||
  884. dialog_state_ == OobeDialogState::HIDDEN) {
  885. dialog_state_allowed = true;
  886. }
  887. const bool user_session_started =
  888. Shell::Get()->session_controller()->NumberOfLoggedInUsers() != 0;
  889. return dialog_state_allowed && !user_session_started;
  890. }
  891. // If OobeRemoveShutdownButton feature is ON: show Shutdown button only in one
  892. // of the cases:
  893. // 1. On general login screen, when OOBE is completed and device is owned;
  894. // 2. On enrollment success step (admins/resellers may use the on screen button
  895. // to shut down the device after enrollment);
  896. // 3. On first screen of gaia login flow (same reason as 2).
  897. bool LoginShelfView::ShouldShowShutdownButton() const {
  898. if (features::IsOobeRemoveShutdownButtonEnabled()) {
  899. return dialog_state_ == OobeDialogState::HIDDEN ||
  900. dialog_state_ == OobeDialogState::ENROLLMENT_SUCCESS ||
  901. dialog_state_ == OobeDialogState::EXTENSION_LOGIN ||
  902. dialog_state_ == OobeDialogState::BLOCKING ||
  903. (dialog_state_ == OobeDialogState::GAIA_SIGNIN &&
  904. is_first_signin_step_);
  905. }
  906. return !(dialog_state_ == OobeDialogState::MIGRATION ||
  907. dialog_state_ == OobeDialogState::ENROLLMENT ||
  908. dialog_state_ == OobeDialogState::ENROLLMENT_CANCEL_ENABLED ||
  909. dialog_state_ == OobeDialogState::ONBOARDING ||
  910. dialog_state_ == OobeDialogState::KIOSK_LAUNCH ||
  911. dialog_state_ == OobeDialogState::PASSWORD_CHANGED);
  912. }
  913. // Show guest button if:
  914. // 1. Guest login is allowed.
  915. // 2. OOBE UI dialog is currently showing the login UI or error.
  916. // 3. No users sessions have started. Button is hidden from all post login
  917. // screens like sync consent, etc.
  918. // 4. It's in login screen or OOBE. Note: In OOBE, the guest button visibility
  919. // is manually controlled by the WebUI.
  920. // 5. OOBE UI dialog is not currently showing gaia signin screen, or if there
  921. // are no user views available. If there are no user pods (i.e. Gaia is the
  922. // only signin option), the guest button should be shown if allowed by policy
  923. // and OOBE.
  924. // 6. There are no scoped guest buttons blockers active.
  925. // 7. The device is not in kiosk license mode.
  926. bool LoginShelfView::ShouldShowGuestButton() const {
  927. if (!allow_guest_)
  928. return false;
  929. if (scoped_guest_button_blockers_ > 0)
  930. return false;
  931. if (!ShouldShowGuestAndAppsButtons())
  932. return false;
  933. const SessionState session_state =
  934. Shell::Get()->session_controller()->GetSessionState();
  935. if (session_state == SessionState::OOBE)
  936. return is_first_signin_step_;
  937. if (session_state != SessionState::LOGIN_PRIMARY)
  938. return false;
  939. return true;
  940. }
  941. bool LoginShelfView::ShouldShowEnterpriseEnrollmentButton() const {
  942. const SessionState session_state =
  943. Shell::Get()->session_controller()->GetSessionState();
  944. return session_state == SessionState::OOBE &&
  945. dialog_state_ == OobeDialogState::USER_CREATION;
  946. }
  947. bool LoginShelfView::ShouldShowSignInButton() const {
  948. const SessionState session_state =
  949. Shell::Get()->session_controller()->GetSessionState();
  950. return session_state == SessionState::OOBE &&
  951. dialog_state_ == OobeDialogState::ENROLLMENT_CANCEL_ENABLED;
  952. }
  953. bool LoginShelfView::ShouldShowAppsButton() const {
  954. if (!ShouldShowGuestAndAppsButtons())
  955. return false;
  956. const SessionState session_state =
  957. Shell::Get()->session_controller()->GetSessionState();
  958. if (session_state != SessionState::LOGIN_PRIMARY)
  959. return false;
  960. return true;
  961. }
  962. bool LoginShelfView::ShouldShowOsInstallButton() const {
  963. if (!switches::IsOsInstallAllowed())
  964. return false;
  965. if (!ShouldShowGuestAndAppsButtons())
  966. return false;
  967. const SessionState session_state =
  968. Shell::Get()->session_controller()->GetSessionState();
  969. if (session_state == SessionState::OOBE)
  970. return is_first_signin_step_;
  971. if (session_state != SessionState::LOGIN_PRIMARY)
  972. return false;
  973. return true;
  974. }
  975. } // namespace ash