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. |
dullweber
2017/04/07 09:39:21
This formatting by "git cl format --js" seems odd,
dschuyler
2017/04/07 22:57:34
I agree that's weird and I would expect a two spac
dullweber
2017/04/10 10:59:50
I submitted a bug for clang-format
| |
33 } | 42 } |
dschuyler
2017/04/07 22:57:34
Hey that helps point out another issue that I miss
dullweber
2017/04/10 10:59:50
Ah, that looks interesting, thanks. I guess the sa
| |
34 }, | 43 }, |
35 | 44 |
36 /** | 45 /** |
37 * List of options for the dropdown menu. | 46 * List of options for the dropdown menu. |
38 * @private {!DropdownMenuOptionList} | 47 * @private {!DropdownMenuOptionList} |
39 */ | 48 */ |
40 clearFromOptions_: { | 49 clearFromOptions_: { |
41 readOnly: true, | 50 readOnly: true, |
42 type: Array, | 51 type: Array, |
43 value: [ | 52 value: [ |
44 {value: 0, name: loadTimeData.getString('clearDataHour')}, | 53 {value: 0, name: loadTimeData.getString('clearDataHour')}, |
45 {value: 1, name: loadTimeData.getString('clearDataDay')}, | 54 {value: 1, name: loadTimeData.getString('clearDataDay')}, |
46 {value: 2, name: loadTimeData.getString('clearDataWeek')}, | 55 {value: 2, name: loadTimeData.getString('clearDataWeek')}, |
47 {value: 3, name: loadTimeData.getString('clearData4Weeks')}, | 56 {value: 3, name: loadTimeData.getString('clearData4Weeks')}, |
48 {value: 4, name: loadTimeData.getString('clearDataEverything')}, | 57 {value: 4, name: loadTimeData.getString('clearDataEverything')}, |
49 ], | 58 ], |
50 }, | 59 }, |
51 | 60 |
52 /** @private */ | 61 /** @private */ |
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 }, | |
78 | |
79 /** @private */ | |
80 importantSitesFlagEnabled_: { | |
81 type: Boolean, | |
82 value: false, | |
83 }, | |
84 | |
63 }, | 85 }, |
64 | 86 |
65 /** @private {settings.ClearBrowsingDataBrowserProxy} */ | 87 /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
66 browserProxy_: null, | 88 browserProxy_: null, |
67 | 89 |
68 /** @override */ | 90 /** @override */ |
69 ready: function() { | 91 ready: function() { |
70 this.$.clearFrom.menuOptions = this.clearFromOptions_; | 92 this.$.clearFrom.menuOptions = this.clearFromOptions_; |
71 this.addWebUIListener( | 93 this.addWebUIListener( |
72 'update-footer', | 94 'update-footer', |
73 this.updateFooter_.bind(this)); | 95 this.updateFooter_.bind(this)); |
74 this.addWebUIListener( | 96 this.addWebUIListener( |
75 'update-counter-text', | 97 'update-counter-text', |
76 this.updateCounterText_.bind(this)); | 98 this.updateCounterText_.bind(this)); |
77 }, | 99 }, |
78 | 100 |
79 /** @override */ | 101 /** @override */ |
80 attached: function() { | 102 attached: function() { |
81 this.browserProxy_ = | 103 this.browserProxy_ = |
82 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); | 104 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
83 this.browserProxy_.initialize().then(function() { | 105 this.browserProxy_.initialize().then(function() { |
84 this.$.dialog.showModal(); | 106 this.$.dialog.showModal(); |
107 this.browserProxy_.fetchImportantSites().then( | |
108 this.receiveImportantSites.bind(this)); | |
85 }.bind(this)); | 109 }.bind(this)); |
86 }, | 110 }, |
87 | 111 |
88 /** | 112 /** |
113 * @param {!ImportantSitesResponse} result | |
114 * @private | |
115 */ | |
116 receiveImportantSites: function(result) { | |
117 this.importantSitesFlagEnabled_ = result.flagEnabled; | |
118 this.set('importantSites_', result.importantSites); | |
119 }, | |
120 | |
121 /** | |
89 * Updates the footer to show only those sentences that are relevant to this | 122 * Updates the footer to show only those sentences that are relevant to this |
90 * user. | 123 * user. |
91 * @param {boolean} syncing Whether the user is syncing data. | 124 * @param {boolean} syncing Whether the user is syncing data. |
92 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other | 125 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other |
93 * forms of browsing history in their account. | 126 * forms of browsing history in their account. |
94 * @private | 127 * @private |
95 */ | 128 */ |
96 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { | 129 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { |
97 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; | 130 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; |
98 this.$.syncedDataSentence.hidden = !syncing; | 131 this.$.syncedDataSentence.hidden = !syncing; |
99 this.$.dialog.classList.add('fully-rendered'); | 132 this.$.dialog.classList.add('fully-rendered'); |
100 }, | 133 }, |
101 | 134 |
102 /** | 135 /** |
103 * Updates the text of a browsing data counter corresponding to the given | 136 * Updates the text of a browsing data counter corresponding to the given |
104 * preference. | 137 * preference. |
105 * @param {string} prefName Browsing data type deletion preference. | 138 * @param {string} prefName Browsing data type deletion preference. |
106 * @param {string} text The text with which to update the counter | 139 * @param {string} text The text with which to update the counter |
107 * @private | 140 * @private |
108 */ | 141 */ |
109 updateCounterText_: function(prefName, text) { | 142 updateCounterText_: function(prefName, text) { |
110 // Data type deletion preferences are named "browser.clear_data.<datatype>". | 143 // Data type deletion preferences are named "browser.clear_data.<datatype>". |
111 // Strip the common prefix, i.e. use only "<datatype>". | 144 // Strip the common prefix, i.e. use only "<datatype>". |
112 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); | 145 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); |
113 this.set('counters_.' + assert(matches[1]), text); | 146 this.set('counters_.' + assert(matches[1]), text); |
114 }, | 147 }, |
115 | 148 |
116 /** | 149 /** |
150 * @param {string} currentDialogState The current dialog state. | |
151 * @return {boolean} Whether this is the clear browsing data dialog. | |
152 * @private | |
153 */ | |
154 isClearBrowsingDataDialog_: function(currentDialogState) { | |
155 return currentDialogState == 'clearBrowsingData'; | |
156 }, | |
157 | |
158 /** | |
159 * @param {string} currentDialogState The current dialog state. | |
160 * @return {boolean} Whether this is the important sites dialog. | |
161 * @private | |
162 */ | |
163 isImportantSitesDialog_: function(currentDialogState) { | |
164 return currentDialogState == 'importantSites'; | |
165 }, | |
166 | |
167 /** @private */ | |
168 shouldShowImportantSites_: function() { | |
169 if (this.isImportantSitesDialog_(this.dialogState_)) | |
170 return false; | |
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 /** | |
117 * Handles the tap on the Clear Data button. | 184 * Handles the tap on the Clear Data button. |
118 * @private | 185 * @private |
119 */ | 186 */ |
120 onClearBrowsingDataTap_: function() { | 187 onClearBrowsingDataTap_: function() { |
188 if (this.shouldShowImportantSites_()) { | |
189 this.dialogState_ = 'importantSites'; | |
190 return; | |
191 } | |
192 | |
121 this.clearingInProgress_ = true; | 193 this.clearingInProgress_ = true; |
122 | 194 |
123 this.browserProxy_.clearBrowsingData().then( | 195 this.browserProxy_.clearBrowsingData(this.importantSites_) |
124 /** | 196 .then( |
125 * @param {boolean} shouldShowNotice Whether we should show the notice | 197 /** |
126 * about other forms of browsing history before closing the dialog. | 198 * @param {boolean} shouldShowNotice Whether we should show the |
127 */ | 199 * notice about other forms of browsing history before closing the |
128 function(shouldShowNotice) { | 200 * dialog. |
129 this.clearingInProgress_ = false; | 201 */ |
130 this.showHistoryDeletionDialog_ = shouldShowNotice; | 202 function(shouldShowNotice) { |
203 this.clearingInProgress_ = false; | |
204 this.showHistoryDeletionDialog_ = shouldShowNotice; | |
131 | 205 |
132 if (!shouldShowNotice) | 206 if (!shouldShowNotice) |
133 this.$.dialog.close(); | 207 this.$.dialog.close(); |
134 }.bind(this)); | 208 }.bind(this)); |
135 }, | 209 }, |
136 | 210 |
137 /** @private */ | 211 /** @private */ |
138 onCancelTap_: function() { | 212 onCancelTap_: function() { |
139 this.$.dialog.cancel(); | 213 this.$.dialog.cancel(); |
140 }, | 214 }, |
141 | 215 |
142 /** | 216 /** |
143 * Handles the closing of the notice about other forms of browsing history. | 217 * Handles the closing of the notice about other forms of browsing history. |
144 * @private | 218 * @private |
145 */ | 219 */ |
146 onHistoryDeletionDialogClose_: function() { | 220 onHistoryDeletionDialogClose_: function() { |
147 this.showHistoryDeletionDialog_ = false; | 221 this.showHistoryDeletionDialog_ = false; |
148 this.$.dialog.close(); | 222 this.$.dialog.close(); |
149 } | 223 } |
150 }); | 224 }); |
OLD | NEW |