Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1783)

Unified Diff: Source/modules/gamepad/NavigatorGamepad.cpp

Issue 868023003: Never (re)start NavigatorGamepad platform event updating once detached. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/NavigatorGamepad.cpp
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
index 118aa9453277b573f4789196923a55c8ee597910..c68f061fff5d0497122022d45368e78d7ee3adae 100644
--- a/Source/modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp
@@ -97,11 +97,8 @@ GamepadList* NavigatorGamepad::gamepads()
{
if (!m_gamepads)
m_gamepads = GamepadList::create();
- if (frame() && frame()->host()) {
- // The frame must be attached to start updating.
- startUpdating();
+ if (startUpdatingIfAttached())
sampleGamepads<Gamepad>(m_gamepads.get());
- }
return m_gamepads.get();
}
@@ -115,6 +112,16 @@ void NavigatorGamepad::trace(Visitor* visitor)
DOMWindowLifecycleObserver::trace(visitor);
}
+bool NavigatorGamepad::startUpdatingIfAttached()
+{
+ // The frame must be attached to start updating.
+ if (frame() && frame()->host()) {
+ startUpdating();
+ return true;
+ }
+ return false;
+}
+
void NavigatorGamepad::didUpdateData()
{
// We should stop listening once we detached.
@@ -214,7 +221,7 @@ void NavigatorGamepad::didAddEventListener(LocalDOMWindow*, const AtomicString&
{
if (isGamepadEvent(eventType)) {
if (page() && page()->visibilityState() == PageVisibilityStateVisible)
- startUpdating();
+ startUpdatingIfAttached();
m_hasEventListener = true;
}
}
@@ -245,7 +252,7 @@ void NavigatorGamepad::pageVisibilityChanged()
// Inform the embedder whether it needs to provide gamepad data for us.
bool visible = page()->visibilityState() == PageVisibilityStateVisible;
if (visible && (m_hasEventListener || m_gamepads))
- startUpdating();
+ startUpdatingIfAttached();
else
stopUpdating();
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698