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

106 lines
4.8 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
---
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 ++++++
5 files changed, 25 insertions(+)
create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
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
@@ -246,6 +246,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
@@ -59,4 +59,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
@@ -17,6 +17,7 @@ GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(
GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kGamepadRawInputChangeEvent);
GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(
kClaimDuplicateGamepadsProductIdentifier);
+GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kRestrictGamepadAccess);
#if BUILDFLAG(IS_WIN)
GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kIgnorePS5GamepadsInWgi);
@@ -34,6 +35,7 @@ GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(
#endif // BUILDFLAG(IS_APPLE)
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/mojom/frame/user_activation_notification_type.mojom-blink.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_gamepad_mapping_type.h"
@@ -88,6 +89,9 @@ NavigatorGamepad& NavigatorGamepad::From(Navigator& navigator) {
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.
@@ -433,6 +437,8 @@ void NavigatorGamepad::MaybeDispatchGamepadEvents(
void NavigatorGamepad::DispatchGamepadConnectionChangedEvent(
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_);
--