Bug 1585096 - Cleanup code path separation in RDM's screenshot action. r=gl

Depends on D82558

Differential Revision: https://phabricator.services.mozilla.com/D82559
This commit is contained in:
Micah Tigley 2020-07-09 20:20:41 +00:00
Родитель 5919140f78
Коммит 70e2aea069
1 изменённых файлов: 2 добавлений и 65 удалений

Просмотреть файл

@ -6,21 +6,11 @@
"use strict";
const Services = require("Services");
const {
TAKE_SCREENSHOT_START,
TAKE_SCREENSHOT_END,
} = require("devtools/client/responsive/actions/index");
const { getFormatStr } = require("devtools/client/responsive/utils/l10n");
const {
getTopLevelWindow,
} = require("devtools/client/responsive/utils/window");
const e10s = require("devtools/client/responsive/utils/e10s");
const CAMERA_AUDIO_URL = "resource://devtools/client/themes/audio/shutter.wav";
const message = require("devtools/client/responsive/utils/message");
const animationFrame = () =>
@ -28,48 +18,6 @@ const animationFrame = () =>
window.requestAnimationFrame(resolve);
});
function getFileName() {
const date = new Date();
const month = ("0" + (date.getMonth() + 1)).substr(-2);
const day = ("0" + date.getDate()).substr(-2);
const dateString = [date.getFullYear(), month, day].join("-");
const timeString = date
.toTimeString()
.replace(/:/g, ".")
.split(" ")[0];
return getFormatStr(
"responsive.screenshotGeneratedFilename",
dateString,
timeString
);
}
function createScreenshotFor(node) {
const mm = node.frameLoader.messageManager;
return e10s.request(mm, "RequestScreenshot");
}
function saveToFile(data, filename) {
const chromeWindow = getTopLevelWindow(window);
const chromeDocument = chromeWindow.document;
// append .png extension to filename if it doesn't exist
filename = filename.replace(/\.png$|$/i, ".png");
// In chrome doc, we don't need to pass a referrer, just pass null
chromeWindow.saveURL(data, filename, null, true, true, null, chromeDocument);
}
function simulateCameraEffects(node) {
if (Services.prefs.getBoolPref("devtools.screenshot.audio.enabled")) {
const cameraAudio = new window.Audio(CAMERA_AUDIO_URL);
cameraAudio.play();
}
node.animate({ opacity: [0, 1] }, 500);
}
module.exports = {
takeScreenshot() {
return async function(dispatch) {
@ -79,19 +27,8 @@ module.exports = {
// can be properly render after the action dispatched above
await animationFrame();
if (
!Services.prefs.getBoolPref("devtools.responsive.browserUI.enabled")
) {
const iframe = document.querySelector("iframe");
const data = await createScreenshotFor(iframe);
simulateCameraEffects(iframe);
saveToFile(data, getFileName());
} else {
window.postMessage({ type: "screenshot" }, "*");
await message.wait(window, "screenshot-captured");
}
window.postMessage({ type: "screenshot" }, "*");
await message.wait(window, "screenshot-captured");
dispatch({ type: TAKE_SCREENSHOT_END });
};