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: false, | |
85 }, | |
86 | |
87 /** @private */ | |
88 showImportantSitesDialog_: { | |
89 type: Boolean, | |
90 value: false | |
91 }, | |
71 }, | 92 }, |
72 | 93 |
73 /** @private {settings.ClearBrowsingDataBrowserProxy} */ | 94 /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
74 browserProxy_: null, | 95 browserProxy_: null, |
75 | 96 |
76 /** @override */ | 97 /** @override */ |
77 ready: function() { | 98 ready: function() { |
78 this.$.clearFrom.menuOptions = this.clearFromOptions_; | 99 this.$.clearFrom.menuOptions = this.clearFromOptions_; |
79 this.addWebUIListener( | 100 this.addWebUIListener( |
80 'update-footer', | 101 'update-footer', |
81 this.updateFooter_.bind(this)); | 102 this.updateFooter_.bind(this)); |
82 this.addWebUIListener( | 103 this.addWebUIListener( |
83 'update-counter-text', | 104 'update-counter-text', |
84 this.updateCounterText_.bind(this)); | 105 this.updateCounterText_.bind(this)); |
85 }, | 106 }, |
86 | 107 |
87 /** @override */ | 108 /** @override */ |
88 attached: function() { | 109 attached: function() { |
89 this.browserProxy_ = | 110 this.browserProxy_ = |
90 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); | 111 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
91 this.browserProxy_.initialize().then(function() { | 112 this.browserProxy_.initialize() |
92 this.$.dialog.showModal(); | 113 .then(function() { |
93 }.bind(this)); | 114 this.$.clearBrowsingDataDialog.showModal(); |
115 return this.browserProxy_.fetchImportantSites(); | |
116 }.bind(this)) | |
117 .then(this.receiveImportantSites_.bind(this)); | |
94 }, | 118 }, |
95 | 119 |
96 /** | 120 /** |
121 * @param {!ImportantSitesResponse} result | |
122 * @private | |
123 */ | |
124 receiveImportantSites_: function(result) { | |
125 this.importantSitesFlagEnabled_ = result.flagEnabled; | |
126 this.set('importantSites_', result.importantSites); | |
127 }, | |
128 | |
129 /** | |
97 * Updates the footer to show only those sentences that are relevant to this | 130 * Updates the footer to show only those sentences that are relevant to this |
98 * user. | 131 * user. |
99 * @param {boolean} syncing Whether the user is syncing data. | 132 * @param {boolean} syncing Whether the user is syncing data. |
100 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other | 133 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other |
101 * forms of browsing history in their account. | 134 * forms of browsing history in their account. |
102 * @private | 135 * @private |
103 */ | 136 */ |
104 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { | 137 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { |
105 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; | 138 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; |
106 this.$.syncedDataSentence.hidden = !syncing; | 139 this.$.syncedDataSentence.hidden = !syncing; |
107 this.$.dialog.classList.add('fully-rendered'); | 140 this.$.clearBrowsingDataDialog.classList.add('fully-rendered'); |
108 }, | 141 }, |
109 | 142 |
110 /** | 143 /** |
111 * Updates the text of a browsing data counter corresponding to the given | 144 * Updates the text of a browsing data counter corresponding to the given |
112 * preference. | 145 * preference. |
113 * @param {string} prefName Browsing data type deletion preference. | 146 * @param {string} prefName Browsing data type deletion preference. |
114 * @param {string} text The text with which to update the counter | 147 * @param {string} text The text with which to update the counter |
115 * @private | 148 * @private |
116 */ | 149 */ |
117 updateCounterText_: function(prefName, text) { | 150 updateCounterText_: function(prefName, text) { |
118 // Data type deletion preferences are named "browser.clear_data.<datatype>". | 151 // Data type deletion preferences are named "browser.clear_data.<datatype>". |
119 // Strip the common prefix, i.e. use only "<datatype>". | 152 // Strip the common prefix, i.e. use only "<datatype>". |
120 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); | 153 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); |
121 this.set('counters_.' + assert(matches[1]), text); | 154 this.set('counters_.' + assert(matches[1]), text); |
122 }, | 155 }, |
123 | 156 |
124 /** | 157 /** |
158 * @return {boolean} Whether the ImportantSites dialog should be shown. | |
159 * @private | |
160 */ | |
161 shouldShowImportantSites_: function() { | |
162 if (!this.importantSitesFlagEnabled_) | |
163 return false; | |
164 if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked) | |
165 return false; | |
166 | |
167 var haveImportantSites = this.importantSites_.length > 0; | |
168 chrome.send( | |
169 'metricsHandler:recordBooleanHistogram', | |
170 ['History.ClearBrowsingData.ImportantDialogShown', haveImportantSites]); | |
171 return haveImportantSites; | |
172 }, | |
173 | |
174 /** | |
125 * Handles the tap on the Clear Data button. | 175 * Handles the tap on the Clear Data button. |
126 * @private | 176 * @private |
127 */ | 177 */ |
128 onClearBrowsingDataTap_: function() { | 178 onClearBrowsingDataTap_: function() { |
179 if (this.shouldShowImportantSites_()) { | |
180 this.showImportantSitesDialog_ = true; | |
181 Polymer.dom.flush(); // Wait for dom-if. | |
Dan Beam
2017/05/16 03:25:25
i think using this.async() is preferred to Polymer
dullweber
2017/05/16 11:08:49
Done.
| |
182 this.$$('#importantSitesDialog').showModal(); | |
183 this.$.clearBrowsingDataDialog.close(); | |
184 } else { | |
185 this.clearBrowsingData_() | |
186 } | |
187 }, | |
188 | |
189 /** | |
190 * Handles closing of the clear browsing data dialog. Stops the close | |
191 * event from propagating if another dialog is shown to prevent the | |
192 * privacy-page from closing this dialog. | |
193 * @private | |
194 */ | |
195 onClearBrowsingDataDialogClose_: function(event) { | |
196 if (this.showImportantSitesDialog_) | |
197 event.stopPropagation() | |
198 }, | |
199 | |
200 /** | |
201 * Clears browsing data and maybe shows a history notice. | |
202 * @private | |
203 */ | |
204 clearBrowsingData_: function() { | |
129 this.clearingInProgress_ = true; | 205 this.clearingInProgress_ = true; |
130 | 206 |
131 this.browserProxy_.clearBrowsingData().then( | 207 this.browserProxy_.clearBrowsingData(this.importantSites_) |
132 /** | 208 .then( |
133 * @param {boolean} shouldShowNotice Whether we should show the notice | 209 /** |
134 * about other forms of browsing history before closing the dialog. | 210 * @param {boolean} shouldShowNotice Whether we should show the |
135 */ | 211 * notice about other forms of browsing history before closing the |
136 function(shouldShowNotice) { | 212 * dialog. |
137 this.clearingInProgress_ = false; | 213 */ |
138 this.showHistoryDeletionDialog_ = shouldShowNotice; | 214 function(shouldShowNotice) { |
215 this.clearingInProgress_ = false; | |
216 this.showHistoryDeletionDialog_ = shouldShowNotice; | |
139 | 217 |
140 if (!shouldShowNotice) | 218 if (!shouldShowNotice) { |
141 this.$.dialog.close(); | 219 this.closeDialogs_(); |
142 }.bind(this)); | 220 } |
Dan Beam
2017/05/16 03:25:25
nit: no curlies
dullweber
2017/05/16 11:08:49
Done.
| |
221 }.bind(this)); | |
222 }, | |
223 | |
224 /** | |
225 * Closes the clear browsing data or important site dialog if they are open. | |
226 * @private | |
227 */ | |
228 closeDialogs_: function() { | |
229 if (this.$.clearBrowsingDataDialog.open) | |
230 this.$.clearBrowsingDataDialog.close(); | |
231 if (this.showImportantSitesDialog_) | |
232 this.$$('#importantSitesDialog').close(); | |
143 }, | 233 }, |
144 | 234 |
145 /** @private */ | 235 /** @private */ |
146 onCancelTap_: function() { | 236 onCancelTap_: function() { |
147 this.$.dialog.cancel(); | 237 this.$.clearBrowsingDataDialog.cancel(); |
148 }, | 238 }, |
149 | 239 |
150 /** | 240 /** |
241 * Handles the tap confirm button in important sites. | |
242 * @private | |
243 */ | |
244 onImportantSitesConfirmTap_: function() { | |
245 this.clearBrowsingData_(); | |
246 }, | |
247 | |
248 /** @private */ | |
249 onImportantSitesCancelTap_: function() { | |
250 this.$$('#importantSitesDialog').cancel(); | |
251 }, | |
252 | |
253 /** | |
151 * Handles the closing of the notice about other forms of browsing history. | 254 * Handles the closing of the notice about other forms of browsing history. |
152 * @private | 255 * @private |
153 */ | 256 */ |
154 onHistoryDeletionDialogClose_: function() { | 257 onHistoryDeletionDialogClose_: function() { |
155 this.showHistoryDeletionDialog_ = false; | 258 this.showHistoryDeletionDialog_ = false; |
156 this.$.dialog.close(); | 259 this.closeDialogs_(); |
157 } | 260 }, |
158 }); | 261 }); |
OLD | NEW |