OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @typedef {{ | 6 * @typedef {{ |
7 * 'title': string, | 7 * 'title': string, |
8 * 'tooltip': string, | 8 * 'tooltip': string, |
9 * 'url': string | 9 * 'url': string |
10 * }} | 10 * }} |
(...skipping 24 matching lines...) Expand all Loading... |
35 prefs: { | 35 prefs: { |
36 type: Object, | 36 type: Object, |
37 notify: true, | 37 notify: true, |
38 }, | 38 }, |
39 | 39 |
40 /** @type {settings.StartupUrlsPageBrowserProxy} */ | 40 /** @type {settings.StartupUrlsPageBrowserProxy} */ |
41 browserProxy_: Object, | 41 browserProxy_: Object, |
42 | 42 |
43 /** @private {string} */ | 43 /** @private {string} */ |
44 newUrl_: { | 44 newUrl_: { |
| 45 observer: 'newUrlChanged_', |
45 type: String, | 46 type: String, |
46 value: '', | 47 value: '', |
47 }, | 48 }, |
48 | 49 |
| 50 isNewUrlValid_: { |
| 51 type: Boolean, |
| 52 value: false, |
| 53 }, |
| 54 |
49 /** | 55 /** |
50 * Pages to load upon browser startup. | 56 * Pages to load upon browser startup. |
51 * @private {!Array<!StartupPageInfo>} | 57 * @private {!Array<!StartupPageInfo>} |
52 */ | 58 */ |
53 startupPages_: Array, | 59 startupPages_: Array, |
54 }, | 60 }, |
55 | 61 |
56 created: function() { | 62 created: function() { |
57 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); | 63 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); |
58 }, | 64 }, |
(...skipping 28 matching lines...) Expand all Loading... |
87 onUseCurrentPagesTap_: function() { | 93 onUseCurrentPagesTap_: function() { |
88 this.browserProxy_.useCurrentPages(); | 94 this.browserProxy_.useCurrentPages(); |
89 }, | 95 }, |
90 | 96 |
91 /** @private */ | 97 /** @private */ |
92 onCancelTap_: function() { | 98 onCancelTap_: function() { |
93 this.$.addUrlDialog.close(); | 99 this.$.addUrlDialog.close(); |
94 }, | 100 }, |
95 | 101 |
96 /** | 102 /** |
97 * @return {boolean} Whether tapping the Add button should be allowed. | 103 * @param {string} newUrl |
98 * @private | 104 * @private |
99 */ | 105 */ |
100 isAddEnabled_: function() { | 106 newUrlChanged_: function(newUrl) { |
101 return this.browserProxy_.canAddPage(this.newUrl_); | 107 if (this.validationResolver_) |
| 108 this.validationResolver_.reject(false); |
| 109 |
| 110 /** @type {?PromiseResolver<boolean>} */ |
| 111 this.validationResolver_ = this.browserProxy_.validateStartupPage(newUrl); |
| 112 |
| 113 this.validationResolver_.promise.then(function(isValid) { |
| 114 this.isNewUrlValid_ = isValid; |
| 115 this.validationResolver_ = null; |
| 116 }.bind(this), function() { |
| 117 // Squelchs console errors. |
| 118 }); |
102 }, | 119 }, |
103 | 120 |
104 /** @private */ | 121 /** @private */ |
105 onAddTap_: function() { | 122 onAddTap_: function() { |
106 assert(this.isAddEnabled_()); | 123 assert(this.isNewUrlValid_); |
107 this.browserProxy_.addStartupPage(this.newUrl_); | 124 this.browserProxy_.addStartupPage(this.newUrl_); |
108 this.$.addUrlDialog.close(); | 125 this.$.addUrlDialog.close(); |
109 }, | 126 }, |
110 | 127 |
111 /** | 128 /** |
112 * @param {!{model: !{index: number}}} e | 129 * @param {!{model: !{index: number}}} e |
113 * @private | 130 * @private |
114 */ | 131 */ |
115 onRemoveUrlTap_: function(e) { | 132 onRemoveUrlTap_: function(e) { |
116 this.browserProxy_.removeStartupPage(e.model.index); | 133 this.browserProxy_.removeStartupPage(e.model.index); |
117 }, | 134 }, |
118 }); | 135 }); |
OLD | NEW |