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

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

Issue 1222623003: Presentation API: implement .getAvalability() (Blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 6ef6307c8934a53802f313219dcca8a74892fc89..ea42f9126ef4979c3fdd6492efea87882a93082c 100644
--- a/Source/modules/presentation/Presentation.cpp
+++ b/Source/modules/presentation/Presentation.cpp
@@ -5,6 +5,7 @@
#include "config.h"
#include "modules/presentation/Presentation.h"
+#include "bindings/core/v8/CallbackPromiseAdapter.h"
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
@@ -13,7 +14,6 @@
#include "core/dom/ExceptionCode.h"
#include "core/frame/LocalFrame.h"
#include "modules/EventTargetModules.h"
-#include "modules/presentation/AvailableChangeEvent.h"
#include "modules/presentation/DefaultSessionStartEvent.h"
#include "modules/presentation/PresentationController.h"
#include "modules/presentation/PresentationSessionClientCallbacks.h"
@@ -95,56 +95,19 @@ ScriptPromise Presentation::joinSession(ScriptState* state, const String& presen
return promise;
}
-bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
+ScriptPromise Presentation::getAvailability(ScriptState* state, const String& presentationUrl)
{
- bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
- if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addEventListener(eventType, listener, useCapture))
- return false;
-
- if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners) {
- PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(true);
- }
-
- return true;
-}
-
-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;
-
- if (hadEventListeners && !hasEventListeners(EventTypeNames::availablechange)) {
- PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(false);
- }
-
- return true;
-}
-
-void Presentation::removeAllEventListeners()
-{
- bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
- RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAllEventListeners();
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state);
+ ScriptPromise promise = resolver->promise();
- if (hadEventListeners) {
- PresentationController* controller = presentationController();
- if (controller)
- controller->updateAvailableChangeWatched(false);
+ PresentationController* controller = presentationController();
+ if (!controller) {
+ 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
+ return promise;
}
-}
-
-void Presentation::didChangeAvailability(bool available)
-{
- dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available));
-}
+ 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
-bool Presentation::isAvailableChangeWatched() const
-{
- return hasEventListeners(EventTypeNames::availablechange);
+ return promise;
}
void Presentation::didStartDefaultSession(PresentationSession* session)

Powered by Google App Engine
This is Rietveld 408576698