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/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/DefaultPresentationStartEvent.h" | |
| 17 #include "modules/presentation/PresentationController.h" | 18 #include "modules/presentation/PresentationController.h" |
| 18 #include "modules/presentation/PresentationSessionClientCallbacks.h" | 19 #include "modules/presentation/PresentationSessionClientCallbacks.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 23 struct PresentationEventInfo { | |
| 24 using EventWatcherUpdateFunc = void (PresentationController::*)(bool); | |
| 25 | |
| 26 AtomicString eventType; | |
| 27 EventWatcherUpdateFunc updateFunc; | |
| 28 }; | |
| 29 | |
| 30 // Maps the event type to the corresponding update method of PresentationControl ler. | |
| 31 static PresentationEventInfo* presentationEventInfos(unsigned& length) | |
|
Peter Beverloo
2015/03/03 21:19:25
nit: unsigned int? Not strictly required (yet), bu
whywhat
2015/03/05 18:41:47
Removed
| |
| 32 { | |
| 33 static PresentationEventInfo eventInfos[] = { | |
| 34 { EventTypeNames::availablechange, &PresentationController::updateAvaila bleChangeWatched }, | |
|
Peter Beverloo
2015/03/03 21:19:25
You're introducing a static initializer here.
Pre
whywhat
2015/03/05 18:41:47
Acknowledged.
| |
| 35 { EventTypeNames::defaultpresentationstart, &PresentationController::upd ateDefaultPresentationStartWatched }, | |
|
Peter Beverloo
2015/03/03 21:19:25
How many events do you expect to have in the end?
whywhat
2015/03/05 18:41:47
Acknowledged.
| |
| 36 }; | |
| 37 length = WTF_ARRAY_LENGTH(eventInfos); | |
| 38 | |
| 39 return eventInfos; | |
| 40 } | |
| 41 | |
| 42 | |
|
Peter Beverloo
2015/03/03 21:19:25
nit: double blank line
whywhat
2015/03/05 18:41:47
Done.
| |
| 22 Presentation::Presentation(LocalFrame* frame) | 43 Presentation::Presentation(LocalFrame* frame) |
| 23 : DOMWindowProperty(frame) | 44 : DOMWindowProperty(frame) |
| 24 { | 45 { |
| 25 } | 46 } |
| 26 | 47 |
| 27 Presentation::~Presentation() | 48 Presentation::~Presentation() |
| 28 { | 49 { |
| 29 } | 50 } |
| 30 | 51 |
| 31 // static | 52 // static |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer attached to the frame.")); | 109 resolver->reject(DOMException::create(InvalidStateError, "The object is no longer attached to the frame.")); |
| 89 return promise; | 110 return promise; |
| 90 } | 111 } |
| 91 controller->joinSession(presentationUrl, presentationId, new PresentationSes sionClientCallbacks(resolver, this)); | 112 controller->joinSession(presentationUrl, presentationId, new PresentationSes sionClientCallbacks(resolver, this)); |
| 92 | 113 |
| 93 return promise; | 114 return promise; |
| 94 } | 115 } |
| 95 | 116 |
| 96 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev entListener> listener, bool useCapture) | 117 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev entListener> listener, bool useCapture) |
| 97 { | 118 { |
| 98 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 119 unsigned length = 0; |
| 99 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE ventListener(eventType, listener, useCapture)) | 120 PresentationEventInfo* eventInfos = presentationEventInfos(length); |
|
Peter Beverloo
2015/03/03 21:19:24
nit: may as well pass a pointer to presentationEve
whywhat
2015/03/05 18:41:47
Acknowledged.
| |
| 100 return false; | |
| 101 | 121 |
| 102 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners ) { | 122 for (unsigned i = 0; i < length; ++i) { |
| 103 PresentationController* controller = presentationController(); | 123 PresentationEventInfo& eventInfo = eventInfos[i]; |
| 104 if (controller) | 124 if (eventInfo.eventType != eventType) |
| 105 controller->updateAvailableChangeWatched(true); | 125 continue; |
| 126 | |
| 127 bool hadEventListeners = hasEventListeners(eventType); | |
| 128 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>:: addEventListener(eventType, listener, useCapture)) | |
| 129 return false; | |
| 130 | |
| 131 if (hasEventListeners(eventType) && !hadEventListeners) { | |
| 132 PresentationController* controller = presentationController(); | |
| 133 if (controller) | |
| 134 (controller->*eventInfo.updateFunc)(true); | |
| 135 } | |
| 136 | |
| 137 return true; | |
| 106 } | 138 } |
| 107 | 139 |
| 108 return true; | 140 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::ad dEventListener(eventType, listener, useCapture); |
| 109 } | 141 } |
| 110 | 142 |
| 111 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture) | 143 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture) |
| 112 { | 144 { |
| 113 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 145 unsigned length = 0; |
| 114 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::remo veEventListener(eventType, listener, useCapture)) | 146 PresentationEventInfo* eventInfos = presentationEventInfos(length); |
| 115 return false; | |
| 116 | 147 |
| 117 if (hadEventListeners && !hasEventListeners(EventTypeNames::availablechange) ) { | 148 for (unsigned i = 0; i < length; ++i) { |
| 118 PresentationController* controller = presentationController(); | 149 PresentationEventInfo& eventInfo = eventInfos[i]; |
| 119 if (controller) | 150 if (eventInfo.eventType != eventType) |
| 120 controller->updateAvailableChangeWatched(false); | 151 continue; |
| 152 | |
| 153 bool hadEventListeners = hasEventListeners(eventType); | |
| 154 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>:: removeEventListener(eventType, listener, useCapture)) | |
| 155 return false; | |
| 156 | |
| 157 if (hadEventListeners && !hasEventListeners(eventType)) { | |
| 158 PresentationController* controller = presentationController(); | |
| 159 if (controller) | |
| 160 (controller->*eventInfo.updateFunc)(false); | |
| 161 } | |
| 162 | |
| 163 return true; | |
| 121 } | 164 } |
| 122 | 165 |
| 123 return true; | 166 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::re moveEventListener(eventType, listener, useCapture); |
| 124 } | 167 } |
| 125 | 168 |
| 126 void Presentation::removeAllEventListeners() | 169 void Presentation::removeAllEventListeners() |
| 127 { | 170 { |
| 128 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange); | 171 unsigned length = 0; |
| 172 PresentationEventInfo* eventInfos = presentationEventInfos(length); | |
| 173 | |
| 174 for (unsigned i = 0; i < length; ++i) { | |
| 175 PresentationEventInfo& eventInfo = eventInfos[i]; | |
| 176 if (!hasEventListeners(eventInfo.eventType)) | |
| 177 continue; | |
| 178 | |
| 179 PresentationController* controller = presentationController(); | |
| 180 if (!controller) | |
| 181 continue; | |
| 182 | |
| 183 (controller->*eventInfo.updateFunc)(false); | |
| 184 } | |
| 185 | |
| 129 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAll EventListeners(); | 186 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAll EventListeners(); |
| 130 | |
| 131 if (hadEventListeners) { | |
| 132 PresentationController* controller = presentationController(); | |
| 133 if (controller) | |
| 134 controller->updateAvailableChangeWatched(false); | |
| 135 } | |
| 136 } | 187 } |
| 137 | 188 |
| 138 void Presentation::didChangeAvailability(bool available) | 189 void Presentation::didChangeAvailability(bool available) |
| 139 { | 190 { |
| 140 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available)); | 191 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available)); |
| 141 } | 192 } |
| 142 | 193 |
| 143 bool Presentation::isAvailableChangeWatched() const | 194 bool Presentation::isAvailableChangeWatched() const |
| 144 { | 195 { |
| 145 return hasEventListeners(EventTypeNames::availablechange); | 196 return hasEventListeners(EventTypeNames::availablechange); |
| 146 } | 197 } |
| 147 | 198 |
| 199 void Presentation::didStartDefaultPresentation(PresentationSession* session) | |
| 200 { | |
| 201 dispatchEvent(DefaultPresentationStartEvent::create(EventTypeNames::defaultp resentationstart, session)); | |
| 202 } | |
| 203 | |
| 204 bool Presentation::isDefaultPresentationStartWatched() const | |
| 205 { | |
| 206 return hasEventListeners(EventTypeNames::defaultpresentationstart); | |
| 207 } | |
| 208 | |
| 148 void Presentation::registerSession(PresentationSession* session) | 209 void Presentation::registerSession(PresentationSession* session) |
| 149 { | 210 { |
| 150 m_openSessions.add(session); | 211 m_openSessions.add(session); |
| 151 } | 212 } |
| 152 | 213 |
| 153 PresentationController* Presentation::presentationController() | 214 PresentationController* Presentation::presentationController() |
| 154 { | 215 { |
| 155 if (!frame()) | 216 if (!frame()) |
| 156 return nullptr; | 217 return nullptr; |
| 157 return PresentationController::from(*frame()); | 218 return PresentationController::from(*frame()); |
| 158 } | 219 } |
| 159 | 220 |
| 160 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |