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
|
// 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() {
/** @const */ var OptionsPage = options.OptionsPage;
//////////////////////////////////////////////////////////////////////////////
// ContentSettings class:
/**
* Encapsulated handling of content settings page.
* @constructor
*/
function ContentSettings() {
this.activeNavTab = null;
this.sessionRestoreEnabled = false;
this.sessionRestoreSelected = false;
OptionsPage.call(this, 'content',
loadTimeData.getString('contentSettingsPageTabTitle'),
'content-settings-page');
// Keep track of the real value of the "clear on exit" preference. (The UI
// might override it if the "continue where I left off" setting is
// selected.)
var self = this;
Preferences.getInstance().addEventListener(
'profile.clear_site_data_on_exit',
function(event) {
if (event.value && typeof event.value['value'] != 'undefined') {
self.clearCookiesOnExit = event.value['value'] == true;
}
});
Preferences.getInstance().addEventListener(
'session.restore_on_startup',
this.onSessionRestoreSelectedChanged.bind(this));
}
cr.addSingletonGetter(ContentSettings);
ContentSettings.prototype = {
__proto__: OptionsPage.prototype,
initializePage: function() {
OptionsPage.prototype.initializePage.call(this);
chrome.send('getContentFilterSettings');
var exceptionsButtons =
this.pageDiv.querySelectorAll('.exceptions-list-button');
for (var i = 0; i < exceptionsButtons.length; i++) {
exceptionsButtons[i].onclick = function(event) {
var page = ContentSettingsExceptionsArea.getInstance();
// Add on the proper hash for the content type, and store that in the
// history so back/forward and tab restore works.
var hash = event.target.getAttribute('contentType');
var url = page.name + '#' + hash;
window.history.replaceState({pageName: page.name},
page.title,
'/' + url);
// Navigate after the history has been replaced in order to have the
// correct hash loaded.
OptionsPage.navigateToPage('contentExceptions');
uber.invokeMethodOnParent('setPath', {path: url});
uber.invokeMethodOnParent('setTitle',
{title: loadTimeData.getString(hash + 'TabTitle')});
};
}
var manageHandlersButton = $('manage-handlers-button');
if (manageHandlersButton) {
manageHandlersButton.onclick = function(event) {
OptionsPage.navigateToPage('handlers');
};
}
if (cr.isChromeOS)
UIAccountTweaks.applyGuestModeVisibility(document);
// Cookies filter page ---------------------------------------------------
$('show-cookies-button').onclick = function(event) {
chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
OptionsPage.navigateToPage('cookies');
};
// Remove from DOM instead of hiding so :last-of-type applies the style
// correctly.
var intentsSection = $('intents-section');
if (!loadTimeData.getBoolean('enable_web_intents') && intentsSection)
intentsSection.parentNode.removeChild(intentsSection);
if (loadTimeData.getBoolean('enable_restore_session_state')) {
this.sessionRestoreEnabled = true;
this.updateSessionRestoreContentSettings();
}
$('content-settings-overlay-confirm').onclick =
OptionsPage.closeOverlay.bind(OptionsPage);
},
/**
* Called when the value of the "On startup" setting changes.
* @param {Event} event Change event.
* @private
*/
onSessionRestoreSelectedChanged: function(event) {
if (!event.value || typeof event.value['value'] == 'undefined')
return;
this.sessionRestoreSelected = event.value['value'] == 1;
if (this.sessionRestoreSelected)
this.updateSessionRestoreContentSettings();
else
this.restoreContentSettings();
},
// If the "continue where I left off" setting is selected, disable the
// "clear on exit" checkbox, and the "session only" setting for cookies.
updateSessionRestoreContentSettings: function() {
// This feature is behind a command line flag.
if (this.sessionRestoreEnabled && this.sessionRestoreSelected) {
$('clear-cookies-on-exit').checked = false;
$('clear-cookies-on-exit').setDisabled('sessionrestore', true);
if ($('cookies-session').checked) {
$('cookies-allow').checked = true;
}
$('cookies-session').disabled = true;
}
},
// Restore the values of the UI elements based on the real values of the
// preferences.
restoreContentSettings: function() {
$('clear-cookies-on-exit').checked = this.clearCookiesOnExit;
$('clear-cookies-on-exit').setDisabled('sessionrestore', false);
if (this.cookiesSession && $('cookies-allow').checked) {
$('cookies-session').checked = true;
}
$('cookies-session').disabled = false;
},
};
ContentSettings.updateHandlersEnabledRadios = function(enabled) {
var selector = '#content-settings-page input[type=radio][value=' +
(enabled ? 'allow' : 'block') + '].handler-radio';
document.querySelector(selector).checked = true;
};
/**
* Sets the values for all the content settings radios.
* @param {Object} dict A mapping from radio groups to the checked value for
* that group.
*/
ContentSettings.setContentFilterSettingsValue = function(dict) {
for (var group in dict) {
document.querySelector('input[type=radio][name=' + group + '][value=' +
dict[group]['value'] + ']').checked = true;
var radios = document.querySelectorAll('input[type=radio][name=' +
group + ']');
var managedBy = dict[group]['managedBy'];
for (var i = 0, len = radios.length; i < len; i++) {
radios[i].disabled = (managedBy != 'default');
radios[i].controlledBy = managedBy;
}
}
// Keep track of the real cookie content setting. (The UI might override it
// if the reopen last pages setting is selected.)
if ('cookies' in dict && 'value' in dict['cookies']) {
ContentSettings.getInstance().cookiesSession =
dict['cookies']['value'] == 'session';
}
ContentSettings.getInstance().updateSessionRestoreContentSettings();
OptionsPage.updateManagedBannerVisibility();
};
/**
* Initializes an exceptions list.
* @param {string} type The content type that we are setting exceptions for.
* @param {Array} list An array of pairs, where the first element of each pair
* is the filter string, and the second is the setting (allow/block).
*/
ContentSettings.setExceptions = function(type, list) {
var exceptionsList =
document.querySelector('div[contentType=' + type + ']' +
' list[mode=normal]');
exceptionsList.setExceptions(list);
};
ContentSettings.setHandlers = function(list) {
$('handlers-list').setHandlers(list);
};
ContentSettings.setIgnoredHandlers = function(list) {
$('ignored-handlers-list').setHandlers(list);
};
ContentSettings.setOTRExceptions = function(type, list) {
var exceptionsList =
document.querySelector('div[contentType=' + type + ']' +
' list[mode=otr]');
exceptionsList.parentNode.hidden = false;
exceptionsList.setExceptions(list);
};
/**
* The browser's response to a request to check the validity of a given URL
* pattern.
* @param {string} type The content type.
* @param {string} mode The browser mode.
* @param {string} pattern The pattern.
* @param {bool} valid Whether said pattern is valid in the context of
* a content exception setting.
*/
ContentSettings.patternValidityCheckComplete =
function(type, mode, pattern, valid) {
var exceptionsList =
document.querySelector('div[contentType=' + type + '] ' +
'list[mode=' + mode + ']');
exceptionsList.patternValidityCheckComplete(pattern, valid);
};
// Export
return {
ContentSettings: ContentSettings
};
});
|