diff --git a/content/html/content/public/HTMLMediaElement.h b/content/html/content/public/HTMLMediaElement.h
index 7bcb547493f..7791da16210 100644
--- a/content/html/content/public/HTMLMediaElement.h
+++ b/content/html/content/public/HTMLMediaElement.h
@@ -39,6 +39,7 @@ class VideoFrameContainer;
namespace dom {
class TextTrack;
class TimeRanges;
+class WakeLock;
}
}
@@ -588,7 +589,7 @@ protected:
*/
virtual void WakeLockCreate();
virtual void WakeLockRelease();
- nsCOMPtr mWakeLock;
+ nsRefPtr mWakeLock;
/**
* Logs a warning message to the web console to report various failures.
diff --git a/content/html/content/public/HTMLVideoElement.h b/content/html/content/public/HTMLVideoElement.h
index 283e08e6f0a..133b7c1297f 100644
--- a/content/html/content/public/HTMLVideoElement.h
+++ b/content/html/content/public/HTMLVideoElement.h
@@ -14,6 +14,7 @@
namespace mozilla {
namespace dom {
+class WakeLock;
class VideoPlaybackQuality;
class HTMLVideoElement MOZ_FINAL : public HTMLMediaElement,
@@ -115,7 +116,7 @@ protected:
virtual void WakeLockRelease();
void WakeLockUpdate();
- nsCOMPtr mScreenWakeLock;
+ nsRefPtr mScreenWakeLock;
private:
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
diff --git a/content/html/content/src/HTMLMediaElement.cpp b/content/html/content/src/HTMLMediaElement.cpp
index 95fe7f24cfd..ff1dcff3aa2 100644
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -75,10 +75,10 @@
#include "nsCSSParser.h"
#include "nsIMediaList.h"
-#include "nsIDOMWakeLock.h"
+#include "mozilla/dom/power/PowerManagerService.h"
+#include "mozilla/dom/WakeLock.h"
#include "ImageContainer.h"
-#include "nsIPowerManagerService.h"
#include "nsRange.h"
#include
@@ -2245,13 +2245,14 @@ void
HTMLMediaElement::WakeLockCreate()
{
if (!mWakeLock) {
- nsCOMPtr pmService =
- do_GetService(POWERMANAGERSERVICE_CONTRACTID);
+ nsRefPtr pmService =
+ power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);
- pmService->NewWakeLock(NS_LITERAL_STRING("cpu"),
- OwnerDoc()->GetWindow(),
- getter_AddRefs(mWakeLock));
+ ErrorResult rv;
+ mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("cpu"),
+ OwnerDoc()->GetInnerWindow(),
+ rv);
}
}
@@ -2259,7 +2260,9 @@ void
HTMLMediaElement::WakeLockRelease()
{
if (mWakeLock) {
- mWakeLock->Unlock();
+ ErrorResult rv;
+ mWakeLock->Unlock(rv);
+ NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
mWakeLock = nullptr;
}
}
diff --git a/content/html/content/src/HTMLVideoElement.cpp b/content/html/content/src/HTMLVideoElement.cpp
index 1bc49191876..0d096acc8f9 100644
--- a/content/html/content/src/HTMLVideoElement.cpp
+++ b/content/html/content/src/HTMLVideoElement.cpp
@@ -27,11 +27,11 @@
#include "nsEventDispatcher.h"
#include "nsIDOMProgressEvent.h"
-#include "nsIPowerManagerService.h"
#include "MediaError.h"
#include "MediaDecoder.h"
#include "mozilla/Preferences.h"
-#include "nsIDOMWakeLock.h"
+#include "mozilla/dom/WakeLock.h"
+#include "mozilla/dom/power/PowerManagerService.h"
#include "nsPerformance.h"
#include "mozilla/dom/VideoPlaybackQuality.h"
@@ -302,19 +302,22 @@ HTMLVideoElement::WakeLockUpdate()
bool hidden = OwnerDoc()->Hidden();
if (mScreenWakeLock && (mPaused || hidden)) {
- mScreenWakeLock->Unlock();
+ ErrorResult rv;
+ mScreenWakeLock->Unlock(rv);
+ NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
mScreenWakeLock = nullptr;
return;
}
if (!mScreenWakeLock && !mPaused && !hidden) {
- nsCOMPtr pmService =
- do_GetService(POWERMANAGERSERVICE_CONTRACTID);
+ nsRefPtr pmService =
+ power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);
- pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
- OwnerDoc()->GetWindow(),
- getter_AddRefs(mScreenWakeLock));
+ ErrorResult rv;
+ mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
+ OwnerDoc()->GetInnerWindow(),
+ rv);
}
}
diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp
index fcacef59630..2c28b10cc5d 100644
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -26,8 +26,8 @@
#include "mozilla/Telemetry.h"
#include "BatteryManager.h"
#include "mozilla/dom/PowerManager.h"
-#include "nsIDOMWakeLock.h"
-#include "nsIPowerManagerService.h"
+#include "mozilla/dom/WakeLock.h"
+#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/MobileMessageManager.h"
#include "mozilla/dom/Telephony.h"
#include "mozilla/Hal.h"
@@ -1131,7 +1131,7 @@ Navigator::GetMozPower(ErrorResult& aRv)
return mPowerManager;
}
-already_AddRefed
+already_AddRefed
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
{
if (!mWindow) {
@@ -1139,15 +1139,14 @@ Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
return nullptr;
}
- nsCOMPtr pmService =
- do_GetService(POWERMANAGERSERVICE_CONTRACTID);
+ nsRefPtr pmService =
+ power::PowerManagerService::GetInstance();
// Maybe it went away for some reason... Or maybe we're just called
// from our XPCOM method.
NS_ENSURE_TRUE(pmService, nullptr);
- nsCOMPtr wakelock;
- aRv = pmService->NewWakeLock(aTopic, mWindow, getter_AddRefs(wakelock));
- return wakelock.forget();
+ ErrorResult rv;
+ return pmService->NewWakeLock(aTopic, mWindow, rv);
}
nsIDOMMozMobileMessageManager*
diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h
index 282b3c51bd6..9a05a7cf29a 100644
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -31,6 +31,7 @@ class Geolocation;
class systemMessageCallback;
class MediaStreamConstraints;
class MediaStreamConstraintsInternal;
+class WakeLock;
}
}
@@ -182,8 +183,8 @@ public:
}
void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
- already_AddRefed RequestWakeLock(const nsAString &aTopic,
- ErrorResult& aRv);
+ already_AddRefed RequestWakeLock(const nsAString &aTopic,
+ ErrorResult& aRv);
nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
ErrorResult& aRv);
void GetDeviceStorages(const nsAString& aType,
diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp
index a43053894e2..fe4e30f75a5 100644
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -148,7 +148,6 @@
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"
-#include "nsIDOMWakeLock.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMMozMmsMessage.h"
@@ -436,9 +435,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS)
- NS_DEFINE_CLASSINFO_DATA(MozWakeLock, nsDOMGenericSH,
- DOM_DEFAULT_SCRIPTABLE_FLAGS)
-
NS_DEFINE_CLASSINFO_DATA(MozMobileMessageManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -1127,10 +1123,6 @@ nsDOMClassInfo::Init()
#endif
DOM_CLASSINFO_MAP_END
- DOM_CLASSINFO_MAP_BEGIN(MozWakeLock, nsIDOMMozWakeLock)
- DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozWakeLock)
- DOM_CLASSINFO_MAP_END
-
DOM_CLASSINFO_MAP_BEGIN(MozMobileMessageManager, nsIDOMMozMobileMessageManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozMobileMessageManager)
DOM_CLASSINFO_MAP_END
diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h
index c88a8252ba1..b9e603329d5 100644
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -77,8 +77,6 @@ DOMCI_CLASS(File)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)
-DOMCI_CLASS(MozWakeLock)
-
DOMCI_CLASS(MozMobileMessageManager)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozMmsMessage)
diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp
index 9145301449d..891504f4dc2 100644
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -22,13 +22,13 @@
#include "nsDOMOfflineResourceList.h"
#include "nsError.h"
#include "nsIIdleService.h"
-#include "nsIPowerManagerService.h"
#include "nsISizeOfEventTarget.h"
#include "nsDOMJSUtils.h"
#include "nsArrayUtils.h"
#include "nsIDOMWindowCollection.h"
#include "nsDOMWindowList.h"
-#include "nsIDOMWakeLock.h"
+#include "mozilla/dom/WakeLock.h"
+#include "mozilla/dom/power/PowerManagerService.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIPermissionManager.h"
#include "nsIScriptContext.h"
@@ -5698,13 +5698,21 @@ nsGlobalWindow::SetFullScreenInternal(bool aFullScreen, bool aRequireTrust)
}
if (!mWakeLock && mFullScreen) {
- nsCOMPtr pmService =
- do_GetService(POWERMANAGERSERVICE_CONTRACTID);
+ nsRefPtr pmService =
+ power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE(pmService, NS_OK);
- pmService->NewWakeLock(NS_LITERAL_STRING("DOM_Fullscreen"), this, getter_AddRefs(mWakeLock));
+ ErrorResult rv;
+ mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("DOM_Fullscreen"),
+ this, rv);
+ if (rv.Failed()) {
+ return rv.ErrorCode();
+ }
+
} else if (mWakeLock && !mFullScreen) {
- mWakeLock->Unlock();
+ ErrorResult rv;
+ mWakeLock->Unlock(rv);
+ NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
mWakeLock = nullptr;
}
diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h
index c66bc75a596..cb12ec72f77 100644
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -82,7 +82,6 @@ class nsICSSDeclaration;
class nsIDocShellTreeOwner;
class nsIDOMCrypto;
class nsIDOMOfflineResourceList;
-class nsIDOMMozWakeLock;
class nsIScrollableFrame;
class nsIControllers;
class nsIScriptContext;
@@ -112,6 +111,7 @@ class Gamepad;
class MediaQueryList;
class Navigator;
class SpeechSynthesis;
+class WakeLock;
namespace indexedDB {
class IDBFactory;
} // namespace indexedDB
@@ -972,7 +972,7 @@ protected:
nsCOMPtr mIdleService;
- nsCOMPtr mWakeLock;
+ nsRefPtr mWakeLock;
static bool sIdleObserversAPIFuzzTimeDisabled;
diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf
index cb10ebe1f4f..9ba517bbe7f 100644
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -822,6 +822,10 @@ DOMInterfaces = {
'nativeType': 'mozilla::dom::PowerManager',
},
+'MozWakeLock': {
+ 'nativeType': 'mozilla::dom::WakeLock',
+},
+
'MozTimeManager': {
'nativeType': 'mozilla::dom::time::TimeManager',
},
@@ -1896,7 +1900,6 @@ addExternalIface('MozTreeBoxObject', nativeType='nsITreeBoxObject',
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')
diff --git a/dom/interfaces/base/domstubs.idl b/dom/interfaces/base/domstubs.idl
index db6156f1eaf..0f93e0e3ccd 100644
--- a/dom/interfaces/base/domstubs.idl
+++ b/dom/interfaces/base/domstubs.idl
@@ -83,6 +83,3 @@ interface nsIDOMPkcs11;
// Used font face (for inspector)
interface nsIDOMFontFace;
interface nsIDOMFontFaceList;
-
-// Power
-interface nsIDOMMozWakeLock;
diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp
index 855bfbf8781..5cbbf75a23c 100644
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -64,7 +64,7 @@
#include "nsIAppsService.h"
#include "nsIClipboard.h"
#include "nsIDOMGeoGeolocation.h"
-#include "nsIDOMWakeLock.h"
+#include "mozilla/dom/WakeLock.h"
#include "nsIDOMWindow.h"
#include "nsIExternalProtocolService.h"
#include "nsIFilePicker.h"
@@ -713,7 +713,7 @@ public:
listener->ShutDown();
}
- void Init(nsIDOMMozWakeLock* aWakeLock)
+ void Init(WakeLock* aWakeLock)
{
MOZ_ASSERT(!mWakeLock);
MOZ_ASSERT(!mTimer);
@@ -751,7 +751,8 @@ private:
{
nsRefPtr kungFuDeathGrip = this;
- mWakeLock->Unlock();
+ ErrorResult rv;
+ mWakeLock->Unlock(rv);
if (mTimer) {
mTimer->Cancel();
@@ -759,7 +760,7 @@ private:
}
}
- nsCOMPtr mWakeLock;
+ nsRefPtr mWakeLock;
nsCOMPtr mTimer;
};
@@ -786,7 +787,7 @@ ContentParent::MaybeTakeCPUWakeLock(Element* aFrameElement)
}
nsRefPtr pms = PowerManagerService::GetInstance();
- nsCOMPtr lock =
+ nsRefPtr lock =
pms->NewWakeLockOnBehalfOfProcess(NS_LITERAL_STRING("cpu"), this);
// This object's Init() function keeps it alive.
diff --git a/dom/power/PowerManagerService.cpp b/dom/power/PowerManagerService.cpp
index 84eb5125512..c506c0c69c2 100644
--- a/dom/power/PowerManagerService.cpp
+++ b/dom/power/PowerManagerService.cpp
@@ -205,22 +205,37 @@ PowerManagerService::GetWakeLockState(const nsAString &aTopic, nsAString &aState
return NS_OK;
}
+already_AddRefed
+PowerManagerService::NewWakeLock(const nsAString& aTopic,
+ nsIDOMWindow* aWindow,
+ mozilla::ErrorResult& aRv)
+{
+ nsRefPtr wakelock = new WakeLock();
+ aRv = wakelock->Init(aTopic, aWindow);
+ if (aRv.Failed()) {
+ return nullptr;
+ }
+
+ return wakelock.forget();
+}
+
NS_IMETHODIMP
PowerManagerService::NewWakeLock(const nsAString &aTopic,
nsIDOMWindow *aWindow,
- nsIDOMMozWakeLock **aWakeLock)
+ nsISupports **aWakeLock)
{
- nsRefPtr wakelock = new WakeLock();
- nsresult rv = wakelock->Init(aTopic, aWindow);
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr wl(wakelock);
- wl.forget(aWakeLock);
+ mozilla::ErrorResult rv;
+ nsRefPtr wakelock = NewWakeLock(aTopic, aWindow, rv);
+ if (rv.Failed()) {
+ return rv.ErrorCode();
+ }
+ nsCOMPtr eventListener = wakelock.get();
+ eventListener.forget(aWakeLock);
return NS_OK;
}
-already_AddRefed
+already_AddRefed
PowerManagerService::NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
ContentParent* aContentParent)
{
diff --git a/dom/power/PowerManagerService.h b/dom/power/PowerManagerService.h
index 7eae5f9e859..51a0660bb72 100644
--- a/dom/power/PowerManagerService.h
+++ b/dom/power/PowerManagerService.h
@@ -13,6 +13,7 @@
#include "mozilla/Observer.h"
#include "Types.h"
#include "mozilla/StaticPtr.h"
+#include "mozilla/dom/WakeLock.h"
namespace mozilla {
namespace dom {
@@ -48,10 +49,14 @@ public:
* - The /given/ process shows up in WakeLockInfo::lockingProcesses.
*
*/
- already_AddRefed
+ already_AddRefed
NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
ContentParent* aContentParent);
+ already_AddRefed
+ NewWakeLock(const nsAString& aTopic, nsIDOMWindow* aWindow,
+ mozilla::ErrorResult& aRv);
+
private:
~PowerManagerService();
diff --git a/dom/power/WakeLock.cpp b/dom/power/WakeLock.cpp
index aa5442ef31c..b923aee808d 100644
--- a/dom/power/WakeLock.cpp
+++ b/dom/power/WakeLock.cpp
@@ -5,9 +5,9 @@
#include "WakeLock.h"
#include "mozilla/dom/ContentParent.h"
+#include "mozilla/dom/MozWakeLockBinding.h"
#include "mozilla/Hal.h"
#include "mozilla/HalWakeLock.h"
-#include "nsDOMClassInfoID.h"
#include "nsDOMEvent.h"
#include "nsError.h"
#include "nsIDocument.h"
@@ -16,31 +16,29 @@
#include "nsPIDOMWindow.h"
#include "nsIPropertyBag2.h"
-DOMCI_DATA(MozWakeLock, mozilla::dom::power::WakeLock)
-
using namespace mozilla::hal;
namespace mozilla {
namespace dom {
-namespace power {
-NS_INTERFACE_MAP_BEGIN(WakeLock)
- NS_INTERFACE_MAP_ENTRY(nsIDOMMozWakeLock)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozWakeLock)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WakeLock)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WakeLock)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
- NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozWakeLock)
NS_INTERFACE_MAP_END
-NS_IMPL_ADDREF(WakeLock)
-NS_IMPL_RELEASE(WakeLock)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(WakeLock)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(WakeLock)
WakeLock::WakeLock()
: mLocked(false)
, mHidden(true)
, mContentParentID(CONTENT_PROCESS_ID_UNKNOWN)
{
+ SetIsDOMBinding();
}
WakeLock::~WakeLock()
@@ -49,6 +47,12 @@ WakeLock::~WakeLock()
DetachEventListener();
}
+JSObject*
+WakeLock::WrapObject(JSContext* aCx, JS::Handle aScope)
+{
+ return MozWakeLockBinding::Wrap(aCx, aScope, this);
+}
+
nsresult
WakeLock::Init(const nsAString &aTopic, nsIDOMWindow *aWindow)
{
@@ -212,27 +216,25 @@ WakeLock::DetachEventListener()
}
}
-NS_IMETHODIMP
-WakeLock::Unlock()
+void
+WakeLock::Unlock(ErrorResult& aRv)
{
/*
* We throw NS_ERROR_DOM_INVALID_STATE_ERR on double unlock.
*/
if (!mLocked) {
- return NS_ERROR_DOM_INVALID_STATE_ERR;
+ aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+ return;
}
DoUnlock();
DetachEventListener();
-
- return NS_OK;
}
-NS_IMETHODIMP
+void
WakeLock::GetTopic(nsAString &aTopic)
{
aTopic.Assign(mTopic);
- return NS_OK;
}
NS_IMETHODIMP
@@ -272,6 +274,12 @@ WakeLock::HandleEvent(nsIDOMEvent *aEvent)
return NS_OK;
}
-} // power
+nsISupports*
+WakeLock::GetParentObject() const
+{
+ nsCOMPtr window = do_QueryInterface(mWindow);
+ return window;
+}
+
} // dom
} // mozilla
diff --git a/dom/power/WakeLock.h b/dom/power/WakeLock.h
index 410790c6cf4..aa5666b2755 100644
--- a/dom/power/WakeLock.h
+++ b/dom/power/WakeLock.h
@@ -7,11 +7,12 @@
#define mozilla_dom_power_WakeLock_h
#include "nsCOMPtr.h"
-#include "nsIDOMWakeLock.h"
#include "nsIDOMEventListener.h"
#include "nsIObserver.h"
#include "nsString.h"
#include "nsWeakReference.h"
+#include "nsWrapperCache.h"
+#include "mozilla/ErrorResult.h"
class nsIDOMWindow;
@@ -20,20 +21,19 @@ namespace dom {
class ContentParent;
-namespace power {
-
-class WakeLock
- : public nsIDOMMozWakeLock
- , public nsIDOMEventListener
+class WakeLock MOZ_FINAL
+ : public nsIDOMEventListener
+ , public nsWrapperCache
, public nsIObserver
, public nsSupportsWeakReference
{
public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIDOMMOZWAKELOCK
NS_DECL_NSIDOMEVENTLISTENER
NS_DECL_NSIOBSERVER
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WakeLock, nsIDOMEventListener)
+
// Note: WakeLock lives for the lifetime of the document in order to avoid
// exposing GC behavior to pages. This means that
// |var foo = navigator.requestWakeLock('cpu'); foo = null;|
@@ -52,6 +52,17 @@ public:
// always considered visible.
nsresult Init(const nsAString &aTopic, ContentParent* aContentParent);
+ // WebIDL methods
+
+ nsISupports* GetParentObject() const;
+
+ virtual JSObject*
+ WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE;
+
+ void GetTopic(nsAString& aTopic);
+
+ void Unlock(ErrorResult& aRv);
+
private:
void DoUnlock();
void DoLock();
@@ -71,7 +82,6 @@ private:
nsWeakPtr mWindow;
};
-} // namespace power
} // namespace dom
} // namespace mozilla
diff --git a/dom/power/moz.build b/dom/power/moz.build
index 7e4b41ae69b..0f17275d7cd 100644
--- a/dom/power/moz.build
+++ b/dom/power/moz.build
@@ -8,7 +8,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
TEST_DIRS += ['test']
XPIDL_SOURCES += [
- 'nsIDOMWakeLock.idl',
'nsIDOMWakeLockListener.idl',
'nsIPowerManagerService.idl',
]
@@ -17,6 +16,7 @@ XPIDL_MODULE = 'dom_power'
EXPORTS.mozilla.dom += [
'PowerManager.h',
+ 'WakeLock.h',
]
EXPORTS.mozilla.dom.power += [
diff --git a/dom/power/nsIPowerManagerService.idl b/dom/power/nsIPowerManagerService.idl
index f06077f5621..9ff4da4a8c3 100644
--- a/dom/power/nsIPowerManagerService.idl
+++ b/dom/power/nsIPowerManagerService.idl
@@ -10,7 +10,6 @@
#define POWERMANAGERSERVICE_CONTRACTID "@mozilla.org/power/powermanagerservice;1"
%}
-interface nsIDOMMozWakeLock;
interface nsIDOMMozWakeLockListener;
interface nsIDOMWindow;
@@ -40,9 +39,9 @@ interface nsIPowerManagerService : nsISupports
DOMString getWakeLockState(in DOMString aTopic);
/**
- * Return a wake lock object of aTopic associated with aWindow.
+ * Return a wake lock (MozWakeLock) object of aTopic associated with aWindow.
* A wake lock without associated window, e.g. used in chrome, is
* always considered invisible.
*/
- nsIDOMMozWakeLock newWakeLock(in DOMString aTopic, [optional] in nsIDOMWindow aWindow);
+ nsISupports newWakeLock(in DOMString aTopic, [optional] in nsIDOMWindow aWindow);
};
diff --git a/dom/system/gonk/nsIVolume.idl b/dom/system/gonk/nsIVolume.idl
index a1abc686675..6cb47d0703f 100644
--- a/dom/system/gonk/nsIVolume.idl
+++ b/dom/system/gonk/nsIVolume.idl
@@ -39,7 +39,7 @@ interface nsIVolume : nsISupports
readonly attribute long mountGeneration;
// While a volume is mounted, it can be locked, preventing it from being
- // shared with the PC. To lock a volume, acquire an nsIDOMMozWakeLock
+ // shared with the PC. To lock a volume, acquire an MozWakeLock
// using the name of this attribute. Note that mountLockName changes
// every time the mountGeneration changes, so you'll need to reacquire
// the wakelock every time the volume becomes mounted.
diff --git a/dom/system/gonk/nsVolumeMountLock.cpp b/dom/system/gonk/nsVolumeMountLock.cpp
index a50d567ca83..f3917a7ab4d 100644
--- a/dom/system/gonk/nsVolumeMountLock.cpp
+++ b/dom/system/gonk/nsVolumeMountLock.cpp
@@ -17,6 +17,7 @@
#define VOLUME_MANAGER_LOG_TAG "nsVolumeMountLock"
#include "VolumeManagerLog.h"
#include "nsServiceManagerUtils.h"
+#include "mozilla/dom/power/PowerManagerService.h"
using namespace mozilla::dom;
using namespace mozilla::services;
@@ -141,14 +142,18 @@ NS_IMETHODIMP nsVolumeMountLock::Observe(nsISupports* aSubject, const char* aTop
mWakeLock = nullptr;
mVolumeGeneration = mountGeneration;
- nsCOMPtr pmService =
- do_GetService(POWERMANAGERSERVICE_CONTRACTID);
+ nsRefPtr pmService =
+ power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE(pmService, NS_ERROR_FAILURE);
nsString mountLockName;
vol->GetMountLockName(mountLockName);
- rv = pmService->NewWakeLock(mountLockName, nullptr, getter_AddRefs(mWakeLock));
- NS_ENSURE_SUCCESS(rv, rv);
+
+ ErrorResult err;
+ mWakeLock = pmService->NewWakeLock(mountLockName, nullptr, err);
+ if (err.Failed()) {
+ return err.ErrorCode();
+ }
LOG("nsVolumeMountLock acquired for '%s' gen %d",
NS_LossyConvertUTF16toASCII(mVolumeName).get(), mVolumeGeneration);
diff --git a/dom/system/gonk/nsVolumeMountLock.h b/dom/system/gonk/nsVolumeMountLock.h
index c760c5346ae..b907f950388 100644
--- a/dom/system/gonk/nsVolumeMountLock.h
+++ b/dom/system/gonk/nsVolumeMountLock.h
@@ -7,10 +7,11 @@
#include "nsIVolumeMountLock.h"
-#include "nsIDOMWakeLock.h"
+#include "mozilla/dom/WakeLock.h"
#include "nsIObserver.h"
#include "nsString.h"
#include "nsTArray.h"
+#include "nsAutoPtr.h"
#include "nsWeakReference.h"
namespace mozilla {
@@ -41,10 +42,10 @@ private:
nsresult Init();
- nsString mVolumeName;
- int32_t mVolumeGeneration;
- nsCOMPtr mWakeLock;
- bool mUnlocked;
+ nsRefPtr mWakeLock;
+ nsString mVolumeName;
+ int32_t mVolumeGeneration;
+ bool mUnlocked;
};
} // namespace system
diff --git a/dom/power/nsIDOMWakeLock.idl b/dom/webidl/MozWakeLock.webidl
similarity index 52%
rename from dom/power/nsIDOMWakeLock.idl
rename to dom/webidl/MozWakeLock.webidl
index c83ebd61383..5969e8af0a5 100644
--- a/dom/power/nsIDOMWakeLock.idl
+++ b/dom/webidl/MozWakeLock.webidl
@@ -1,19 +1,18 @@
-/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
+ * 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"
-
-[scriptable, uuid(2e61eed1-5983-4562-8f26-fd361ab4a00d)]
-interface nsIDOMMozWakeLock : nsISupports
+[Func="Navigator::HasWakeLockSupport"]
+interface MozWakeLock
{
readonly attribute DOMString topic;
/**
* Release the wake lock.
- *
* @throw NS_ERROR_DOM_INVALID_STATE_ERR if already unlocked.
*/
+ [Throws]
void unlock();
};
diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl
index ba12afb796e..a95c3c891fe 100644
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -17,8 +17,6 @@
* and create derivative works of this document.
*/
-interface MozWakeLock;
-
// http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object
[HeaderFile="Navigator.h", NeedNewResolve]
interface Navigator {
@@ -193,7 +191,7 @@ partial interface Navigator {
* One topic can be locked multiple times; it is considered released only when
* all locks on the topic have been released.
*
- * The returned nsIDOMMozWakeLock object is a token of the lock. You can
+ * The returned MozWakeLock object is a token of the lock. You can
* unlock the lock via the object's |unlock| method. The lock is released
* automatically when its associated window is unloaded.
*
diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build
index 039b51c4ab8..5571d05faba 100644
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -233,6 +233,7 @@ WEBIDL_FILES = [
'MozNamedAttrMap.webidl',
'MozPowerManager.webidl',
'MozTimeManager.webidl',
+ 'MozWakeLock.webidl',
'MutationEvent.webidl',
'MutationObserver.webidl',
'NetDashboard.webidl',