| 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/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 PresentationController* controller = presentation->presentationController(); |
| 35 if (controller) |
| 36 controller->setPresentation(presentation); |
| 37 return presentation; |
| 30 } | 38 } |
| 31 | 39 |
| 32 const AtomicString& Presentation::interfaceName() const | 40 const AtomicString& Presentation::interfaceName() const |
| 33 { | 41 { |
| 34 return EventTargetNames::Presentation; | 42 return EventTargetNames::Presentation; |
| 35 } | 43 } |
| 36 | 44 |
| 37 ExecutionContext* Presentation::executionContext() const | 45 ExecutionContext* Presentation::executionContext() const |
| 38 { | 46 { |
| 39 return ContextLifecycleObserver::executionContext(); | 47 return ContextLifecycleObserver::executionContext(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 60 } | 68 } |
| 61 | 69 |
| 62 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender
Id, const String& presentationId) | 70 ScriptPromise Presentation::joinSession(ScriptState* state, const String& sender
Id, const String& presentationId) |
| 63 { | 71 { |
| 64 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); | 72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(state); |
| 65 ScriptPromise promise = resolver->promise(); | 73 ScriptPromise promise = resolver->promise(); |
| 66 resolver->reject(DOMException::create(NotSupportedError, "The method is not
supported yet.")); | 74 resolver->reject(DOMException::create(NotSupportedError, "The method is not
supported yet.")); |
| 67 return promise; | 75 return promise; |
| 68 } | 76 } |
| 69 | 77 |
| 78 bool Presentation::addEventListener(const AtomicString& eventType, PassRefPtr<Ev
entListener> listener, bool useCapture) |
| 79 { |
| 80 if (eventType == EventTypeNames::availablechange) { |
| 81 PresentationController* controller = presentationController(); |
| 82 if (controller) |
| 83 controller->addDeviceAvailabilityListener(); |
| 84 } |
| 85 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::ad
dEventListener(eventType, listener, useCapture); |
| 86 } |
| 87 |
| 88 bool Presentation::removeEventListener(const AtomicString& eventType, PassRefPtr
<EventListener> listener, bool useCapture) |
| 89 { |
| 90 if (eventType == EventTypeNames::availablechange) { |
| 91 PresentationController* controller = presentationController(); |
| 92 if (controller) |
| 93 controller->removeDeviceAvailabilityListener(); |
| 94 } |
| 95 return RefCountedGarbageCollectedEventTargetWithInlineData<Presentation>::re
moveEventListener(eventType, listener, useCapture); |
| 96 } |
| 97 |
| 98 void Presentation::didChangeAvailability(bool available) |
| 99 { |
| 100 dispatchEvent(AvailableChangeEvent::create(EventTypeNames::availablechange,
available)); |
| 101 } |
| 102 |
| 103 PresentationController* Presentation::presentationController() |
| 104 { |
| 105 Document* document = toDocument(executionContext()); |
| 106 if (!document) |
| 107 return nullptr; |
| 108 LocalFrame* frame = document->frame(); |
| 109 if (!frame) |
| 110 return nullptr; |
| 111 return PresentationController::from(*frame); |
| 112 } |
| 113 |
| 70 } // namespace blink | 114 } // namespace blink |
| OLD | NEW |