Files
cromite/build/patches/Add-a-flag-to-disable-GamePad-API.patch
T

117 lines
5.2 KiB
Diff

From: uazo <uazo@users.noreply.github.com>
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 ++--
content/child/runtime_features.cc | 2 ++
.../about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc | 7 +++++++
device/gamepad/public/cpp/gamepad_features.cc | 8 ++++++++
device/gamepad/public/cpp/gamepad_features.h | 2 ++
.../blink/renderer/modules/gamepad/navigator_gamepad.cc | 6 ++++++
6 files changed, 27 insertions(+), 2 deletions(-)
create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
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
@@ -8364,9 +8364,9 @@
"expiry_milestone": 140
},
{
- "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": "retain-omnibox-on-focus",
diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc
--- a/content/child/runtime_features.cc
+++ b/content/child/runtime_features.cc
@@ -253,6 +253,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
{wf::EnablePaymentApp, raw_ref(features::kServiceWorkerPaymentApps)},
{wf::EnablePeriodicBackgroundSync,
raw_ref(features::kPeriodicBackgroundSync)},
+ {wf::EnableRestrictGamepadAccess,
+ raw_ref(features::kRestrictGamepadAccess)},
{wf::EnableSecurePaymentConfirmation,
raw_ref(features::kSecurePaymentConfirmation)},
{wf::EnableSecurePaymentConfirmationDebug,
diff --git a/cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc b/cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
@@ -0,0 +1,7 @@
+#ifdef FLAG_SECTION
+
+ {"restrict-gamepad-access", "Restrict gamepad access",
+ "Disable the Gamepad API", kOsAll,
+ FEATURE_VALUE_TYPE(features::kRestrictGamepadAccess)},
+
+#endif
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
@@ -36,4 +36,12 @@ bool IsGamepadMultitouchEnabled() {
return false;
}
+CROMITE_FEATURE(kRestrictGamepadAccess,
+ "RestrictGamepadAccess",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+
+bool IsRestrictGamepadAccessEnabled() {
+ return base::FeatureList::IsEnabled(kRestrictGamepadAccess);
+}
+
} // namespace features
diff --git a/device/gamepad/public/cpp/gamepad_features.h b/device/gamepad/public/cpp/gamepad_features.h
--- a/device/gamepad/public/cpp/gamepad_features.h
+++ b/device/gamepad/public/cpp/gamepad_features.h
@@ -13,8 +13,10 @@ namespace features {
GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(
kEnableWindowsGamingInputDataFetcher);
GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kEnableGamepadMultitouch);
+GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kRestrictGamepadAccess);
GAMEPAD_FEATURES_EXPORT bool IsGamepadMultitouchEnabled();
+GAMEPAD_FEATURES_EXPORT bool IsRestrictGamepadAccessEnabled();
} // 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
@@ -27,6 +27,7 @@
#include "base/auto_reset.h"
#include "device/gamepad/public/cpp/gamepads.h"
+#include "device/gamepad/public/cpp/gamepad_features.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-blink.h"
@@ -114,6 +115,9 @@ void RecordGamepadsForIdentifiabilityStudy(
HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(
Navigator& navigator,
ExceptionState& exception_state) {
+ if (::features::IsRestrictGamepadAccessEnabled()) {
+ return HeapVector<Member<Gamepad>>();
+ }
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.
@@ -420,6 +424,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() {
void NavigatorGamepad::DispatchGamepadEvent(const AtomicString& event_name,
Gamepad* gamepad) {
+ if (::features::IsRestrictGamepadAccessEnabled())
+ return;
// Ensure that we're blocking re-entrancy.
DCHECK(processing_events_);
DCHECK(has_connection_event_listener_);
--