.: Support for Battery Status API.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Mar 2012 12:23:07 +0000 (12:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Mar 2012 12:23:07 +0000 (12:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=62698

Enable BATTERY_STATUS for WebKit-Efl.
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

* Source/cmake/OptionsEfl.cmake:
* Source/cmakeconfig.h.cmake:

Source/WebCore: Support for Battery Status API
https://bugs.webkit.org/show_bug.cgi?id=62698

Battery Status API is implemented under the Navigator class.
Battery Status API has four types of events, and all events are operated based on a callback mechanism.
 : onchargingchange, onchargingtimechange, ondischargingtimechange, onlevelchange.
The battery status can be accessed using BatteryManager(navigator.webkitBattery), and battery status is controlled by BatteryController which manages instances of BatteryManager.
When battery status event is raised, BatteryController calls all registered BatteryManager's event dispatcher.
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

Tests: batterystatus/add-listener-from-callback.html
       batterystatus/basic-all-types-of-events.html
       batterystatus/basic-operation.html
       batterystatus/event-after-navigation.html
       batterystatus/multiple-frames.html
       batterystatus/updates.html
       batterystatus/window-property.html

* CMakeLists.txt:
* Modules/battery/BatteryClient.h: Added.
(WebCore):
(BatteryClient):
(WebCore::BatteryClient::~BatteryClient):
* Modules/battery/BatteryController.cpp: Added.
(WebCore):
(WebCore::BatteryController::BatteryController):
(WebCore::BatteryController::~BatteryController):
(WebCore::BatteryController::create):
(WebCore::BatteryController::addListener):
(WebCore::BatteryController::removeListener):
(WebCore::BatteryController::didChangeBatteryStatus):
(WebCore::BatteryController::supplementName):
(WebCore::BatteryController::isActive):
(WebCore::provideBatteryTo):
* Modules/battery/BatteryController.h: Added.
(WebCore):
(BatteryController):
(WebCore::BatteryController::client):
(WebCore::BatteryController::from):
* Modules/battery/BatteryManager.cpp: Added.
(WebCore):
(WebCore::BatteryManager::create):
(WebCore::BatteryManager::~BatteryManager):
(WebCore::BatteryManager::BatteryManager):
(WebCore::BatteryManager::charging):
(WebCore::BatteryManager::chargingTime):
(WebCore::BatteryManager::dischargingTime):
(WebCore::BatteryManager::level):
(WebCore::BatteryManager::didChangeBatteryStatus):
(WebCore::BatteryManager::suspend):
(WebCore::BatteryManager::resume):
(WebCore::BatteryManager::stop):
* Modules/battery/BatteryManager.h: Added.
(WebCore):
(BatteryManager):
(WebCore::BatteryManager::interfaceName):
(WebCore::BatteryManager::scriptExecutionContext):
(WebCore::BatteryManager::batteryControllerDestroyed):
(WebCore::BatteryManager::canSuspend):
(WebCore::BatteryManager::eventTargetData):
(WebCore::BatteryManager::ensureEventTargetData):
(WebCore::BatteryManager::refEventTarget):
(WebCore::BatteryManager::derefEventTarget):
* Modules/battery/BatteryManager.idl: Added.
* Modules/battery/BatteryStatus.cpp: Added.
(WebCore):
(WebCore::BatteryStatus::create):
(WebCore::BatteryStatus::BatteryStatus):
* Modules/battery/BatteryStatus.h: Added.
(WebCore):
(BatteryStatus):
(WebCore::BatteryStatus::charging):
(WebCore::BatteryStatus::chargingTime):
(WebCore::BatteryStatus::dischargingTime):
(WebCore::BatteryStatus::level):
* Modules/battery/NavigatorBattery.cpp: Added.
(WebCore):
(WebCore::NavigatorBattery::NavigatorBattery):
(WebCore::NavigatorBattery::~NavigatorBattery):
(WebCore::NavigatorBattery::webkitBattery):
(WebCore::NavigatorBattery::from):
(WebCore::NavigatorBattery::batteryManager):
* Modules/battery/NavigatorBattery.h: Added.
(WebCore):
(NavigatorBattery):
* Modules/battery/NavigatorBattery.idl: Added.
* dom/EventNames.h:
(WebCore):
* dom/EventTargetFactory.in:
* testing/Internals.cpp:
(WebCore::Internals::setBatteryStatus):
(WebCore):
* testing/Internals.h:
(Internals):
* testing/Internals.idl:

Source/WebKit: Support for Battery Status API
https://bugs.webkit.org/show_bug.cgi?id=62698

Add include directory and file.
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

* PlatformEfl.cmake:

Source/WebKit/efl: Support for Battery Status API
https://bugs.webkit.org/show_bug.cgi?id=62698

Add BatteryClientEfl class implementation for the layout tests now.
BatteryClientEfl class is not fully implemented in this patch.
(It will be completed by other patch as necessary in the Efl port.)
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

* WebCoreSupport/BatteryClientEfl.cpp: Added.
(WebCore):
(WebCore::BatteryClientEfl::BatteryClientEfl):
(WebCore::BatteryClientEfl::setController):
(WebCore::BatteryClientEfl::startUpdating):
(WebCore::BatteryClientEfl::stopUpdating):
(WebCore::BatteryClientEfl::batteryControllerDestroyed):
(WebCore::BatteryClientEfl::setBatteryStatus):
* WebCoreSupport/BatteryClientEfl.h: Added.
(WebCore):
(BatteryClientEfl):
(WebCore::BatteryClientEfl::~BatteryClientEfl):
* ewk/ewk_view.cpp:
(_Ewk_View_Private_Data):
(_ewk_view_priv_new):

Tools: Support for Battery Status API
https://bugs.webkit.org/show_bug.cgi?id=62698

Add include directory and file.
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

* Scripts/build-webkit:

LayoutTests: Support for Battery Status API.
https://bugs.webkit.org/show_bug.cgi?id=62698

Add new test cases for Battery Status API.
http://www.w3.org/TR/battery-status/

Patch by Kihong Kwon <kihong.kwon@samsung.com> on 2012-03-16
Reviewed by Adam Barth.

* batterystatus/add-listener-from-callback-expected.txt: Added.
* batterystatus/add-listener-from-callback.html: Added.
* batterystatus/basic-all-types-of-events-expected.txt: Added.
* batterystatus/basic-all-types-of-events.html: Added.
* batterystatus/basic-operation-expected.txt: Added.
* batterystatus/basic-operation.html: Added.
* batterystatus/event-after-navigation-expected.txt: Added.
* batterystatus/event-after-navigation.html: Added.
* batterystatus/multiple-frames-expected.txt: Added.
* batterystatus/multiple-frames.html: Added.
* batterystatus/resources/event-after-navigation-new.html: Added.
* batterystatus/script-tests/add-listener-from-callback.js: Added.
(checkBatteryStatus):
(firstListener):
(secondListener):
(maybeFinishTest):
* batterystatus/script-tests/basic-all-types-of-events.js: Added.
(checkBatteryStatus):
(battery):
* batterystatus/script-tests/basic-operation.js: Added.
* batterystatus/script-tests/event-after-navigation.js: Added.
* batterystatus/script-tests/multiple-frames.js: Added.
(checkBatteryStatus):
(checkChildBatteryStatus):
(mainFrameListener):
(childFrameListener):
(maybeFinishTest):
* batterystatus/script-tests/updates.js: Added.
(checkBatteryStatus):
(setBatteryStatus):
(firstListener):
(updateListener):
* batterystatus/script-tests/window-property.js: Added.
(hasOnBatteryProperty):
* batterystatus/updates-expected.txt: Added.
* batterystatus/updates.html: Added.
* batterystatus/window-property-expected.txt: Added.
* batterystatus/window-property.html: Added.
* platform/chromium/test_expectations.txt:
* platform/gtk/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110991 268f45cc-cd09-0410-ab3c-d52691b4dbfc

58 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/batterystatus/add-listener-from-callback-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/add-listener-from-callback.html [new file with mode: 0644]
LayoutTests/batterystatus/basic-all-types-of-events-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/basic-all-types-of-events.html [new file with mode: 0644]
LayoutTests/batterystatus/basic-operation-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/basic-operation.html [new file with mode: 0644]
LayoutTests/batterystatus/event-after-navigation-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/event-after-navigation.html [new file with mode: 0644]
LayoutTests/batterystatus/multiple-frames-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/multiple-frames.html [new file with mode: 0644]
LayoutTests/batterystatus/resources/event-after-navigation-new.html [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/add-listener-from-callback.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/basic-all-types-of-events.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/basic-operation.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/event-after-navigation.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/multiple-frames.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/updates.js [new file with mode: 0644]
LayoutTests/batterystatus/script-tests/window-property.js [new file with mode: 0644]
LayoutTests/batterystatus/updates-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/updates.html [new file with mode: 0644]
LayoutTests/batterystatus/window-property-expected.txt [new file with mode: 0644]
LayoutTests/batterystatus/window-property.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wincairo/Skipped
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/battery/BatteryClient.h [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryController.cpp [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryController.h [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryManager.cpp [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryManager.h [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryManager.idl [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryStatus.cpp [new file with mode: 0644]
Source/WebCore/Modules/battery/BatteryStatus.h [new file with mode: 0644]
Source/WebCore/Modules/battery/NavigatorBattery.cpp [new file with mode: 0644]
Source/WebCore/Modules/battery/NavigatorBattery.h [new file with mode: 0644]
Source/WebCore/Modules/battery/NavigatorBattery.idl [new file with mode: 0644]
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/EventTargetFactory.in
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/PlatformEfl.cmake
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp [new file with mode: 0644]
Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h [new file with mode: 0644]
Source/WebKit/efl/ewk/ewk_view.cpp
Source/cmake/OptionsEfl.cmake
Source/cmakeconfig.h.cmake
Tools/ChangeLog
Tools/Scripts/build-webkit

index 7387cdfcf7a7c5d581eedad75502bd06f18e51ee..ff6e2ba0c162a247a1c96646c00e45a774d17e8a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API.
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Enable BATTERY_STATUS for WebKit-Efl.
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        * Source/cmake/OptionsEfl.cmake:
+        * Source/cmakeconfig.h.cmake:
+
 2012-03-15  Patrick Gansterer  <paroga@webkit.org>
 
         [EFL] Make zlib a general build requirement
index a266737e0c461510dd9b61ef6ff8de4ba970590b..da7a3ded7b4d45494f3f7208d5773894b77bf261 100644 (file)
@@ -1,3 +1,57 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API.
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Add new test cases for Battery Status API.
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        * batterystatus/add-listener-from-callback-expected.txt: Added.
+        * batterystatus/add-listener-from-callback.html: Added.
+        * batterystatus/basic-all-types-of-events-expected.txt: Added.
+        * batterystatus/basic-all-types-of-events.html: Added.
+        * batterystatus/basic-operation-expected.txt: Added.
+        * batterystatus/basic-operation.html: Added.
+        * batterystatus/event-after-navigation-expected.txt: Added.
+        * batterystatus/event-after-navigation.html: Added.
+        * batterystatus/multiple-frames-expected.txt: Added.
+        * batterystatus/multiple-frames.html: Added.
+        * batterystatus/resources/event-after-navigation-new.html: Added.
+        * batterystatus/script-tests/add-listener-from-callback.js: Added.
+        (checkBatteryStatus):
+        (firstListener):
+        (secondListener):
+        (maybeFinishTest):
+        * batterystatus/script-tests/basic-all-types-of-events.js: Added.
+        (checkBatteryStatus):
+        (battery):
+        * batterystatus/script-tests/basic-operation.js: Added.
+        * batterystatus/script-tests/event-after-navigation.js: Added.
+        * batterystatus/script-tests/multiple-frames.js: Added.
+        (checkBatteryStatus):
+        (checkChildBatteryStatus):
+        (mainFrameListener):
+        (childFrameListener):
+        (maybeFinishTest):
+        * batterystatus/script-tests/updates.js: Added.
+        (checkBatteryStatus):
+        (setBatteryStatus):
+        (firstListener):
+        (updateListener):
+        * batterystatus/script-tests/window-property.js: Added.
+        (hasOnBatteryProperty):
+        * batterystatus/updates-expected.txt: Added.
+        * batterystatus/updates.html: Added.
+        * batterystatus/window-property-expected.txt: Added.
+        * batterystatus/window-property.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/gtk/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+
 2012-03-16  Hajime Morrita  <morrita@chromium.org>
 
         Unreviewed gardening, marking a failing test.
diff --git a/LayoutTests/batterystatus/add-listener-from-callback-expected.txt b/LayoutTests/batterystatus/add-listener-from-callback-expected.txt
new file mode 100644 (file)
index 0000000..8e67459
--- /dev/null
@@ -0,0 +1,21 @@
+Tests that adding a new event listener from a callback works as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/add-listener-from-callback.html b/LayoutTests/batterystatus/add-listener-from-callback.html
new file mode 100644 (file)
index 0000000..d4b2291
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/add-listener-from-callback.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/basic-all-types-of-events-expected.txt b/LayoutTests/batterystatus/basic-all-types-of-events-expected.txt
new file mode 100644 (file)
index 0000000..71c374f
--- /dev/null
@@ -0,0 +1,29 @@
+Tests the basic operation of all BatteryStatus events.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+chargingchange event is raised
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+chargingtimechange event is raised
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+dischargingtimechange event is raised
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+levelchange event is raised
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/basic-all-types-of-events.html b/LayoutTests/batterystatus/basic-all-types-of-events.html
new file mode 100644 (file)
index 0000000..7fee4e0
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/basic-all-types-of-events.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/basic-operation-expected.txt b/LayoutTests/batterystatus/basic-operation-expected.txt
new file mode 100644 (file)
index 0000000..d13c8f0
--- /dev/null
@@ -0,0 +1,13 @@
+Tests the basic operation of BatteryStatus.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/basic-operation.html b/LayoutTests/batterystatus/basic-operation.html
new file mode 100644 (file)
index 0000000..e2d4474
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/basic-operation.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/event-after-navigation-expected.txt b/LayoutTests/batterystatus/event-after-navigation-expected.txt
new file mode 100644 (file)
index 0000000..8e6bc39
--- /dev/null
@@ -0,0 +1,3 @@
+Tests for a crash where an event is fired after the page has been navigated away when the original page is in the page cache.
+
+SUCCESS
diff --git a/LayoutTests/batterystatus/event-after-navigation.html b/LayoutTests/batterystatus/event-after-navigation.html
new file mode 100644 (file)
index 0000000..96b0c5e
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/event-after-navigation.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/multiple-frames-expected.txt b/LayoutTests/batterystatus/multiple-frames-expected.txt
new file mode 100644 (file)
index 0000000..9de2cd0
--- /dev/null
@@ -0,0 +1,17 @@
+Tests using BatteryStatus from multiple frames.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/multiple-frames.html b/LayoutTests/batterystatus/multiple-frames.html
new file mode 100644 (file)
index 0000000..386b0a2
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/multiple-frames.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/resources/event-after-navigation-new.html b/LayoutTests/batterystatus/resources/event-after-navigation-new.html
new file mode 100644 (file)
index 0000000..c132b5a
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+  <head>
+  </head>
+  <body>
+    Tests for a crash where an event is fired after the page has been navigated
+    away when the original page is in the page cache.<br><br>
+    SUCCESS
+    <script>
+        internals.setBatteryStatus(document, 'chargingchange', true, 3000, Number.POSITIVE_INFINITY, 0.5);
+        layoutTestController.notifyDone();
+    </script>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/batterystatus/script-tests/add-listener-from-callback.js b/LayoutTests/batterystatus/script-tests/add-listener-from-callback.js
new file mode 100644 (file)
index 0000000..7376689
--- /dev/null
@@ -0,0 +1,44 @@
+description('Tests that adding a new event listener from a callback works as expected.');
+
+var charging = false;
+var chargingTime = Number.POSITIVE_INFINITY;
+var dischargingTime = 6000;
+var level = 0.7;
+
+var battery = navigator.webkitBattery;
+
+function checkBatteryStatus() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+}
+
+var firstListenerEvents = 0;
+function firstListener() {
+    checkBatteryStatus();
+    if (++firstListenerEvents == 1) {
+        battery.addEventListener('chargingchange', secondListener);
+        internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+    }
+    else if (firstListenerEvents > 2)
+        testFailed('Too many events for first listener.');
+    maybeFinishTest();
+}
+
+var secondListenerEvents = 0;
+function secondListener() {
+    checkBatteryStatus();
+    if (++secondListenerEvents > 1)
+        testFailed('Too many events for second listener.');
+    maybeFinishTest();
+}
+
+function maybeFinishTest() {
+    if (firstListenerEvents == 2 && secondListenerEvents == 1)
+        finishJSTest();
+}
+
+battery.addEventListener('chargingchange', firstListener);
+internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/basic-all-types-of-events.js b/LayoutTests/batterystatus/script-tests/basic-all-types-of-events.js
new file mode 100644 (file)
index 0000000..a1fbe1e
--- /dev/null
@@ -0,0 +1,42 @@
+description('Tests the basic operation of all BatteryStatus events.');
+
+var charging = false;
+var chargingTime = Number.POSITIVE_INFINITY;
+var dischargingTime = 6000;
+var level = 0.7;
+
+var battery = navigator.webkitBattery;
+
+function checkBatteryStatus() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+}
+
+battery.addEventListener('chargingchange', function() {
+    debug('chargingchange event is raised');
+    checkBatteryStatus();
+});
+
+battery.addEventListener('chargingtimechange', function() {
+    debug('chargingtimechange event is raised');
+    checkBatteryStatus();
+});
+
+battery.addEventListener('dischargingtimechange', function() {
+    debug('dischargingtimechange event is raised');
+    checkBatteryStatus();
+});
+
+battery.addEventListener('levelchange', function() {
+    debug('levelchange event is raised');
+    checkBatteryStatus();
+    finishJSTest();
+});
+
+internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+internals.setBatteryStatus(document, 'chargingtimechange', charging, chargingTime, dischargingTime, level);
+internals.setBatteryStatus(document, 'dischargingtimechange', charging, chargingTime, dischargingTime, level);
+internals.setBatteryStatus(document, 'levelchange', charging, chargingTime, dischargingTime, level);
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/basic-operation.js b/LayoutTests/batterystatus/script-tests/basic-operation.js
new file mode 100644 (file)
index 0000000..b58f18c
--- /dev/null
@@ -0,0 +1,19 @@
+description('Tests the basic operation of BatteryStatus.');
+
+var charging = false;
+var chargingTime = Number.POSITIVE_INFINITY;
+var dischargingTime = 6000;
+var level = 0.7;
+
+var battery = navigator.webkitBattery;
+
+battery.addEventListener('chargingchange', function() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+    finishJSTest();
+});
+
+internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/event-after-navigation.js b/LayoutTests/batterystatus/script-tests/event-after-navigation.js
new file mode 100644 (file)
index 0000000..de7c512
--- /dev/null
@@ -0,0 +1,13 @@
+description('Tests for a crash where an event is fired after the page has been navigated away when the original page is in the page cache.');
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference('WebKitUsesPageCachePreferenceKey', 1);
+else
+    debug('This test can not be run without the LayoutTestController');
+
+document.body.onload = function() {
+    navigator.webkitBattery.addEventListener('chargingchange', function() { } );
+    window.location = "resources/event-after-navigation-new.html";
+}
+
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/multiple-frames.js b/LayoutTests/batterystatus/script-tests/multiple-frames.js
new file mode 100644 (file)
index 0000000..e69581a
--- /dev/null
@@ -0,0 +1,51 @@
+description('Tests using BatteryStatus from multiple frames.');
+
+var charging = false;
+var chargingTime = Number.POSITIVE_INFINITY;
+var dischargingTime = 6000;
+var level = 0.7;
+
+var battery = navigator.webkitBattery;
+
+function checkBatteryStatus() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+}
+
+function checkChildBatteryStatus() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+}
+
+var hasMainFrameEventFired = false;
+function mainFrameListener() {
+    hasMainFrameEventFired = true;
+    maybeFinishTest();
+}
+
+var hasChildFrameEventFired = false;
+function childFrameListener() {
+    hasChildFrameEventFired = true;
+    maybeFinishTest();
+}
+
+function maybeFinishTest() {
+    if (hasMainFrameEventFired && hasChildFrameEventFired) {
+        checkBatteryStatus();
+        checkChildBatteryStatus();
+        finishJSTest();
+    }
+}
+
+var childFrame = document.createElement('iframe');
+document.body.appendChild(childFrame);
+var childBattery = childFrame.contentWindow.navigator.webkitBattery
+childBattery.addEventListener('chargingchange', childFrameListener);
+battery.addEventListener('chargingchange', mainFrameListener);
+
+internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/updates.js b/LayoutTests/batterystatus/script-tests/updates.js
new file mode 100644 (file)
index 0000000..7a96667
--- /dev/null
@@ -0,0 +1,39 @@
+description('Tests that updates to the battery event causes new events to fire.');
+
+var charging = false;
+var chargingTime = Number.POSITIVE_INFINITY;
+var dischargingTime = 6000;
+var level = 0.7;
+
+var battery = navigator.webkitBattery;
+
+function checkBatteryStatus() {
+    shouldBe('battery.charging', 'charging');
+    shouldBe('battery.chargingTime', 'chargingTime');
+    shouldBe('battery.dischargingTime', 'dischargingTime');
+    shouldBe('battery.level', 'level');
+}
+
+function setBatteryStatus() {
+    internals.setBatteryStatus(document, 'chargingchange', charging, chargingTime, dischargingTime, level);
+}
+
+function firstListener() {
+    checkBatteryStatus();
+    battery.removeEventListener('chargingchange', firstListener);
+    battery.addEventListener('chargingchange', updateListener);
+    charging = true;
+    chargingTime = 7000;
+    dischargingTime = Number.POSITIVE_INFINITY;
+    level = 0.3;
+       setBatteryStatus();
+}
+
+function updateListener(event) {
+    checkBatteryStatus(event);
+    finishJSTest();
+}
+
+battery.addEventListener('chargingchange', firstListener);
+setBatteryStatus();
+window.jsTestIsAsync = true;
diff --git a/LayoutTests/batterystatus/script-tests/window-property.js b/LayoutTests/batterystatus/script-tests/window-property.js
new file mode 100644 (file)
index 0000000..fefe376
--- /dev/null
@@ -0,0 +1,23 @@
+description('Tests that the window.navigator.battery properties are present.');
+
+function hasOnBatteryProperty()
+{
+    var result = 0;
+    for (var property in navigator.webkitBattery) {
+        if (property == 'onchargingchange' ||
+            property == 'onchargingtimechange' ||
+            property == 'ondischargingtimechange' ||
+            property == 'onlevelchange')
+            result += 1;
+    }
+    if (result == 4)
+        return true;
+    return false;
+}
+
+shouldBeTrue("typeof navigator.webkitBattery == 'object'");
+shouldBeTrue("hasOnBatteryProperty()");
+shouldBeTrue("navigator.webkitBattery.hasOwnProperty('onchargingchange')");
+shouldBeTrue("navigator.webkitBattery.hasOwnProperty('onchargingtimechange')");
+shouldBeTrue("navigator.webkitBattery.hasOwnProperty('ondischargingtimechange')");
+shouldBeTrue("navigator.webkitBattery.hasOwnProperty('onlevelchange')");
diff --git a/LayoutTests/batterystatus/updates-expected.txt b/LayoutTests/batterystatus/updates-expected.txt
new file mode 100644 (file)
index 0000000..31734c1
--- /dev/null
@@ -0,0 +1,17 @@
+Tests that updates to the battery event causes new events to fire.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS battery.charging is charging
+PASS battery.chargingTime is chargingTime
+PASS battery.dischargingTime is dischargingTime
+PASS battery.level is level
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/updates.html b/LayoutTests/batterystatus/updates.html
new file mode 100644 (file)
index 0000000..e733ad1
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/updates.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/batterystatus/window-property-expected.txt b/LayoutTests/batterystatus/window-property-expected.txt
new file mode 100644 (file)
index 0000000..41e6fd5
--- /dev/null
@@ -0,0 +1,15 @@
+Tests that the window.navigator.battery properties are present.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS typeof navigator.webkitBattery == 'object' is true
+PASS hasOnBatteryProperty() is true
+PASS navigator.webkitBattery.hasOwnProperty('onchargingchange') is true
+PASS navigator.webkitBattery.hasOwnProperty('onchargingtimechange') is true
+PASS navigator.webkitBattery.hasOwnProperty('ondischargingtimechange') is true
+PASS navigator.webkitBattery.hasOwnProperty('onlevelchange') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/batterystatus/window-property.html b/LayoutTests/batterystatus/window-property.html
new file mode 100644 (file)
index 0000000..e9088f2
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/window-property.js"></script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index b8db5c6251825fd2358e538a8acbb72bd9925694..66ec743c0af5979ec69777843b97bc04059f4a03 100644 (file)
@@ -113,6 +113,9 @@ BUGCR103939 SKIP : http/tests/appcache/wrong-content-type.html = TEXT
 // Vibration API is not supported yet in the chromium port.
 BUGWK72010 SKIP : fast/dom/navigator-vibration.html = FAIL
 
+// Battery Status API is not supported yet in the chromium port.
+BUGWK62698 SKIP : batterystatus = PASS FAIL
+
 // -----------------------------------------------------------------
 // WONTFIX TESTS
 // -----------------------------------------------------------------
index 0dd765e50601daef77f866f2305275629e05cf93..5918f2932ca492dc784a25a8aab7b37c32100ee5 100644 (file)
@@ -402,6 +402,9 @@ webintents/
 # Pointer Lock is not implemented.
 pointer-lock/
 
+#Battery Status API support not yet. http://webkit.org/b/62698
+batterystatus
+
 ###############################################################################
 # TESTS FAILING
 ###############################################################################
index eafb9a192d4d527b27e36b202363251d21239507..ebafd031eb4f73f9c8a85e7e4ce628f014cc5bf4 100644 (file)
@@ -583,3 +583,7 @@ svg/custom/delete-text-crash.html
 canvas/philip/tests/2d.line.cap.round.html
 canvas/philip/tests/2d.shadow.canvas.transparent.2.html
 canvas/philip/tests/2d.shadow.image.transparent.2.html
+
+# https://bugs.webkit.org/show_bug.cgi?id=62698
+# Needs BatteryClient implementation.
+batterystatus/
index 56dd7acaa98820bcfceab9b1f4b2c71b66cc9add..a16c4a58bba6595b5b9a817b5c3440e8e1b2fd2d 100644 (file)
@@ -362,6 +362,9 @@ fast/dom/Window/window-postmessage-arrays.html
 #Vibration API is not implemented.
 fast/dom/navigator-vibration.html
 
+#Battery Status API is not implemented.
+batterystatus
+
 # =========================================================================== #
 #       Drag and Drop Support in DRT.                                         #
 # =========================================================================== #
index 3cdef094dfae59b02d1de65c047330c5cc06faca..f75b6a940ac44713136d28188b98eed45247c871 100644 (file)
@@ -1661,6 +1661,9 @@ fast/repaint/transform-absolute-in-positioned-container.html
 #Vibration API is not implemented.
 fast/dom/navigator-vibration.html
 
+#Battery Status API is not implemented.
+batterystatus
+
 # Those tests need a text baseline after lazily allocating layers.
 # The change should only be layer removal.
 animations/combo-transform-translate+scale.html
index 1d777f4c1d4754541167cdf2ac8480487c371515..b8c37df2f7d2370a7511c70f99150397a91a6f57 100644 (file)
@@ -2058,3 +2058,6 @@ fast/mutation/end-of-task-delivery.html
 
 #Vibration API is not implemented.
 fast/dom/navigator-vibration.html
+
+#Battery Status API is not implemented.
+batterystatus
index bf0cd3ca625393d3f1cdf64485c00630acda1dbb..69ca95a8970212990d8022051424623ca67c25de 100644 (file)
@@ -2334,6 +2334,22 @@ SET(WebCoreTestSupport_SOURCES
     testing/InternalSettings.cpp
 )
 
+IF (ENABLE_BATTERY_STATUS)
+    LIST(APPEND WebCore_INCLUDE_DIRECTORIES
+        "${WEBCORE_DIR}/Modules/battery"
+    )
+    LIST(APPEND WebCore_IDL_FILES
+        Modules/battery/NavigatorBattery.idl
+        Modules/battery/BatteryManager.idl
+    )
+    LIST(APPEND WebCore_SOURCES
+        Modules/battery/NavigatorBattery.cpp
+        Modules/battery/BatteryController.cpp
+        Modules/battery/BatteryManager.cpp
+        Modules/battery/BatteryStatus.cpp
+    )
+ENDIF ()
+
 # Modules that the bindings generator scripts may use
 SET(SCRIPTS_RESOLVE_SUPPLEMENTAL
     ${WEBCORE_DIR}/bindings/scripts/IDLParser.pm
index 00e95e302d31856da828ff5817badd49e239e12b..beebc49b04a11d6027365b2ddbcfe3e2485cf4e5 100644 (file)
@@ -1,3 +1,103 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Battery Status API is implemented under the Navigator class.
+        Battery Status API has four types of events, and all events are operated based on a callback mechanism.
+         : onchargingchange, onchargingtimechange, ondischargingtimechange, onlevelchange.
+        The battery status can be accessed using BatteryManager(navigator.webkitBattery), and battery status is controlled by BatteryController which manages instances of BatteryManager.
+        When battery status event is raised, BatteryController calls all registered BatteryManager's event dispatcher.
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        Tests: batterystatus/add-listener-from-callback.html
+               batterystatus/basic-all-types-of-events.html
+               batterystatus/basic-operation.html
+               batterystatus/event-after-navigation.html
+               batterystatus/multiple-frames.html
+               batterystatus/updates.html
+               batterystatus/window-property.html
+
+        * CMakeLists.txt:
+        * Modules/battery/BatteryClient.h: Added.
+        (WebCore):
+        (BatteryClient):
+        (WebCore::BatteryClient::~BatteryClient):
+        * Modules/battery/BatteryController.cpp: Added.
+        (WebCore):
+        (WebCore::BatteryController::BatteryController):
+        (WebCore::BatteryController::~BatteryController):
+        (WebCore::BatteryController::create):
+        (WebCore::BatteryController::addListener):
+        (WebCore::BatteryController::removeListener):
+        (WebCore::BatteryController::didChangeBatteryStatus):
+        (WebCore::BatteryController::supplementName):
+        (WebCore::BatteryController::isActive):
+        (WebCore::provideBatteryTo):
+        * Modules/battery/BatteryController.h: Added.
+        (WebCore):
+        (BatteryController):
+        (WebCore::BatteryController::client):
+        (WebCore::BatteryController::from):
+        * Modules/battery/BatteryManager.cpp: Added.
+        (WebCore):
+        (WebCore::BatteryManager::create):
+        (WebCore::BatteryManager::~BatteryManager):
+        (WebCore::BatteryManager::BatteryManager):
+        (WebCore::BatteryManager::charging):
+        (WebCore::BatteryManager::chargingTime):
+        (WebCore::BatteryManager::dischargingTime):
+        (WebCore::BatteryManager::level):
+        (WebCore::BatteryManager::didChangeBatteryStatus):
+        (WebCore::BatteryManager::suspend):
+        (WebCore::BatteryManager::resume):
+        (WebCore::BatteryManager::stop):
+        * Modules/battery/BatteryManager.h: Added.
+        (WebCore):
+        (BatteryManager):
+        (WebCore::BatteryManager::interfaceName):
+        (WebCore::BatteryManager::scriptExecutionContext):
+        (WebCore::BatteryManager::batteryControllerDestroyed):
+        (WebCore::BatteryManager::canSuspend):
+        (WebCore::BatteryManager::eventTargetData):
+        (WebCore::BatteryManager::ensureEventTargetData):
+        (WebCore::BatteryManager::refEventTarget):
+        (WebCore::BatteryManager::derefEventTarget):
+        * Modules/battery/BatteryManager.idl: Added.
+        * Modules/battery/BatteryStatus.cpp: Added.
+        (WebCore):
+        (WebCore::BatteryStatus::create):
+        (WebCore::BatteryStatus::BatteryStatus):
+        * Modules/battery/BatteryStatus.h: Added.
+        (WebCore):
+        (BatteryStatus):
+        (WebCore::BatteryStatus::charging):
+        (WebCore::BatteryStatus::chargingTime):
+        (WebCore::BatteryStatus::dischargingTime):
+        (WebCore::BatteryStatus::level):
+        * Modules/battery/NavigatorBattery.cpp: Added.
+        (WebCore):
+        (WebCore::NavigatorBattery::NavigatorBattery):
+        (WebCore::NavigatorBattery::~NavigatorBattery):
+        (WebCore::NavigatorBattery::webkitBattery):
+        (WebCore::NavigatorBattery::from):
+        (WebCore::NavigatorBattery::batteryManager):
+        * Modules/battery/NavigatorBattery.h: Added.
+        (WebCore):
+        (NavigatorBattery):
+        * Modules/battery/NavigatorBattery.idl: Added.
+        * dom/EventNames.h:
+        (WebCore):
+        * dom/EventTargetFactory.in:
+        * testing/Internals.cpp:
+        (WebCore::Internals::setBatteryStatus):
+        (WebCore):
+        * testing/Internals.h:
+        (Internals):
+        * testing/Internals.idl:
+
 2012-03-16  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Web Inspector: HeapSnapshot: speedup buildReverseIndex.
diff --git a/Source/WebCore/Modules/battery/BatteryClient.h b/Source/WebCore/Modules/battery/BatteryClient.h
new file mode 100644 (file)
index 0000000..bf56336
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BatteryClient_h
+#define BatteryClient_h
+
+#if ENABLE(BATTERY_STATUS)
+
+namespace WebCore {
+
+class BatteryController;
+class Page;
+
+class BatteryClient {
+public:
+    virtual ~BatteryClient() { }
+
+    virtual void setController(BatteryController*) = 0;
+    virtual void startUpdating() = 0;
+    virtual void stopUpdating() = 0;
+    virtual void batteryControllerDestroyed() = 0;
+};
+
+void provideBatteryTo(Page*, BatteryClient*);
+
+}
+
+#endif // BATTERY_STATUS
+#endif // BatteryClient_h
+
diff --git a/Source/WebCore/Modules/battery/BatteryController.cpp b/Source/WebCore/Modules/battery/BatteryController.cpp
new file mode 100644 (file)
index 0000000..5d192a9
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "BatteryController.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryClient.h"
+#include "BatteryStatus.h"
+#include "Event.h"
+
+namespace WebCore {
+
+BatteryController::BatteryController(BatteryClient* client)
+    : m_client(client)
+{
+    ASSERT(m_client);
+    m_client->setController(this);
+}
+
+BatteryController::~BatteryController()
+{
+    for (ListenerVector::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
+        (*it)->batteryControllerDestroyed();
+    m_client->batteryControllerDestroyed();
+}
+
+PassOwnPtr<BatteryController> BatteryController::create(BatteryClient* client)
+{
+    return adoptPtr(new BatteryController(client));
+}
+
+void BatteryController::addListener(BatteryManager* batteryManager)
+{
+    m_listeners.append(batteryManager);
+    m_client->startUpdating();
+}
+
+void BatteryController::removeListener(BatteryManager* batteryManager)
+{
+    size_t pos = m_listeners.find(batteryManager);
+    if (pos == WTF::notFound)
+        return;
+    m_listeners.remove(pos);
+    if (m_listeners.isEmpty())
+        m_client->stopUpdating();
+}
+
+void BatteryController::didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus> batteryStatus)
+{
+    RefPtr<Event> event = Event::create(eventType, false, false);
+    RefPtr<BatteryStatus> battery = batteryStatus;
+    for (ListenerVector::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
+        (*it)->didChangeBatteryStatus(event, battery);
+}
+
+const AtomicString& BatteryController::supplementName()
+{
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("BatteryController"));
+    return name;
+}
+
+bool BatteryController::isActive(Page* page)
+{
+    return static_cast<bool>(BatteryController::from(page));
+}
+
+void provideBatteryTo(Page* page, BatteryClient* client)
+{
+    Supplement<Page>::provideTo(page, BatteryController::supplementName(), BatteryController::create(client));
+}
+
+}
+
+#endif // BATTERY_STATUS
+
diff --git a/Source/WebCore/Modules/battery/BatteryController.h b/Source/WebCore/Modules/battery/BatteryController.h
new file mode 100644 (file)
index 0000000..a5d779a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BatteryController_h
+#define BatteryController_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryManager.h"
+#include "Page.h"
+
+namespace WebCore {
+
+class BatteryClient;
+
+class BatteryController : public Supplement<Page> {
+public:
+    ~BatteryController();
+
+    static PassOwnPtr<BatteryController> create(BatteryClient*);
+
+    void addListener(BatteryManager*);
+    void removeListener(BatteryManager*);
+    void didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus>);
+
+    BatteryClient* client() const { return m_client; }
+
+    static const AtomicString& supplementName();
+    static BatteryController* from(Page* page) { return static_cast<BatteryController*>(Supplement<Page>::from(page, supplementName())); }
+    static bool isActive(Page*);
+
+private:
+    typedef Vector<BatteryManager*> ListenerVector;
+
+    explicit BatteryController(BatteryClient*);
+
+    BatteryClient* m_client;
+    ListenerVector m_listeners;
+};
+
+}
+
+#endif // BATTERY_STATUS
+#endif // BatteryController_h
+
diff --git a/Source/WebCore/Modules/battery/BatteryManager.cpp b/Source/WebCore/Modules/battery/BatteryManager.cpp
new file mode 100644 (file)
index 0000000..7e8d131
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "BatteryManager.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryController.h"
+#include "BatteryStatus.h"
+#include "Event.h"
+#include "Frame.h"
+#include "Navigator.h"
+#include <limits>
+
+namespace WebCore {
+
+PassRefPtr<BatteryManager> BatteryManager::create(ScriptExecutionContext* context, Navigator* navigator)
+{
+    RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(context, navigator)));
+    batteryManager->suspendIfNeeded();
+    return batteryManager.release();
+}
+
+BatteryManager::~BatteryManager()
+{
+}
+
+BatteryManager::BatteryManager(ScriptExecutionContext* context, Navigator* navigator)
+    : ActiveDOMObject(context, this)
+    , m_batteryController(BatteryController::from(navigator->frame()->page()))
+    , m_batteryStatus(0)
+{
+    m_batteryController->addListener(this);
+}
+
+bool BatteryManager::charging()
+{
+    return m_batteryStatus->charging();
+}
+
+double BatteryManager::chargingTime()
+{
+    if (!m_batteryStatus->charging())
+        return std::numeric_limits<double>::infinity();
+
+    return m_batteryStatus->chargingTime();
+}
+
+double BatteryManager::dischargingTime()
+{
+    if (m_batteryStatus->charging())
+        return std::numeric_limits<double>::infinity();
+
+    return m_batteryStatus->dischargingTime();
+}
+
+double BatteryManager::level()
+{
+    return m_batteryStatus->level();
+}
+
+void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr<BatteryStatus> batteryStatus)
+{
+    m_batteryStatus = batteryStatus;
+    dispatchEvent(event);
+}
+
+void BatteryManager::suspend(ReasonForSuspension)
+{
+    if (m_batteryController)
+        m_batteryController->removeListener(this);
+}
+
+void BatteryManager::resume()
+{
+    if (m_batteryController)
+        m_batteryController->addListener(this);
+}
+
+void BatteryManager::stop()
+{
+    if (m_batteryController)
+        m_batteryController->removeListener(this);
+}
+
+} // namespace WebCore
+
+#endif // BATTERY_STATUS
+
diff --git a/Source/WebCore/Modules/battery/BatteryManager.h b/Source/WebCore/Modules/battery/BatteryManager.h
new file mode 100644 (file)
index 0000000..7978ddc
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BatteryManager_h
+#define BatteryManager_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "ActiveDOMObject.h"
+#include "BatteryStatus.h"
+#include "EventTarget.h"
+
+namespace WebCore {
+
+class BatteryController;
+class Navigator;
+class ScriptExecutionContext;
+
+class BatteryManager : public ActiveDOMObject, public RefCounted<BatteryManager>, public EventTarget {
+public:
+    virtual ~BatteryManager();
+    static PassRefPtr<BatteryManager> create(ScriptExecutionContext*, Navigator*);
+
+    // EventTarget implementation.
+    virtual const WTF::AtomicString& interfaceName() const { return eventNames().interfaceForBatteryManager; }
+    virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); }
+
+    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>, PassRefPtr<BatteryStatus>);
+    void batteryControllerDestroyed() { m_batteryController = 0; }
+
+    using RefCounted<BatteryManager>::ref;
+    using RefCounted<BatteryManager>::deref;
+
+    // ActiveDOMObject implementation.
+    virtual bool canSuspend() const { return true; }
+    virtual void suspend(ReasonForSuspension);
+    virtual void resume();
+    virtual void stop();
+
+protected:
+    virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
+    virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
+
+private:
+    BatteryManager(ScriptExecutionContext*, Navigator*);
+
+    // EventTarget implementation.
+    virtual void refEventTarget() { ref(); }
+    virtual void derefEventTarget() { deref(); }
+
+    BatteryController* m_batteryController;
+    EventTargetData m_eventTargetData;
+    RefPtr<BatteryStatus> m_batteryStatus;
+};
+
+}
+
+#endif // BATTERY_STATUS
+#endif // BatteryManager_h
+
diff --git a/Source/WebCore/Modules/battery/BatteryManager.idl b/Source/WebCore/Modules/battery/BatteryManager.idl
new file mode 100644 (file)
index 0000000..e552df3
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+module window {
+
+    // http://dev.w3.org/2009/dap/system-info/battery-status.html
+    interface [
+        Conditional=BATTERY_STATUS,
+        ActiveDOMObject,
+        EventTarget
+     ] BatteryManager {
+        readonly attribute boolean charging;
+        readonly attribute double chargingTime;
+        readonly attribute double dischargingTime;
+        readonly attribute double level;
+
+        attribute EventListener onchargingchange;
+        attribute EventListener onchargingtimechange;
+        attribute EventListener ondischargingtimechange;
+        attribute EventListener onlevelchange;
+
+        // EventTarget interface
+        void addEventListener(in DOMString type,
+                              in EventListener listener,
+                              in [Optional] boolean useCapture);
+        void removeEventListener(in DOMString type,
+                                 in EventListener listener,
+                                 in [Optional] boolean useCapture);
+        boolean dispatchEvent(in Event evt)
+            raises(EventException);
+    };
+
+}
+
diff --git a/Source/WebCore/Modules/battery/BatteryStatus.cpp b/Source/WebCore/Modules/battery/BatteryStatus.cpp
new file mode 100644 (file)
index 0000000..00f530b
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "BatteryStatus.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include <limits>
+
+namespace WebCore {
+
+PassRefPtr<BatteryStatus> BatteryStatus::create()
+{
+    return adoptRef(new BatteryStatus);
+}
+
+PassRefPtr<BatteryStatus> BatteryStatus::create(bool charging, double chargingTime, double dischargingTime, double level)
+{
+    return adoptRef(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
+
+#endif // BATTERY_STATUS
+
diff --git a/Source/WebCore/Modules/battery/BatteryStatus.h b/Source/WebCore/Modules/battery/BatteryStatus.h
new file mode 100644 (file)
index 0000000..2c451ab
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BatteryStatus_h
+#define BatteryStatus_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class BatteryStatus : public RefCounted<BatteryStatus> {
+public:
+    static PassRefPtr<BatteryStatus> create();
+    static PassRefPtr<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 // BATTERY_STATUS
+#endif // BatteryStatus_h
+
diff --git a/Source/WebCore/Modules/battery/NavigatorBattery.cpp b/Source/WebCore/Modules/battery/NavigatorBattery.cpp
new file mode 100644 (file)
index 0000000..1b67248
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "NavigatorBattery.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryController.h"
+#include "BatteryManager.h"
+#include "Navigator.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+NavigatorBattery::NavigatorBattery()
+{
+}
+
+NavigatorBattery::~NavigatorBattery()
+{
+}
+
+BatteryManager* NavigatorBattery::webkitBattery(ScriptExecutionContext* context, Navigator* navigator)
+{
+    NavigatorBattery* navigatorBattery = NavigatorBattery::from(navigator);
+    if (!navigatorBattery->m_batteryManager)
+        navigatorBattery->m_batteryManager = BatteryManager::create(context, navigator);
+    return navigatorBattery->m_batteryManager.get();
+}
+
+NavigatorBattery* NavigatorBattery::from(Navigator* navigator)
+{
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("NavigatorBattery"));
+    NavigatorBattery* supplement = static_cast<NavigatorBattery*>(Supplement<Navigator>::from(navigator, name));
+    if (!supplement) {
+        supplement = new NavigatorBattery();
+        provideTo(navigator, name, adoptPtr(supplement));
+    }
+    return supplement;
+}
+
+BatteryManager* NavigatorBattery::batteryManager()
+{
+    return m_batteryManager.get();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(BATTERY_STATUS)
+
+
diff --git a/Source/WebCore/Modules/battery/NavigatorBattery.h b/Source/WebCore/Modules/battery/NavigatorBattery.h
new file mode 100644 (file)
index 0000000..9fae9df
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef NavigatorBattery_h
+#define NavigatorBattery_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "Supplementable.h"
+
+namespace WebCore {
+
+class BatteryManager;
+class Navigator;
+class ScriptExecutionContext;
+
+class NavigatorBattery : public Supplement<Navigator> {
+public:
+    virtual ~NavigatorBattery();
+
+    static NavigatorBattery* from(Navigator*);
+
+    static BatteryManager* webkitBattery(ScriptExecutionContext*, Navigator*);
+    BatteryManager* batteryManager();
+
+ private:
+    NavigatorBattery();
+
+    RefPtr<BatteryManager> m_batteryManager;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(BATTERY_STATUS)
+
+#endif // NavigatorBattery_h
+
+
diff --git a/Source/WebCore/Modules/battery/NavigatorBattery.idl b/Source/WebCore/Modules/battery/NavigatorBattery.idl
new file mode 100644 (file)
index 0000000..6cdb783
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+module window {
+
+    interface [
+        CallWith=ScriptExecutionContext,
+        Conditional=BATTERY_STATUS,
+        Supplemental=Navigator
+    ] NavigatorBattery {
+        readonly attribute BatteryManager webkitBattery;
+    };
+
+}
+
index dbfc4f9c7f8c4482bc3896507ee184c505d8e69b..6e22b73815d1123ee4545e6a4510bd3ca53897f0 100644 (file)
@@ -41,6 +41,8 @@ namespace WebCore {
     macro(blur) \
     macro(cached) \
     macro(change) \
+    macro(chargingchange) \
+    macro(chargingtimechange) \
     macro(checking) \
     macro(click) \
     macro(close) \
@@ -55,6 +57,7 @@ namespace WebCore {
     macro(dblclick) \
     macro(devicemotion) \
     macro(deviceorientation) \
+    macro(dischargingtimechange) \
     macro(display) \
     macro(downloading) \
     macro(drag) \
@@ -74,6 +77,7 @@ namespace WebCore {
     macro(keydown) \
     macro(keypress) \
     macro(keyup) \
+    macro(levelchange) \
     macro(load) \
     macro(loadstart) \
     macro(message) \
index 8577d3e3974a3a2a2e0b9a36469fba33efd08f51..d998b46e7a31e78d807c7191426023dc654b4fdd 100644 (file)
@@ -1,6 +1,7 @@
 namespace="EventTarget"
 
 AudioContext conditional=WEB_AUDIO
+BatteryManager conditional=BATTERY_STATUS
 DedicatedWorkerContext conditional=WORKERS
 DOMApplicationCache
 DOMWindow
index c2936864f7e4b230d4d5c938ba9845ed41ac5afa..622b64e3e01e635763c7089b0db67c03e3a28224 100644 (file)
 #include "ColorChooser.h"
 #endif
 
+#if ENABLE(BATTERY_STATUS)
+#include "BatteryController.h"
+#endif
+
 namespace WebCore {
 
 static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerTypes& result)
@@ -714,4 +718,22 @@ void Internals::emitInspectorDidCancelFrame()
     InspectorInstrumentation::didCancelFrame(frame()->page());
 }
 
+void Internals::setBatteryStatus(Document* document, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode& ec)
+{
+    if (!document || !document->page()) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+#if ENABLE(BATTERY_STATUS)
+    BatteryController::from(document->page())->didChangeBatteryStatus(eventType, BatteryStatus::create(charging, chargingTime, dischargingTime, level));
+#else
+    UNUSED_PARAM(eventType);
+    UNUSED_PARAM(charging);
+    UNUSED_PARAM(chargingTime);
+    UNUSED_PARAM(dischargingTime);
+    UNUSED_PARAM(level);
+#endif
+}
+
 }
index 67c0922bbb5b0f4fabefaacd04f39b7dad0ba042..9716a3ca4ded6f1617e04b80c2c1c26068374f15 100644 (file)
@@ -136,6 +136,8 @@ public:
 
     InternalSettings* settings() const { return m_settings.get(); }
 
+    void setBatteryStatus(Document*, const String& eventType, bool charging, double chargingTime, double dischargingTime, double level, ExceptionCode&);
+
 private:
     explicit Internals(Document*);
     DocumentMarker* markerAt(Node*, const String& markerType, unsigned index, ExceptionCode&);
index d9856ad025e58b99a910254d56026a8aa329e334..72bf90790c47f2ee82259348229bb7945e381567 100644 (file)
@@ -110,6 +110,10 @@ module window {
         void emitInspectorDidCancelFrame();
 
         readonly attribute InternalSettings settings;
+
+#if defined(ENABLE_BATTERY_STATUS) && ENABLE_BATTERY_STATUS
+        void setBatteryStatus(in Document document, in DOMString eventType, in boolean charging, in double chargingTime, in double dischargingTime, in double level) raises (DOMException);
+#endif
     };
 }
 
index 4f1cf58b977d5fba172861db1b388bc99892d632..bc3a567d863ddff3c96e34df6e6e9968f15d49c1 100644 (file)
@@ -1,3 +1,15 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Add include directory and file.
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        * PlatformEfl.cmake:
+
 2012-03-11  Timothy Hatcher  <timothy@apple.com>
 
         Update how the Web Inspector resources are loaded.
index 1debe368418b58a7637235c6a1790c43cdbecb6b..158413553d9302dad17e824a594db6d7c3ac1f5c 100644 (file)
@@ -126,6 +126,10 @@ IF (ENABLE_VIBRATION)
     )
 ENDIF ()
 
+IF (ENABLE_BATTERY_STATUS)
+    LIST(APPEND WebKit_INCLUDE_DIRECTORIES ${WEBCORE_DIR}/Modules/battery)
+    LIST(APPEND WebKit_SOURCES efl/WebCoreSupport/BatteryClientEfl.cpp)
+ENDIF ()
 
 SET(WebKit_THEME_DEFINITION "")
 IF (ENABLE_PROGRESS_TAG)
index 306775af9bef7e60c6dbde4afe05c55e61631ca6..14718dbabe0dc25d3b4c8107de0b45121cb4ae6f 100644 (file)
@@ -1,3 +1,31 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Add BatteryClientEfl class implementation for the layout tests now.
+        BatteryClientEfl class is not fully implemented in this patch.
+        (It will be completed by other patch as necessary in the Efl port.)
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        * WebCoreSupport/BatteryClientEfl.cpp: Added.
+        (WebCore):
+        (WebCore::BatteryClientEfl::BatteryClientEfl):
+        (WebCore::BatteryClientEfl::setController):
+        (WebCore::BatteryClientEfl::startUpdating):
+        (WebCore::BatteryClientEfl::stopUpdating):
+        (WebCore::BatteryClientEfl::batteryControllerDestroyed):
+        (WebCore::BatteryClientEfl::setBatteryStatus):
+        * WebCoreSupport/BatteryClientEfl.h: Added.
+        (WebCore):
+        (BatteryClientEfl):
+        (WebCore::BatteryClientEfl::~BatteryClientEfl):
+        * ewk/ewk_view.cpp:
+        (_Ewk_View_Private_Data):
+        (_ewk_view_priv_new):
+
 2012-03-13  Jon Lee  <jonlee@apple.com>
 
         Separate NOTIFICATIONS and LEGACY_NOTIFICATIONS
diff --git a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp
new file mode 100644 (file)
index 0000000..88dbfd9
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "BatteryClientEfl.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryController.h"
+
+namespace WebCore {
+
+BatteryClientEfl::BatteryClientEfl()
+    : m_controller(0)
+{
+}
+
+void BatteryClientEfl::setController(BatteryController* controller)
+{
+    m_controller = controller;
+}
+
+void BatteryClientEfl::startUpdating()
+{
+    // FIXME: Need to implement for getting battery status to the efl port.
+}
+
+void BatteryClientEfl::stopUpdating()
+{
+    // FIXME: Need to implement for getting battery status to the efl port
+}
+
+void BatteryClientEfl::batteryControllerDestroyed()
+{
+    delete this;
+}
+
+void BatteryClientEfl::setBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus> batteryStatus)
+{
+    m_controller->didChangeBatteryStatus(eventType, batteryStatus);
+}
+
+}
+
+#endif // BATTERY_STATUS
+
diff --git a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h
new file mode 100644 (file)
index 0000000..a4f71c8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BatteryClientEfl_h
+#define BatteryClientEfl_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "BatteryClient.h"
+#include <wtf/text/AtomicString.h>
+
+namespace WebCore {
+
+class BatteryController;
+class BatteryStatus;
+
+class BatteryClientEfl : public BatteryClient {
+public:
+    BatteryClientEfl();
+    ~BatteryClientEfl() { };
+
+    virtual void setController(BatteryController*);
+    virtual void startUpdating();
+    virtual void stopUpdating();
+    virtual void batteryControllerDestroyed();
+
+    void setBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus>);
+
+private:
+    BatteryController* m_controller;
+};
+
+}
+
+#endif // BATTERY_STATUS
+#endif // BatteryClientEfl_h
+
index 17a6ea069692bf69fd37fe5dced96b62982d3f51..7a52caf1c22311a111c4b5f30e0f477d0c2e457c 100644 (file)
 #include "VibrationClientEfl.h"
 #endif
 
+#if ENABLE(BATTERY_STATUS)
+#include "BatteryClientEfl.h"
+#endif
+
 static const float zoomMinimum = 0.05;
 static const float zoomMaximum = 4.0;
 
@@ -618,6 +622,10 @@ static Ewk_View_Private_Data* _ewk_view_priv_new(Ewk_View_Smart_Data* smartData)
     WebCore::provideVibrationTo(priv->page.get(), new WebCore::VibrationClientEfl(smartData->self));
 #endif
 
+#if ENABLE(BATTERY_STATUS)
+    WebCore::provideBatteryTo(priv->page.get(), new WebCore::BatteryClientEfl);
+#endif
+
     priv->pageSettings = priv->page->settings();
 
     priv->viewportArguments.width = WebCore::ViewportArguments::ValueAuto;
index 40e8730f3f92524aeef8ac16362c7702c3c20bdb..41f50eb3ab51ae558d2781c3a46864e58f1a0ce4 100644 (file)
@@ -64,6 +64,7 @@ SET(THEME_BINARY_DIR ${CMAKE_BINARY_DIR}/WebKit/efl/DefaultTheme)
 
 SET(VERSION_SCRIPT "-Wl,--version-script,${CMAKE_MODULE_PATH}/eflsymbols.filter")
 
+WEBKIT_FEATURE(ENABLE_BATTERY_STATUS "Enable battery status api" DEFAULT ON)
 WEBKIT_FEATURE(ENABLE_BLOB "Enable blob slice" DEFAULT OFF)
 WEBKIT_FEATURE(ENABLE_CHANNEL_MESSAGING "Enable channel messaging" DEFAULT ON)
 WEBKIT_FEATURE(ENABLE_DATALIST "Enable datalist" DEFAULT ON)
index ce216ab290f4a7cf34136d631bda5e302467c270..82caf6f55f3e09f6d925dac49a2860adbc13b2fa 100644 (file)
@@ -6,6 +6,7 @@
 
 
 #cmakedefine01 ENABLE_AS_IMAGE
+#cmakedefine01 ENABLE_BATTERY_STATUS
 #cmakedefine01 ENABLE_BLOB
 #cmakedefine01 ENABLE_CHANNEL_MESSAGING
 #cmakedefine01 ENABLE_DATALIST
index e422cb5cf2d45cef08da2d9d311b5d687e18dcbb..aa260cc7da17d6aa84c241e46acf6e4467f87dcb 100644 (file)
@@ -1,3 +1,15 @@
+2012-03-16  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        Support for Battery Status API
+        https://bugs.webkit.org/show_bug.cgi?id=62698
+
+        Add include directory and file.
+        http://www.w3.org/TR/battery-status/
+
+        Reviewed by Adam Barth.
+
+        * Scripts/build-webkit:
+
 2012-03-16  Kishore Bolisetty  <kbolisetty@innominds.com>
 
         check-webkit-style fails on LayoutTests/platform/efl/test_expectations.txt
index adffdb919763e62389199e86626071d8745a8f58..ccc431575a0e001c95851369d7517e2011122fb3 100755 (executable)
@@ -70,6 +70,7 @@ my (
     $threeDRenderingSupport,
     $accelerated2dCanvasSupport,
     $animationAPISupport,
+    $batterystatusAPISupport,
     $blobSupport,
     $channelMessagingSupport,
     $coverageSupport,
@@ -160,6 +161,9 @@ my @features = (
     { option => "animation-api", desc => "Toggle animation API support",
       define => "ENABLE_ANIMATION_API", default => isBlackBerry(), value => \$animationAPISupport },
 
+    { option => "battery-status-api", desc => "Toggle battery status API support",
+      define => "ENABLE_BATTERY_STATUS", default => isEfl(), value => \$batterystatusAPISupport },
+
     { option => "blob", desc => "Toggle Blob support",
       define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk() || isChromium() || isBlackBerry()), value => \$blobSupport },