Skip to content

Commit

Permalink
Bug 1733639 - Use toBlob instead of toDataURL. r=Gijs
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Baumgardner committed Oct 14, 2021
1 parent 72d9ef1 commit cc86983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions browser/components/screenshots/content/screenshots.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="Content-Security-Policy" content="default-src chrome:;img-src data:; object-src 'none'">
<meta http-equiv="Content-Security-Policy" content="default-src chrome:;img-src blob:; object-src 'none'">

<link rel="localization" href="browser/screenshots.ftl">

Expand All @@ -33,7 +33,6 @@
</div>
<div class="preview-image">
<div id="preview-image-div" class="preview-image-area">
<img id="placeholder-image"/>
</div>
</div>
</div>
Expand Down
17 changes: 13 additions & 4 deletions browser/components/screenshots/content/screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ScreenshotsUI extends HTMLElement {
let browsingContext = BrowsingContext.get(browsingContextId);
let win = browsingContext.top.embedderElement.ownerGlobal;
Services.obs.notifyObservers(win, "toggle-screenshot-disable", "false");
URL.revokeObjectURL(document.getElementById("placeholder-image").src);
window.close();
}

Expand Down Expand Up @@ -102,10 +103,11 @@ class ScreenshotsUI extends HTMLElement {
// add the download to the download list in the Downloads list in the Browser UI
list.add(download);

this.close();

// Await successful completion of the save via the download manager
await download.start();

// need to close after download because blob url is revoked on close
this.close();
} catch (ex) {}
}

Expand Down Expand Up @@ -203,8 +205,15 @@ class ScreenshotsUI extends HTMLElement {

context.drawImage(snapshot, 0, 0);

let imgEle = this.ownerDocument.getElementById("placeholder-image");
imgEle.src = canvas.toDataURL();
canvas.toBlob(function(blob) {
let newImg = document.createElement("img");
let url = URL.createObjectURL(blob);

newImg.setAttribute("id", "placeholder-image");

newImg.src = url;
document.getElementById("preview-image-div").appendChild(newImg);
});

snapshot.close();
}
Expand Down

0 comments on commit cc86983

Please sign in to comment.