Backed out 5 changesets (bug 1617023, bug 1627141, bug 1626812) for causing being related to Bug 1611310 CLOSED TREE
authorStefan Hindli <shindli@mozilla.com>
Wed, 08 Apr 2020 01:45:47 +0300
changeset 522826 c125833dc46abea4b53adc37022b71a5cd10a11c
parent 522825 b975de50682b1097d637427179f35c5d29b4e3e0
child 522827 ab5d839fd72dc77633dc58103df5234ba645b1e0
push id112325
push usershindli@mozilla.com
push dateTue, 07 Apr 2020 22:52:46 +0000
treeherderautoland@ab5d839fd72d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1617023, 1627141, 1626812, 1611310
milestone77.0a1
backs outb975de50682b1097d637427179f35c5d29b4e3e0
481325c44e806c01a24b1adb63f519ea383b4fc2
546b90fd16893acd681e1f1628d48254e0a38946
f54ac49bbc0ad8e6f8ed5fc7b80b8dc382d4a7db
1ebf382e7133e7a848c4e785002a828604704c0b
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
Backed out 5 changesets (bug 1617023, bug 1627141, bug 1626812) for causing being related to Bug 1611310 CLOSED TREE Backed out changeset b975de50682b (bug 1627141) Backed out changeset 481325c44e80 (bug 1626812) Backed out changeset 546b90fd1689 (bug 1617023) Backed out changeset f54ac49bbc0a (bug 1617023) Backed out changeset 1ebf382e7133 (bug 1617023)
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
dom/vr/VRDisplay.cpp
dom/vr/XRInputSource.cpp
dom/vr/XRInputSource.h
dom/vr/XRInputSourceArray.cpp
dom/vr/XRInputSourceArray.h
dom/vr/XRSession.cpp
gfx/vr/VRDisplayClient.cpp
gfx/vr/VRDisplayClient.h
gfx/vr/gfxVR.h
gfx/vr/service/OculusSession.cpp
gfx/vr/service/OpenVRSession.cpp
gfx/vr/service/OpenVRSession.h
gfx/vr/service/VRSession.cpp
gfx/vr/service/VRSession.h
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -45,37 +45,16 @@ bool sShutdown = false;
 
 StaticRefPtr<GamepadManager> gGamepadManagerSingleton;
 const uint32_t VR_GAMEPAD_IDX_OFFSET = 0x01 << 16;
 
 }  // namespace
 
 NS_IMPL_ISUPPORTS(GamepadManager, nsIObserver)
 
-/*static*/
-uint32_t GamepadManager::GetGamepadIndexWithServiceType(
-    uint32_t aIndex, GamepadServiceType aServiceType) {
-  uint32_t newIndex = 0;
-
-  switch (aServiceType) {
-    case GamepadServiceType::Standard:
-      MOZ_ASSERT(aIndex <= VR_GAMEPAD_IDX_OFFSET);
-      newIndex = aIndex;
-      break;
-    case GamepadServiceType::VR:
-      newIndex = aIndex + VR_GAMEPAD_IDX_OFFSET;
-      break;
-    default:
-      MOZ_ASSERT(false);
-      break;
-  }
-
-  return newIndex;
-}
-
 GamepadManager::GamepadManager()
     : mEnabled(false),
       mNonstandardEventsEnabled(false),
       mShuttingDown(false),
       mPromiseID(0) {}
 
 nsresult GamepadManager::Init() {
   mEnabled = StaticPrefs::dom_gamepad_enabled();
@@ -211,16 +190,36 @@ already_AddRefed<Gamepad> GamepadManager
   return nullptr;
 }
 
 already_AddRefed<Gamepad> GamepadManager::GetGamepad(
     uint32_t aGamepadId, GamepadServiceType aServiceType) const {
   return GetGamepad(GetGamepadIndexWithServiceType(aGamepadId, aServiceType));
 }
 
+uint32_t GamepadManager::GetGamepadIndexWithServiceType(
+    uint32_t aIndex, GamepadServiceType aServiceType) const {
+  uint32_t newIndex = 0;
+
+  switch (aServiceType) {
+    case GamepadServiceType::Standard:
+      MOZ_ASSERT(aIndex <= VR_GAMEPAD_IDX_OFFSET);
+      newIndex = aIndex;
+      break;
+    case GamepadServiceType::VR:
+      newIndex = aIndex + VR_GAMEPAD_IDX_OFFSET;
+      break;
+    default:
+      MOZ_ASSERT(false);
+      break;
+  }
+
+  return newIndex;
+}
+
 void GamepadManager::AddGamepad(uint32_t aIndex, const nsAString& aId,
                                 GamepadMappingType aMapping, GamepadHand aHand,
                                 GamepadServiceType aServiceType,
                                 uint32_t aDisplayID, uint32_t aNumButtons,
                                 uint32_t aNumAxes, uint32_t aNumHaptics,
                                 uint32_t aNumLightIndicator,
                                 uint32_t aNumTouchEvents) {
   uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -30,21 +30,16 @@ class GamepadManager final : public nsIO
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   // Returns true if we actually have a service up and running
   static bool IsServiceRunning();
   // Get the singleton service
   static already_AddRefed<GamepadManager> GetService();
 
-  // Our gamepad index has VR_GAMEPAD_IDX_OFFSET while GamepadChannelType
-  // is from VRManager.
-  static uint32_t GetGamepadIndexWithServiceType(
-      uint32_t aIndex, GamepadServiceType aServiceType);
-
   void BeginShutdown();
   void StopMonitoring();
 
   // Indicate that |aWindow| wants to receive gamepad events.
   void AddListener(nsGlobalWindowInner* aWindow);
   // Indicate that |aWindow| should no longer receive gamepad events.
   void RemoveListener(nsGlobalWindowInner* aWindow);
 
@@ -139,16 +134,20 @@ class GamepadManager final : public nsIO
   // to this window. This should only return true if the user
   // explicitly interacted with a gamepad while this window
   // was focused, by pressing buttons or similar actions.
   bool WindowHasSeenGamepad(nsGlobalWindowInner* aWindow,
                             uint32_t aIndex) const;
   // Indicate that a window has received data from a gamepad.
   void SetWindowHasSeenGamepad(nsGlobalWindowInner* aWindow, uint32_t aIndex,
                                bool aHasSeen = true);
+  // Our gamepad index has VR_GAMEPAD_IDX_OFFSET while GamepadChannelType
+  // is from VRManager.
+  uint32_t GetGamepadIndexWithServiceType(
+      uint32_t aIndex, GamepadServiceType aServiceType) const;
 
   // Gamepads connected to the system. Copies of these are handed out
   // to each window.
   nsRefPtrHashtable<nsUint32HashKey, Gamepad> mGamepads;
   // Inner windows that are listening for gamepad events.
   // has been sent to that window.
   nsTArray<RefPtr<nsGlobalWindowInner>> mListeners;
   uint32_t mPromiseID;
--- a/dom/vr/VRDisplay.cpp
+++ b/dom/vr/VRDisplay.cpp
@@ -477,17 +477,16 @@ already_AddRefed<Promise> VRDisplay::Req
 
   RefPtr<Promise> promise = Promise::Create(global, aRv);
   NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
 
   bool isChromePresentation = aCallerType == CallerType::System;
   uint32_t presentationGroup =
       isChromePresentation ? gfx::kVRGroupChrome : gfx::kVRGroupContent;
 
-  mClient->SetXRAPIMode(gfx::VRAPIMode::WebVR);
   if (!UserActivation::IsHandlingUserInput() && !isChromePresentation &&
       !IsHandlingVRNavigationEvent() && StaticPrefs::dom_vr_require_gesture() &&
       !IsPresenting()) {
     // The WebVR API states that if called outside of a user gesture, the
     // promise must be rejected.  We allow VR presentations to start within
     // trusted events such as vrdisplayactivate, which triggers in response to
     // HMD proximity sensors and when navigating within a VR presentation.
     // This user gesture requirement is not enforced for chrome/system code.
--- a/dom/vr/XRInputSource.cpp
+++ b/dom/vr/XRInputSource.cpp
@@ -3,19 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/XRInputSource.h"
 #include "XRNativeOriginViewer.h"
 #include "XRNativeOriginTracker.h"
 
-#include "mozilla/dom/Gamepad.h"
-#include "mozilla/dom/GamepadManager.h"
-
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(XRInputSource, mParent)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(XRInputSource, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(XRInputSource, Release)
 
 // Follow the controller profile ids from https://github.com/immersive-web/webxr-input-profiles.
@@ -100,27 +97,17 @@ nsTArray<nsString> GetInputSourceProfile
       break;
     default:
       NS_WARNING("Unsupported XR input source profile.\n");
       break;
   }
   return profile;
 }
 
-XRInputSource::XRInputSource(nsISupports* aParent)
- : mParent(aParent),
-   mGamepad(nullptr),
-   mIndex(-1) {}
-
-XRInputSource::~XRInputSource() {
-  mTargetRaySpace = nullptr;
-  mGripSpace = nullptr;
-  mGamepad = nullptr;
-  mozilla::DropJSObjects(this);
-}
+XRInputSource::XRInputSource(nsISupports* aParent) : mParent(aParent) {}
 
 JSObject* XRInputSource::WrapObject(JSContext* aCx,
                                     JS::Handle<JSObject*> aGivenProto) {
   return XRInputSource_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 XRHandedness XRInputSource::Handedness() {
   return mHandedness;
@@ -138,17 +125,18 @@ XRSpace* XRInputSource::GetGripSpace() {
   return mGripSpace;
 }
 
 void XRInputSource::GetProfiles(nsTArray<nsString>& aResult) {
   aResult = mProfiles;
 }
 
 Gamepad* XRInputSource::GetGamepad() {
-  return mGamepad;
+  // TODO (Bug 1617023): Implement Gamepad for XRInputSource.
+  return nullptr;
 }
 
 void XRInputSource::Setup(XRSession* aSession, uint32_t aIndex) {
   MOZ_ASSERT(aSession);
   gfx::VRDisplayClient* displayClient = aSession->GetDisplayClient();
   if (!displayClient) {
     MOZ_ASSERT(displayClient);
     return;
@@ -193,61 +181,23 @@ void XRInputSource::Setup(XRSession* aSe
       mTargetRayMode = XRTargetRayMode::Screen;
       break;
     default:
       MOZ_ASSERT(false && "Undefined TargetRayMode type.");
       break;
   }
   mTargetRaySpace = new XRSpace(aSession->GetParentObject(), aSession, nativeOriginTargetRay);
   mGripSpace = new XRSpace(aSession->GetParentObject(), aSession, nativeOriginGrip);
-  const uint32_t gamepadId = displayInfo.mDisplayID * kVRControllerMaxCount + aIndex;
-  const uint32_t hashKey = GamepadManager::GetGamepadIndexWithServiceType(gamepadId, GamepadServiceType::VR);
-  mGamepad = new Gamepad(mParent, NS_ConvertASCIItoUTF16(""), -1, hashKey, GamepadMappingType::Xr_standard,
-    controllerState.hand, displayInfo.mDisplayID, controllerState.numButtons, controllerState.numAxes,
-    controllerState.numHaptics, 0, 0);
   mIndex = aIndex;
 }
 
 void XRInputSource::SetGamepadIsConnected(bool aConnected) {
-  mGamepad->SetConnected(aConnected);
 }
 
 void XRInputSource::Update(XRSession* aSession) {
-  MOZ_ASSERT(aSession && mIndex >= 0 && mGamepad);
-
-  gfx::VRDisplayClient* displayClient = aSession->GetDisplayClient();
-  if (!displayClient) {
-    MOZ_ASSERT(displayClient);
-    return;
-  }
-  const gfx::VRDisplayInfo& displayInfo = displayClient->GetDisplayInfo();
-  const gfx::VRControllerState& controllerState = displayInfo.mControllerState[mIndex];
-  MOZ_ASSERT(controllerState.controllerName[0] != '\0');
-
-  // Update button values.
-  nsTArray<RefPtr<GamepadButton>> buttons;
-  mGamepad->GetButtons(buttons);
-  for (uint32_t i = 0; i < controllerState.numButtons; ++i) {
-    const bool pressed = controllerState.buttonPressed & (1ULL << i);
-    const bool touched = controllerState.buttonTouched & (1ULL << i);
-
-    if (buttons[i]->Pressed() != pressed || buttons[i]->Touched() != touched ||
-      buttons[i]->Value() != controllerState.triggerValue[i]) {
-      mGamepad->SetButton(i, pressed, touched, controllerState.triggerValue[i]);
-    }
-  }
-  // Update axis values.
-  nsTArray<double> axes;
-  mGamepad->GetAxes(axes);
-  for (uint32_t i = 0; i < controllerState.numAxes; ++i) {
-    if (axes[i] != controllerState.axisValue[i]) {
-      mGamepad->SetAxis(i, controllerState.axisValue[i]);
-    }
-  }
-  }
 }
 
 int32_t XRInputSource::GetIndex() {
   return mIndex;
 }
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/vr/XRInputSource.h
+++ b/dom/vr/XRInputSource.h
@@ -44,27 +44,26 @@ class XRInputSource final : public nsWra
   void GetProfiles(nsTArray<nsString>& aResult);
   Gamepad* GetGamepad();
   void Setup(XRSession* aSession, uint32_t aIndex);
   void SetGamepadIsConnected(bool aConnected);
   void Update(XRSession* aSession);
   int32_t GetIndex();
 
  protected:
-  virtual ~XRInputSource();
+  virtual ~XRInputSource() = default;
 
   nsCOMPtr<nsISupports> mParent;
 
  private:
   nsTArray<nsString> mProfiles;
   XRHandedness mHandedness;
   XRTargetRayMode mTargetRayMode;
 
   RefPtr<XRSpace> mTargetRaySpace;
   RefPtr<XRSpace> mGripSpace;
-  RefPtr<Gamepad> mGamepad;
   int32_t mIndex;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_XRInputSource_h_
--- a/dom/vr/XRInputSourceArray.cpp
+++ b/dom/vr/XRInputSourceArray.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/XRInputSourceArray.h"
 #include "mozilla/dom/XRSession.h"
-#include "mozilla/dom/XRInputSourcesChangeEvent.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(XRInputSourceArray, mParent,
                                       mInputSources)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(XRInputSourceArray)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(XRInputSourceArray)
@@ -36,98 +35,38 @@ void XRInputSourceArray::Update(XRSessio
     return;
   }
 
   XRInputSourcesChangeEventInit addInit;
   nsTArray<RefPtr<XRInputSource>> removedInputs;
   for (int32_t i = 0; i < gfx::kVRControllerMaxCount; ++i) {
     const gfx::VRControllerState& controllerState = displayClient->GetDisplayInfo().mControllerState[i];
     if (controllerState.controllerName[0] == '\0') {
-      // Checking if exising controllers need to be removed.
-      for (auto& input : mInputSources) {
-        if (input->GetIndex() == i) {
-          removedInputs.AppendElement(input);
-          break;
-        }
-      }
-      continue;
+      break; // We would not have an empty slot before others.
     }
-
     bool found = false;
     RefPtr<XRInputSource> inputSource = nullptr;
     for (auto& input : mInputSources) {
       if (input->GetIndex() == i) {
         found = true;
         inputSource = input;
         break;
       }
     }
     // Checking if it is added before.
-    if (!found &&
-      (controllerState.numButtons > 0 || controllerState.numAxes > 0)) {
+    if (!found) {
       inputSource = new XRInputSource(mParent);
       inputSource->Setup(aSession, i);
       mInputSources.AppendElement(inputSource);
-
-      addInit.mBubbles = false;
-      addInit.mCancelable = false;
-      addInit.mSession = aSession;
-      addInit.mAdded.AppendElement(*inputSource, mozilla::fallible);
     }
     // If added, updating the current controller states.
-    if (inputSource) {
-      inputSource->Update(aSession);
-    }
-  }
-
-  // Send `inputsourceschange` for new controllers.
-  if (addInit.mAdded.Length()) {
-    RefPtr<XRInputSourcesChangeEvent> event = XRInputSourcesChangeEvent::Constructor(aSession,
-        NS_LITERAL_STRING("inputsourceschange"), addInit);
-
-    event->SetTrusted(true);
-    aSession->DispatchEvent(*event);
-  }
-
-  // If there's a controller is removed, dispatch `inputsourceschange`.
-  if (removedInputs.Length()) {
-    DispatchInputSourceRemovedEvent(removedInputs, aSession);
-  }
-  for (auto& input: removedInputs) {
-    mInputSources.RemoveElement(input);
+    inputSource->Update(aSession);
   }
 }
 
-void XRInputSourceArray::DispatchInputSourceRemovedEvent(
-  const nsTArray<RefPtr<XRInputSource>>& aInputs, XRSession* aSession) {
-  XRInputSourcesChangeEventInit init;
-
-  for (auto& input: aInputs) {
-    input->SetGamepadIsConnected(false);
-
-    init.mBubbles = false;
-    init.mCancelable = false;
-    init.mSession = aSession;
-    init.mRemoved.AppendElement(*input, mozilla::fallible);
-  }
-
-  if (init.mRemoved.Length()) {
-    RefPtr<XRInputSourcesChangeEvent> event = XRInputSourcesChangeEvent::Constructor(aSession,
-      NS_LITERAL_STRING("inputsourceschange"), init);
-
-    event->SetTrusted(true);
-    aSession->DispatchEvent(*event);
-  }
-}
-
-void XRInputSourceArray::Clear(XRSession* aSession) {
-  DispatchInputSourceRemovedEvent(mInputSources, aSession);
-  mInputSources.Clear();
-}
-
 uint32_t XRInputSourceArray::Length() { return mInputSources.Length(); }
 
 XRInputSource* XRInputSourceArray::IndexedGetter(uint32_t aIndex,
                                                  bool& aFound) {
   aFound = aIndex < mInputSources.Length();
   if (!aFound) {
     return nullptr;
   }
--- a/dom/vr/XRInputSourceArray.h
+++ b/dom/vr/XRInputSourceArray.h
@@ -31,25 +31,21 @@ class XRInputSourceArray final : public 
   JSObject* WrapObject(JSContext* aCx,
                        JS::Handle<JSObject*> aGivenProto) override;
 
   // WebIDL Members
   XRInputSource* IndexedGetter(uint32_t aIndex, bool& aFound);
   uint32_t Length();
   void Setup(XRSession* aSession, RefPtr<gfx::VRDisplayClient> aDisplayClient);
   void Update(XRSession* aSession);
-  void Clear(XRSession* aSession);
+  void Clear();
 
  protected:
   virtual ~XRInputSourceArray() = default;
 
- private:
-  void DispatchInputSourceRemovedEvent(const nsTArray<RefPtr<XRInputSource>>& aInputs,
-                                       XRSession* aSession);
-
   nsCOMPtr<nsISupports> mParent;
   nsTArray<RefPtr<XRInputSource>> mInputSources;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_XRInputSourceArray_h_
--- a/dom/vr/XRSession.cpp
+++ b/dom/vr/XRSession.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/XRSession.h"
 
-#include "mozilla/dom/XRSessionEvent.h"
 #include "mozilla/dom/DocumentInlines.h"
 #include "XRSystem.h"
 #include "XRRenderState.h"
 #include "XRBoundedReferenceSpace.h"
 #include "XRFrame.h"
 #include "XRNativeOrigin.h"
 #include "XRNativeOriginFixed.h"
 #include "XRNativeOriginViewer.h"
@@ -109,19 +108,16 @@ XRSession::XRSession(
     aClient->SessionStarted(this);
   }
   mActiveRenderState = new XRRenderState(aWindow, this);
   mStartTimeStamp = TimeStamp::Now();
   if (IsImmersive()) {
     mDisplayPresentation =
         mDisplayClient->BeginPresentation({}, gfx::kVRGroupContent);
   }
-  if (mDisplayClient) {
-    mDisplayClient->SetXRAPIMode(gfx::VRAPIMode::WebXR);
-  }
   // TODO: Handle XR input sources are no longer available cases.
   // https://immersive-web.github.io/webxr/#dom-xrsession-inputsources
   mInputSources = new XRInputSourceArray(aWindow);
 }
 
 XRSession::~XRSession() { MOZ_ASSERT(mShutdown); }
 
 gfx::VRDisplayClient* XRSession::GetDisplayClient() { return mDisplayClient; }
@@ -395,40 +391,28 @@ void XRSession::Shutdown() {
   // Unregister from nsRefreshObserver
   if (mRefreshDriver) {
     mRefreshDriver->RemoveRefreshObserver(this, FlushType::Display);
     mRefreshDriver = nullptr;
   }
 }
 
 void XRSession::ExitPresentInternal() {
-  if (mInputSources) {
-    mInputSources->Clear(this);
-  }
   if (mDisplayClient) {
     mDisplayClient->SessionEnded(this);
   }
 
   if (mXRSystem) {
     mXRSystem->SessionEnded(this);
   }
 
   mDisplayPresentation = nullptr;
   if (!mEnded) {
     mEnded = true;
-
-    XRSessionEventInit init;
-    init.mBubbles = false;
-    init.mCancelable = false;
-    init.mSession = this;
-    RefPtr<XRSessionEvent> event = XRSessionEvent::Constructor(this,
-      NS_LITERAL_STRING("end"), init);
-
-    event->SetTrusted(true);
-    this->DispatchEvent(*event);
+    DispatchTrustedEvent(NS_LITERAL_STRING("end"));
   }
 }
 
 void XRSession::DisconnectFromOwner() {
   MOZ_ASSERT(NS_IsMainThread());
   Shutdown();
   DOMEventTargetHelper::DisconnectFromOwner();
 }
--- a/gfx/vr/VRDisplayClient.cpp
+++ b/gfx/vr/VRDisplayClient.cpp
@@ -10,17 +10,16 @@
 #include "prenv.h"
 
 #include "nsIGlobalObject.h"
 #include "nsRefPtrHashtable.h"
 #include "nsString.h"
 #include "mozilla/dom/GamepadManager.h"
 #include "mozilla/dom/Gamepad.h"
 #include "mozilla/dom/XRSession.h"
-#include "mozilla/dom/XRInputSourceArray.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/WebXRBinding.h"
 #include "nsServiceManagerUtils.h"
 
 #ifdef XP_WIN
 #  include "../layers/d3d11/CompositorD3D11.h"
 #endif
@@ -35,18 +34,17 @@ using namespace mozilla::gfx;
 
 VRDisplayClient::VRDisplayClient(const VRDisplayInfo& aDisplayInfo)
     : mDisplayInfo(aDisplayInfo),
       bLastEventWasMounted(false),
       bLastEventWasPresenting(false),
       mPresentationCount(0),
       mLastEventFrameId(0),
       mLastPresentingGeneration(0),
-      mLastEventControllerState{},
-      mAPIMode(VRAPIMode::WebXR) {
+      mLastEventControllerState{} {
   MOZ_COUNT_CTOR(VRDisplayClient);
 }
 
 VRDisplayClient::~VRDisplayClient() { MOZ_COUNT_DTOR(VRDisplayClient); }
 
 void VRDisplayClient::UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo) {
   mDisplayInfo = aDisplayInfo;
   FireEvents();
@@ -98,20 +96,16 @@ bool VRDisplayClient::IsPresentationGene
 
   return true;
 }
 
 void VRDisplayClient::MakePresentationGenerationCurrent() {
   mLastPresentingGeneration = mDisplayInfo.mDisplayState.presentingGeneration;
 }
 
-void VRDisplayClient::SetXRAPIMode(gfx::VRAPIMode aMode) {
-  mAPIMode = aMode;
-}
-
 void VRDisplayClient::FireEvents() {
   RefPtr<VRManagerChild> vm = VRManagerChild::Get();
   // Only fire these events for non-chrome VR sessions
   bool isPresenting = (mDisplayInfo.mPresentingGroups & kVRGroupContent) != 0;
 
   // Check if we need to trigger onVRDisplayPresentChange event
   if (bLastEventWasPresenting != isPresenting) {
     bLastEventWasPresenting = isPresenting;
@@ -141,28 +135,18 @@ void VRDisplayClient::FireEvents() {
   }
 
   // Check if we need to trigger VRDisplay.requestAnimationFrame
   if (mLastEventFrameId != mDisplayInfo.mFrameId) {
     mLastEventFrameId = mDisplayInfo.mFrameId;
     StartFrame();
   }
 
-  // In WebXR spec, Gamepad instances returned by an XRInputSource's gamepad attribute
-  // MUST NOT be included in the array returned by navigator.getGamepads().
-  if (mAPIMode == VRAPIMode::WebVR) {
-    FireGamepadEvents();
-  }
-  // Update controller states into XRInputSourceArray.
-  for (auto& session : mSessions) {
-    dom::XRInputSourceArray* inputs = session->InputSources();
-    if (inputs) {
-      inputs->Update(session);
-    }
-  }
+  // We only call FireGamepadEvents() in WebVR instead of WebXR
+  FireGamepadEvents();
 }
 
 void VRDisplayClient::GamepadMappingForWebVR(
     VRControllerState& aControllerState) {
   float triggerValue[kVRControllerMaxButtons];
   memcpy(triggerValue, aControllerState.triggerValue,
          sizeof(aControllerState.triggerValue));
   const uint64_t buttonPressed = aControllerState.buttonPressed;
--- a/gfx/vr/VRDisplayClient.h
+++ b/gfx/vr/VRDisplayClient.h
@@ -52,17 +52,16 @@ class VRDisplayClient {
   bool IsPresentationGenerationCurrent() const;
   void MakePresentationGenerationCurrent();
 
   void StartVRNavigation();
   void StopVRNavigation(const TimeDuration& aTimeout);
 
   bool IsPresenting();
   bool IsReferenceSpaceTypeSupported(dom::XRReferenceSpaceType aType) const;
-  void SetXRAPIMode(gfx::VRAPIMode aMode);
 
  protected:
   virtual ~VRDisplayClient();
 
   MOZ_CAN_RUN_SCRIPT void FireEvents();
   void FireGamepadEvents();
   MOZ_CAN_RUN_SCRIPT void StartFrame();
 
@@ -88,15 +87,14 @@ class VRDisplayClient {
    * when the window is closed.
    */
   nsTArray<RefPtr<dom::XRSession>> mSessions;
 
  private:
   void GamepadMappingForWebVR(VRControllerState& aControllerState);
 
   VRSubmitFrameResultInfo mSubmitFrameResult;
-  gfx::VRAPIMode mAPIMode;
 };
 
 }  // namespace gfx
 }  // namespace mozilla
 
 #endif /* GFX_VR_DISPLAY_CLIENT_H */
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -23,18 +23,16 @@ namespace mozilla {
 namespace layers {
 class PTextureParent;
 }
 namespace dom {
 enum class GamepadMappingType : uint8_t;
 enum class GamepadHand : uint8_t;
 }  // namespace dom
 namespace gfx {
-enum class VRAPIMode : uint8_t {WebXR, WebVR, NumVRAPIModes};
-
 class VRLayerParent;
 class VRDisplayHost;
 class VRManagerPromise;
 
 // The maximum number of frames of latency that we would expect before we
 // should give up applying pose prediction.
 // If latency is greater than one second, then the experience is not likely
 // to be corrected by pose prediction.  Setting this value too
--- a/gfx/vr/service/OculusSession.cpp
+++ b/gfx/vr/service/OculusSession.cpp
@@ -1260,18 +1260,16 @@ void OculusSession::UpdateControllerPose
                               dom::GamepadCapabilityFlags::Cap_Orientation);
       if (bNewController) {
         controllerState.flags |= dom::GamepadCapabilityFlags::Cap_Orientation;
         controllerState.flags |= dom::GamepadCapabilityFlags::Cap_Position;
         controllerState.flags |=
             dom::GamepadCapabilityFlags::Cap_AngularAcceleration;
         controllerState.flags |=
             dom::GamepadCapabilityFlags::Cap_LinearAcceleration;
-        controllerState.flags |=
-            dom::GamepadCapabilityFlags::Cap_TargetRaySpacePosition;
       }
 
       if (bNewController || trackingState.HandStatusFlags[handIdx] &
                                 ovrStatus_OrientationTracked) {
         controllerState.pose.orientation[0] = pose.ThePose.Orientation.x;
         controllerState.pose.orientation[1] = pose.ThePose.Orientation.y;
         controllerState.pose.orientation[2] = pose.ThePose.Orientation.z;
         controllerState.pose.orientation[3] = pose.ThePose.Orientation.w;
@@ -1315,31 +1313,30 @@ void OculusSession::UpdateControllerPose
 void OculusSession::EnumerateControllers(VRSystemState& aState,
                                          const ovrInputState& aInputState) {
   for (uint32_t handIdx = 0; handIdx < 2; handIdx++) {
     // Left Touch Controller will always be at index 0 and
     // and Right Touch Controller will always be at index 1
     VRControllerState& controllerState = aState.controllerState[handIdx];
     if (aInputState.ControllerType & OculusControllerTypes[handIdx]) {
       bool bNewController = false;
-      // Touch Controller detected
+      // Left Touch Controller detected
       if (controllerState.controllerName[0] == '\0') {
         // Controller has been just enumerated
         strncpy(controllerState.controllerName, OculusControllerNames[handIdx],
                 kVRControllerNameMaxLen);
         controllerState.hand = OculusControllerHand[handIdx];
-        controllerState.targetRayMode = gfx::TargetRayMode::TrackedPointer;
         controllerState.numButtons = kNumOculusButtons;
         controllerState.numAxes = kNumOculusAxes;
         controllerState.numHaptics = kNumOculusHaptcs;
         controllerState.type = VRControllerType::OculusTouch;
         bNewController = true;
       }
     } else {
-      // Touch Controller not detected
+      // Left Touch Controller not detected
       if (controllerState.controllerName[0] != '\0') {
         // Clear any newly disconnected ontrollers
         memset(&controllerState, 0, sizeof(VRControllerState));
       }
     }
   }
 }
 
@@ -1404,17 +1401,16 @@ void OculusSession::UpdateControllerInpu
       if (abs(axisValue) < 0.0000009f) {
         axisValue = 0.0f;  // Clear noise signal
       }
       controllerState.axisValue[axisIdx] = axisValue;
       axisIdx++;
 
       MOZ_ASSERT(axisIdx == kNumOculusAxes);
     }
-    SetControllerSelectionAndSqueezeFrameId(controllerState, aState.displayState.lastSubmittedFrameId);
   }
 }
 
 void OculusSession::UpdateTelemetry(VRSystemState& aSystemState) {
   if (!mSession) {
     return;
   }
   ovrPerfStats perfStats;
--- a/gfx/vr/service/OpenVRSession.cpp
+++ b/gfx/vr/service/OpenVRSession.cpp
@@ -986,17 +986,16 @@ void OpenVRSession::EnumerateControllers
                               deviceId, contrlType);
         // Controllers should be the same type with one VR display.
         MOZ_ASSERT(controllerType == contrlType ||
                    controllerType == VRControllerType::_empty);
         controllerType = contrlType;
         strncpy(controllerState.controllerName, deviceId.BeginReading(),
                 kVRControllerNameMaxLen);
         controllerState.numHaptics = kNumOpenVRHaptics;
-        controllerState.targetRayMode = gfx::TargetRayMode::TrackedPointer;
         controllerState.type = controllerType;
       }
       controllerPresent[stateIndex] = true;
       mControllerDeviceIndex[stateIndex] = static_cast<OpenVRHand>(handIndex);
       ++stateIndex;
     }
   }
 
@@ -1042,17 +1041,16 @@ void OpenVRSession::UpdateControllerButt
        ++stateIndex) {
     const OpenVRHand role = mControllerDeviceIndex[stateIndex];
     if (role == OpenVRHand::None) {
       continue;
     }
     VRControllerState& controllerState = aState.controllerState[stateIndex];
     controllerState.hand = GetControllerHandFromControllerRole(role);
     mControllerMapper->UpdateButtons(controllerState, mControllerHand[role]);
-    SetControllerSelectionAndSqueezeFrameId(controllerState, aState.displayState.lastSubmittedFrameId);
   }
 }
 
 void OpenVRSession::UpdateControllerPoses(VRSystemState& aState) {
   MOZ_ASSERT(mVRSystem);
 
   for (uint32_t stateIndex = 0; stateIndex < kVRControllerMaxCount;
        ++stateIndex) {
@@ -1068,18 +1066,17 @@ void OpenVRSession::UpdateControllerPose
             vr::k_ulInvalidInputValueHandle) != vr::VRInputError_None ||
         !poseData.bActive || !poseData.pose.bPoseIsValid) {
       controllerState.isOrientationValid = false;
       controllerState.isPositionValid = false;
     } else {
       const ::vr::TrackedDevicePose_t& pose = poseData.pose;
       if (pose.bDeviceIsConnected) {
         controllerState.flags = (dom::GamepadCapabilityFlags::Cap_Orientation |
-                                 dom::GamepadCapabilityFlags::Cap_Position |
-                                 dom::GamepadCapabilityFlags::Cap_TargetRaySpacePosition);
+                                 dom::GamepadCapabilityFlags::Cap_Position);
       } else {
         controllerState.flags = dom::GamepadCapabilityFlags::Cap_None;
       }
       if (pose.bPoseIsValid &&
           pose.eTrackingResult == ::vr::TrackingResult_Running_OK) {
         gfx::Matrix4x4 m;
 
         // NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4.  But
--- a/gfx/vr/service/OpenVRSession.h
+++ b/gfx/vr/service/OpenVRSession.h
@@ -68,17 +68,16 @@ class OpenVRSession : public VRSession {
   ::vr::VRActionSetHandle_t mActionsetFirefox = vr::k_ulInvalidActionSetHandle;
   OpenVRHand mControllerDeviceIndex[kVRControllerMaxCount];
   ControllerInfo mControllerHand[OpenVRHand::Total];
   float mHapticPulseRemaining[kVRControllerMaxCount][kNumOpenVRHaptics];
   float mHapticPulseIntensity[kVRControllerMaxCount][kNumOpenVRHaptics];
   bool mIsWindowsMR;
   TimeStamp mLastHapticUpdate;
 
-  static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
   bool InitState(mozilla::gfx::VRSystemState& aSystemState);
   void UpdateStageParameters(mozilla::gfx::VRDisplayState& aState);
   void UpdateEyeParameters(mozilla::gfx::VRSystemState& aState);
   void UpdateHeadsetPose(mozilla::gfx::VRSystemState& aState);
   void EnumerateControllers(VRSystemState& aState);
   void UpdateControllerPoses(VRSystemState& aState);
   void UpdateControllerButtons(VRSystemState& aState);
   void UpdateTelemetry(VRSystemState& aSystemState);
@@ -95,16 +94,17 @@ class OpenVRSession : public VRSession {
                              ::vr::TrackedDeviceIndex_t aDeviceIndex,
                              nsCString& aId,
                              mozilla::gfx::VRControllerType& aControllerType);
   void UpdateHaptics();
   void StartHapticThread();
   void StopHapticThread();
   void StartHapticTimer();
   void StopHapticTimer();
+  static void HapticTimerCallback(nsITimer* aTimer, void* aClosure);
   RefPtr<nsITimer> mHapticTimer;
   RefPtr<VRThread> mHapticThread;
   mozilla::Mutex mControllerHapticStateMutex;
   UniquePtr<OpenVRControllerMapper> mControllerMapper;
 };
 
 }  // namespace gfx
 }  // namespace mozilla
--- a/gfx/vr/service/VRSession.cpp
+++ b/gfx/vr/service/VRSession.cpp
@@ -162,31 +162,9 @@ void VRSession::UpdateTrigger(VRControll
     aState.buttonPressed |= mask;
     aState.buttonTouched |= mask;
   } else {
     aState.buttonPressed &= ~mask;
     aState.buttonTouched &= ~mask;
   }
 }
 
-void VRSession::SetControllerSelectionAndSqueezeFrameId(VRControllerState& controllerState,
-                                                        uint64_t aFrameId) {
-  // The 1st button, trigger, is its selection action.
-  const bool selectionPressed = controllerState.buttonPressed & 1ULL;
-  if (selectionPressed && controllerState.selectActionStopFrameId
-    >= controllerState.selectActionStartFrameId) {
-      controllerState.selectActionStartFrameId = aFrameId;
-  } else if (!selectionPressed && controllerState.selectActionStartFrameId
-    > controllerState.selectActionStopFrameId) {
-      controllerState.selectActionStopFrameId = aFrameId;
-  }
-  // The 2nd button, squeeze, is its squeeze action.
-  const bool squeezePressed = controllerState.buttonPressed & (1ULL << 1);
-  if (squeezePressed && controllerState.squeezeActionStopFrameId
-    >= controllerState.squeezeActionStartFrameId) {
-      controllerState.squeezeActionStartFrameId = aFrameId;
-  } else if (!squeezePressed && controllerState.squeezeActionStartFrameId
-    > controllerState.squeezeActionStopFrameId) {
-      controllerState.squeezeActionStopFrameId = aFrameId;
-  }
-}
-
 bool VRSession::ShouldQuit() const { return mShouldQuit; }
--- a/gfx/vr/service/VRSession.h
+++ b/gfx/vr/service/VRSession.h
@@ -79,15 +79,14 @@ class VRSession {
   ID3D11Device1* mDevice;
   ID3D11DeviceContext1* mContext;
   ID3DDeviceContextState* mDeviceContextState;
 
 #elif defined(XP_MACOSX)
   virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
                            const VRLayerTextureHandle& aTexture) = 0;
 #endif
-  void SetControllerSelectionAndSqueezeFrameId(VRControllerState& controllerState, uint64_t aFrameId);
 };
 
 }  // namespace gfx
 }  // namespace mozilla
 
 #endif  // GFX_VR_SERVICE_VRSESSION_H