зеркало из https://github.com/mozilla/pjs.git
Bug 700298 - r=smaug
This commit is contained in:
Родитель
e2e6d5823c
Коммит
beaf6dbbef
|
@ -749,8 +749,22 @@ NS_IMETHODIMP
|
|||
Navigator::GetMozBattery(nsIDOMBatteryManager** aBattery)
|
||||
{
|
||||
if (!mBatteryManager) {
|
||||
*aBattery = nsnull;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mDocShell);
|
||||
NS_ENSURE_TRUE(window, NS_OK);
|
||||
|
||||
nsCOMPtr<nsIDocument> document = do_GetInterface(mDocShell);
|
||||
NS_ENSURE_TRUE(document, NS_OK);
|
||||
|
||||
nsIScriptGlobalObject* sgo = document->GetScopeObject();
|
||||
NS_ENSURE_TRUE(sgo, NS_OK);
|
||||
|
||||
nsIScriptContext* scx = sgo->GetContext();
|
||||
NS_ENSURE_TRUE(scx, NS_OK);
|
||||
|
||||
mBatteryManager = new battery::BatteryManager();
|
||||
mBatteryManager->Init();
|
||||
mBatteryManager->Init(window->GetCurrentInnerWindow(), scx);
|
||||
}
|
||||
|
||||
NS_ADDREF(*aBattery = mBatteryManager);
|
||||
|
|
|
@ -61,26 +61,28 @@ namespace battery {
|
|||
NS_IMPL_CYCLE_COLLECTION_CLASS(BatteryManager)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BatteryManager,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnLevelChangeListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnChargingChangeListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnDischargingTimeChangeListener)
|
||||
nsDOMEventTargetWrapperCache)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(levelchange)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(chargingchange)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(chargingtimechange)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(dischargingtimechange)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BatteryManager,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnLevelChangeListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnChargingChangeListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnDischargingTimeChangeListener)
|
||||
nsDOMEventTargetWrapperCache)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(levelchange)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(chargingchange)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(chargingtimechange)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(dischargingtimechange)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
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_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetWrapperCache)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(BatteryManager, nsDOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(BatteryManager, nsDOMEventTargetHelper)
|
||||
NS_IMPL_ADDREF_INHERITED(BatteryManager, nsDOMEventTargetWrapperCache)
|
||||
NS_IMPL_RELEASE_INHERITED(BatteryManager, nsDOMEventTargetWrapperCache)
|
||||
|
||||
BatteryManager::BatteryManager()
|
||||
: mLevel(kDefaultLevel)
|
||||
|
@ -97,8 +99,12 @@ BatteryManager::~BatteryManager()
|
|||
}
|
||||
|
||||
void
|
||||
BatteryManager::Init()
|
||||
BatteryManager::Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext)
|
||||
{
|
||||
// Those vars come from nsDOMEventTargetHelper.
|
||||
mOwner = aWindow;
|
||||
mScriptContext = aScriptContext;
|
||||
|
||||
hal::RegisterBatteryObserver(this);
|
||||
|
||||
hal::BatteryInformation* batteryInfo = new hal::BatteryInformation();
|
||||
|
@ -157,61 +163,10 @@ BatteryManager::GetChargingTime(double* aChargingTime)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::GetOnlevelchange(nsIDOMEventListener** aOnlevelchange)
|
||||
{
|
||||
return GetInnerEventListener(mOnLevelChangeListener, aOnlevelchange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::SetOnlevelchange(nsIDOMEventListener* aOnlevelchange)
|
||||
{
|
||||
return RemoveAddEventListener(LEVELCHANGE_EVENT_NAME, mOnLevelChangeListener,
|
||||
aOnlevelchange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::GetOnchargingchange(nsIDOMEventListener** aOnchargingchange)
|
||||
{
|
||||
return GetInnerEventListener(mOnChargingChangeListener, aOnchargingchange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::SetOnchargingchange(nsIDOMEventListener* aOnchargingchange)
|
||||
{
|
||||
return RemoveAddEventListener(CHARGINGCHANGE_EVENT_NAME,
|
||||
mOnChargingChangeListener, aOnchargingchange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::GetOndischargingtimechange(nsIDOMEventListener** aOndischargingtimechange)
|
||||
{
|
||||
return GetInnerEventListener(mOnDischargingTimeChangeListener,
|
||||
aOndischargingtimechange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::SetOndischargingtimechange(nsIDOMEventListener* aOndischargingtimechange)
|
||||
{
|
||||
return RemoveAddEventListener(DISCHARGINGTIMECHANGE_EVENT_NAME,
|
||||
mOnDischargingTimeChangeListener,
|
||||
aOndischargingtimechange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::GetOnchargingtimechange(nsIDOMEventListener** aOnchargingtimechange)
|
||||
{
|
||||
return GetInnerEventListener(mOnChargingTimeChangeListener,
|
||||
aOnchargingtimechange);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BatteryManager::SetOnchargingtimechange(nsIDOMEventListener* aOnchargingtimechange)
|
||||
{
|
||||
return RemoveAddEventListener(CHARGINGTIMECHANGE_EVENT_NAME,
|
||||
mOnChargingTimeChangeListener,
|
||||
aOnchargingtimechange);
|
||||
}
|
||||
NS_IMPL_EVENT_HANDLER(BatteryManager, levelchange)
|
||||
NS_IMPL_EVENT_HANDLER(BatteryManager, chargingchange)
|
||||
NS_IMPL_EVENT_HANDLER(BatteryManager, chargingtimechange)
|
||||
NS_IMPL_EVENT_HANDLER(BatteryManager, dischargingtimechange)
|
||||
|
||||
nsresult
|
||||
BatteryManager::DispatchTrustedEventToSelf(const nsAString& aEventName)
|
||||
|
|
|
@ -39,11 +39,14 @@
|
|||
#define mozilla_dom_battery_BatteryManager_h
|
||||
|
||||
#include "nsIDOMBatteryManager.h"
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "nsDOMEventTargetWrapperCache.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/Observer.h"
|
||||
#include "Types.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
class nsIScriptContext;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace hal {
|
||||
|
@ -53,26 +56,26 @@ class BatteryInformation;
|
|||
namespace dom {
|
||||
namespace battery {
|
||||
|
||||
class BatteryManager : public nsIDOMBatteryManager
|
||||
, public nsDOMEventTargetHelper
|
||||
class BatteryManager : public nsDOMEventTargetWrapperCache
|
||||
, public nsIDOMBatteryManager
|
||||
, public BatteryObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMBATTERYMANAGER
|
||||
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
|
||||
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetWrapperCache::)
|
||||
|
||||
BatteryManager();
|
||||
virtual ~BatteryManager();
|
||||
|
||||
void Init();
|
||||
void Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext);
|
||||
void Shutdown();
|
||||
|
||||
// For IObserver.
|
||||
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BatteryManager,
|
||||
nsDOMEventTargetHelper)
|
||||
nsDOMEventTargetWrapperCache)
|
||||
|
||||
/**
|
||||
* Returns whether the battery api is supported (ie. not disabled by the user)
|
||||
|
@ -101,10 +104,10 @@ private:
|
|||
*/
|
||||
double mRemainingTime;
|
||||
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnLevelChangeListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnChargingChangeListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnDischargingTimeChangeListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnChargingTimeChangeListener;
|
||||
NS_DECL_EVENT_HANDLER(levelchange);
|
||||
NS_DECL_EVENT_HANDLER(chargingchange);
|
||||
NS_DECL_EVENT_HANDLER(chargingtimechange);
|
||||
NS_DECL_EVENT_HANDLER(dischargingtimechange);
|
||||
};
|
||||
|
||||
} // namespace battery
|
||||
|
|
Загрузка…
Ссылка в новой задаче