Bug 1352410 - Add a preference to enable or disable haptic feedback for gamepads; r=Lenzak
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 27 Jul 2017 17:55:16 +0800
changeset 420132 a5e025d29c794fde8d3556ecd92ba3e9a2104d4f
parent 420131 0400aea3c9ce9fde2681598ebc108d0554f33d67
child 420133 eeb8b3ad1b548d635b63bc0af9cb805af192604b
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersLenzak
bugs1352410
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1352410 - Add a preference to enable or disable haptic feedback for gamepads; r=Lenzak MozReview-Commit-ID: 70FFdcd3n5q
dom/gamepad/GamepadManager.cpp
modules/libpref/init/all.js
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -636,47 +636,54 @@ GamepadManager::SetGamepadByEvent(const 
   return ret;
 }
 
 already_AddRefed<Promise>
 GamepadManager::VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
                               double aIntensity, double aDuration,
                               nsIGlobalObject* aGlobal, ErrorResult& aRv)
 {
+  const char* kGamepadHapticEnabledPref = "dom.gamepad.haptic_feedback.enabled";
   RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
-
-  if (aControllerIdx >= VR_GAMEPAD_IDX_OFFSET) {
-    if (gfx::VRManagerChild::IsCreated()) {
-      const uint32_t index = aControllerIdx - VR_GAMEPAD_IDX_OFFSET;
-      gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
-      vm->AddPromise(mPromiseID, promise);
-      vm->SendVibrateHaptic(index, aHapticIndex,
-                            aIntensity, aDuration,
-                            mPromiseID);
-    }
-  } else {
-    for (const auto& channelChild: mChannelChildren) {
-      channelChild->AddPromise(mPromiseID, promise);
-      channelChild->SendVibrateHaptic(aControllerIdx, aHapticIndex,
-                                      aIntensity, aDuration,
-                                      mPromiseID);
+  if (Preferences::GetBool(kGamepadHapticEnabledPref)) {
+    if (aControllerIdx >= VR_GAMEPAD_IDX_OFFSET) {
+      if (gfx::VRManagerChild::IsCreated()) {
+        const uint32_t index = aControllerIdx - VR_GAMEPAD_IDX_OFFSET;
+        gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+        vm->AddPromise(mPromiseID, promise);
+        vm->SendVibrateHaptic(index, aHapticIndex,
+                              aIntensity, aDuration,
+                              mPromiseID);
+      }
+    } else {
+      for (const auto& channelChild: mChannelChildren) {
+        channelChild->AddPromise(mPromiseID, promise);
+        channelChild->SendVibrateHaptic(aControllerIdx, aHapticIndex,
+                                        aIntensity, aDuration,
+                                        mPromiseID);
+      }
     }
   }
 
   ++mPromiseID;
   return promise.forget();
 }
 
 void
 GamepadManager::StopHaptics()
 {
+  const char* kGamepadHapticEnabledPref = "dom.gamepad.haptic_feedback.enabled";
+  if (!Preferences::GetBool(kGamepadHapticEnabledPref)) {
+    return;
+  }
+
   for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
     const uint32_t gamepadIndex = iter.UserData()->HashKey();
     if (gamepadIndex >= VR_GAMEPAD_IDX_OFFSET) {
       if (gfx::VRManagerChild::IsCreated()) {
         const uint32_t index = gamepadIndex - VR_GAMEPAD_IDX_OFFSET;
         gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
         vm->SendStopVibrateHaptic(index);
       }
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -197,16 +197,17 @@ pref("dom.requestIdleCallback.enabled", 
 pref("dom.gamepad.enabled", true);
 pref("dom.gamepad.test.enabled", false);
 #ifdef RELEASE_OR_BETA
 pref("dom.gamepad.non_standard_events.enabled", false);
 #else
 pref("dom.gamepad.non_standard_events.enabled", true);
 #endif
 pref("dom.gamepad.extensions.enabled", true);
+pref("dom.gamepad.haptic_feedback.enabled", true);
 
 // If this is true, TextEventDispatcher dispatches keydown and keyup events
 // even during composition (keypress events are never fired during composition
 // even if this is true).
 pref("dom.keyboardevent.dispatch_during_composition", false);
 
 // Whether to run add-on code in different compartments from browser code. This
 // causes a separate compartment for each (addon, global) combination, which may