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

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

Issue 832263007: Added plumbing for the availablechange event from Blink to WebPresentationClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 93957fe0c91249fd3de4e7059667e4557ba7a0fc..b4a6da06f776fd5145f76394ea5a37fafcee062b 100644
--- a/Source/modules/presentation/Presentation.cpp
+++ b/Source/modules/presentation/Presentation.cpp
@@ -9,8 +9,12 @@
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMException.h"
+#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/frame/LocalFrame.h"
#include "modules/EventTargetModules.h"
+#include "modules/presentation/AvailableChangeEvent.h"
+#include "modules/presentation/PresentationController.h"
namespace blink {
@@ -21,12 +25,19 @@ Presentation::Presentation(ExecutionContext* executionContext)
Presentation::~Presentation()
{
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->setPresentation(nullptr);
}
// static
Presentation* Presentation::create(ExecutionContext* executionContext)
{
- return new Presentation(executionContext);
+ Presentation* presentation = new Presentation(executionContext);
+ PresentationController* controller = presentation->presentationController();
+ if (controller)
+ controller->setPresentation(presentation);
Peter Beverloo 2015/01/07 14:29:08 When is it valid for the runtime Presentation flag
whywhat 2015/01/07 16:22:16 I imagined a hypothetical situation where the UA m
Peter Beverloo 2015/01/07 19:53:11 In that case we wouldn't enable the run-time flag,
whywhat 2015/01/08 16:05:28 Done.
+ return presentation;
}
const AtomicString& Presentation::interfaceName() const
@@ -67,4 +78,44 @@ ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender
return promise;
}
+bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
+{
+ if (eventType == EventTypeNames::availablechange) {
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->addDeviceAvailabilityListener();
+ }
+ return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addEventListener(eventType, listener, useCapture);
+}
+
+bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
+{
+ if (eventType == EventTypeNames::availablechange) {
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->removeDeviceAvailabilityListener();
+ }
+ return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeEventListener(eventType, listener, useCapture);
+}
+
+void Presentation::deviceAvailabilityChanged(bool available)
Peter Beverloo 2015/01/07 14:29:08 Why is this called "deviceAvailabilityChanged" whi
whywhat 2015/01/07 16:22:16 Done.
+{
+ dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available));
+}
+
+PresentationController* Presentation::presentationController()
+{
+ if (!frame())
Peter Beverloo 2015/01/07 14:29:08 Rather than having a separate frame() method, coul
whywhat 2015/01/07 16:22:16 Done.
+ return nullptr;
+ return PresentationController::from(*frame());
+}
+
+LocalFrame* Presentation::frame()
+{
+ Document* document = toDocument(executionContext());
+ if (document)
+ return document->frame();
+ return nullptr;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698