mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-30 09:16:58 -10:00
In prevision of Promise.jsm removal, use defer helper module instead of Promise.jsm as that's the only one feature that DOM Promise don't support. PART3: Manual fixes - Go manually fix: http://searchfox.org/mozilla-central/source/devtools/client/dom/dom-panel.js which has duplicated import of defer symbol (it already used to import it) - execute eslint, see all the places where we import of 'promise' is no longer use it (there may be leftovers not covered by eslint that will be covered in bug 1387128) devtools/server/tests/mochitest/inspector-helpers.js needs to keep importing promise as it is a shared test script. - fix devtools/client/performance/panel.js and devtools/client/webconsole/console-output.js which use loader.lazyRequireGetter(this, "promise") and miss the defer import - fix devtools/server/worker.js to use 'worker.require(devtools/shared/defer")' MozReview-Commit-ID: HIOB5Et87Wc
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
/* 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 Services = require("Services");
|
|
const protocol = require("devtools/shared/protocol");
|
|
const defer = require("devtools/shared/defer");
|
|
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");
|
|
|
|
exports.DeviceActor = protocol.ActorClassWithSpec(deviceSpec, {
|
|
_desc: null,
|
|
|
|
getDescription: function () {
|
|
return getSystemInfo();
|
|
},
|
|
|
|
getWallpaper: function () {
|
|
let deferred = 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);
|
|
let { devicePixelRatio } = window;
|
|
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);
|
|
}
|
|
});
|