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/battery/BatteryManager.h" | 5 #include "modules/battery/BatteryManager.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
9 #include "modules/battery/BatteryDispatcher.h" | 9 #include "modules/battery/BatteryDispatcher.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 BatteryManager::BatteryManager(ExecutionContext* context) | 27 BatteryManager::BatteryManager(ExecutionContext* context) |
28 : ActiveDOMObject(context) | 28 : ActiveDOMObject(context) |
29 , PlatformEventController(toDocument(context)->page()) | 29 , PlatformEventController(toDocument(context)->page()) |
30 { | 30 { |
31 } | 31 } |
32 | 32 |
33 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState) | 33 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState) |
34 { | 34 { |
35 if (!m_batteryProperty) { | 35 if (!m_batteryProperty) { |
36 m_batteryProperty = new BatteryProperty(scriptState->executionContext(),
this, BatteryProperty::Ready); | 36 m_batteryProperty = new BatteryProperty(scriptState->getExecutionContext
(), this, BatteryProperty::Ready); |
37 | 37 |
38 // If the context is in a stopped state already, do not start updating. | 38 // If the context is in a stopped state already, do not start updating. |
39 if (!executionContext() || executionContext()->activeDOMObjectsAreStoppe
d()) { | 39 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAre
Stopped()) { |
40 m_batteryProperty->resolve(this); | 40 m_batteryProperty->resolve(this); |
41 } else { | 41 } else { |
42 m_hasEventListener = true; | 42 m_hasEventListener = true; |
43 startUpdating(); | 43 startUpdating(); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 return m_batteryProperty->promise(scriptState->world()); | 47 return m_batteryProperty->promise(scriptState->world()); |
48 } | 48 } |
49 | 49 |
(...skipping 22 matching lines...) Expand all Loading... |
72 ASSERT(m_batteryProperty); | 72 ASSERT(m_batteryProperty); |
73 | 73 |
74 BatteryStatus oldStatus = m_batteryStatus; | 74 BatteryStatus oldStatus = m_batteryStatus; |
75 m_batteryStatus = *BatteryDispatcher::instance().latestData(); | 75 m_batteryStatus = *BatteryDispatcher::instance().latestData(); |
76 | 76 |
77 if (m_batteryProperty->getState() == ScriptPromisePropertyBase::Pending) { | 77 if (m_batteryProperty->getState() == ScriptPromisePropertyBase::Pending) { |
78 m_batteryProperty->resolve(this); | 78 m_batteryProperty->resolve(this); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 Document* document = toDocument(executionContext()); | 82 Document* document = toDocument(getExecutionContext()); |
83 ASSERT(document); | 83 ASSERT(document); |
84 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) | 84 if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAr
eStopped()) |
85 return; | 85 return; |
86 | 86 |
87 if (m_batteryStatus.charging() != oldStatus.charging()) | 87 if (m_batteryStatus.charging() != oldStatus.charging()) |
88 dispatchEvent(Event::create(EventTypeNames::chargingchange)); | 88 dispatchEvent(Event::create(EventTypeNames::chargingchange)); |
89 if (m_batteryStatus.charging_time() != oldStatus.charging_time()) | 89 if (m_batteryStatus.charging_time() != oldStatus.charging_time()) |
90 dispatchEvent(Event::create(EventTypeNames::chargingtimechange)); | 90 dispatchEvent(Event::create(EventTypeNames::chargingtimechange)); |
91 if (m_batteryStatus.discharging_time() != oldStatus.discharging_time()) | 91 if (m_batteryStatus.discharging_time() != oldStatus.discharging_time()) |
92 dispatchEvent(Event::create(EventTypeNames::dischargingtimechange)); | 92 dispatchEvent(Event::create(EventTypeNames::dischargingtimechange)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 DEFINE_TRACE(BatteryManager) | 138 DEFINE_TRACE(BatteryManager) |
139 { | 139 { |
140 visitor->trace(m_batteryProperty); | 140 visitor->trace(m_batteryProperty); |
141 PlatformEventController::trace(visitor); | 141 PlatformEventController::trace(visitor); |
142 RefCountedGarbageCollectedEventTargetWithInlineData<BatteryManager>::trace(v
isitor); | 142 RefCountedGarbageCollectedEventTargetWithInlineData<BatteryManager>::trace(v
isitor); |
143 ActiveDOMObject::trace(visitor); | 143 ActiveDOMObject::trace(visitor); |
144 } | 144 } |
145 | 145 |
146 } // namespace blink | 146 } // namespace blink |
OLD | NEW |