OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "modules/presentation/Presentation.h" | 6 #include "modules/presentation/Presentation.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/Document.h" | |
12 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
14 #include "core/frame/LocalFrame.h" | |
13 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
16 #include "modules/presentation/AvailableChangeEvent.h" | |
17 #include "modules/presentation/PresentationController.h" | |
14 | 18 |
15 namespace blink { | 19 namespace blink { |
16 | 20 |
17 Presentation::Presentation(ExecutionContext* executionContext) | 21 Presentation::Presentation(ExecutionContext* executionContext) |
18 : ContextLifecycleObserver(executionContext) | 22 : ContextLifecycleObserver(executionContext) |
19 { | 23 { |
20 } | 24 } |
21 | 25 |
22 Presentation::~Presentation() | 26 Presentation::~Presentation() |
23 { | 27 { |
28 PresentationController* controller = presentationController(); | |
29 if (controller) | |
30 controller->setPresentation(nullptr); | |
24 } | 31 } |
25 | 32 |
26 // static | 33 // static |
27 Presentation* Presentation::create(ExecutionContext* executionContext) | 34 Presentation* Presentation::create(ExecutionContext* executionContext) |
28 { | 35 { |
29 return new Presentation(executionContext); | 36 Presentation* presentation = new Presentation(executionContext); |
37 PresentationController* controller = presentation->presentationController(); | |
38 if (controller) | |
39 controller->setPresentation(presentation); | |
Peter Beverloo
2015/01/07 14:29:08
When is it valid for the runtime Presentation flag
whywhat
2015/01/07 16:22:16
I imagined a hypothetical situation where the UA m
Peter Beverloo
2015/01/07 19:53:11
In that case we wouldn't enable the run-time flag,
whywhat
2015/01/08 16:05:28
Done.
| |
40 return presentation; | |
30 } | 41 } |
31 | 42 |
32 const AtomicString& Presentation::interfaceName() const | 43 const AtomicString& Presentation::interfaceName() const |
33 { | 44 { |
34 return EventTargetNames::Presentation; | 45 return EventTargetNames::Presentation; |
35 } | 46 } |
36 | 47 |
37 ExecutionContext* Presentation::executionContext() const | 48 ExecutionContext* Presentation::executionContext() const |
38 { | 49 { |
39 return ContextLifecycleObserver::executionContext(); | 50 return ContextLifecycleObserver::executionContext(); |
(...skipping 20 matching lines...) Expand all Loading... | |
60 } | 71 } |
61 | 72 |
62 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender Id, const String& presentationId) | 73 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender Id, const String& presentationId) |
63 { | 74 { |
64 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(state); | 75 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(state); |
65 ScriptPromise promise = resolver->promise(); | 76 ScriptPromise promise = resolver->promise(); |
66 resolver->reject(DOMException::create(NotSupportedError, "The method is not supported yet.")); | 77 resolver->reject(DOMException::create(NotSupportedError, "The method is not supported yet.")); |
67 return promise; | 78 return promise; |
68 } | 79 } |
69 | 80 |
81 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev entListener> listener, bool useCapture) | |
82 { | |
83 if (eventType == EventTypeNames::availablechange) { | |
84 PresentationController* controller = presentationController(); | |
85 if (controller) | |
86 controller->addDeviceAvailabilityListener(); | |
87 } | |
88 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::ad dEventListener(eventType, listener, useCapture); | |
89 } | |
90 | |
91 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture) | |
92 { | |
93 if (eventType == EventTypeNames::availablechange) { | |
94 PresentationController* controller = presentationController(); | |
95 if (controller) | |
96 controller->removeDeviceAvailabilityListener(); | |
97 } | |
98 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::re moveEventListener(eventType, listener, useCapture); | |
99 } | |
100 | |
101 void Presentation::deviceAvailabilityChanged(bool available) | |
Peter Beverloo
2015/01/07 14:29:08
Why is this called "deviceAvailabilityChanged" whi
whywhat
2015/01/07 16:22:16
Done.
| |
102 { | |
103 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available)); | |
104 } | |
105 | |
106 PresentationController* Presentation::presentationController() | |
107 { | |
108 if (!frame()) | |
Peter Beverloo
2015/01/07 14:29:08
Rather than having a separate frame() method, coul
whywhat
2015/01/07 16:22:16
Done.
| |
109 return nullptr; | |
110 return PresentationController::from(*frame()); | |
111 } | |
112 | |
113 LocalFrame* Presentation::frame() | |
114 { | |
115 Document* document = toDocument(executionContext()); | |
116 if (document) | |
117 return document->frame(); | |
118 return nullptr; | |
119 } | |
120 | |
70 } // namespace blink | 121 } // namespace blink |
OLD | NEW |