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 * @fileoverview 'settings-clear-browsing-data-dialog' allows the user to delete | 6 * @fileoverview 'settings-clear-browsing-data-dialog' allows the user to delete |
7 * browsing data that has been cached by Chromium. | 7 * browsing data that has been cached by Chromium. |
8 */ | 8 */ |
9 Polymer({ | 9 Polymer({ |
10 is: 'settings-clear-browsing-data-dialog', | 10 is: 'settings-clear-browsing-data-dialog', |
(...skipping 10 matching lines...) Expand all Loading... | |
21 }, | 21 }, |
22 | 22 |
23 /** | 23 /** |
24 * Results of browsing data counters, keyed by the suffix of | 24 * Results of browsing data counters, keyed by the suffix of |
25 * the corresponding data type deletion preference, as reported | 25 * the corresponding data type deletion preference, as reported |
26 * by the C++ side. | 26 * by the C++ side. |
27 * @private {!Object<string>} | 27 * @private {!Object<string>} |
28 */ | 28 */ |
29 counters_: { | 29 counters_: { |
30 type: Object, | 30 type: Object, |
31 value: { | 31 // Will be filled as results are reported. |
32 // Will be filled as results are reported. | 32 value: function() { |
33 return {}; | |
33 } | 34 } |
34 }, | 35 }, |
35 | 36 |
36 /** | 37 /** |
37 * List of options for the dropdown menu. | 38 * List of options for the dropdown menu. |
38 * @private {!DropdownMenuOptionList} | 39 * @private {!DropdownMenuOptionList} |
39 */ | 40 */ |
40 clearFromOptions_: { | 41 clearFromOptions_: { |
41 readOnly: true, | 42 readOnly: true, |
42 type: Array, | 43 type: Array, |
(...skipping 18 matching lines...) Expand all Loading... | |
61 value: function() { | 62 value: function() { |
62 return loadTimeData.getBoolean('isSupervised'); | 63 return loadTimeData.getBoolean('isSupervised'); |
63 }, | 64 }, |
64 }, | 65 }, |
65 | 66 |
66 /** @private */ | 67 /** @private */ |
67 showHistoryDeletionDialog_: { | 68 showHistoryDeletionDialog_: { |
68 type: Boolean, | 69 type: Boolean, |
69 value: false, | 70 value: false, |
70 }, | 71 }, |
72 | |
73 /** @private {!Array<ImportantSite>} */ | |
74 importantSites_: { | |
75 type: Array, | |
76 value: function() { | |
77 return []; | |
78 } | |
79 }, | |
80 | |
81 /** @private */ | |
82 importantSitesFlagEnabled_: { | |
83 type: Boolean, | |
84 value: function() { | |
85 return loadTimeData.getBoolean('importantSitesInCbd'); | |
86 }, | |
87 }, | |
88 | |
89 /** @private */ | |
90 showImportantSitesDialog_: { | |
91 type: Boolean, | |
92 value: false | |
93 }, | |
71 }, | 94 }, |
72 | 95 |
73 /** @private {settings.ClearBrowsingDataBrowserProxy} */ | 96 /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
74 browserProxy_: null, | 97 browserProxy_: null, |
75 | 98 |
76 /** @override */ | 99 /** @override */ |
77 ready: function() { | 100 ready: function() { |
78 this.$.clearFrom.menuOptions = this.clearFromOptions_; | 101 this.$.clearFrom.menuOptions = this.clearFromOptions_; |
79 this.addWebUIListener( | 102 this.addWebUIListener( |
80 'update-footer', | 103 'update-footer', |
81 this.updateFooter_.bind(this)); | 104 this.updateFooter_.bind(this)); |
82 this.addWebUIListener( | 105 this.addWebUIListener( |
83 'update-counter-text', | 106 'update-counter-text', |
84 this.updateCounterText_.bind(this)); | 107 this.updateCounterText_.bind(this)); |
85 }, | 108 }, |
86 | 109 |
87 /** @override */ | 110 /** @override */ |
88 attached: function() { | 111 attached: function() { |
89 this.browserProxy_ = | 112 this.browserProxy_ = |
90 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); | 113 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
91 this.browserProxy_.initialize().then(function() { | 114 var initializePromise = this.browserProxy_.initialize().then(function() { |
92 this.$.dialog.showModal(); | 115 this.$.clearBrowsingDataDialog.showModal(); |
93 }.bind(this)); | 116 }.bind(this)); |
117 | |
118 if (this.importantSitesFlagEnabled_) | |
119 initializePromise.then(this.fetchImportantSites_.bind(this)); | |
Dan Beam
2017/05/16 19:46:09
why can't this just be
this.browserProxy_.initial
dullweber
2017/05/17 09:57:37
It doesn't need to wait for the dialog but I thoug
| |
94 }, | 120 }, |
95 | 121 |
96 /** | 122 /** |
123 * @private | |
124 */ | |
125 fetchImportantSites_: function() { | |
126 this.browserProxy_.fetchImportantSites().then( | |
127 this.receiveImportantSites_.bind(this)); | |
128 }, | |
129 | |
130 /** | |
131 * @param {!ImportantSitesResponse} result | |
132 * @private | |
133 */ | |
134 receiveImportantSites_: function(result) { | |
135 this.set('importantSites_', result.importantSites); | |
136 }, | |
137 | |
138 /** | |
97 * Updates the footer to show only those sentences that are relevant to this | 139 * Updates the footer to show only those sentences that are relevant to this |
98 * user. | 140 * user. |
99 * @param {boolean} syncing Whether the user is syncing data. | 141 * @param {boolean} syncing Whether the user is syncing data. |
100 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other | 142 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other |
101 * forms of browsing history in their account. | 143 * forms of browsing history in their account. |
102 * @private | 144 * @private |
103 */ | 145 */ |
104 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { | 146 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { |
105 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; | 147 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; |
106 this.$.syncedDataSentence.hidden = !syncing; | 148 this.$.syncedDataSentence.hidden = !syncing; |
107 this.$.dialog.classList.add('fully-rendered'); | 149 this.$.clearBrowsingDataDialog.classList.add('fully-rendered'); |
108 }, | 150 }, |
109 | 151 |
110 /** | 152 /** |
111 * Updates the text of a browsing data counter corresponding to the given | 153 * Updates the text of a browsing data counter corresponding to the given |
112 * preference. | 154 * preference. |
113 * @param {string} prefName Browsing data type deletion preference. | 155 * @param {string} prefName Browsing data type deletion preference. |
114 * @param {string} text The text with which to update the counter | 156 * @param {string} text The text with which to update the counter |
115 * @private | 157 * @private |
116 */ | 158 */ |
117 updateCounterText_: function(prefName, text) { | 159 updateCounterText_: function(prefName, text) { |
118 // Data type deletion preferences are named "browser.clear_data.<datatype>". | 160 // Data type deletion preferences are named "browser.clear_data.<datatype>". |
119 // Strip the common prefix, i.e. use only "<datatype>". | 161 // Strip the common prefix, i.e. use only "<datatype>". |
120 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); | 162 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); |
121 this.set('counters_.' + assert(matches[1]), text); | 163 this.set('counters_.' + assert(matches[1]), text); |
122 }, | 164 }, |
123 | 165 |
124 /** | 166 /** |
167 * @return {boolean} Whether the ImportantSites dialog should be shown. | |
168 * @private | |
169 */ | |
170 shouldShowImportantSites_: function() { | |
171 if (!this.importantSitesFlagEnabled_) | |
172 return false; | |
173 if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked) | |
174 return false; | |
175 | |
176 var haveImportantSites = this.importantSites_.length > 0; | |
177 chrome.send( | |
178 'metricsHandler:recordBooleanHistogram', | |
179 ['History.ClearBrowsingData.ImportantDialogShown', haveImportantSites]); | |
180 return haveImportantSites; | |
181 }, | |
182 | |
183 /** | |
125 * Handles the tap on the Clear Data button. | 184 * Handles the tap on the Clear Data button. |
126 * @private | 185 * @private |
127 */ | 186 */ |
128 onClearBrowsingDataTap_: function() { | 187 onClearBrowsingDataTap_: function() { |
188 if (this.shouldShowImportantSites_()) { | |
189 this.showImportantSitesDialog_ = true; | |
190 this.$.clearBrowsingDataDialog.close(); | |
191 // Show important sites dialog after dom-if is applied. | |
192 this.async(function() { | |
193 this.$$('#importantSitesDialog').showModal(); | |
194 }); | |
195 } else { | |
196 this.clearBrowsingData_(); | |
197 } | |
198 }, | |
199 | |
200 /** | |
201 * Handles closing of the clear browsing data dialog. Stops the close | |
202 * event from propagating if another dialog is shown to prevent the | |
203 * privacy-page from closing this dialog. | |
204 * @private | |
205 */ | |
206 onClearBrowsingDataDialogClose_: function(event) { | |
207 if (this.showImportantSitesDialog_) | |
208 event.stopPropagation(); | |
209 }, | |
210 | |
211 /** | |
212 * Clears browsing data and maybe shows a history notice. | |
213 * @private | |
214 */ | |
215 clearBrowsingData_: function() { | |
129 this.clearingInProgress_ = true; | 216 this.clearingInProgress_ = true; |
130 | 217 |
131 this.browserProxy_.clearBrowsingData().then( | 218 this.browserProxy_.clearBrowsingData(this.importantSites_) |
132 /** | 219 .then( |
133 * @param {boolean} shouldShowNotice Whether we should show the notice | 220 /** |
134 * about other forms of browsing history before closing the dialog. | 221 * @param {boolean} shouldShowNotice Whether we should show the |
135 */ | 222 * notice about other forms of browsing history before closing the |
136 function(shouldShowNotice) { | 223 * dialog. |
137 this.clearingInProgress_ = false; | 224 */ |
138 this.showHistoryDeletionDialog_ = shouldShowNotice; | 225 function(shouldShowNotice) { |
226 this.clearingInProgress_ = false; | |
227 this.showHistoryDeletionDialog_ = shouldShowNotice; | |
228 if (!shouldShowNotice) | |
229 this.closeDialogs_(); | |
230 }.bind(this)); | |
231 }, | |
139 | 232 |
140 if (!shouldShowNotice) | 233 /** |
141 this.$.dialog.close(); | 234 * Closes the clear browsing data or important site dialog if they are open. |
142 }.bind(this)); | 235 * @private |
236 */ | |
237 closeDialogs_: function() { | |
238 if (this.$.clearBrowsingDataDialog.open) | |
239 this.$.clearBrowsingDataDialog.close(); | |
240 if (this.showImportantSitesDialog_) | |
241 this.$$('#importantSitesDialog').close(); | |
143 }, | 242 }, |
144 | 243 |
145 /** @private */ | 244 /** @private */ |
146 onCancelTap_: function() { | 245 onCancelTap_: function() { |
147 this.$.dialog.cancel(); | 246 this.$.clearBrowsingDataDialog.cancel(); |
148 }, | 247 }, |
149 | 248 |
150 /** | 249 /** |
250 * Handles the tap confirm button in important sites. | |
251 * @private | |
252 */ | |
253 onImportantSitesConfirmTap_: function() { | |
254 this.clearBrowsingData_(); | |
255 }, | |
256 | |
257 /** @private */ | |
258 onImportantSitesCancelTap_: function() { | |
259 this.$$('#importantSitesDialog').cancel(); | |
260 }, | |
261 | |
262 /** | |
151 * Handles the closing of the notice about other forms of browsing history. | 263 * Handles the closing of the notice about other forms of browsing history. |
152 * @private | 264 * @private |
153 */ | 265 */ |
154 onHistoryDeletionDialogClose_: function() { | 266 onHistoryDeletionDialogClose_: function() { |
155 this.showHistoryDeletionDialog_ = false; | 267 this.showHistoryDeletionDialog_ = false; |
156 this.$.dialog.close(); | 268 this.closeDialogs_(); |
157 } | 269 }, |
158 }); | 270 }); |
OLD | NEW |