forked from mirrors/gecko-dev
Bug 1492736 - Part 1. Add nsIWakeLock to manage wake lock from devtools. r=baku
DevTools wants to use wake lock to keep screen. But since MozWakeLock is removed by bug 1369194, there is no way to unlock wake lock from script. So this issue adds nsIWakeLock to unlock wake lock. Differential Revision: https://phabricator.services.mozilla.com/D7158 --HG-- extra : rebase_source : 4d6069fce27a7d85ce484a1418a8a17de83166f1
This commit is contained in:
parent
d6f4b6f2ba
commit
a10b8df4d2
8 changed files with 57 additions and 4 deletions
|
|
@ -139,7 +139,7 @@ PowerManagerService::NewWakeLock(const nsAString& aTopic,
|
|||
NS_IMETHODIMP
|
||||
PowerManagerService::NewWakeLock(const nsAString &aTopic,
|
||||
mozIDOMWindow *aWindow,
|
||||
nsISupports **aWakeLock)
|
||||
nsIWakeLock **aWakeLock)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
RefPtr<WakeLock> wakelock =
|
||||
|
|
@ -148,8 +148,7 @@ PowerManagerService::NewWakeLock(const nsAString &aTopic,
|
|||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> eventListener = wakelock.get();
|
||||
eventListener.forget(aWakeLock);
|
||||
wakelock.forget(aWakeLock);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ NS_INTERFACE_MAP_BEGIN(WakeLock)
|
|||
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWakeLock)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(WakeLock)
|
||||
|
|
@ -258,6 +259,14 @@ WakeLock::HandleEvent(Event *aEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
WakeLock::Unlock()
|
||||
{
|
||||
ErrorResult error;
|
||||
Unlock(error);
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner*
|
||||
WakeLock::GetParentObject() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIWakeLock.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
|
@ -26,10 +27,12 @@ class WakeLock final
|
|||
: public nsIDOMEventListener
|
||||
, public nsIObserver
|
||||
, public nsSupportsWeakReference
|
||||
, public nsIWakeLock
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIWAKELOCK
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ with Files("**"):
|
|||
XPIDL_SOURCES += [
|
||||
'nsIDOMWakeLockListener.idl',
|
||||
'nsIPowerManagerService.idl',
|
||||
'nsIWakeLock.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom_power'
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
interface nsIDOMMozWakeLockListener;
|
||||
interface mozIDOMWindow;
|
||||
interface nsIWakeLock;
|
||||
|
||||
/**
|
||||
* For use with non-content code.
|
||||
|
|
@ -28,5 +29,5 @@ interface nsIPowerManagerService : nsISupports
|
|||
* A wake lock without associated window, e.g. used in chrome, is
|
||||
* always considered invisible.
|
||||
*/
|
||||
nsISupports newWakeLock(in AString aTopic, [optional] in mozIDOMWindow aWindow);
|
||||
nsIWakeLock newWakeLock(in AString aTopic, [optional] in mozIDOMWindow aWindow);
|
||||
};
|
||||
|
|
|
|||
12
dom/power/nsIWakeLock.idl
Normal file
12
dom/power/nsIWakeLock.idl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(e27e57ce-fa63-4035-b9ef-27c5dc0cc3ae)]
|
||||
interface nsIWakeLock : nsISupports
|
||||
{
|
||||
void unlock();
|
||||
};
|
||||
|
|
@ -81,3 +81,4 @@ support-files =
|
|||
[browser_noopener_null_uri.js]
|
||||
[browser_test_performance_metrics_off.js]
|
||||
skip-if = verify
|
||||
[browser_wakelock.js]
|
||||
|
|
|
|||
27
dom/tests/browser/browser_wakelock.js
Normal file
27
dom/tests/browser/browser_wakelock.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async () => {
|
||||
info("creating test window");
|
||||
let win = await BrowserTestUtils.openNewBrowserWindow();
|
||||
|
||||
const pm = Cc["@mozilla.org/power/powermanagerservice;1"]
|
||||
.getService(Ci.nsIPowerManagerService);
|
||||
|
||||
is(pm.getWakeLockState("screen"), "unlocked", "Wakelock should be unlocked state");
|
||||
|
||||
info("aquiring wakelock");
|
||||
const wakelock = pm.newWakeLock("screen", win);
|
||||
isnot(pm.getWakeLockState("screen"), "unlocked", "Wakelock shouldn't be unlocked state");
|
||||
|
||||
info("releasing wakelock");
|
||||
wakelock.unlock();
|
||||
is(pm.getWakeLockState("screen"), "unlocked", "Wakelock should be unlocked state");
|
||||
|
||||
info("closing test window");
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
Loading…
Reference in a new issue