Title: [149063] trunk/Source/WebCore
Revision
149063
Author
commit-qu...@webkit.org
Date
2013-04-24 13:38:38 -0700 (Wed, 24 Apr 2013)

Log Message

Battery API won't return updated battery status until client calls didChangeBatteryStatus
https://bugs.webkit.org/show_bug.cgi?id=114891

Patch by Otto Derek Cheung <otche...@rim.com> on 2013-04-24
Reviewed by Rob Buis.

The BatteryStatus object in BatteryManager won't get updated until BatteryClient calls
didChangeBatteryStatus in BatteryController. Any attempts to call webkitBattery.charged()
or other get functions will always return the default values until the next battery status
change object gets passed to the controller.

We need to update the manager when we attach it to the controller, and update all
existing managers when the controller receives it's first battery status object.

* Modules/battery/BatteryController.cpp:
(WebCore::BatteryController::addListener):
(WebCore::BatteryController::updateBatteryStatus):
* Modules/battery/BatteryManager.cpp:
(WebCore::BatteryManager::didChangeBatteryStatus):
(WebCore::BatteryManager::updateBatteryStatus):
(WebCore):
* Modules/battery/BatteryManager.h:
(BatteryManager):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149062 => 149063)


--- trunk/Source/WebCore/ChangeLog	2013-04-24 20:11:03 UTC (rev 149062)
+++ trunk/Source/WebCore/ChangeLog	2013-04-24 20:38:38 UTC (rev 149063)
@@ -1,3 +1,28 @@
+2013-04-24  Otto Derek Cheung  <otche...@rim.com>
+
+        Battery API won't return updated battery status until client calls didChangeBatteryStatus
+        https://bugs.webkit.org/show_bug.cgi?id=114891
+
+        Reviewed by Rob Buis.
+
+        The BatteryStatus object in BatteryManager won't get updated until BatteryClient calls
+        didChangeBatteryStatus in BatteryController. Any attempts to call webkitBattery.charged()
+        or other get functions will always return the default values until the next battery status
+        change object gets passed to the controller.
+
+        We need to update the manager when we attach it to the controller, and update all
+        existing managers when the controller receives it's first battery status object.
+
+        * Modules/battery/BatteryController.cpp:
+        (WebCore::BatteryController::addListener):
+        (WebCore::BatteryController::updateBatteryStatus):
+        * Modules/battery/BatteryManager.cpp:
+        (WebCore::BatteryManager::didChangeBatteryStatus):
+        (WebCore::BatteryManager::updateBatteryStatus):
+        (WebCore):
+        * Modules/battery/BatteryManager.h:
+        (BatteryManager):
+
 2013-04-24  Jacky Jiang  <zhaji...@blackberry.com>
 
         Clean up unused code in ViewportArguments.h

Modified: trunk/Source/WebCore/Modules/battery/BatteryController.cpp (149062 => 149063)


--- trunk/Source/WebCore/Modules/battery/BatteryController.cpp	2013-04-24 20:11:03 UTC (rev 149062)
+++ trunk/Source/WebCore/Modules/battery/BatteryController.cpp	2013-04-24 20:38:38 UTC (rev 149063)
@@ -51,6 +51,9 @@
 {
     m_listeners.append(batteryManager);
     m_client->startUpdating();
+
+    if (m_batteryStatus)
+        batteryManager->updateBatteryStatus(m_batteryStatus);
 }
 
 void BatteryController::removeListener(BatteryManager* batteryManager)
@@ -76,6 +79,9 @@
 
         if (m_batteryStatus->level() != status->level())
             didChangeBatteryStatus(WebCore::eventNames().levelchangeEvent, status);
+    } else {
+        for (ListenerVector::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
+            (*it)->updateBatteryStatus(status);
     }
 
     m_batteryStatus = status.release();

Modified: trunk/Source/WebCore/Modules/battery/BatteryManager.cpp (149062 => 149063)


--- trunk/Source/WebCore/Modules/battery/BatteryManager.cpp	2013-04-24 20:11:03 UTC (rev 149062)
+++ trunk/Source/WebCore/Modules/battery/BatteryManager.cpp	2013-04-24 20:38:38 UTC (rev 149063)
@@ -79,10 +79,15 @@
 
 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr<BatteryStatus> batteryStatus)
 {
-    m_batteryStatus = batteryStatus;
+    updateBatteryStatus(batteryStatus);
     dispatchEvent(event);
 }
 
+void BatteryManager::updateBatteryStatus(PassRefPtr<BatteryStatus> batteryStatus)
+{
+    m_batteryStatus = batteryStatus;
+}
+
 void BatteryManager::suspend(ReasonForSuspension)
 {
     if (m_batteryController)

Modified: trunk/Source/WebCore/Modules/battery/BatteryManager.h (149062 => 149063)


--- trunk/Source/WebCore/Modules/battery/BatteryManager.h	2013-04-24 20:11:03 UTC (rev 149062)
+++ trunk/Source/WebCore/Modules/battery/BatteryManager.h	2013-04-24 20:38:38 UTC (rev 149063)
@@ -52,6 +52,7 @@
     DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange);
 
     void didChangeBatteryStatus(PassRefPtr<Event>, PassRefPtr<BatteryStatus>);
+    void updateBatteryStatus(PassRefPtr<BatteryStatus>);
     void batteryControllerDestroyed() { m_batteryController = 0; }
 
     using RefCounted<BatteryManager>::ref;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to