diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/server/actors/device.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/device.js')
-rw-r--r-- | devtools/server/actors/device.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/devtools/server/actors/device.js b/devtools/server/actors/device.js new file mode 100644 index 0000000000..7daba432da --- /dev/null +++ b/devtools/server/actors/device.js @@ -0,0 +1,74 @@ +/* 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/. */ + +"use strict"; + +const protocol = require("resource://devtools/shared/protocol.js"); + +const { + DevToolsServer, +} = require("resource://devtools/server/devtools-server.js"); +const { getSystemInfo } = require("resource://devtools/shared/system.js"); +const { deviceSpec } = require("resource://devtools/shared/specs/device.js"); +const { AppConstants } = ChromeUtils.importESModule( + "resource://gre/modules/AppConstants.sys.mjs" +); + +exports.DeviceActor = protocol.ActorClassWithSpec(deviceSpec, { + initialize(conn) { + protocol.Actor.prototype.initialize.call(this, conn); + // pageshow and pagehide event release wake lock, so we have to acquire + // wake lock again by pageshow event + this._onPageShow = this._onPageShow.bind(this); + if (this._window) { + this._window.addEventListener("pageshow", this._onPageShow, true); + } + this._acquireWakeLock(); + }, + + destroy() { + protocol.Actor.prototype.destroy.call(this); + this._releaseWakeLock(); + if (this._window) { + this._window.removeEventListener("pageshow", this._onPageShow, true); + } + }, + + getDescription() { + return Object.assign({}, getSystemInfo(), { + canDebugServiceWorkers: true, + }); + }, + + _acquireWakeLock() { + if (AppConstants.platform !== "android") { + return; + } + + const pm = Cc["@mozilla.org/power/powermanagerservice;1"].getService( + Ci.nsIPowerManagerService + ); + this._wakelock = pm.newWakeLock("screen", this._window); + }, + + _releaseWakeLock() { + if (this._wakelock) { + try { + this._wakelock.unlock(); + } catch (e) { + // Ignore error since wake lock is already unlocked + } + this._wakelock = null; + } + }, + + _onPageShow() { + this._releaseWakeLock(); + this._acquireWakeLock(); + }, + + get _window() { + return Services.wm.getMostRecentWindow(DevToolsServer.chromeWindowType); + }, +}); |