Commit e11acd79 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Notify the user when zip pack requests fail as part of launching.

If a file is not openable while preparing the launch data for a file
handler, the file handling app is launched without any file entries and
without the handler ID. With DriveFS, hosted docs will fail in this
fashion; when attempting to zip files including a hosted doc, this
causes the zip archiver to fail silently since it's launched without any
information.

Pass the handler ID to the app when launching without any entries so it
can identify what the user was attempting to do. In the zip archiver,
display the same notification that would be displayed if the zip pack
operation later failed when such launch events are received.

Bug: 892595
Change-Id: I3d2e145a8c6e955b03891063813c0624b692d943
Reviewed-on: https://chromium-review.googlesource.com/c/1303320Reviewed-by: default avatarAnand Mistry <amistry@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604843}
parent d05b46dd
......@@ -134,7 +134,7 @@ class PlatformAppPathLauncher
return;
if (entry_paths_.empty()) {
LaunchWithNoLaunchData();
LaunchWithBasicData();
return;
}
......@@ -174,7 +174,8 @@ class PlatformAppPathLauncher
LOG(WARNING) << "Cannot make absolute path from " << it->value();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::Bind(&PlatformAppPathLauncher::LaunchWithNoLaunchData, this));
base::BindOnce(&PlatformAppPathLauncher::LaunchWithBasicData,
this));
return;
}
}
......@@ -193,10 +194,10 @@ class PlatformAppPathLauncher
}
void OnFilesInvalid(const base::FilePath& /* error_path */) {
LaunchWithNoLaunchData();
LaunchWithBasicData();
}
void LaunchWithNoLaunchData() {
void LaunchWithBasicData() {
// This method is required as an entry point on the UI thread.
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -207,6 +208,8 @@ class PlatformAppPathLauncher
std::unique_ptr<app_runtime::LaunchData> launch_data =
std::make_unique<app_runtime::LaunchData>();
launch_data->action_data = std::move(action_data_);
if (!handler_id_.empty())
launch_data->id = std::make_unique<std::string>(handler_id_);
AppRuntimeEventRouter::DispatchOnLaunchedEvent(
context_, app, launch_source_, std::move(launch_data));
......@@ -274,7 +277,7 @@ class PlatformAppPathLauncher
// with no launch data.
if (!handler) {
LOG(WARNING) << "Extension does not provide a valid file handler.";
LaunchWithNoLaunchData();
LaunchWithBasicData();
return;
}
......
......@@ -109,6 +109,12 @@ unpacker.app = {
*/
mountProcessCounter: 0,
/**
* The number of pack requests received with no inputs.
* @type {number}
*/
invalidPackInputs_: 0,
/**
* Function called on receiving a message from NaCl module. Registered by
* common.js.
......@@ -871,6 +877,20 @@ unpacker.app = {
*/
onLaunched: function(launchData, opt_onSuccess, opt_onError) {
if (launchData.items == null) {
if (launchData.id === 'pack' || launchData.id === 'pack_using_tmp') {
unpacker.app.stringDataLoadedPromise.then((stringData) => {
chrome.notifications.create(
'invalid-pack-' + unpacker.app.invalidPackInputs_++, {
type: 'basic',
iconUrl: chrome.runtime.getManifest().icons[128],
title: unpacker.Compressor.DEFAULT_ARCHIVE_NAME,
message: stringData['ZIP_ARCHIVER_PACKING_ERROR_MESSAGE']
},
function() {});
});
return;
}
// The user tried to launch us directly.
console.log('Ignoring launch request w/out items field', {launchData});
return;
......
......@@ -30,14 +30,14 @@ function setupZipArchiver() {
chrome.fileSystemProvider.onReadFileRequested.addListener(
unpacker.app.onReadFileRequested);
// Load translations
unpacker.app.loadStringData();
// Clean all temporary files inside the work directory, just in case the
// extension aborted previously without removing ones.
unpacker.app.cleanWorkDirectory();
}
// Load translations
unpacker.app.loadStringData();
// Event called on opening a file with the extension or mime type
// declared in the manifest file.
chrome.app.runtime.onLaunched.addListener(unpacker.app.onLaunched);
......
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