| 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 "modules/presentation/PresentationAvailability.h" | 5 #include "modules/presentation/PresentationAvailability.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
| 10 #include "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return nullptr; | 26 return nullptr; |
| 27 PresentationController* controller = PresentationController::from(*document-
>frame()); | 27 PresentationController* controller = PresentationController::from(*document-
>frame()); |
| 28 return controller ? controller->client() : nullptr; | 28 return controller ? controller->client() : nullptr; |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // anonymous namespace | 31 } // anonymous namespace |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 PresentationAvailability* PresentationAvailability::take(ScriptPromiseResolver*
resolver, const KURL& url, bool value) | 34 PresentationAvailability* PresentationAvailability::take(ScriptPromiseResolver*
resolver, const KURL& url, bool value) |
| 35 { | 35 { |
| 36 PresentationAvailability* presentationAvailability = new PresentationAvailab
ility(resolver->executionContext(), url, value); | 36 PresentationAvailability* presentationAvailability = new PresentationAvailab
ility(resolver->getExecutionContext(), url, value); |
| 37 presentationAvailability->suspendIfNeeded(); | 37 presentationAvailability->suspendIfNeeded(); |
| 38 presentationAvailability->updateListening(); | 38 presentationAvailability->updateListening(); |
| 39 return presentationAvailability; | 39 return presentationAvailability; |
| 40 } | 40 } |
| 41 | 41 |
| 42 PresentationAvailability::PresentationAvailability(ExecutionContext* executionCo
ntext, const KURL& url, bool value) | 42 PresentationAvailability::PresentationAvailability(ExecutionContext* executionCo
ntext, const KURL& url, bool value) |
| 43 : ActiveDOMObject(executionContext) | 43 : ActiveDOMObject(executionContext) |
| 44 , PageLifecycleObserver(toDocument(executionContext)->page()) | 44 , PageLifecycleObserver(toDocument(executionContext)->page()) |
| 45 , m_url(url) | 45 , m_url(url) |
| 46 , m_value(value) | 46 , m_value(value) |
| 47 , m_state(State::Active) | 47 , m_state(State::Active) |
| 48 { | 48 { |
| 49 ASSERT(executionContext->isDocument()); | 49 ASSERT(executionContext->isDocument()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 PresentationAvailability::~PresentationAvailability() | 52 PresentationAvailability::~PresentationAvailability() |
| 53 { | 53 { |
| 54 } | 54 } |
| 55 | 55 |
| 56 const AtomicString& PresentationAvailability::interfaceName() const | 56 const AtomicString& PresentationAvailability::interfaceName() const |
| 57 { | 57 { |
| 58 return EventTargetNames::PresentationAvailability; | 58 return EventTargetNames::PresentationAvailability; |
| 59 } | 59 } |
| 60 | 60 |
| 61 ExecutionContext* PresentationAvailability::executionContext() const | 61 ExecutionContext* PresentationAvailability::getExecutionContext() const |
| 62 { | 62 { |
| 63 return ActiveDOMObject::executionContext(); | 63 return ActiveDOMObject::getExecutionContext(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool PresentationAvailability::addEventListenerInternal(const AtomicString& even
tType, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOption
s& options) | 66 bool PresentationAvailability::addEventListenerInternal(const AtomicString& even
tType, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOption
s& options) |
| 67 { | 67 { |
| 68 if (eventType == EventTypeNames::change) | 68 if (eventType == EventTypeNames::change) |
| 69 UseCounter::count(executionContext(), UseCounter::PresentationAvailabili
tyChangeEventListener); | 69 UseCounter::count(getExecutionContext(), UseCounter::PresentationAvailab
ilityChangeEventListener); |
| 70 | 70 |
| 71 return EventTarget::addEventListenerInternal(eventType, listener, options); | 71 return EventTarget::addEventListenerInternal(eventType, listener, options); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PresentationAvailability::availabilityChanged(bool value) | 74 void PresentationAvailability::availabilityChanged(bool value) |
| 75 { | 75 { |
| 76 if (m_value == value) | 76 if (m_value == value) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 m_value = value; | 79 m_value = value; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 void PresentationAvailability::setState(State state) | 110 void PresentationAvailability::setState(State state) |
| 111 { | 111 { |
| 112 m_state = state; | 112 m_state = state; |
| 113 updateListening(); | 113 updateListening(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void PresentationAvailability::updateListening() | 116 void PresentationAvailability::updateListening() |
| 117 { | 117 { |
| 118 WebPresentationClient* client = presentationClient(executionContext()); | 118 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 119 if (!client) | 119 if (!client) |
| 120 return; | 120 return; |
| 121 | 121 |
| 122 if (m_state == State::Active && (toDocument(executionContext())->pageVisibil
ityState() == PageVisibilityStateVisible)) | 122 if (m_state == State::Active && (toDocument(getExecutionContext())->pageVisi
bilityState() == PageVisibilityStateVisible)) |
| 123 client->startListening(this); | 123 client->startListening(this); |
| 124 else | 124 else |
| 125 client->stopListening(this); | 125 client->stopListening(this); |
| 126 } | 126 } |
| 127 | 127 |
| 128 const WebURL PresentationAvailability::url() const | 128 const WebURL PresentationAvailability::url() const |
| 129 { | 129 { |
| 130 return WebURL(m_url); | 130 return WebURL(m_url); |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool PresentationAvailability::value() const | 133 bool PresentationAvailability::value() const |
| 134 { | 134 { |
| 135 return m_value; | 135 return m_value; |
| 136 } | 136 } |
| 137 | 137 |
| 138 DEFINE_TRACE(PresentationAvailability) | 138 DEFINE_TRACE(PresentationAvailability) |
| 139 { | 139 { |
| 140 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationAvailability
>::trace(visitor); | 140 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationAvailability
>::trace(visitor); |
| 141 PageLifecycleObserver::trace(visitor); | 141 PageLifecycleObserver::trace(visitor); |
| 142 ActiveDOMObject::trace(visitor); | 142 ActiveDOMObject::trace(visitor); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |