Add-flags-to-disable-device-motion-and-orientation-APIs.patch 9.1 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. third_party/blink/public/platform/web_runtime_features.h | 2 ++
  14. third_party/blink/renderer/modules/modules_initializer.cc | 9 ++++++---
  15. .../blink/renderer/platform/exported/web_runtime_features.cc | 8 ++++++++
  16. .../blink/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. @@ -2770,6 +2770,12 @@ const FeatureEntry kFeatureEntries[] = {
  22. {"enable-generic-sensor", flag_descriptions::kEnableGenericSensorName,
  23. flag_descriptions::kEnableGenericSensorDescription, kOsAll,
  24. FEATURE_VALUE_TYPE(features::kGenericSensor)},
  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-generic-sensor-extra-classes",
  32. flag_descriptions::kEnableGenericSensorExtraClassesName,
  33. flag_descriptions::kEnableGenericSensorExtraClassesDescription, kOsAll,
  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. @@ -599,6 +599,14 @@ const char kEnableGenericSensorDescription[] =
  38. "Accelerometer, LinearAccelerationSensor, Gyroscope, "
  39. "AbsoluteOrientationSensor and RelativeOrientationSensor interfaces.";
  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. @@ -391,6 +391,12 @@ extern const char kEnableEnumeratingAudioDevicesDescription[];
  55. extern const char kEnableGenericSensorName[];
  56. extern const char kEnableGenericSensorDescription[];
  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. @@ -144,6 +144,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
  69. base::FeatureList::IsEnabled(features::kSharedArrayBuffer) ||
  70. base::FeatureList::IsEnabled(features::kWebAssemblyThreads));
  71. + WebRuntimeFeatures::EnableDeviceMotion(base::FeatureList::IsEnabled(features::kDeviceMotion));
  72. + WebRuntimeFeatures::EnableDeviceOrientation(base::FeatureList::IsEnabled(features::kDeviceOrientation));
  73. +
  74. if (command_line.HasSwitch(switches::kDisableSharedWorkers))
  75. WebRuntimeFeatures::EnableSharedWorker(false);
  76. diff --git a/content/public/common/content_features.cc b/content/public/common/content_features.cc
  77. --- a/content/public/common/content_features.cc
  78. +++ b/content/public/common/content_features.cc
  79. @@ -596,6 +596,16 @@ const base::Feature kWebRtcHideLocalIpsWithMdns{
  80. // https://wicg.github.io/webusb
  81. const base::Feature kWebUsb{"WebUSB", base::FEATURE_ENABLED_BY_DEFAULT};
  82. +// Enables the device motion API used to track device acceleration;
  83. +// no user authorization or notifications happens when in use.
  84. +const base::Feature kDeviceMotion{"DeviceMotion",
  85. + base::FEATURE_DISABLED_BY_DEFAULT};
  86. +
  87. +// Enables the device orientation API used to track device orientation;
  88. +// no user authorization or notifications happens when in use.
  89. +const base::Feature kDeviceOrientation{"DeviceOrientation",
  90. + base::FEATURE_DISABLED_BY_DEFAULT};
  91. +
  92. // Controls whether WebVR VSync-aligned render loop timing is enabled.
  93. const base::Feature kWebVrVsyncAlign{"WebVrVsyncAlign",
  94. base::FEATURE_ENABLED_BY_DEFAULT};
  95. diff --git a/content/public/common/content_features.h b/content/public/common/content_features.h
  96. --- a/content/public/common/content_features.h
  97. +++ b/content/public/common/content_features.h
  98. @@ -155,6 +155,8 @@ CONTENT_EXPORT extern const char kWebXrRenderPathParamValueGpuFence[];
  99. CONTENT_EXPORT extern const char kWebXrRenderPathParamValueSharedBuffer[];
  100. #endif // defined(OS_ANDROID)
  101. +CONTENT_EXPORT extern const base::Feature kDeviceMotion, kDeviceOrientation;
  102. +
  103. #if !defined(OS_ANDROID)
  104. CONTENT_EXPORT extern const base::Feature kWebUIPolymer2;
  105. #endif // !defined(OS_ANDROID)
  106. diff --git a/third_party/blink/public/platform/web_runtime_features.h b/third_party/blink/public/platform/web_runtime_features.h
  107. --- a/third_party/blink/public/platform/web_runtime_features.h
  108. +++ b/third_party/blink/public/platform/web_runtime_features.h
  109. @@ -95,6 +95,8 @@ class WebRuntimeFeatures {
  110. BLINK_PLATFORM_EXPORT static void EnableScrollTopLeftInterop(bool);
  111. BLINK_PLATFORM_EXPORT static void EnableKeyboardFocusableScrollers(bool);
  112. BLINK_PLATFORM_EXPORT static void EnableDatabase(bool);
  113. + BLINK_PLATFORM_EXPORT static void EnableDeviceMotion(bool);
  114. + BLINK_PLATFORM_EXPORT static void EnableDeviceOrientation(bool);
  115. BLINK_PLATFORM_EXPORT static void EnableDecodeToYUV(bool);
  116. BLINK_PLATFORM_EXPORT static void EnableDisplayCutoutAPI(bool);
  117. BLINK_PLATFORM_EXPORT static void EnableFastMobileScrolling(bool);
  118. diff --git a/third_party/blink/renderer/modules/modules_initializer.cc b/third_party/blink/renderer/modules/modules_initializer.cc
  119. --- a/third_party/blink/renderer/modules/modules_initializer.cc
  120. +++ b/third_party/blink/renderer/modules/modules_initializer.cc
  121. @@ -233,9 +233,12 @@ void ModulesInitializer::InitInspectorAgentSession(
  122. void ModulesInitializer::OnClearWindowObjectInMainWorld(
  123. Document& document,
  124. const Settings& settings) const {
  125. - DeviceMotionController::From(document);
  126. - DeviceOrientationController::From(document);
  127. - DeviceOrientationAbsoluteController::From(document);
  128. + if (RuntimeEnabledFeatures::DeviceMotionEnabled())
  129. + DeviceMotionController::From(document);
  130. + if (RuntimeEnabledFeatures::DeviceOrientationEnabled()) {
  131. + DeviceOrientationController::From(document);
  132. + DeviceOrientationAbsoluteController::From(document);
  133. + }
  134. NavigatorGamepad::From(document);
  135. NavigatorServiceWorker::From(document);
  136. DOMWindowStorageController::From(document);
  137. diff --git a/third_party/blink/renderer/platform/exported/web_runtime_features.cc b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  138. --- a/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  139. +++ b/third_party/blink/renderer/platform/exported/web_runtime_features.cc
  140. @@ -160,6 +160,14 @@ void WebRuntimeFeatures::EnableDatabase(bool enable) {
  141. RuntimeEnabledFeatures::SetDatabaseEnabled(enable);
  142. }
  143. +void WebRuntimeFeatures::EnableDeviceMotion(bool enable) {
  144. + RuntimeEnabledFeatures::SetDeviceMotionEnabled(enable);
  145. +}
  146. +
  147. +void WebRuntimeFeatures::EnableDeviceOrientation(bool enable) {
  148. + RuntimeEnabledFeatures::SetDeviceOrientationEnabled(enable);
  149. +}
  150. +
  151. void WebRuntimeFeatures::EnableDecodeToYUV(bool enable) {
  152. RuntimeEnabledFeatures::SetDecodeToYUVEnabled(enable);
  153. }
  154. diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  155. --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
  156. +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
  157. @@ -374,6 +374,14 @@
  158. status: "stable",
  159. },
  160. {
  161. + name: "DeviceMotion",
  162. + status: "stable",
  163. + },
  164. + {
  165. + name: "DeviceOrientation",
  166. + status: "stable",
  167. + },
  168. + {
  169. name: "DecodeToYUV",
  170. status: "experimental",
  171. },
  172. --
  173. 2.11.0