Chromium Code Reviews| 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 { | 22 { |
| 22 ASSERT(executionContext && executionContext->isDocument()); | 23 ASSERT(executionContext && executionContext->isDocument()); |
| 23 | 24 |
| 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 = PresentationController::from(*document- >frame()); | 28 PresentationController* controller = PresentationController::from(*document- >frame()); |
| 28 return controller ? controller->client() : nullptr; | 29 return controller ? controller->client() : nullptr; |
| 29 } | 30 } |
| 30 | 31 |
| 31 } // anonymous namespace | 32 } // anonymous namespace |
| 32 | 33 |
| 33 // static | 34 // static |
| 34 PresentationAvailability* PresentationAvailability::take(ScriptPromiseResolver* resolver, const KURL& url, bool value) | 35 PresentationAvailability* PresentationAvailability::take(ScriptPromiseResolver* resolver, const WTF::Vector<KURL>& urls, bool value) |
| 35 { | 36 { |
| 36 PresentationAvailability* presentationAvailability = new PresentationAvailab ility(resolver->getExecutionContext(), url, value); | 37 PresentationAvailability* presentationAvailability = new PresentationAvailab ility(resolver->getExecutionContext(), urls, value); |
| 37 presentationAvailability->suspendIfNeeded(); | 38 presentationAvailability->suspendIfNeeded(); |
| 38 presentationAvailability->updateListening(); | 39 presentationAvailability->updateListening(); |
| 39 return presentationAvailability; | 40 return presentationAvailability; |
| 40 } | 41 } |
| 41 | 42 |
| 42 PresentationAvailability::PresentationAvailability(ExecutionContext* executionCo ntext, const KURL& url, bool value) | 43 PresentationAvailability::PresentationAvailability(ExecutionContext* executionCo ntext, const WTF::Vector<KURL>& urls, bool value) |
| 43 : ActiveScriptWrappable(this) | 44 : ActiveScriptWrappable(this) |
| 44 , ActiveDOMObject(executionContext) | 45 , ActiveDOMObject(executionContext) |
| 45 , PageVisibilityObserver(toDocument(executionContext)->page()) | 46 , PageVisibilityObserver(toDocument(executionContext)->page()) |
| 46 , m_url(url) | |
| 47 , m_value(value) | 47 , m_value(value) |
| 48 , m_state(State::Active) | 48 , m_state(State::Active) |
| 49 { | 49 { |
| 50 ASSERT(executionContext->isDocument()); | 50 ASSERT(executionContext->isDocument()); |
| 51 WebVector<WebURL> data(urls.size()); | |
| 52 for (size_t i = 0; i < urls.size(); ++i) { | |
| 53 data[i] = WebURL(urls[i]); | |
| 54 } | |
|
mlamouri (slow - plz ping)
2016/07/19 12:45:03
style: we don't use { } when not needed usually.
mark a. foltz
2016/07/19 17:38:47
Done.
| |
| 55 m_urls.swap(data); | |
|
mlamouri (slow - plz ping)
2016/07/19 12:45:03
nit: I am probably missing something but could you
mark a. foltz
2016/07/19 17:38:47
WebVector does not provide any method to resize it
mlamouri (slow - plz ping)
2016/07/20 13:02:10
I'm speechless :)
imcheng
2016/07/20 17:20:45
But you can initialize m_urls with a size param, r
| |
| 51 } | 56 } |
| 52 | 57 |
| 53 PresentationAvailability::~PresentationAvailability() | 58 PresentationAvailability::~PresentationAvailability() |
| 54 { | 59 { |
| 55 } | 60 } |
| 56 | 61 |
| 57 const AtomicString& PresentationAvailability::interfaceName() const | 62 const AtomicString& PresentationAvailability::interfaceName() const |
| 58 { | 63 { |
| 59 return EventTargetNames::PresentationAvailability; | 64 return EventTargetNames::PresentationAvailability; |
| 60 } | 65 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 WebPresentationClient* client = presentationClient(getExecutionContext()); | 123 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 119 if (!client) | 124 if (!client) |
| 120 return; | 125 return; |
| 121 | 126 |
| 122 if (m_state == State::Active && (toDocument(getExecutionContext())->pageVisi bilityState() == PageVisibilityStateVisible)) | 127 if (m_state == State::Active && (toDocument(getExecutionContext())->pageVisi bilityState() == PageVisibilityStateVisible)) |
| 123 client->startListening(this); | 128 client->startListening(this); |
| 124 else | 129 else |
| 125 client->stopListening(this); | 130 client->stopListening(this); |
| 126 } | 131 } |
| 127 | 132 |
| 128 const WebURL PresentationAvailability::url() const | 133 const WebVector<WebURL>& PresentationAvailability::urls() const |
| 129 { | 134 { |
| 130 return WebURL(m_url); | 135 return m_urls; |
| 131 } | 136 } |
| 132 | 137 |
| 133 bool PresentationAvailability::value() const | 138 bool PresentationAvailability::value() const |
| 134 { | 139 { |
| 135 return m_value; | 140 return m_value; |
| 136 } | 141 } |
| 137 | 142 |
| 138 DEFINE_TRACE(PresentationAvailability) | 143 DEFINE_TRACE(PresentationAvailability) |
| 139 { | 144 { |
| 140 EventTargetWithInlineData::trace(visitor); | 145 EventTargetWithInlineData::trace(visitor); |
| 141 PageVisibilityObserver::trace(visitor); | 146 PageVisibilityObserver::trace(visitor); |
| 142 ActiveDOMObject::trace(visitor); | 147 ActiveDOMObject::trace(visitor); |
| 143 } | 148 } |
| 144 | 149 |
| 145 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |