diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/server/actors/device.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/actors/device.js')
-rw-r--r-- | devtools/server/actors/device.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/devtools/server/actors/device.js b/devtools/server/actors/device.js new file mode 100644 index 000000000..bf400913a --- /dev/null +++ b/devtools/server/actors/device.js @@ -0,0 +1,70 @@ +/* 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} = require("chrome"); +const Services = require("Services"); +const protocol = require("devtools/shared/protocol"); +const promise = require("promise"); +const {LongStringActor} = require("devtools/server/actors/string"); +const {DebuggerServer} = require("devtools/server/main"); +const {getSystemInfo, getSetting} = require("devtools/shared/system"); +const {deviceSpec} = require("devtools/shared/specs/device"); +const FileReader = require("FileReader"); +const {PermissionsTable} = require("resource://gre/modules/PermissionsTable.jsm"); + +var DeviceActor = exports.DeviceActor = protocol.ActorClassWithSpec(deviceSpec, { + _desc: null, + + getDescription: function () { + return getSystemInfo(); + }, + + getWallpaper: function () { + let deferred = promise.defer(); + getSetting("wallpaper.image").then((blob) => { + let reader = new FileReader(); + let conn = this.conn; + reader.addEventListener("load", function () { + let str = new LongStringActor(conn, reader.result); + deferred.resolve(str); + }); + reader.addEventListener("error", function () { + deferred.reject(reader.error); + }); + reader.readAsDataURL(blob); + }); + return deferred.promise; + }, + + screenshotToDataURL: function () { + let window = Services.wm.getMostRecentWindow(DebuggerServer.chromeWindowType); + var devicePixelRatio = window.devicePixelRatio; + let canvas = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); + let width = window.innerWidth; + let height = window.innerHeight; + canvas.setAttribute("width", Math.round(width * devicePixelRatio)); + canvas.setAttribute("height", Math.round(height * devicePixelRatio)); + let context = canvas.getContext("2d"); + let flags = + context.DRAWWINDOW_DRAW_CARET | + context.DRAWWINDOW_DRAW_VIEW | + context.DRAWWINDOW_USE_WIDGET_LAYERS; + context.scale(devicePixelRatio, devicePixelRatio); + context.drawWindow(window, 0, 0, width, height, "rgb(255,255,255)", flags); + let dataURL = canvas.toDataURL("image/png"); + return new LongStringActor(this.conn, dataURL); + }, + + getRawPermissionsTable: function () { + return { + rawPermissionsTable: PermissionsTable, + UNKNOWN_ACTION: Ci.nsIPermissionManager.UNKNOWN_ACTION, + ALLOW_ACTION: Ci.nsIPermissionManager.ALLOW_ACTION, + DENY_ACTION: Ci.nsIPermissionManager.DENY_ACTION, + PROMPT_ACTION: Ci.nsIPermissionManager.PROMPT_ACTION + }; + } +}); |