Chromium Code Reviews| Index: Source/modules/battery/BatteryManager.cpp |
| diff --git a/Source/modules/battery/BatteryManager.cpp b/Source/modules/battery/BatteryManager.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6b74279a4db9cffd867693713c14a8e7b38ae2c |
| --- /dev/null |
| +++ b/Source/modules/battery/BatteryManager.cpp |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/battery/BatteryManager.h" |
| + |
| +#include "RuntimeEnabledFeatures.h" |
| +#include "core/dom/Document.h" |
| +#include "core/events/Event.h" |
| +#include "core/frame/Frame.h" |
| +#include "core/frame/Navigator.h" |
| +#include "modules/battery/BatteryStatus.h" |
| +#include <limits> |
| + |
| +namespace WebCore { |
| + |
| +PassRefPtr<BatteryManager> BatteryManager::create(Frame* frame) |
| +{ |
| + RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(frame))); |
| + batteryManager->suspendIfNeeded(); |
| + return batteryManager.release(); |
| +} |
| + |
| +BatteryManager::~BatteryManager() |
| +{ |
| +} |
| + |
| +BatteryManager::BatteryManager(Navigator* navigator) |
| + : ActiveDOMObject(navigator->frame()->document()) |
| + , m_batteryStatus(nullptr) |
| +{ |
| +} |
| + |
| +BatteryManager::BatteryManager(Frame* frame) |
| + : ActiveDOMObject(frame->document()) |
|
abarth-chromium
2014/02/28 06:45:14
Notice that this base class (and ContextDestructio
|
| + , m_batteryStatus(nullptr) |
| +{ |
| +} |
| + |
| +bool BatteryManager::charging() |
| +{ |
| + return m_batteryStatus ? m_batteryStatus->charging() : true; |
| +} |
| + |
| +double BatteryManager::chargingTime() |
| +{ |
| + if (!m_batteryStatus || !m_batteryStatus->charging()) |
| + return std::numeric_limits<double>::infinity(); |
| + |
| + return m_batteryStatus->chargingTime(); |
| +} |
| + |
| +double BatteryManager::dischargingTime() |
| +{ |
| + if (!m_batteryStatus || m_batteryStatus->charging()) |
| + return std::numeric_limits<double>::infinity(); |
| + |
| + return m_batteryStatus->dischargingTime(); |
| +} |
| + |
| +double BatteryManager::level() |
| +{ |
| + return m_batteryStatus ? m_batteryStatus->level() : 1; |
| +} |
| + |
| +void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr<BatteryStatus> batteryStatus) |
| +{ |
| + if (RuntimeEnabledFeatures::batteryStatusEnabled()) { |
|
abarth-chromium
2014/02/28 06:45:14
This check isn't correct. Instead, you should jus
|
| + m_batteryStatus = batteryStatus; |
| + dispatchEvent(event); |
| + } |
| +} |
| + |
| +void BatteryManager::suspend() |
| +{ |
| + /* Stop listening from the Controller */ |
| +} |
| + |
| +void BatteryManager::resume() |
| +{ |
| + /* Start listening to the Controller */ |
| +} |
| + |
| +void BatteryManager::stop() |
| +{ |
| + /* Stop listening from the Controller */ |
| +} |
|
abarth-chromium
2014/02/28 06:45:14
Please remove these functions. We can add them in
|
| + |
| +} // namespace WebCore |
| + |