| 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/DOMException.h" | 7 #include "core/dom/DOMException.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 "modules/battery/BatteryDispatcher.h" | 10 #include "modules/battery/BatteryDispatcher.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 : ActiveScriptWrappable(this), | 24 : ActiveScriptWrappable(this), |
| 25 ActiveDOMObject(context), | 25 ActiveDOMObject(context), |
| 26 PlatformEventController(toDocument(context)->page()) {} | 26 PlatformEventController(toDocument(context)->page()) {} |
| 27 | 27 |
| 28 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState) { | 28 ScriptPromise BatteryManager::startRequest(ScriptState* scriptState) { |
| 29 if (!m_batteryProperty) { | 29 if (!m_batteryProperty) { |
| 30 m_batteryProperty = new BatteryProperty(scriptState->getExecutionContext(), | 30 m_batteryProperty = new BatteryProperty(scriptState->getExecutionContext(), |
| 31 this, BatteryProperty::Ready); | 31 this, BatteryProperty::Ready); |
| 32 | 32 |
| 33 // If the context is in a stopped state already, do not start updating. | 33 // If the context is in a stopped state already, do not start updating. |
| 34 if (!getExecutionContext() || | 34 if (!getExecutionContext() || getExecutionContext()->isContextDestroyed()) { |
| 35 getExecutionContext()->activeDOMObjectsAreStopped()) { | |
| 36 m_batteryProperty->resolve(this); | 35 m_batteryProperty->resolve(this); |
| 37 } else { | 36 } else { |
| 38 m_hasEventListener = true; | 37 m_hasEventListener = true; |
| 39 startUpdating(); | 38 startUpdating(); |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 | 41 |
| 43 return m_batteryProperty->promise(scriptState->world()); | 42 return m_batteryProperty->promise(scriptState->world()); |
| 44 } | 43 } |
| 45 | 44 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 66 m_batteryStatus = *BatteryDispatcher::instance().latestData(); | 65 m_batteryStatus = *BatteryDispatcher::instance().latestData(); |
| 67 | 66 |
| 68 if (m_batteryProperty->getState() == ScriptPromisePropertyBase::Pending) { | 67 if (m_batteryProperty->getState() == ScriptPromisePropertyBase::Pending) { |
| 69 m_batteryProperty->resolve(this); | 68 m_batteryProperty->resolve(this); |
| 70 return; | 69 return; |
| 71 } | 70 } |
| 72 | 71 |
| 73 Document* document = toDocument(getExecutionContext()); | 72 Document* document = toDocument(getExecutionContext()); |
| 74 DCHECK(document); | 73 DCHECK(document); |
| 75 if (document->activeDOMObjectsAreSuspended() || | 74 if (document->activeDOMObjectsAreSuspended() || |
| 76 document->activeDOMObjectsAreStopped()) | 75 document->isContextDestroyed()) |
| 77 return; | 76 return; |
| 78 | 77 |
| 79 if (m_batteryStatus.charging() != oldStatus.charging()) | 78 if (m_batteryStatus.charging() != oldStatus.charging()) |
| 80 dispatchEvent(Event::create(EventTypeNames::chargingchange)); | 79 dispatchEvent(Event::create(EventTypeNames::chargingchange)); |
| 81 if (m_batteryStatus.charging_time() != oldStatus.charging_time()) | 80 if (m_batteryStatus.charging_time() != oldStatus.charging_time()) |
| 82 dispatchEvent(Event::create(EventTypeNames::chargingtimechange)); | 81 dispatchEvent(Event::create(EventTypeNames::chargingtimechange)); |
| 83 if (m_batteryStatus.discharging_time() != oldStatus.discharging_time()) | 82 if (m_batteryStatus.discharging_time() != oldStatus.discharging_time()) |
| 84 dispatchEvent(Event::create(EventTypeNames::dischargingtimechange)); | 83 dispatchEvent(Event::create(EventTypeNames::dischargingtimechange)); |
| 85 if (m_batteryStatus.level() != oldStatus.level()) | 84 if (m_batteryStatus.level() != oldStatus.level()) |
| 86 dispatchEvent(Event::create(EventTypeNames::levelchange)); | 85 dispatchEvent(Event::create(EventTypeNames::levelchange)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 120 } |
| 122 | 121 |
| 123 DEFINE_TRACE(BatteryManager) { | 122 DEFINE_TRACE(BatteryManager) { |
| 124 visitor->trace(m_batteryProperty); | 123 visitor->trace(m_batteryProperty); |
| 125 PlatformEventController::trace(visitor); | 124 PlatformEventController::trace(visitor); |
| 126 EventTargetWithInlineData::trace(visitor); | 125 EventTargetWithInlineData::trace(visitor); |
| 127 ActiveDOMObject::trace(visitor); | 126 ActiveDOMObject::trace(visitor); |
| 128 } | 127 } |
| 129 | 128 |
| 130 } // namespace blink | 129 } // namespace blink |
| OLD | NEW |