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', |
11 | 11 |
12 behaviors: [WebUIListenerBehavior], | 12 behaviors: [WebUIListenerBehavior], |
13 | 13 |
14 properties: { | 14 properties: { |
15 /** | 15 /** |
16 * Preferences state. | 16 * Preferences state. |
17 */ | 17 */ |
18 prefs: { | 18 prefs: { |
19 type: Object, | 19 type: Object, |
20 notify: true, | 20 notify: true, |
21 }, | 21 }, |
22 | 22 |
23 /** | 23 /** |
24 * State of this dialog, either "clearBrowsingData" or "importantSites". | |
25 * @private | |
26 */ | |
27 dialogState_: { | |
28 type: String, | |
29 value: "clearBrowsingData", | |
30 }, | |
31 | |
32 /** | |
24 * Results of browsing data counters, keyed by the suffix of | 33 * Results of browsing data counters, keyed by the suffix of |
25 * the corresponding data type deletion preference, as reported | 34 * the corresponding data type deletion preference, as reported |
26 * by the C++ side. | 35 * by the C++ side. |
27 * @private {!Object<string>} | 36 * @private {!Object<string>} |
28 */ | 37 */ |
29 counters_: { | 38 counters_: { |
30 type: Object, | 39 type: Object, |
31 value: { | 40 value: { |
32 // Will be filled as results are reported. | 41 // Will be filled as results are reported. |
33 } | 42 } |
(...skipping 19 matching lines...) Expand all Loading... | |
53 clearingInProgress_: { | 62 clearingInProgress_: { |
54 type: Boolean, | 63 type: Boolean, |
55 value: false, | 64 value: false, |
56 }, | 65 }, |
57 | 66 |
58 /** @private */ | 67 /** @private */ |
59 showHistoryDeletionDialog_: { | 68 showHistoryDeletionDialog_: { |
60 type: Boolean, | 69 type: Boolean, |
61 value: false, | 70 value: false, |
62 }, | 71 }, |
72 | |
73 /** @private {!Array<ImportantSite>} */ | |
74 importantSites_: { | |
75 type: Array, | |
76 value: [], | |
77 }, | |
63 }, | 78 }, |
64 | 79 |
65 /** @private {settings.ClearBrowsingDataBrowserProxy} */ | 80 /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
66 browserProxy_: null, | 81 browserProxy_: null, |
67 | 82 |
68 /** @override */ | 83 /** @override */ |
69 ready: function() { | 84 ready: function() { |
70 this.$.clearFrom.menuOptions = this.clearFromOptions_; | 85 this.$.clearFrom.menuOptions = this.clearFromOptions_; |
71 this.addWebUIListener( | 86 this.addWebUIListener( |
72 'update-footer', | 87 'update-footer', |
73 this.updateFooter_.bind(this)); | 88 this.updateFooter_.bind(this)); |
74 this.addWebUIListener( | 89 this.addWebUIListener( |
75 'update-counter-text', | 90 'update-counter-text', |
76 this.updateCounterText_.bind(this)); | 91 this.updateCounterText_.bind(this)); |
77 }, | 92 }, |
78 | 93 |
79 /** @override */ | 94 /** @override */ |
80 attached: function() { | 95 attached: function() { |
81 this.browserProxy_ = | 96 this.browserProxy_ = |
82 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); | 97 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
83 this.browserProxy_.initialize().then(function() { | 98 this.browserProxy_.initialize().then(function() { |
84 this.$.dialog.showModal(); | 99 this.$.dialog.showModal(); |
100 this.browserProxy_.fetchImportantSites().then( | |
101 this.receiveImportantSites.bind(this)); | |
85 }.bind(this)); | 102 }.bind(this)); |
86 }, | 103 }, |
87 | 104 |
88 /** | 105 /** |
106 * @param {!ImportantSitesResponse} result | |
107 * @private | |
108 */ | |
109 receiveImportantSites: function(result) { | |
110 if (result.dialogDisabled) { | |
111 this.set('importantSites_', []); | |
112 } else { | |
113 this.set('importantSites_', result.importantSites); | |
114 } | |
115 }, | |
116 | |
117 /** | |
89 * Updates the footer to show only those sentences that are relevant to this | 118 * Updates the footer to show only those sentences that are relevant to this |
90 * user. | 119 * user. |
91 * @param {boolean} syncing Whether the user is syncing data. | 120 * @param {boolean} syncing Whether the user is syncing data. |
92 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other | 121 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other |
93 * forms of browsing history in their account. | 122 * forms of browsing history in their account. |
94 * @private | 123 * @private |
95 */ | 124 */ |
96 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { | 125 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { |
97 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; | 126 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; |
98 this.$.syncedDataSentence.hidden = !syncing; | 127 this.$.syncedDataSentence.hidden = !syncing; |
99 this.$.dialog.classList.add('fully-rendered'); | 128 this.$.dialog.classList.add('fully-rendered'); |
100 }, | 129 }, |
101 | 130 |
102 /** | 131 /** |
103 * Updates the text of a browsing data counter corresponding to the given | 132 * Updates the text of a browsing data counter corresponding to the given |
104 * preference. | 133 * preference. |
105 * @param {string} prefName Browsing data type deletion preference. | 134 * @param {string} prefName Browsing data type deletion preference. |
106 * @param {string} text The text with which to update the counter | 135 * @param {string} text The text with which to update the counter |
107 * @private | 136 * @private |
108 */ | 137 */ |
109 updateCounterText_: function(prefName, text) { | 138 updateCounterText_: function(prefName, text) { |
110 // Data type deletion preferences are named "browser.clear_data.<datatype>". | 139 // Data type deletion preferences are named "browser.clear_data.<datatype>". |
111 // Strip the common prefix, i.e. use only "<datatype>". | 140 // Strip the common prefix, i.e. use only "<datatype>". |
112 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); | 141 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); |
113 this.set('counters_.' + assert(matches[1]), text); | 142 this.set('counters_.' + assert(matches[1]), text); |
114 }, | 143 }, |
115 | 144 |
116 /** | 145 /** |
146 * @param {string} currentDialogState The current dialog state. | |
147 * @return {boolean} Whether this is the clear browsing data dialog. | |
148 * @private | |
149 */ | |
150 isClearBrowsingDataDialog_: function(currentDialogState) { | |
151 return currentDialogState == "clearBrowsingData"; | |
152 }, | |
153 | |
154 /** | |
155 * @param {string} currentDialogState The current dialog state. | |
156 * @return {boolean} Whether this is the important sites dialog. | |
157 * @private | |
158 */ | |
159 isImportantSitesDialog_: function(currentDialogState) { | |
160 return currentDialogState == "importantSites"; | |
161 }, | |
162 | |
163 /** @private */ | |
164 shouldShowImportantSites_: function() { | |
165 if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked) { | |
166 return false; | |
167 } | |
168 return this.isClearBrowsingDataDialog_(this.dialogState_) && | |
dmurph
2017/03/06 21:16:48
Please also reference
https://cs.chromium.org/chro
dullweber
2017/03/07 12:24:34
I'm already passing the result of this method to j
| |
169 this.importantSites_.length; | |
170 // TODO(dullweber): Log Histogram? | |
171 }, | |
172 | |
173 /** | |
117 * Handles the tap on the Clear Data button. | 174 * Handles the tap on the Clear Data button. |
118 * @private | 175 * @private |
119 */ | 176 */ |
120 onClearBrowsingDataTap_: function() { | 177 onClearBrowsingDataTap_: function() { |
178 if (this.shouldShowImportantSites_()) { | |
179 this.dialogState_ = "importantSites"; | |
180 return | |
181 } | |
182 | |
121 this.clearingInProgress_ = true; | 183 this.clearingInProgress_ = true; |
122 | 184 |
123 this.browserProxy_.clearBrowsingData().then( | 185 this.browserProxy_.clearBrowsingData(this.importantSites_).then( |
124 /** | 186 /** |
125 * @param {boolean} shouldShowNotice Whether we should show the notice | 187 * @param {boolean} shouldShowNotice Whether we should show the notice |
126 * about other forms of browsing history before closing the dialog. | 188 * about other forms of browsing history before closing the dialog. |
127 */ | 189 */ |
128 function(shouldShowNotice) { | 190 function(shouldShowNotice) { |
129 this.clearingInProgress_ = false; | 191 this.clearingInProgress_ = false; |
130 this.showHistoryDeletionDialog_ = shouldShowNotice; | 192 this.showHistoryDeletionDialog_ = shouldShowNotice; |
131 | 193 |
132 if (!shouldShowNotice) | 194 if (!shouldShowNotice) |
133 this.$.dialog.close(); | 195 this.$.dialog.close(); |
134 }.bind(this)); | 196 }.bind(this)); |
135 }, | 197 }, |
136 | 198 |
137 /** @private */ | 199 /** @private */ |
138 onCancelTap_: function() { | 200 onCancelTap_: function() { |
139 this.$.dialog.cancel(); | 201 this.$.dialog.cancel(); |
140 }, | 202 }, |
141 | 203 |
142 /** | 204 /** |
143 * Handles the closing of the notice about other forms of browsing history. | 205 * Handles the closing of the notice about other forms of browsing history. |
144 * @private | 206 * @private |
145 */ | 207 */ |
146 onHistoryDeletionDialogClose_: function() { | 208 onHistoryDeletionDialogClose_: function() { |
147 this.showHistoryDeletionDialog_ = false; | 209 this.showHistoryDeletionDialog_ = false; |
148 this.$.dialog.close(); | 210 this.$.dialog.close(); |
149 } | 211 } |
150 }); | 212 }); |
OLD | NEW |