diff options
Diffstat (limited to 'chromium/chrome/browser/resources/pdf/controller.js')
-rw-r--r-- | chromium/chrome/browser/resources/pdf/controller.js | 145 |
1 files changed, 15 insertions, 130 deletions
diff --git a/chromium/chrome/browser/resources/pdf/controller.js b/chromium/chrome/browser/resources/pdf/controller.js index 9eccd835645..95c02f1fa0d 100644 --- a/chromium/chrome/browser/resources/pdf/controller.js +++ b/chromium/chrome/browser/resources/pdf/controller.js @@ -6,8 +6,8 @@ import {assert} from 'chrome://resources/js/assert.m.js'; import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {PromiseResolver} from 'chrome://resources/js/promise_resolver.m.js'; -import {$} from 'chrome://resources/js/util.m.js'; +import {SaveRequestType} from './constants.js'; import {PartialPoint, Point, Viewport} from './viewport.js'; /** @typedef {{ type: string }} */ @@ -45,25 +45,6 @@ let EmailMessageData; */ export let PrintPreviewParams; -// Note: Redefining this type here, to work around the fact that ink externs -// are only available on Chrome OS, so the targets that contain them cannot be -// built on other platforms. -// TODO (rbpotter): Break InkController into its own file that is only included -// on Chrome OS. - -/** - * @typedef {{ - * setAnnotationTool: function(AnnotationTool):void, - * viewportChanged: function():void, - * saveDocument: function():!Promise, - * undo: function():void, - * redo: function():void, - * load: function(string, !ArrayBuffer):!Promise, - * viewport: !Viewport, - * }} - */ -let ViewerInkHostElement; - /** * Creates a cryptographically secure pseudorandom 128-bit token. * @return {string} The generated token as a hex string. @@ -105,12 +86,13 @@ export class ContentController { /** * Requests that the current document be saved. - * @param {boolean} requireResult whether a response is required, otherwise - * the controller may save the document to disk internally. + * @param {!SaveRequestType} requestType The type of save request. If + * ANNOTATION, a response is required, otherwise the controller may save + * the document to disk internally. * @return {Promise<{fileName: string, dataToSave: ArrayBuffer}>} * @abstract */ - save(requireResult) {} + save(requestType) {} /** * Loads PDF document from `data` activates UI. @@ -128,110 +110,9 @@ export class ContentController { unload() {} } -/** - * Controller for annotation mode, on Chrome OS only. Fires the following events - * from its event target: - * has-unsaved-changes: Fired to indicate there are ink annotations that have - * not been saved. - * set-annotation-undo-state: Contains information about whether undo or redo - * options are available. - */ -export class InkController extends ContentController { - /** @param {!Viewport} viewport */ - constructor(viewport) { - super(); - - /** @private {!Viewport} */ - this.viewport_ = viewport; - - /** @private {?ViewerInkHostElement} */ - this.inkHost_ = null; - - /** @private {!EventTarget} */ - this.eventTarget_ = new EventTarget(); - - /** @type {?AnnotationTool} */ - this.tool_ = null; - } - - /** @return {!EventTarget} */ - getEventTarget() { - return this.eventTarget_; - } - - /** @param {AnnotationTool} tool */ - setAnnotationTool(tool) { - this.tool_ = tool; - if (this.inkHost_) { - this.inkHost_.setAnnotationTool(tool); - } - } - - /** @override */ - rotateClockwise() { - // TODO(dstockwell): implement rotation - } - - /** @override */ - rotateCounterclockwise() { - // TODO(dstockwell): implement rotation - } - - /** @override */ - setTwoUpView(enableTwoUpView) { - // TODO(dstockwell): Implement two up view. - } - - /** @override */ - viewportChanged() { - this.inkHost_.viewportChanged(); - } - - /** @override */ - save(requireResult) { - return this.inkHost_.saveDocument(); - } - - /** @override */ - undo() { - this.inkHost_.undo(); - } - - /** @override */ - redo() { - this.inkHost_.redo(); - } - - /** @override */ - load(filename, data) { - if (!this.inkHost_) { - const inkHost = document.createElement('viewer-ink-host'); - $('content').appendChild(inkHost); - this.inkHost_ = /** @type {!ViewerInkHostElement} */ (inkHost); - this.inkHost_.viewport = this.viewport_; - inkHost.addEventListener('stroke-added', e => { - this.eventTarget_.dispatchEvent(new CustomEvent('has-unsaved-changes')); - }); - inkHost.addEventListener('undo-state-changed', e => { - this.eventTarget_.dispatchEvent( - new CustomEvent('set-annotation-undo-state', {detail: e.detail})); - }); - } - return this.inkHost_.load(filename, data); - } - - /** @override */ - unload() { - this.inkHost_.remove(); - this.inkHost_ = null; - } -} - -/** - * PDF plugin controller, responsible for communicating with the embedded plugin - * element. Dispatches a 'plugin-message' event containing the message from the - * plugin, if a message type not handled by this controller is received. - */ +// PDF plugin controller, responsible for communicating with the embedded plugin +// element. Dispatches a 'plugin-message' event containing the message from the +// plugin, if a message type not handled by this controller is received. export class PluginController extends ContentController { /** * @param {!HTMLEmbedElement} plugin @@ -407,11 +288,15 @@ export class PluginController extends ContentController { } /** @override */ - save(requireResult) { + save(requestType) { const resolver = new PromiseResolver(); const newToken = createToken(); this.pendingTokens_.set(newToken, resolver); - this.postMessage_({type: 'save', token: newToken, force: requireResult}); + this.postMessage_({ + type: 'save', + token: newToken, + saveRequestType: requestType, + }); return resolver.promise; } @@ -420,6 +305,7 @@ export class PluginController extends ContentController { const url = URL.createObjectURL(new Blob([data])); this.plugin_.removeAttribute('headers'); this.plugin_.setAttribute('stream-url', url); + this.plugin_.setAttribute('has-edits', ''); this.plugin_.style.display = 'block'; try { await this.getLoadedCallback_(); @@ -476,7 +362,6 @@ export class PluginController extends ContentController { /** * Handles the pdf file buffer received from the plugin. - * * @param {!SaveDataMessageData} messageData data of the message event. * @private */ |