From: uazo Date: Fri, 21 Apr 2023 13:10:20 +0000 Subject: Add a flag to disable GamePad API Adds restrict-gamepad-access flag (default active) to disable GamePad API. License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html --- chrome/browser/flag-metadata.json | 4 ++-- chrome/browser/flag_descriptions.cc | 2 +- device/gamepad/public/cpp/gamepad_features.cc | 1 + .../blink/renderer/modules/gamepad/navigator_gamepad.cc | 6 ++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json --- a/chrome/browser/flag-metadata.json +++ b/chrome/browser/flag-metadata.json @@ -7195,9 +7195,9 @@ "expiry_milestone": 125 }, { - "name": "restrict-gamepad-access", + "name": "restrict-gamepad-access", // restrict-gamepad-access" "owners": [ "//device/gamepad/OWNERS", "jameshollyer@chromium.org" ], - "expiry_milestone": 96 + "expiry_milestone": -1 }, { "name": "revamp-page-info-ios", diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc --- a/chrome/browser/flag_descriptions.cc +++ b/chrome/browser/flag_descriptions.cc @@ -3089,7 +3089,7 @@ const char kResetShortcutCustomizationsDescription[] = const char kRestrictGamepadAccessName[] = "Restrict gamepad access"; const char kRestrictGamepadAccessDescription[] = - "Enables Permissions Policy and Secure Context restrictions on the Gamepad " + "Disable the Gamepad " "API"; const char kRoundedDisplay[] = "Rounded display"; diff --git a/device/gamepad/public/cpp/gamepad_features.cc b/device/gamepad/public/cpp/gamepad_features.cc --- a/device/gamepad/public/cpp/gamepad_features.cc +++ b/device/gamepad/public/cpp/gamepad_features.cc @@ -65,4 +65,5 @@ bool IsGamepadMultitouchEnabled() { return false; } +SET_CROMITE_FEATURE_ENABLED(kRestrictGamepadAccess); } // namespace features diff --git a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc --- a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc +++ b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc @@ -113,6 +113,10 @@ void RecordGamepadsForIdentifiabilityStudy( HeapVector> NavigatorGamepad::getGamepads( Navigator& navigator, ExceptionState& exception_state) { + if (base::FeatureList::IsEnabled(::features::kRestrictGamepadAccess)) { + exception_state.ThrowSecurityError("Access to the feature \"gamepad\" is denied"); + return HeapVector>(); + } if (!navigator.DomWindow()) { // Using an existing NavigatorGamepad if one exists, but don't create one // for a detached window, as its subclasses depend on a non-null window. @@ -435,6 +439,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() { void NavigatorGamepad::DispatchGamepadEvent(const AtomicString& event_name, Gamepad* gamepad) { + if (base::FeatureList::IsEnabled(::features::kRestrictGamepadAccess)) + return; // Ensure that we're blocking re-entrancy. DCHECK(processing_events_); DCHECK(has_connection_event_listener_); --