From 453222dca764473dd29137ad8b06d7a57350b549 Mon Sep 17 00:00:00 2001 From: Jiyeon Kim Date: Thu, 16 Aug 2012 19:37:56 +0900 Subject: [PATCH] Enable Battery Status API [Title] Enable Battery status API [Issue #] N/A [Problem] Have to change uPower API to vconf API. [Cause] System team couldn't add uPower package. [Solution] Change API for tizen specific. [Team] HTML5 TG [Developer] jiyeon.kim [SCMRequest] N/A Change-Id: I0d34ca3592b791efa605c14ad7aedcf7ffbfe979 --- Source/WebCore/Modules/battery/BatteryClient.h | 2 - .../WebCore/Modules/battery/BatteryController.cpp | 1 - Source/WebCore/PlatformEfl.cmake | 1 + Source/WebCore/PlatformTizen.cmake | 9 + Source/WebCore/platform/efl/BatteryProviderEfl.cpp | 287 +++++++++++++++++++++ Source/WebCore/platform/efl/BatteryProviderEfl.h | 69 +++++ .../platform/efl/BatteryProviderEflClient.h | 40 +++ Source/WebKit/PlatformEfl.cmake | 1 + .../WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp | 143 +--------- .../WebKit/efl/WebCoreSupport/BatteryClientEfl.h | 37 ++- Source/WebKit/efl/ewk/ewk_view.cpp | 2 +- Source/WebKit2/CMakeLists.txt | 13 + Source/WebKit2/Platform/CoreIPC/MessageID.h | 2 + Source/WebKit2/PlatformEfl.cmake | 1 + Source/WebKit2/Shared/API/c/WKBase.h | 2 + Source/WebKit2/Shared/APIObject.h | 2 + Source/WebKit2/Shared/WebBatteryStatus.cpp | 60 +++++ Source/WebKit2/Shared/WebBatteryStatus.h | 77 ++++++ Source/WebKit2/UIProcess/API/C/WKAPICast.h | 4 + .../WebKit2/UIProcess/API/C/WKBatteryManager.cpp | 66 +++++ Source/WebKit2/UIProcess/API/C/WKBatteryManager.h | 60 +++++ Source/WebKit2/UIProcess/API/C/WKBatteryStatus.cpp | 55 ++++ Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h | 43 +++ Source/WebKit2/UIProcess/API/C/WKContext.cpp | 9 + Source/WebKit2/UIProcess/API/C/WKContext.h | 1 + .../WebKit2/UIProcess/API/efl/BatteryProvider.cpp | 94 +++++++ Source/WebKit2/UIProcess/API/efl/BatteryProvider.h | 58 +++++ Source/WebKit2/UIProcess/API/efl/ewk_context.cpp | 8 + .../WebKit2/UIProcess/WebBatteryManagerProxy.cpp | 102 ++++++++ Source/WebKit2/UIProcess/WebBatteryManagerProxy.h | 84 ++++++ .../UIProcess/WebBatteryManagerProxy.messages.in | 30 +++ Source/WebKit2/UIProcess/WebBatteryProvider.cpp | 54 ++++ Source/WebKit2/UIProcess/WebBatteryProvider.h | 49 ++++ Source/WebKit2/UIProcess/WebContext.cpp | 22 ++ Source/WebKit2/UIProcess/WebContext.h | 9 + Source/WebKit2/UIProcess/WebProcessProxy.cpp | 3 + .../WebProcess/Battery/WebBatteryManager.cpp | 103 ++++++++ .../WebKit2/WebProcess/Battery/WebBatteryManager.h | 75 ++++++ .../Battery/WebBatteryManager.messages.in | 30 +++ .../WebProcess/WebCoreSupport/WebBatteryClient.cpp | 57 ++++ .../WebProcess/WebCoreSupport/WebBatteryClient.h | 58 +++++ Source/WebKit2/WebProcess/WebPage/WebPage.cpp | 8 + Source/WebKit2/WebProcess/WebProcess.cpp | 10 + Source/WebKit2/WebProcess/WebProcess.h | 11 + Source/cmake/FindPmapi.cmake | 31 +++ Source/cmake/OptionsTizen.cmake | 8 +- packaging/webkit2-efl.spec | 1 + 47 files changed, 1732 insertions(+), 160 deletions(-) create mode 100644 Source/WebCore/platform/efl/BatteryProviderEfl.cpp create mode 100644 Source/WebCore/platform/efl/BatteryProviderEfl.h create mode 100644 Source/WebCore/platform/efl/BatteryProviderEflClient.h create mode 100644 Source/WebKit2/Shared/WebBatteryStatus.cpp create mode 100644 Source/WebKit2/Shared/WebBatteryStatus.h create mode 100644 Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp create mode 100644 Source/WebKit2/UIProcess/API/C/WKBatteryManager.h create mode 100644 Source/WebKit2/UIProcess/API/C/WKBatteryStatus.cpp create mode 100644 Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h create mode 100644 Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp create mode 100644 Source/WebKit2/UIProcess/API/efl/BatteryProvider.h create mode 100644 Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp create mode 100644 Source/WebKit2/UIProcess/WebBatteryManagerProxy.h create mode 100644 Source/WebKit2/UIProcess/WebBatteryManagerProxy.messages.in create mode 100644 Source/WebKit2/UIProcess/WebBatteryProvider.cpp create mode 100644 Source/WebKit2/UIProcess/WebBatteryProvider.h create mode 100644 Source/WebKit2/WebProcess/Battery/WebBatteryManager.cpp create mode 100644 Source/WebKit2/WebProcess/Battery/WebBatteryManager.h create mode 100644 Source/WebKit2/WebProcess/Battery/WebBatteryManager.messages.in create mode 100644 Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.cpp create mode 100644 Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.h create mode 100755 Source/cmake/FindPmapi.cmake diff --git a/Source/WebCore/Modules/battery/BatteryClient.h b/Source/WebCore/Modules/battery/BatteryClient.h index bf56336..2c87a44 100644 --- a/Source/WebCore/Modules/battery/BatteryClient.h +++ b/Source/WebCore/Modules/battery/BatteryClient.h @@ -24,14 +24,12 @@ 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; diff --git a/Source/WebCore/Modules/battery/BatteryController.cpp b/Source/WebCore/Modules/battery/BatteryController.cpp index 7a7688f..c342e5b 100644 --- a/Source/WebCore/Modules/battery/BatteryController.cpp +++ b/Source/WebCore/Modules/battery/BatteryController.cpp @@ -33,7 +33,6 @@ BatteryController::BatteryController(BatteryClient* client) : m_client(client) { ASSERT(m_client); - m_client->setController(this); } BatteryController::~BatteryController() diff --git a/Source/WebCore/PlatformEfl.cmake b/Source/WebCore/PlatformEfl.cmake index 714615c..8ada5e1 100644 --- a/Source/WebCore/PlatformEfl.cmake +++ b/Source/WebCore/PlatformEfl.cmake @@ -23,6 +23,7 @@ LIST(APPEND WebCore_SOURCES page/efl/EventHandlerEfl.cpp platform/Cursor.cpp platform/RunLoop.cpp + platform/efl/BatteryProviderEfl.cpp platform/efl/ClipboardEfl.cpp platform/efl/ColorChooserEfl.cpp platform/efl/ContextMenuEfl.cpp diff --git a/Source/WebCore/PlatformTizen.cmake b/Source/WebCore/PlatformTizen.cmake index 822f205..3a88cde 100644 --- a/Source/WebCore/PlatformTizen.cmake +++ b/Source/WebCore/PlatformTizen.cmake @@ -197,6 +197,15 @@ IF (WTF_USE_SKIA) LIST(REMOVE_ITEM WebCore_SOURCES platform/graphics/efl/FontEfl.cpp) ENDIF () +IF (ENABLE_TIZEN_BATTERY_STATUS) + LIST(APPEND WebCore_LIBRARIES + ${Pmapi_LIBRARIES} + ) + LIST(APPEND WebCore_INCLUDE_DIRECTORIES + ${Pmapi_INCLUDE_DIRS} + ) +ENDIF() + IF (ENABLE_TIZEN_MM_PLAYER) LIST(APPEND WebCore_INCLUDE_DIRECTORIES ${ELEMENTARY_INCLUDE_DIRS} diff --git a/Source/WebCore/platform/efl/BatteryProviderEfl.cpp b/Source/WebCore/platform/efl/BatteryProviderEfl.cpp new file mode 100644 index 0000000..2c9b208 --- /dev/null +++ b/Source/WebCore/platform/efl/BatteryProviderEfl.cpp @@ -0,0 +1,287 @@ +/* + * 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 "BatteryProviderEfl.h" + +#if ENABLE(BATTERY_STATUS) + +#include "BatteryProviderEflClient.h" +#include "EventNames.h" +#if ENABLE(TIZEN_BATTERY_STATUS) +#include +#include +#else +#include +#endif +#include + +namespace WebCore { + +BatteryProviderEfl::BatteryProviderEfl(BatteryProviderEflClient* client) + : m_client(client) +#if !ENABLE(TIZEN_BATTERY_STATUS) + , m_timer(this, &BatteryProviderEfl::timerFired) + , m_batteryStatusRefreshInterval(1.0) +#endif +{ +} + + +BatteryStatus* BatteryProviderEfl::batteryStatus() const +{ + return m_batteryStatus.get(); +} + +#if ENABLE(TIZEN_BATTERY_STATUS) +void batteryChangeCallback(keynode_t *keynode, void* data) +{ + char *key = vconf_keynode_get_name(keynode); + if (!key || strlen(key) == 0) { + LOG_ERROR("vconf_keynode_get_name failed"); + return; + } + BatteryProviderEfl* client = static_cast(data); + BatteryStatus* clientBatteryStatus = client->batteryStatus(); + + bool chargingBool = false; + int chargingInt = 0; + int chargingTime = std::numeric_limits::infinity(); + int dischargingTime = std::numeric_limits::infinity(); + int level = 1; + + bool chargingChanged = false; + bool chargingTimeChanged = false; + bool dischargingTimeChanged = false; + bool levelChanged = false; + + chargingBool = clientBatteryStatus->charging(); + chargingTime = clientBatteryStatus->chargingTime(); + dischargingTime = clientBatteryStatus->dischargingTime(); + level = clientBatteryStatus->level(); + + if (!strncmp(key, VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, strlen(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW))) { + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &chargingInt); + chargingInt ? chargingBool = true : chargingBool = false; + if (clientBatteryStatus->charging() != chargingBool) + chargingChanged = true; + } + else if (!strncmp(key, VCONFKEY_PM_BATTERY_TIMETOFULL, strlen(VCONFKEY_PM_BATTERY_TIMETOFULL))) { + vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, &chargingTime); + if (clientBatteryStatus->chargingTime() != chargingTime) + chargingTimeChanged = true; + } + else if (!strncmp(key, VCONFKEY_PM_BATTERY_TIMETOEMPTY, strlen(VCONFKEY_PM_BATTERY_TIMETOEMPTY))) { + vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, &dischargingTime); + if (clientBatteryStatus->dischargingTime() != dischargingTime) + dischargingTimeChanged = true; + } + else if (!strncmp(key, VCONFKEY_SYSMAN_BATTERY_CAPACITY, strlen(VCONFKEY_SYSMAN_BATTERY_CAPACITY))) { + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &level); + if (clientBatteryStatus->level() != level) + levelChanged = true; + } + + WTF::RefPtr batteryStatus = BatteryStatus::create(chargingBool, static_cast(chargingTime), static_cast(dischargingTime), static_cast(level)); + if (chargingChanged) + client->setBatteryStatus(eventNames().chargingchangeEvent, batteryStatus); + if (chargingTimeChanged) + client->setBatteryStatus(eventNames().chargingtimechangeEvent, batteryStatus); + if (dischargingTimeChanged) + client->setBatteryStatus(eventNames().dischargingtimechangeEvent, batteryStatus); + if (levelChanged) + client->setBatteryStatus(eventNames().levelchangeEvent, batteryStatus); +} +#endif + +void BatteryProviderEfl::startUpdating() +{ +#if ENABLE(TIZEN_BATTERY_STATUS) + bool chargingBool = false; + int chargingInt = 0; + int chargingTime = std::numeric_limits::infinity(); + int dischargingTime = std::numeric_limits::infinity(); + int level = 1; + + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &chargingInt); + chargingInt ? chargingBool = true : chargingBool = false; + vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, &chargingTime); + vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, &dischargingTime); + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &level); + + WTF::RefPtr batteryStatus = BatteryStatus::create(chargingBool, static_cast(chargingTime), static_cast(dischargingTime), static_cast(level)); + this->setBatteryStatus(eventNames().chargingchangeEvent, batteryStatus); + this->setBatteryStatus(eventNames().chargingtimechangeEvent, batteryStatus); + this->setBatteryStatus(eventNames().dischargingtimechangeEvent, batteryStatus); + this->setBatteryStatus(eventNames().levelchangeEvent, batteryStatus); + + pm_start_batteryinfo(0x1); + pm_start_batteryinfo(0x2); + vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, batteryChangeCallback, static_cast(this)); + vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, batteryChangeCallback, static_cast(this)); + vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, batteryChangeCallback, static_cast(this)); + vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, batteryChangeCallback, static_cast(this)); +#else + if (m_timer.isActive()) + return; + + if (!e_dbus_init()) + return; + + if (!e_ukit_init()) { + e_dbus_shutdown(); + return; + } + + m_timer.startRepeating(m_batteryStatusRefreshInterval); +#endif +} + +void BatteryProviderEfl::stopUpdating() +{ +#if ENABLE(TIZEN_BATTERY_STATUS) + pm_stop_batteryinfo(0x1); + pm_stop_batteryinfo(0x2); + vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, batteryChangeCallback); + vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, batteryChangeCallback); + vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, batteryChangeCallback); + vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, batteryChangeCallback); +#else + m_timer.stop(); + + e_ukit_shutdown(); + e_dbus_shutdown(); +#endif +} + +void BatteryProviderEfl::setBatteryStatus(const AtomicString& eventType, PassRefPtr batteryStatus) +{ + m_batteryStatus = batteryStatus; + m_client->didChangeBatteryStatus(eventType, m_batteryStatus); +} + +#if !ENABLE(TIZEN_BATTERY_STATUS) +void BatteryProviderEfl::timerFired(Timer* timer) +{ + ASSERT_UNUSED(timer, timer == &m_timer); + + E_DBus_Connection* edbusConnection = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (edbusConnection) + e_upower_get_all_devices(edbusConnection, getBatteryStatus, static_cast(this)); +} + +void BatteryProviderEfl::getBatteryStatus(void* data, void* replyData, DBusError* dBusError) +{ + E_Ukit_Get_All_Devices_Return* eukitDeviceNames = static_cast(replyData); + if (!eukitDeviceNames || !eukitDeviceNames->strings || dbus_error_is_set(dBusError)) { + dbus_error_free(dBusError); + return; + } + + E_DBus_Connection* edbusConnection = e_dbus_bus_get(DBUS_BUS_SYSTEM); + Eina_List* list; + void* deviceName; + EINA_LIST_FOREACH(eukitDeviceNames->strings, list, deviceName) + e_upower_get_all_properties(edbusConnection, static_cast(deviceName), setBatteryClient, data); +} + +void BatteryProviderEfl::setBatteryClient(void* data, void* replyData, DBusError* dBusError) +{ + E_Ukit_Get_All_Properties_Return* eukitPropertyNames = static_cast(replyData); + + if (!eukitPropertyNames || dbus_error_is_set(dBusError)) { + dbus_error_free(dBusError); + return; + } + + if (!eukitPropertyNames->properties) + return; + + E_Ukit_Property* property = static_cast(eina_hash_find(eukitPropertyNames->properties, "Type")); + if (!property || property->val.u != E_UPOWER_SOURCE_BATTERY) + return; + + BatteryProviderEfl* client = static_cast(data); + BatteryStatus* clientBatteryStatus = client->batteryStatus(); + bool charging = false; + bool chargingChanged = false; + static unsigned chargingState = 0; + + property = static_cast(eina_hash_find(eukitPropertyNames->properties, "State")); + if (!property) + return; + if (!clientBatteryStatus || chargingState != property->val.u) { + chargingChanged = true; + chargingState = property->val.u; + (chargingState == E_UPOWER_STATE_FULL || chargingState == E_UPOWER_STATE_CHARGING) ? charging = true : charging = false; + } else + charging = clientBatteryStatus->charging(); + + bool chargingTimeChanged = false; + bool dischargingTimeChanged = false; + double chargingTime = std::numeric_limits::infinity(); + double dischargingTime = std::numeric_limits::infinity(); + + if (charging) { + if (!clientBatteryStatus || clientBatteryStatus->dischargingTime() != std::numeric_limits::infinity()) + dischargingTimeChanged = true; + dischargingTime = std::numeric_limits::infinity(); + property = static_cast(eina_hash_find(eukitPropertyNames->properties, "TimeToFull")); + if (!property) + return; + if (!clientBatteryStatus || clientBatteryStatus->chargingTime() != property->val.x) + chargingTimeChanged = true; + chargingTime = property->val.x; + } else { + if (!clientBatteryStatus || clientBatteryStatus->chargingTime() != std::numeric_limits::infinity()) + chargingTimeChanged = true; + chargingTime = std::numeric_limits::infinity(); + property = static_cast(eina_hash_find(eukitPropertyNames->properties, "TimeToEmpty")); + if (!property) + return; + if (!clientBatteryStatus || clientBatteryStatus->dischargingTime() != property->val.x) + dischargingTimeChanged = true; + dischargingTime = property->val.x; + } + + double level = 0; + bool levelChanged = false; + + property = static_cast(eina_hash_find(eukitPropertyNames->properties, "Percentage")); + if (!property) + return; + if (!clientBatteryStatus || clientBatteryStatus->level() != property->val.d) + levelChanged = true; + level = property->val.d; + + WTF::RefPtr batteryStatus = BatteryStatus::create(charging, chargingTime, dischargingTime, level); + if (chargingChanged) + client->setBatteryStatus(eventNames().chargingchangeEvent, batteryStatus); + if (chargingTimeChanged) + client->setBatteryStatus(eventNames().chargingtimechangeEvent, batteryStatus); + if (dischargingTimeChanged) + client->setBatteryStatus(eventNames().dischargingtimechangeEvent, batteryStatus); + if (levelChanged) + client->setBatteryStatus(eventNames().levelchangeEvent, batteryStatus); +} +#endif +} + +#endif // BATTERY_STATUS + diff --git a/Source/WebCore/platform/efl/BatteryProviderEfl.h b/Source/WebCore/platform/efl/BatteryProviderEfl.h new file mode 100644 index 0000000..4422e51 --- /dev/null +++ b/Source/WebCore/platform/efl/BatteryProviderEfl.h @@ -0,0 +1,69 @@ +/* + * 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 BatteryProviderEfl_h +#define BatteryProviderEfl_h + +#if ENABLE(BATTERY_STATUS) + +#include "BatteryClient.h" +#include "BatteryStatus.h" +#include "Timer.h" +#include + +#if !ENABLE(TIZEN_BATTERY_STATUS) +typedef struct DBusError DBusError; +#endif + +namespace WebCore { + +class BatteryProviderEflClient; + +class BatteryProviderEfl { +public: + BatteryProviderEfl(BatteryProviderEflClient*); + ~BatteryProviderEfl() { } + + virtual void startUpdating(); + virtual void stopUpdating(); + + void setBatteryStatus(const AtomicString& eventType, PassRefPtr); + BatteryStatus* batteryStatus() const; + +private: +#if !ENABLE(TIZEN_BATTERY_STATUS) + void timerFired(Timer*); + static void getBatteryStatus(void* data, void* replyData, DBusError*); + static void setBatteryClient(void* data, void* replyData, DBusError*); +#endif + BatteryProviderEflClient* m_client; +#if !ENABLE(TIZEN_BATTERY_STATUS) + Timer m_timer; +#endif + RefPtr m_batteryStatus; +#if !ENABLE(TIZEN_BATTERY_STATUS) + const double m_batteryStatusRefreshInterval; +#endif +}; + +} + +#endif // ENABLE(BATTERY_STATUS) +#endif // BatteryProviderEfl_h + diff --git a/Source/WebCore/platform/efl/BatteryProviderEflClient.h b/Source/WebCore/platform/efl/BatteryProviderEflClient.h new file mode 100644 index 0000000..c3ed8d0 --- /dev/null +++ b/Source/WebCore/platform/efl/BatteryProviderEflClient.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * 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 BatteryProviderEflClient_h +#define BatteryProviderEflClient_h + +#if ENABLE(BATTERY_STATUS) + +#include "BatteryStatus.h" +#include + +namespace WebCore { + +class BatteryProviderEflClient { +public: + virtual void didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr) = 0; +}; + +} // namespace WebCore + +#endif // ENABLE(BATTERY_STATUS) + +#endif // BatteryProviderEflClient_h diff --git a/Source/WebKit/PlatformEfl.cmake b/Source/WebKit/PlatformEfl.cmake index ea95f19..cccd06a 100755 --- a/Source/WebKit/PlatformEfl.cmake +++ b/Source/WebKit/PlatformEfl.cmake @@ -85,6 +85,7 @@ ENDIF () LIST(APPEND WebKit_SOURCES efl/WebCoreSupport/AssertMatchingEnums.cpp + efl/WebCoreSupport/BatteryClientEfl.cpp efl/WebCoreSupport/ChromeClientEfl.cpp efl/WebCoreSupport/DeviceOrientationClientEfl.cpp efl/WebCoreSupport/DeviceMotionClientEfl.cpp diff --git a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp index 2e12c14..e61da11 100644 --- a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp +++ b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2012 Samsung Electronics + * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2012 Intel Corporation. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,44 +24,26 @@ #if ENABLE(BATTERY_STATUS) #include "BatteryController.h" -#include "EventNames.h" -#include - -namespace WebCore { BatteryClientEfl::BatteryClientEfl() : m_controller(0) - , m_timer(this, &BatteryClientEfl::timerFired) - , m_batteryStatusRefreshInterval(1.0) + , m_provider(this) { } -void BatteryClientEfl::setController(BatteryController* controller) +void BatteryClientEfl::setController(WebCore::BatteryController* controller) { m_controller = controller; } void BatteryClientEfl::startUpdating() { - if (m_timer.isActive()) - return; - - if (!e_dbus_init()) - return; - - if (!e_ukit_init()) { - e_dbus_shutdown(); - return; - } - - m_timer.startRepeating(m_batteryStatusRefreshInterval); + m_provider.startUpdating(); } void BatteryClientEfl::stopUpdating() { - m_timer.stop(); - e_ukit_shutdown(); - e_dbus_shutdown(); + m_provider.stopUpdating(); } void BatteryClientEfl::batteryControllerDestroyed() @@ -68,116 +51,10 @@ void BatteryClientEfl::batteryControllerDestroyed() delete this; } -void BatteryClientEfl::setBatteryStatus(const AtomicString& eventType, PassRefPtr batteryStatus) -{ - m_batteryStatus = batteryStatus; - m_controller->didChangeBatteryStatus(eventType, m_batteryStatus); -} - -void BatteryClientEfl::timerFired(Timer* timer) +void BatteryClientEfl::didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr status) { - ASSERT_UNUSED(timer, timer == &m_timer); - E_DBus_Connection* edbusConnection = e_dbus_bus_get(DBUS_BUS_SYSTEM); - if (edbusConnection) - e_upower_get_all_devices(edbusConnection, getBatteryStatus, static_cast(this)); + ASSERT(m_controller); + m_controller->didChangeBatteryStatus(eventType, status); } -void BatteryClientEfl::getBatteryStatus(void* data, void* replyData, DBusError* dBusError) -{ - E_Ukit_Get_All_Devices_Return* eukitDeviceNames = static_cast(replyData); - if (!eukitDeviceNames || !eukitDeviceNames->strings || dbus_error_is_set(dBusError)) { - dbus_error_free(dBusError); - return; - } - - E_DBus_Connection* edbusConnection = e_dbus_bus_get(DBUS_BUS_SYSTEM); - Eina_List* list; - void* deviceName; - EINA_LIST_FOREACH(eukitDeviceNames->strings, list, deviceName) - e_upower_get_all_properties(edbusConnection, static_cast(deviceName), setBatteryClient, data); -} - -void BatteryClientEfl::setBatteryClient(void* data, void* replyData, DBusError* dBusError) -{ - E_Ukit_Get_All_Properties_Return* eukitPropertyNames = static_cast(replyData); - - if (!eukitPropertyNames || dbus_error_is_set(dBusError)) { - dbus_error_free(dBusError); - return; - } - - if (!eukitPropertyNames->properties) - return; - - E_Ukit_Property* property = static_cast(eina_hash_find(eukitPropertyNames->properties, "Type")); - if (!property || property->val.u != E_UPOWER_SOURCE_BATTERY) - return; - - BatteryClientEfl* client = static_cast(data); - BatteryStatus* clientBatteryStatus = client->batteryStatus(); - bool charging = false; - bool chargingChanged = false; - static unsigned chargingState = 0; - - property = static_cast(eina_hash_find(eukitPropertyNames->properties, "State")); - if (!property) - return; - if (!clientBatteryStatus || chargingState != property->val.u) { - chargingChanged = true; - chargingState = property->val.u; - (chargingState == E_UPOWER_STATE_FULL || chargingState == E_UPOWER_STATE_CHARGING) ? charging = true : charging = false; - } else - charging = clientBatteryStatus->charging(); - - bool chargingTimeChanged = false; - bool dischargingTimeChanged = false; - double chargingTime = std::numeric_limits::infinity(); - double dischargingTime = std::numeric_limits::infinity(); - - if (charging) { - if (!clientBatteryStatus || clientBatteryStatus->dischargingTime() != std::numeric_limits::infinity()) - dischargingTimeChanged = true; - dischargingTime = std::numeric_limits::infinity(); - property = static_cast(eina_hash_find(eukitPropertyNames->properties, "TimeToFull")); - if (!property) - return; - if (!clientBatteryStatus || clientBatteryStatus->chargingTime() != property->val.x) - chargingTimeChanged = true; - chargingTime = property->val.x; - } else { - if (!clientBatteryStatus || clientBatteryStatus->chargingTime() != std::numeric_limits::infinity()) - chargingTimeChanged = true; - chargingTime = std::numeric_limits::infinity(); - property = static_cast(eina_hash_find(eukitPropertyNames->properties, "TimeToEmpty")); - if (!property) - return; - if (!clientBatteryStatus || clientBatteryStatus->dischargingTime() != property->val.x) - dischargingTimeChanged = true; - dischargingTime = property->val.x; - } - - double level = 0; - bool levelChanged = false; - - property = static_cast(eina_hash_find(eukitPropertyNames->properties, "Percentage")); - if (!property) - return; - if (!clientBatteryStatus || clientBatteryStatus->level() != property->val.d) - levelChanged = true; - level = property->val.d; - - WTF::RefPtr batteryStatus = BatteryStatus::create(charging, chargingTime, dischargingTime, level); - if (chargingChanged) - client->setBatteryStatus(eventNames().chargingchangeEvent, batteryStatus); - if (chargingTimeChanged) - client->setBatteryStatus(eventNames().chargingtimechangeEvent, batteryStatus); - if (dischargingTimeChanged) - client->setBatteryStatus(eventNames().dischargingtimechangeEvent, batteryStatus); - if (levelChanged) - client->setBatteryStatus(eventNames().levelchangeEvent, batteryStatus); -} - -} - -#endif // BATTERY_STATUS - +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h index df47d70..4ba11e8 100644 --- a/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h +++ b/Source/WebKit/efl/WebCoreSupport/BatteryClientEfl.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2012 Samsung Electronics + * Copyright (C) 2012 Samsung Electronics. All rights reserved. + * Copyright (C) 2012 Intel Corporation. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,42 +24,34 @@ #if ENABLE(BATTERY_STATUS) #include "BatteryClient.h" +#include "BatteryProviderEfl.h" +#include "BatteryProviderEflClient.h" #include "BatteryStatus.h" -#include "Timer.h" -#include -#include +#include namespace WebCore { - class BatteryController; -class BatteryStatus; +} -class BatteryClientEfl : public BatteryClient { +class BatteryClientEfl : public WebCore::BatteryClient, public WebCore::BatteryProviderEflClient { public: BatteryClientEfl(); - ~BatteryClientEfl() { }; + virtual ~BatteryClientEfl() { } - virtual void setController(BatteryController*); + // BatteryClient interface. + virtual void setController(WebCore::BatteryController*); virtual void startUpdating(); virtual void stopUpdating(); virtual void batteryControllerDestroyed(); - void setBatteryStatus(const AtomicString& eventType, PassRefPtr); - BatteryStatus* batteryStatus() { return m_batteryStatus.get(); } - private: - void timerFired(Timer*); - static void getBatteryStatus(void* data, void* replyData, DBusError*); - static void setBatteryClient(void* data, void* replyData, DBusError*); + // BatteryProviderEflClient interface. + virtual void didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr); - BatteryController* m_controller; - Timer m_timer; - RefPtr m_batteryStatus; - const double m_batteryStatusRefreshInterval; + WebCore::BatteryController* m_controller; + WebCore::BatteryProviderEfl m_provider; }; -} +#endif // ENABLE(BATTERY_STATUS) -#endif // BATTERY_STATUS #endif // BatteryClientEfl_h - diff --git a/Source/WebKit/efl/ewk/ewk_view.cpp b/Source/WebKit/efl/ewk/ewk_view.cpp index 0b65336..e672505 100755 --- a/Source/WebKit/efl/ewk/ewk_view.cpp +++ b/Source/WebKit/efl/ewk/ewk_view.cpp @@ -1127,7 +1127,7 @@ static Ewk_View_Private_Data* _ewk_view_priv_new(Ewk_View_Smart_Data* smartData) #endif #if ENABLE(BATTERY_STATUS) - WebCore::provideBatteryTo(priv->page.get(), new WebCore::BatteryClientEfl); + WebCore::provideBatteryTo(priv->page.get(), new BatteryClientEfl); #endif priv->pageSettings = priv->page->settings(); diff --git a/Source/WebKit2/CMakeLists.txt b/Source/WebKit2/CMakeLists.txt index e63dbcb..055f777 100644 --- a/Source/WebKit2/CMakeLists.txt +++ b/Source/WebKit2/CMakeLists.txt @@ -25,6 +25,7 @@ SET(WebKit2_INCLUDE_DIRECTORIES "${WEBKIT2_DIR}/WebProcess" "${WEBKIT2_DIR}/WebProcess/ApplicationCache" "${WEBKIT2_DIR}/WebProcess/Authentication" + "${WEBKIT2_DIR}/WebProcess/Battery" "${WEBKIT2_DIR}/WebProcess/Cookies" "${WEBKIT2_DIR}/WebProcess/Cookies/soup" "${WEBKIT2_DIR}/WebProcess/Downloads" @@ -48,6 +49,7 @@ SET(WebKit2_INCLUDE_DIRECTORIES "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/soup" "${WEBKIT2_DIR}/WebProcess/WebPage" "${WEBCORE_DIR}" + "${WEBCORE_DIR}/Modules/battery" "${WEBCORE_DIR}/Modules/intents" "${WEBCORE_DIR}/accessibility" "${WEBCORE_DIR}/bindings/js" @@ -151,6 +153,7 @@ SET(WebKit2_SOURCES Shared/UpdateInfo.cpp Shared/VisitedLinkTable.cpp Shared/WebBackForwardListItem.cpp + Shared/WebBatteryStatus.cpp Shared/WebConnection.cpp Shared/WebConnectionClient.cpp Shared/WebContextMenuItem.cpp @@ -264,6 +267,8 @@ SET(WebKit2_SOURCES UIProcess/VisitedLinkProvider.cpp UIProcess/WebApplicationCacheManagerProxy.cpp UIProcess/WebBackForwardList.cpp + UIProcess/WebBatteryManagerProxy.cpp + UIProcess/WebBatteryProvider.cpp UIProcess/WebConnectionToWebProcess.cpp UIProcess/WebContext.cpp UIProcess/WebContextConnectionClient.cpp @@ -312,6 +317,8 @@ SET(WebKit2_SOURCES UIProcess/API/C/WKAuthenticationDecisionListener.cpp UIProcess/API/C/WKBackForwardList.cpp UIProcess/API/C/WKBackForwardListItem.cpp + UIProcess/API/C/WKBatteryManager.cpp + UIProcess/API/C/WKBatteryStatus.cpp UIProcess/API/C/WKContext.cpp UIProcess/API/C/WKCookieManager.cpp UIProcess/API/C/WKCredential.cpp @@ -379,6 +386,8 @@ SET(WebKit2_SOURCES WebProcess/Authentication/AuthenticationManager.cpp + WebProcess/Battery/WebBatteryManager.cpp + WebProcess/Cookies/WebCookieManager.cpp WebProcess/Cookies/soup/WebCookieManagerSoup.cpp @@ -460,6 +469,7 @@ SET(WebKit2_SOURCES WebProcess/soup/WebKitSoupRequestInputStream.cpp WebProcess/soup/WebSoupRequestManager.cpp + WebProcess/WebCoreSupport/WebBatteryClient.cpp WebProcess/WebCoreSupport/WebChromeClient.cpp WebProcess/WebCoreSupport/WebColorChooser.cpp WebProcess/WebCoreSupport/WebContextMenuClient.cpp @@ -511,6 +521,7 @@ SET(WebKit2_MESSAGES_IN_FILES UIProcess/DrawingAreaProxy.messages.in UIProcess/LayerTreeHostProxy.messages.in UIProcess/WebApplicationCacheManagerProxy.messages.in + UIProcess/WebBatteryManagerProxy.messages.in UIProcess/WebContext.messages.in UIProcess/WebCookieManagerProxy.messages.in UIProcess/WebDatabaseManagerProxy.messages.in @@ -551,6 +562,8 @@ SET(WebKit2_MESSAGES_IN_FILES WebProcess/Authentication/AuthenticationManager.messages.in + WebProcess/Battery/WebBatteryManager.messages.in + WebProcess/Cookies/WebCookieManager.messages.in WebProcess/FullScreen/WebFullScreenManager.messages.in diff --git a/Source/WebKit2/Platform/CoreIPC/MessageID.h b/Source/WebKit2/Platform/CoreIPC/MessageID.h index 5f398aa..d54176e 100644 --- a/Source/WebKit2/Platform/CoreIPC/MessageID.h +++ b/Source/WebKit2/Platform/CoreIPC/MessageID.h @@ -40,6 +40,7 @@ enum MessageClass { MessageClassInjectedBundle, MessageClassLayerTreeHost, MessageClassWebApplicationCacheManager, + MessageClassWebBatteryManagerProxy, MessageClassWebCookieManager, MessageClassWebDatabaseManager, MessageClassWebFullScreenManager, @@ -62,6 +63,7 @@ enum MessageClass { MessageClassDrawingAreaProxy, MessageClassLayerTreeHostProxy, MessageClassWebApplicationCacheManagerProxy, + MessageClassWebBatteryManager, MessageClassWebContext, MessageClassWebContextLegacy, MessageClassWebCookieManagerProxy, diff --git a/Source/WebKit2/PlatformEfl.cmake b/Source/WebKit2/PlatformEfl.cmake index e2a3f69..16e1cb5 100755 --- a/Source/WebKit2/PlatformEfl.cmake +++ b/Source/WebKit2/PlatformEfl.cmake @@ -29,6 +29,7 @@ LIST(APPEND WebKit2_SOURCES UIProcess/API/C/soup/WKContextSoup.cpp UIProcess/API/C/soup/WKSoupRequestManager.cpp + UIProcess/API/efl/BatteryProvider.cpp UIProcess/API/efl/PageClientImpl.cpp UIProcess/API/efl/ewk_context.cpp UIProcess/API/efl/ewk_view.cpp diff --git a/Source/WebKit2/Shared/API/c/WKBase.h b/Source/WebKit2/Shared/API/c/WKBase.h index c527da3..d5cfd6b 100644 --- a/Source/WebKit2/Shared/API/c/WKBase.h +++ b/Source/WebKit2/Shared/API/c/WKBase.h @@ -90,6 +90,8 @@ typedef const struct OpaqueWKAuthenticationChallenge* WKAuthenticationChallengeR typedef const struct OpaqueWKAuthenticationDecisionListener* WKAuthenticationDecisionListenerRef; typedef const struct OpaqueWKBackForwardList* WKBackForwardListRef; typedef const struct OpaqueWKBackForwardListItem* WKBackForwardListItemRef; +typedef const struct OpaqueWKBatteryManager* WKBatteryManagerRef; +typedef const struct OpaqueWKBatteryStatus* WKBatteryStatusRef; typedef const struct OpaqueWKResourceCacheManager* WKResourceCacheManagerRef; typedef const struct OpaqueWKContext* WKContextRef; typedef const struct OpaqueWKCookieManager* WKCookieManagerRef; diff --git a/Source/WebKit2/Shared/APIObject.h b/Source/WebKit2/Shared/APIObject.h index 264cffa..6c7641c 100644 --- a/Source/WebKit2/Shared/APIObject.h +++ b/Source/WebKit2/Shared/APIObject.h @@ -76,6 +76,8 @@ public: TypeApplicationCacheManager, TypeBackForwardList, TypeBackForwardListItem, + TypeBatteryManager, + TypeBatteryStatus, TypeCacheManager, TypeContext, TypeCookieManager, diff --git a/Source/WebKit2/Shared/WebBatteryStatus.cpp b/Source/WebKit2/Shared/WebBatteryStatus.cpp new file mode 100644 index 0000000..c8d806d --- /dev/null +++ b/Source/WebKit2/Shared/WebBatteryStatus.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebBatteryStatus.h" + +#if ENABLE(BATTERY_STATUS) + +#include "ArgumentCoders.h" +#include "Arguments.h" + +namespace WebKit { + +WebBatteryStatus::WebBatteryStatus(bool isCharging, double chargingTime, double dischargingTime, double level) +{ + m_data.isCharging = isCharging; + m_data.chargingTime = chargingTime; + m_data.dischargingTime = dischargingTime; + m_data.level = level; +} + +WebBatteryStatus::~WebBatteryStatus() +{ +} + +void WebBatteryStatus::Data::encode(CoreIPC::ArgumentEncoder* encoder) const +{ + encoder->encode(CoreIPC::In(isCharging, chargingTime, dischargingTime, level)); +} + +bool WebBatteryStatus::Data::decode(CoreIPC::ArgumentDecoder* decoder, Data& data) +{ + return decoder->decode(CoreIPC::Out(data.isCharging, data.chargingTime, data.dischargingTime, data.level)); +} + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/Shared/WebBatteryStatus.h b/Source/WebKit2/Shared/WebBatteryStatus.h new file mode 100644 index 0000000..fd1d793 --- /dev/null +++ b/Source/WebKit2/Shared/WebBatteryStatus.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebBatteryStatus_h +#define WebBatteryStatus_h + +#if ENABLE(BATTERY_STATUS) + +#include "APIObject.h" +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" +#include + +namespace WebKit { + +class WebBatteryStatus : public APIObject { +public: + static const Type APIType = TypeBatteryStatus; + + struct Data { + void encode(CoreIPC::ArgumentEncoder*) const; + static bool decode(CoreIPC::ArgumentDecoder*, Data&); + + bool isCharging; + double chargingTime; + double dischargingTime; + double level; + }; + + static PassRefPtr create(bool isCharging, double chargingTime, double dischargingTime, double level) + { + return adoptRef(new WebBatteryStatus(isCharging, chargingTime, dischargingTime, level)); + } + + virtual ~WebBatteryStatus(); + double isCharging() const { return m_data.isCharging; } + double chargingTime() const { return m_data.chargingTime; } + double dischargingTime() const { return m_data.dischargingTime; } + double level() const { return m_data.level; } + + const Data& data() const { return m_data; } + +private: + WebBatteryStatus(bool isCharging, double chargingTime, double dischargingTime, double level); + + virtual Type type() const { return APIType; } + + Data m_data; +}; + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) + +#endif // WebBatteryStatus_h diff --git a/Source/WebKit2/UIProcess/API/C/WKAPICast.h b/Source/WebKit2/UIProcess/API/C/WKAPICast.h index 5f3f064..5f9733c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKAPICast.h +++ b/Source/WebKit2/UIProcess/API/C/WKAPICast.h @@ -56,6 +56,8 @@ class NotificationPermissionRequest; class WebApplicationCacheManagerProxy; class WebBackForwardList; class WebBackForwardListItem; +class WebBatteryManagerProxy; +class WebBatteryStatus; class WebResourceCacheManagerProxy; class WebContext; class WebCookieManagerProxy; @@ -95,6 +97,8 @@ WK_ADD_API_MAPPING(WKAuthenticationChallengeRef, AuthenticationChallengeProxy) WK_ADD_API_MAPPING(WKAuthenticationDecisionListenerRef, AuthenticationDecisionListener) WK_ADD_API_MAPPING(WKBackForwardListItemRef, WebBackForwardListItem) WK_ADD_API_MAPPING(WKBackForwardListRef, WebBackForwardList) +WK_ADD_API_MAPPING(WKBatteryManagerRef, WebBatteryManagerProxy) +WK_ADD_API_MAPPING(WKBatteryStatusRef, WebBatteryStatus) WK_ADD_API_MAPPING(WKResourceCacheManagerRef, WebResourceCacheManagerProxy) WK_ADD_API_MAPPING(WKContextRef, WebContext) WK_ADD_API_MAPPING(WKCookieManagerRef, WebCookieManagerProxy) diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp new file mode 100644 index 0000000..950336d --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBatteryManager.h" + +#include "WKAPICast.h" +#include + +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryManagerProxy.h" +#endif + +using namespace WebKit; + +WKTypeID WKBatteryManagerGetTypeID() +{ +#if ENABLE(BATTERY_STATUS) + return toAPI(WebBatteryManagerProxy::APIType); +#else + return 0; +#endif +} + +void WKBatteryManagerSetProvider(WKBatteryManagerRef batteryManager, const WKBatteryProvider* provider) +{ +#if ENABLE(BATTERY_STATUS) + toImpl(batteryManager)->initializeProvider(provider); +#endif +} + +void WKBatteryManagerProviderDidChangeBatteryStatus(WKBatteryManagerRef batteryManager, WKStringRef eventType, WKBatteryStatusRef status) +{ +#if ENABLE(BATTERY_STATUS) + toImpl(batteryManager)->providerDidChangeBatteryStatus(AtomicString(toImpl(eventType)->string()), toImpl(status)); +#endif +} + +void WKBatteryManagerProviderUpdateBatteryStatus(WKBatteryManagerRef batteryManager, WKBatteryStatusRef status) +{ +#if ENABLE(BATTERY_STATUS) + toImpl(batteryManager)->providerUpdateBatteryStatus(toImpl(status)); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h new file mode 100644 index 0000000..712cbfb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryManager.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBatteryManager_h +#define WKBatteryManager_h + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Provider. +typedef void (*WKBatteryProviderStartUpdatingCallback)(WKBatteryManagerRef batteryManager, const void* clientInfo); +typedef void (*WKBatteryProviderStopUpdatingCallback)(WKBatteryManagerRef batteryManager, const void* clientInfo); + +struct WKBatteryProvider { + int version; + const void * clientInfo; + WKBatteryProviderStartUpdatingCallback startUpdating; + WKBatteryProviderStopUpdatingCallback stopUpdating; +}; +typedef struct WKBatteryProvider WKBatteryProvider; + +enum { kWKBatteryProviderCurrentVersion = 0 }; + +WK_EXPORT WKTypeID WKBatteryManagerGetTypeID(); + +WK_EXPORT void WKBatteryManagerSetProvider(WKBatteryManagerRef batteryManager, const WKBatteryProvider* provider); + +WK_EXPORT void WKBatteryManagerProviderDidChangeBatteryStatus(WKBatteryManagerRef batteryManager, WKStringRef eventType, WKBatteryStatusRef status); +WK_EXPORT void WKBatteryManagerProviderUpdateBatteryStatus(WKBatteryManagerRef batteryManager, WKBatteryStatusRef status); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBatteryManager_h */ diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.cpp b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.cpp new file mode 100644 index 0000000..0069a6f --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBatteryStatus.h" + +#include "WKAPICast.h" + +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryStatus.h" +#endif + +using namespace WebKit; + +WKTypeID WKBatteryStatusGetTypeID() +{ +#if ENABLE(BATTERY_STATUS) + return toAPI(WebBatteryStatus::APIType); +#else + return 0; +#endif +} + +WKBatteryStatusRef WKBatteryStatusCreate(bool isCharging, double chargingTime, double dischargingTime, double level) +{ +#if ENABLE(BATTERY_STATUS) + RefPtr status = WebBatteryStatus::create(isCharging, chargingTime, dischargingTime, level); + return toAPI(status.release().leakRef()); +#else + return 0; +#endif +} + diff --git a/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h new file mode 100644 index 0000000..afa1dd9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/C/WKBatteryStatus.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBatteryStatus_h +#define WKBatteryStatus_h + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBatteryStatusGetTypeID(); + +WK_EXPORT WKBatteryStatusRef WKBatteryStatusCreate(bool isCharging, double chargingTime, double dischargingTime, double level); + +#ifdef __cplusplus +} +#endif + +#endif // WKBatteryStatus_h diff --git a/Source/WebKit2/UIProcess/API/C/WKContext.cpp b/Source/WebKit2/UIProcess/API/C/WKContext.cpp index 7e1a176..9ce1045 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContext.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKContext.cpp @@ -193,6 +193,15 @@ WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef co return toAPI(toImpl(contextRef)->applicationCacheManagerProxy()); } +WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef) +{ +#if ENABLE(BATTERY_STATUS) + return toAPI(toImpl(contextRef)->batteryManagerProxy()); +#else + return 0; +#endif +} + WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef contextRef) { return toAPI(toImpl(contextRef)->databaseManagerProxy()); diff --git a/Source/WebKit2/UIProcess/API/C/WKContext.h b/Source/WebKit2/UIProcess/API/C/WKContext.h index 493d3ed..28c645f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContext.h +++ b/Source/WebKit2/UIProcess/API/C/WKContext.h @@ -148,6 +148,7 @@ WK_EXPORT void WKContextStopMemorySampler(WKContextRef context); WK_EXPORT void WKContextSetIndexedDatabaseDirectory(WKContextRef contextRef, WKStringRef indexedDatabaseDirectory); WK_EXPORT WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef context); +WK_EXPORT WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef context); WK_EXPORT WKCookieManagerRef WKContextGetCookieManager(WKContextRef context); WK_EXPORT WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef context); WK_EXPORT WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef context); diff --git a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp new file mode 100644 index 0000000..18c9e14 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "BatteryProvider.h" + +#if ENABLE(BATTERY_STATUS) + +#include "WKAPICast.h" +#include "WKBatteryManager.h" +#include "WKBatteryStatus.h" + +using namespace WebCore; +using namespace WebKit; + +static inline BatteryProvider* toBatteryProvider(const void* clientInfo) +{ + return static_cast(const_cast(clientInfo)); +} + +static void startUpdatingCallback(WKBatteryManagerRef batteryManager, const void* clientInfo) +{ + toBatteryProvider(clientInfo)->startUpdating(); +} + +static void stopUpdatingCallback(WKBatteryManagerRef batteryManager, const void* clientInfo) +{ + toBatteryProvider(clientInfo)->stopUpdating(); +} + +BatteryProvider::~BatteryProvider() +{ + m_provider.stopUpdating(); +} + +PassRefPtr BatteryProvider::create(WKBatteryManagerRef wkBatteryManager) +{ + return adoptRef(new BatteryProvider(wkBatteryManager)); +} + +BatteryProvider::BatteryProvider(WKBatteryManagerRef wkBatteryManager) + : m_wkBatteryManager(wkBatteryManager) + , m_provider(this) +{ + ASSERT(wkBatteryManager); + + WKBatteryProvider wkBatteryProvider = { + kWKBatteryProviderCurrentVersion, + this, // clientInfo + startUpdatingCallback, + stopUpdatingCallback + }; + WKBatteryManagerSetProvider(m_wkBatteryManager.get(), &wkBatteryProvider); +} + +void BatteryProvider::startUpdating() +{ + m_provider.startUpdating(); +} + +void BatteryProvider::stopUpdating() +{ + m_provider.stopUpdating(); +} + +void BatteryProvider::didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr status) +{ + WKRetainPtr wkBatteryStatus(AdoptWK, WKBatteryStatusCreate(status->charging(), status->chargingTime(), status->dischargingTime(), status->level())); + WKBatteryManagerProviderDidChangeBatteryStatus(m_wkBatteryManager.get(), toAPI(eventType.impl()), wkBatteryStatus.get()); +} + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h new file mode 100644 index 0000000..e9e4cf5 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BatteryProvider_h +#define BatteryProvider_h + +#if ENABLE(BATTERY_STATUS) + +#include "BatteryProviderEfl.h" +#include "BatteryProviderEflClient.h" +#include "BatteryStatus.h" +#include "WKRetainPtr.h" +#include +#include + +class BatteryProvider : public RefCounted, public WebCore::BatteryProviderEflClient { +public: + virtual ~BatteryProvider(); + static PassRefPtr create(WKBatteryManagerRef); + + void startUpdating(); + void stopUpdating(); + +private: + BatteryProvider(WKBatteryManagerRef); + + // BatteryProviderEflClient interface. + virtual void didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr); + + WKRetainPtr m_wkBatteryManager; + WebCore::BatteryProviderEfl m_provider; +}; + +#endif // ENABLE(BATTERY_STATUS) + +#endif // BatteryProvider_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp index 2b8eb56..1b286b5 100755 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp @@ -21,6 +21,7 @@ #include "config.h" #include "ewk_context.h" +#include "BatteryProvider.h" #include "WKAPICast.h" #include "WKApplicationCacheManager.h" #include "WKArray.h" @@ -49,6 +50,9 @@ using namespace WebKit; struct _Ewk_Context { WKRetainPtr context; +#if ENABLE(BATTERY_STATUS) + RefPtr batteryProvider; +#endif const char* proxyAddress; #if ENABLE(TIZEN_SQL_DATABASE) uint64_t defaultDatabaseQuota; @@ -65,6 +69,10 @@ struct _Ewk_Context { _Ewk_Context(WKRetainPtr contextRef) : context(contextRef) { +#if ENABLE(BATTERY_STATUS) + WKBatteryManagerRef wkBatteryManager = WKContextGetBatteryManager(contextRef.get()); + batteryProvider = BatteryProvider::create(wkBatteryManager); +#endif this->proxyAddress = 0; #if ENABLE(TIZEN_SQL_DATABASE) this->defaultDatabaseQuota = 5 * 1024 * 1024; diff --git a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp new file mode 100644 index 0000000..c3897e8 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebBatteryManagerProxy.h" + +#if ENABLE(BATTERY_STATUS) + +#include "WebBatteryManagerMessages.h" +#include "WebContext.h" + +namespace WebKit { + +PassRefPtr WebBatteryManagerProxy::create(WebContext* context) +{ + return adoptRef(new WebBatteryManagerProxy(context)); +} + +WebBatteryManagerProxy::WebBatteryManagerProxy(WebContext* context) + : m_isUpdating(false) + , m_context(context) +{ +} + +WebBatteryManagerProxy::~WebBatteryManagerProxy() +{ +} + +void WebBatteryManagerProxy::invalidate() +{ + stopUpdating(); +} + +void WebBatteryManagerProxy::initializeProvider(const WKBatteryProvider* provider) +{ + m_provider.initialize(provider); +} + +void WebBatteryManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) +{ + didReceiveWebBatteryManagerProxyMessage(connection, messageID, arguments); +} + +void WebBatteryManagerProxy::startUpdating() +{ + if (m_isUpdating) + return; + + m_provider.startUpdating(this); + m_isUpdating = true; +} + +void WebBatteryManagerProxy::stopUpdating() +{ + if (!m_isUpdating) + return; + + m_provider.stopUpdating(this); + m_isUpdating = false; +} + +void WebBatteryManagerProxy::providerDidChangeBatteryStatus(const WTF::AtomicString& eventType, WebBatteryStatus* status) +{ + if (!m_context) + return; + + m_context->sendToAllProcesses(Messages::WebBatteryManager::DidChangeBatteryStatus(eventType, status->data())); +} + +void WebBatteryManagerProxy::providerUpdateBatteryStatus(WebBatteryStatus* status) +{ + if (!m_context) + return; + + m_context->sendToAllProcesses(Messages::WebBatteryManager::UpdateBatteryStatus(status->data())); +} + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h new file mode 100644 index 0000000..9fa5bdc --- /dev/null +++ b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebBatteryManagerProxy_h +#define WebBatteryManagerProxy_h + +#if ENABLE(BATTERY_STATUS) + +#include "APIObject.h" +#include "MessageID.h" +#include "WebBatteryProvider.h" +#include + +namespace CoreIPC { +class ArgumentDecoder; +class Connection; +} + +namespace WebKit { + +class WebContext; +class WebBatteryStatus; + +class WebBatteryManagerProxy : public APIObject { +public: + static const Type APIType = TypeBatteryManager; + + static PassRefPtr create(WebContext*); + virtual ~WebBatteryManagerProxy(); + + void invalidate(); + void clearContext() { m_context = 0; } + + void initializeProvider(const WKBatteryProvider*); + + void providerDidChangeBatteryStatus(const WTF::AtomicString&, WebBatteryStatus*); + void providerUpdateBatteryStatus(WebBatteryStatus*); + + void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + +private: + explicit WebBatteryManagerProxy(WebContext*); + + virtual Type type() const { return APIType; } + + // Implemented in generated WebBatteryManagerProxyMessageReceiver.cpp + void didReceiveWebBatteryManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + + void startUpdating(); + void stopUpdating(); + + bool m_isUpdating; + + WebContext* m_context; + WebBatteryProvider m_provider; +}; + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) + +#endif // WebBatteryManagerProxy_h diff --git a/Source/WebKit2/UIProcess/WebBatteryManagerProxy.messages.in b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.messages.in new file mode 100644 index 0000000..3faefa1 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebBatteryManagerProxy.messages.in @@ -0,0 +1,30 @@ +# Copyright (C) 2012 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#if ENABLE(BATTERY_STATUS) + +messages -> WebBatteryManagerProxy { + StartUpdating(); + StopUpdating(); +} + +#endif diff --git a/Source/WebKit2/UIProcess/WebBatteryProvider.cpp b/Source/WebKit2/UIProcess/WebBatteryProvider.cpp new file mode 100644 index 0000000..8284160 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebBatteryProvider.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebBatteryProvider.h" + +#if ENABLE(BATTERY_STATUS) + +#include "WKAPICast.h" +#include "WebBatteryManagerProxy.h" + +namespace WebKit { + +void WebBatteryProvider::startUpdating(WebBatteryManagerProxy* batteryManager) +{ + if (!m_client.startUpdating) + return; + + m_client.startUpdating(toAPI(batteryManager), m_client.clientInfo); +} + +void WebBatteryProvider::stopUpdating(WebBatteryManagerProxy* batteryManager) +{ + if (!m_client.stopUpdating) + return; + + m_client.stopUpdating(toAPI(batteryManager), m_client.clientInfo); +} + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/UIProcess/WebBatteryProvider.h b/Source/WebKit2/UIProcess/WebBatteryProvider.h new file mode 100644 index 0000000..f599068 --- /dev/null +++ b/Source/WebKit2/UIProcess/WebBatteryProvider.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebBatteryProvider_h +#define WebBatteryProvider_h + +#if ENABLE(BATTERY_STATUS) + +#include "APIClient.h" +#include "WKBatteryManager.h" +#include + +namespace WebKit { + +class WebBatteryManagerProxy; + +class WebBatteryProvider : public APIClient { +public: + void startUpdating(WebBatteryManagerProxy*); + void stopUpdating(WebBatteryManagerProxy*); +}; + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) + +#endif // WebBatteryProvider_h diff --git a/Source/WebKit2/UIProcess/WebContext.cpp b/Source/WebKit2/UIProcess/WebContext.cpp index 21307cc..196fb81 100644 --- a/Source/WebKit2/UIProcess/WebContext.cpp +++ b/Source/WebKit2/UIProcess/WebContext.cpp @@ -66,6 +66,10 @@ #include "BuiltInPDFView.h" #endif +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryManagerProxy.h" +#endif + #if USE(SOUP) #include "WebSoupRequestManagerProxy.h" #endif @@ -130,6 +134,9 @@ WebContext::WebContext(ProcessModel processModel, const String& injectedBundlePa , m_memorySamplerEnabled(false) , m_memorySamplerInterval(1400.0) , m_applicationCacheManagerProxy(WebApplicationCacheManagerProxy::create(this)) +#if ENABLE(BATTERY_STATUS) + , m_batteryManagerProxy(WebBatteryManagerProxy::create(this)) +#endif , m_cookieManagerProxy(WebCookieManagerProxy::create(this)) , m_databaseManagerProxy(WebDatabaseManagerProxy::create(this)) , m_geolocationManagerProxy(WebGeolocationManagerProxy::create(this)) @@ -179,6 +186,11 @@ WebContext::~WebContext() m_applicationCacheManagerProxy->invalidate(); m_applicationCacheManagerProxy->clearContext(); +#if ENABLE(BATTERY_STATUS) + m_batteryManagerProxy->invalidate(); + m_batteryManagerProxy->clearContext(); +#endif + m_cookieManagerProxy->invalidate(); m_cookieManagerProxy->clearContext(); @@ -399,6 +411,9 @@ void WebContext::disconnectProcess(WebProcessProxy* process) m_downloads.clear(); m_applicationCacheManagerProxy->invalidate(); +#if ENABLE(BATTERY_STATUS) + m_batteryManagerProxy->invalidate(); +#endif m_cookieManagerProxy->invalidate(); m_databaseManagerProxy->invalidate(); m_geolocationManagerProxy->invalidate(); @@ -740,6 +755,13 @@ void WebContext::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::Mes return; } +#if ENABLE(BATTERY_STATUS) + if (messageID.is()) { + m_batteryManagerProxy->didReceiveMessage(connection, messageID, arguments); + return; + } +#endif + if (messageID.is()) { m_cookieManagerProxy->didReceiveMessage(connection, messageID, arguments); return; diff --git a/Source/WebKit2/UIProcess/WebContext.h b/Source/WebKit2/UIProcess/WebContext.h index a1ab1b9..21161c4 100644 --- a/Source/WebKit2/UIProcess/WebContext.h +++ b/Source/WebKit2/UIProcess/WebContext.h @@ -48,6 +48,9 @@ namespace WebKit { class DownloadProxy; class WebApplicationCacheManagerProxy; +#if ENABLE(BATTERY_STATUS) +class WebBatteryManagerProxy; +#endif class WebCookieManagerProxy; class WebDatabaseManagerProxy; class WebGeolocationManagerProxy; @@ -173,6 +176,9 @@ public: static HashSet pdfAndPostScriptMIMETypes(); WebApplicationCacheManagerProxy* applicationCacheManagerProxy() const { return m_applicationCacheManagerProxy.get(); } +#if ENABLE(BATTERY_STATUS) + WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); } +#endif WebCookieManagerProxy* cookieManagerProxy() const { return m_cookieManagerProxy.get(); } WebDatabaseManagerProxy* databaseManagerProxy() const { return m_databaseManagerProxy.get(); } WebGeolocationManagerProxy* geolocationManagerProxy() const { return m_geolocationManagerProxy.get(); } @@ -342,6 +348,9 @@ private: double m_memorySamplerInterval; RefPtr m_applicationCacheManagerProxy; +#if ENABLE(BATTERY_STATUS) + RefPtr m_batteryManagerProxy; +#endif RefPtr m_cookieManagerProxy; RefPtr m_databaseManagerProxy; RefPtr m_geolocationManagerProxy; diff --git a/Source/WebKit2/UIProcess/WebProcessProxy.cpp b/Source/WebKit2/UIProcess/WebProcessProxy.cpp index 455df4d..152a72e 100644 --- a/Source/WebKit2/UIProcess/WebProcessProxy.cpp +++ b/Source/WebKit2/UIProcess/WebProcessProxy.cpp @@ -307,6 +307,9 @@ void WebProcessProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC || messageID.is() || messageID.is() || messageID.is() +#if ENABLE(BATTERY_STATUS) + || messageID.is() +#endif || messageID.is() || messageID.is() || messageID.is() diff --git a/Source/WebKit2/WebProcess/Battery/WebBatteryManager.cpp b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.cpp new file mode 100644 index 0000000..9dae141 --- /dev/null +++ b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebBatteryManager.h" + +#if ENABLE(BATTERY_STATUS) + +#include "WebBatteryManagerProxyMessages.h" +#include "WebPage.h" +#include "WebProcess.h" +#include +#include +#include + +using namespace WebCore; + +namespace WebKit { + +WebBatteryManager::WebBatteryManager(WebProcess* process) + : m_process(process) +{ +} + +WebBatteryManager::~WebBatteryManager() +{ +} + +void WebBatteryManager::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) +{ + didReceiveWebBatteryManagerMessage(connection, messageID, arguments); +} + +void WebBatteryManager::registerWebPage(WebPage* page) +{ + LOG_ERROR("====Jiyeon WebBatteryManager::registerWebPage"); + bool wasEmpty = m_pageSet.isEmpty(); + + m_pageSet.add(page); + + if (wasEmpty) + m_process->connection()->send(Messages::WebBatteryManagerProxy::StartUpdating(), 0); +} + +void WebBatteryManager::unregisterWebPage(WebPage* page) +{ + m_pageSet.remove(page); + + if (m_pageSet.isEmpty()) + m_process->connection()->send(Messages::WebBatteryManagerProxy::StopUpdating(), 0); +} + +void WebBatteryManager::didChangeBatteryStatus(const WTF::AtomicString& eventType, const WebBatteryStatus::Data& data) +{ + RefPtr status = BatteryStatus::create(data.isCharging, data.chargingTime, data.dischargingTime, data.level); + + HashSet::const_iterator it = m_pageSet.begin(); + HashSet::const_iterator end = m_pageSet.end(); + for (; it != end; ++it) { + WebPage* page = *it; + if (page->corePage()) + BatteryController::from(page->corePage())->didChangeBatteryStatus(eventType, status.get()); + } +} + +void WebBatteryManager::updateBatteryStatus(const WebBatteryStatus::Data& data) +{ + RefPtr status = BatteryStatus::create(data.isCharging, data.chargingTime, data.dischargingTime, data.level); + + HashSet::const_iterator it = m_pageSet.begin(); + HashSet::const_iterator end = m_pageSet.end(); + for (; it != end; ++it) { + WebPage* page = *it; + if (page->corePage()) + BatteryController::from(page->corePage())->updateBatteryStatus(status.get()); + } +} + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/WebProcess/Battery/WebBatteryManager.h b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.h new file mode 100644 index 0000000..509718d --- /dev/null +++ b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebBatteryManager_h +#define WebBatteryManager_h + +#if ENABLE(BATTERY_STATUS) + +#include "MessageID.h" +#include "WebBatteryStatus.h" +#include "WebCoreArgumentCoders.h" +#include +#include +#include + +namespace CoreIPC { +class ArgumentDecoder; +class Connection; +} + +namespace WebKit { + +class WebPage; +class WebProcess; + +class WebBatteryManager { + WTF_MAKE_NONCOPYABLE(WebBatteryManager); + +public: + explicit WebBatteryManager(WebProcess*); + ~WebBatteryManager(); + + void registerWebPage(WebPage*); + void unregisterWebPage(WebPage*); + + void didChangeBatteryStatus(const WTF::AtomicString& eventType, const WebBatteryStatus::Data&); + void updateBatteryStatus(const WebBatteryStatus::Data&); + + void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + +private: + // Implemented in generated WebBatteryManagerMessageReceiver.cpp + void didReceiveWebBatteryManagerMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + + WebProcess* m_process; + HashSet m_pageSet; +}; + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) + +#endif // WebBatteryManager_h diff --git a/Source/WebKit2/WebProcess/Battery/WebBatteryManager.messages.in b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.messages.in new file mode 100644 index 0000000..37e73ef --- /dev/null +++ b/Source/WebKit2/WebProcess/Battery/WebBatteryManager.messages.in @@ -0,0 +1,30 @@ +# Copyright (C) 2012 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#if ENABLE(BATTERY_STATUS) + +messages -> WebBatteryManager { + DidChangeBatteryStatus(AtomicString eventType, WebKit::WebBatteryStatus::Data status); + UpdateBatteryStatus(WebKit::WebBatteryStatus::Data status); +} + +#endif diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.cpp new file mode 100644 index 0000000..91033fa --- /dev/null +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebBatteryClient.h" + +#if ENABLE(BATTERY_STATUS) + +#include "WebBatteryManager.h" +#include "WebPage.h" +#include "WebProcess.h" + +using namespace WebCore; + +namespace WebKit { + +void WebBatteryClient::startUpdating() +{ + WebProcess::shared().batteryManager().registerWebPage(m_page); +} + +void WebBatteryClient::stopUpdating() +{ + WebProcess::shared().batteryManager().unregisterWebPage(m_page); +} + +void WebBatteryClient::batteryControllerDestroyed() +{ + WebProcess::shared().batteryManager().unregisterWebPage(m_page); + delete this; +} + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.h b/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.h new file mode 100644 index 0000000..b260c62 --- /dev/null +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebBatteryClient.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebBatteryClient_h +#define WebBatteryClient_h + +#if ENABLE(BATTERY_STATUS) + +#include + +namespace WebKit { + +class WebPage; + +class WebBatteryClient : public WebCore::BatteryClient { +public: + WebBatteryClient(WebPage* page) + : m_page(page) + { + } + + virtual ~WebBatteryClient() { } + +private: + virtual void startUpdating() OVERRIDE; + virtual void stopUpdating() OVERRIDE; + virtual void batteryControllerDestroyed() OVERRIDE; + + WebPage* m_page; +}; + +} // namespace WebKit + +#endif // ENABLE(BATTERY_STATUS) + +#endif // WebBatteryClient_h diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index 4b1560e..71e1201 100755 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -130,6 +130,10 @@ #endif #endif +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryClient.h" +#endif + #if PLATFORM(MAC) #include "BuiltInPDFView.h" #endif @@ -297,6 +301,10 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters) m_page = adoptPtr(new Page(pageClients)); +#if ENABLE(BATTERY_STATUS) + WebCore::provideBatteryTo(m_page.get(), new WebBatteryClient(this)); +#endif + #if ENABLE(GEOLOCATION) WebCore::provideGeolocationTo(m_page.get(), new WebGeolocationClient(this)); #endif diff --git a/Source/WebKit2/WebProcess/WebProcess.cpp b/Source/WebKit2/WebProcess/WebProcess.cpp index de5dfd0..1ce5b60 100644 --- a/Source/WebKit2/WebProcess/WebProcess.cpp +++ b/Source/WebKit2/WebProcess/WebProcess.cpp @@ -150,6 +150,9 @@ WebProcess::WebProcess() #endif , m_textCheckerState() , m_geolocationManager(this) +#if ENABLE(BATTERY_STATUS) + , m_batteryManager(this) +#endif #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) , m_notificationManager(this) #endif @@ -676,6 +679,13 @@ void WebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::Mes return; } +#if ENABLE(BATTERY_STATUS) + if (messageID.is()) { + m_batteryManager.didReceiveMessage(connection, messageID, arguments); + return; + } +#endif + if (messageID.is()) { m_iconDatabaseProxy.didReceiveMessage(connection, messageID, arguments); return; diff --git a/Source/WebKit2/WebProcess/WebProcess.h b/Source/WebKit2/WebProcess/WebProcess.h index f319328..4d3c214 100644 --- a/Source/WebKit2/WebProcess/WebProcess.h +++ b/Source/WebKit2/WebProcess/WebProcess.h @@ -57,6 +57,10 @@ class QNetworkAccessManager; #include #endif +#if ENABLE(BATTERY_STATUS) +#include "WebBatteryManager.h" +#endif + #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) #include "WebNotificationManager.h" #endif @@ -143,6 +147,10 @@ public: // Geolocation WebGeolocationManager& geolocationManager() { return m_geolocationManager; } +#if ENABLE(BATTERY_STATUS) + WebBatteryManager& batteryManager() { return m_batteryManager; } +#endif + #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) WebNotificationManager& notificationManager() { return m_notificationManager; } #endif @@ -308,6 +316,9 @@ private: TextCheckerState m_textCheckerState; WebGeolocationManager m_geolocationManager; +#if ENABLE(BATTERY_STATUS) + WebBatteryManager m_batteryManager; +#endif #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) WebNotificationManager m_notificationManager; #endif diff --git a/Source/cmake/FindPmapi.cmake b/Source/cmake/FindPmapi.cmake new file mode 100755 index 0000000..f6a27e1 --- /dev/null +++ b/Source/cmake/FindPmapi.cmake @@ -0,0 +1,31 @@ +# - Try to find Pmapi +# Once done, this will define +# +# Pmapi_FOUND - system has pmapi +# Pmapi_INCLUDE_DIRS - the pmapi include directories +# Pmapi_LIBRARIES - link these to use pmapi + +include(LibFindMacros) + +# Use pkg-config to get hints about paths +libfind_pkg_check_modules(Pmapi_PKGCONF pmapi) + +# Include dir +find_path(Pmapi_INCLUDE_DIR + NAMES pmapi.h + PATHS ${Pmapi_PKGCONF_INCLUDE_DIRS} + PATH_SUFFIXES pmapi +) + +# Finally the library itself +find_library(Pmapi_LIBRARY + NAMES pmapi + PATHS ${Pmapi_PKGCONF_LIBRARY_DIRS} +) + +# Set the include dir variables and the libraries and let libfind_process do the rest. +# NOTE: Singular variables for this library, plural for libraries this this lib depends on. +set(Pmapi_PROCESS_INCLUDES Pmapi_INCLUDE_DIR Pmapi_INCLUDE_DIRS) +set(Pmapi_PROCESS_LIBS Pmapi_LIBRARY Pmapi_LIBRARIES) +libfind_process(Pmapi) + diff --git a/Source/cmake/OptionsTizen.cmake b/Source/cmake/OptionsTizen.cmake index 290521c..b5b26e4 100755 --- a/Source/cmake/OptionsTizen.cmake +++ b/Source/cmake/OptionsTizen.cmake @@ -63,7 +63,7 @@ SET(VERSION_SCRIPT "-Wl,--version-script,${CMAKE_MODULE_PATH}/eflsymbols.filter" WEBKIT_OPTION_BEGIN() WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_3D_RENDERING ON) -WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_BATTERY_STATUS OFF) +WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_BATTERY_STATUS ON) WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_BLOB ON) WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_FILTERS ON) WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DATALIST ON) @@ -198,6 +198,12 @@ IF (ENABLE_TIZEN_SUPPORT) SET(ENABLE_TOUCH_ICON_LOADING 1) + IF (ENABLE_BATTERY_STATUS) + ADD_DEFINITIONS(-DENABLE_TIZEN_BATTERY_STATUS=1) + SET(ENABLE_TIZEN_BATTERY_STATUS 1) + FIND_PACKAGE(Pmapi REQUIRED) + ENDIF () + IF (ENABLE_WEBKIT2) # SET(ENABLE_NOTIFICATIONS 1) # LIST(APPEND FEATURE_DEFINES ENABLE_NOTIFICATIONS) diff --git a/packaging/webkit2-efl.spec b/packaging/webkit2-efl.spec index de6699b..1605499 100755 --- a/packaging/webkit2-efl.spec +++ b/packaging/webkit2-efl.spec @@ -47,6 +47,7 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(leveldb) BuildRequires: pkgconfig(capi-location-manager) BuildRequires: pkgconfig(ui-gadget-1) +BuildRequires: pkgconfig(pmapi) %ifarch %{arm} BuildRequires: pkgconfig(gles20) -- 2.7.4