diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/server/actors/device.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.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 | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/devtools/server/actors/device.js b/devtools/server/actors/device.js new file mode 100644 index 0000000000..50d30350aa --- /dev/null +++ b/devtools/server/actors/device.js @@ -0,0 +1,83 @@ +/* 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 { Ci, Cc } = require("chrome"); +const Services = require("Services"); +const protocol = require("devtools/shared/protocol"); + +const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); +XPCOMUtils.defineLazyServiceGetter( + this, + "swm", + "@mozilla.org/serviceworkers/manager;1", + "nsIServiceWorkerManager" +); + +const { DevToolsServer } = require("devtools/server/devtools-server"); +const { getSystemInfo } = require("devtools/shared/system"); +const { deviceSpec } = require("devtools/shared/specs/device"); +const { AppConstants } = require("resource://gre/modules/AppConstants.jsm"); + +exports.DeviceActor = protocol.ActorClassWithSpec(deviceSpec, { + initialize: function(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: function() { + protocol.Actor.prototype.destroy.call(this); + this._releaseWakeLock(); + if (this._window) { + this._window.removeEventListener("pageshow", this._onPageShow, true); + } + }, + + getDescription: function() { + return Object.assign({}, getSystemInfo(), { + // ServiceWorker debugging is only supported when parent-intercept is + // enabled. This cannot change at runtime, so it can be treated as a + // constant for the device. + canDebugServiceWorkers: swm.isParentInterceptEnabled(), + }); + }, + + _acquireWakeLock: function() { + if (AppConstants.platform !== "android") { + return; + } + + const pm = Cc["@mozilla.org/power/powermanagerservice;1"].getService( + Ci.nsIPowerManagerService + ); + this._wakelock = pm.newWakeLock("screen", this._window); + }, + + _releaseWakeLock: function() { + if (this._wakelock) { + try { + this._wakelock.unlock(); + } catch (e) { + // Ignore error since wake lock is already unlocked + } + this._wakelock = null; + } + }, + + _onPageShow: function() { + this._releaseWakeLock(); + this._acquireWakeLock(); + }, + + get _window() { + return Services.wm.getMostRecentWindow(DevToolsServer.chromeWindowType); + }, +}); |