Commit 7bb09e62 authored by Mitch McDermott's avatar Mitch McDermott Committed by Commit Bot

Propagate full Error object to unprivileged MediaApp upon SaveCopy error.

Previously when we encountered an error during SaveCopy, we would sometimes just pass the error name and miss out on a lot of useful information. This CL removes that handling and just lets the error object propagate through the app.

Other half of this change is http://cl/317591265.

Bug: b/152809763
Change-Id: I65017f6b5359a8f22a7e9a33952b980f547833d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256115Reviewed-by: default avatarBugs Nash <bugsnash@chromium.org>
Commit-Queue: Mitchell McDermott <mcdermottm@google.com>
Cr-Commit-Position: refs/heads/master@{#781195}
parent 8a04da62
...@@ -150,24 +150,11 @@ guestMessagePipe.registerHandler(Message.SAVE_COPY, async (message) => { ...@@ -150,24 +150,11 @@ guestMessagePipe.registerHandler(Message.SAVE_COPY, async (message) => {
// provide an extension automatically. See crbug/1082624#c23. // provide an extension automatically. See crbug/1082624#c23.
excludeAcceptAllOption: true, excludeAcceptAllOption: true,
}; };
// This may throw an error, but we can handle and recover from it on the
// unprivileged side.
/** @type {!FileSystemHandle} */ /** @type {!FileSystemHandle} */
let fileSystemHandle; const fileSystemHandle = /** @type {!FileSystemHandle} */ (
// chooseFileSystem is where recoverable errors happen, errors in the write await window.chooseFileSystemEntries(options));
// process should be treated as unexpected and propagated through
// MessagePipe's standard exception handling.
try {
fileSystemHandle =
/** @type {!FileSystemHandle} */ (
await window.chooseFileSystemEntries(options));
} catch (/** @type {!DOMException} */ err) {
if (err.name !== 'SecurityError' && err.name !== 'AbortError') {
// Unknown error.
throw err;
}
console.log(`Aborting SAVE_COPY: ${err.message}`);
return err.name;
}
const {handle} = await getFileFromHandle(fileSystemHandle); const {handle} = await getFileFromHandle(fileSystemHandle);
// Note `handle` could be the same as a `FileSystemFileHandle` that exists in // Note `handle` could be the same as a `FileSystemFileHandle` that exists in
// `tokenMap`. Possibly even the `File` currently open. But that's OK. E.g. // `tokenMap`. Possibly even the `File` currently open. But that's OK. E.g.
......
...@@ -129,9 +129,7 @@ mediaApp.ClientApiDelegate.prototype.openFeedbackDialog = function() {}; ...@@ -129,9 +129,7 @@ mediaApp.ClientApiDelegate.prototype.openFeedbackDialog = function() {};
* Saves a copy of `file` in a custom location with a custom * Saves a copy of `file` in a custom location with a custom
* name which the user is prompted for via a native save file dialog. * name which the user is prompted for via a native save file dialog.
* @param {!mediaApp.AbstractFile} file * @param {!mediaApp.AbstractFile} file
* @return {!Promise<?string>} Promise which resolves when the request has been * @return {!Promise<undefined>}
* acknowledged. If the dialog could not be opened the promise resolves with
* an error message. Otherwise, with null after writing is complete.
*/ */
mediaApp.ClientApiDelegate.prototype.saveCopy = function(file) {}; mediaApp.ClientApiDelegate.prototype.saveCopy = function(file) {};
......
...@@ -150,15 +150,12 @@ const DELEGATE = { ...@@ -150,15 +150,12 @@ const DELEGATE = {
}, },
/** /**
* @param {!mediaApp.AbstractFile} abstractFile * @param {!mediaApp.AbstractFile} abstractFile
* @return {!Promise<?string>} * @return {!Promise<undefined>}
*/ */
async saveCopy(abstractFile) { async saveCopy(/** !mediaApp.AbstractFile */ abstractFile) {
/** @type {!SaveCopyMessage} */ /** @type {!SaveCopyMessage} */
const msg = {blob: abstractFile.blob, suggestedName: abstractFile.name}; const msg = {blob: abstractFile.blob, suggestedName: abstractFile.name};
const response = await parentMessagePipe.sendMessage(Message.SAVE_COPY, msg);
/** @type {!SaveCopyResponse} */ (
await parentMessagePipe.sendMessage(Message.SAVE_COPY, msg));
return response.errorMessage;
} }
}; };
......
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