Chromium Code Reviews| 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/PresentationController.h" | 18 #include "modules/presentation/PresentationController.h" |
| 19 #include "modules/presentation/PresentationSessionClientCallbacks.h" | 19 #include "modules/presentation/PresentationSessionClientCallbacks.h" |
| 20 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" | 20 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 | 23 |
| 24 Presentation::Presentation(LocalFrame* frame) | 24 Presentation::Presentation(LocalFrame* frame) |
| 25 : DOMWindowProperty(frame) | 25 : DOMWindowProperty(frame) |
| 26 { | 26 { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 PresentationController* controller = presentationController(); | 88 PresentationController* controller = presentationController(); |
| 89 if (!controller) { | 89 if (!controller) { |
| 90 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer attached to the frame.")); | 90 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer attached to the frame.")); |
| 91 return promise; | 91 return promise; |
| 92 } | 92 } |
| 93 controller->joinSession(presentationUrl, presentationId, new PresentationSes sionClientCallbacks(resolver, this)); | 93 controller->joinSession(presentationUrl, presentationId, new PresentationSes sionClientCallbacks(resolver, this)); |
| 94 | 94 |
| 95 return promise; | 95 return promise; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev entListener> listener, bool useCapture) | 98 ScriptPromise Presentation::getAvailability(ScriptState* state, const String& pr esentationUrl) |
| 99 { | 99 { |
| 100 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 100 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(state); |
| 101 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE ventListener(eventType, listener, useCapture)) | 101 ScriptPromise promise = resolver->promise(); |
| 102 return false; | |
| 103 | 102 |
| 104 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners ) { | 103 PresentationController* controller = presentationController(); |
| 105 PresentationController* controller = presentationController(); | 104 if (!controller) { |
| 106 if (controller) | 105 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer attached to the frame.")); |
|
whywhat
2015/07/02 22:32:37
nit: If we have the same check in other methods, s
mlamouri (slow - plz ping)
2015/07/03 13:58:26
I will look into refactoring in a follow-up. This
| |
| 107 controller->updateAvailableChangeWatched(true); | 106 return promise; |
| 108 } | 107 } |
| 108 controller->getAvailability(presentationUrl, new CallbackPromiseAdapter<bool , void>(resolver)); | |
|
whywhat
2015/07/02 22:32:37
so bool means this implements Promise<bool> rather
mlamouri (slow - plz ping)
2015/07/03 13:58:26
Oouups. That was meant to be temporary :) Fixed. P
| |
| 109 | 109 |
| 110 return true; | 110 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 } | 111 } |
| 149 | 112 |
| 150 void Presentation::didStartDefaultSession(PresentationSession* session) | 113 void Presentation::didStartDefaultSession(PresentationSession* session) |
| 151 { | 114 { |
| 152 dispatchEvent(DefaultSessionStartEvent::create(EventTypeNames::defaultsessio nstart, session)); | 115 dispatchEvent(DefaultSessionStartEvent::create(EventTypeNames::defaultsessio nstart, session)); |
| 153 } | 116 } |
| 154 | 117 |
| 155 void Presentation::didChangeSessionState(WebPresentationSessionClient* sessionCl ient, WebPresentationSessionState sessionState) | 118 void Presentation::didChangeSessionState(WebPresentationSessionClient* sessionCl ient, WebPresentationSessionState sessionState) |
| 156 { | 119 { |
| 157 PresentationSession* session = findSession(sessionClient); | 120 PresentationSession* session = findSession(sessionClient); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 185 PresentationSession* Presentation::findSession(WebPresentationSessionClient* ses sionClient) | 148 PresentationSession* Presentation::findSession(WebPresentationSessionClient* ses sionClient) |
| 186 { | 149 { |
| 187 for (const auto& session : m_openSessions) { | 150 for (const auto& session : m_openSessions) { |
| 188 if (session->matches(sessionClient)) | 151 if (session->matches(sessionClient)) |
| 189 return session.get(); | 152 return session.get(); |
| 190 } | 153 } |
| 191 return nullptr; | 154 return nullptr; |
| 192 } | 155 } |
| 193 | 156 |
| 194 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |