Bug 1487115 - Fix navigator.Gamepads returns empty VR array after a page load when using gfxVRExternal r=qdot,kip

Differential Revision: https://phabricator.services.mozilla.com/D4570

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Imanol Fernandez 2018-08-29 19:10:55 +00:00
Родитель 53c32e8a26
Коммит 01d16686d3
3 изменённых файлов: 15 добавлений и 3 удалений

Просмотреть файл

@ -211,8 +211,15 @@ GamepadManager::GetGamepad(uint32_t aIndex) const
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)
GamepadServiceType aServiceType) const
{
uint32_t newIndex = 0;

Просмотреть файл

@ -60,6 +60,9 @@ class GamepadManager final : public nsIObserver
// Returns gamepad object if index exists, null otherwise
already_AddRefed<Gamepad> GetGamepad(uint32_t aIndex) const;
// Returns gamepad object if GamepadId exists, null otherwise
already_AddRefed<Gamepad> GetGamepad(uint32_t aGamepadId, GamepadServiceType aServiceType) const;
// Receive GamepadChangeEvent messages from parent process to fire DOM events
void Update(const GamepadChangeEvent& aGamepadEvent);
@ -132,7 +135,7 @@ class GamepadManager final : public nsIObserver
bool aHasSeen = true);
// Our gamepad index has VR_GAMEPAD_IDX_OFFSET while GamepadChannelType
// is from VRManager.
uint32_t GetGamepadIndexWithServiceType(uint32_t aIndex, GamepadServiceType aServiceType);
uint32_t GetGamepadIndexWithServiceType(uint32_t aIndex, GamepadServiceType aServiceType) const;
// Gamepads connected to the system. Copies of these are handed out
// to each window.

Просмотреть файл

@ -13,6 +13,7 @@
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "mozilla/dom/GamepadManager.h"
#include "mozilla/dom/Gamepad.h"
#include "mozilla/Preferences.h"
#include "mozilla/Unused.h"
#include "nsServiceManagerUtils.h"
@ -169,7 +170,8 @@ VRDisplayClient::FireGamepadEvents()
}
// Send events to notify that new controllers are added
if (lastState.controllerName[0] == '\0') {
RefPtr<dom::Gamepad> existing = gamepadManager->GetGamepad(gamepadId, dom::GamepadServiceType::VR);
if (lastState.controllerName[0] == '\0' || !existing) {
dom::GamepadAdded info(NS_ConvertUTF8toUTF16(state.controllerName),
dom::GamepadMappingType::_empty,
state.hand,