Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #4174, don't overwrite correctly-scaled canvas dimensions; pass t…
Browse files Browse the repository at this point in the history
…he shot type to downloadShot and copyShot
  • Loading branch information
jaredhirsch committed Mar 6, 2018
1 parent 2f79432 commit 9a8b11b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions addon/webextension/selector/shooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
}
const canvas = captureToCanvas(selectedPos, captureType);
ui.iframe.showLoader();
const width = selectedPos.right - selectedPos.left;
const height = selectedPos.bottom - selectedPos.top;
const imageData = canvas.getContext("2d").getImageData(0, 0, width, height);
const imageData = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height);
return callBackground("canvasToDataURL", imageData);
}

Expand Down Expand Up @@ -180,8 +178,8 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
}));
};

exports.downloadShot = function(selectedPos, previewDataUrl) {
const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, "fullPage");
exports.downloadShot = function(selectedPos, previewDataUrl, type) {
const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, type);
catcher.watchPromise(shotPromise.then(dataUrl => {
let promise = Promise.resolve(dataUrl);
if (!dataUrl) {
Expand Down Expand Up @@ -214,7 +212,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
};

let copyInProgress = null;
exports.copyShot = function(selectedPos, previewDataUrl) {
exports.copyShot = function(selectedPos, previewDataUrl, type) {
// This is pretty slow. We'll ignore additional user triggered copy events
// while it is in progress.
if (copyInProgress) {
Expand All @@ -231,7 +229,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
copyInProgress = null;
}
}
const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, "fullPage");
const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, type);
catcher.watchPromise(shotPromise.then(dataUrl => {
const blob = blobConverters.dataUrlToBlob(dataUrl);
catcher.watchPromise(callBackground("copyShotToClipboard", blob).then(() => {
Expand Down
4 changes: 2 additions & 2 deletions addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ this.uicontrol = (function() {
const previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
// Downloaded shots don't have dimension limits
removeDimensionLimitsOnFullPageShot();
shooter.downloadShot(selectedPos, previewDataUrl);
shooter.downloadShot(selectedPos, previewDataUrl, captureType);
}

function copyShot() {
const previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
// Copied shots don't have dimension limits
removeDimensionLimitsOnFullPageShot();
shooter.copyShot(selectedPos, previewDataUrl);
shooter.copyShot(selectedPos, previewDataUrl, captureType);
}

/** *********************************************
Expand Down

0 comments on commit 9a8b11b

Please sign in to comment.