Add-flag-to-disable-vibration.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sun, 27 Jun 2021 17:35:39 +0200
  3. Subject: Add flag to disable vibration
  4. ---
  5. chrome/browser/about_flags.cc | 4 ++++
  6. chrome/browser/flag_descriptions.cc | 3 +++
  7. chrome/browser/flag_descriptions.h | 3 +++
  8. content/child/runtime_features.cc | 1 +
  9. content/public/common/content_features.cc | 3 +++
  10. content/public/common/content_features.h | 2 ++
  11. third_party/blink/public/platform/web_runtime_features.h | 1 +
  12. .../blink/renderer/modules/vibration/vibration_controller.cc | 3 +++
  13. .../blink/renderer/platform/exported/web_runtime_features.cc | 4 ++++
  14. .../blink/renderer/platform/runtime_enabled_features.json5 | 4 ++++
  15. 10 files changed, 28 insertions(+)
  16. diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  17. --- a/chrome/browser/about_flags.cc
  18. +++ b/chrome/browser/about_flags.cc
  19. @@ -6412,6 +6412,10 @@ const FeatureEntry kFeatureEntries[] = {
  20. FEATURE_VALUE_TYPE(features::kNewMacNotificationAPI)},
  21. #endif
  22. + {"enable-vibration", flag_descriptions::kEnableVibrationName,
  23. + flag_descriptions::kEnableVibrationDescription, kOsAll,
  24. + FEATURE_VALUE_TYPE(features::kVibration)},
  25. +
  26. #if BUILDFLAG(IS_CHROMEOS_ASH)
  27. {"exo-gamepad-vibration", flag_descriptions::kExoGamepadVibrationName,
  28. flag_descriptions::kExoGamepadVibrationDescription, kOsCrOS,
  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. @@ -5242,6 +5242,9 @@ const char kDefaultMeetWebAppDescription[] =
  33. "Enables the Meet web app to be installed by default.";
  34. #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
  35. +const char kEnableVibrationName[] = "Vibration";
  36. +const char kEnableVibrationDescription[] = "Enable vibration API; an user gesture will still be needed.";
  37. +
  38. #if defined(OS_CHROMEOS)
  39. const char kDeprecateLowUsageCodecsName[] = "Deprecates low usage media codecs";
  40. const char kDeprecateLowUsageCodecsDescription[] =
  41. diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
  42. --- a/chrome/browser/flag_descriptions.h
  43. +++ b/chrome/browser/flag_descriptions.h
  44. @@ -3044,6 +3044,9 @@ extern const char kDefaultMeetWebAppName[];
  45. extern const char kDefaultMeetWebAppDescription[];
  46. #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
  47. +extern const char kEnableVibrationName[];
  48. +extern const char kEnableVibrationDescription[];
  49. +
  50. #if defined(OS_CHROMEOS)
  51. extern const char kDeprecateLowUsageCodecsName[];
  52. extern const char kDeprecateLowUsageCodecsDescription[];
  53. diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc
  54. --- a/content/child/runtime_features.cc
  55. +++ b/content/child/runtime_features.cc
  56. @@ -102,6 +102,7 @@ void SetRuntimeFeatureDefaultsForPlatform(
  57. #if defined(OS_ANDROID)
  58. if (command_line.HasSwitch(switches::kDisableMediaSessionAPI))
  59. WebRuntimeFeatures::EnableMediaSession(false);
  60. + WebRuntimeFeatures::EnableVibration(base::FeatureList::IsEnabled(features::kVibration));
  61. #endif
  62. #if defined(OS_ANDROID)
  63. diff --git a/content/public/common/content_features.cc b/content/public/common/content_features.cc
  64. --- a/content/public/common/content_features.cc
  65. +++ b/content/public/common/content_features.cc
  66. @@ -103,6 +103,9 @@ const base::Feature kBackForwardCacheSameSiteForBots{
  67. // BackForwardCacheMemoryControls is enabled only on Android to disable
  68. // BackForwardCache for lower memory devices due to memory limiations.
  69. +// Enables vibration; an user gesture will still be required if enabled.
  70. +const base::Feature kVibration{"Vibration",
  71. + base::FEATURE_DISABLED_BY_DEFAULT};
  72. const base::Feature kBackForwardCacheMemoryControls{
  73. "BackForwardCacheMemoryControls",
  74. diff --git a/content/public/common/content_features.h b/content/public/common/content_features.h
  75. --- a/content/public/common/content_features.h
  76. +++ b/content/public/common/content_features.h
  77. @@ -273,6 +273,8 @@ CONTENT_EXPORT extern const base::Feature kWarmUpNetworkProcess;
  78. CONTENT_EXPORT extern const base::Feature kWebNfc;
  79. #endif // defined(OS_ANDROID)
  80. +CONTENT_EXPORT extern const base::Feature kVibration;
  81. +
  82. #if defined(OS_MAC)
  83. CONTENT_EXPORT extern const base::Feature kDeviceMonitorMac;
  84. CONTENT_EXPORT extern const base::Feature kIOSurfaceCapturer;
  85. diff --git a/third_party/blink/public/platform/web_runtime_features.h b/third_party/blink/public/platform/web_runtime_features.h
  86. --- a/third_party/blink/public/platform/web_runtime_features.h
  87. +++ b/third_party/blink/public/platform/web_runtime_features.h
  88. @@ -90,6 +90,7 @@ class WebRuntimeFeatures {
  89. BLINK_PLATFORM_EXPORT static void EnableBlockingFocusWithoutUserActivation(
  90. bool);
  91. BLINK_PLATFORM_EXPORT static void EnableCacheInlineScriptCode(bool);
  92. + BLINK_PLATFORM_EXPORT static void EnableVibration(bool);
  93. BLINK_PLATFORM_EXPORT static void EnableCapabilityDelegationPaymentRequest(
  94. bool enable);
  95. BLINK_PLATFORM_EXPORT static void EnableClickPointerEvent(bool enable);
  96. diff --git a/third_party/blink/renderer/modules/vibration/vibration_controller.cc b/third_party/blink/renderer/modules/vibration/vibration_controller.cc
  97. --- a/third_party/blink/renderer/modules/vibration/vibration_controller.cc
  98. +++ b/third_party/blink/renderer/modules/vibration/vibration_controller.cc
  99. @@ -30,6 +30,7 @@
  100. #include "third_party/blink/renderer/core/frame/navigator.h"
  101. #include "third_party/blink/renderer/core/page/page.h"
  102. #include "third_party/blink/renderer/platform/mojo/mojo_helper.h"
  103. +#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
  104. // Maximum number of entries in a vibration pattern.
  105. const unsigned kVibrationPatternLengthMax = 99;
  106. @@ -149,6 +150,8 @@ bool VibrationController::vibrate(Navigator& navigator,
  107. // reference to |window| or |navigator| was retained in another window.
  108. if (!navigator.DomWindow())
  109. return false;
  110. + if (!RuntimeEnabledFeatures::VibrationEnabled())
  111. + return false;
  112. return From(navigator).Vibrate(pattern);
  113. }
  114. diff --git a/third_party/blink/renderer/platform/exported/web_runtime_features.cc b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  115. --- a/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  116. +++ b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  117. @@ -182,6 +182,10 @@ void WebRuntimeFeatures::EnableScrollTopLeftInterop(bool enable) {
  118. RuntimeEnabledFeatures::SetScrollTopLeftInteropEnabled(enable);
  119. }
  120. +void WebRuntimeFeatures::EnableVibration(bool enable) {
  121. + RuntimeEnabledFeatures::SetVibrationEnabled(enable);
  122. +}
  123. +
  124. void WebRuntimeFeatures::EnableKeyboardAccessibleTooltip(bool enable) {
  125. RuntimeEnabledFeatures::SetKeyboardAccessibleTooltipEnabled(enable);
  126. }
  127. diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  128. --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
  129. +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  130. @@ -1575,6 +1575,10 @@
  131. name: "OrientationEvent",
  132. status: {"Android": "stable"},
  133. },
  134. + {
  135. + name: "Vibration",
  136. + status: "stable",
  137. + },
  138. {
  139. name: "OriginIsolationHeader",
  140. status: "stable",
  141. --
  142. 2.20.1