OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/vr/NavigatorVR.h" | 5 #include "modules/vr/NavigatorVR.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/frame/FrameOwner.h" | |
11 #include "core/frame/LocalDOMWindow.h" | 12 #include "core/frame/LocalDOMWindow.h" |
12 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
13 #include "core/frame/Navigator.h" | 14 #include "core/frame/Navigator.h" |
14 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
15 #include "modules/vr/VRController.h" | 16 #include "modules/vr/VRController.h" |
16 #include "modules/vr/VRDisplay.h" | 17 #include "modules/vr/VRDisplay.h" |
17 #include "modules/vr/VRGetDevicesCallback.h" | 18 #include "modules/vr/VRGetDevicesCallback.h" |
18 #include "modules/vr/VRPose.h" | 19 #include "modules/vr/VRPose.h" |
19 #include "wtf/PtrUtil.h" | 20 #include "wtf/PtrUtil.h" |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
24 // https://html.spec.whatwg.org/multipage/embedded-content.html#allowed-to-use | |
25 bool NavigatorVR::allowedToUseVR(const Frame* frame) | |
26 { | |
27 // To determine whether a Document object |document| is allowed to use the | |
28 // feature indicated by attribute name |allowattribute|, run these steps: | |
29 | |
30 // 1. If |document| has no browsing context, then return false. | |
31 if (!frame) | |
32 return false; | |
33 | |
34 // 2. If |document|'s browsing context has no browsing context container, th en | |
35 // return true. | |
36 if (frame->isMainFrame()) | |
37 return true; | |
38 | |
39 // 3. If |document|'s browsing context has a browsing context container that | |
40 // is an iframe element with an |allowattribute| attribute specified, and | |
41 // whose node document is allowed to use the feature indicated by | |
42 // |allowattribute|, then return true. | |
43 if (frame->owner() && frame->owner()->allowVR()) | |
44 return allowedToUseVR(frame->tree().parent()); | |
45 | |
46 // 4. Return false. | |
47 return false; | |
48 } | |
49 | |
23 NavigatorVR* NavigatorVR::from(Document& document) | 50 NavigatorVR* NavigatorVR::from(Document& document) |
24 { | 51 { |
25 if (!document.frame() || !document.frame()->domWindow()) | 52 if (!document.frame() || !document.frame()->domWindow()) |
26 return 0; | 53 return 0; |
27 Navigator& navigator = *document.frame()->domWindow()->navigator(); | 54 Navigator& navigator = *document.frame()->domWindow()->navigator(); |
28 return &from(navigator); | 55 return &from(navigator); |
29 } | 56 } |
30 | 57 |
31 NavigatorVR& NavigatorVR::from(Navigator& navigator) | 58 NavigatorVR& NavigatorVR::from(Navigator& navigator) |
32 { | 59 { |
33 NavigatorVR* supplement = static_cast<NavigatorVR*>(Supplement<Navigator>::f rom(navigator, supplementName())); | 60 NavigatorVR* supplement = static_cast<NavigatorVR*>(Supplement<Navigator>::f rom(navigator, supplementName())); |
34 if (!supplement) { | 61 if (!supplement) { |
35 supplement = new NavigatorVR(navigator.frame()); | 62 supplement = new NavigatorVR(navigator.frame()); |
36 provideTo(navigator, supplementName(), supplement); | 63 provideTo(navigator, supplementName(), supplement); |
37 } | 64 } |
38 return *supplement; | 65 return *supplement; |
39 } | 66 } |
40 | 67 |
41 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState, Navigator& na vigator) | 68 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState, Navigator& na vigator) |
42 { | 69 { |
43 return NavigatorVR::from(navigator).getVRDisplays(scriptState); | 70 return NavigatorVR::from(navigator).getVRDisplays(scriptState); |
44 } | 71 } |
45 | 72 |
46 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) | 73 ScriptPromise NavigatorVR::getVRDisplays(ScriptState* scriptState) |
47 { | 74 { |
48 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 75 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
49 ScriptPromise promise = resolver->promise(); | 76 ScriptPromise promise = resolver->promise(); |
50 | 77 |
78 if (!allowedToUseVR(m_frame)) { | |
79 DOMException* exception = DOMException::create(NotAllowedError, "Access to VR devices is not allowed in this context."); | |
80 resolver->reject(exception); | |
81 return promise; | |
82 } | |
83 | |
51 Document* document = m_frame ? m_frame->document() : 0; | 84 Document* document = m_frame ? m_frame->document() : 0; |
52 | 85 |
53 if (!document || !controller()) { | 86 if (!document || !controller()) { |
54 DOMException* exception = DOMException::create(InvalidStateError, "The o bject is no longer associated to a document."); | 87 DOMException* exception = DOMException::create(InvalidStateError, "The o bject is no longer associated to a document."); |
55 resolver->reject(exception); | 88 resolver->reject(exception); |
56 return promise; | 89 return promise; |
57 } | 90 } |
58 | 91 |
59 controller()->getDisplays(resolver); | 92 controller()->getDisplays(resolver); |
60 | 93 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 | 126 |
94 NavigatorVR::~NavigatorVR() | 127 NavigatorVR::~NavigatorVR() |
95 { | 128 { |
96 } | 129 } |
97 | 130 |
98 const char* NavigatorVR::supplementName() | 131 const char* NavigatorVR::supplementName() |
99 { | 132 { |
100 return "NavigatorVR"; | 133 return "NavigatorVR"; |
101 } | 134 } |
102 | 135 |
103 void NavigatorVR::fireVRDisplayPresentChange(VRDisplay* display) | 136 void NavigatorVR::fireVRDisplayPresentChange(VRDisplay* display) |
alexmos
2016/09/23 00:53:31
The spec mentions that VR events should also not b
| |
104 { | 137 { |
105 if (m_frame && m_frame->localDOMWindow()) { | 138 if (m_frame && m_frame->localDOMWindow()) { |
106 m_frame->localDOMWindow()->enqueueWindowEvent( | 139 m_frame->localDOMWindow()->enqueueWindowEvent( |
107 VRDisplayEvent::create(EventTypeNames::vrdisplaypresentchange, true, false, display, "")); | 140 VRDisplayEvent::create(EventTypeNames::vrdisplaypresentchange, true, false, display, "")); |
108 } | 141 } |
109 } | 142 } |
110 | 143 |
111 } // namespace blink | 144 } // namespace blink |
OLD | NEW |