Bug 952079 - Porting nsIDOMWakeLock to WebIDL, r=smaug

This commit is contained in:
Andrea Marchesini 2014-01-07 13:16:07 +01:00
parent d7ed5ac1a8
commit 3b6ab3516b
25 changed files with 164 additions and 116 deletions

View File

@ -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<nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<WakeLock> mWakeLock;
/**
* Logs a warning message to the web console to report various failures.

View File

@ -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<nsIDOMMozWakeLock> mScreenWakeLock;
nsRefPtr<WakeLock> mScreenWakeLock;
private:
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,

View File

@ -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 <algorithm>
@ -2245,13 +2245,14 @@ void
HTMLMediaElement::WakeLockCreate()
{
if (!mWakeLock) {
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsRefPtr<power::PowerManagerService> 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;
}
}

View File

@ -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<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsRefPtr<power::PowerManagerService> 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);
}
}

View File

@ -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<nsIDOMMozWakeLock>
already_AddRefed<WakeLock>
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
{
if (!mWindow) {
@ -1139,15 +1139,14 @@ Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
return nullptr;
}
nsCOMPtr<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsRefPtr<power::PowerManagerService> 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<nsIDOMMozWakeLock> wakelock;
aRv = pmService->NewWakeLock(aTopic, mWindow, getter_AddRefs(wakelock));
return wakelock.forget();
ErrorResult rv;
return pmService->NewWakeLock(aTopic, mWindow, rv);
}
nsIDOMMozMobileMessageManager*

View File

@ -31,6 +31,7 @@ class Geolocation;
class systemMessageCallback;
class MediaStreamConstraints;
class MediaStreamConstraintsInternal;
class WakeLock;
}
}
@ -182,7 +183,7 @@ public:
}
void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
already_AddRefed<nsIDOMMozWakeLock> RequestWakeLock(const nsAString &aTopic,
already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
ErrorResult& aRv);
nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
ErrorResult& aRv);

View File

@ -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

View File

@ -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)

View File

@ -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<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsRefPtr<power::PowerManagerService> 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;
}

View File

@ -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 <nsIIdleService> mIdleService;
nsCOMPtr <nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<mozilla::dom::WakeLock> mWakeLock;
static bool sIdleObserversAPIFuzzTimeDisabled;

View File

@ -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')

View File

@ -83,6 +83,3 @@ interface nsIDOMPkcs11;
// Used font face (for inspector)
interface nsIDOMFontFace;
interface nsIDOMFontFaceList;
// Power
interface nsIDOMMozWakeLock;

View File

@ -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<SystemMessageHandledListener> kungFuDeathGrip = this;
mWakeLock->Unlock();
ErrorResult rv;
mWakeLock->Unlock(rv);
if (mTimer) {
mTimer->Cancel();
@ -759,7 +760,7 @@ private:
}
}
nsCOMPtr<nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<WakeLock> mWakeLock;
nsCOMPtr<nsITimer> mTimer;
};
@ -786,7 +787,7 @@ ContentParent::MaybeTakeCPUWakeLock(Element* aFrameElement)
}
nsRefPtr<PowerManagerService> pms = PowerManagerService::GetInstance();
nsCOMPtr<nsIDOMMozWakeLock> lock =
nsRefPtr<WakeLock> lock =
pms->NewWakeLockOnBehalfOfProcess(NS_LITERAL_STRING("cpu"), this);
// This object's Init() function keeps it alive.

View File

@ -205,22 +205,37 @@ PowerManagerService::GetWakeLockState(const nsAString &aTopic, nsAString &aState
return NS_OK;
}
already_AddRefed<WakeLock>
PowerManagerService::NewWakeLock(const nsAString& aTopic,
nsIDOMWindow* aWindow,
mozilla::ErrorResult& aRv)
{
nsRefPtr<WakeLock> 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> wakelock = new WakeLock();
nsresult rv = wakelock->Init(aTopic, aWindow);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMMozWakeLock> wl(wakelock);
wl.forget(aWakeLock);
mozilla::ErrorResult rv;
nsRefPtr<WakeLock> wakelock = NewWakeLock(aTopic, aWindow, rv);
if (rv.Failed()) {
return rv.ErrorCode();
}
nsCOMPtr<nsIDOMEventListener> eventListener = wakelock.get();
eventListener.forget(aWakeLock);
return NS_OK;
}
already_AddRefed<nsIDOMMozWakeLock>
already_AddRefed<WakeLock>
PowerManagerService::NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
ContentParent* aContentParent)
{

View File

@ -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<nsIDOMMozWakeLock>
already_AddRefed<WakeLock>
NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
ContentParent* aContentParent);
already_AddRefed<WakeLock>
NewWakeLock(const nsAString& aTopic, nsIDOMWindow* aWindow,
mozilla::ErrorResult& aRv);
private:
~PowerManagerService();

View File

@ -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<JSObject*> 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<nsPIDOMWindow> window = do_QueryInterface(mWindow);
return window;
}
} // dom
} // mozilla

View File

@ -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<JSObject*> 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

View File

@ -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 += [

View File

@ -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);
};

View File

@ -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.

View File

@ -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<nsIPowerManagerService> pmService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsRefPtr<power::PowerManagerService> 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);

View File

@ -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,9 +42,9 @@ private:
nsresult Init();
nsRefPtr<dom::WakeLock> mWakeLock;
nsString mVolumeName;
int32_t mVolumeGeneration;
nsCOMPtr<nsIDOMMozWakeLock> mWakeLock;
bool mUnlocked;
};

View File

@ -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();
};

View File

@ -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.
*

View File

@ -233,6 +233,7 @@ WEBIDL_FILES = [
'MozNamedAttrMap.webidl',
'MozPowerManager.webidl',
'MozTimeManager.webidl',
'MozWakeLock.webidl',
'MutationEvent.webidl',
'MutationObserver.webidl',
'NetDashboard.webidl',