From: csagan5 <32685696+csagan5@users.noreply.github.com> Date: Sun, 27 Jun 2021 17:35:39 +0200 Subject: Add flag to disable vibration License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html --- content/child/runtime_features.cc | 1 + .../about_flags_cc/Add-flag-to-disable-vibration.inc | 8 ++++++++ .../content_features_cc/Add-flag-to-disable-vibration.inc | 4 ++++ .../content_features_h/Add-flag-to-disable-vibration.inc | 1 + third_party/blink/public/platform/web_runtime_features.h | 1 + .../renderer/modules/vibration/vibration_controller.cc | 3 +++ .../renderer/platform/exported/web_runtime_features.cc | 4 ++++ .../renderer/platform/runtime_enabled_features.json5 | 4 ++++ 8 files changed, 26 insertions(+) create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Add-flag-to-disable-vibration.inc create mode 100644 cromite_flags/content/public/common/content_features_cc/Add-flag-to-disable-vibration.inc create mode 100644 cromite_flags/content/public/common/content_features_h/Add-flag-to-disable-vibration.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 @@ -82,6 +82,7 @@ void SetRuntimeFeatureDefaultsForPlatform( if (command_line.HasSwitch(switches::kDisableMediaSessionAPI)) { WebRuntimeFeatures::EnableMediaSession(false); } + WebRuntimeFeatures::EnableVibration(base::FeatureList::IsEnabled(features::kVibration)); #endif #if BUILDFLAG(IS_ANDROID) diff --git a/cromite_flags/chrome/browser/about_flags_cc/Add-flag-to-disable-vibration.inc b/cromite_flags/chrome/browser/about_flags_cc/Add-flag-to-disable-vibration.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/chrome/browser/about_flags_cc/Add-flag-to-disable-vibration.inc @@ -0,0 +1,8 @@ +#ifdef FLAG_SECTION + + {"enable-vibration", + "Vibration", + "Enable vibration API; an user gesture will still be needed.", kOsAll, + FEATURE_VALUE_TYPE(features::kVibration)}, + +#endif diff --git a/cromite_flags/content/public/common/content_features_cc/Add-flag-to-disable-vibration.inc b/cromite_flags/content/public/common/content_features_cc/Add-flag-to-disable-vibration.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/content/public/common/content_features_cc/Add-flag-to-disable-vibration.inc @@ -0,0 +1,4 @@ +// Enables vibration; an user gesture will still be required if enabled. +CROMITE_FEATURE(kVibration, + "VibrationEnabled", + base::FEATURE_DISABLED_BY_DEFAULT); diff --git a/cromite_flags/content/public/common/content_features_h/Add-flag-to-disable-vibration.inc b/cromite_flags/content/public/common/content_features_h/Add-flag-to-disable-vibration.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/content/public/common/content_features_h/Add-flag-to-disable-vibration.inc @@ -0,0 +1 @@ +CONTENT_EXPORT BASE_DECLARE_FEATURE(kVibration); diff --git a/third_party/blink/public/platform/web_runtime_features.h b/third_party/blink/public/platform/web_runtime_features.h --- a/third_party/blink/public/platform/web_runtime_features.h +++ b/third_party/blink/public/platform/web_runtime_features.h @@ -70,6 +70,7 @@ class BLINK_PLATFORM_EXPORT WebRuntimeFeatures : public WebRuntimeFeaturesBase { static void EnableFingerprintingCanvasImageDataNoise(bool); static void EnableFluentScrollbars(bool); static void EnableDesktopAndroidScrollbars(bool); + static void EnableVibration(bool); static void EnableLocalNetworkAccessWebRTC(bool); diff --git a/third_party/blink/renderer/modules/vibration/vibration_controller.cc b/third_party/blink/renderer/modules/vibration/vibration_controller.cc --- a/third_party/blink/renderer/modules/vibration/vibration_controller.cc +++ b/third_party/blink/renderer/modules/vibration/vibration_controller.cc @@ -28,6 +28,7 @@ #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/navigator.h" #include "third_party/blink/renderer/core/page/page.h" +#include "third_party/blink/renderer/platform/runtime_enabled_features.h" // Maximum number of entries in a vibration pattern. const unsigned kVibrationPatternLengthMax = 99; @@ -108,6 +109,8 @@ bool VibrationController::vibrate(Navigator& navigator, // reference to |window| or |navigator| was retained in another window. if (!navigator.DomWindow()) return false; + if (!RuntimeEnabledFeatures::VibrationEnabled()) + return false; return From(navigator).Vibrate(pattern); } diff --git a/third_party/blink/renderer/platform/exported/web_runtime_features.cc b/third_party/blink/renderer/platform/exported/web_runtime_features.cc --- a/third_party/blink/renderer/platform/exported/web_runtime_features.cc +++ b/third_party/blink/renderer/platform/exported/web_runtime_features.cc @@ -52,6 +52,10 @@ void WebRuntimeFeatures::EnableTestOnlyFeatures(bool enable) { RuntimeEnabledFeatures::SetTestFeaturesEnabled(enable); } +void WebRuntimeFeatures::EnableVibration(bool enable) { + RuntimeEnabledFeatures::SetVibrationEnabled(enable); +} + void WebRuntimeFeatures::EnableOriginTrialControlledFeatures(bool enable) { RuntimeEnabledFeatures::SetOriginTrialControlledFeaturesEnabled(enable); } diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5 --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5 +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5 @@ -1242,6 +1242,10 @@ { name: "CompositingDecisionAtAnimationPhaseBoundaries" }, + { + name: "Vibration", + status: "stable", + }, { name: "CompositionForegroundMarkers", status: { --