Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/browser/resources/settings/clear_browsing_data_dialog/clear_browsing_data_dialog.js

Issue 2716333002: Implement important sites dialog for desktop. (Closed)
Patch Set: fix comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 10 matching lines...) Expand all
53 clearingInProgress_: { 54 clearingInProgress_: {
54 type: Boolean, 55 type: Boolean,
55 value: false, 56 value: false,
56 }, 57 },
57 58
58 /** @private */ 59 /** @private */
59 showHistoryDeletionDialog_: { 60 showHistoryDeletionDialog_: {
60 type: Boolean, 61 type: Boolean,
61 value: false, 62 value: false,
62 }, 63 },
64
65 /** @private {!Array<ImportantSite>} */
66 importantSites_: {
67 type: Array,
68 value: function() {
69 return [];
70 }
71 },
72
73 /** @private */
74 importantSitesFlagEnabled_: {
75 type: Boolean,
76 value: false,
77 },
78
Dan Beam 2017/05/09 19:23:18 remove extra \n
dullweber 2017/05/11 13:13:47 Done.
63 }, 79 },
64 80
65 /** @private {settings.ClearBrowsingDataBrowserProxy} */ 81 /** @private {settings.ClearBrowsingDataBrowserProxy} */
66 browserProxy_: null, 82 browserProxy_: null,
67 83
68 /** @override */ 84 /** @override */
69 ready: function() { 85 ready: function() {
70 this.$.clearFrom.menuOptions = this.clearFromOptions_; 86 this.$.clearFrom.menuOptions = this.clearFromOptions_;
71 this.addWebUIListener( 87 this.addWebUIListener(
72 'update-footer', 88 'update-footer',
73 this.updateFooter_.bind(this)); 89 this.updateFooter_.bind(this));
74 this.addWebUIListener( 90 this.addWebUIListener(
75 'update-counter-text', 91 'update-counter-text',
76 this.updateCounterText_.bind(this)); 92 this.updateCounterText_.bind(this));
77 }, 93 },
78 94
79 /** @override */ 95 /** @override */
80 attached: function() { 96 attached: function() {
81 this.browserProxy_ = 97 this.browserProxy_ =
82 settings.ClearBrowsingDataBrowserProxyImpl.getInstance(); 98 settings.ClearBrowsingDataBrowserProxyImpl.getInstance();
83 this.browserProxy_.initialize().then(function() { 99 this.browserProxy_.initialize()
84 this.$.dialog.showModal(); 100 .then(function() {
85 }.bind(this)); 101 this.$.clearBrowsingDataDialog.showModal();
102 return this.browserProxy_.fetchImportantSites();
103 }.bind(this))
104 .then(this.receiveImportantSites_.bind(this));
86 }, 105 },
87 106
88 /** 107 /**
108 * @param {!ImportantSitesResponse} result
109 * @private
110 */
111 receiveImportantSites_: function(result) {
112 this.importantSitesFlagEnabled_ = result.flagEnabled;
113 this.set('importantSites_', result.importantSites);
114 },
115
116 /**
89 * Updates the footer to show only those sentences that are relevant to this 117 * Updates the footer to show only those sentences that are relevant to this
90 * user. 118 * user.
91 * @param {boolean} syncing Whether the user is syncing data. 119 * @param {boolean} syncing Whether the user is syncing data.
92 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other 120 * @param {boolean} otherFormsOfBrowsingHistory Whether the user has other
93 * forms of browsing history in their account. 121 * forms of browsing history in their account.
94 * @private 122 * @private
95 */ 123 */
96 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) { 124 updateFooter_: function(syncing, otherFormsOfBrowsingHistory) {
97 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory; 125 this.$.googleFooter.hidden = !otherFormsOfBrowsingHistory;
98 this.$.syncedDataSentence.hidden = !syncing; 126 this.$.syncedDataSentence.hidden = !syncing;
99 this.$.dialog.classList.add('fully-rendered'); 127 this.$.clearBrowsingDataDialog.classList.add('fully-rendered');
100 }, 128 },
101 129
102 /** 130 /**
103 * Updates the text of a browsing data counter corresponding to the given 131 * Updates the text of a browsing data counter corresponding to the given
104 * preference. 132 * preference.
105 * @param {string} prefName Browsing data type deletion preference. 133 * @param {string} prefName Browsing data type deletion preference.
106 * @param {string} text The text with which to update the counter 134 * @param {string} text The text with which to update the counter
107 * @private 135 * @private
108 */ 136 */
109 updateCounterText_: function(prefName, text) { 137 updateCounterText_: function(prefName, text) {
110 // Data type deletion preferences are named "browser.clear_data.<datatype>". 138 // Data type deletion preferences are named "browser.clear_data.<datatype>".
111 // Strip the common prefix, i.e. use only "<datatype>". 139 // Strip the common prefix, i.e. use only "<datatype>".
112 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/); 140 var matches = prefName.match(/^browser\.clear_data\.(\w+)$/);
113 this.set('counters_.' + assert(matches[1]), text); 141 this.set('counters_.' + assert(matches[1]), text);
114 }, 142 },
115 143
116 /** 144 /**
145 * @return {boolean} Whether the ImportantSites dialog should be shown.
146 * @private
147 */
148 shouldShowImportantSites_: function() {
149 if (!this.importantSitesFlagEnabled_)
150 return false;
151 if (!this.$.cookiesCheckbox.checked && !this.$.cacheCheckbox.checked)
152 return false;
153
154 var haveImportantSites = this.importantSites_.length > 0;
155 chrome.send(
156 'metricsHandler:recordBooleanHistogram',
157 ['History.ClearBrowsingData.ImportantDialogShown', haveImportantSites]);
158 return haveImportantSites;
159 },
160
161 /**
117 * Handles the tap on the Clear Data button. 162 * Handles the tap on the Clear Data button.
118 * @private 163 * @private
119 */ 164 */
120 onClearBrowsingDataTap_: function() { 165 onClearBrowsingDataTap_: function() {
166 if (this.shouldShowImportantSites_()) {
167 this.$.importantSitesDialog.showModal();
168 this.$.clearBrowsingDataDialog.close();
169 } else {
170 this.clearBrowsingData_()
171 }
172 },
173
174 /**
175 * Handles closing of the clear browsing data dialog. Stops the close
176 * event from propagating if another dialog is shown to prevent the
177 * privacy-page from closing this dialog.
178 * @private
179 */
180 onClearBrowsingDataDialogClose_: function(event) {
181 if (this.$.importantSitesDialog.open)
182 event.stopPropagation()
183 },
184
185 /**
186 * Clears browsing data and maybe shows a history notice.
187 * @private
188 */
189 clearBrowsingData_: function() {
121 this.clearingInProgress_ = true; 190 this.clearingInProgress_ = true;
122 191
123 this.browserProxy_.clearBrowsingData().then( 192 this.browserProxy_.clearBrowsingData(this.importantSites_)
124 /** 193 .then(
125 * @param {boolean} shouldShowNotice Whether we should show the notice 194 /**
126 * about other forms of browsing history before closing the dialog. 195 * @param {boolean} shouldShowNotice Whether we should show the
127 */ 196 * notice about other forms of browsing history before closing the
128 function(shouldShowNotice) { 197 * dialog.
129 this.clearingInProgress_ = false; 198 */
130 this.showHistoryDeletionDialog_ = shouldShowNotice; 199 function(shouldShowNotice) {
200 this.clearingInProgress_ = false;
201 this.showHistoryDeletionDialog_ = shouldShowNotice;
131 202
132 if (!shouldShowNotice) 203 if (!shouldShowNotice) {
133 this.$.dialog.close(); 204 closeDialogs_();
Dan Beam 2017/05/09 19:23:18 fairly sure this should be this.closeDialogs_() an
dullweber 2017/05/11 13:13:47 Done.
134 }.bind(this)); 205 }
206 }.bind(this));
207 },
208
209 /**
210 * Closes the clear browsing data or important site dialog if they are open.
211 * @private
212 */
213 closeDialogs_() {
Dan Beam 2017/05/09 19:23:18 this is an ES6 feature (object literal extensions)
dullweber 2017/05/11 13:13:45 sorry, I compiled without vulcanize and I also jus
214 if (this.$.clearBrowsingDataDialog.open)
215 this.$.clearBrowsingDataDialog.close();
216 if (this.$.importantSitesDialog.open)
217 this.$.importantSitesDialog.close();
135 }, 218 },
136 219
137 /** @private */ 220 /** @private */
138 onCancelTap_: function() { 221 onCancelTap_: function() {
139 this.$.dialog.cancel(); 222 this.$.clearBrowsingDataDialog.cancel();
140 }, 223 },
141 224
142 /** 225 /**
226 * Handles the tap confirm button in important sites.
227 * @private
228 */
229 onImportantSitesConfirmTap_: function() {
230 this.clearBrowsingData_();
231 },
232
233 /** @private */
234 onImportantSitesCancelTap_: function() {
235 this.$.importantSitesDialog.cancel();
236 },
237
238 /**
143 * Handles the closing of the notice about other forms of browsing history. 239 * Handles the closing of the notice about other forms of browsing history.
144 * @private 240 * @private
145 */ 241 */
146 onHistoryDeletionDialogClose_: function() { 242 onHistoryDeletionDialogClose_: function() {
147 this.showHistoryDeletionDialog_ = false; 243 this.showHistoryDeletionDialog_ = false;
148 this.$.dialog.close(); 244 closeDialogs_();
Dan Beam 2017/05/09 19:23:18 same (should be this.closeDialogs_())
dullweber 2017/05/11 13:13:46 Done.
149 } 245 },
150 }); 246 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698