Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1521)

Unified Diff: Source/modules/presentation/Presentation.cpp

Issue 974993002: [Presentation API] Added the DefaultPresentationStart event and parsing of the default presentation… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Default implementation for the new WebPresentationClient method Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/presentation/Presentation.cpp
diff --git a/Source/modules/presentation/Presentation.cpp b/Source/modules/presentation/Presentation.cpp
index 6213d4f13505572dec88ee06057941372f2fe0df..f8c23793164f8ce08199999066bb62ba88d28ff9 100644
--- a/Source/modules/presentation/Presentation.cpp
+++ b/Source/modules/presentation/Presentation.cpp
@@ -14,11 +14,32 @@
#include "core/frame/LocalFrame.h"
#include "modules/EventTargetModules.h"
#include "modules/presentation/AvailableChangeEvent.h"
+#include "modules/presentation/DefaultPresentationStartEvent.h"
#include "modules/presentation/PresentationController.h"
#include "modules/presentation/PresentationSessionClientCallbacks.h"
namespace blink {
+struct PresentationEventInfo {
+ using EventWatcherUpdateFunc = void (PresentationController::*)(bool);
+
+ AtomicString eventType;
+ EventWatcherUpdateFunc updateFunc;
+};
+
+// Maps the event type to the corresponding update method of PresentationController.
+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
+{
+ static PresentationEventInfo eventInfos[] = {
+ { EventTypeNames::availablechange, &PresentationController::updateAvailableChangeWatched },
Peter Beverloo 2015/03/03 21:19:25 You're introducing a static initializer here. Pre
whywhat 2015/03/05 18:41:47 Acknowledged.
+ { EventTypeNames::defaultpresentationstart, &PresentationController::updateDefaultPresentationStartWatched },
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.
+ };
+ length = WTF_ARRAY_LENGTH(eventInfos);
+
+ return eventInfos;
+}
+
+
Peter Beverloo 2015/03/03 21:19:25 nit: double blank line
whywhat 2015/03/05 18:41:47 Done.
Presentation::Presentation(LocalFrame* frame)
: DOMWindowProperty(frame)
{
@@ -95,44 +116,74 @@ ScriptPromise Presentation::joinSession(ScriptState* state, const String& presen
bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
{
- bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
- if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addEventListener(eventType, listener, useCapture))
- return false;
+ unsigned length = 0;
+ 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.
- if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners) {
- PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(true);
+ for (unsigned i = 0; i < length; ++i) {
+ PresentationEventInfo& eventInfo = eventInfos[i];
+ if (eventInfo.eventType != eventType)
+ continue;
+
+ bool hadEventListeners = hasEventListeners(eventType);
+ if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addEventListener(eventType, listener, useCapture))
+ return false;
+
+ if (hasEventListeners(eventType) && !hadEventListeners) {
+ PresentationController* controller = presentationController();
+ if (controller)
+ (controller->*eventInfo.updateFunc)(true);
+ }
+
+ return true;
}
- return true;
+ return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addEventListener(eventType, listener, useCapture);
}
bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
{
- bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
- if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeEventListener(eventType, listener, useCapture))
- return false;
+ unsigned length = 0;
+ PresentationEventInfo* eventInfos = presentationEventInfos(length);
- if (hadEventListeners && !hasEventListeners(EventTypeNames::availablechange)) {
- PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(false);
+ for (unsigned i = 0; i < length; ++i) {
+ PresentationEventInfo& eventInfo = eventInfos[i];
+ if (eventInfo.eventType != eventType)
+ continue;
+
+ bool hadEventListeners = hasEventListeners(eventType);
+ if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeEventListener(eventType, listener, useCapture))
+ return false;
+
+ if (hadEventListeners && !hasEventListeners(eventType)) {
+ PresentationController* controller = presentationController();
+ if (controller)
+ (controller->*eventInfo.updateFunc)(false);
+ }
+
+ return true;
}
- return true;
+ return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeEventListener(eventType, listener, useCapture);
}
void Presentation::removeAllEventListeners()
{
- bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
- RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAllEventListeners();
+ unsigned length = 0;
+ PresentationEventInfo* eventInfos = presentationEventInfos(length);
+
+ for (unsigned i = 0; i < length; ++i) {
+ PresentationEventInfo& eventInfo = eventInfos[i];
+ if (!hasEventListeners(eventInfo.eventType))
+ continue;
- if (hadEventListeners) {
PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(false);
+ if (!controller)
+ continue;
+
+ (controller->*eventInfo.updateFunc)(false);
}
+
+ RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAllEventListeners();
}
void Presentation::didChangeAvailability(bool available)
@@ -145,6 +196,16 @@ bool Presentation::isAvailableChangeWatched() const
return hasEventListeners(EventTypeNames::availablechange);
}
+void Presentation::didStartDefaultPresentation(PresentationSession* session)
+{
+ dispatchEvent(DefaultPresentationStartEvent::create(EventTypeNames::defaultpresentationstart, session));
+}
+
+bool Presentation::isDefaultPresentationStartWatched() const
+{
+ return hasEventListeners(EventTypeNames::defaultpresentationstart);
+}
+
void Presentation::registerSession(PresentationSession* session)
{
m_openSessions.add(session);

Powered by Google App Engine
This is Rietveld 408576698