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

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

Issue 2703283003: Gracefully handle navigator.getVRDisplays() in detached contexts. (Closed)
Patch Set: Created 3 years, 10 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 | « third_party/WebKit/LayoutTests/vr/getVRDisplays_detached.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9afab6780516d62c816cc3c292538588cb1a6a1d..10b97ce59f8527b26ffad074ea52ec5c95d802b0 100644
--- a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp
+++ b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp
@@ -25,9 +25,19 @@
namespace blink {
+namespace {
+
+void rejectNavigatorDetached(ScriptPromiseResolver* resolver) {
+ DOMException* exception = DOMException::create(
+ InvalidStateError, "The object is no longer associated with a document.");
+ resolver->reject(exception);
+}
+
+} // namespace
+
NavigatorVR* NavigatorVR::from(Document& document) {
if (!document.frame() || !document.frame()->domWindow())
- return 0;
+ return nullptr;
Navigator& navigator = *document.frame()->domWindow()->navigator();
return &from(navigator);
}
@@ -44,6 +54,13 @@ NavigatorVR& NavigatorVR::from(Navigator& navigator) {
ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState,
Navigator& navigator) {
+ if (!navigator.frame()) {
+ ScriptPromiseResolver* resolver =
+ ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
mthiesse 2017/02/21 15:19:27 nit: Why not remove this line, and return resolver
sof 2017/02/21 15:29:12 You have to call promise() before rejecting/resolv
+ rejectNavigatorDetached(resolver);
+ return promise;
+ }
return NavigatorVR::from(navigator).getVRDisplays(scriptState);
}
@@ -52,9 +69,7 @@ ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) {
ScriptPromise promise = resolver->promise();
if (!document()) {
- DOMException* exception = DOMException::create(
- InvalidStateError, "The object is no longer associated to a document.");
- resolver->reject(exception);
+ rejectNavigatorDetached(resolver);
return promise;
}
@@ -73,7 +88,7 @@ ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) {
VRController* NavigatorVR::controller() {
if (!supplementable()->frame())
- return 0;
+ return nullptr;
if (!m_controller) {
m_controller = new VRController(this);
@@ -85,8 +100,10 @@ VRController* NavigatorVR::controller() {
}
Document* NavigatorVR::document() {
- return supplementable()->frame() ? supplementable()->frame()->document()
- : nullptr;
+ if (!supplementable()->frame())
+ return nullptr;
+
+ return supplementable()->frame()->document();
}
DEFINE_TRACE(NavigatorVR) {
@@ -108,14 +125,16 @@ const char* NavigatorVR::supplementName() {
}
void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) {
- if (supplementable()->frame()) {
- supplementable()->frame()->domWindow()->enqueueWindowEvent(event);
- }
+ if (!supplementable()->frame())
+ return;
+
+ supplementable()->frame()->domWindow()->enqueueWindowEvent(event);
}
void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) {
if (!(supplementable()->frame()))
return;
+
UserGestureIndicator gestureIndicator(
DocumentUserGestureToken::create(document()));
LocalDOMWindow* window = supplementable()->frame()->domWindow();
@@ -161,10 +180,11 @@ void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window,
}
void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) {
- if (m_controller) {
- m_controller->setListeningForActivate(false);
- m_listeningForActivate = false;
- }
+ if (!m_controller)
+ return;
+
+ m_controller->setListeningForActivate(false);
+ m_listeningForActivate = false;
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/LayoutTests/vr/getVRDisplays_detached.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698