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. 4 5 if (!loadTimeData.getBoolean('newContentSettings')) { 6 7 cr.define('options', function() { 8 /** @const */ var OptionsPage = options.OptionsPage; 9 10 ////////////////////////////////////////////////////////////////////////////// 11 // ContentSettings class: 12 13 /** 14 * Encapsulated handling of content settings page. 15 * @constructor 16 */ 17 function ContentSettings() { 18 this.activeNavTab = null; 19 OptionsPage.call(this, 'content', 20 loadTimeData.getString('contentSettingsPageTabTitle'), 21 'content-settings-page'); 22 } 23 24 cr.addSingletonGetter(ContentSettings); 25 26 ContentSettings.prototype = { 27 __proto__: OptionsPage.prototype, 28 29 initializePage: function() { 30 OptionsPage.prototype.initializePage.call(this); 31 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(); 37 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}, 43 page.title, 44 '/' + url); 45 46 // Navigate after the history has been replaced in order to have the 47 // correct hash loaded. 48 OptionsPage.showPageByName('contentExceptions', false); 49 50 uber.invokeMethodOnParent('setPath', {path: url}); 51 uber.invokeMethodOnParent('setTitle', 52 {title: loadTimeData.getString(hash + 'TabTitle')}); 53 }; 54 } 55 56 var manageHandlersButton = $('manage-handlers-button'); 57 if (manageHandlersButton) { 58 manageHandlersButton.onclick = function(event) { 59 OptionsPage.navigateToPage('handlers'); 60 }; 61 } 62 63 $('manage-galleries-button').onclick = function(event) { 64 OptionsPage.navigateToPage('manageGalleries'); 65 }; 66 67 if (cr.isChromeOS) 68 UIAccountTweaks.applyGuestModeVisibility(document); 69 70 // Cookies filter page --------------------------------------------------- 71 $('show-cookies-button').onclick = function(event) { 72 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']); 73 OptionsPage.navigateToPage('cookies'); 74 }; 75 76 $('content-settings-overlay-confirm').onclick = 77 OptionsPage.closeOverlay.bind(OptionsPage); 78 79 $('media-pepper-flash-default').hidden = true; 80 $('media-pepper-flash-exceptions').hidden = true; 81 82 $('media-select-mic').addEventListener('change', 83 ContentSettings.setDefaultMicrophone_); 84 $('media-select-camera').addEventListener('change', 85 ContentSettings.setDefaultCamera_); 86 }, 87 }; 88 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; 93 }; 94 95 /** 96 * Sets the values for all the content settings radios. 97 * @param {Object} dict A mapping from radio groups to the checked value for 98 * that group. 99 */ 100 ContentSettings.setContentFilterSettingsValue = function(dict) { 101 for (var group in dict) { 102 var managedBy = dict[group].managedBy; 103 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ? 104 managedBy : null; 105 document.querySelector('input[type=radio][name=' + group + '][value=' + 106 dict[group].value + ']').checked = true; 107 var radios = document.querySelectorAll('input[type=radio][name=' + 108 group + ']'); 109 for (var i = 0, len = radios.length; i < len; i++) { 110 radios[i].disabled = (managedBy != 'default'); 111 radios[i].controlledBy = controlledBy; 112 } 113 var indicators = document.querySelectorAll( 114 'span.controlled-setting-indicator[content-setting=' + group + ']'); 115 if (indicators.length == 0) 116 continue; 117 // Create a synthetic pref change event decorated as 118 // CoreOptionsHandler::CreateValueForPref() does. 119 var event = new cr.Event(group); 120 event.value = { 121 value: dict[group].value, 122 controlledBy: controlledBy, 123 }; 124 for (var i = 0; i < indicators.length; i++) 125 indicators[i].handlePrefChange(event); 126 } 127 }; 128 129 /** 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 139 * media label. 140 * {String} bubbleText The text to use inside the bubble if it is shown. 141 */ 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); 147 148 if (mediaSettings.micDisabled) 149 $('media-select-mic').disabled = true; 150 if (mediaSettings.cameraDisabled) 151 $('media-select-camera').disabled = true; 152 153 OptionsPage.hideBubble(); 154 // Create a synthetic pref change event decorated as 155 // CoreOptionsHandler::CreateValueForPref() does. 156 var event = new cr.Event(); 157 event.value = {}; 158 159 if (mediaSettings.showBubble) { 160 event.value = { controlledBy: 'policy' }; 161 $('media-indicator').setAttribute( 162 'textpolicy', loadTimeData.getString(mediaSettings.bubbleText)); 163 $('media-indicator').location = cr.ui.ArrowLocation.TOP_START; 164 } 165 166 $('media-indicator').handlePrefChange(event); 167 }; 168 169 /** 170 * Initializes an exceptions list. 171 * @param {string} type The content type that we are setting exceptions for. 172 * @param {Array} list An array of pairs, where the first element of each pair 173 * is the filter string, and the second is the setting (allow/block). 174 */ 175 ContentSettings.setExceptions = function(type, list) { 176 var exceptionsList = 177 document.querySelector('div[contentType=' + type + ']' + 178 ' list[mode=normal]'); 179 exceptionsList.setExceptions(list); 180 }; 181 182 ContentSettings.setHandlers = function(list) { 183 $('handlers-list').setHandlers(list); 184 }; 185 186 ContentSettings.setIgnoredHandlers = function(list) { 187 $('ignored-handlers-list').setHandlers(list); 188 }; 189 190 ContentSettings.setOTRExceptions = function(type, list) { 191 var exceptionsList = 192 document.querySelector('div[contentType=' + type + ']' + 193 ' list[mode=otr]'); 194 195 exceptionsList.parentNode.hidden = false; 196 exceptionsList.setExceptions(list); 197 }; 198 199 /** 200 * The browser's response to a request to check the validity of a given URL 201 * pattern. 202 * @param {string} type The content type. 203 * @param {string} mode The browser mode. 204 * @param {string} pattern The pattern. 205 * @param {bool} valid Whether said pattern is valid in the context of 206 * a content exception setting. 207 */ 208 ContentSettings.patternValidityCheckComplete = 209 function(type, mode, pattern, valid) { 210 var exceptionsList = 211 document.querySelector('div[contentType=' + type + '] ' + 212 'list[mode=' + mode + ']'); 213 exceptionsList.patternValidityCheckComplete(pattern, valid); 214 }; 215 216 /** 217 * Shows/hides the link to the Pepper Flash camera and microphone default 218 * settings. 219 * Please note that whether the link is actually showed or not is also 220 * affected by the style class pepper-flash-settings. 221 */ 222 ContentSettings.showMediaPepperFlashDefaultLink = function(show) { 223 $('media-pepper-flash-default').hidden = !show; 224 } 225 226 /** 227 * Shows/hides the link to the Pepper Flash camera and microphone 228 * site-specific settings. 229 * Please note that whether the link is actually showed or not is also 230 * affected by the style class pepper-flash-settings. 231 */ 232 ContentSettings.showMediaPepperFlashExceptionsLink = function(show) { 233 $('media-pepper-flash-exceptions').hidden = !show; 234 } 235 236 /** 237 * Shows/hides the whole Web MIDI settings. 238 * @param {bool} show Wether to show the whole Web MIDI settings. 239 */ 240 ContentSettings.showExperimentalWebMIDISettings = function(show) { 241 $('experimental-web-midi-settings').hidden = !show; 242 } 243 244 /** 245 * Updates the microphone/camera devices menu with the given entries. 246 * @param {string} type The device type. 247 * @param {Array} devices List of available devices. 248 * @param {string} defaultdevice The unique id of the current default device. 249 */ 250 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) { 251 var deviceSelect = ''; 252 if (type == 'mic') { 253 deviceSelect = $('media-select-mic'); 254 } else if (type == 'camera') { 255 deviceSelect = $('media-select-camera'); 256 } else { 257 console.error('Unknown device type for <device select> UI element: ' + 258 type); 259 return; 260 } 261 262 deviceSelect.textContent = ''; 263 264 var deviceCount = devices.length; 265 var defaultIndex = -1; 266 for (var i = 0; i < deviceCount; i++) { 267 var device = devices[i]; 268 var option = new Option(device.name, device.id); 269 if (option.value == defaultdevice) 270 defaultIndex = i; 271 deviceSelect.appendChild(option); 272 } 273 if (defaultIndex >= 0) 274 deviceSelect.selectedIndex = defaultIndex; 275 }; 276 277 /** 278 * Set the default microphone device based on the popup selection. 279 * @private 280 */ 281 ContentSettings.setDefaultMicrophone_ = function() { 282 var deviceSelect = $('media-select-mic'); 283 chrome.send('setDefaultCaptureDevice', ['mic', deviceSelect.value]); 284 }; 285 286 /** 287 * Set the default camera device based on the popup selection. 288 * @private 289 */ 290 ContentSettings.setDefaultCamera_ = function() { 291 var deviceSelect = $('media-select-camera'); 292 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]); 293 }; 294 295 // Export 296 return { 297 ContentSettings: ContentSettings 298 }; 299 300 }); 301 302 } 303