Bug 838124 - Convert BatteryManager to WebIDL. r=peterv

This commit is contained in:
Andrea Marchesini 2013-02-05 07:54:49 -05:00
parent 67b204034f
commit b822140315
12 changed files with 85 additions and 95 deletions

View File

@ -1124,7 +1124,7 @@ NS_IMETHODIMP Navigator::GetMozNotification(nsIDOMDesktopNotificationCenter** aR
//*****************************************************************************
NS_IMETHODIMP
Navigator::GetBattery(nsIDOMBatteryManager** aBattery)
Navigator::GetBattery(nsISupports** aBattery)
{
if (!mBatteryManager) {
*aBattery = nullptr;

View File

@ -415,7 +415,6 @@ using mozilla::dom::workers::ResolveWorkerClasses;
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"
#include "nsIDOMBatteryManager.h"
#include "BatteryManager.h"
#include "nsIDOMPowerManager.h"
#include "nsIDOMWakeLock.h"
@ -1257,9 +1256,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(GeoPositionError, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(BatteryManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozPowerManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -3364,11 +3360,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMGeoPositionError)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(BatteryManager, nsIDOMBatteryManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBatteryManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozPowerManager, nsIDOMMozPowerManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozPowerManager)
DOM_CLASSINFO_MAP_END

View File

@ -309,8 +309,6 @@ DOMCI_CLASS(GeoPosition)
DOMCI_CLASS(GeoPositionCoords)
DOMCI_CLASS(GeoPositionError)
DOMCI_CLASS(BatteryManager)
DOMCI_CLASS(MozPowerManager)
DOMCI_CLASS(MozWakeLock)

View File

@ -11,6 +11,7 @@
#include "nsDOMEvent.h"
#include "mozilla/Preferences.h"
#include "nsDOMEventTargetHelper.h"
#include "mozilla/dom/BatteryManagerBinding.h"
/**
* We have to use macros here because our leak analysis tool things we are
@ -21,32 +22,16 @@
#define DISCHARGINGTIMECHANGE_EVENT_NAME NS_LITERAL_STRING("dischargingtimechange")
#define CHARGINGTIMECHANGE_EVENT_NAME NS_LITERAL_STRING("chargingtimechange")
DOMCI_DATA(BatteryManager, mozilla::dom::battery::BatteryManager)
namespace mozilla {
namespace dom {
namespace battery {
NS_IMPL_CYCLE_COLLECTION_INHERITED_0(BatteryManager, nsDOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BatteryManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMBatteryManager)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BatteryManager)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(BatteryManager, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(BatteryManager, nsDOMEventTargetHelper)
NS_IMPL_EVENT_HANDLER(BatteryManager, levelchange)
NS_IMPL_EVENT_HANDLER(BatteryManager, chargingchange)
NS_IMPL_EVENT_HANDLER(BatteryManager, chargingtimechange)
NS_IMPL_EVENT_HANDLER(BatteryManager, dischargingtimechange)
BatteryManager::BatteryManager()
: mLevel(kDefaultLevel)
, mCharging(kDefaultCharging)
, mRemainingTime(kDefaultRemainingTime)
{
SetIsDOMBinding();
}
void
@ -68,46 +53,30 @@ BatteryManager::Shutdown()
hal::UnregisterBatteryObserver(this);
}
NS_IMETHODIMP
BatteryManager::GetCharging(bool* aCharging)
JSObject*
BatteryManager::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
*aCharging = mCharging;
return NS_OK;
return BatteryManagerBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
NS_IMETHODIMP
BatteryManager::GetLevel(double* aLevel)
{
*aLevel = mLevel;
return NS_OK;
}
NS_IMETHODIMP
BatteryManager::GetDischargingTime(double* aDischargingTime)
double
BatteryManager::DischargingTime() const
{
if (mCharging || mRemainingTime == kUnknownRemainingTime) {
*aDischargingTime = std::numeric_limits<double>::infinity();
return NS_OK;
return std::numeric_limits<double>::infinity();
}
*aDischargingTime = mRemainingTime;
return NS_OK;
return mRemainingTime;
}
NS_IMETHODIMP
BatteryManager::GetChargingTime(double* aChargingTime)
double
BatteryManager::ChargingTime() const
{
if (!mCharging || mRemainingTime == kUnknownRemainingTime) {
*aChargingTime = std::numeric_limits<double>::infinity();
return NS_OK;
return std::numeric_limits<double>::infinity();
}
*aChargingTime = mRemainingTime;
return NS_OK;
return mRemainingTime;
}
void

View File

@ -6,7 +6,6 @@
#ifndef mozilla_dom_battery_BatteryManager_h
#define mozilla_dom_battery_BatteryManager_h
#include "nsIDOMBatteryManager.h"
#include "nsDOMEventTargetHelper.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Observer.h"
@ -26,14 +25,9 @@ namespace dom {
namespace battery {
class BatteryManager : public nsDOMEventTargetHelper
, public nsIDOMBatteryManager
, public BatteryObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMBATTERYMANAGER
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
BatteryManager();
void Init(nsPIDOMWindow *aWindow);
@ -42,15 +36,42 @@ public:
// For IObserver.
void Notify(const hal::BatteryInformation& aBatteryInfo);
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BatteryManager,
nsDOMEventTargetHelper)
/**
* Returns whether the battery api is supported (ie. not disabled by the user)
* @return whether the battery api is supported.
*/
static bool HasSupport();
/**
* WebIDL Interface
*/
nsPIDOMWindow* GetParentObject() const
{
return GetOwner();
}
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap);
bool Charging() const
{
return mCharging;
}
double ChargingTime() const;
double DischargingTime() const;
double Level() const
{
return mLevel;
}
IMPL_EVENT_HANDLER(chargingchange)
IMPL_EVENT_HANDLER(chargingtimechange)
IMPL_EVENT_HANDLER(dischargingtimechange)
IMPL_EVENT_HANDLER(levelchange)
private:
/**

View File

@ -33,7 +33,6 @@ LOCAL_INCLUDES = \
$(NULL)
XPIDLSRCS = \
nsIDOMBatteryManager.idl \
nsINavigatorBattery.idl \
$(NULL)

View File

@ -1,21 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIDOMEventTarget.idl"
interface nsIDOMEventListener;
[scriptable, builtinclass, uuid(3d95d773-3c19-4944-8152-ec6ca01a8bde)]
interface nsIDOMBatteryManager : nsIDOMEventTarget
{
readonly attribute double level;
readonly attribute boolean charging;
readonly attribute double dischargingTime;
readonly attribute double chargingTime;
[implicit_jscontext] attribute jsval onlevelchange;
[implicit_jscontext] attribute jsval onchargingchange;
[implicit_jscontext] attribute jsval ondischargingtimechange;
[implicit_jscontext] attribute jsval onchargingtimechange;
};

View File

@ -4,10 +4,8 @@
#include "nsISupports.idl"
interface nsIDOMBatteryManager;
[scriptable, uuid(4a78a8d5-5bbb-4a92-ad97-f19e853a7008)]
[scriptable, uuid(16ed7adc-b3e0-43c6-a121-5a2b500e90d0)]
interface nsINavigatorBattery : nsISupports
{
readonly attribute nsIDOMBatteryManager battery;
readonly attribute nsISupports battery;
};

View File

@ -130,6 +130,11 @@ DOMInterfaces = {
'workers': True,
}],
'BatteryManager': {
'nativeType': 'mozilla::dom::battery::BatteryManager',
'headerFile': 'BatteryManager.h'
},
'CanvasRenderingContext2D': {
'implicitJSContext': [
'createImageData', 'getImageData', 'strokeStyle',
@ -142,9 +147,9 @@ DOMInterfaces = {
}
},
'CaretPosition' : {
'nativeType': 'nsDOMCaretPosition',
},
'CaretPosition' : {
'nativeType': 'nsDOMCaretPosition',
},
'CDATASection': {
'hasInstanceInterface': 'nsIDOMCDATASection',
@ -537,7 +542,7 @@ DOMInterfaces = {
'workers': True,
}],
'MutationObserver': {
'nativeType': 'nsDOMMutationObserver',
},

View File

@ -84,6 +84,7 @@ LOCAL_INCLUDES += -I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/content/html/content/src \
-I$(topsrcdir)/media/webrtc/signaling/src/peerconnection \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/dom/battery \
-I$(topsrcdir)/content/xslt/src/base \
-I$(topsrcdir)/content/xslt/src/xpath \
-I$(topsrcdir)/content/xml/content/src \

View File

@ -0,0 +1,28 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://www.w3.org/TR/battery-status/
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
[NoInterfaceObject]
interface BatteryManager : EventTarget {
readonly attribute boolean charging;
readonly attribute unrestricted double chargingTime;
readonly attribute unrestricted double dischargingTime;
readonly attribute double level;
[SetterThrows]
attribute EventHandler onchargingchange;
[SetterThrows]
attribute EventHandler onchargingtimechange;
[SetterThrows]
attribute EventHandler ondischargingtimechange;
[SetterThrows]
attribute EventHandler onlevelchange;
};

View File

@ -17,6 +17,7 @@ webidl_files = \
AudioNode.webidl \
AudioParam.webidl \
AudioSourceNode.webidl \
BatteryManager.webidl \
BiquadFilterNode.webidl \
Blob.webidl \
CanvasRenderingContext2D.webidl \