Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js

Issue 2627123002: Load Passwords and Autofill in the corresponding sub page. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/passwords_and_forms_page/passwords_and_forms_page.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'settings-autofill-section' is the section containing saved 6 * @fileoverview 'settings-autofill-section' is the section containing saved
7 * addresses and credit cards for use in autofill. 7 * addresses and credit cards for use in autofill.
8 */ 8 */
9
10 /**
11 * Interface for all callbacks to the autofill API.
12 * @interface
13 */
14 function AutofillManager() {}
15
16 /** @typedef {chrome.autofillPrivate.AddressEntry} */
17 AutofillManager.AddressEntry;
18
19 /** @typedef {chrome.autofillPrivate.CreditCardEntry} */
20 AutofillManager.CreditCardEntry;
21
22 AutofillManager.prototype = {
23 /**
24 * Add an observer to the list of addresses.
25 * @param {function(!Array<!AutofillManager.AddressEntry>):void} listener
26 */
27 addAddressListChangedListener: assertNotReached,
28
29 /**
30 * Remove an observer from the list of addresses.
31 * @param {function(!Array<!AutofillManager.AddressEntry>):void} listener
32 */
33 removeAddressListChangedListener: assertNotReached,
34
35 /**
36 * Request the list of addresses.
37 * @param {function(!Array<!AutofillManager.AddressEntry>):void} callback
38 */
39 getAddressList: assertNotReached,
40
41 /**
42 * Saves the given address.
43 * @param {!AutofillManager.AddressEntry} address
44 */
45 saveAddress: assertNotReached,
46
47 /** @param {string} guid The guid of the address to remove. */
48 removeAddress: assertNotReached,
49
50 /**
51 * Add an observer to the list of credit cards.
52 * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} listener
53 */
54 addCreditCardListChangedListener: assertNotReached,
55
56 /**
57 * Remove an observer from the list of credit cards.
58 * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} listener
59 */
60 removeCreditCardListChangedListener: assertNotReached,
61
62 /**
63 * Request the list of credit cards.
64 * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} callback
65 */
66 getCreditCardList: assertNotReached,
67
68 /** @param {string} guid The GUID of the credit card to remove. */
69 removeCreditCard: assertNotReached,
70
71 /** @param {string} guid The GUID to credit card to remove from the cache. */
72 clearCachedCreditCard: assertNotReached,
73
74 /**
75 * Saves the given credit card.
76 * @param {!AutofillManager.CreditCardEntry} creditCard
77 */
78 saveCreditCard: assertNotReached,
79 };
80
81 /**
82 * Implementation that accesses the private API.
83 * @implements {AutofillManager}
84 * @constructor
85 */
86 function AutofillManagerImpl() {}
87 cr.addSingletonGetter(AutofillManagerImpl);
88
89 AutofillManagerImpl.prototype = {
90 __proto__: AutofillManager,
91
92 /** @override */
93 addAddressListChangedListener: function(listener) {
94 chrome.autofillPrivate.onAddressListChanged.addListener(listener);
95 },
96
97 /** @override */
98 removeAddressListChangedListener: function(listener) {
99 chrome.autofillPrivate.onAddressListChanged.removeListener(listener);
100 },
101
102 /** @override */
103 getAddressList: function(callback) {
104 chrome.autofillPrivate.getAddressList(callback);
105 },
106
107 /** @override */
108 saveAddress: function(address) {
109 chrome.autofillPrivate.saveAddress(address);
110 },
111
112 /** @override */
113 removeAddress: function(guid) {
114 chrome.autofillPrivate.removeEntry(assert(guid));
115 },
116
117 /** @override */
118 addCreditCardListChangedListener: function(listener) {
119 chrome.autofillPrivate.onCreditCardListChanged.addListener(listener);
120 },
121
122 /** @override */
123 removeCreditCardListChangedListener: function(listener) {
124 chrome.autofillPrivate.onCreditCardListChanged.removeListener(listener);
125 },
126
127 /** @override */
128 getCreditCardList: function(callback) {
129 chrome.autofillPrivate.getCreditCardList(callback);
130 },
131
132 /** @override */
133 removeCreditCard: function(guid) {
134 chrome.autofillPrivate.removeEntry(assert(guid));
135 },
136
137 /** @override */
138 clearCachedCreditCard: function(guid) {
139 chrome.autofillPrivate.maskCreditCard(assert(guid));
140 },
141
142 /** @override */
143 saveCreditCard: function(creditCard) {
144 chrome.autofillPrivate.saveCreditCard(creditCard);
145 }
146 };
147
9 (function() { 148 (function() {
10 'use strict'; 149 'use strict';
11 150
12 Polymer({ 151 Polymer({
13 is: 'settings-autofill-section', 152 is: 'settings-autofill-section',
14 153
15 behaviors: [I18nBehavior], 154 behaviors: [I18nBehavior],
16 155
17 properties: { 156 properties: {
18 /** 157 /**
19 * An array of saved addresses. 158 * An array of saved addresses.
20 * @type {!Array<!chrome.autofillPrivate.AddressEntry>} 159 * @type {!Array<!AutofillManager.AddressEntry>}
21 */ 160 */
22 addresses: Array, 161 addresses: Array,
23 162
24 /** 163 /**
25 * The model for any address related action menus or dialogs. 164 * The model for any address related action menus or dialogs.
26 * @private {?chrome.autofillPrivate.AddressEntry} 165 * @private {?chrome.autofillPrivate.AddressEntry}
27 */ 166 */
28 activeAddress: Object, 167 activeAddress: Object,
29 168
30 /** @private */ 169 /** @private */
31 showAddressDialog_: Boolean, 170 showAddressDialog_: Boolean,
32 171
33 /** 172 /**
34 * An array of saved credit cards. 173 * An array of saved credit cards.
35 * @type {!Array<!chrome.autofillPrivate.CreditCardEntry>} 174 * @type {!Array<!AutofillManager.CreditCardEntry>}
36 */ 175 */
37 creditCards: Array, 176 creditCards: Array,
38 177
39 /** 178 /**
40 * The model for any credit card related action menus or dialogs. 179 * The model for any credit card related action menus or dialogs.
41 * @private {?chrome.autofillPrivate.CreditCardEntry} 180 * @private {?chrome.autofillPrivate.CreditCardEntry}
42 */ 181 */
43 activeCreditCard: Object, 182 activeCreditCard: Object,
44 183
45 /** @private */ 184 /** @private */
46 showCreditCardDialog_: Boolean, 185 showCreditCardDialog_: Boolean,
47 }, 186 },
48 187
188 listeners: {
189 'save-address': 'saveAddress_',
190 'save-credit-card': 'saveCreditCard_',
191 },
192
193 /**
194 * @type {AutofillManager}
195 * @private
196 */
197 autofillManager_: null,
198
199 /**
200 * @type {?function(!Array<!AutofillManager.AddressEntry>)}
201 * @private
202 */
203 setAddressesListener_: null,
204
205 /**
206 * @type {?function(!Array<!AutofillManager.CreditCardEntry>)}
207 * @private
208 */
209 setCreditCardsListener_: null,
210
211 /** @override */
212 ready: function() {
213 // Create listener functions.
214 /** @type {function(!Array<!AutofillManager.AddressEntry>)} */
215 var setAddressesListener = function(list) {
216 this.addresses = list;
217 }.bind(this);
218
219 /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */
220 var setCreditCardsListener = function(list) {
221 this.creditCards = list;
222 }.bind(this);
223
224 // Remember the bound reference in order to detach.
225 this.setAddressesListener_ = setAddressesListener;
226 this.setCreditCardsListener_ = setCreditCardsListener;
227
228 // Set the managers. These can be overridden by tests.
229 this.autofillManager_ = AutofillManagerImpl.getInstance();
230
231 // Request initial data.
232 this.autofillManager_.getAddressList(setAddressesListener);
233 this.autofillManager_.getCreditCardList(setCreditCardsListener);
234
235 // Listen for changes.
236 this.autofillManager_.addAddressListChangedListener(setAddressesListener);
237 this.autofillManager_.addCreditCardListChangedListener(
238 setCreditCardsListener);
239 },
240
241 /** @override */
242 detached: function() {
243 this.autofillManager_.removeAddressListChangedListener(
244 /** @type {function(!Array<!AutofillManager.AddressEntry>)} */(
245 this.setAddressesListener_));
246 this.autofillManager_.removeCreditCardListChangedListener(
247 /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */(
248 this.setCreditCardsListener_));
249 },
250
49 /** 251 /**
50 * Formats the expiration date so it's displayed as MM/YYYY. 252 * Formats the expiration date so it's displayed as MM/YYYY.
51 * @param {!chrome.autofillPrivate.CreditCardEntry} item 253 * @param {!chrome.autofillPrivate.CreditCardEntry} item
52 * @return {string} 254 * @return {string}
255 * @private
53 */ 256 */
54 expiration_: function(item) { 257 expiration_: function(item) {
55 return item.expirationMonth + '/' + item.expirationYear; 258 return item.expirationMonth + '/' + item.expirationYear;
56 }, 259 },
57 260
58 /** 261 /**
59 * Open the address action menu. 262 * Open the address action menu.
60 * @param {!Event} e The polymer event. 263 * @param {!Event} e The polymer event.
61 * @private 264 * @private
62 */ 265 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /** @private */ 309 /** @private */
107 onRemoteEditAddressTap_: function() { 310 onRemoteEditAddressTap_: function() {
108 window.open(this.i18n('manageAddressesUrl')); 311 window.open(this.i18n('manageAddressesUrl'));
109 }, 312 },
110 313
111 /** 314 /**
112 * Handles tapping on the "Remove" address button. 315 * Handles tapping on the "Remove" address button.
113 * @private 316 * @private
114 */ 317 */
115 onMenuRemoveAddressTap_: function() { 318 onMenuRemoveAddressTap_: function() {
116 this.fire('remove-address', this.activeAddress); 319 this.autofillManager_.removeAddress(
320 /** @type {string} */(this.activeAddress.guid));
117 this.$.addressSharedMenu.close(); 321 this.$.addressSharedMenu.close();
118 }, 322 },
119 323
120 /** 324 /**
121 * Opens the credit card action menu. 325 * Opens the credit card action menu.
122 * @param {!Event} e The polymer event. 326 * @param {!Event} e The polymer event.
123 * @private 327 * @private
124 */ 328 */
125 onCreditCardMenuTap_: function(e) { 329 onCreditCardMenuTap_: function(e) {
126 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e); 330 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 /** @private */ 378 /** @private */
175 onRemoteEditCreditCardTap_: function() { 379 onRemoteEditCreditCardTap_: function() {
176 window.open(this.i18n('manageCreditCardsUrl')); 380 window.open(this.i18n('manageCreditCardsUrl'));
177 }, 381 },
178 382
179 /** 383 /**
180 * Handles tapping on the "Remove" credit card button. 384 * Handles tapping on the "Remove" credit card button.
181 * @private 385 * @private
182 */ 386 */
183 onMenuRemoveCreditCardTap_: function() { 387 onMenuRemoveCreditCardTap_: function() {
184 this.fire('remove-credit-card', this.activeCreditCard); 388 this.autofillManager_.removeCreditCard(
389 /** @type {string} */(this.activeCreditCard.guid));
185 this.$.creditCardSharedMenu.close(); 390 this.$.creditCardSharedMenu.close();
186 }, 391 },
187 392
188 /** 393 /**
189 * Handles tapping on the "Clear copy" button for cached credit cards. 394 * Handles tapping on the "Clear copy" button for cached credit cards.
190 * @private 395 * @private
191 */ 396 */
192 onMenuClearCreditCardTap_: function() { 397 onMenuClearCreditCardTap_: function() {
193 this.fire('clear-credit-card', this.activeCreditCard); 398 this.autofillManager_.clearCachedCreditCard(
399 /** @type {string} */(this.activeCreditCard.guid));
194 this.$.creditCardSharedMenu.close(); 400 this.$.creditCardSharedMenu.close();
195 }, 401 },
196 402
197 /** 403 /**
198 * Returns true if the list exists and has items. 404 * Returns true if the list exists and has items.
199 * @param {Array<Object>} list 405 * @param {Array<Object>} list
200 * @return {boolean} 406 * @return {boolean}
201 * @private 407 * @private
202 */ 408 */
203 hasSome_: function(list) { 409 hasSome_: function(list) {
204 return !!(list && list.length); 410 return !!(list && list.length);
205 }, 411 },
412
413 /**
414 * Listens for the save-address event, and calls the private API.
415 * @param {!Event} event
416 * @private
417 */
418 saveAddress_: function(event) {
419 this.autofillManager_.saveAddress(event.detail);
420 },
421
422 /**
423 * Listens for the save-credit-card event, and calls the private API.
424 * @param {!Event} event
425 * @private
426 */
427 saveCreditCard_: function(event) {
428 this.autofillManager_.saveCreditCard(event.detail);
429 },
206 }); 430 });
207 })(); 431 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/passwords_and_forms_page/passwords_and_forms_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698