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 Page
= cr
.ui
.pageManager
.Page
;
7 /** @const */ var PageManager
= cr
.ui
.pageManager
.PageManager
;
9 // Lookup table to generate the i18n strings.
10 /** @const */ var permissionsLookup
= {
11 'location': 'location',
12 'notifications': 'notifications',
13 'media-stream': 'mediaStream',
15 'multiple-automatic-downloads': 'multipleAutomaticDownloads',
19 'javascript': 'javascript'
22 //////////////////////////////////////////////////////////////////////////////
23 // ContentSettings class:
26 * Encapsulated handling of content settings page.
29 function ContentSettings() {
30 this.activeNavTab
= null;
31 Page
.call(this, 'content',
32 loadTimeData
.getString('contentSettingsPageTabTitle'),
33 'content-settings-page');
36 cr
.addSingletonGetter(ContentSettings
);
38 ContentSettings
.prototype = {
39 __proto__
: Page
.prototype,
42 initializePage: function() {
43 Page
.prototype.initializePage
.call(this);
45 var exceptionsButtons
=
46 this.pageDiv
.querySelectorAll('.exceptions-list-button');
47 for (var i
= 0; i
< exceptionsButtons
.length
; i
++) {
48 exceptionsButtons
[i
].onclick = function(event
) {
49 var hash
= event
.currentTarget
.getAttribute('contentType');
50 PageManager
.showPageByName('contentExceptions', true,
55 var experimentalExceptionsButtons
=
56 this.pageDiv
.querySelectorAll('.website-settings-permission-button');
57 for (var i
= 0; i
< experimentalExceptionsButtons
.length
; i
++) {
58 experimentalExceptionsButtons
[i
].onclick = function(event
) {
59 var hash
= event
.currentTarget
.getAttribute('contentType');
60 WebsiteSettingsManager
.showWebsiteSettings(hash
);
64 var manageHandlersButton
= $('manage-handlers-button');
65 if (manageHandlersButton
) {
66 manageHandlersButton
.onclick = function(event
) {
67 PageManager
.showPageByName('handlers');
72 // Disable some controls for Guest in Chrome OS.
73 UIAccountTweaks
.applyGuestSessionVisibility(document
);
75 // Disable some controls for Public session in Chrome OS.
76 UIAccountTweaks
.applyPublicSessionVisibility(document
);
79 // Cookies filter page ---------------------------------------------------
80 $('show-cookies-button').onclick = function(event
) {
81 chrome
.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']);
82 PageManager
.showPageByName('cookies');
85 $('content-settings-overlay-confirm').onclick
=
86 PageManager
.closeOverlay
.bind(PageManager
);
88 $('media-pepper-flash-default').hidden
= true;
89 $('media-pepper-flash-exceptions').hidden
= true;
91 $('media-select-mic').addEventListener('change',
92 ContentSettings
.setDefaultMicrophone_
);
93 $('media-select-camera').addEventListener('change',
94 ContentSettings
.setDefaultCamera_
);
96 if (loadTimeData
.getBoolean('websiteSettingsManagerEnabled')) {
98 this.pageDiv
.querySelectorAll('.replace-with-website-settings');
99 for (var i
= 0; i
< oldUI
.length
; i
++) {
100 oldUI
[i
].hidden
= true;
104 this.pageDiv
.querySelectorAll('.experimental-website-settings');
105 for (var i
= 0; i
< newUI
.length
; i
++) {
106 newUI
[i
].hidden
= false;
112 ContentSettings
.updateHandlersEnabledRadios = function(enabled
) {
113 var selector
= '#content-settings-page input[type=radio][value=' +
114 (enabled
? 'allow' : 'block') + '].handler-radio';
115 document
.querySelector(selector
).checked
= true;
119 * Sets the values for all the content settings radios and labels.
120 * @param {Object} dict A mapping from radio groups to the checked value for
123 ContentSettings
.setContentFilterSettingsValue = function(dict
) {
124 for (var group
in dict
) {
125 var settingLabel
= $(group
+ '-default-string');
127 var value
= dict
[group
].value
;
129 permissionsLookup
[group
] + value
[0].toUpperCase() + value
.slice(1);
130 settingLabel
.textContent
= loadTimeData
.getString(valueId
);
133 var managedBy
= dict
[group
].managedBy
;
134 var controlledBy
= managedBy
== 'policy' || managedBy
== 'extension' ?
136 document
.querySelector('input[type=radio][name=' + group
+ '][value=' +
137 dict
[group
].value
+ ']').checked
= true;
138 var radios
= document
.querySelectorAll('input[type=radio][name=' +
140 for (var i
= 0, len
= radios
.length
; i
< len
; i
++) {
141 radios
[i
].disabled
= (managedBy
!= 'default');
142 radios
[i
].controlledBy
= controlledBy
;
144 var indicators
= document
.querySelectorAll(
145 'span.controlled-setting-indicator[content-setting=' + group
+ ']');
146 if (indicators
.length
== 0)
148 // Create a synthetic pref change event decorated as
149 // CoreOptionsHandler::CreateValueForPref() does.
150 var event
= new Event(group
);
152 value
: dict
[group
].value
,
153 controlledBy
: controlledBy
,
155 for (var i
= 0; i
< indicators
.length
; i
++) {
156 indicators
[i
].handlePrefChange(event
);
162 * Updates the labels and indicators for the Media settings. Those require
163 * special handling because they are backed by multiple prefs and can change
164 * their scope based on the managed state of the backing prefs.
165 * @param {Object} mediaSettings A dictionary containing the following fields:
166 * {String} askText The label for the ask radio button.
167 * {String} blockText The label for the block radio button.
168 * {Boolean} cameraDisabled Whether to disable the camera dropdown.
169 * {Boolean} micDisabled Whether to disable the microphone dropdown.
170 * {Boolean} showBubble Wether to show the managed icon and bubble for the
172 * {String} bubbleText The text to use inside the bubble if it is shown.
174 ContentSettings
.updateMediaUI = function(mediaSettings
) {
175 $('media-stream-ask-label').innerHTML
=
176 loadTimeData
.getString(mediaSettings
.askText
);
177 $('media-stream-block-label').innerHTML
=
178 loadTimeData
.getString(mediaSettings
.blockText
);
180 if (mediaSettings
.micDisabled
)
181 $('media-select-mic').disabled
= true;
182 if (mediaSettings
.cameraDisabled
)
183 $('media-select-camera').disabled
= true;
185 PageManager
.hideBubble();
186 // Create a synthetic pref change event decorated as
187 // CoreOptionsHandler::CreateValueForPref() does.
188 // TODO(arv): It was not clear what event type this should use?
189 var event
= new Event('undefined');
192 if (mediaSettings
.showBubble
) {
193 event
.value
= { controlledBy
: 'policy' };
194 $('media-indicator').setAttribute(
195 'textpolicy', loadTimeData
.getString(mediaSettings
.bubbleText
));
196 $('media-indicator').location
= cr
.ui
.ArrowLocation
.TOP_START
;
199 $('media-indicator').handlePrefChange(event
);
203 * Initializes an exceptions list.
204 * @param {string} type The content type that we are setting exceptions for.
205 * @param {Array} exceptions An array of pairs, where the first element of
206 * each pair is the filter string, and the second is the setting
209 ContentSettings
.setExceptions = function(type
, exceptions
) {
210 this.getExceptionsList(type
, 'normal').setExceptions(exceptions
);
213 ContentSettings
.setHandlers = function(handlers
) {
214 $('handlers-list').setHandlers(handlers
);
217 ContentSettings
.setIgnoredHandlers = function(ignoredHandlers
) {
218 $('ignored-handlers-list').setHandlers(ignoredHandlers
);
221 ContentSettings
.setOTRExceptions = function(type
, otrExceptions
) {
222 var exceptionsList
= this.getExceptionsList(type
, 'otr');
223 // Settings for Guest hides many sections, so check for null first.
224 if (exceptionsList
) {
225 exceptionsList
.parentNode
.hidden
= false;
226 exceptionsList
.setExceptions(otrExceptions
);
231 * @param {string} type The type of exceptions (e.g. "location") to get.
232 * @param {string} mode The mode of the desired exceptions list (e.g. otr).
233 * @return {?options.contentSettings.ExceptionsList} The corresponding
234 * exceptions list or null.
236 ContentSettings
.getExceptionsList = function(type
, mode
) {
237 return document
.querySelector(
238 'div[contentType=' + type
+ '] list[mode=' + mode
+ ']');
242 * The browser's response to a request to check the validity of a given URL
244 * @param {string} type The content type.
245 * @param {string} mode The browser mode.
246 * @param {string} pattern The pattern.
247 * @param {boolean} valid Whether said pattern is valid in the context of
248 * a content exception setting.
250 ContentSettings
.patternValidityCheckComplete
=
251 function(type
, mode
, pattern
, valid
) {
252 this.getExceptionsList(type
, mode
).patternValidityCheckComplete(pattern
,
257 * Shows/hides the link to the Pepper Flash camera and microphone default
259 * Please note that whether the link is actually showed or not is also
260 * affected by the style class pepper-flash-settings.
262 ContentSettings
.showMediaPepperFlashDefaultLink = function(show
) {
263 $('media-pepper-flash-default').hidden
= !show
;
267 * Shows/hides the link to the Pepper Flash camera and microphone
268 * site-specific settings.
269 * Please note that whether the link is actually showed or not is also
270 * affected by the style class pepper-flash-settings.
272 ContentSettings
.showMediaPepperFlashExceptionsLink = function(show
) {
273 $('media-pepper-flash-exceptions').hidden
= !show
;
277 * Shows/hides the whole Web MIDI settings.
278 * @param {boolean} show Wether to show the whole Web MIDI settings.
280 ContentSettings
.showExperimentalWebMIDISettings = function(show
) {
281 $('experimental-web-midi-settings').hidden
= !show
;
285 * Updates the microphone/camera devices menu with the given entries.
286 * @param {string} type The device type.
287 * @param {Array} devices List of available devices.
288 * @param {string} defaultdevice The unique id of the current default device.
290 ContentSettings
.updateDevicesMenu = function(type
, devices
, defaultdevice
) {
291 var deviceSelect
= '';
293 deviceSelect
= $('media-select-mic');
294 } else if (type
== 'camera') {
295 deviceSelect
= $('media-select-camera');
297 console
.error('Unknown device type for <device select> UI element: ' +
302 deviceSelect
.textContent
= '';
304 var deviceCount
= devices
.length
;
305 var defaultIndex
= -1;
306 for (var i
= 0; i
< deviceCount
; i
++) {
307 var device
= devices
[i
];
308 var option
= new Option(device
.name
, device
.id
);
309 if (option
.value
== defaultdevice
)
311 deviceSelect
.appendChild(option
);
313 if (defaultIndex
>= 0)
314 deviceSelect
.selectedIndex
= defaultIndex
;
318 * Enables/disables the protected content exceptions button.
319 * @param {boolean} enable Whether to enable the button.
321 ContentSettings
.enableProtectedContentExceptions = function(enable
) {
322 var exceptionsButton
= $('protected-content-exceptions');
323 if (exceptionsButton
)
324 exceptionsButton
.disabled
= !enable
;
328 * Set the default microphone device based on the popup selection.
331 ContentSettings
.setDefaultMicrophone_ = function() {
332 var deviceSelect
= $('media-select-mic');
333 chrome
.send('setDefaultCaptureDevice', ['mic', deviceSelect
.value
]);
337 * Set the default camera device based on the popup selection.
340 ContentSettings
.setDefaultCamera_ = function() {
341 var deviceSelect
= $('media-select-camera');
342 chrome
.send('setDefaultCaptureDevice', ['camera', deviceSelect
.value
]);
347 ContentSettings
: ContentSettings