1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
var Page = cr.ui.pageManager.Page;
var PageManager = cr.ui.pageManager.PageManager;
/**
* ClearBrowserDataOverlay class
* Encapsulated handling of the 'Clear Browser Data' overlay page.
* @class
*/
function ClearBrowserDataOverlay() {
Page.call(this, 'clearBrowserData',
loadTimeData.getString('clearBrowserDataOverlayTabTitle'),
'clear-browser-data-overlay');
}
cr.addSingletonGetter(ClearBrowserDataOverlay);
ClearBrowserDataOverlay.prototype = {
// Inherit ClearBrowserDataOverlay from Page.
__proto__: Page.prototype,
/**
* Whether deleting history and downloads is allowed.
* @type {boolean}
* @private
*/
allowDeletingHistory_: true,
/**
* Whether or not clearing browsing data is currently in progress.
* @type {boolean}
* @private
*/
isClearingInProgress_: false,
/**
* Whether or not the WebUI handler has completed initialization.
*
* Unless this becomes true, it must be assumed that the above flags might
* not contain the authoritative values.
*
* @type {boolean}
* @private
*/
isInitializationComplete_: false,
/** @override */
initializePage: function() {
Page.prototype.initializePage.call(this);
var f = this.updateStateOfControls_.bind(this);
var types = ['browser.clear_data.browsing_history',
'browser.clear_data.download_history',
'browser.clear_data.cache',
'browser.clear_data.cookies',
'browser.clear_data.passwords',
'browser.clear_data.form_data',
'browser.clear_data.hosted_apps_data',
'browser.clear_data.content_licenses'];
types.forEach(function(type) {
Preferences.getInstance().addEventListener(type, f);
});
var checkboxes = document.querySelectorAll(
'#cbd-content-area input[type=checkbox]');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].onclick = f;
}
$('clear-browser-data-dismiss').onclick = function(event) {
ClearBrowserDataOverlay.dismiss();
};
$('clear-browser-data-commit').onclick = function(event) {
ClearBrowserDataOverlay.setClearing(true);
chrome.send('performClearBrowserData');
};
// For managed profiles, hide the checkboxes controlling whether or not
// browsing and download history should be cleared. Note that this is
// different than just disabling them as a result of enterprise policies.
if (!loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes')) {
$('delete-browsing-history-container').hidden = true;
$('delete-download-history-container').hidden = true;
}
this.updateStateOfControls_();
},
/**
* Create a footer that explains that some content is not cleared by the
* clear browsing data dialog and warns that the deletion may be synced.
* @param {boolean} simple Whether to use a simple support string.
* @param {boolean} syncing Whether the user uses Sync.
* @private
*/
createFooter_: function(simple, syncing) {
// The localized string is of the form "Saved [content settings] and
// {search engines} will not be cleared and may reflect your browsing
// habits.", or of the form "Some settings that may reflect browsing
// habits |will not be cleared|." if the simplified support string
// experiment is enabled. The following parses out the parts in brackets
// and braces and converts them into buttons whereas the remainders are
// represented as span elements.
var footer =
document.querySelector('#some-stuff-remains-footer p');
var footerFragments =
loadTimeData.getString('clearBrowserDataSupportString')
.split(/([|#])/);
if (simple) {
footerFragments.unshift(
loadTimeData.getString('clearBrowserDataSyncWarning') +
' ' // Padding between the sync warning and the rest of the footer.
);
}
for (var i = 0; i < footerFragments.length;) {
var linkId = '';
if (i + 2 < footerFragments.length) {
if (footerFragments[i] == '|' && footerFragments[i + 2] == '|') {
if (simple)
linkId = 'open-not-deleted-help-from-clear-browsing-data';
else
linkId = 'open-content-settings-from-clear-browsing-data';
} else if (footerFragments[i] == '#' &&
footerFragments[i + 2] == '#') {
linkId = 'open-search-engines-from-clear-browsing-data';
}
}
if (linkId) {
var link = new ActionLink;
link.id = linkId;
link.textContent = footerFragments[i + 1];
footer.appendChild(link);
i += 3;
} else {
var span = document.createElement('span');
span.textContent = footerFragments[i];
if (simple && i == 0) {
span.id = 'clear-browser-data-sync-warning';
span.hidden = !syncing;
}
footer.appendChild(span);
i += 1;
}
}
if (simple) {
$('open-not-deleted-help-from-clear-browsing-data').onclick =
function(event) {
// TODO(msramek): Link to the exact page when the article is written.
window.open('https://support.google.com/chrome/');
};
} else {
$('open-content-settings-from-clear-browsing-data').onclick =
function(event) {
PageManager.showPageByName('content');
};
$('open-search-engines-from-clear-browsing-data').onclick =
function(event) {
PageManager.showPageByName('searchEngines');
};
}
},
/**
* Shows or hides the sync warning based on whether the user uses Sync.
* @param {boolean} syncing Whether the user uses Sync.
* @private
*/
updateSyncWarning_: function(syncing) {
$('clear-browser-data-sync-warning').hidden = !syncing;
},
/**
* Sets whether or not we are in the process of clearing data.
* @param {boolean} clearing Whether the browsing data is currently being
* cleared.
* @private
*/
setClearing_: function(clearing) {
this.isClearingInProgress_ = clearing;
this.updateStateOfControls_();
},
/**
* Sets whether deleting history and downloads is disallowed by enterprise
* policies. This is called on initialization and in response to a change in
* the corresponding preference.
* @param {boolean} allowed Whether to allow deleting history and downloads.
* @private
*/
setAllowDeletingHistory_: function(allowed) {
this.allowDeletingHistory_ = allowed;
this.updateStateOfControls_();
},
/**
* Called by the WebUI handler to signal that it has finished calling all
* initialization methods.
* @private
*/
markInitializationComplete_: function() {
this.isInitializationComplete_ = true;
this.updateStateOfControls_();
},
/**
* Updates the enabled/disabled/hidden status of all controls on the dialog.
* @private
*/
updateStateOfControls_: function() {
// The commit button is enabled if at least one data type selected to be
// cleared, and if we are not already in the process of clearing.
// To prevent the commit button from being hazardously enabled for a very
// short time before setClearing() is called the first time by the native
// side, also disable the button if |isInitializationComplete_| is false.
var enabled = false;
if (this.isInitializationComplete_ && !this.isClearingInProgress_) {
var checkboxes = document.querySelectorAll(
'#cbd-content-area input[type=checkbox]');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
enabled = true;
break;
}
}
}
$('clear-browser-data-commit').disabled = !enabled;
// The checkboxes for clearing history/downloads are enabled unless they
// are disallowed by policies, or we are in the process of clearing data.
// To prevent flickering, these, and the rest of the controls can safely
// be enabled for a short time before the first call to setClearing().
var enabled = this.allowDeletingHistory_ && !this.isClearingInProgress_;
$('delete-browsing-history-checkbox').disabled = !enabled;
$('delete-download-history-checkbox').disabled = !enabled;
if (!this.allowDeletingHistory_) {
$('delete-browsing-history-checkbox').checked = false;
$('delete-download-history-checkbox').checked = false;
}
// Enable everything else unless we are in the process of clearing.
var clearing = this.isClearingInProgress_;
$('delete-cache-checkbox').disabled = clearing;
$('delete-cookies-checkbox').disabled = clearing;
$('delete-passwords-checkbox').disabled = clearing;
$('delete-form-data-checkbox').disabled = clearing;
$('delete-hosted-apps-data-checkbox').disabled = clearing;
$('deauthorize-content-licenses-checkbox').disabled = clearing;
$('clear-browser-data-time-period').disabled = clearing;
$('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden';
$('clear-browser-data-dismiss').disabled = clearing;
},
/**
* Updates the given data volume counter with a given text.
* @param {string} pref_name Name of the deletion preference of the counter
* to be updated.
* @param {string} text The new text of the counter.
* @private
*/
updateCounter_: function(pref_name, text) {
var counter = document.querySelector(
'input[pref="' + pref_name + '"] ~ .clear-browser-data-counter');
counter.textContent = text;
}
};
//
// Chrome callbacks
//
ClearBrowserDataOverlay.setAllowDeletingHistory = function(allowed) {
ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory_(allowed);
};
ClearBrowserDataOverlay.updateCounter = function(pref_name, text) {
ClearBrowserDataOverlay.getInstance().updateCounter_(pref_name, text);
};
ClearBrowserDataOverlay.createFooter = function(simple, syncing) {
ClearBrowserDataOverlay.getInstance().createFooter_(simple, syncing);
};
ClearBrowserDataOverlay.updateSyncWarning = function(syncing) {
ClearBrowserDataOverlay.getInstance().updateSyncWarning_(syncing);
};
ClearBrowserDataOverlay.setClearing = function(clearing) {
ClearBrowserDataOverlay.getInstance().setClearing_(clearing);
};
ClearBrowserDataOverlay.markInitializationComplete = function() {
ClearBrowserDataOverlay.getInstance().markInitializationComplete_();
};
ClearBrowserDataOverlay.setBannerText = function(text) {
$('clear-browser-data-info-banner').innerText = text;
};
ClearBrowserDataOverlay.doneClearing = function() {
// The delay gives the user some feedback that the clearing
// actually worked. Otherwise the dialog just vanishes instantly in most
// cases.
window.setTimeout(function() {
ClearBrowserDataOverlay.setClearing(false);
ClearBrowserDataOverlay.dismiss();
}, 200);
};
ClearBrowserDataOverlay.dismiss = function() {
var topmostVisiblePage = PageManager.getTopmostVisiblePage();
if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData')
PageManager.closeOverlay();
};
// Export
return {
ClearBrowserDataOverlay: ClearBrowserDataOverlay
};
});
|