Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 608690e1 authored by Carmelo Messina's avatar Carmelo Messina
Browse files

Add a flag to disable GamePad API: Returns an empty list of devices without...

Add a flag to disable GamePad API: Returns an empty list of devices without generating javascript exceptions (#1948)
parent 823a8fd1
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
 .../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   | 7 +++++++
 6 files changed, 28 insertions(+), 2 deletions(-)
 .../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
@@ -94,18 +94,17 @@ diff --git a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc b/t
 #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,10 @@ void RecordGamepadsForIdentifiabilityStudy(
@@ -114,6 +115,9 @@ void RecordGamepadsForIdentifiabilityStudy(
 HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(
     Navigator& navigator,
     ExceptionState& exception_state) {
+  if (::features::IsRestrictGamepadAccessEnabled()) {
+    exception_state.ThrowSecurityError("Access to the feature \"gamepad\" is denied");
+    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 +425,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() {
@@ -420,6 +424,8 @@ void NavigatorGamepad::SampleAndCompareGamepadState() {
 
 void NavigatorGamepad::DispatchGamepadEvent(const AtomicString& event_name,
                                             Gamepad* gamepad) {