No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / resources / options / content_settings.js
blobf77b3f48b9af2a007d971b03e668c9e9c4c86633
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');
7 /**
8 * @typedef {{appId: string,
9 * appName: (string|undefined),
10 * embeddingOrigin: (string|undefined),
11 * origin: string,
12 * setting: string,
13 * source: string,
14 * video: (string|undefined)}}
16 options.Exception;
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 = {
24 'location': 'location',
25 'notifications': 'notifications',
26 'media-stream': 'mediaStream',
27 'cookies': 'cookies',
28 'multiple-automatic-downloads': 'multipleAutomaticDownloads',
29 'images': 'images',
30 'plugins': 'plugins',
31 'popups': 'popups',
32 'javascript': 'javascript'
35 //////////////////////////////////////////////////////////////////////////////
36 // ContentSettings class:
38 /**
39 * Encapsulated handling of content settings page.
40 * @constructor
41 * @extends {cr.ui.pageManager.Page}
43 function ContentSettings() {
44 this.activeNavTab = null;
45 Page.call(this, 'content',
46 loadTimeData.getString('contentSettingsPageTabTitle'),
47 'content-settings-page');
50 cr.addSingletonGetter(ContentSettings);
52 ContentSettings.prototype = {
53 __proto__: Page.prototype,
55 /** @override */
56 initializePage: function() {
57 Page.prototype.initializePage.call(this);
59 var exceptionsButtons =
60 this.pageDiv.querySelectorAll('.exceptions-list-button');
61 for (var i = 0; i < exceptionsButtons.length; i++) {
62 exceptionsButtons[i].onclick = function(event) {
63 var hash = event.currentTarget.getAttribute('contentType');
64 PageManager.showPageByName('contentExceptions', true,
65 {hash: '#' + hash});
69 var manageHandlersButton = $('manage-handlers-button');
70 if (manageHandlersButton) {
71 manageHandlersButton.onclick = function(event) {
72 PageManager.showPageByName('handlers');
76 if (cr.isChromeOS) {
77 // Disable some controls for Guest in Chrome OS.
78 UIAccountTweaks.applyGuestSessionVisibility(document);
80 // Disable some controls for Public session in Chrome OS.
81 UIAccountTweaks.applyPublicSessionVisibility(document);
84 // Cookies filter page ---------------------------------------------------
85 $('show-cookies-button').onclick = function(event) {
86 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
87 PageManager.showPageByName('cookies');
90 $('content-settings-overlay-confirm').onclick =
91 PageManager.closeOverlay.bind(PageManager);
93 $('media-pepper-flash-default').hidden = true;
94 $('media-pepper-flash-exceptions').hidden = true;
96 $('media-select-mic').addEventListener('change',
97 ContentSettings.setDefaultMicrophone_);
98 $('media-select-camera').addEventListener('change',
99 ContentSettings.setDefaultCamera_);
103 ContentSettings.updateHandlersEnabledRadios = function(enabled) {
104 var selector = '#content-settings-page input[type=radio][value=' +
105 (enabled ? 'allow' : 'block') + '].handler-radio';
106 document.querySelector(selector).checked = true;
110 * Sets the values for all the content settings radios and labels.
111 * @param {Object<{managedBy: string, value: string}>} dict A mapping from
112 * radio groups to the checked value for that group.
114 ContentSettings.setContentFilterSettingsValue = function(dict) {
115 for (var group in dict) {
116 var settingLabel = $(group + '-default-string');
117 if (settingLabel) {
118 var value = dict[group].value;
119 var valueId =
120 permissionsLookup[group] + value[0].toUpperCase() + value.slice(1);
121 settingLabel.textContent = loadTimeData.getString(valueId);
124 var managedBy = dict[group].managedBy;
125 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ?
126 managedBy : null;
127 document.querySelector('input[type=radio][name=' + group + '][value=' +
128 dict[group].value + ']').checked = true;
129 var radios = document.querySelectorAll('input[type=radio][name=' +
130 group + ']');
131 for (var i = 0, len = radios.length; i < len; i++) {
132 radios[i].disabled = (managedBy != 'default');
133 radios[i].controlledBy = controlledBy;
135 var indicators = document.querySelectorAll(
136 'span.controlled-setting-indicator[content-setting=' + group + ']');
137 if (indicators.length == 0)
138 continue;
139 // Create a synthetic pref change event decorated as
140 // CoreOptionsHandler::CreateValueForPref() does.
141 var event = new Event(group);
142 event.value = {
143 value: dict[group].value,
144 controlledBy: controlledBy,
146 for (var i = 0; i < indicators.length; i++) {
147 indicators[i].handlePrefChange(event);
153 * Updates the labels and indicators for the Media settings. Those require
154 * special handling because they are backed by multiple prefs and can change
155 * their scope based on the managed state of the backing prefs.
156 * @param {{askText: string, blockText: string, cameraDisabled: boolean,
157 * micDisabled: boolean, showBubble: boolean, bubbleText: string}}
158 * mediaSettings A dictionary containing the following fields:
159 * askText The label for the ask radio button.
160 * blockText The label for the block radio button.
161 * cameraDisabled Whether to disable the camera dropdown.
162 * micDisabled Whether to disable the microphone dropdown.
163 * showBubble Wether to show the managed icon and bubble for the media
164 * label.
165 * bubbleText The text to use inside the bubble if it is shown.
167 ContentSettings.updateMediaUI = function(mediaSettings) {
168 $('media-stream-ask-label').innerHTML =
169 loadTimeData.getString(mediaSettings.askText);
170 $('media-stream-block-label').innerHTML =
171 loadTimeData.getString(mediaSettings.blockText);
173 if (mediaSettings.micDisabled)
174 $('media-select-mic').disabled = true;
175 if (mediaSettings.cameraDisabled)
176 $('media-select-camera').disabled = true;
178 PageManager.hideBubble();
179 // Create a synthetic pref change event decorated as
180 // CoreOptionsHandler::CreateValueForPref() does.
181 // TODO(arv): It was not clear what event type this should use?
182 var event = new Event('undefined');
183 event.value = {};
185 if (mediaSettings.showBubble) {
186 event.value = { controlledBy: 'policy' };
187 $('media-indicator').setAttribute(
188 'textpolicy', loadTimeData.getString(mediaSettings.bubbleText));
189 $('media-indicator').location = cr.ui.ArrowLocation.TOP_START;
192 $('media-indicator').handlePrefChange(event);
196 * Initializes an exceptions list.
197 * @param {string} type The content type that we are setting exceptions for.
198 * @param {Array<options.Exception>} exceptions An array of pairs, where the
199 * first element of each pair is the filter string, and the second is the
200 * setting (allow/block).
202 ContentSettings.setExceptions = function(type, exceptions) {
203 this.getExceptionsList(type, 'normal').setExceptions(exceptions);
206 ContentSettings.setHandlers = function(handlers) {
207 $('handlers-list').setHandlers(handlers);
210 ContentSettings.setIgnoredHandlers = function(ignoredHandlers) {
211 $('ignored-handlers-list').setHandlers(ignoredHandlers);
214 ContentSettings.setOTRExceptions = function(type, otrExceptions) {
215 var exceptionsList = this.getExceptionsList(type, 'otr');
216 // Settings for Guest hides many sections, so check for null first.
217 if (exceptionsList) {
218 exceptionsList.parentNode.hidden = false;
219 exceptionsList.setExceptions(otrExceptions);
224 * @param {string} type The type of exceptions (e.g. "location") to get.
225 * @param {string} mode The mode of the desired exceptions list (e.g. otr).
226 * @return {?options.contentSettings.ExceptionsList} The corresponding
227 * exceptions list or null.
229 ContentSettings.getExceptionsList = function(type, mode) {
230 var exceptionsList = document.querySelector(
231 'div[contentType=' + type + '] list[mode=' + mode + ']');
232 return !exceptionsList ? null :
233 assertInstanceof(exceptionsList,
234 options.contentSettings.ExceptionsList);
238 * The browser's response to a request to check the validity of a given URL
239 * pattern.
240 * @param {string} type The content type.
241 * @param {string} mode The browser mode.
242 * @param {string} pattern The pattern.
243 * @param {boolean} valid Whether said pattern is valid in the context of
244 * a content exception setting.
246 ContentSettings.patternValidityCheckComplete =
247 function(type, mode, pattern, valid) {
248 this.getExceptionsList(type, mode).patternValidityCheckComplete(pattern,
249 valid);
253 * Shows/hides the link to the Pepper Flash camera and microphone default
254 * settings.
255 * Please note that whether the link is actually showed or not is also
256 * affected by the style class pepper-flash-settings.
258 ContentSettings.showMediaPepperFlashDefaultLink = function(show) {
259 $('media-pepper-flash-default').hidden = !show;
263 * Shows/hides the link to the Pepper Flash camera and microphone
264 * site-specific settings.
265 * Please note that whether the link is actually showed or not is also
266 * affected by the style class pepper-flash-settings.
268 ContentSettings.showMediaPepperFlashExceptionsLink = function(show) {
269 $('media-pepper-flash-exceptions').hidden = !show;
273 * Updates the microphone/camera devices menu with the given entries.
274 * @param {string} type The device type.
275 * @param {Array} devices List of available devices.
276 * @param {string} defaultdevice The unique id of the current default device.
278 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) {
279 var deviceSelect = '';
280 if (type == 'mic') {
281 deviceSelect = $('media-select-mic');
282 } else if (type == 'camera') {
283 deviceSelect = $('media-select-camera');
284 } else {
285 console.error('Unknown device type for <device select> UI element: ' +
286 type);
287 return;
290 deviceSelect.textContent = '';
292 var deviceCount = devices.length;
293 var defaultIndex = -1;
294 for (var i = 0; i < deviceCount; i++) {
295 var device = devices[i];
296 var option = new Option(device.name, device.id);
297 if (option.value == defaultdevice)
298 defaultIndex = i;
299 deviceSelect.appendChild(option);
301 if (defaultIndex >= 0)
302 deviceSelect.selectedIndex = defaultIndex;
306 * Enables/disables the protected content exceptions button.
307 * @param {boolean} enable Whether to enable the button.
309 ContentSettings.enableProtectedContentExceptions = function(enable) {
310 var exceptionsButton = $('protected-content-exceptions');
311 if (exceptionsButton)
312 exceptionsButton.disabled = !enable;
316 * Set the default microphone device based on the popup selection.
317 * @private
319 ContentSettings.setDefaultMicrophone_ = function() {
320 var deviceSelect = $('media-select-mic');
321 chrome.send('setDefaultCaptureDevice', ['mic', deviceSelect.value]);
325 * Set the default camera device based on the popup selection.
326 * @private
328 ContentSettings.setDefaultCamera_ = function() {
329 var deviceSelect = $('media-select-camera');
330 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]);
333 // Export
334 return {
335 ContentSettings: ContentSettings