| 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/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/Document.h" | 13 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/frame/LocalFrame.h" | 15 #include "core/frame/LocalFrame.h" |
| 15 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
| 16 #include "modules/presentation/AvailableChangeEvent.h" | |
| 17 #include "modules/presentation/DefaultSessionStartEvent.h" | 17 #include "modules/presentation/DefaultSessionStartEvent.h" |
| 18 #include "modules/presentation/PresentationAvailabilityCallback.h" |
| 18 #include "modules/presentation/PresentationController.h" | 19 #include "modules/presentation/PresentationController.h" |
| 19 #include "modules/presentation/PresentationSessionClientCallbacks.h" | 20 #include "modules/presentation/PresentationSessionClientCallbacks.h" |
| 20 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" | 21 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" |
| 21 | 22 |
| 22 namespace blink { | 23 namespace blink { |
| 23 | 24 |
| 24 Presentation::Presentation(LocalFrame* frame) | 25 Presentation::Presentation(LocalFrame* frame) |
| 25 : DOMWindowProperty(frame) | 26 : DOMWindowProperty(frame) |
| 26 { | 27 { |
| 27 } | 28 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 PresentationController* controller = presentationController(); | 89 PresentationController* controller = presentationController(); |
| 89 if (!controller) { | 90 if (!controller) { |
| 90 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer attached to the frame.")); | 91 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer attached to the frame.")); |
| 91 return promise; | 92 return promise; |
| 92 } | 93 } |
| 93 controller->joinSession(presentationUrl, presentationId, new PresentationSes
sionClientCallbacks(resolver, this)); | 94 controller->joinSession(presentationUrl, presentationId, new PresentationSes
sionClientCallbacks(resolver, this)); |
| 94 | 95 |
| 95 return promise; | 96 return promise; |
| 96 } | 97 } |
| 97 | 98 |
| 98 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev
entListener> listener, bool useCapture) | 99 ScriptPromise Presentation::getAvailability(ScriptState* state, const String& pr
esentationUrl) |
| 99 { | 100 { |
| 100 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 101 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); |
| 101 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE
ventListener(eventType, listener, useCapture)) | 102 ScriptPromise promise = resolver->promise(); |
| 102 return false; | |
| 103 | 103 |
| 104 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners
) { | 104 PresentationController* controller = presentationController(); |
| 105 PresentationController* controller = presentationController(); | 105 if (!controller) { |
| 106 if (controller) | 106 resolver->reject(DOMException::create(InvalidStateError, "The object is
no longer attached to the frame.")); |
| 107 controller->updateAvailableChangeWatched(true); | 107 return promise; |
| 108 } | 108 } |
| 109 controller->getAvailability(presentationUrl, new PresentationAvailabilityCal
lback(resolver)); |
| 109 | 110 |
| 110 return true; | 111 return promise; |
| 111 } | |
| 112 | |
| 113 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr
<EventListener> listener, bool useCapture) | |
| 114 { | |
| 115 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | |
| 116 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::remo
veEventListener(eventType, listener, useCapture)) | |
| 117 return false; | |
| 118 | |
| 119 if (hadEventListeners && !hasEventListeners(EventTypeNames::availablechange)
) { | |
| 120 PresentationController* controller = presentationController(); | |
| 121 if (controller) | |
| 122 controller->updateAvailableChangeWatched(false); | |
| 123 } | |
| 124 | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 void Presentation::removeAllEventListeners() | |
| 129 { | |
| 130 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | |
| 131 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAll
EventListeners(); | |
| 132 | |
| 133 if (hadEventListeners) { | |
| 134 PresentationController* controller = presentationController(); | |
| 135 if (controller) | |
| 136 controller->updateAvailableChangeWatched(false); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void Presentation::didChangeAvailability(bool available) | |
| 141 { | |
| 142 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange,
available)); | |
| 143 } | |
| 144 | |
| 145 bool Presentation::isAvailableChangeWatched() const | |
| 146 { | |
| 147 return hasEventListeners(EventTypeNames::availablechange); | |
| 148 } | 112 } |
| 149 | 113 |
| 150 void Presentation::didStartDefaultSession(PresentationSession* session) | 114 void Presentation::didStartDefaultSession(PresentationSession* session) |
| 151 { | 115 { |
| 152 dispatchEvent(DefaultSessionStartEvent::create(EventTypeNames::defaultsessio
nstart, session)); | 116 dispatchEvent(DefaultSessionStartEvent::create(EventTypeNames::defaultsessio
nstart, session)); |
| 153 } | 117 } |
| 154 | 118 |
| 155 void Presentation::didChangeSessionState(WebPresentationSessionClient* sessionCl
ient, WebPresentationSessionState sessionState) | 119 void Presentation::didChangeSessionState(WebPresentationSessionClient* sessionCl
ient, WebPresentationSessionState sessionState) |
| 156 { | 120 { |
| 157 PresentationSession* session = findSession(sessionClient); | 121 PresentationSession* session = findSession(sessionClient); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 185 PresentationSession* Presentation::findSession(WebPresentationSessionClient* ses
sionClient) | 149 PresentationSession* Presentation::findSession(WebPresentationSessionClient* ses
sionClient) |
| 186 { | 150 { |
| 187 for (const auto& session : m_openSessions) { | 151 for (const auto& session : m_openSessions) { |
| 188 if (session->matches(sessionClient)) | 152 if (session->matches(sessionClient)) |
| 189 return session.get(); | 153 return session.get(); |
| 190 } | 154 } |
| 191 return nullptr; | 155 return nullptr; |
| 192 } | 156 } |
| 193 | 157 |
| 194 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |