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) { ...@@ -107,12 +107,20 @@ function PiexLoaderResponse(data) {
} }
/** /**
* Resolves the file entry associated with DOM filesystem |url| and returns * Returns the source data.
* the file content in an ArrayBuffer. *
* @param {string} url - DOM filesystem URL of the file. * If the source is an ArrayBuffer, return it. Otherwise assume the source is
* @returns {!Promise<!ArrayBuffer>} * 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) => { return new Promise((resolve, reject) => {
/** /**
* Reject the Promise on fileEntry URL resolve or file read failures. * Reject the Promise on fileEntry URL resolve or file read failures.
...@@ -149,6 +157,7 @@ function readFromFileSystem(url) { ...@@ -149,6 +157,7 @@ function readFromFileSystem(url) {
}, failure); }, failure);
} }
const url = /** @type {string} */ (source);
window.webkitResolveLocalFileSystemURL(url, readEntry, failure); window.webkitResolveLocalFileSystemURL(url, readEntry, failure);
}); });
} }
...@@ -474,14 +483,14 @@ function PiexLoader() {} ...@@ -474,14 +483,14 @@ function PiexLoader() {}
* to reload the page. Callback |onPiexModuleFailed| is used to indicate that * to reload the page. Callback |onPiexModuleFailed| is used to indicate that
* the caller should initiate failure recovery steps. * the caller should initiate failure recovery steps.
* *
* @param {string} url * @param {string|!ArrayBuffer} source
* @param {!function()} onPiexModuleFailed * @param {!function()} onPiexModuleFailed
* @return {!Promise<!PiexLoaderResponse>} * @return {!Promise<!PiexLoaderResponse>}
*/ */
PiexLoader.prototype.load = function(url, onPiexModuleFailed) { PiexLoader.prototype.load = function(source, onPiexModuleFailed) {
let imageBuffer; let imageBuffer;
return readFromFileSystem(url) return readSourceData(source)
.then((buffer) => { .then((buffer) => {
if (piexModuleFailed() === true) { if (piexModuleFailed() === true) {
// Just reject here: handle in the .catch() clause below. // 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