Add support to Battery Status API in blink.

This patch adds basic Battery Manager to Navigator with default battery
status values and the test enables to test if those values are passed
correctly.

Intent-to-Implement link: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/fzoG6Phr09k/dnAEzkgMA1YJ

BUG=122593

Review URL: https://codereview.chromium.org/182613002

git-svn-id: svn://svn.chromium.org/blink/trunk@168632 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b9d011c6
...@@ -421,6 +421,10 @@ crbug.com/290411 [ Win Mac ] fast/text/sub-pixel/text-scaling-webfont.html [ Ski ...@@ -421,6 +421,10 @@ crbug.com/290411 [ Win Mac ] fast/text/sub-pixel/text-scaling-webfont.html [ Ski
crbug.com/290411 [ Linux ] fast/text/sub-pixel/text-scaling-pixel.html [ Pass Failure ] crbug.com/290411 [ Linux ] fast/text/sub-pixel/text-scaling-pixel.html [ Pass Failure ]
crbug.com/334269 [ Mac ] fast/text/font-variant-ligatures.html [ ImageOnlyFailure ] crbug.com/334269 [ Mac ] fast/text/font-variant-ligatures.html [ ImageOnlyFailure ]
crbug.com/122593 [ Mac ] fast/dom/Window/property-access-on-cached-properties-after-frame-removed.html [ NeedsRebaseline ]
crbug.com/122593 [ Mac ] fast/dom/Window/property-access-on-cached-window-after-frame-removed.html [ NeedsRebaseline ]
crbug.com/122593 [ Mac ] fast/dom/Window/property-access-on-cached-window-after-frame-navigated.html [ NeedsRebaseline ]
crbug.com/122593 [ Mac ] fast/dom/Window/property-access-on-cached-properties-after-frame-navigated.html [ NeedsRebaseline ]
# Switching to content shell failures # Switching to content shell failures
crbug.com/231866 [ Lion ] fast/backgrounds/animated-gif-as-background.html [ Pass ImageOnlyFailure ] crbug.com/231866 [ Lion ] fast/backgrounds/animated-gif-as-background.html [ Pass ImageOnlyFailure ]
......
This test prints the default battery status values.
Charging Status: Charging
Charging Time: Infinity
Discharging Time: Infinity
Percentage: 100
<html>
<body>
<p>This test prints the default battery status values.</p>
<p id="p1"></p>
<p id="p2"></p>
<p id="p3"></p>
<p id="p4"></p>
</body>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var battery = navigator.battery;
document.getElementById("p1").innerHTML = "Charging Status: " + (battery.charging ? "Charging" : "Discharging");
document.getElementById("p2").innerHTML = "Charging Time: " + battery.chargingTime;
document.getElementById("p3").innerHTML = "Discharging Time: " + battery.dischargingTime;
document.getElementById("p4").innerHTML = "Percentage: " + battery.level*100;
</script>
</html>
...@@ -22,6 +22,10 @@ PASS window.cached_navigator.product is window.navigator.product ...@@ -22,6 +22,10 @@ PASS window.cached_navigator.product is window.navigator.product
PASS window.cached_navigator.productSub is window.navigator.productSub PASS window.cached_navigator.productSub is window.navigator.productSub
PASS window.cached_navigator.userAgent is '' PASS window.cached_navigator.userAgent is ''
PASS window.cached_navigator.vendor is window.navigator.vendor PASS window.cached_navigator.vendor is window.navigator.vendor
PASS window.cached_navigator_battery.charging is true
PASS window.cached_navigator_battery.chargingTime is Infinity
PASS window.cached_navigator_battery.dischargingTime is Infinity
PASS window.cached_navigator_battery.level is 1
PASS window.cached_performance_timing.connectEnd is 0 PASS window.cached_performance_timing.connectEnd is 0
PASS window.cached_performance_timing.connectStart is 0 PASS window.cached_performance_timing.connectStart is 0
PASS window.cached_performance_timing.domContentLoadedEventEnd is 0 PASS window.cached_performance_timing.domContentLoadedEventEnd is 0
......
...@@ -22,6 +22,10 @@ PASS window.cached_navigator.product is window.navigator.product ...@@ -22,6 +22,10 @@ PASS window.cached_navigator.product is window.navigator.product
PASS window.cached_navigator.productSub is window.navigator.productSub PASS window.cached_navigator.productSub is window.navigator.productSub
PASS window.cached_navigator.userAgent is '' PASS window.cached_navigator.userAgent is ''
PASS window.cached_navigator.vendor is window.navigator.vendor PASS window.cached_navigator.vendor is window.navigator.vendor
PASS window.cached_navigator_battery.charging is true
PASS window.cached_navigator_battery.chargingTime is Infinity
PASS window.cached_navigator_battery.dischargingTime is Infinity
PASS window.cached_navigator_battery.level is 1
PASS window.cached_performance_timing.connectEnd is 0 PASS window.cached_performance_timing.connectEnd is 0
PASS window.cached_performance_timing.connectStart is 0 PASS window.cached_performance_timing.connectStart is 0
PASS window.cached_performance_timing.domLoading is 0 PASS window.cached_performance_timing.domLoading is 0
......
...@@ -19,6 +19,10 @@ PASS oldChildWindow.menubar.visible is newChildWindow.menubar.visible ...@@ -19,6 +19,10 @@ PASS oldChildWindow.menubar.visible is newChildWindow.menubar.visible
PASS oldChildWindow.navigator.appCodeName is newChildWindow.navigator.appCodeName PASS oldChildWindow.navigator.appCodeName is newChildWindow.navigator.appCodeName
PASS oldChildWindow.navigator.appName is newChildWindow.navigator.appName PASS oldChildWindow.navigator.appName is newChildWindow.navigator.appName
PASS oldChildWindow.navigator.appVersion is newChildWindow.navigator.appVersion PASS oldChildWindow.navigator.appVersion is newChildWindow.navigator.appVersion
PASS oldChildWindow.navigator.battery.charging is newChildWindow.navigator.battery.charging
PASS oldChildWindow.navigator.battery.chargingTime is newChildWindow.navigator.battery.chargingTime
PASS oldChildWindow.navigator.battery.dischargingTime is newChildWindow.navigator.battery.dischargingTime
PASS oldChildWindow.navigator.battery.level is newChildWindow.navigator.battery.level
PASS oldChildWindow.navigator.cookieEnabled is newChildWindow.navigator.cookieEnabled PASS oldChildWindow.navigator.cookieEnabled is newChildWindow.navigator.cookieEnabled
PASS oldChildWindow.navigator.language is newChildWindow.navigator.language PASS oldChildWindow.navigator.language is newChildWindow.navigator.language
PASS oldChildWindow.navigator.onLine is newChildWindow.navigator.onLine PASS oldChildWindow.navigator.onLine is newChildWindow.navigator.onLine
......
...@@ -18,6 +18,10 @@ PASS childWindow.menubar.visible is false ...@@ -18,6 +18,10 @@ PASS childWindow.menubar.visible is false
PASS childWindow.navigator.appCodeName is window.navigator.appCodeName PASS childWindow.navigator.appCodeName is window.navigator.appCodeName
PASS childWindow.navigator.appName is window.navigator.appName PASS childWindow.navigator.appName is window.navigator.appName
PASS childWindow.navigator.appVersion is '' PASS childWindow.navigator.appVersion is ''
PASS childWindow.navigator.battery.charging is true
PASS childWindow.navigator.battery.chargingTime is Infinity
PASS childWindow.navigator.battery.dischargingTime is Infinity
PASS childWindow.navigator.battery.level is 1
PASS childWindow.navigator.cookieEnabled is false PASS childWindow.navigator.cookieEnabled is false
PASS childWindow.navigator.language is window.navigator.language PASS childWindow.navigator.language is window.navigator.language
PASS childWindow.navigator.onLine is window.navigator.onLine PASS childWindow.navigator.onLine is window.navigator.onLine
......
...@@ -53,6 +53,18 @@ function emitExpectedResult(path, expected) ...@@ -53,6 +53,18 @@ function emitExpectedResult(path, expected)
case "navigator.vendor": case "navigator.vendor":
expected = "window." + propertyPath; expected = "window." + propertyPath;
break; break;
case "navigator.battery.charging":
expected = "true";
break;
case "navigator.battery.chargingTime":
expected = "Infinity";
break;
case "navigator.battery.dischargingTime":
expected = "Infinity";
break;
case "navigator.battery.level":
expected = "1";
break;
} }
insertExpectedResult(path, expected); insertExpectedResult(path, expected);
......
...@@ -3,6 +3,7 @@ This tests that the navigator object of a deleted frame is disconnected properly ...@@ -3,6 +3,7 @@ This tests that the navigator object of a deleted frame is disconnected properly
navigator.appCodeName is OK navigator.appCodeName is OK
navigator.appName is OK navigator.appName is OK
navigator.appVersion is OK navigator.appVersion is OK
navigator.battery is OK
navigator.cookieEnabled is OK navigator.cookieEnabled is OK
navigator.doNotTrack is OK navigator.doNotTrack is OK
navigator.getStorageUpdates() is OK navigator.getStorageUpdates() is OK
...@@ -31,6 +32,7 @@ navigator.webkitTemporaryStorage is OK ...@@ -31,6 +32,7 @@ navigator.webkitTemporaryStorage is OK
navigator.appCodeName is OK navigator.appCodeName is OK
navigator.appName is OK navigator.appName is OK
navigator.appVersion is OK navigator.appVersion is OK
navigator.battery is OK
navigator.cookieEnabled is OK navigator.cookieEnabled is OK
navigator.doNotTrack is OK navigator.doNotTrack is OK
navigator.getStorageUpdates() is OK navigator.getStorageUpdates() is OK
......
...@@ -21,6 +21,7 @@ core/workers/SharedWorkerGlobalScope ...@@ -21,6 +21,7 @@ core/workers/SharedWorkerGlobalScope
core/workers/Worker core/workers/Worker
core/xml/XMLHttpRequest core/xml/XMLHttpRequest
core/xml/XMLHttpRequestUpload core/xml/XMLHttpRequestUpload
modules/battery/BatteryManager
modules/encryptedmedia/MediaKeySession modules/encryptedmedia/MediaKeySession
modules/filesystem/FileWriter modules/filesystem/FileWriter
modules/indexeddb/IDBDatabase modules/indexeddb/IDBDatabase
......
// 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/events/Event.h"
#include "modules/battery/BatteryStatus.h"
#include <limits>
namespace WebCore {
PassRefPtr<BatteryManager> BatteryManager::create(ExecutionContext* context)
{
return adoptRef(new BatteryManager(context));
}
BatteryManager::~BatteryManager()
{
}
BatteryManager::BatteryManager(ExecutionContext* context)
: ContextLifecycleObserver(context)
, 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)
{
ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled());
m_batteryStatus = batteryStatus;
dispatchEvent(event);
}
} // namespace WebCore
// 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.
#ifndef BatteryManager_h
#define BatteryManager_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/dom/Document.h"
#include "core/events/EventTarget.h"
#include "modules/battery/BatteryStatus.h"
namespace WebCore {
class Navigator;
class BatteryManager : public ContextLifecycleObserver, public RefCounted<BatteryManager>, public EventTarget {
public:
virtual ~BatteryManager();
static PassRefPtr<BatteryManager> create(ExecutionContext*);
// EventTarget implementation.
virtual const WTF::AtomicString& interfaceName() const { return EventTargetNames::BatteryManager; }
virtual ExecutionContext* executionContext() const OVERRIDE FINAL { return ContextLifecycleObserver::executionContext(); }
bool charging();
double chargingTime();
double dischargingTime();
double level();
DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange);
void didChangeBatteryStatus(PassRefPtr<Event>, PassOwnPtr<BatteryStatus>);
using RefCounted<BatteryManager>::ref;
using RefCounted<BatteryManager>::deref;
protected:
virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
virtual EventTargetData& ensureEventTargetData() { return m_eventTargetData; }
private:
explicit BatteryManager(ExecutionContext*);
// EventTarget implementation.
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
EventTargetData m_eventTargetData;
OwnPtr<BatteryStatus> m_batteryStatus;
};
}
#endif // BatteryManager_h
// 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.
// http://dev.w3.org/2009/dap/system-info/battery-status.html
[
NoInterfaceObject,
RuntimeEnabled=BatteryStatus,
] interface BatteryManager : EventTarget {
readonly attribute boolean charging;
readonly attribute double chargingTime;
readonly attribute double dischargingTime;
readonly attribute double level;
attribute EventHandler onchargingchange;
attribute EventHandler onchargingtimechange;
attribute EventHandler ondischargingtimechange;
attribute EventHandler onlevelchange;
};
// 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/BatteryStatus.h"
#include <limits>
namespace WebCore {
PassOwnPtr<BatteryStatus> BatteryStatus::create()
{
return adoptPtr(new BatteryStatus);
}
PassOwnPtr<BatteryStatus> BatteryStatus::create(bool charging, double chargingTime, double dischargingTime, double level)
{
return adoptPtr(new BatteryStatus(charging, chargingTime, dischargingTime, level));
}
BatteryStatus::BatteryStatus()
: m_charging(true)
, m_chargingTime(0)
, m_dischargingTime(std::numeric_limits<double>::infinity())
, m_level(1)
{
}
BatteryStatus::BatteryStatus(bool charging, double chargingTime, double dischargingTime, double level)
: m_charging(charging)
, m_chargingTime(chargingTime)
, m_dischargingTime(dischargingTime)
, m_level(level)
{
}
} // namespace WebCore
// 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.
#ifndef BatteryStatus_h
#define BatteryStatus_h
#include "wtf/PassOwnPtr.h"
#include "wtf/RefCounted.h"
namespace WebCore {
class BatteryStatus {
public:
static PassOwnPtr<BatteryStatus> create();
static PassOwnPtr<BatteryStatus> create(bool charging, double chargingTime, double dischargingTime, double level);
bool charging() const { return m_charging; }
double chargingTime() const { return m_chargingTime; }
double dischargingTime() const { return m_dischargingTime; }
double level() const { return m_level; }
private:
BatteryStatus();
BatteryStatus(bool charging, double chargingTime, double dischargingTime, double level);
bool m_charging;
double m_chargingTime;
double m_dischargingTime;
double m_level;
};
} // namespace WebCore
#endif // BatteryStatus_h
// 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/NavigatorBattery.h"
#include "core/frame/LocalFrame.h"
#include "modules/battery/BatteryManager.h"
namespace WebCore {
NavigatorBattery::NavigatorBattery()
{
}
NavigatorBattery::~NavigatorBattery()
{
}
BatteryManager* NavigatorBattery::battery(Navigator& navigator)
{
return NavigatorBattery::from(navigator).batteryManager(navigator);
}
BatteryManager* NavigatorBattery::batteryManager(Navigator& navigator)
{
if (!m_batteryManager && navigator.frame())
m_batteryManager = BatteryManager::create(navigator.frame()->document());
return m_batteryManager.get();
}
const char* NavigatorBattery::supplementName()
{
return "NavigatorBattery";
}
NavigatorBattery& NavigatorBattery::from(Navigator& navigator)
{
NavigatorBattery* supplement = static_cast<NavigatorBattery*>(Supplement<Navigator>::from(navigator, supplementName()));
if (!supplement) {
supplement = new NavigatorBattery();
provideTo(navigator, supplementName(), adoptPtr(supplement));
}
return *supplement;
}
} // namespace WebCore
// 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.
#ifndef NavigatorBattery_h
#define NavigatorBattery_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
namespace WebCore {
class BatteryManager;
class Navigator;
class NavigatorBattery : public Supplement<Navigator> {
public:
virtual ~NavigatorBattery();
static NavigatorBattery& from(Navigator&);
static BatteryManager* battery(Navigator&);
BatteryManager* batteryManager(Navigator&);
private:
explicit NavigatorBattery();
static const char* supplementName();
RefPtr<BatteryManager> m_batteryManager;
};
} // namespace WebCore
#endif // NavigatorBattery_h
// 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.
[
RuntimeEnabled=BatteryStatus,
] partial interface Navigator {
readonly attribute BatteryManager battery;
};
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# Files for which bindings (.cpp and .h files) will be generated # Files for which bindings (.cpp and .h files) will be generated
'modules_idl_files': [ 'modules_idl_files': [
'<@(extra_blink_module_idl_files)', '<@(extra_blink_module_idl_files)',
'battery/BatteryManager.idl',
'crypto/AesKeyAlgorithm.idl', 'crypto/AesKeyAlgorithm.idl',
'crypto/Crypto.idl', 'crypto/Crypto.idl',
'crypto/HmacKeyAlgorithm.idl', 'crypto/HmacKeyAlgorithm.idl',
...@@ -185,6 +186,7 @@ ...@@ -185,6 +186,7 @@
], ],
# 'partial interface' or target (right side of) 'implements' # 'partial interface' or target (right side of) 'implements'
'modules_dependency_idl_files': [ 'modules_dependency_idl_files': [
'battery/NavigatorBattery.idl',
'crypto/WindowCrypto.idl', 'crypto/WindowCrypto.idl',
'crypto/WorkerGlobalScopeCrypto.idl', 'crypto/WorkerGlobalScopeCrypto.idl',
'donottrack/NavigatorDoNotTrack.idl', 'donottrack/NavigatorDoNotTrack.idl',
...@@ -222,6 +224,12 @@ ...@@ -222,6 +224,12 @@
], ],
'modules_files': [ 'modules_files': [
'<@(extra_blink_module_files)', '<@(extra_blink_module_files)',
'battery/BatteryManager.cpp',
'battery/BatteryManager.h',
'battery/BatteryStatus.cpp',
'battery/BatteryStatus.h',
'battery/NavigatorBattery.cpp',
'battery/NavigatorBattery.h',
'crypto/Crypto.cpp', 'crypto/Crypto.cpp',
'crypto/Crypto.h', 'crypto/Crypto.h',
'crypto/CryptoResultImpl.cpp', 'crypto/CryptoResultImpl.cpp',
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
ApplicationCache status=stable ApplicationCache status=stable
AuthorShadowDOMForAnyElement AuthorShadowDOMForAnyElement
BatteryStatus status=test
BeforeLoad status=test BeforeLoad status=test
// Enable bleeding-edge code to make Blink draw content faster. // Enable bleeding-edge code to make Blink draw content faster.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment