From e3796f6f416c70cd72a57ebbd4ec8882232df3ef Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 16 Apr 2017 00:11:44 +0200 Subject: [PATCH 1/2] Convert the password prompt to ES6 syntax --- web/password_prompt.js | 79 +++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/web/password_prompt.js b/web/password_prompt.js index af8cb6fbc..2a2db4e6e 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -30,15 +30,11 @@ import { PasswordResponses } from './pdfjs'; * entry. */ -/** - * @class - */ -var PasswordPrompt = (function PasswordPromptClosure() { +class PasswordPrompt { /** - * @constructs PasswordPrompt * @param {PasswordPromptOptions} options */ - function PasswordPrompt(options) { + constructor(options) { this.overlayName = options.overlayName; this.container = options.container; this.label = options.label; @@ -52,58 +48,53 @@ var PasswordPrompt = (function PasswordPromptClosure() { // Attach the event listeners. this.submitButton.addEventListener('click', this.verify.bind(this)); this.cancelButton.addEventListener('click', this.close.bind(this)); - this.input.addEventListener('keydown', function (e) { + this.input.addEventListener('keydown', (e) => { if (e.keyCode === 13) { // Enter key this.verify(); } - }.bind(this)); + }); OverlayManager.register(this.overlayName, this.container, this.close.bind(this), true); } - PasswordPrompt.prototype = { - open: function PasswordPrompt_open() { - OverlayManager.open(this.overlayName).then(function () { - this.input.type = 'password'; - this.input.focus(); + open() { + OverlayManager.open(this.overlayName).then(() => { + this.input.type = 'password'; + this.input.focus(); - var promptString = mozL10n.get('password_label', null, - 'Enter the password to open this PDF file.'); + var promptString = mozL10n.get('password_label', null, + 'Enter the password to open this PDF file.'); - if (this.reason === PasswordResponses.INCORRECT_PASSWORD) { - promptString = mozL10n.get('password_invalid', null, - 'Invalid password. Please try again.'); - } - - this.label.textContent = promptString; - }.bind(this)); - }, - - close: function PasswordPrompt_close() { - OverlayManager.close(this.overlayName).then(function () { - this.input.value = ''; - this.input.type = ''; - }.bind(this)); - }, - - verify: function PasswordPrompt_verify() { - var password = this.input.value; - if (password && password.length > 0) { - this.close(); - return this.updateCallback(password); + if (this.reason === PasswordResponses.INCORRECT_PASSWORD) { + promptString = mozL10n.get('password_invalid', null, + 'Invalid password. Please try again.'); } - }, - setUpdateCallback: - function PasswordPrompt_setUpdateCallback(updateCallback, reason) { - this.updateCallback = updateCallback; - this.reason = reason; + this.label.textContent = promptString; + }); + } + + close() { + OverlayManager.close(this.overlayName).then(() => { + this.input.value = ''; + this.input.type = ''; + }); + } + + verify() { + var password = this.input.value; + if (password && password.length > 0) { + this.close(); + return this.updateCallback(password); } - }; + } - return PasswordPrompt; -})(); + setUpdateCallback(updateCallback, reason) { + this.updateCallback = updateCallback; + this.reason = reason; + } +} export { PasswordPrompt, From dfd338a399aea2f999419f7119f625dd790ffd2e Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 16 Apr 2017 00:28:24 +0200 Subject: [PATCH 2/2] Remove the password prompt input type hack The browsers have become smarter and made this hack no longer functional. Since this is now enforced by practically all browsers, there is nothing more we can do about this. It is up to the user to serve the viewer over HTTPS or deal with the warning. Note that this is in no way specific for PDF.js. Any site with password inputs served over HTTP has this problem right now. This hack was provided as a convenience for the users, but nothing more than that. --- web/password_prompt.js | 2 -- web/viewer.html | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/web/password_prompt.js b/web/password_prompt.js index 2a2db4e6e..8730ba996 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -60,7 +60,6 @@ class PasswordPrompt { open() { OverlayManager.open(this.overlayName).then(() => { - this.input.type = 'password'; this.input.focus(); var promptString = mozL10n.get('password_label', null, @@ -78,7 +77,6 @@ class PasswordPrompt { close() { OverlayManager.close(this.overlayName).then(() => { this.input.value = ''; - this.input.type = ''; }); } diff --git a/web/viewer.html b/web/viewer.html index 766fc2b47..d08f6392e 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -307,8 +307,7 @@ See https://github.com/adobe-type-tools/cmap-resources

Enter the password to open this PDF file:

- - +