Skip to content

Commit

Permalink
Shortcuts: Add ShortcutCustomizationAllowed policy
Browse files Browse the repository at this point in the history
* This CL adds the ShortcutCustomizationAllowed admin policy.
* Add |accelerator_prefs|, it will be get initialized by shell and used
  to register the boolean.
* In the following CLs, we will use this policy to control
  ash::prefs::kShortcutCustomizationAllowed, then use the pref to
  allow/disallow customization of key shortcuts. We will also add an
  observer to support dynamic refresh (without needing to restart
  Chrome).
* Follow this doc:
   - https://crsrc.org/c/docs/enterprise/add_new_policy.md

Bug: b/216049298
Test: json tests
Change-Id: Ifa2c541e774210f9625ec4cfa2951fea073a60aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4775980
Reviewed-by: Julian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: Roland Bock <rbock@google.com>
Commit-Queue: Longbo Wei <longbowei@google.com>
Reviewed-by: Jimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187332}
  • Loading branch information
Longbo Wei authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent f4c234d commit dcc3837
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ component("ash") {
"accelerators/accelerator_ids.h",
"accelerators/accelerator_notifications.cc",
"accelerators/accelerator_notifications.h",
"accelerators/accelerator_prefs.cc",
"accelerators/accelerator_prefs.h",
"accelerators/accelerator_table.cc",
"accelerators/accelerator_table.h",
"accelerators/accelerator_tracker.cc",
Expand Down
20 changes: 20 additions & 0 deletions ash/accelerators/accelerator_prefs.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/accelerators/accelerator_prefs.h"

#include "ash/constants/ash_pref_names.h"
#include "components/prefs/pref_registry_simple.h"

namespace ash {

AcceleratorPrefs::AcceleratorPrefs() = default;
AcceleratorPrefs::~AcceleratorPrefs() = default;

// static:
void AcceleratorPrefs::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kShortcutCustomizationAllowed, true);
}

} // namespace ash
27 changes: 27 additions & 0 deletions ash/accelerators/accelerator_prefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_ACCELERATORS_ACCELERATOR_PREFS_H_
#define ASH_ACCELERATORS_ACCELERATOR_PREFS_H_

#include "ash/ash_export.h"

class PrefRegistrySimple;

namespace ash {
// `AcceleratorPrefs` manages shortcut preference settings. It is used to
// register the prefs and observe the change in shortcut policy.
class ASH_EXPORT AcceleratorPrefs {
public:
AcceleratorPrefs();
AcceleratorPrefs(const AcceleratorPrefs&) = delete;
AcceleratorPrefs& operator=(const AcceleratorPrefs&) = delete;
~AcceleratorPrefs();

static void RegisterProfilePrefs(PrefRegistrySimple* registry);
};

} // namespace ash

#endif // ASH_ACCELERATORS_ACCELERATOR_PREFS_H_
2 changes: 2 additions & 0 deletions ash/ash_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

#include "ash/accelerators/accelerator_prefs.h"
#include "ash/accelerators/ash_accelerator_configuration.h"
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/accessibility/magnifier/docked_magnifier_controller.h"
Expand Down Expand Up @@ -94,6 +95,7 @@ namespace {
void RegisterProfilePrefs(PrefRegistrySimple* registry,
std::string_view country,
bool for_test) {
AcceleratorPrefs::RegisterProfilePrefs(registry);
AccessibilityControllerImpl::RegisterProfilePrefs(registry);
AppListControllerImpl::RegisterProfilePrefs(registry);
AppListNudgeController::RegisterProfilePrefs(registry);
Expand Down
5 changes: 5 additions & 0 deletions ash/constants/ash_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,11 @@ inline constexpr char kSixPackKeyInsertNotificationsRemaining[] =
inline constexpr char kHandsFreeProfileInputSuperResolution[] =
"ash.hands_free_profile_input_super_resolution";

// A boolean pref used by an admin policy to allow/disallow user to customize
// system shortcut. See the policy at ShortcutCustomizationAllowed.yaml.
inline constexpr char kShortcutCustomizationAllowed[] =
"ash.shortcut_customization_allowed";

// NOTE: New prefs should start with the "ash." prefix. Existing prefs moved
// into this file should not be renamed, since they may be synced.

Expand Down
6 changes: 6 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <utility>

#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/accelerators/accelerator_prefs.h"
#include "ash/accelerators/accelerator_tracker.h"
#include "ash/accelerators/ash_accelerator_configuration.h"
#include "ash/accelerators/ash_focus_manager_factory.h"
Expand Down Expand Up @@ -812,6 +813,8 @@ Shell::~Shell() {
// Must be destructed before human_presence_orientation_controller_.
power_prefs_.reset();

accelerator_prefs_.reset();

// Must be destructed before the tablet mode and message center controllers,
// both of which these rely on.
snooping_protection_controller_.reset();
Expand Down Expand Up @@ -1372,6 +1375,9 @@ void Shell::Init(
cursor_manager_->SetDisplay(
display::Screen::GetScreen()->GetPrimaryDisplay());

// Initialize before AcceleratorController and AshAcceleratorConfiguration.
accelerator_prefs_ = std::make_unique<AcceleratorPrefs>();

// Must be initialized after InputMethodManager.
accelerator_keycode_lookup_cache_ =
std::make_unique<AcceleratorKeycodeLookupCache>();
Expand Down
3 changes: 3 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace ash {

class AcceleratorControllerImpl;
class AcceleratorKeycodeLookupCache;
class AcceleratorPrefs;
class AcceleratorTracker;
class AccessibilityControllerImpl;
class AccessibilityDelegate;
Expand Down Expand Up @@ -394,6 +395,7 @@ class ASH_EXPORT Shell : public SessionObserver,
wm::AcceleratorFilter* accelerator_filter() {
return accelerator_filter_.get();
}
AcceleratorPrefs* accelerator_prefs() { return accelerator_prefs_.get(); }
AcceleratorTracker* accelerator_tracker() {
return accelerator_tracker_.get();
}
Expand Down Expand Up @@ -941,6 +943,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<AcceleratorControllerImpl> accelerator_controller_;
std::unique_ptr<AcceleratorKeycodeLookupCache>
accelerator_keycode_lookup_cache_;
std::unique_ptr<AcceleratorPrefs> accelerator_prefs_;
std::unique_ptr<AccessibilityControllerImpl> accessibility_controller_;
std::unique_ptr<AccessibilityDelegate> accessibility_delegate_;
std::unique_ptr<AccessibilityFocusRingControllerImpl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kPhysicalKeyboardPredictiveWriting,
ash::prefs::kManagedPhysicalKeyboardPredictiveWritingAllowed,
base::Value::Type::BOOLEAN },
{ key::kShortcutCustomizationAllowed,
ash::prefs::kShortcutCustomizationAllowed,
base::Value::Type::BOOLEAN },
{ key::kStickyKeysEnabled,
ash::prefs::kAccessibilityStickyKeysEnabled,
base::Value::Type::BOOLEAN },
Expand Down
1 change: 1 addition & 0 deletions components/policy/resources/templates/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ policies:
1144: CompressionDictionaryTransportEnabled
1145: MicrosoftOfficeCloudUpload
1146: GoogleWorkspaceCloudUpload
1147: ShortcutCustomizationAllowed
atomic_groups:
1: Homepage
2: RemoteAccess
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
caption: Allow customization of system shortcuts
desc: |-
This policy controls whether customization of system shortcuts is allowed.
When this policy is enabled or unset, users will be able to customize system shortcuts through the Key Shortcuts App.
When this policy is disabled, the Key Shortcuts app will be in read-only mode, disallowing any customization.
default: true
example_value: true
features:
dynamic_refresh: true
per_profile: false
owners:
- jimmyxgong@chromium.org
- zentaro@chromium.org
- cros-peripheral@google.com
items:
- caption: Allow the user to customize system shortcuts
value: true
- caption: Disallow the user to customize system shortcuts
value: false
schema:
type: boolean
future_on:
- chrome_os
tags: []
type: main
35 changes: 35 additions & 0 deletions components/policy/test/data/policy_test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -11021,6 +11021,41 @@
}
]
},
"ShortcutCustomizationAllowed": {
"os": [
"chromeos_ash"
],
"policy_pref_mapping_tests": [
{
"note": "Default value (no policies set).",
"prefs": {
"ash.shortcut_customization_allowed": {
"default_value": true
}
}
},
{
"policies": {
"ShortcutCustomizationAllowed": true
},
"prefs": {
"ash.shortcut_customization_allowed": {
"value": true
}
}
},
{
"policies": {
"ShortcutCustomizationAllowed": false
},
"prefs": {
"ash.shortcut_customization_allowed": {
"value": false
}
}
}
]
},
"VirtualKeyboardFeatures": {
"os": [
"chromeos_ash"
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33822,6 +33822,7 @@ Called by update_document_policy_enum.py.-->
<int value="1144" label="CompressionDictionaryTransportEnabled"/>
<int value="1145" label="MicrosoftOfficeCloudUpload"/>
<int value="1146" label="GoogleWorkspaceCloudUpload"/>
<int value="1147" label="ShortcutCustomizationAllowed"/>
</enum>

<enum name="EnterprisePoliciesSources">
Expand Down

0 comments on commit dcc3837

Please sign in to comment.