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

Side by Side 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: Changed the event listeners logic a bit. Addressed the comments. 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 unified diff | Download patch
OLDNEW
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/ExceptionCode.h" 13 #include "core/dom/ExceptionCode.h"
14 #include "core/frame/LocalFrame.h"
13 #include "modules/EventTargetModules.h" 15 #include "modules/EventTargetModules.h"
16 #include "modules/presentation/AvailableChangeEvent.h"
17 #include "modules/presentation/PresentationController.h"
14 18
15 namespace blink { 19 namespace blink {
16 20
17 Presentation::Presentation(ExecutionContext* executionContext) 21 Presentation::Presentation(ExecutionContext* executionContext)
18 : ContextLifecycleObserver(executionContext) 22 : ContextLifecycleObserver(executionContext)
19 { 23 {
20 } 24 }
21 25
22 Presentation::~Presentation() 26 Presentation::~Presentation()
23 { 27 {
24 } 28 }
25 29
26 // static 30 // static
27 Presentation* Presentation::create(ExecutionContext* executionContext) 31 Presentation* Presentation::create(ExecutionContext* executionContext)
28 { 32 {
29 return new Presentation(executionContext); 33 Presentation* presentation = new Presentation(executionContext);
34 presentation->presentationController()->setPresentation(presentation);
35 return presentation;
30 } 36 }
31 37
32 const AtomicString& Presentation::interfaceName() const 38 const AtomicString& Presentation::interfaceName() const
33 { 39 {
34 return EventTargetNames::Presentation; 40 return EventTargetNames::Presentation;
35 } 41 }
36 42
37 ExecutionContext* Presentation::executionContext() const 43 ExecutionContext* Presentation::executionContext() const
38 { 44 {
39 return ContextLifecycleObserver::executionContext(); 45 return ContextLifecycleObserver::executionContext();
(...skipping 20 matching lines...) Expand all
60 } 66 }
61 67
62 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender Id, const String& presentationId) 68 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender Id, const String& presentationId)
63 { 69 {
64 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(state); 70 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(state);
65 ScriptPromise promise = resolver->promise(); 71 ScriptPromise promise = resolver->promise();
66 resolver->reject(DOMException::create(NotSupportedError, "The method is not supported yet.")); 72 resolver->reject(DOMException::create(NotSupportedError, "The method is not supported yet."));
67 return promise; 73 return promise;
68 } 74 }
69 75
76 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev entListener> listener, bool useCapture)
77 {
78 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
79 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::addE ventListener(eventType, listener, useCapture))
80 return false;
81
82 if (hasEventListeners(EventTypeNames::availablechange) && !hadEventListeners )
83 presentationController()->updateAvailableChangeWatched(true);
84
85 return true;
86 }
87
88 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr <EventListener> listener, bool useCapture)
89 {
90 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
91 if (!RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::remo veEventListener(eventType, listener, useCapture))
92 return false;
93
94 if (hadEventListeners && !hasEventListeners(EventTypeNames::availablechange) )
95 presentationController()->updateAvailableChangeWatched(false);
96
97 return true;
98 }
99
100 void Presentation::removeAllEventListeners()
101 {
102 bool hadEventListeners = hasEventListeners(EventTypeNames::availablechange);
103 RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::removeAll EventListeners();
104
105 if (hadEventListeners)
106 presentationController()->updateAvailableChangeWatched(false);
107 }
108
109 void Presentation::didChangeAvailability(bool available)
110 {
111 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange, available));
112 }
113
114 PresentationController* Presentation::presentationController()
115 {
116 Document* document = toDocument(executionContext());
117 if (!document)
118 return nullptr;
119 LocalFrame* frame = document->frame();
120 if (!frame)
121 return nullptr;
122 PresentationController* controller = PresentationController::from(*frame);
123 ASSERT(controller);
124 return controller;
125 }
126
70 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698