Bug 968804 - Part q: Add inner window assertions to the gamepad methods; r=khuey

This commit is contained in:
Ms2ger 2014-06-29 17:36:02 +02:00
Родитель a4e50b6951
Коммит 91b523c2d5
5 изменённых файлов: 34 добавлений и 13 удалений

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

@ -1481,8 +1481,12 @@ nsGlobalWindow::CleanUp()
inner->CleanUp();
}
DisableGamepadUpdates();
mHasGamepad = false;
if (IsInnerWindow()) {
DisableGamepadUpdates();
mHasGamepad = false;
} else {
MOZ_ASSERT(!mHasGamepad);
}
if (mCleanMessageManager) {
NS_ABORT_IF_FALSE(mIsChrome, "only chrome should have msg manager cleaned");
@ -9771,7 +9775,8 @@ void nsGlobalWindow::UpdateTouchState()
void
nsGlobalWindow::EnableGamepadUpdates()
{
FORWARD_TO_INNER_VOID(EnableGamepadUpdates, ());
MOZ_ASSERT(IsInnerWindow());
if (mHasGamepad) {
#ifdef MOZ_GAMEPAD
nsRefPtr<GamepadService> gamepadsvc(GamepadService::GetService());
@ -9785,7 +9790,8 @@ nsGlobalWindow::EnableGamepadUpdates()
void
nsGlobalWindow::DisableGamepadUpdates()
{
FORWARD_TO_INNER_VOID(DisableGamepadUpdates, ());
MOZ_ASSERT(IsInnerWindow());
if (mHasGamepad) {
#ifdef MOZ_GAMEPAD
nsRefPtr<GamepadService> gamepadsvc(GamepadService::GetService());
@ -13048,7 +13054,7 @@ nsGlobalWindow::DisableDeviceSensor(uint32_t aType)
void
nsGlobalWindow::SetHasGamepadEventListener(bool aHasGamepad/* = true*/)
{
FORWARD_TO_INNER_VOID(SetHasGamepadEventListener, (aHasGamepad));
MOZ_ASSERT(IsInnerWindow());
mHasGamepad = aHasGamepad;
if (aHasGamepad) {
EnableGamepadUpdates();
@ -13127,14 +13133,14 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
void
nsGlobalWindow::AddGamepad(uint32_t aIndex, Gamepad* aGamepad)
{
FORWARD_TO_INNER_VOID(AddGamepad, (aIndex, aGamepad));
MOZ_ASSERT(IsInnerWindow());
mGamepads.Put(aIndex, aGamepad);
}
void
nsGlobalWindow::RemoveGamepad(uint32_t aIndex)
{
FORWARD_TO_INNER_VOID(RemoveGamepad, (aIndex));
MOZ_ASSERT(IsInnerWindow());
mGamepads.Remove(aIndex);
}
@ -13153,7 +13159,7 @@ nsGlobalWindow::EnumGamepadsForGet(const uint32_t& aKey, Gamepad* aData,
void
nsGlobalWindow::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads)
{
FORWARD_TO_INNER_VOID(GetGamepads, (aGamepads));
MOZ_ASSERT(IsInnerWindow());
aGamepads.Clear();
// mGamepads.Count() may not be sufficient, but it's not harmful.
aGamepads.SetCapacity(mGamepads.Count());
@ -13163,7 +13169,7 @@ nsGlobalWindow::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads)
already_AddRefed<Gamepad>
nsGlobalWindow::GetGamepad(uint32_t aIndex)
{
FORWARD_TO_INNER(GetGamepad, (aIndex), nullptr);
MOZ_ASSERT(IsInnerWindow());
nsRefPtr<Gamepad> gamepad;
if (mGamepads.Get(aIndex, getter_AddRefs(gamepad))) {
return gamepad.forget();
@ -13175,14 +13181,14 @@ nsGlobalWindow::GetGamepad(uint32_t aIndex)
void
nsGlobalWindow::SetHasSeenGamepadInput(bool aHasSeen)
{
FORWARD_TO_INNER_VOID(SetHasSeenGamepadInput, (aHasSeen));
MOZ_ASSERT(IsInnerWindow());
mHasSeenGamepadInput = aHasSeen;
}
bool
nsGlobalWindow::HasSeenGamepadInput()
{
FORWARD_TO_INNER(HasSeenGamepadInput, (), false);
MOZ_ASSERT(IsInnerWindow());
return mHasSeenGamepadInput;
}
@ -13199,7 +13205,7 @@ nsGlobalWindow::EnumGamepadsForSync(const uint32_t& aKey, Gamepad* aData,
void
nsGlobalWindow::SyncGamepadState()
{
FORWARD_TO_INNER_VOID(SyncGamepadState, ());
MOZ_ASSERT(IsInnerWindow());
if (mHasSeenGamepadInput) {
mGamepads.EnumerateRead(EnumGamepadsForSync, nullptr);
}

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

@ -499,6 +499,7 @@ public:
virtual nsresult SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust);
bool FullScreen() const;
// Inner windows only.
virtual void SetHasGamepadEventListener(bool aHasGamepad = true);
// nsIInterfaceRequestor
@ -739,6 +740,7 @@ public:
SlowScriptResponse ShowSlowScriptDialog();
#ifdef MOZ_GAMEPAD
// Inner windows only.
void AddGamepad(uint32_t aIndex, mozilla::dom::Gamepad* aGamepad);
void RemoveGamepad(uint32_t aIndex);
void GetGamepads(nsTArray<nsRefPtr<mozilla::dom::Gamepad> >& aGamepads);
@ -754,6 +756,7 @@ public:
void* aUserArg);
#endif
// Inner windows only.
// Enable/disable updates for gamepad input.
void EnableGamepadUpdates();
void DisableGamepadUpdates();
@ -1486,6 +1489,7 @@ protected:
// This member is only used by inner windows.
bool mInnerObjectsFreed : 1;
// Inner windows only.
// Indicates whether this window wants gamepad input events
bool mHasGamepad : 1;
#ifdef MOZ_GAMEPAD

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

@ -649,6 +649,8 @@ public:
/**
* Tell this window that there is an observer for gamepad input
*
* Inner windows only.
*/
virtual void SetHasGamepadEventListener(bool aHasGamepad = true) = 0;

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

@ -98,6 +98,9 @@ GamepadService::BeginShutdown()
void
GamepadService::AddListener(nsGlobalWindow* aWindow)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
if (mShuttingDown) {
return;
}
@ -117,6 +120,9 @@ GamepadService::AddListener(nsGlobalWindow* aWindow)
void
GamepadService::RemoveListener(nsGlobalWindow* aWindow)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
if (mShuttingDown) {
// Doesn't matter at this point. It's possible we're being called
// as a result of our own destructor here, so just bail out.
@ -445,6 +451,9 @@ GamepadService::SetWindowHasSeenGamepad(nsGlobalWindow* aWindow,
uint32_t aIndex,
bool aHasSeen)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
if (mListeners.IndexOf(aWindow) == NoIndex) {
// This window isn't even listening for gamepad events.
return;

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

@ -118,7 +118,7 @@ class GamepadService : public nsIObserver
// Gamepads connected to the system. Copies of these are handed out
// to each window.
nsTArray<nsRefPtr<Gamepad> > mGamepads;
// nsGlobalWindows that are listening for gamepad events.
// Inner windows that are listening for gamepad events.
// has been sent to that window.
nsTArray<nsRefPtr<nsGlobalWindow> > mListeners;
nsCOMPtr<nsITimer> mTimer;