Commit d9caf50c authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[piexwasm] Accept RAW image source data in a ArrayBuffer

piex-wasm assumes a fileSystemURL input as the RAW image source. Allow
other users to input the RAW image source in an ArrayBuffer.

Bug: 1132695
Change-Id: I47bcb837d42a8ca96ccdc79e306e012e0a3a82c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2433744Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811106}
parent 51043f79
......@@ -107,12 +107,20 @@ function PiexLoaderResponse(data) {
}
/**
* Resolves the file entry associated with DOM filesystem |url| and returns
* the file content in an ArrayBuffer.
* @param {string} url - DOM filesystem URL of the file.
* @returns {!Promise<!ArrayBuffer>}
* Returns the source data.
*
* If the source is an ArrayBuffer, return it. Otherwise assume the source is
* is DOM file system URL: resolve the associated file system entry, and read
* and return its content in an ArrayBuffer.
*
* @param {string|!ArrayBuffer} source
* @return {!Promise<!ArrayBuffer>}
*/
function readFromFileSystem(url) {
function readSourceData(source) {
if (source instanceof ArrayBuffer) {
return Promise.resolve(source);
}
return new Promise((resolve, reject) => {
/**
* Reject the Promise on fileEntry URL resolve or file read failures.
......@@ -149,6 +157,7 @@ function readFromFileSystem(url) {
}, failure);
}
const url = /** @type {string} */ (source);
window.webkitResolveLocalFileSystemURL(url, readEntry, failure);
});
}
......@@ -474,14 +483,14 @@ function PiexLoader() {}
* to reload the page. Callback |onPiexModuleFailed| is used to indicate that
* the caller should initiate failure recovery steps.
*
* @param {string} url
* @param {string|!ArrayBuffer} source
* @param {!function()} onPiexModuleFailed
* @return {!Promise<!PiexLoaderResponse>}
*/
PiexLoader.prototype.load = function(url, onPiexModuleFailed) {
PiexLoader.prototype.load = function(source, onPiexModuleFailed) {
let imageBuffer;
return readFromFileSystem(url)
return readSourceData(source)
.then((buffer) => {
if (piexModuleFailed() === true) {
// Just reject here: handle in the .catch() clause below.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment