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 // Will be filled as results are reported. |
32 // Will be filled as results are reported. | 41 value: function() { return {}; } |
33 } | |
34 }, | 42 }, |
35 | 43 |
36 /** | 44 /** |
37 * List of options for the dropdown menu. | 45 * List of options for the dropdown menu. |
38 * @private {!DropdownMenuOptionList} | 46 * @private {!DropdownMenuOptionList} |
39 */ | 47 */ |
40 clearFromOptions_: { | 48 clearFromOptions_: { |
41 readOnly: true, | 49 readOnly: true, |
42 type: Array, | 50 type: Array, |
43 value: [ | 51 value: [ |
44 {value: 0, name: loadTimeData.getString('clearDataHour')}, | 52 {value: 0, name: loadTimeData.getString('clearDataHour')}, |
45 {value: 1, name: loadTimeData.getString('clearDataDay')}, | 53 {value: 1, name: loadTimeData.getString('clearDataDay')}, |
46 {value: 2, name: loadTimeData.getString('clearDataWeek')}, | 54 {value: 2, name: loadTimeData.getString('clearDataWeek')}, |
47 {value: 3, name: loadTimeData.getString('clearData4Weeks')}, | 55 {value: 3, name: loadTimeData.getString('clearData4Weeks')}, |
48 {value: 4, name: loadTimeData.getString('clearDataEverything')}, | 56 {value: 4, name: loadTimeData.getString('clearDataEverything')}, |
49 ], | 57 ], |
50 }, | 58 }, |
51 | 59 |
52 /** @private */ | 60 /** @private */ |
53 clearingInProgress_: { | 61 clearingInProgress_: { |
54 type: Boolean, | 62 type: Boolean, |
55 value: false, | 63 value: false, |
56 }, | 64 }, |
57 | 65 |
58 /** @private */ | 66 /** @private */ |
59 showHistoryDeletionDialog_: { | 67 showHistoryDeletionDialog_: { |
60 type: Boolean, | 68 type: Boolean, |
61 value: false, | 69 value: false, |
62 }, | 70 }, |
| 71 |
| 72 /** @private {!Array<ImportantSite>} */ |
| 73 importantSites_: { |
| 74 type: Array, |
| 75 value: function() { return []; } |
| 76 }, |
| 77 |
| 78 /** @private */ |
| 79 importantSitesFlagEnabled_: { |
| 80 type: Boolean, |
| 81 value: false, |
| 82 }, |
| 83 |
63 }, | 84 }, |
64 | 85 |
65 /** @private {settings.ClearBrowsingDataBrowserProxy} */ | 86 /** @private {settings.ClearBrowsingDataBrowserProxy} */ |
66 browserProxy_: null, | 87 browserProxy_: null, |
67 | 88 |
68 /** @override */ | 89 /** @override */ |
69 ready: function() { | 90 ready: function() { |
70 this.$.clearFrom.menuOptions = this.clearFromOptions_; | 91 this.$.clearFrom.menuOptions = this.clearFromOptions_; |
71 this.addWebUIListener( | 92 this.addWebUIListener( |
72 'update-footer', | 93 'update-footer', |
73 this.updateFooter_.bind(this)); | 94 this.updateFooter_.bind(this)); |
74 this.addWebUIListener( | 95 this.addWebUIListener( |
75 'update-counter-text', | 96 'update-counter-text', |
76 this.updateCounterText_.bind(this)); | 97 this.updateCounterText_.bind(this)); |
77 }, | 98 }, |
78 | 99 |
79 /** @override */ | 100 /** @override */ |
80 attached: function() { | 101 attached: function() { |
81 this.browserProxy_ = | 102 this.browserProxy_ = |
82 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); | 103 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); |
83 this.browserProxy_.initialize().then(function() { | 104 this.browserProxy_.initialize() |
84 this.$.dialog.showModal(); | 105 .then(function() { |
85 }.bind(this)); | 106 this.$.dialog.showModal(); |
| 107 return this.browserProxy_.fetchImportantSites(); |
| 108 }.bind(this)) |
| 109 .then(this.receiveImportantSites.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 |