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

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: Feedback 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
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 assert(guid);
115 chrome.autofillPrivate.removeEntry(guid);
116 },
117
118 /** @override */
119 addCreditCardListChangedListener: function(listener) {
120 chrome.autofillPrivate.onCreditCardListChanged.addListener(listener);
121 },
122
123 /** @override */
124 removeCreditCardListChangedListener: function(listener) {
125 chrome.autofillPrivate.onCreditCardListChanged.removeListener(listener);
126 },
127
128 /** @override */
129 getCreditCardList: function(callback) {
130 chrome.autofillPrivate.getCreditCardList(callback);
131 },
132
133 /** @override */
134 removeCreditCard: function(guid) {
135 assert(guid);
136 chrome.autofillPrivate.removeEntry(guid);
137 },
138
139 /** @override */
140 clearCachedCreditCard: function(guid) {
141 assert(guid);
142 chrome.autofillPrivate.maskCreditCard(guid);
143 },
144
145 /** @override */
146 saveCreditCard: function(creditCard) {
147 chrome.autofillPrivate.saveCreditCard(creditCard);
148 }
149 };
150
9 (function() { 151 (function() {
10 'use strict'; 152 'use strict';
11 153
12 Polymer({ 154 Polymer({
13 is: 'settings-autofill-section', 155 is: 'settings-autofill-section',
14 156
15 behaviors: [I18nBehavior], 157 behaviors: [I18nBehavior],
16 158
17 properties: { 159 properties: {
18 /** 160 /**
19 * An array of saved addresses. 161 * An array of saved addresses.
20 * @type {!Array<!chrome.autofillPrivate.AddressEntry>} 162 * @type {!Array<!AutofillManager.AddressEntry>}
21 */ 163 */
22 addresses: Array, 164 addresses: Array,
23 165
24 /** 166 /**
25 * The model for any address related action menus or dialogs. 167 * The model for any address related action menus or dialogs.
26 * @private {?chrome.autofillPrivate.AddressEntry} 168 * @private {?chrome.autofillPrivate.AddressEntry}
27 */ 169 */
28 activeAddress: Object, 170 activeAddress: Object,
29 171
30 /** @private */ 172 /** @private */
31 showAddressDialog_: Boolean, 173 showAddressDialog_: Boolean,
32 174
33 /** 175 /**
34 * An array of saved credit cards. 176 * An array of saved credit cards.
35 * @type {!Array<!chrome.autofillPrivate.CreditCardEntry>} 177 * @type {!Array<!AutofillManager.CreditCardEntry>}
36 */ 178 */
37 creditCards: Array, 179 creditCards: Array,
38 180
39 /** 181 /**
40 * The model for any credit card related action menus or dialogs. 182 * The model for any credit card related action menus or dialogs.
41 * @private {?chrome.autofillPrivate.CreditCardEntry} 183 * @private {?chrome.autofillPrivate.CreditCardEntry}
42 */ 184 */
43 activeCreditCard: Object, 185 activeCreditCard: Object,
44 186
45 /** @private */ 187 /** @private */
46 showCreditCardDialog_: Boolean, 188 showCreditCardDialog_: Boolean,
47 }, 189 },
48 190
191 listeners: {
192 'save-address': 'saveAddress_',
193 'save-credit-card': 'saveCreditCard_',
194 },
195
196 /** @type {AutofillManager} */
dpapad 2017/02/15 02:01:38 @private
hcarmona 2017/02/15 18:18:23 Done. Here, and elsewhere.
197 autofillManager_: null,
198
199 /** @type {?function(!Array<!AutofillManager.AddressEntry>)} */
200 setAddressesListener_: null,
201
202 /** @type {?function(!Array<!AutofillManager.CreditCardEntry>)} */
203 setCreditCardsListener_: null,
204
205 /** @override */
206 ready: function() {
207 // Create listener functions.
208 /** @type {function(!Array<!AutofillManager.AddressEntry>)} */
209 var setAddressesListener = function(list) {
210 this.addresses = list;
211 }.bind(this);
212
213 /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */
214 var setCreditCardsListener = function(list) {
215 this.creditCards = list;
216 }.bind(this);
217
218 // Remember the bound reference in order to detach.
219 this.setAddressesListener_ = setAddressesListener;
dpapad 2017/02/15 02:01:38 Nit: Are the local vars setAddressesListener and s
hcarmona 2017/02/15 18:18:23 We can... but that will necessitate casting to the
220 this.setCreditCardsListener_ = setCreditCardsListener;
221
222 // Set the managers. These can be overridden by tests.
223 this.autofillManager_ = AutofillManagerImpl.getInstance();
224
225 // Request initial data.
226 this.autofillManager_.getAddressList(setAddressesListener);
227 this.autofillManager_.getCreditCardList(setCreditCardsListener);
228
229 // Listen for changes.
230 this.autofillManager_.addAddressListChangedListener(setAddressesListener);
231 this.autofillManager_.addCreditCardListChangedListener(
232 setCreditCardsListener);
233 },
234
235 /** @override */
236 detached: function() {
237 this.autofillManager_.removeAddressListChangedListener(
238 /** @type {function(!Array<!AutofillManager.AddressEntry>)} */(
239 this.setAddressesListener_));
240 this.autofillManager_.removeCreditCardListChangedListener(
241 /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */(
242 this.setCreditCardsListener_));
243 },
244
49 /** 245 /**
50 * Formats the expiration date so it's displayed as MM/YYYY. 246 * Formats the expiration date so it's displayed as MM/YYYY.
51 * @param {!chrome.autofillPrivate.CreditCardEntry} item 247 * @param {!chrome.autofillPrivate.CreditCardEntry} item
52 * @return {string} 248 * @return {string}
53 */ 249 */
54 expiration_: function(item) { 250 expiration_: function(item) {
55 return item.expirationMonth + '/' + item.expirationYear; 251 return item.expirationMonth + '/' + item.expirationYear;
56 }, 252 },
57 253
58 /** 254 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /** @private */ 302 /** @private */
107 onRemoteEditAddressTap_: function() { 303 onRemoteEditAddressTap_: function() {
108 window.open(this.i18n('manageAddressesUrl')); 304 window.open(this.i18n('manageAddressesUrl'));
109 }, 305 },
110 306
111 /** 307 /**
112 * Handles tapping on the "Remove" address button. 308 * Handles tapping on the "Remove" address button.
113 * @private 309 * @private
114 */ 310 */
115 onMenuRemoveAddressTap_: function() { 311 onMenuRemoveAddressTap_: function() {
116 this.fire('remove-address', this.activeAddress); 312 this.autofillManager_.removeAddress(
313 /** @type {string} */(this.activeAddress.guid));
117 this.$.addressSharedMenu.close(); 314 this.$.addressSharedMenu.close();
118 }, 315 },
119 316
120 /** 317 /**
121 * Opens the credit card action menu. 318 * Opens the credit card action menu.
122 * @param {!Event} e The polymer event. 319 * @param {!Event} e The polymer event.
123 * @private 320 * @private
124 */ 321 */
125 onCreditCardMenuTap_: function(e) { 322 onCreditCardMenuTap_: function(e) {
126 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e); 323 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 /** @private */ 371 /** @private */
175 onRemoteEditCreditCardTap_: function() { 372 onRemoteEditCreditCardTap_: function() {
176 window.open(this.i18n('manageCreditCardsUrl')); 373 window.open(this.i18n('manageCreditCardsUrl'));
177 }, 374 },
178 375
179 /** 376 /**
180 * Handles tapping on the "Remove" credit card button. 377 * Handles tapping on the "Remove" credit card button.
181 * @private 378 * @private
182 */ 379 */
183 onMenuRemoveCreditCardTap_: function() { 380 onMenuRemoveCreditCardTap_: function() {
184 this.fire('remove-credit-card', this.activeCreditCard); 381 this.autofillManager_.removeCreditCard(
382 /** @type {string} */(this.activeCreditCard.guid));
185 this.$.creditCardSharedMenu.close(); 383 this.$.creditCardSharedMenu.close();
186 }, 384 },
187 385
188 /** 386 /**
189 * Handles tapping on the "Clear copy" button for cached credit cards. 387 * Handles tapping on the "Clear copy" button for cached credit cards.
190 * @private 388 * @private
191 */ 389 */
192 onMenuClearCreditCardTap_: function() { 390 onMenuClearCreditCardTap_: function() {
193 this.fire('clear-credit-card', this.activeCreditCard); 391 this.autofillManager_.clearCachedCreditCard(
392 /** @type {string} */(this.activeCreditCard.guid));
194 this.$.creditCardSharedMenu.close(); 393 this.$.creditCardSharedMenu.close();
195 }, 394 },
196 395
197 /** 396 /**
198 * Returns true if the list exists and has items. 397 * Returns true if the list exists and has items.
199 * @param {Array<Object>} list 398 * @param {Array<Object>} list
200 * @return {boolean} 399 * @return {boolean}
201 * @private 400 * @private
202 */ 401 */
203 hasSome_: function(list) { 402 hasSome_: function(list) {
204 return !!(list && list.length); 403 return !!(list && list.length);
205 }, 404 },
405
406 /**
407 * Listens for the save-address event, and calls the private API.
408 * @param {!Event} event
409 * @private
410 */
411 saveAddress_: function(event) {
412 this.autofillManager_.saveAddress(event.detail);
413 },
414
415 /**
416 * Listens for the save-credit-card event, and calls the private API.
417 * @param {!Event} event
418 * @private
419 */
420 saveCreditCard_: function(event) {
421 this.autofillManager_.saveCreditCard(event.detail);
422 },
206 }); 423 });
207 })(); 424 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698