Skip to content

Commit

Permalink
Bug 952079 - Porting nsIDOMWakeLock to WebIDL, r=smaug
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed Jan 7, 2014
1 parent 79c60e8 commit 62bd000
Show file tree
Hide file tree
Showing 25 changed files with 164 additions and 116 deletions.
3 changes: 2 additions & 1 deletion content/html/content/public/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class VideoFrameContainer;
namespace dom {
class TextTrack;
class TimeRanges;
class WakeLock;
}
}

Expand Down Expand Up @@ -588,7 +589,7 @@ class HTMLMediaElement : public nsGenericHTMLElement,
*/
virtual void WakeLockCreate();
virtual void WakeLockRelease();
nsCOMPtr<nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<WakeLock> mWakeLock;

/**
* Logs a warning message to the web console to report various failures.
Expand Down
3 changes: 2 additions & 1 deletion content/html/content/public/HTMLVideoElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace mozilla {
namespace dom {

class WakeLock;
class VideoPlaybackQuality;

class HTMLVideoElement MOZ_FINAL : public HTMLMediaElement,
Expand Down Expand Up @@ -115,7 +116,7 @@ class HTMLVideoElement MOZ_FINAL : public HTMLMediaElement,
virtual void WakeLockRelease();
void WakeLockUpdate();

nsCOMPtr<nsIDOMMozWakeLock> mScreenWakeLock;
nsRefPtr<WakeLock> mScreenWakeLock;

private:
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
Expand Down
19 changes: 11 additions & 8 deletions content/html/content/src/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -2245,21 +2245,24 @@ 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);
}
}

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;
}
}
Expand Down
19 changes: 11 additions & 8 deletions content/html/content/src/HTMLVideoElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

Expand Down
15 changes: 7 additions & 8 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1131,23 +1131,22 @@ Navigator::GetMozPower(ErrorResult& aRv)
return mPowerManager;
}

already_AddRefed<nsIDOMMozWakeLock>
already_AddRefed<WakeLock>
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
{
if (!mWindow) {
aRv.Throw(NS_ERROR_UNEXPECTED);
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*
Expand Down
5 changes: 3 additions & 2 deletions dom/base/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Geolocation;
class systemMessageCallback;
class MediaStreamConstraints;
class MediaStreamConstraintsInternal;
class WakeLock;
}
}

Expand Down Expand Up @@ -182,8 +183,8 @@ class Navigator : public nsIDOMNavigator
}
void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
already_AddRefed<nsIDOMMozWakeLock> RequestWakeLock(const nsAString &aTopic,
ErrorResult& aRv);
already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
ErrorResult& aRv);
nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
ErrorResult& aRv);
void GetDeviceStorages(const nsAString& aType,
Expand Down
8 changes: 0 additions & 8 deletions dom/base/nsDOMClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"

#include "nsIDOMWakeLock.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMMozMmsMessage.h"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions dom/base/nsDOMClassInfoClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsGlobalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class nsICSSDeclaration;
class nsIDocShellTreeOwner;
class nsIDOMCrypto;
class nsIDOMOfflineResourceList;
class nsIDOMMozWakeLock;
class nsIScrollableFrame;
class nsIControllers;
class nsIScriptContext;
Expand Down Expand Up @@ -112,6 +111,7 @@ class Gamepad;
class MediaQueryList;
class Navigator;
class SpeechSynthesis;
class WakeLock;
namespace indexedDB {
class IDBFactory;
} // namespace indexedDB
Expand Down Expand Up @@ -972,7 +972,7 @@ class nsGlobalWindow : public mozilla::dom::EventTarget,

nsCOMPtr <nsIIdleService> mIdleService;

nsCOMPtr <nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<mozilla::dom::WakeLock> mWakeLock;

static bool sIdleObserversAPIFuzzTimeDisabled;

Expand Down
5 changes: 4 additions & 1 deletion dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ DOMInterfaces = {
'nativeType': 'mozilla::dom::PowerManager',
},

'MozWakeLock': {
'nativeType': 'mozilla::dom::WakeLock',
},

'MozTimeManager': {
'nativeType': 'mozilla::dom::time::TimeManager',
},
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 0 additions & 3 deletions dom/interfaces/base/domstubs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,3 @@ interface nsIDOMPkcs11;
// Used font face (for inspector)
interface nsIDOMFontFace;
interface nsIDOMFontFaceList;

// Power
interface nsIDOMMozWakeLock;
11 changes: 6 additions & 5 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -713,7 +713,7 @@ class SystemMessageHandledListener MOZ_FINAL
listener->ShutDown();
}

void Init(nsIDOMMozWakeLock* aWakeLock)
void Init(WakeLock* aWakeLock)
{
MOZ_ASSERT(!mWakeLock);
MOZ_ASSERT(!mTimer);
Expand Down Expand Up @@ -751,15 +751,16 @@ class SystemMessageHandledListener MOZ_FINAL
{
nsRefPtr<SystemMessageHandledListener> kungFuDeathGrip = this;

mWakeLock->Unlock();
ErrorResult rv;
mWakeLock->Unlock(rv);

if (mTimer) {
mTimer->Cancel();
mTimer = nullptr;
}
}

nsCOMPtr<nsIDOMMozWakeLock> mWakeLock;
nsRefPtr<WakeLock> mWakeLock;
nsCOMPtr<nsITimer> mTimer;
};

Expand All @@ -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.
Expand Down
Loading

0 comments on commit 62bd000

Please sign in to comment.