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.exportPath('options');
8 * @typedef {{appId: string,
9 * appName: (string|undefined),
10 * embeddingOrigin: (string|undefined),
14 * video: (string|undefined)}}
18 cr.define('options', function() {
19 /** @const */ var Page = cr.ui.pageManager.Page;
20 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
22 // Lookup table to generate the i18n strings.
23 /** @const */ var permissionsLookup = {
26 'javascript': 'javascript',
27 'location': 'location',
28 'media-stream-camera': 'mediaStreamCamera',
29 'media-stream-mic': 'mediaStreamMic',
30 'multiple-automatic-downloads': 'multipleAutomaticDownloads',
31 'notifications': 'notifications',
36 //////////////////////////////////////////////////////////////////////////////
37 // ContentSettings class:
40 * Encapsulated handling of content settings page.
42 * @extends {cr.ui.pageManager.Page}
44 function ContentSettings() {
45 this.activeNavTab = null;
46 Page.call(this, 'content',
47 loadTimeData.getString('contentSettingsPageTabTitle'),
48 'content-settings-page');
51 cr.addSingletonGetter(ContentSettings);
53 ContentSettings.prototype = {
54 __proto__: Page.prototype,
57 initializePage: function() {
58 Page.prototype.initializePage.call(this);
60 var exceptionsButtons =
61 this.pageDiv.querySelectorAll('.exceptions-list-button');
62 for (var i = 0; i < exceptionsButtons.length; i++) {
63 exceptionsButtons[i].onclick = function(event) {
64 var hash = event.currentTarget.getAttribute('contentType');
65 PageManager.showPageByName('contentExceptions', true,
70 var manageHandlersButton = $('manage-handlers-button');
71 if (manageHandlersButton) {
72 manageHandlersButton.onclick = function(event) {
73 PageManager.showPageByName('handlers');
78 // Disable some controls for Guest in Chrome OS.
79 UIAccountTweaks.applyGuestSessionVisibility(document);
81 // Disable some controls for Public session in Chrome OS.
82 UIAccountTweaks.applyPublicSessionVisibility(document);
85 // Cookies filter page ---------------------------------------------------
86 $('show-cookies-button').onclick = function(event) {
87 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
88 PageManager.showPageByName('cookies');
91 $('content-settings-overlay-confirm').onclick =
92 PageManager.closeOverlay.bind(PageManager);
94 $('media-pepper-flash-default-mic').hidden = true;
95 $('media-pepper-flash-default-camera').hidden = true;
96 $('media-pepper-flash-exceptions-mic').hidden = true;
97 $('media-pepper-flash-exceptions-camera').hidden = true;
99 $('media-select-mic').addEventListener('change',
100 ContentSettings.setDefaultMicrophone_);
101 $('media-select-camera').addEventListener('change',
102 ContentSettings.setDefaultCamera_);
106 ContentSettings.updateHandlersEnabledRadios = function(enabled) {
107 var selector = '#content-settings-page input[type=radio][value=' +
108 (enabled ? 'allow' : 'block') + '].handler-radio';
109 document.querySelector(selector).checked = true;
113 * Sets the values for all the content settings radios and labels.
114 * @param {Object<{managedBy: string, value: string}>} dict A mapping from
115 * radio groups to the checked value for that group.
117 ContentSettings.setContentFilterSettingsValue = function(dict) {
118 for (var group in dict) {
119 var settingLabel = $(group + '-default-string');
121 var value = dict[group].value;
123 permissionsLookup[group] + value[0].toUpperCase() + value.slice(1);
124 settingLabel.textContent = loadTimeData.getString(valueId);
127 var managedBy = dict[group].managedBy;
128 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ?
130 document.querySelector('input[type=radio][name=' + group + '][value=' +
131 dict[group].value + ']').checked = true;
132 var radios = document.querySelectorAll('input[type=radio][name=' +
134 for (var i = 0, len = radios.length; i < len; i++) {
135 radios[i].disabled = (managedBy != 'default');
136 radios[i].controlledBy = controlledBy;
138 var indicators = document.querySelectorAll(
139 'span.controlled-setting-indicator[content-setting=' + group + ']');
140 if (indicators.length == 0)
142 // Create a synthetic pref change event decorated as
143 // CoreOptionsHandler::CreateValueForPref() does.
144 var event = new Event(group);
146 value: dict[group].value,
147 controlledBy: controlledBy,
149 for (var i = 0; i < indicators.length; i++) {
150 indicators[i].handlePrefChange(event);
156 * Initializes an exceptions list.
157 * @param {string} type The content type that we are setting exceptions for.
158 * @param {Array<options.Exception>} exceptions An array of pairs, where the
159 * first element of each pair is the filter string, and the second is the
160 * setting (allow/block).
162 ContentSettings.setExceptions = function(type, exceptions) {
163 this.getExceptionsList(type, 'normal').setExceptions(exceptions);
166 ContentSettings.setHandlers = function(handlers) {
167 $('handlers-list').setHandlers(handlers);
170 ContentSettings.setIgnoredHandlers = function(ignoredHandlers) {
171 $('ignored-handlers-list').setHandlers(ignoredHandlers);
174 ContentSettings.setOTRExceptions = function(type, otrExceptions) {
175 var exceptionsList = this.getExceptionsList(type, 'otr');
176 // Settings for Guest hides many sections, so check for null first.
177 if (exceptionsList) {
178 exceptionsList.parentNode.hidden = false;
179 exceptionsList.setExceptions(otrExceptions);
184 * @param {string} type The type of exceptions (e.g. "location") to get.
185 * @param {string} mode The mode of the desired exceptions list (e.g. otr).
186 * @return {?options.contentSettings.ExceptionsList} The corresponding
187 * exceptions list or null.
189 ContentSettings.getExceptionsList = function(type, mode) {
190 var exceptionsList = document.querySelector(
191 'div[contentType=' + type + '] list[mode=' + mode + ']');
192 return !exceptionsList ? null :
193 assertInstanceof(exceptionsList,
194 options.contentSettings.ExceptionsList);
198 * The browser's response to a request to check the validity of a given URL
200 * @param {string} type The content type.
201 * @param {string} mode The browser mode.
202 * @param {string} pattern The pattern.
203 * @param {boolean} valid Whether said pattern is valid in the context of
204 * a content exception setting.
206 ContentSettings.patternValidityCheckComplete =
207 function(type, mode, pattern, valid) {
208 this.getExceptionsList(type, mode).patternValidityCheckComplete(pattern,
213 * Shows/hides the link to the Pepper Flash camera or microphone,
214 * default or exceptions settings.
215 * Please note that whether the link is actually showed or not is also
216 * affected by the style class pepper-flash-settings.
217 * @param {string} linkType Can be 'default' or 'exceptions'.
218 * @param {string} contentType Can be 'mic' or 'camera'.
219 * @param {boolean} show Whether to show (or hide) the link.
221 ContentSettings.showMediaPepperFlashLink =
222 function(linkType, contentType, show) {
223 assert(['default', 'exceptions'].indexOf(linkType) >= 0);
224 assert(['mic', 'camera'].indexOf(contentType) >= 0);
225 $('media-pepper-flash-' + linkType + '-' + contentType).hidden = !show;
229 * Updates the microphone/camera devices menu with the given entries.
230 * @param {string} type The device type.
231 * @param {Array} devices List of available devices.
232 * @param {string} defaultdevice The unique id of the current default device.
234 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) {
235 var deviceSelect = '';
237 deviceSelect = $('media-select-mic');
238 } else if (type == 'camera') {
239 deviceSelect = $('media-select-camera');
241 console.error('Unknown device type for <device select> UI element: ' +
246 deviceSelect.textContent = '';
248 var deviceCount = devices.length;
249 var defaultIndex = -1;
250 for (var i = 0; i < deviceCount; i++) {
251 var device = devices[i];
252 var option = new Option(device.name, device.id);
253 if (option.value == defaultdevice)
255 deviceSelect.appendChild(option);
257 if (defaultIndex >= 0)
258 deviceSelect.selectedIndex = defaultIndex;
262 * Sets the visibility of the microphone/camera devices menu.
263 * @param {string} type The content settings type name of this device.
264 * @param {boolean} show Whether to show the menu.
266 ContentSettings.setDevicesMenuVisibility = function(type, show) {
267 assert(type == 'media-stream-mic' || type == 'media-stream-camera');
268 var deviceSelect = $(type == 'media-stream-mic' ? 'media-select-mic' :
269 'media-select-camera');
270 deviceSelect.hidden = !show;
274 * Enables/disables the protected content exceptions button.
275 * @param {boolean} enable Whether to enable the button.
277 ContentSettings.enableProtectedContentExceptions = function(enable) {
278 var exceptionsButton = $('protected-content-exceptions');
279 if (exceptionsButton)
280 exceptionsButton.disabled = !enable;
284 * Set the default microphone device based on the popup selection.
287 ContentSettings.setDefaultMicrophone_ = function() {
288 var deviceSelect = $('media-select-mic');
289 chrome.send('setDefaultCaptureDevice', ['mic', deviceSelect.value]);
293 * Set the default camera device based on the popup selection.
296 ContentSettings.setDefaultCamera_ = function() {
297 var deviceSelect = $('media-select-camera');
298 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]);
303 ContentSettings: ContentSettings