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

Unified Diff: third_party/WebKit/Source/modules/vr/NavigatorVR.cpp

Issue 2668003003: Provide WebVR pose data only to the focused frame. (Closed)
Patch Set: Address comments Created 3 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
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 076b64f97ce91586aaa57f9bb66de94042215eba..dfa7ad2027ecf79051fc6577904466a2c5185fa8 100644
--- a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp
+++ b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp
@@ -14,6 +14,7 @@
#include "core/frame/LocalFrame.h"
#include "core/frame/Navigator.h"
#include "core/frame/UseCounter.h"
+#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "modules/vr/VRController.h"
#include "modules/vr/VRDisplay.h"
@@ -25,6 +26,18 @@
namespace blink {
+namespace {
+bool isFrameFocused(LocalFrame* frame) {
+ if (!frame)
+ return false;
+ Page* page = frame->page();
+ if (!page)
+ return false;
+ const FocusController& controller = page->focusController();
+ return controller.isFocused() && (controller.focusedOrMainFrame() == frame);
+}
+} // namespace
+
NavigatorVR* NavigatorVR::from(Document& document) {
if (!document.frame() || !document.frame()->domWindow())
return 0;
@@ -77,6 +90,8 @@ VRController* NavigatorVR::controller() {
if (!m_controller) {
m_controller = new VRController(this);
+ m_controller->setListeningForActivate(m_listeningForActivate);
+ m_controller->focusChanged(m_focused);
}
return m_controller;
@@ -90,13 +105,14 @@ Document* NavigatorVR::document() {
DEFINE_TRACE(NavigatorVR) {
visitor->trace(m_controller);
Supplement<Navigator>::trace(visitor);
- PageVisibilityObserver::trace(visitor);
}
NavigatorVR::NavigatorVR(Navigator& navigator)
- : Supplement<Navigator>(navigator),
- PageVisibilityObserver(navigator.frame()->page()) {
+ : Supplement<Navigator>(navigator) {
navigator.frame()->domWindow()->registerEventListenerObserver(this);
+ navigator.frame()->page()->focusController().registerFocusChangedObserver(
+ this);
+ focusedFrameChanged();
}
NavigatorVR::~NavigatorVR() {}
@@ -122,13 +138,20 @@ void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) {
window->dispatchEvent(event);
}
-void NavigatorVR::pageVisibilityChanged() {
- if (!page())
+void NavigatorVR::focusedFrameChanged() {
+ if (isFrameFocused(supplementable()->frame())) {
+ if (!m_focused && m_controller) {
+ m_controller->setListeningForActivate(m_listeningForActivate);
+ m_controller->focusChanged(true);
+ }
+ m_focused = true;
return;
- if (m_controller) {
- m_controller->setListeningForActivate(page()->isPageVisible() &&
- m_listeningForActivate);
}
+ if (m_focused && m_controller) {
+ m_controller->setListeningForActivate(false);
+ m_controller->focusChanged(false);
+ }
+ m_focused = false;
}
void NavigatorVR::didAddEventListener(LocalDOMWindow* window,
@@ -138,7 +161,7 @@ void NavigatorVR::didAddEventListener(LocalDOMWindow* window,
if (eventType == EventTypeNames::vrdisplayactivate &&
supplementable()->frame() && supplementable()->frame()->document() &&
Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) {
- controller()->setListeningForActivate(true);
+ controller()->setListeningForActivate(m_focused);
m_listeningForActivate = true;
} else if (eventType == EventTypeNames::vrdisplayconnect) {
// If the page is listening for connection events make sure we've created a

Powered by Google App Engine
This is Rietveld 408576698