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. 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. @@ -1593,6 +1593,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. @@ -644,6 +644,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. @@ -398,6 +398,12 @@ extern const char kEnableTLS13EarlyDataDescription[];
  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. @@ -84,6 +84,9 @@ void SetIndividualRuntimeFeatures(
  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. @@ -685,6 +685,16 @@ const base::Feature kExperimentalProductivityFeatures{
  80. // TODO(rouslan): Remove this.
  81. const base::Feature kWebPayments{"WebPayments",
  82. base::FEATURE_ENABLED_BY_DEFAULT};
  83. +// Enables the device motion API used to track device acceleration;
  84. +// no user authorization or notifications happens when in use.
  85. +const base::Feature kDeviceMotion{"DeviceMotion",
  86. + base::FEATURE_DISABLED_BY_DEFAULT};
  87. +
  88. +// Enables the device orientation API used to track device orientation;
  89. +// no user authorization or notifications happens when in use.
  90. +const base::Feature kDeviceOrientation{"DeviceOrientation",
  91. + base::FEATURE_DISABLED_BY_DEFAULT};
  92. +
  93. // Makes WebRTC use ECDSA certs by default (i.e., when no cert type was
  94. // specified in JS).
  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. @@ -157,6 +157,8 @@ CONTENT_EXPORT extern const base::Feature kScriptStreamingOnPreload;
  99. CONTENT_EXPORT extern const base::Feature kTrustedDOMTypes;
  100. CONTENT_EXPORT extern const base::Feature kBrowserUseDisplayThreadPriority;
  101. +CONTENT_EXPORT extern const base::Feature kDeviceMotion, kDeviceOrientation;
  102. +
  103. #if defined(OS_ANDROID)
  104. CONTENT_EXPORT extern const base::Feature kAndroidAutofillAccessibility;
  105. CONTENT_EXPORT extern const base::Feature
  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. @@ -91,6 +91,8 @@ class WebRuntimeFeatures {
  110. BLINK_PLATFORM_EXPORT static void EnableCSSHexAlphaColor(bool);
  111. BLINK_PLATFORM_EXPORT static void EnableSameSiteByDefaultCookies(bool);
  112. BLINK_PLATFORM_EXPORT static void EnableScrollTopLeftInterop(bool);
  113. + BLINK_PLATFORM_EXPORT static void EnableDeviceMotion(bool);
  114. + BLINK_PLATFORM_EXPORT static void EnableDeviceOrientation(bool);
  115. BLINK_PLATFORM_EXPORT static void EnableKeyboardFocusableScrollers(bool);
  116. BLINK_PLATFORM_EXPORT static void EnableDatabase(bool);
  117. BLINK_PLATFORM_EXPORT static void EnableDecodeJpeg420ImagesToYUV(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. @@ -244,9 +244,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::EnableScrollTopLeftInterop(bool enable) {
  141. RuntimeEnabledFeatures::SetScrollTopLeftInteropEnabled(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::EnableKeyboardFocusableScrollers(bool enable) {
  152. RuntimeEnabledFeatures::SetKeyboardFocusableScrollersEnabled(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. @@ -1119,6 +1119,14 @@
  158. status: "experimental",
  159. },
  160. {
  161. + name: "DeviceMotion",
  162. + status: "stable",
  163. + },
  164. + {
  165. + name: "DeviceOrientation",
  166. + status: "stable",
  167. + },
  168. + {
  169. name: "OnDeviceChange",
  170. // Android does not yet support SystemMonitor.
  171. status: {"Android": "", "default": "stable"},
  172. --
  173. 2.11.0