@@ -5,16 +5,19 @@ Subject: Add a flag to disable GamePad API
5
5
Adds restrict-gamepad-access flag (default active) to disable GamePad API.
6
6
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
7
7
---
8
- chrome/browser/flag-metadata.json | 4 ++--
9
- chrome/browser/flag_descriptions.cc | 2 +-
10
- device/gamepad/public/cpp/gamepad_features.cc | 1 +
11
- .../blink/renderer/modules/gamepad/navigator_gamepad.cc | 6 ++++++
12
- 4 files changed, 10 insertions(+), 3 deletions(-)
8
+ chrome/browser/flag-metadata.json | 4 ++--
9
+ content/child/runtime_features.cc | 2 ++
10
+ .../about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc | 7 +++++++
11
+ device/gamepad/public/cpp/gamepad_features.cc | 8 ++++++++
12
+ device/gamepad/public/cpp/gamepad_features.h | 2 ++
13
+ .../blink/renderer/modules/gamepad/navigator_gamepad.cc | 7 +++++++
14
+ 6 files changed, 28 insertions(+), 2 deletions(-)
15
+ create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
13
16
14
17
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
15
18
--- a/chrome/browser/flag-metadata.json
16
19
+++ b/chrome/browser/flag-metadata.json
17
- @@ -7807 ,9 +7807 ,9 @@
20
+ @@ -7726 ,9 +7726 ,9 @@
18
21
"expiry_milestone" : 130
19
22
},
20
23
{
@@ -26,46 +29,87 @@ diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.js
26
29
},
27
30
{
28
31
"name": "retain-omnibox-on-focus",
29
- diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
30
- --- a/chrome/browser/flag_descriptions.cc
31
- +++ b/chrome/browser/flag_descriptions.cc
32
- @@ -3331,7 +3331,7 @@ const char kResetShortcutCustomizationsDescription[] =
33
-
34
- const char kRestrictGamepadAccessName[] = "Restrict gamepad access";
35
- const char kRestrictGamepadAccessDescription[] =
36
- - "Enables Permissions Policy and Secure Context restrictions on the Gamepad "
37
- + "Disable the Gamepad "
38
- "API";
39
-
40
- #if BUILDFLAG(IS_ANDROID)
32
+ diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc
33
+ --- a/content/child/runtime_features.cc
34
+ +++ b/content/child/runtime_features.cc
35
+ @@ -271,6 +271,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
36
+ raw_ref(features::kPeriodicBackgroundSync)},
37
+ {wf::EnablePushMessagingSubscriptionChange,
38
+ raw_ref(features::kPushSubscriptionChangeEvent)},
39
+ + {wf::EnableRestrictGamepadAccess,
40
+ + raw_ref(features::kRestrictGamepadAccess)},
41
+ {wf::EnableSecurePaymentConfirmation,
42
+ raw_ref(features::kSecurePaymentConfirmation)},
43
+ {wf::EnableSecurePaymentConfirmationDebug,
44
+ 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
45
+ new file mode 100644
46
+ --- /dev/null
47
+ +++ b/cromite_flags/chrome/browser/about_flags_cc/Add-a-flag-to-disable-GamePad-API.inc
48
+ @@ -0,0 +1,7 @@
49
+ + #ifdef FLAG_SECTION
50
+ +
51
+ + {"restrict-gamepad-access", "Restrict gamepad access",
52
+ + "Disable the Gamepad API", kOsAll,
53
+ + FEATURE_VALUE_TYPE(features::kRestrictGamepadAccess)},
54
+ +
55
+ + #endif
41
56
diff --git a/device/gamepad/public/cpp/gamepad_features.cc b/device/gamepad/public/cpp/gamepad_features.cc
42
57
--- a/device/gamepad/public/cpp/gamepad_features.cc
43
58
+++ b/device/gamepad/public/cpp/gamepad_features.cc
44
- @@ -64 ,4 +64,5 @@ bool IsGamepadMultitouchEnabled() {
59
+ @@ -27 ,4 +27,12 @@ bool IsGamepadMultitouchEnabled() {
45
60
return false;
46
61
}
47
62
48
- + SET_CROMITE_FEATURE_ENABLED(kRestrictGamepadAccess);
63
+ + CROMITE_FEATURE(kRestrictGamepadAccess,
64
+ + "RestrictGamepadAccess",
65
+ + base::FEATURE_ENABLED_BY_DEFAULT);
66
+ +
67
+ + bool IsRestrictGamepadAccessEnabled() {
68
+ + return base::FeatureList::IsEnabled(kRestrictGamepadAccess);
69
+ + }
70
+ +
71
+ } // namespace features
72
+ diff --git a/device/gamepad/public/cpp/gamepad_features.h b/device/gamepad/public/cpp/gamepad_features.h
73
+ --- a/device/gamepad/public/cpp/gamepad_features.h
74
+ +++ b/device/gamepad/public/cpp/gamepad_features.h
75
+ @@ -11,8 +11,10 @@
76
+ namespace features {
77
+
78
+ GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kEnableGamepadMultitouch);
79
+ + GAMEPAD_FEATURES_EXPORT BASE_DECLARE_FEATURE(kRestrictGamepadAccess);
80
+
81
+ GAMEPAD_FEATURES_EXPORT bool IsGamepadMultitouchEnabled();
82
+ + GAMEPAD_FEATURES_EXPORT bool IsRestrictGamepadAccessEnabled();
83
+
49
84
} // namespace features
85
+
50
86
diff --git a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc
51
87
--- a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc
52
88
+++ b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc
53
- @@ -120,6 +120,10 @@ void RecordGamepadsForIdentifiabilityStudy(
89
+ @@ -27,6 +27,7 @@
90
+
91
+ #include "base/auto_reset.h"
92
+ #include "device/gamepad/public/cpp/gamepads.h"
93
+ + #include "device/gamepad/public/cpp/gamepad_features.h"
94
+ #include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
95
+ #include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
96
+ #include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-blink.h"
97
+ @@ -112,6 +113,10 @@ void RecordGamepadsForIdentifiabilityStudy(
54
98
HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(
55
99
Navigator& navigator,
56
100
ExceptionState& exception_state) {
57
- + if (base::FeatureList::IsEnabled(:: features::kRestrictGamepadAccess )) {
101
+ + if (:: features::IsRestrictGamepadAccessEnabled( )) {
58
102
+ exception_state.ThrowSecurityError("Access to the feature \"gamepad\" is denied");
59
103
+ return HeapVector<Member<Gamepad>>();
60
104
+ }
61
105
if (!navigator.DomWindow()) {
62
106
// Using an existing NavigatorGamepad if one exists, but don't create one
63
107
// for a detached window, as its subclasses depend on a non-null window.
64
- @@ -442 ,6 +446 ,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() {
108
+ @@ -418 ,6 +423 ,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() {
65
109
66
110
void NavigatorGamepad::DispatchGamepadEvent(const AtomicString& event_name,
67
111
Gamepad* gamepad) {
68
- + if (base::FeatureList::IsEnabled(:: features::kRestrictGamepadAccess ))
112
+ + if (:: features::IsRestrictGamepadAccessEnabled( ))
69
113
+ return;
70
114
// Ensure that we're blocking re-entrancy.
71
115
DCHECK(processing_events_);
0 commit comments