Commit f092d373 authored by Michael Checo's avatar Michael Checo Committed by Commit Bot

Scanning: Show dialog when users try to close the app during a scan

Bug: 1059779
Test: browser_tests --gtest_filter=ScanningAppBrowserTest.All
Change-Id: I6f4681eb55b73449794384ebae3f1e873eec6550
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523238
Commit-Queue: Michael Checo <michaelcheco@google.com>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825388}
parent 82459222
......@@ -124,6 +124,12 @@ Polymer({
type: Boolean,
value: false,
},
/** @private {boolean} */
isScanInProgress_: {
type: Boolean,
value: false,
},
},
/** @override */
......@@ -134,6 +140,15 @@ Polymer({
/** @override */
ready() {
window.addEventListener('beforeunload', event => {
// When the user tries to close the app while a scan is in progress,
// show the 'Leave site' dialog.
if (this.isScanInProgress_) {
event.preventDefault();
event.returnValue = '';
}
});
this.scanService_.getScanners().then(
/*@type {!{scanners: !ScannerArr}}*/ (response) => {
this.onScannersReceived_(response);
......@@ -142,6 +157,7 @@ Polymer({
/** @override */
detached() {
// TODO(jschettler): Cancel any ongoing scan jobs.
if (this.scanJobObserverReceiver_) {
this.scanJobObserverReceiver_.$.close();
}
......@@ -180,6 +196,7 @@ Polymer({
'Scan failed.';
this.settingsDisabled_ = false;
this.scanButtonDisabled_ = false;
this.isScanInProgress_ = false;
},
/**
......@@ -319,6 +336,7 @@ Polymer({
this.statusText_ = 'Scanning page 1: 0%';
this.settingsDisabled_ = true;
this.scanButtonDisabled_ = true;
this.isScanInProgress_ = true;
},
/** @private */
......
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