| 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" |
| 11 #include "modules/EventTargetModulesNames.h" | 11 #include "modules/EventTargetModulesNames.h" |
| 12 #include "modules/presentation/PresentationController.h" | 12 #include "modules/presentation/PresentationController.h" |
| 13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 #include "public/platform/modules/presentation/WebPresentationClient.h" | 14 #include "public/platform/modules/presentation/WebPresentationClient.h" |
| 15 #include "wtf/Vector.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 WebPresentationClient* presentationClient(ExecutionContext* executionContext) { | 21 WebPresentationClient* presentationClient(ExecutionContext* executionContext) { |
| 21 if (!executionContext) | 22 if (!executionContext) |
| 22 return nullptr; | 23 return nullptr; |
| 23 DCHECK(executionContext->isDocument()); | 24 DCHECK(executionContext->isDocument()); |
| 24 Document* document = toDocument(executionContext); | 25 Document* document = toDocument(executionContext); |
| 25 if (!document->frame()) | 26 if (!document->frame()) |
| 26 return nullptr; | 27 return nullptr; |
| 27 PresentationController* controller = | 28 PresentationController* controller = |
| 28 PresentationController::from(*document->frame()); | 29 PresentationController::from(*document->frame()); |
| 29 return controller ? controller->client() : nullptr; | 30 return controller ? controller->client() : nullptr; |
| 30 } | 31 } |
| 31 | 32 |
| 32 } // anonymous namespace | 33 } // anonymous namespace |
| 33 | 34 |
| 34 // static | 35 // static |
| 35 PresentationAvailability* PresentationAvailability::take( | 36 PresentationAvailability* PresentationAvailability::take( |
| 36 PresentationAvailabilityProperty* resolver, | 37 PresentationAvailabilityProperty* resolver, |
| 37 const KURL& url, | 38 const WTF::Vector<KURL>& urls, |
| 38 bool value) { | 39 bool value) { |
| 39 PresentationAvailability* presentationAvailability = | 40 PresentationAvailability* presentationAvailability = |
| 40 new PresentationAvailability(resolver->getExecutionContext(), url, value); | 41 new PresentationAvailability(resolver->getExecutionContext(), urls, |
| 42 value); |
| 41 presentationAvailability->suspendIfNeeded(); | 43 presentationAvailability->suspendIfNeeded(); |
| 42 presentationAvailability->updateListening(); | 44 presentationAvailability->updateListening(); |
| 43 return presentationAvailability; | 45 return presentationAvailability; |
| 44 } | 46 } |
| 45 | 47 |
| 46 PresentationAvailability::PresentationAvailability( | 48 PresentationAvailability::PresentationAvailability( |
| 47 ExecutionContext* executionContext, | 49 ExecutionContext* executionContext, |
| 48 const KURL& url, | 50 const WTF::Vector<KURL>& urls, |
| 49 bool value) | 51 bool value) |
| 50 : SuspendableObject(executionContext), | 52 : SuspendableObject(executionContext), |
| 51 PageVisibilityObserver(toDocument(executionContext)->page()), | 53 PageVisibilityObserver(toDocument(executionContext)->page()), |
| 52 m_url(url), | 54 m_urls(urls), |
| 53 m_value(value), | 55 m_value(value), |
| 54 m_state(State::Active) { | 56 m_state(State::Active) { |
| 55 ASSERT(executionContext->isDocument()); | 57 ASSERT(executionContext->isDocument()); |
| 58 WebVector<WebURL> data(urls.size()); |
| 59 for (size_t i = 0; i < urls.size(); ++i) |
| 60 data[i] = WebURL(urls[i]); |
| 61 |
| 62 m_urls.swap(data); |
| 56 } | 63 } |
| 57 | 64 |
| 58 PresentationAvailability::~PresentationAvailability() {} | 65 PresentationAvailability::~PresentationAvailability() {} |
| 59 | 66 |
| 60 const AtomicString& PresentationAvailability::interfaceName() const { | 67 const AtomicString& PresentationAvailability::interfaceName() const { |
| 61 return EventTargetNames::PresentationAvailability; | 68 return EventTargetNames::PresentationAvailability; |
| 62 } | 69 } |
| 63 | 70 |
| 64 ExecutionContext* PresentationAvailability::getExecutionContext() const { | 71 ExecutionContext* PresentationAvailability::getExecutionContext() const { |
| 65 return SuspendableObject::getExecutionContext(); | 72 return SuspendableObject::getExecutionContext(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return; | 122 return; |
| 116 | 123 |
| 117 if (m_state == State::Active && | 124 if (m_state == State::Active && |
| 118 (toDocument(getExecutionContext())->pageVisibilityState() == | 125 (toDocument(getExecutionContext())->pageVisibilityState() == |
| 119 PageVisibilityStateVisible)) | 126 PageVisibilityStateVisible)) |
| 120 client->startListening(this); | 127 client->startListening(this); |
| 121 else | 128 else |
| 122 client->stopListening(this); | 129 client->stopListening(this); |
| 123 } | 130 } |
| 124 | 131 |
| 125 const WebURL PresentationAvailability::url() const { | 132 const WebVector<WebURL>& PresentationAvailability::urls() const { |
| 126 return WebURL(m_url); | 133 return m_urls; |
| 127 } | 134 } |
| 128 | 135 |
| 129 bool PresentationAvailability::value() const { | 136 bool PresentationAvailability::value() const { |
| 130 return m_value; | 137 return m_value; |
| 131 } | 138 } |
| 132 | 139 |
| 133 DEFINE_TRACE(PresentationAvailability) { | 140 DEFINE_TRACE(PresentationAvailability) { |
| 134 EventTargetWithInlineData::trace(visitor); | 141 EventTargetWithInlineData::trace(visitor); |
| 135 PageVisibilityObserver::trace(visitor); | 142 PageVisibilityObserver::trace(visitor); |
| 136 SuspendableObject::trace(visitor); | 143 SuspendableObject::trace(visitor); |
| 137 } | 144 } |
| 138 | 145 |
| 139 } // namespace blink | 146 } // namespace blink |
| OLD | NEW |