diff options
Diffstat (limited to 'chromium/chrome/browser/resources/settings/autofill_page')
9 files changed, 165 insertions, 10 deletions
diff --git a/chromium/chrome/browser/resources/settings/autofill_page/BUILD.gn b/chromium/chrome/browser/resources/settings/autofill_page/BUILD.gn index c40261fd353..84a9f949cac 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/BUILD.gn +++ b/chromium/chrome/browser/resources/settings/autofill_page/BUILD.gn @@ -9,6 +9,7 @@ js_type_check("closure_compile") { ":address_edit_dialog", ":autofill_page", ":autofill_section", + ":blocking_request_manager", ":credit_card_edit_dialog", ":credit_card_list", ":credit_card_list_entry", @@ -50,6 +51,9 @@ js_library("autofill_section") { externs_list = [ "$externs_path/autofill_private.js" ] } +js_library("blocking_request_manager") { +} + js_library("payments_section") { deps = [ ":credit_card_edit_dialog", @@ -134,5 +138,8 @@ js_library("password_edit_dialog") { } js_library("show_password_behavior") { + deps = [ + ":blocking_request_manager", + ] externs_list = [ "$externs_path/passwords_private.js" ] } diff --git a/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.html b/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.html new file mode 100644 index 00000000000..12f53887d68 --- /dev/null +++ b/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.html @@ -0,0 +1,2 @@ +<link rel="import" href="chrome://resources/html/cr.html"> +<script src="blocking_request_manager.js"></script> diff --git a/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.js b/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.js new file mode 100644 index 00000000000..69d4eb60818 --- /dev/null +++ b/chromium/chrome/browser/resources/settings/autofill_page/blocking_request_manager.js @@ -0,0 +1,40 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * @fileoverview Helper class for making blocking requests that are resolved + * elsewhere in the DOM. + */ +cr.define('settings', function() { + class BlockingRequestManager { + /** @param {Function} makeRequest Function to initiate flow for request. */ + constructor(makeRequest) { + this.makeRequest_ = makeRequest; + /** + * @private {Function} callback Provided in requests and called when the + * request is resolved. + */ + this.callback_ = null; + } + + /** + * Make a blocking request. + * @param {Function} callback Function to be called if/when the request is + * successfully resolved. + */ + request(callback) { + this.callback_ = callback; + this.makeRequest_(); + } + + /** Called if/when request is resolved successfully. */ + resolve() { + this.callback_(); + } + } + + return { + BlockingRequestManager: BlockingRequestManager, + }; +}); diff --git a/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.html b/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.html index bc044b56f64..ab305896fc3 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.html +++ b/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.html @@ -6,6 +6,9 @@ <link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-progress/paper-progress.html"> <link rel="import" href="../settings_shared_css.html"> +<if expr="chromeos"> +<link rel="import" href="blocking_request_manager.html"> +</if> <dom-module id="passwords-export-dialog"> <template> diff --git a/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.js b/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.js index 094f607d633..d57d44916c2 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.js +++ b/chromium/chrome/browser/resources/settings/autofill_page/passwords_export_dialog.js @@ -52,6 +52,11 @@ Polymer({ /** @private */ showErrorDialog_: Boolean, + + // <if expr="chromeos"> + /** @type settings.BlockingRequestManager */ + tokenRequestManager: Object + // </if> }, listeners: { @@ -177,11 +182,22 @@ Polymer({ this.async(() => this.fire('passwords-export-dialog-close')); }, + /** @private */ + onExportTap_: function() { + // <if expr="chromeos"> + this.tokenRequestManager.request(this.exportPasswords_.bind(this)); + // </if> + // <if expr="not chromeos"> + this.exportPasswords_(); + // </if> + }, + /** - * Fires an event that should trigger the password export process. + * Tells the PasswordsPrivate API to export saved passwords in a .csv pending + * security checks. * @private */ - onExportTap_: function() { + exportPasswords_: function() { this.passwordManager_.exportPasswords(() => { if (chrome.runtime.lastError && chrome.runtime.lastError.message == 'in-progress') { diff --git a/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.html b/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.html index 74cd237e755..2f65256cce8 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.html +++ b/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.html @@ -23,6 +23,10 @@ <link rel="import" href="passwords_shared_css.html"> <link rel="import" href="password_list_item.html"> <link rel="import" href="password_manager_proxy.html"> +<if expr="chromeos"> +<link rel="import" href="../controls/password_prompt_dialog.html"> +<link rel="import" href="blocking_request_manager.html"> +</if> <dom-module id="passwords-section"> <template> @@ -106,6 +110,9 @@ scroll-target="[[subpageScrollTarget]]" risk-selection> <template> <password-list-item item="[[item]]" tabindex$="[[tabIndex]]" +<if expr="chromeos"> + token-request-manager="[[tokenRequestManager_]]" +</if> first$="[[!index]]" iron-list-tab-index="[[tabIndex]]" last-focused="{{lastFocused_}}" list-blurred="{{listBlurred_}}"> </password-list-item> @@ -134,14 +141,27 @@ </cr-action-menu> <template is="dom-if" if="[[showPasswordsExportDialog_]]" restamp> <passwords-export-dialog - on-passwords-export-dialog-close="onPasswordsExportDialogClosed_"> +<if expr="chromeos"> + token-request-manager="[[tokenRequestManager_]]" +</if> + on-passwords-export-dialog-close="onPasswordsExportDialogClosed_"> </passwords-export-dialog> </template> <template is="dom-if" if="[[showPasswordEditDialog_]]" restamp> <password-edit-dialog on-close="onPasswordEditDialogClosed_" +<if expr="chromeos"> + token-request-manager="[[tokenRequestManager_]]" +</if> item="[[activePassword.item]]"> </password-edit-dialog> </template> +<if expr="chromeos"> + <template is="dom-if" if="[[showPasswordPromptDialog_]]" restamp> + <settings-password-prompt-dialog auth-token="{{authToken_}}" + on-close="onPasswordPromptClosed_"> + </settings-password-prompt-dialog> + </template> +</if> <cr-toast id="undoToast" duration="[[toastDuration_]]"> <div id="undoLabel">$i18n{passwordDeleted}</div> <paper-button on-click="onUndoButtonTap_"> diff --git a/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.js b/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.js index 2dc5b59bacb..1603dc8b370 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.js +++ b/chromium/chrome/browser/resources/settings/autofill_page/passwords_section.js @@ -122,11 +122,28 @@ Polymer({ /** @private */ listBlurred_: Boolean, + + // <if expr="chromeos"> + /** + * Auth token for retrieving passwords if required by OS. + * @private + */ + authToken_: { + type: String, + value: '', + observer: 'onAuthTokenChanged_', + }, + + /** @private */ + showPasswordPromptDialog_: Boolean, + + /** @private {settings.BlockingRequestManager} */ + tokenRequestManager_: Object + // </if> }, listeners: { 'password-menu-tap': 'onPasswordMenuTap_', - 'export-passwords': 'onExportPasswords_', }, keyBindings: { @@ -184,6 +201,11 @@ Polymer({ // Set the manager. These can be overridden by tests. this.passwordManager_ = PasswordManagerImpl.getInstance(); + // <if expr="chromeos"> + this.tokenRequestManager_ = new settings.BlockingRequestManager( + () => this.showPasswordPromptDialog_ = true); + // </if> + // Request initial data. this.passwordManager_.getSavedPasswordList(setSavedPasswordsListener); this.passwordManager_.getExceptionList(setPasswordExceptionsListener); @@ -219,6 +241,33 @@ Polymer({ } }, + // <if expr="chromeos"> + /** + * When |authToken_| changes to a new non-empty value, it means that the + * password-prompt-dialog succeeded in creating a fresh token in the + * quickUnlockPrivate API. Because new tokens can only ever be created + * immediately following a GAIA password check, the passwordsPrivate API can + * now safely grant requests for secure data (i.e. saved passwords) for a + * limited time. This observer resolves the request, triggering a callback + * that requires a fresh auth token to succeed and that was provided to the + * BlockingRequestManager by another DOM element seeking secure data. + * + * @param {string} newToken The newly created auth token. Note that its + * precise value is not relevant here, only the facts that it changed and + * that it is non-empty (i.e. not expired). + * @private + */ + onAuthTokenChanged_: function(newToken) { + if (newToken) { + this.tokenRequestManager_.resolve(); + } + }, + + onPasswordPromptClosed_: function() { + this.showPasswordPromptDialog_ = false; + }, + // </if> + /** * Shows the edit password dialog. * @param {!Event} e diff --git a/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.html b/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.html index 73ee8c03754..f9787f2abb6 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.html +++ b/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.html @@ -1,2 +1,6 @@ <link rel="import" href="chrome://resources/html/polymer.html"> +<if expr="chromeos"> +<link rel="import" href="blocking_request_manager.html"> +</if> + <script src="show_password_behavior.js"></script> diff --git a/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.js b/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.js index 097bdb2f0c6..4f73b4d1e1b 100644 --- a/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.js +++ b/chromium/chrome/browser/resources/settings/autofill_page/show_password_behavior.js @@ -16,6 +16,11 @@ const ShowPasswordBehavior = { * @type {!ShowPasswordBehavior.UiEntryWithPassword} */ item: Object, + + // <if expr="chromeos"> + /** @type settings.BlockingRequestManager */ + tokenRequestManager: Object + // </if> }, /** @@ -69,13 +74,22 @@ const ShowPasswordBehavior = { onShowPasswordButtonTap_: function() { if (this.item.password) { this.set('item.password', ''); - } else { - PasswordManagerImpl.getInstance() - .getPlaintextPassword(this.item.entry.id) - .then(password => { - this.set('item.password', password); - }); + return; } + PasswordManagerImpl.getInstance() + .getPlaintextPassword(this.item.entry.id) + .then(password => { + if (password) { + this.set('item.password', password); + } + // <if expr="chromeos"> + if (!password) { + // If no password was found, refresh auth token and retry. + this.tokenRequestManager.request( + this.onShowPasswordButtonTap_.bind(this)); + } + // </if> + }); }, }; |