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

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 {?function(!Array<!AutofillManager.AddressEntry>)} */
197 setAddressesListener_: null,
198
199 /** @type {?function(!Array<!AutofillManager.CreditCardEntry>)} */
200 setCreditCardsListener_: null,
201
202 /** @override */
203 ready: function() {
204 // Create listener functions.
205 this.setAddressesListener_ = function(list) {
206 this.addresses = list;
207 }.bind(this);
208
209 this.setCreditCardsListener_ = function(list) {
210 this.creditCards = list;
211 }.bind(this);
212
213 // Set the managers. These can be overridden by tests.
214 this.autofillManager_ = AutofillManagerImpl.getInstance();
dpapad 2017/02/14 20:43:17 Similar issue as with the password_section.js is p
hcarmona 2017/02/15 00:13:34 Done.
215
216 // Request initial data.
217 this.autofillManager_.getAddressList(this.setAddressesListener_);
218 this.autofillManager_.getCreditCardList(this.setCreditCardsListener_);
219
220 // Listen for changes.
221 this.autofillManager_.addAddressListChangedListener(
222 this.setAddressesListener_);
223 this.autofillManager_.addCreditCardListChangedListener(
224 this.setCreditCardsListener_);
225 },
226
227 /** @override */
228 detached: function() {
229 this.autofillManager_.removeAddressListChangedListener(
230 this.setAddressesListener_);
231 this.autofillManager_.removeCreditCardListChangedListener(
232 this.setCreditCardsListener_);
233 },
234
49 /** 235 /**
50 * Formats the expiration date so it's displayed as MM/YYYY. 236 * Formats the expiration date so it's displayed as MM/YYYY.
51 * @param {!chrome.autofillPrivate.CreditCardEntry} item 237 * @param {!chrome.autofillPrivate.CreditCardEntry} item
52 * @return {string} 238 * @return {string}
53 */ 239 */
54 expiration_: function(item) { 240 expiration_: function(item) {
55 return item.expirationMonth + '/' + item.expirationYear; 241 return item.expirationMonth + '/' + item.expirationYear;
56 }, 242 },
57 243
58 /** 244 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /** @private */ 292 /** @private */
107 onRemoteEditAddressTap_: function() { 293 onRemoteEditAddressTap_: function() {
108 window.open(this.i18n('manageAddressesUrl')); 294 window.open(this.i18n('manageAddressesUrl'));
109 }, 295 },
110 296
111 /** 297 /**
112 * Handles tapping on the "Remove" address button. 298 * Handles tapping on the "Remove" address button.
113 * @private 299 * @private
114 */ 300 */
115 onMenuRemoveAddressTap_: function() { 301 onMenuRemoveAddressTap_: function() {
116 this.fire('remove-address', this.activeAddress); 302 this.autofillManager_.removeAddress(this.activeAddress.guid);
117 this.$.addressSharedMenu.close(); 303 this.$.addressSharedMenu.close();
118 }, 304 },
119 305
120 /** 306 /**
121 * Opens the credit card action menu. 307 * Opens the credit card action menu.
122 * @param {!Event} e The polymer event. 308 * @param {!Event} e The polymer event.
123 * @private 309 * @private
124 */ 310 */
125 onCreditCardMenuTap_: function(e) { 311 onCreditCardMenuTap_: function(e) {
126 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e); 312 var menuEvent = /** @type {!{model: !{item: !Object}}} */(e);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 /** @private */ 360 /** @private */
175 onRemoteEditCreditCardTap_: function() { 361 onRemoteEditCreditCardTap_: function() {
176 window.open(this.i18n('manageCreditCardsUrl')); 362 window.open(this.i18n('manageCreditCardsUrl'));
177 }, 363 },
178 364
179 /** 365 /**
180 * Handles tapping on the "Remove" credit card button. 366 * Handles tapping on the "Remove" credit card button.
181 * @private 367 * @private
182 */ 368 */
183 onMenuRemoveCreditCardTap_: function() { 369 onMenuRemoveCreditCardTap_: function() {
184 this.fire('remove-credit-card', this.activeCreditCard); 370 this.autofillManager_.removeCreditCard(this.activeCreditCard.guid);
185 this.$.creditCardSharedMenu.close(); 371 this.$.creditCardSharedMenu.close();
186 }, 372 },
187 373
188 /** 374 /**
189 * Handles tapping on the "Clear copy" button for cached credit cards. 375 * Handles tapping on the "Clear copy" button for cached credit cards.
190 * @private 376 * @private
191 */ 377 */
192 onMenuClearCreditCardTap_: function() { 378 onMenuClearCreditCardTap_: function() {
193 this.fire('clear-credit-card', this.activeCreditCard); 379 this.autofillManager_.clearCachedCreditCard(this.activeCreditCard.guid);
194 this.$.creditCardSharedMenu.close(); 380 this.$.creditCardSharedMenu.close();
195 }, 381 },
196 382
197 /** 383 /**
198 * Returns true if the list exists and has items. 384 * Returns true if the list exists and has items.
199 * @param {Array<Object>} list 385 * @param {Array<Object>} list
200 * @return {boolean} 386 * @return {boolean}
201 * @private 387 * @private
202 */ 388 */
203 hasSome_: function(list) { 389 hasSome_: function(list) {
204 return !!(list && list.length); 390 return !!(list && list.length);
205 }, 391 },
392
393 /**
394 * Listens for the save-address event, and calls the private API.
395 * @param {!Event} event
396 * @private
397 */
398 saveAddress_: function(event) {
399 this.autofillManager_.saveAddress(event.detail);
400 },
401
402 /**
403 * Listens for the save-credit-card event, and calls the private API.
404 * @param {!Event} event
405 * @private
406 */
407 saveCreditCard_: function(event) {
408 this.autofillManager_.saveCreditCard(event.detail);
409 },
206 }); 410 });
207 })(); 411 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698