Skip to content

Commit

Permalink
OOBE: Add common LoginAcceleratorAction table
Browse files Browse the repository at this point in the history
Bug: 1102393
Change-Id: I676aff22ea638b8a6d892e9306167b8357ccbc77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283209
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Denis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785520}
  • Loading branch information
Denis Kuznetsov authored and Commit Bot committed Jul 6, 2020
1 parent 06695e7 commit 148257e
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 98 deletions.
43 changes: 24 additions & 19 deletions ash/login/ui/lock_contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/login_accelerators.h"
#include "ash/public/cpp/login_types.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
Expand Down Expand Up @@ -2098,25 +2099,29 @@ bool LockContentsView::OnKeyPressed(const ui::KeyEvent& event) {
}

void LockContentsView::RegisterAccelerators() {
// Applies on login and lock:
accel_map_[ui::Accelerator(ui::VKEY_V, ui::EF_ALT_DOWN)] =
AcceleratorAction::kToggleSystemInfo;

// Login-only accelerators:
if (screen_type_ == LockScreen::ScreenType::kLogin) {
accel_map_[ui::Accelerator(ui::VKEY_I,
ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)] =
AcceleratorAction::kShowFeedback;

for (size_t i = 0; i < kLoginAcceleratorDataLength; ++i) {
if (!kLoginAcceleratorData[i].global)
continue;
if ((screen_type_ == LockScreen::ScreenType::kLogin) &&
!(kLoginAcceleratorData[i].scope & kScopeLogin)) {
continue;
}
if ((screen_type_ == LockScreen::ScreenType::kLock) &&
!(kLoginAcceleratorData[i].scope & kScopeLock)) {
continue;
}
// Show reset conflicts with rotate screen when --ash-dev-shortcuts is
// passed. Favor --ash-dev-shortcuts since that is explicitly added.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
if (kLoginAcceleratorData[i].action ==
LoginAcceleratorAction::kShowResetScreen &&
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshDeveloperShortcuts)) {
accel_map_[ui::Accelerator(ui::VKEY_R, ui::EF_CONTROL_DOWN |
ui::EF_SHIFT_DOWN |
ui::EF_ALT_DOWN)] =
AcceleratorAction::kShowResetScreen;
continue;
}

accel_map_[ui::Accelerator(kLoginAcceleratorData[i].keycode,
kLoginAcceleratorData[i].modifiers)] =
kLoginAcceleratorData[i].action;
}

// Register the accelerators.
Expand All @@ -2126,15 +2131,15 @@ void LockContentsView::RegisterAccelerators() {
controller->Register({item.first}, this);
}

void LockContentsView::PerformAction(AcceleratorAction action) {
void LockContentsView::PerformAction(LoginAcceleratorAction action) {
switch (action) {
case AcceleratorAction::kToggleSystemInfo:
case LoginAcceleratorAction::kToggleSystemInfo:
ToggleSystemInfo();
break;
case AcceleratorAction::kShowFeedback:
case LoginAcceleratorAction::kShowFeedback:
Shell::Get()->login_screen_controller()->ShowFeedback();
break;
case AcceleratorAction::kShowResetScreen:
case LoginAcceleratorAction::kShowResetScreen:
Shell::Get()->login_screen_controller()->ShowResetScreen();
break;
default:
Expand Down
11 changes: 3 additions & 8 deletions ash/login/ui/lock_contents_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ash/login/ui/login_tooltip_view.h"
#include "ash/login/ui/non_accessible_view.h"
#include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/public/cpp/login_accelerators.h"
#include "ash/public/cpp/login_types.h"
#include "ash/public/cpp/system_tray_focus_observer.h"
#include "base/callback_forward.h"
Expand Down Expand Up @@ -118,12 +119,6 @@ class ASH_EXPORT LockContentsView
kExclusivePublicAccountExpandedView,
};

enum class AcceleratorAction {
kToggleSystemInfo,
kShowFeedback,
kShowResetScreen,
};

// Number of login attempts before a login dialog is shown. For example, if
// this value is 4 then the user can submit their password 4 times, and on the
// 4th bad attempt the login dialog is shown. This only applies to the login
Expand Down Expand Up @@ -392,7 +387,7 @@ class ASH_EXPORT LockContentsView
void RegisterAccelerators();

// Performs the specified accelerator action.
void PerformAction(AcceleratorAction action);
void PerformAction(LoginAcceleratorAction action);

// Check whether the view should display the system information based on all
// factors including policy settings, channel and Alt-V accelerator.
Expand Down Expand Up @@ -487,7 +482,7 @@ class ASH_EXPORT LockContentsView
bool keyboard_shown_ = false;

// Accelerators handled by login screen.
std::map<ui::Accelerator, AcceleratorAction> accel_map_;
std::map<ui::Accelerator, LoginAcceleratorAction> accel_map_;

// Notifies Chrome when user activity is detected on the login screen so that
// the auto-login timer can be reset.
Expand Down
2 changes: 2 additions & 0 deletions ash/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ component("cpp") {
"locale_update_controller.h",
"lock_screen_widget_factory.cc",
"lock_screen_widget_factory.h",
"login_accelerators.cc",
"login_accelerators.h",
"login_constants.h",
"login_screen.cc",
"login_screen.h",
Expand Down
67 changes: 67 additions & 0 deletions ash/public/cpp/login_accelerators.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2018 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 "ash/public/cpp/login_accelerators.h"

#include "base/stl_util.h"

namespace ash {

// clang-format off
const LoginAcceleratorData kLoginAcceleratorData[] = {
{
kToggleSystemInfo,
ui::VKEY_V, ui::EF_ALT_DOWN,
true, kScopeOobe | kScopeLogin | kScopeLock,
}, {
kShowFeedback,
ui::VKEY_I, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
true, kScopeOobe | kScopeLogin,
}, {
kShowResetScreen,
ui::VKEY_R, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
true, kScopeOobe | kScopeLogin,
}, {
kAppLaunchBailout,
ui::VKEY_S, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe | kScopeLogin,
}, {
kAppLaunchNetworkConfig,
ui::VKEY_N, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe | kScopeLogin,
}, {
kCancelScreenAction,
ui::VKEY_ESCAPE, ui::EF_NONE,
false, kScopeOobe | kScopeLogin,
}, {
kStartEnrollment,
ui::VKEY_E, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe,
}, {
kStartDemoMode,
ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe,
}, {
kEnableDebugging,
ui::VKEY_X, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN,
false, kScopeOobe,
}, {
kEditDeviceRequisition,
ui::VKEY_D, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN,
false, kScopeOobe,
}, {
kDeviceRequisitionRemora,
ui::VKEY_H, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe,
}, {
kEnableConsumerKiosk,
ui::VKEY_K, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
false, kScopeOobe,
},
};
// clang-format on

const size_t kLoginAcceleratorDataLength = base::size(kLoginAcceleratorData);

} // namespace ash
61 changes: 61 additions & 0 deletions ash/public/cpp/login_accelerators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2020 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 ASH_PUBLIC_CPP_LOGIN_ACCELERATORS_H_
#define ASH_PUBLIC_CPP_LOGIN_ACCELERATORS_H_

#include <stddef.h>

#include "ash/public/cpp/ash_public_export.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"

namespace ash {

// Accelerator actions specific for out-of-box flow, login and lock screens.

// Flags that define in which contexts accelerator should be enabled.
enum LoginActionScope {
// Available during out-of-box flow.
kScopeOobe = 1 << 0,
// Available on the login screen.
kScopeLogin = 1 << 1,
// Available on the lock screen.
kScopeLock = 1 << 2,
};

enum LoginAcceleratorAction {
kToggleSystemInfo,
kShowFeedback,
kShowResetScreen,
kAppLaunchBailout,
kAppLaunchNetworkConfig,
kCancelScreenAction,
kStartEnrollment,
kEnableConsumerKiosk,
kEnableDebugging,
kEditDeviceRequisition,
kDeviceRequisitionRemora,
kStartDemoMode,
};

struct LoginAcceleratorData {
LoginAcceleratorAction action;
ui::KeyboardCode keycode;
// Combination of ui::EventFlags.
int modifiers;
// Defines if accelerator will be registered in AcceleratorController (|true|)
// or only for login/lock dialog view (|false|).
bool global;
// Combination of LoginActionScope flags.
int scope;
};

// Accelerators handled by OOBE / Login components.
ASH_PUBLIC_EXPORT extern const LoginAcceleratorData kLoginAcceleratorData[];
ASH_PUBLIC_EXPORT extern const size_t kLoginAcceleratorDataLength;

} // namespace ash

#endif // ASH_PUBLIC_CPP_LOGIN_ACCELERATORS_H_
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,8 @@ source_set("chromeos") {
"login/ui/views/user_board_view.h",
"login/ui/web_contents_forced_title.cc",
"login/ui/web_contents_forced_title.h",
"login/ui/webui_accelerator_mapping.cc",
"login/ui/webui_accelerator_mapping.h",
"login/ui/webui_login_view.cc",
"login/ui/webui_login_view.h",
"login/user_board_view_mojo.cc",
Expand Down
25 changes: 15 additions & 10 deletions chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <utility>
#include <vector>

#include "ash/public/cpp/login_accelerators.h"
#include "ash/public/cpp/login_screen.h"
#include "ash/public/cpp/login_screen_model.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_mojo.h"
#include "chrome/browser/chromeos/login/ui/oobe_dialog_size_utils.h"
#include "chrome/browser/chromeos/login/ui/webui_accelerator_mapping.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
Expand Down Expand Up @@ -41,9 +43,6 @@ namespace chromeos {
namespace {

constexpr char kGaiaURL[] = "chrome://oobe/gaia-signin";
constexpr char kAppLaunchBailout[] = "app_launch_bailout";
constexpr char kAppLaunchNetworkConfig[] = "app_launch_network_config";
constexpr char kCancel[] = "cancel";

CoreOobeView::DialogPaddingMode ConvertDialogPaddingMode(
OobeDialogPaddingMode padding) {
Expand Down Expand Up @@ -304,12 +303,18 @@ OobeUIDialogDelegate::OobeUIDialogDelegate(
: controller_(controller) {
keyboard_observer_.Add(ChromeKeyboardControllerClient::Get());

accel_map_[ui::Accelerator(
ui::VKEY_S, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)] = kAppLaunchBailout;
accel_map_[ui::Accelerator(ui::VKEY_N,
ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)] =
kAppLaunchNetworkConfig;
accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, 0)] = kCancel;
for (size_t i = 0; i < ash::kLoginAcceleratorDataLength; ++i) {
if (ash::kLoginAcceleratorData[i].global)
continue;
if (!(ash::kLoginAcceleratorData[i].scope &
(ash::kScopeLogin | ash::kScopeLock))) {
continue;
}

accel_map_[ui::Accelerator(ash::kLoginAcceleratorData[i].keycode,
ash::kLoginAcceleratorData[i].modifiers)] =
ash::kLoginAcceleratorData[i].action;
}

DCHECK(!dialog_view_ && !widget_);
// Life cycle of |dialog_view_| is managed by the widget:
Expand Down Expand Up @@ -491,7 +496,7 @@ bool OobeUIDialogDelegate::AcceleratorPressed(
if (entry == accel_map_.end())
return false;

GetOobeUI()->ForwardAccelerator(entry->second);
GetOobeUI()->ForwardAccelerator(MapToWebUIAccelerator(entry->second));
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <string>

#include "ash/public/cpp/login_accelerators.h"
#include "ash/public/cpp/login_types.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -131,7 +132,7 @@ class OobeUIDialogDelegate : public ui::WebDialogDelegate,
ScopedObserver<CaptivePortalWindowProxy, CaptivePortalWindowProxy::Observer>
captive_portal_observer_{this};

std::map<ui::Accelerator, std::string> accel_map_;
std::map<ui::Accelerator, ash::LoginAcceleratorAction> accel_map_;
ash::OobeDialogState state_ = ash::OobeDialogState::HIDDEN;

// Whether the captive portal screen should be shown the next time the Gaia
Expand Down
61 changes: 61 additions & 0 deletions chrome/browser/chromeos/login/ui/webui_accelerator_mapping.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2020 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/ui/webui_accelerator_mapping.h"

#include <string>

#include "ash/public/cpp/login_accelerators.h"

namespace chromeos {

namespace {

// These strings must be kept in sync with handleAccelerator()
// in display_manager.js.
const char kAccelNameCancel[] = "cancel";
const char kAccelNameEnableDebugging[] = "debugging";
const char kAccelNameEnrollment[] = "enrollment";
const char kAccelNameKioskEnable[] = "kiosk_enable";
const char kAccelNameVersion[] = "version";
const char kAccelNameReset[] = "reset";
const char kAccelNameDeviceRequisition[] = "device_requisition";
const char kAccelNameDeviceRequisitionRemora[] = "device_requisition_remora";
const char kAccelNameAppLaunchBailout[] = "app_launch_bailout";
const char kAccelNameAppLaunchNetworkConfig[] = "app_launch_network_config";
const char kAccelNameDemoMode[] = "demo_mode";
const char kAccelSendFeedback[] = "send_feedback";

} // namespace

std::string MapToWebUIAccelerator(ash::LoginAcceleratorAction action) {
switch (action) {
case ash::LoginAcceleratorAction::kToggleSystemInfo:
return kAccelNameVersion;
case ash::LoginAcceleratorAction::kShowFeedback:
return kAccelSendFeedback;
case ash::LoginAcceleratorAction::kShowResetScreen:
return kAccelNameReset;
case ash::LoginAcceleratorAction::kAppLaunchBailout:
return kAccelNameAppLaunchBailout;
case ash::LoginAcceleratorAction::kAppLaunchNetworkConfig:
return kAccelNameAppLaunchNetworkConfig;
case ash::LoginAcceleratorAction::kCancelScreenAction:
return kAccelNameCancel;
case ash::LoginAcceleratorAction::kStartEnrollment:
return kAccelNameEnrollment;
case ash::LoginAcceleratorAction::kEnableConsumerKiosk:
return kAccelNameKioskEnable;
case ash::LoginAcceleratorAction::kEnableDebugging:
return kAccelNameEnableDebugging;
case ash::LoginAcceleratorAction::kEditDeviceRequisition:
return kAccelNameDeviceRequisition;
case ash::LoginAcceleratorAction::kDeviceRequisitionRemora:
return kAccelNameDeviceRequisitionRemora;
case ash::LoginAcceleratorAction::kStartDemoMode:
return kAccelNameDemoMode;
}
}

} // namespace chromeos

0 comments on commit 148257e

Please sign in to comment.