Add-flags-to-disable-device-motion-and-orientation-APIs.patch 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Mon, 22 Oct 2018 21:29:53 +0200
  3. Subject: Add flags to disable device motion and orientation APIs
  4. Both flags will be disabled by default and prevent usage of gyroscope and
  5. legacy acceleration events.
  6. ---
  7. chrome/browser/about_flags.cc | 6 ++++++
  8. chrome/browser/flag_descriptions.cc | 8 ++++++++
  9. chrome/browser/flag_descriptions.h | 6 ++++++
  10. content/child/runtime_features.cc | 3 +++
  11. content/public/common/content_features.cc | 10 ++++++++++
  12. content/public/common/content_features.h | 2 ++
  13. .../blink/public/platform/web_runtime_features.h | 2 ++
  14. .../blink/renderer/modules/modules_initializer.cc | 9 ++++++---
  15. .../renderer/platform/exported/web_runtime_features.cc | 8 ++++++++
  16. .../renderer/platform/runtime_enabled_features.json5 | 8 ++++++++
  17. 10 files changed, 59 insertions(+), 3 deletions(-)
  18. diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  19. --- a/chrome/browser/about_flags.cc
  20. +++ b/chrome/browser/about_flags.cc
  21. @@ -1992,6 +1992,12 @@ const FeatureEntry kFeatureEntries[] = {
  22. {"enable-gpu-rasterization", flag_descriptions::kGpuRasterizationName,
  23. flag_descriptions::kGpuRasterizationDescription, kOsAll,
  24. MULTI_VALUE_TYPE(kEnableGpuRasterizationChoices)},
  25. + {"enable-device-motion", flag_descriptions::kEnableDeviceMotionName,
  26. + flag_descriptions::kEnableDeviceMotionDescription, kOsAll,
  27. + FEATURE_VALUE_TYPE(features::kDeviceMotion)},
  28. + {"enable-device-orientation", flag_descriptions::kEnableDeviceOrientationName,
  29. + flag_descriptions::kEnableDeviceOrientationDescription, kOsAll,
  30. + FEATURE_VALUE_TYPE(features::kDeviceOrientation)},
  31. {"enable-oop-rasterization", flag_descriptions::kOopRasterizationName,
  32. flag_descriptions::kOopRasterizationDescription, kOsAll,
  33. MULTI_VALUE_TYPE(kEnableOopRasterizationChoices)},
  34. diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
  35. --- a/chrome/browser/flag_descriptions.cc
  36. +++ b/chrome/browser/flag_descriptions.cc
  37. @@ -596,6 +596,14 @@ const char kWinrtSensorsImplementationDescription[] =
  38. "Enables usage of the Windows.Devices.Sensors WinRT APIs on Windows for "
  39. "sensors";
  40. +const char kEnableDeviceMotionName[] = "Enable device motion";
  41. +const char kEnableDeviceMotionDescription[] =
  42. + "Enable device motion API which is used to detect changes in acceleration";
  43. +
  44. +const char kEnableDeviceOrientationName[] = "Enable device orientation";
  45. +const char kEnableDeviceOrientationDescription[] =
  46. + "Enable device orientation API which is used to detect changes in orientation";
  47. +
  48. const char kEnableGenericSensorExtraClassesName[] =
  49. "Generic Sensor Extra Classes";
  50. const char kEnableGenericSensorExtraClassesDescription[] =
  51. diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
  52. --- a/chrome/browser/flag_descriptions.h
  53. +++ b/chrome/browser/flag_descriptions.h
  54. @@ -362,6 +362,12 @@ extern const char kWinrtGeolocationImplementationDescription[];
  55. extern const char kWinrtSensorsImplementationName[];
  56. extern const char kWinrtSensorsImplementationDescription[];
  57. +extern const char kEnableDeviceMotionName[];
  58. +extern const char kEnableDeviceMotionDescription[];
  59. +
  60. +extern const char kEnableDeviceOrientationName[];
  61. +extern const char kEnableDeviceOrientationDescription[];
  62. +
  63. extern const char kEnableGenericSensorExtraClassesName[];
  64. extern const char kEnableGenericSensorExtraClassesDescription[];
  65. diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc
  66. --- a/content/child/runtime_features.cc
  67. +++ b/content/child/runtime_features.cc
  68. @@ -87,6 +87,9 @@ void SetRuntimeFeatureDefaultsForPlatform(
  69. command_line.HasSwitch(
  70. switches::kEnableGpuMemoryBufferCompositorResources) &&
  71. !command_line.HasSwitch(switches::kDisableWebGLImageChromium) &&
  72. + WebRuntimeFeatures::EnableDeviceMotion(base::FeatureList::IsEnabled(features::kDeviceMotion));
  73. + WebRuntimeFeatures::EnableDeviceOrientation(base::FeatureList::IsEnabled(features::kDeviceOrientation));
  74. +
  75. !command_line.HasSwitch(switches::kDisableGpu) &&
  76. base::FeatureList::IsEnabled(features::kWebGLImageChromium);
  77. #else
  78. diff --git a/content/public/common/content_features.cc b/content/public/common/content_features.cc
  79. --- a/content/public/common/content_features.cc
  80. +++ b/content/public/common/content_features.cc
  81. @@ -781,6 +781,16 @@ const base::Feature kWebOtpBackend{"kWebOtpBackend",
  82. // TODO(rouslan): Remove this.
  83. const base::Feature kWebPayments{"WebPayments",
  84. base::FEATURE_ENABLED_BY_DEFAULT};
  85. +// Enables the device motion API used to track device acceleration;
  86. +// no user authorization or notifications happens when in use.
  87. +const base::Feature kDeviceMotion{"DeviceMotion",
  88. + base::FEATURE_DISABLED_BY_DEFAULT};
  89. +
  90. +// Enables the device orientation API used to track device orientation;
  91. +// no user authorization or notifications happens when in use.
  92. +const base::Feature kDeviceOrientation{"DeviceOrientation",
  93. + base::FEATURE_DISABLED_BY_DEFAULT};
  94. +
  95. // Minimal user interface experience for payments on the web.
  96. const base::Feature kWebPaymentsMinimalUI{"WebPaymentsMinimalUI",
  97. diff --git a/content/public/common/content_features.h b/content/public/common/content_features.h
  98. --- a/content/public/common/content_features.h
  99. +++ b/content/public/common/content_features.h
  100. @@ -171,6 +171,8 @@ CONTENT_EXPORT extern const base::Feature kWebXrHitTest;
  101. CONTENT_EXPORT extern const base::Feature kWebXrIncubations;
  102. CONTENT_EXPORT extern const base::Feature kWebXrPermissionsApi;
  103. +CONTENT_EXPORT extern const base::Feature kDeviceMotion, kDeviceOrientation;
  104. +
  105. #if defined(OS_ANDROID)
  106. CONTENT_EXPORT extern const base::Feature kAndroidAutofillAccessibility;
  107. CONTENT_EXPORT extern const base::Feature
  108. diff --git a/third_party/blink/public/platform/web_runtime_features.h b/third_party/blink/public/platform/web_runtime_features.h
  109. --- a/third_party/blink/public/platform/web_runtime_features.h
  110. +++ b/third_party/blink/public/platform/web_runtime_features.h
  111. @@ -100,6 +100,8 @@ class WebRuntimeFeatures {
  112. BLINK_PLATFORM_EXPORT static void EnableCSSHexAlphaColor(bool);
  113. BLINK_PLATFORM_EXPORT static void EnableSameSiteByDefaultCookies(bool);
  114. BLINK_PLATFORM_EXPORT static void EnableScrollTopLeftInterop(bool);
  115. + BLINK_PLATFORM_EXPORT static void EnableDeviceMotion(bool);
  116. + BLINK_PLATFORM_EXPORT static void EnableDeviceOrientation(bool);
  117. BLINK_PLATFORM_EXPORT static void EnableKeyboardFocusableScrollers(bool);
  118. BLINK_PLATFORM_EXPORT static void EnableDatabase(bool);
  119. BLINK_PLATFORM_EXPORT static void EnableDecodeJpeg420ImagesToYUV(bool);
  120. diff --git a/third_party/blink/renderer/modules/modules_initializer.cc b/third_party/blink/renderer/modules/modules_initializer.cc
  121. --- a/third_party/blink/renderer/modules/modules_initializer.cc
  122. +++ b/third_party/blink/renderer/modules/modules_initializer.cc
  123. @@ -244,9 +244,12 @@ void ModulesInitializer::InitInspectorAgentSession(
  124. void ModulesInitializer::OnClearWindowObjectInMainWorld(
  125. Document& document,
  126. const Settings& settings) const {
  127. - DeviceMotionController::From(document);
  128. - DeviceOrientationController::From(document);
  129. - DeviceOrientationAbsoluteController::From(document);
  130. + if (RuntimeEnabledFeatures::DeviceMotionEnabled())
  131. + DeviceMotionController::From(document);
  132. + if (RuntimeEnabledFeatures::DeviceOrientationEnabled()) {
  133. + DeviceOrientationController::From(document);
  134. + DeviceOrientationAbsoluteController::From(document);
  135. + }
  136. NavigatorGamepad::From(document);
  137. NavigatorServiceWorker::From(document);
  138. DOMWindowStorageController::From(document);
  139. diff --git a/third_party/blink/renderer/platform/exported/web_runtime_features.cc b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  140. --- a/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  141. +++ b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  142. @@ -183,6 +183,14 @@ void WebRuntimeFeatures::EnableScrollTopLeftInterop(bool enable) {
  143. RuntimeEnabledFeatures::SetScrollTopLeftInteropEnabled(enable);
  144. }
  145. +void WebRuntimeFeatures::EnableDeviceMotion(bool enable) {
  146. + RuntimeEnabledFeatures::SetDeviceMotionEnabled(enable);
  147. +}
  148. +
  149. +void WebRuntimeFeatures::EnableDeviceOrientation(bool enable) {
  150. + RuntimeEnabledFeatures::SetDeviceOrientationEnabled(enable);
  151. +}
  152. +
  153. void WebRuntimeFeatures::EnableKeyboardFocusableScrollers(bool enable) {
  154. RuntimeEnabledFeatures::SetKeyboardFocusableScrollersEnabled(enable);
  155. }
  156. diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  157. --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
  158. +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  159. @@ -1202,6 +1202,14 @@
  160. name: "OffscreenCanvasCommit",
  161. status: "experimental",
  162. },
  163. + {
  164. + name: "DeviceMotion",
  165. + status: "stable",
  166. + },
  167. + {
  168. + name: "DeviceOrientation",
  169. + status: "stable",
  170. + },
  171. {
  172. name: "OnDeviceChange",
  173. // Android does not yet support SystemMonitor.
  174. --
  175. 2.17.1