Index: third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
diff --git a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
index a157e2c3d1b13e5066d01f441854b29eacde782c..de32e5af44b98de1a8a58c3e5f703478dd00bb36 100644 |
--- a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
+++ b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
@@ -94,7 +94,9 @@ DEFINE_TRACE(NavigatorVR) { |
DOMWindowProperty::trace(visitor); |
} |
-NavigatorVR::NavigatorVR(LocalFrame* frame) : DOMWindowProperty(frame) {} |
+NavigatorVR::NavigatorVR(LocalFrame* frame) : DOMWindowProperty(frame) { |
+ frame->localDOMWindow()->registerEventListenerObserver(this); |
+} |
NavigatorVR::~NavigatorVR() {} |
@@ -117,4 +119,29 @@ void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
} |
} |
+void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
+ const AtomicString& eventType) { |
+ if (eventType == EventTypeNames::vrdisplayactivate) { |
+ controller()->setListeningForActivate(true); |
+ } else if (eventType == EventTypeNames::vrdisplayconnect) { |
+ // If the page is listening for connection events make sure we've created a |
+ // controller so that we'll be notified of new devices. |
+ controller(); |
+ } |
+} |
+ |
+void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
+ const AtomicString& eventType) { |
+ if (eventType == EventTypeNames::vrdisplayactivate && |
+ !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
+ controller()->setListeningForActivate(false); |
+ } |
+} |
+ |
+void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { |
+ if (m_controller) { |
+ m_controller->setListeningForActivate(false); |
+ } |
+} |
+ |
} // namespace blink |