1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 if (!loadTimeData.getBoolean('newContentSettings')) {
7 cr.define('options', function() {
8 /** @const */ var OptionsPage = options.OptionsPage;
10 //////////////////////////////////////////////////////////////////////////////
11 // ContentSettings class:
14 * Encapsulated handling of content settings page.
17 function ContentSettings() {
18 this.activeNavTab = null;
19 OptionsPage.call(this, 'content',
20 loadTimeData.getString('contentSettingsPageTabTitle'),
21 'content-settings-page');
24 cr.addSingletonGetter(ContentSettings);
26 ContentSettings.prototype = {
27 __proto__: OptionsPage.prototype,
29 initializePage: function() {
30 OptionsPage.prototype.initializePage.call(this);
32 var exceptionsButtons =
33 this.pageDiv.querySelectorAll('.exceptions-list-button');
34 for (var i = 0; i < exceptionsButtons.length; i++) {
35 exceptionsButtons[i].onclick = function(event) {
36 var page = ContentSettingsExceptionsArea.getInstance();
38 // Add on the proper hash for the content type, and store that in the
39 // history so back/forward and tab restore works.
40 var hash = event.currentTarget.getAttribute('contentType');
41 var url = page.name + '#' + hash;
42 window.history.pushState({pageName: page.name},
46 // Navigate after the history has been replaced in order to have the
47 // correct hash loaded.
48 OptionsPage.showPageByName('contentExceptions', false);
50 uber.invokeMethodOnParent('setPath', {path: url});
51 uber.invokeMethodOnParent('setTitle',
52 {title: loadTimeData.getString(hash + 'TabTitle')});
56 var manageHandlersButton = $('manage-handlers-button');
57 if (manageHandlersButton) {
58 manageHandlersButton.onclick = function(event) {
59 OptionsPage.navigateToPage('handlers');
63 $('manage-galleries-button').onclick = function(event) {
64 OptionsPage.navigateToPage('manageGalleries');
68 UIAccountTweaks.applyGuestModeVisibility(document);
70 // Cookies filter page ---------------------------------------------------
71 $('show-cookies-button').onclick = function(event) {
72 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
73 OptionsPage.navigateToPage('cookies');
76 $('content-settings-overlay-confirm').onclick =
77 OptionsPage.closeOverlay.bind(OptionsPage);
79 $('media-pepper-flash-default').hidden = true;
80 $('media-pepper-flash-exceptions').hidden = true;
82 $('media-select-mic').addEventListener('change',
83 ContentSettings.setDefaultMicrophone_);
84 $('media-select-camera').addEventListener('change',
85 ContentSettings.setDefaultCamera_);
89 ContentSettings.updateHandlersEnabledRadios = function(enabled) {
90 var selector = '#content-settings-page input[type=radio][value=' +
91 (enabled ? 'allow' : 'block') + '].handler-radio';
92 document.querySelector(selector).checked = true;
96 * Sets the values for all the content settings radios.
97 * @param {Object} dict A mapping from radio groups to the checked value for
100 ContentSettings.setContentFilterSettingsValue = function(dict) {
101 for (var group in dict) {
102 var managedBy = dict[group].managedBy;
103 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ?
105 document.querySelector('input[type=radio][name=' + group + '][value=' +
106 dict[group].value + ']').checked = true;
107 var radios = document.querySelectorAll('input[type=radio][name=' +
109 for (var i = 0, len = radios.length; i < len; i++) {
110 radios[i].disabled = (managedBy != 'default');
111 radios[i].controlledBy = controlledBy;
113 var indicators = document.querySelectorAll(
114 'span.controlled-setting-indicator[content-setting=' + group + ']');
115 if (indicators.length == 0)
117 // Create a synthetic pref change event decorated as
118 // CoreOptionsHandler::CreateValueForPref() does.
119 var event = new Event(group);
121 value: dict[group].value,
122 controlledBy: controlledBy,
124 for (var i = 0; i < indicators.length; i++)
125 indicators[i].handlePrefChange(event);
130 * Updates the labels and indicators for the Media settings. Those require
131 * special handling because they are backed by multiple prefs and can change
132 * their scope based on the managed state of the backing prefs.
133 * @param {Object} mediaSettings A dictionary containing the following fields:
134 * {String} askText The label for the ask radio button.
135 * {String} blockText The label for the block radio button.
136 * {Boolean} cameraDisabled Whether to disable the camera dropdown.
137 * {Boolean} micDisabled Whether to disable the microphone dropdown.
138 * {Boolean} showBubble Wether to show the managed icon and bubble for the
140 * {String} bubbleText The text to use inside the bubble if it is shown.
142 ContentSettings.updateMediaUI = function(mediaSettings) {
143 $('media-stream-ask-label').innerHTML =
144 loadTimeData.getString(mediaSettings.askText);
145 $('media-stream-block-label').innerHTML =
146 loadTimeData.getString(mediaSettings.blockText);
148 if (mediaSettings.micDisabled)
149 $('media-select-mic').disabled = true;
150 if (mediaSettings.cameraDisabled)
151 $('media-select-camera').disabled = true;
153 OptionsPage.hideBubble();
154 // Create a synthetic pref change event decorated as
155 // CoreOptionsHandler::CreateValueForPref() does.
156 // TODO(arv): It was not clear what event type this should use?
157 var event = new Event('undefined');
160 if (mediaSettings.showBubble) {
161 event.value = { controlledBy: 'policy' };
162 $('media-indicator').setAttribute(
163 'textpolicy', loadTimeData.getString(mediaSettings.bubbleText));
164 $('media-indicator').location = cr.ui.ArrowLocation.TOP_START;
167 $('media-indicator').handlePrefChange(event);
171 * Initializes an exceptions list.
172 * @param {string} type The content type that we are setting exceptions for.
173 * @param {Array} list An array of pairs, where the first element of each pair
174 * is the filter string, and the second is the setting (allow/block).
176 ContentSettings.setExceptions = function(type, list) {
178 document.querySelector('div[contentType=' + type + ']' +
179 ' list[mode=normal]');
180 exceptionsList.setExceptions(list);
183 ContentSettings.setHandlers = function(list) {
184 $('handlers-list').setHandlers(list);
187 ContentSettings.setIgnoredHandlers = function(list) {
188 $('ignored-handlers-list').setHandlers(list);
191 ContentSettings.setOTRExceptions = function(type, list) {
193 document.querySelector('div[contentType=' + type + ']' +
196 exceptionsList.parentNode.hidden = false;
197 exceptionsList.setExceptions(list);
201 * The browser's response to a request to check the validity of a given URL
203 * @param {string} type The content type.
204 * @param {string} mode The browser mode.
205 * @param {string} pattern The pattern.
206 * @param {bool} valid Whether said pattern is valid in the context of
207 * a content exception setting.
209 ContentSettings.patternValidityCheckComplete =
210 function(type, mode, pattern, valid) {
212 document.querySelector('div[contentType=' + type + '] ' +
213 'list[mode=' + mode + ']');
214 exceptionsList.patternValidityCheckComplete(pattern, valid);
218 * Shows/hides the link to the Pepper Flash camera and microphone default
220 * Please note that whether the link is actually showed or not is also
221 * affected by the style class pepper-flash-settings.
223 ContentSettings.showMediaPepperFlashDefaultLink = function(show) {
224 $('media-pepper-flash-default').hidden = !show;
228 * Shows/hides the link to the Pepper Flash camera and microphone
229 * site-specific settings.
230 * Please note that whether the link is actually showed or not is also
231 * affected by the style class pepper-flash-settings.
233 ContentSettings.showMediaPepperFlashExceptionsLink = function(show) {
234 $('media-pepper-flash-exceptions').hidden = !show;
238 * Shows/hides the whole Web MIDI settings.
239 * @param {bool} show Wether to show the whole Web MIDI settings.
241 ContentSettings.showExperimentalWebMIDISettings = function(show) {
242 $('experimental-web-midi-settings').hidden = !show;
246 * Updates the microphone/camera devices menu with the given entries.
247 * @param {string} type The device type.
248 * @param {Array} devices List of available devices.
249 * @param {string} defaultdevice The unique id of the current default device.
251 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) {
252 var deviceSelect = '';
254 deviceSelect = $('media-select-mic');
255 } else if (type == 'camera') {
256 deviceSelect = $('media-select-camera');
258 console.error('Unknown device type for <device select> UI element: ' +
263 deviceSelect.textContent = '';
265 var deviceCount = devices.length;
266 var defaultIndex = -1;
267 for (var i = 0; i < deviceCount; i++) {
268 var device = devices[i];
269 var option = new Option(device.name, device.id);
270 if (option.value == defaultdevice)
272 deviceSelect.appendChild(option);
274 if (defaultIndex >= 0)
275 deviceSelect.selectedIndex = defaultIndex;
279 * Enables/disables the protected content exceptions button.
280 * @param {bool} enable Whether to enable the button.
282 ContentSettings.enableProtectedContentExceptions = function(enable) {
283 var exceptionsButton = $('protected-content-exceptions');
284 if (exceptionsButton) {
285 exceptionsButton.disabled = !enable;
290 * Set the default microphone device based on the popup selection.
293 ContentSettings.setDefaultMicrophone_ = function() {
294 var deviceSelect = $('media-select-mic');
295 chrome.send('setDefaultCaptureDevice', ['mic', deviceSelect.value]);
299 * Set the default camera device based on the popup selection.
302 ContentSettings.setDefaultCamera_ = function() {
303 var deviceSelect = $('media-select-camera');
304 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]);
309 ContentSettings: ContentSettings