- Revision
- 160445
- Author
- [email protected]
- Date
- 2013-12-11 10:23:02 -0800 (Wed, 11 Dec 2013)
Log Message
[GTK][WK2] Add the WebKitBatteryProvider class
https://bugs.webkit.org/show_bug.cgi?id=115720
Reviewed by Martin Robinson.
Source/WebKit2:
This patch adds the WebKitBatteryProvider class which sets up a BatteryProviderUPower instance,
controlling the provider's activity when instrumented to do so by the WebBatteryManagerProxy
and relaying the battery status updates from the battery provider to the battery manager.
* GNUmakefile.list.am: Add the build targets for the new source files.
* UIProcess/API/gtk/WebKitBatteryProvider.cpp: Added.
(toBatteryProvider): A helper inline method that casts the client info to the battery provider instance.
(startUpdatingCallback): Relays the instruction to the WebKitBattery instance.
(stopUpdatingCallback): Ditto.
(WebKitBatteryProvider::create):
(WebKitBatteryProvider::WebKitBatteryProvider): Set up a WKBatteryProvider and set it to the passed-in battery manager.
(WebKitBatteryProvider::~WebKitBatteryProvider): Force the BatteryProviderUPower to stop updating.
(WebKitBatteryProvider::startUpdating): Relays the instruction to the BatteryProviderUPower instance.
(WebKitBatteryProvider::stopUpdating): Ditto.
(WebKitBatteryProvider::notifyBatteryStatusUnavailable): Update the battery manager with the new status that
has the default values that are to be used when the implementation cannot determine the battery status (as per
the Battery Status API specification).
(WebKitBatteryProvider::notifyBatteryStatusUpdated): Update the battery status.
* UIProcess/API/gtk/WebKitBatteryProvider.h: Added.
(WebKitBatteryProvider): Define the WebKitBatteryProvider reference-counted interface that also inherits from the
BatteryProviderUPowerClient interface.
* UIProcess/API/gtk/WebKitWebContext.cpp:
(_WebKitWebContextPrivate): Add a WebKitBatteryProvider member variable to the struct.
(createDefaultWebContext): Create a new battery provider when initializing the default web context.
Tools:
* gtk/generate-gtkdoc:
(get_webkit2_options): Ignore the WebKitBatteryProvider source files when generating the documentation.
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (160444 => 160445)
--- trunk/Source/WebKit2/ChangeLog 2013-12-11 18:16:48 UTC (rev 160444)
+++ trunk/Source/WebKit2/ChangeLog 2013-12-11 18:23:02 UTC (rev 160445)
@@ -1,5 +1,37 @@
2013-12-11 José Dapena Paz <[email protected]> and Zan Dobersek <[email protected]>
+ [GTK][WK2] Add the WebKitBatteryProvider class
+ https://bugs.webkit.org/show_bug.cgi?id=115720
+
+ Reviewed by Martin Robinson.
+
+ This patch adds the WebKitBatteryProvider class which sets up a BatteryProviderUPower instance,
+ controlling the provider's activity when instrumented to do so by the WebBatteryManagerProxy
+ and relaying the battery status updates from the battery provider to the battery manager.
+
+ * GNUmakefile.list.am: Add the build targets for the new source files.
+ * UIProcess/API/gtk/WebKitBatteryProvider.cpp: Added.
+ (toBatteryProvider): A helper inline method that casts the client info to the battery provider instance.
+ (startUpdatingCallback): Relays the instruction to the WebKitBattery instance.
+ (stopUpdatingCallback): Ditto.
+ (WebKitBatteryProvider::create):
+ (WebKitBatteryProvider::WebKitBatteryProvider): Set up a WKBatteryProvider and set it to the passed-in battery manager.
+ (WebKitBatteryProvider::~WebKitBatteryProvider): Force the BatteryProviderUPower to stop updating.
+ (WebKitBatteryProvider::startUpdating): Relays the instruction to the BatteryProviderUPower instance.
+ (WebKitBatteryProvider::stopUpdating): Ditto.
+ (WebKitBatteryProvider::notifyBatteryStatusUnavailable): Update the battery manager with the new status that
+ has the default values that are to be used when the implementation cannot determine the battery status (as per
+ the Battery Status API specification).
+ (WebKitBatteryProvider::notifyBatteryStatusUpdated): Update the battery status.
+ * UIProcess/API/gtk/WebKitBatteryProvider.h: Added.
+ (WebKitBatteryProvider): Define the WebKitBatteryProvider reference-counted interface that also inherits from the
+ BatteryProviderUPowerClient interface.
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (_WebKitWebContextPrivate): Add a WebKitBatteryProvider member variable to the struct.
+ (createDefaultWebContext): Create a new battery provider when initializing the default web context.
+
+2013-12-11 José Dapena Paz <[email protected]> and Zan Dobersek <[email protected]>
+
[GTK] Add a UPower-based BatteryProvider
https://bugs.webkit.org/show_bug.cgi?id=115719
Modified: trunk/Source/WebKit2/GNUmakefile.list.am (160444 => 160445)
--- trunk/Source/WebKit2/GNUmakefile.list.am 2013-12-11 18:16:48 UTC (rev 160444)
+++ trunk/Source/WebKit2/GNUmakefile.list.am 2013-12-11 18:23:02 UTC (rev 160445)
@@ -724,6 +724,8 @@
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.h \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp \
+ Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h \
Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfo.h \
Source/WebKit2/UIProcess/API/gtk/WebKitCertificateInfoPrivate.h \
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp (0 => 160445)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.cpp 2013-12-11 18:23:02 UTC (rev 160445)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * 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 "WebKitBatteryProvider.h"
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "WebBatteryManagerProxy.h"
+#include "WebBatteryStatus.h"
+#include <limits>
+
+using namespace WebKit;
+
+static inline WebKitBatteryProvider* toBatteryProvider(const void* clientInfo)
+{
+ return static_cast<WebKitBatteryProvider*>(const_cast<void*>(clientInfo));
+}
+
+static void startUpdatingCallback(WKBatteryManagerRef batteryManager, const void* clientInfo)
+{
+ toBatteryProvider(clientInfo)->startUpdating();
+}
+
+static void stopUpdatingCallback(WKBatteryManagerRef batteryManager, const void* clientInfo)
+{
+ toBatteryProvider(clientInfo)->stopUpdating();
+}
+
+PassRefPtr<WebKitBatteryProvider> WebKitBatteryProvider::create(WebBatteryManagerProxy* batteryManager)
+{
+ return adoptRef(new WebKitBatteryProvider(batteryManager));
+}
+
+WebKitBatteryProvider::WebKitBatteryProvider(WebBatteryManagerProxy* batteryManager)
+ : m_batteryManager(batteryManager)
+ , m_provider(this)
+{
+ ASSERT(batteryManager);
+
+ WKBatteryProviderV0 wkBatteryProvider = {
+ {
+ 0, // version
+ this // clientInfo
+ },
+ startUpdatingCallback,
+ stopUpdatingCallback
+ };
+ WKBatteryManagerSetProvider(toAPI(batteryManager), &wkBatteryProvider.base);
+}
+
+WebKitBatteryProvider::~WebKitBatteryProvider()
+{
+ m_provider.stopUpdating();
+}
+
+void WebKitBatteryProvider::startUpdating()
+{
+ m_provider.startUpdating();
+}
+
+void WebKitBatteryProvider::stopUpdating()
+{
+ m_provider.stopUpdating();
+}
+
+void WebKitBatteryProvider::updateBatteryStatus(WebCore::BatteryProviderUPowerStatus status, double secondsRemaining, double batteryLevel)
+{
+ RefPtr<WebBatteryStatus> batteryStatus;
+
+ switch (status) {
+ case WebCore::NotAvailable:
+ // When an implementation cannot report battery status, the default values should be used.
+ batteryStatus = WebBatteryStatus::create(true, std::numeric_limits<double>::infinity(),
+ std::numeric_limits<double>::infinity(), 1.0);
+ break;
+ case WebCore::Charging:
+ batteryStatus = WebBatteryStatus::create(true, secondsRemaining, 0, batteryLevel);
+ break;
+ case WebCore::Discharging:
+ batteryStatus = WebBatteryStatus::create(false, 0, secondsRemaining, batteryLevel);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ m_batteryManager->providerUpdateBatteryStatus(batteryStatus.get());
+}
+
+#endif // ENABLE(BATTERY_STATUS)
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h (0 => 160445)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitBatteryProvider.h 2013-12-11 18:23:02 UTC (rev 160445)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * 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 WebKitBatteryProvider_h
+#define WebKitBatteryProvider_h
+
+#if ENABLE(BATTERY_STATUS)
+
+#include "WebKitPrivate.h"
+#include <WebCore/BatteryProviderUPowerClient.h>
+#include <WebCore/BatteryProviderUPower.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class WebKitBatteryProvider : public RefCounted<WebKitBatteryProvider>, public WebCore::BatteryProviderUPowerClient {
+public:
+ static PassRefPtr<WebKitBatteryProvider> create(WebBatteryManagerProxy*);
+ virtual ~WebKitBatteryProvider();
+
+ void startUpdating();
+ void stopUpdating();
+
+private:
+ WebKitBatteryProvider(WebBatteryManagerProxy*);
+
+ // WebCore::BatteryProviderUPowerClient
+ virtual void updateBatteryStatus(WebCore::BatteryProviderUPowerStatus, double secondsRemaining, double batteryLevel);
+
+ RefPtr<WebBatteryManagerProxy> m_batteryManager;
+ WebCore::BatteryProviderUPower m_provider;
+};
+
+}
+
+#endif // ENABLE(BATTERY_STATUS)
+
+#endif // WebKitBatteryProvider_h
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (160444 => 160445)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2013-12-11 18:16:48 UTC (rev 160444)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2013-12-11 18:23:02 UTC (rev 160445)
@@ -20,9 +20,11 @@
#include "config.h"
#include "WebKitWebContext.h"
+#include "WebBatteryManagerProxy.h"
#include "WebCertificateInfo.h"
#include "WebCookieManagerProxy.h"
#include "WebGeolocationManagerProxy.h"
+#include "WebKitBatteryProvider.h"
#include "WebKitCertificateInfoPrivate.h"
#include "WebKitCookieManagerPrivate.h"
#include "WebKitDownloadClient.h"
@@ -139,6 +141,9 @@
#if ENABLE(GEOLOCATION)
RefPtr<WebKitGeolocationProvider> geolocationProvider;
#endif
+#if ENABLE(BATTERY_STATUS)
+ RefPtr<WebKitBatteryProvider> batteryProvider;
+#endif
#if ENABLE(SPELLCHECK)
OwnPtr<WebKitTextChecker> textChecker;
#endif
@@ -211,6 +216,9 @@
#if ENABLE(GEOLOCATION)
priv->geolocationProvider = WebKitGeolocationProvider::create(priv->context->supplement<WebGeolocationManagerProxy>());
#endif
+#if ENABLE(BATTERY_STATUS)
+ priv->batteryProvider = WebKitBatteryProvider::create(priv->context->supplement<WebBatteryManagerProxy>());
+#endif
#if ENABLE(SPELLCHECK)
priv->textChecker = WebKitTextChecker::create();
#endif
Modified: trunk/Tools/ChangeLog (160444 => 160445)
--- trunk/Tools/ChangeLog 2013-12-11 18:16:48 UTC (rev 160444)
+++ trunk/Tools/ChangeLog 2013-12-11 18:23:02 UTC (rev 160445)
@@ -1,3 +1,13 @@
+2013-12-11 José Dapena Paz <[email protected]> and Zan Dobersek <[email protected]>
+
+ [GTK][WK2] Add the WebKitBatteryProvider class
+ https://bugs.webkit.org/show_bug.cgi?id=115720
+
+ Reviewed by Martin Robinson.
+
+ * gtk/generate-gtkdoc:
+ (get_webkit2_options): Ignore the WebKitBatteryProvider source files when generating the documentation.
+
2013-12-11 Mark Rowe <[email protected]>
<https://webkit.org/b/125563> Remove the DumpRenderTree Perl Support module
Modified: trunk/Tools/gtk/generate-gtkdoc (160444 => 160445)
--- trunk/Tools/gtk/generate-gtkdoc 2013-12-11 18:16:48 UTC (rev 160444)
+++ trunk/Tools/gtk/generate-gtkdoc 2013-12-11 18:23:02 UTC (rev 160445)
@@ -104,9 +104,10 @@
'ignored_files': glob.glob(src_path('*Private.h')) + \
glob.glob(injected_bundle_src_path('*Private.h')) + \
glob.glob(src_path('*Client*')) + \
+ glob.glob(src_path('WebKitAuthenticationDialog.*')) + \
+ glob.glob(src_path('WebKitBatteryProvider.*')) + \
glob.glob(src_path('WebKitGeolocationProvider.*')) + \
glob.glob(src_path('WebKitTextChecker.*')) + \
- glob.glob(src_path('WebKitAuthenticationDialog.*')) + \
glob.glob(src_path('WebKitWebViewBaseAccessible.*')) + \
glob.glob(src_path('WebViewBaseInputMethodFilter.*')) + \
glob.glob(derived_sources_path('webkit2gtk', 'webkit2', 'WebKitMarshal.*')) + \