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