Bug 911603 - Convert MozPowerManager to WebIDL r=Ms2ger

--HG--
rename : dom/power/nsIDOMPowerManager.idl => dom/webidl/MozPowerManager.webidl
This commit is contained in:
David Zbarsky 2013-09-10 19:03:56 -04:00
parent 74d286ade3
commit c0ee768917
13 changed files with 110 additions and 94 deletions

View File

@ -1100,7 +1100,7 @@ Navigator::GetBattery(ErrorResult& aRv)
return mBatteryManager;
}
nsIDOMMozPowerManager*
power::PowerManager*
Navigator::GetMozPower(ErrorResult& aRv)
{
if (!mPowerManager) {

View File

@ -199,7 +199,7 @@ public:
{
aRv = GetBuildID(aBuildID);
}
nsIDOMMozPowerManager* GetMozPower(ErrorResult& aRv);
power::PowerManager* GetMozPower(ErrorResult& aRv);
bool JavaEnabled(ErrorResult& aRv);
bool TaintEnabled()
{

View File

@ -158,7 +158,6 @@
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"
#include "nsIDOMPowerManager.h"
#include "nsIDOMWakeLock.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIDOMMozSmsMessage.h"
@ -464,9 +463,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozPowerManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozWakeLock, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -1280,10 +1276,6 @@ nsDOMClassInfo::Init()
#endif
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozPowerManager, nsIDOMMozPowerManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozPowerManager)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozWakeLock, nsIDOMMozWakeLock)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozWakeLock)
DOM_CLASSINFO_MAP_END

View File

@ -88,7 +88,6 @@ DOMCI_CLASS(File)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)
DOMCI_CLASS(MozPowerManager)
DOMCI_CLASS(MozWakeLock)
DOMCI_CLASS(MozMobileMessageManager)

View File

@ -776,8 +776,8 @@ DOMInterfaces = {
'nativeType': 'nsDOMAttributeMap',
},
'MozTimeManager': {
'nativeType': 'mozilla::dom::time::TimeManager',
'MozPowerManager': {
'nativeType': 'mozilla::dom::power::PowerManager',
},
'MozStkCommandEvent' : {
@ -785,6 +785,10 @@ DOMInterfaces = {
'headerFile': 'StkCommandEvent.h',
},
'MozTimeManager': {
'nativeType': 'mozilla::dom::time::TimeManager',
},
'MozVoicemail': {
'nativeType': 'mozilla::dom::Voicemail',
},
@ -1799,7 +1803,6 @@ addExternalIface('MozMediaStreamOptions', nativeType='nsIMediaStreamOptions',
addExternalIface('MozMobileConnection', headerFile='nsIDOMMobileConnection.h')
addExternalIface('MozMobileMessageManager', headerFile='nsIDOMMobileMessageManager.h')
addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True)
addExternalIface('MozPowerManager', headerFile='nsIDOMPowerManager.h')
addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource',
notflattened=True)
addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True)
@ -1810,6 +1813,7 @@ addExternalIface('MozTreeColumn', nativeType='nsITreeColumn',
headerFile='nsITreeColumns.h')
addExternalIface('MozVoicemailStatus')
addExternalIface('MozWakeLock', headerFile='nsIDOMWakeLock.h')
addExternalIface('MozWakeLockListener', headerFile='nsIDOMWakeLockListener.h')
addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder')
addExternalIface('nsIControllers', nativeType='nsIControllers')
addExternalIface('nsIInputStreamCallback', nativeType='nsIInputStreamCallback',

View File

@ -85,5 +85,4 @@ interface nsIDOMFontFace;
interface nsIDOMFontFaceList;
// Power
interface nsIDOMMozPowerManager;
interface nsIDOMMozWakeLock;

View File

@ -20,7 +20,7 @@ var gData = [
{
perm: ["power"],
obj: "mozPower",
idl: "nsIDOMMozPowerManager",
webidl: "MozPowerManager",
},
]
</script>

View File

@ -15,29 +15,33 @@
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsError.h"
DOMCI_DATA(MozPowerManager, mozilla::dom::power::PowerManager)
#include "mozilla/dom/MozPowerManagerBinding.h"
namespace mozilla {
namespace dom {
namespace power {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PowerManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozPowerManager)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozPowerManager)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozWakeLockListener)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozPowerManager)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_1(PowerManager, mListeners)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(PowerManager, mListeners, mWindow)
NS_IMPL_CYCLE_COLLECTING_ADDREF(PowerManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PowerManager)
/* virtual */ JSObject*
PowerManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return MozPowerManagerBinding::Wrap(aCx, aScope, this);
}
nsresult
PowerManager::Init(nsIDOMWindow *aWindow)
{
mWindow = do_GetWeakReference(aWindow);
mWindow = aWindow;
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
@ -60,63 +64,62 @@ PowerManager::Shutdown()
return NS_OK;
}
NS_IMETHODIMP
PowerManager::Reboot()
void
PowerManager::Reboot(ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
NS_ENSURE_STATE(pmService);
pmService->Reboot();
return NS_OK;
if (pmService) {
pmService->Reboot();
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
NS_IMETHODIMP
void
PowerManager::FactoryReset()
{
hal::FactoryReset();
return NS_OK;
}
NS_IMETHODIMP
PowerManager::PowerOff()
void
PowerManager::PowerOff(ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
NS_ENSURE_STATE(pmService);
pmService->PowerOff();
return NS_OK;
if (pmService) {
pmService->PowerOff();
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
NS_IMETHODIMP
void
PowerManager::AddWakeLockListener(nsIDOMMozWakeLockListener *aListener)
{
// already added? bail out.
if (mListeners.Contains(aListener))
return NS_OK;
mListeners.AppendElement(aListener);
return NS_OK;
if (!mListeners.Contains(aListener)) {
mListeners.AppendElement(aListener);
}
}
NS_IMETHODIMP
void
PowerManager::RemoveWakeLockListener(nsIDOMMozWakeLockListener *aListener)
{
mListeners.RemoveElement(aListener);
return NS_OK;
}
NS_IMETHODIMP
PowerManager::GetWakeLockState(const nsAString &aTopic, nsAString &aState)
void
PowerManager::GetWakeLockState(const nsAString& aTopic,
nsAString& aState,
ErrorResult& aRv)
{
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
NS_ENSURE_STATE(pmService);
return pmService->GetWakeLockState(aTopic, aState);
if (pmService) {
aRv = pmService->GetWakeLockState(aTopic, aState);
} else {
aRv.Throw(NS_ERROR_UNEXPECTED);
}
}
NS_IMETHODIMP
@ -138,47 +141,44 @@ PowerManager::Callback(const nsAString &aTopic, const nsAString &aState)
return NS_OK;
}
NS_IMETHODIMP
PowerManager::GetScreenEnabled(bool *aEnabled)
bool
PowerManager::ScreenEnabled()
{
*aEnabled = hal::GetScreenEnabled();
return NS_OK;
return hal::GetScreenEnabled();
}
NS_IMETHODIMP
void
PowerManager::SetScreenEnabled(bool aEnabled)
{
hal::SetScreenEnabled(aEnabled);
return NS_OK;
}
NS_IMETHODIMP
PowerManager::GetScreenBrightness(double *aBrightness)
double
PowerManager::ScreenBrightness()
{
*aBrightness = hal::GetScreenBrightness();
return NS_OK;
return hal::GetScreenBrightness();
}
NS_IMETHODIMP
PowerManager::SetScreenBrightness(double aBrightness)
void
PowerManager::SetScreenBrightness(double aBrightness, ErrorResult& aRv)
{
NS_ENSURE_TRUE(0 <= aBrightness && aBrightness <= 1, NS_ERROR_INVALID_ARG);
hal::SetScreenBrightness(aBrightness);
return NS_OK;
if (0 <= aBrightness && aBrightness <= 1) {
hal::SetScreenBrightness(aBrightness);
} else {
aRv.Throw(NS_ERROR_INVALID_ARG);
}
}
NS_IMETHODIMP
PowerManager::GetCpuSleepAllowed(bool *aAllowed)
bool
PowerManager::CpuSleepAllowed()
{
*aAllowed = hal::GetCpuSleepAllowed();
return NS_OK;
return hal::GetCpuSleepAllowed();
}
NS_IMETHODIMP
void
PowerManager::SetCpuSleepAllowed(bool aAllowed)
{
hal::SetCpuSleepAllowed(aAllowed);
return NS_OK;
}
bool

View File

@ -7,30 +7,32 @@
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIDOMPowerManager.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIDOMWindow.h"
#include "nsWeakReference.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
class nsPIDOMWindow;
namespace mozilla {
class ErrorResult;
namespace dom {
namespace power {
class PowerManager
: public nsIDOMMozPowerManager
, public nsIDOMMozWakeLockListener
class PowerManager MOZ_FINAL : public nsIDOMMozWakeLockListener
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PowerManager, nsIDOMMozPowerManager)
NS_DECL_NSIDOMMOZPOWERMANAGER
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PowerManager)
NS_DECL_NSIDOMMOZWAKELOCKLISTENER
PowerManager() {};
virtual ~PowerManager() {};
PowerManager()
{
SetIsDOMBinding();
}
nsresult Init(nsIDOMWindow *aWindow);
nsresult Shutdown();
@ -39,9 +41,28 @@ public:
static already_AddRefed<PowerManager> CreateInstance(nsPIDOMWindow*);
private:
// WebIDL
nsIDOMWindow* GetParentObject() const
{
return mWindow;
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void Reboot(ErrorResult& aRv);
void FactoryReset();
void PowerOff(ErrorResult& aRv);
void AddWakeLockListener(nsIDOMMozWakeLockListener* aListener);
void RemoveWakeLockListener(nsIDOMMozWakeLockListener* aListener);
void GetWakeLockState(const nsAString& aTopic, nsAString& aState,
ErrorResult& aRv);
bool ScreenEnabled();
void SetScreenEnabled(bool aEnabled);
double ScreenBrightness();
void SetScreenBrightness(double aBrightness, ErrorResult& aRv);
bool CpuSleepAllowed();
void SetCpuSleepAllowed(bool aAllowed);
nsWeakPtr mWindow;
private:
nsCOMPtr<nsIDOMWindow> mWindow;
nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener> > mListeners;
};

View File

@ -8,7 +8,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
TEST_DIRS += ['test']
XPIDL_SOURCES += [
'nsIDOMPowerManager.idl',
'nsIDOMWakeLock.idl',
'nsIDOMWakeLockListener.idl',
'nsIPowerManagerService.idl',
@ -17,6 +16,7 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'dom_power'
EXPORTS.mozilla.dom.power += [
'PowerManager.h',
'PowerManagerService.h',
'Types.h',
]

View File

@ -3,17 +3,16 @@
* 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 "nsISupports.idl"
interface nsIDOMMozWakeLockListener;
interface MozWakeLockListener;
/**
* This interface implements navigator.mozPower
*/
[scriptable, uuid(7b181fef-2757-4198-89a0-8c426b8439ea)]
interface nsIDOMMozPowerManager : nsISupports
interface MozPowerManager
{
[Throws]
void powerOff();
[Throws]
void reboot();
void factoryReset();
@ -23,8 +22,8 @@ interface nsIDOMMozPowerManager : nsISupports
* - locked but not visible
* - locked and visible
*/
void addWakeLockListener(in nsIDOMMozWakeLockListener aListener);
void removeWakeLockListener(in nsIDOMMozWakeLockListener aListener);
void addWakeLockListener(MozWakeLockListener aListener);
void removeWakeLockListener(MozWakeLockListener aListener);
/**
* Query the wake lock state of the topic.
@ -41,7 +40,8 @@ interface nsIDOMMozPowerManager : nsISupports
*
* @param aTopic The resource name related to the wake lock.
*/
DOMString getWakeLockState(in DOMString aTopic);
[Throws]
DOMString getWakeLockState(DOMString aTopic);
/**
* Is the device's screen currently enabled? This attribute controls the
@ -64,6 +64,7 @@ interface nsIDOMMozPowerManager : nsISupports
*
* @throw NS_ERROR_INVALID_ARG if brightness is not in the range [0, 1].
*/
[SetterThrows]
attribute double screenBrightness;
/**

View File

@ -17,7 +17,6 @@
* and create derivative works of this document.
*/
interface MozPowerManager;
interface MozWakeLock;
// http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object

View File

@ -211,6 +211,7 @@ WEBIDL_FILES = [
'MozActivity.webidl',
'MozMmsMessage.webidl',
'MozNamedAttrMap.webidl',
'MozPowerManager.webidl',
'MozTimeManager.webidl',
'MutationEvent.webidl',
'MutationObserver.webidl',