Commit 3f421b3c authored by dstockwell's avatar dstockwell Committed by Commit Bot

pdf: Warn user when closing if they have made annotations but not saved

Bug: 902646, 933205
Change-Id: I7ddb3da8ac6131532896f886a03451351b3780aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1482356
Commit-Queue: dstockwell <dstockwell@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637542}
parent 69581072
...@@ -171,8 +171,10 @@ Polymer({ ...@@ -171,8 +171,10 @@ Polymer({
this.activePointer_ = null; this.activePointer_ = null;
if (!this.pointerGesture_) { if (!this.pointerGesture_) {
this.dispatchPointerEvent_(e); this.dispatchPointerEvent_(e);
// If the stroke was not cancelled, record metrics. // If the stroke was not cancelled (type == pointercanel),
// notify about mutation and record metrics.
if (e.type == 'pointerup') { if (e.type == 'pointerup') {
this.dispatchEvent(new CustomEvent('stroke-added'));
if (e.pointerType == 'mouse') { if (e.pointerType == 'mouse') {
PDFMetrics.record(PDFMetrics.UserAction.ANNOTATE_STROKE_DEVICE_MOUSE); PDFMetrics.record(PDFMetrics.UserAction.ANNOTATE_STROKE_DEVICE_MOUSE);
} else if (e.pointerType == 'pen') { } else if (e.pointerType == 'pen') {
......
...@@ -1187,6 +1187,9 @@ PDFViewer.prototype = { ...@@ -1187,6 +1187,9 @@ PDFViewer.prototype = {
entry.createWriter(writer => { entry.createWriter(writer => {
writer.write( writer.write(
new Blob([result.dataToSave], {type: 'application/pdf'})); new Blob([result.dataToSave], {type: 'application/pdf'}));
// Unblock closing the window now that the user has saved
// successfully.
chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(false);
}); });
}); });
...@@ -1225,6 +1228,11 @@ PDFViewer.prototype = { ...@@ -1225,6 +1228,11 @@ PDFViewer.prototype = {
this.currentController_.rotateCounterclockwise(); this.currentController_.rotateCounterclockwise();
this.updateAnnotationAvailable_(); this.updateAnnotationAvailable_();
}, },
setHasUnsavedChanges: function() {
// Warn the user if they attempt to close the window without saving.
chrome.mimeHandlerPrivate.setShowBeforeUnloadDialog(true);
},
}; };
/** @abstract */ /** @abstract */
...@@ -1356,6 +1364,9 @@ class InkController extends ContentController { ...@@ -1356,6 +1364,9 @@ class InkController extends ContentController {
this.inkHost_ = document.createElement('viewer-ink-host'); this.inkHost_ = document.createElement('viewer-ink-host');
$('content').appendChild(this.inkHost_); $('content').appendChild(this.inkHost_);
this.inkHost_.viewport = this.viewport_; this.inkHost_.viewport = this.viewport_;
this.inkHost_.addEventListener('stroke-added', e => {
this.viewer_.setHasUnsavedChanges();
});
} }
return this.inkHost_.load(filename, data); return this.inkHost_.load(filename, data);
} }
......
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