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 cr.define('options', function() {
6 /** @const */ var OptionsPage = options.OptionsPage;
8 //////////////////////////////////////////////////////////////////////////////
9 // ContentSettings class:
12 * Encapsulated handling of content settings page.
15 function ContentSettings() {
16 this.activeNavTab = null;
17 OptionsPage.call(this, 'content',
18 loadTimeData.getString('contentSettingsPageTabTitle'),
19 'content-settings-page');
22 cr.addSingletonGetter(ContentSettings);
24 ContentSettings.prototype = {
25 __proto__: OptionsPage.prototype,
27 initializePage: function() {
28 OptionsPage.prototype.initializePage.call(this);
30 var exceptionsButtons =
31 this.pageDiv.querySelectorAll('.exceptions-list-button');
32 for (var i = 0; i < exceptionsButtons.length; i++) {
33 exceptionsButtons[i].onclick = function(event) {
34 var page = ContentSettingsExceptionsArea.getInstance();
36 // Add on the proper hash for the content type, and store that in the
37 // history so back/forward and tab restore works.
38 var hash = event.currentTarget.getAttribute('contentType');
39 var url = page.name + '#' + hash;
40 uber.pushState({pageName: page.name}, url);
42 // Navigate after the local history has been replaced in order to have
43 // the correct hash loaded.
44 OptionsPage.showPageByName('contentExceptions', false);
48 var manageHandlersButton = $('manage-handlers-button');
49 if (manageHandlersButton) {
50 manageHandlersButton.onclick = function(event) {
51 OptionsPage.navigateToPage('handlers');
56 UIAccountTweaks.applyGuestModeVisibility(document);
58 // Cookies filter page ---------------------------------------------------
59 $('show-cookies-button').onclick = function(event) {
60 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
61 OptionsPage.navigateToPage('cookies');
64 $('content-settings-overlay-confirm').onclick =
65 OptionsPage.closeOverlay.bind(OptionsPage);
67 $('media-pepper-flash-default').hidden = true;
68 $('media-pepper-flash-exceptions').hidden = true;
70 $('media-select-mic').addEventListener('change',
71 ContentSettings.setDefaultMicrophone_);
72 $('media-select-camera').addEventListener('change',
73 ContentSettings.setDefaultCamera_);
77 ContentSettings.updateHandlersEnabledRadios = function(enabled) {
78 var selector = '#content-settings-page input[type=radio][value=' +
79 (enabled ? 'allow' : 'block') + '].handler-radio';
80 document.querySelector(selector).checked = true;
84 * Sets the values for all the content settings radios.
85 * @param {Object} dict A mapping from radio groups to the checked value for
88 ContentSettings.setContentFilterSettingsValue = function(dict) {
89 for (var group in dict) {
90 var managedBy = dict[group].managedBy;
91 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ?
93 document.querySelector('input[type=radio][name=' + group + '][value=' +
94 dict[group].value + ']').checked = true;
95 var radios = document.querySelectorAll('input[type=radio][name=' +
97 for (var i = 0, len = radios.length; i < len; i++) {
98 radios[i].disabled = (managedBy != 'default');
99 radios[i].controlledBy = controlledBy;
101 var indicators = document.querySelectorAll(
102 'span.controlled-setting-indicator[content-setting=' + group + ']');
103 if (indicators.length == 0)
105 // Create a synthetic pref change event decorated as
106 // CoreOptionsHandler::CreateValueForPref() does.
107 var event = new Event(group);
109 value: dict[group].value,
110 controlledBy: controlledBy,
112 for (var i = 0; i < indicators.length; i++) {
113 indicators[i].handlePrefChange(event);
119 * Updates the labels and indicators for the Media settings. Those require
120 * special handling because they are backed by multiple prefs and can change
121 * their scope based on the managed state of the backing prefs.
122 * @param {Object} mediaSettings A dictionary containing the following fields:
123 * {String} askText The label for the ask radio button.
124 * {String} blockText The label for the block radio button.
125 * {Boolean} cameraDisabled Whether to disable the camera dropdown.
126 * {Boolean} micDisabled Whether to disable the microphone dropdown.
127 * {Boolean} showBubble Wether to show the managed icon and bubble for the
129 * {String} bubbleText The text to use inside the bubble if it is shown.
131 ContentSettings.updateMediaUI = function(mediaSettings) {
132 $('media-stream-ask-label').innerHTML =
133 loadTimeData.getString(mediaSettings.askText);
134 $('media-stream-block-label').innerHTML =
135 loadTimeData.getString(mediaSettings.blockText);
137 if (mediaSettings.micDisabled)
138 $('media-select-mic').disabled = true;
139 if (mediaSettings.cameraDisabled)
140 $('media-select-camera').disabled = true;
142 OptionsPage.hideBubble();
143 // Create a synthetic pref change event decorated as
144 // CoreOptionsHandler::CreateValueForPref() does.
145 // TODO(arv): It was not clear what event type this should use?
146 var event = new Event('undefined');
149 if (mediaSettings.showBubble) {
150 event.value = { controlledBy: 'policy' };
151 $('media-indicator').setAttribute(
152 'textpolicy', loadTimeData.getString(mediaSettings.bubbleText));
153 $('media-indicator').location = cr.ui.ArrowLocation.TOP_START;
156 $('media-indicator').handlePrefChange(event);
160 * Initializes an exceptions list.
161 * @param {string} type The content type that we are setting exceptions for.
162 * @param {Array} exceptions An array of pairs, where the first element of
163 * each pair is the filter string, and the second is the setting
166 ContentSettings.setExceptions = function(type, exceptions) {
167 this.getExceptionsList(type, 'normal').setExceptions(exceptions);
170 ContentSettings.setHandlers = function(handlers) {
171 $('handlers-list').setHandlers(handlers);
174 ContentSettings.setIgnoredHandlers = function(ignoredHandlers) {
175 $('ignored-handlers-list').setHandlers(ignoredHandlers);
178 ContentSettings.setOTRExceptions = function(type, otrExceptions) {
179 var exceptionsList = this.getExceptionsList(type, 'otr');
180 exceptionsList.parentNode.hidden = false;
181 exceptionsList.setExceptions(otrExceptions);
185 * @param {string} type The type of exceptions (e.g. "location") to get.
186 * @param {string} mode The mode of the desired exceptions list (e.g. otr).
187 * @return {?ExceptionsList} The corresponding exceptions list or null.
189 ContentSettings.getExceptionsList = function(type, mode) {
190 return document.querySelector(
191 'div[contentType=' + type + '] list[mode=' + mode + ']');
195 * The browser's response to a request to check the validity of a given URL
197 * @param {string} type The content type.
198 * @param {string} mode The browser mode.
199 * @param {string} pattern The pattern.
200 * @param {bool} valid Whether said pattern is valid in the context of
201 * a content exception setting.
203 ContentSettings.patternValidityCheckComplete =
204 function(type, mode, pattern, valid) {
205 this.getExceptionsList(type, mode).patternValidityCheckComplete(pattern,
210 * Shows/hides the link to the Pepper Flash camera and microphone default
212 * Please note that whether the link is actually showed or not is also
213 * affected by the style class pepper-flash-settings.
215 ContentSettings.showMediaPepperFlashDefaultLink = function(show) {
216 $('media-pepper-flash-default').hidden = !show;
220 * Shows/hides the link to the Pepper Flash camera and microphone
221 * site-specific settings.
222 * Please note that whether the link is actually showed or not is also
223 * affected by the style class pepper-flash-settings.
225 ContentSettings.showMediaPepperFlashExceptionsLink = function(show) {
226 $('media-pepper-flash-exceptions').hidden = !show;
230 * Shows/hides the whole Web MIDI settings.
231 * @param {bool} show Wether to show the whole Web MIDI settings.
233 ContentSettings.showExperimentalWebMIDISettings = function(show) {
234 $('experimental-web-midi-settings').hidden = !show;
238 * Updates the microphone/camera devices menu with the given entries.
239 * @param {string} type The device type.
240 * @param {Array} devices List of available devices.
241 * @param {string} defaultdevice The unique id of the current default device.
243 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) {
244 var deviceSelect = '';
246 deviceSelect = $('media-select-mic');
247 } else if (type == 'camera') {
248 deviceSelect = $('media-select-camera');
250 console.error('Unknown device type for <device select> UI element: ' +
255 deviceSelect.textContent = '';
257 var deviceCount = devices.length;
258 var defaultIndex = -1;
259 for (var i = 0; i < deviceCount; i++) {
260 var device = devices[i];
261 var option = new Option(device.name, device.id);
262 if (option.value == defaultdevice)
264 deviceSelect.appendChild(option);
266 if (defaultIndex >= 0)
267 deviceSelect.selectedIndex = defaultIndex;
271 * Enables/disables the protected content exceptions button.
272 * @param {bool} enable Whether to enable the button.
274 ContentSettings.enableProtectedContentExceptions = function(enable) {
275 var exceptionsButton = $('protected-content-exceptions');
276 if (exceptionsButton)
277 exceptionsButton.disabled = !enable;
281 * Set the default microphone device based on the popup selection.
284 ContentSettings.setDefaultMicrophone_ = function() {
285 var deviceSelect = $('media-select-mic');
286 chrome.send('setDefaultCaptureDevice', ['mic', deviceSelect.value]);
290 * Set the default camera device based on the popup selection.
293 ContentSettings.setDefaultCamera_ = function() {
294 var deviceSelect = $('media-select-camera');
295 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]);
300 ContentSettings: ContentSettings