Bug 1588980 - Part 1: Hide HTMLCanvasElement.mozGetAsFile behind a preference; r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D60283

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2020-01-18 05:06:25 +00:00
Родитель d02527e65d
Коммит 6ba1137eeb
8 изменённых файлов: 39 добавлений и 6 удалений

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

@ -193,6 +193,7 @@ tags = imagebitmap
[test_ImageData_ctor.html]
[test_isPointInStroke.html]
[test_mozGetAsFile.html]
prefs = canvas.mozgetasfile.enabled=true
[test_strokeText_throw.html]
[test_toBlob.html]
[test_toBlob_zero_dimension.html]

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

@ -14,7 +14,7 @@ function BlobListener(type, canvas, callback, file)
reader.onload =
function(e) {
is(e.target.result, canvas.toDataURL(type),
"<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
"<canvas>.toBlob() should equal <canvas>.toDataURL()");
callback(canvas);
};
reader.readAsDataURL(file);

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

@ -135,7 +135,11 @@ function testBlob(file, contents, testName) {
function testSlice(file, size, type, contents, fileType, range) {
is(file.type, type, fileType + " file is correct type");
is(file.size, size, fileType + " file is correct size");
ok(file instanceof File, fileType + " file is a File");
if (fileType == "fileFile") {
ok(file instanceof File, fileType + " file is a File");
} else if (fileType == "memFile") {
ok(!(file instanceof File), fileType + " file is not a File");
}
ok(file instanceof Blob, fileType + " file is also a Blob");
let slice = file.slice(0, size);
@ -377,3 +381,15 @@ function createFile(data, name) {
});
});
}
function toBlobPromise(canvas) {
function BlobListener(callback, file) {
var reader = new FileReader();
reader.onload = () => callback(file);
reader.readAsDataURL(file);
}
return new Promise(resolve => {
canvas.toBlob(BlobListener.bind(undefined, resolve));
});
}

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

@ -21,7 +21,12 @@ SimpleTest.requestLongerTimeout(4);
createCanvasURL()
.then(data => {
let cx = $("canvas").getContext('2d');
let memFile = cx.canvas.mozGetAsFile("image/png");
return Promise.all([toBlobPromise(cx.canvas),
Promise.resolve(data)]);
})
.then(args => {
let [memFile, data] = args;
return testSlice(memFile, data.length, "image/png", data, "memFile", RANGE_1);
})

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

@ -21,7 +21,12 @@ SimpleTest.requestLongerTimeout(4);
createCanvasURL()
.then(data => {
let cx = $("canvas").getContext('2d');
let memFile = cx.canvas.mozGetAsFile("image/png");
return Promise.all([toBlobPromise(cx.canvas),
Promise.resolve(data)]);
})
.then(args => {
let [memFile, data] = args;
return testSlice(memFile, data.length, "image/png", data, "memFile", RANGE_2);
})

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

@ -38,7 +38,7 @@ interface HTMLCanvasElement : HTMLElement {
partial interface HTMLCanvasElement {
[Pure, SetterThrows]
attribute boolean mozOpaque;
[Throws, NeedsSubjectPrincipal]
[Throws, NeedsSubjectPrincipal, Pref="canvas.mozgetasfile.enabled"]
File mozGetAsFile(DOMString name, optional DOMString? type = null);
// A Mozilla-only extension to get a canvas context backed by double-buffered
// shared memory. Only privileged callers can call this.

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

@ -9,7 +9,7 @@ load 570451.png
# Bug 1390704 - Skip on debug because it triggers a quadratic behavior that makes it take
# so much time that it can trip on the reftest timeout of 5 minutes.
skip-if(Android||isDebugBuild) load 694165-1.xhtml
load 681190.html
pref(canvas.mozgetasfile.enabled,true) load 681190.html
load 732319-1.html
load 844403-1.html
load 856616.gif

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

@ -1063,6 +1063,12 @@
value: false
mirror: always
# Provide ability to turn on support for canvas mozGetAsFile API.
- name: canvas.mozgetasfile.enabled
type: bool
value: false
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "channelclassifier."
#---------------------------------------------------------------------------