| 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/Document.h" |
| 13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
| 15 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
| 16 #include "modules/presentation/AvailableChangeEvent.h" | 16 #include "modules/presentation/AvailableChangeEvent.h" |
| 17 #include "modules/presentation/PresentationController.h" | 17 #include "modules/presentation/PresentationController.h" |
| 18 #include "modules/presentation/PresentationSessionClientCallbacks.h" |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 | 21 |
| 21 Presentation::Presentation(LocalFrame* frame) | 22 Presentation::Presentation(LocalFrame* frame) |
| 22 : DOMWindowProperty(frame) | 23 : DOMWindowProperty(frame) |
| 23 { | 24 { |
| 24 } | 25 } |
| 25 | 26 |
| 26 Presentation::~Presentation() | 27 Presentation::~Presentation() |
| 27 { | 28 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 ExecutionContext* Presentation::executionContext() const | 46 ExecutionContext* Presentation::executionContext() const |
| 46 { | 47 { |
| 47 if (!frame()) | 48 if (!frame()) |
| 48 return nullptr; | 49 return nullptr; |
| 49 return frame()->document(); | 50 return frame()->document(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 DEFINE_TRACE(Presentation) | 53 DEFINE_TRACE(Presentation) |
| 53 { | 54 { |
| 54 visitor->trace(m_session); | 55 visitor->trace(m_session); |
| 56 visitor->trace(m_openSessions); |
| 55 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::trace(vis
itor); | 57 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::trace(vis
itor); |
| 56 DOMWindowProperty::trace(visitor); | 58 DOMWindowProperty::trace(visitor); |
| 57 } | 59 } |
| 58 | 60 |
| 59 PresentationSession* Presentation::session() const | 61 PresentationSession* Presentation::session() const |
| 60 { | 62 { |
| 61 return m_session.get(); | 63 return m_session.get(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 ScriptPromise Presentation::startSession(ScriptState* state, const String& prese
ntationUrl, const String& presentationId) | 66 ScriptPromise Presentation::startSession(ScriptState* state, const String& prese
ntationUrl, const String& presentationId) |
| 65 { | 67 { |
| 66 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); | 68 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); |
| 67 ScriptPromise promise = resolver->promise(); | 69 ScriptPromise promise = resolver->promise(); |
| 68 resolver->reject(DOMException::create(NotSupportedError, "The method is not
supported yet.")); | 70 |
| 71 PresentationController* controller = presentationController(); |
| 72 if (!controller) { |
| 73 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer attached to the frame.")); |
| 74 return promise; |
| 75 } |
| 76 controller->startSession(presentationUrl, presentationId, new PresentationSe
ssionClientCallbacks(resolver, this)); |
| 77 |
| 69 return promise; | 78 return promise; |
| 70 } | 79 } |
| 71 | 80 |
| 72 ScriptPromise Presentation::joinSession(ScriptState* state, const String& presen
tationUrl, const String& presentationId) | 81 ScriptPromise Presentation::joinSession(ScriptState* state, const String& presen
tationUrl, const String& presentationId) |
| 73 { | 82 { |
| 74 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); | 83 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); |
| 75 ScriptPromise promise = resolver->promise(); | 84 ScriptPromise promise = resolver->promise(); |
| 76 resolver->reject(DOMException::create(NotSupportedError, "The method is not
supported yet.")); | 85 |
| 86 PresentationController* controller = presentationController(); |
| 87 if (!controller) { |
| 88 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer attached to the frame.")); |
| 89 return promise; |
| 90 } |
| 91 controller->joinSession(presentationUrl, presentationId, new PresentationSes
sionClientCallbacks(resolver, this)); |
| 92 |
| 77 return promise; | 93 return promise; |
| 78 } | 94 } |
| 79 | 95 |
| 80 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev
entListener> listener, bool useCapture) | 96 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev
entListener> listener, bool useCapture) |
| 81 { | 97 { |
| 82 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 98 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); |
| 83 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE
ventListener(eventType, listener, useCapture)) | 99 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE
ventListener(eventType, listener, useCapture)) |
| 84 return false; | 100 return false; |
| 85 | 101 |
| 86 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners
) { | 102 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners
) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 void Presentation::didChangeAvailability(bool available) | 138 void Presentation::didChangeAvailability(bool available) |
| 123 { | 139 { |
| 124 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange,
available)); | 140 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange,
available)); |
| 125 } | 141 } |
| 126 | 142 |
| 127 bool Presentation::isAvailableChangeWatched() const | 143 bool Presentation::isAvailableChangeWatched() const |
| 128 { | 144 { |
| 129 return hasEventListeners(EventTypeNames::availablechange); | 145 return hasEventListeners(EventTypeNames::availablechange); |
| 130 } | 146 } |
| 131 | 147 |
| 148 void Presentation::didCreateSession(PresentationSession* session) |
| 149 { |
| 150 m_openSessions.add(session); |
| 151 } |
| 152 |
| 132 PresentationController* Presentation::presentationController() | 153 PresentationController* Presentation::presentationController() |
| 133 { | 154 { |
| 134 if (!frame()) | 155 if (!frame()) |
| 135 return nullptr; | 156 return nullptr; |
| 136 return PresentationController::from(*frame()); | 157 return PresentationController::from(*frame()); |
| 137 } | 158 } |
| 138 | 159 |
| 139 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |