Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/presentation/PresentationAvailability.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/events/Event.h" | |
| 11 #include "modules/EventTargetModulesNames.h" | |
| 12 #include "modules/presentation/PresentationController.h" | |
| 13 #include "public/platform/Platform.h" | |
| 14 #include "public/platform/modules/presentation/WebPresentationClient.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 WebPresentationClient* presentationClient(ExecutionContext* executionContext) | |
| 21 { | |
| 22 ASSERT(executionContext && executionContext->isDocument()); | |
| 23 | |
| 24 Document* document = toDocument(executionContext); | |
| 25 if (!document->frame()) | |
| 26 return nullptr; | |
| 27 PresentationController* controller = PresentationController::from(*document- >frame()); | |
| 28 return controller ? controller->client() : nullptr; | |
| 29 } | |
| 30 | |
| 31 } // anonymous namespace | |
| 32 | |
| 33 // static | |
| 34 PresentationAvailability* PresentationAvailability::take(ScriptPromiseResolver* resolver, bool value) | |
| 35 { | |
| 36 PresentationAvailability* presentationAvailability = PresentationAvailabilit y::create(resolver->executionContext(), value); | |
| 37 presentationAvailability->startListening(); | |
| 38 return presentationAvailability; | |
| 39 } | |
| 40 | |
| 41 PresentationAvailability* PresentationAvailability::create(ExecutionContext* exe cutionContext, bool value) | |
|
whywhat
2015/07/02 22:32:37
What's different about this create() method? Why s
| |
| 42 { | |
| 43 PresentationAvailability* presentationAvailability = new PresentationAvailab ility(executionContext, value); | |
| 44 presentationAvailability->suspendIfNeeded(); | |
| 45 return presentationAvailability; | |
| 46 } | |
| 47 | |
| 48 PresentationAvailability::PresentationAvailability(ExecutionContext* executionCo ntext, bool value) | |
| 49 : ActiveDOMObject(executionContext) | |
| 50 , m_value(value) | |
| 51 , m_listening(false) | |
| 52 { | |
| 53 } | |
| 54 | |
| 55 PresentationAvailability::~PresentationAvailability() | |
| 56 { | |
| 57 stopListening(); | |
| 58 } | |
| 59 | |
| 60 const AtomicString& PresentationAvailability::interfaceName() const | |
| 61 { | |
| 62 return EventTargetNames::PresentationAvailability; | |
| 63 } | |
| 64 | |
| 65 ExecutionContext* PresentationAvailability::executionContext() const | |
| 66 { | |
| 67 return ActiveDOMObject::executionContext(); | |
| 68 } | |
| 69 | |
| 70 void PresentationAvailability::availabilityChanged(bool value) | |
| 71 { | |
| 72 if (m_value == value) | |
| 73 return; | |
| 74 | |
| 75 m_value = value; | |
| 76 dispatchEvent(Event::create(EventTypeNames::change)); | |
| 77 } | |
| 78 | |
| 79 bool PresentationAvailability::hasPendingActivity() const | |
| 80 { | |
| 81 return m_listening; | |
| 82 } | |
| 83 | |
| 84 void PresentationAvailability::resume() | |
| 85 { | |
| 86 startListening(); | |
| 87 } | |
| 88 | |
| 89 void PresentationAvailability::suspend() | |
|
whywhat
2015/07/02 22:32:37
We thought about suspending the monitoring when th
mlamouri (slow - plz ping)
2015/07/03 13:58:26
I do not think it will include page visibility but
| |
| 90 { | |
| 91 stopListening(); | |
| 92 } | |
| 93 | |
| 94 void PresentationAvailability::stop() | |
| 95 { | |
| 96 stopListening(); | |
| 97 } | |
| 98 | |
| 99 void PresentationAvailability::startListening() | |
| 100 { | |
| 101 ASSERT(!m_listening); | |
| 102 | |
| 103 WebPresentationClient* client = presentationClient(executionContext()); | |
| 104 if (!client) | |
| 105 return; | |
| 106 m_listening = true; | |
| 107 client->startListening(this); | |
| 108 } | |
| 109 | |
| 110 void PresentationAvailability::stopListening() | |
| 111 { | |
| 112 if (!m_listening) | |
| 113 return; | |
| 114 | |
| 115 ASSERT(executionContext()); | |
| 116 | |
| 117 m_listening = false; | |
|
whywhat
2015/07/02 22:32:37
nit: perhaps swap this line with the ASSERT above?
mlamouri (slow - plz ping)
2015/07/03 13:58:26
I prefer to have ASSERT() as early as possible.
whywhat
2015/07/03 15:40:47
I think logically m_listening belongs to the if ab
| |
| 118 WebPresentationClient* client = presentationClient(executionContext()); | |
| 119 if (!client) | |
| 120 return; | |
| 121 client->stopListening(this); | |
| 122 } | |
| 123 | |
| 124 bool PresentationAvailability::value() const | |
| 125 { | |
| 126 return m_value; | |
| 127 } | |
| 128 | |
| 129 DEFINE_TRACE(PresentationAvailability) | |
| 130 { | |
| 131 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationAvailability >::trace(visitor); | |
| 132 ActiveDOMObject::trace(visitor); | |
| 133 } | |
| 134 | |
| 135 } // namespace | |
| OLD | NEW |