Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/resources/options/content_settings.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.exportPath('options'); 5 cr.exportPath('options');
6 6
7 /** 7 /**
8 * @typedef {{appId: string, 8 * @typedef {{appId: string,
9 * appName: (string|undefined), 9 * appName: (string|undefined),
10 * embeddingOrigin: (string|undefined), 10 * embeddingOrigin: (string|undefined),
(...skipping 11 matching lines...) Expand all
22 ////////////////////////////////////////////////////////////////////////////// 22 //////////////////////////////////////////////////////////////////////////////
23 // ContentSettings class: 23 // ContentSettings class:
24 24
25 /** 25 /**
26 * Encapsulated handling of content settings page. 26 * Encapsulated handling of content settings page.
27 * @constructor 27 * @constructor
28 * @extends {cr.ui.pageManager.Page} 28 * @extends {cr.ui.pageManager.Page}
29 */ 29 */
30 function ContentSettings() { 30 function ContentSettings() {
31 this.activeNavTab = null; 31 this.activeNavTab = null;
32 Page.call(this, 'content', 32 Page.call(
33 loadTimeData.getString('contentSettingsPageTabTitle'), 33 this, 'content', loadTimeData.getString('contentSettingsPageTabTitle'),
34 'content-settings-page'); 34 'content-settings-page');
35 } 35 }
36 36
37 cr.addSingletonGetter(ContentSettings); 37 cr.addSingletonGetter(ContentSettings);
38 38
39 ContentSettings.prototype = { 39 ContentSettings.prototype = {
40 __proto__: Page.prototype, 40 __proto__: Page.prototype,
41 41
42 /** @override */ 42 /** @override */
43 initializePage: function() { 43 initializePage: function() {
44 Page.prototype.initializePage.call(this); 44 Page.prototype.initializePage.call(this);
45 45
46 var exceptionsButtons = 46 var exceptionsButtons =
47 this.pageDiv.querySelectorAll('.exceptions-list-button'); 47 this.pageDiv.querySelectorAll('.exceptions-list-button');
48 for (var i = 0; i < exceptionsButtons.length; i++) { 48 for (var i = 0; i < exceptionsButtons.length; i++) {
49 exceptionsButtons[i].onclick = function(event) { 49 exceptionsButtons[i].onclick = function(event) {
50 var hash = event.currentTarget.getAttribute('contentType'); 50 var hash = event.currentTarget.getAttribute('contentType');
51 PageManager.showPageByName('contentExceptions', true, 51 PageManager.showPageByName(
52 {hash: '#' + hash}); 52 'contentExceptions', true, {hash: '#' + hash});
53 }; 53 };
54 } 54 }
55 55
56 var manageHandlersButton = $('manage-handlers-button'); 56 var manageHandlersButton = $('manage-handlers-button');
57 if (manageHandlersButton) { 57 if (manageHandlersButton) {
58 manageHandlersButton.onclick = function(event) { 58 manageHandlersButton.onclick = function(event) {
59 PageManager.showPageByName('handlers'); 59 PageManager.showPageByName('handlers');
60 }; 60 };
61 } 61 }
62 62
(...skipping 12 matching lines...) Expand all
75 }; 75 };
76 76
77 $('content-settings-overlay-confirm').onclick = 77 $('content-settings-overlay-confirm').onclick =
78 PageManager.closeOverlay.bind(PageManager); 78 PageManager.closeOverlay.bind(PageManager);
79 79
80 $('media-pepper-flash-default-mic').hidden = true; 80 $('media-pepper-flash-default-mic').hidden = true;
81 $('media-pepper-flash-default-camera').hidden = true; 81 $('media-pepper-flash-default-camera').hidden = true;
82 $('media-pepper-flash-exceptions-mic').hidden = true; 82 $('media-pepper-flash-exceptions-mic').hidden = true;
83 $('media-pepper-flash-exceptions-camera').hidden = true; 83 $('media-pepper-flash-exceptions-camera').hidden = true;
84 84
85 $('media-select-mic').addEventListener('change', 85 $('media-select-mic')
86 ContentSettings.setDefaultMicrophone_); 86 .addEventListener('change', ContentSettings.setDefaultMicrophone_);
87 $('media-select-camera').addEventListener('change', 87 $('media-select-camera')
88 ContentSettings.setDefaultCamera_); 88 .addEventListener('change', ContentSettings.setDefaultCamera_);
89 }, 89 },
90 }; 90 };
91 91
92 ContentSettings.updateHandlersEnabledRadios = function(enabled) { 92 ContentSettings.updateHandlersEnabledRadios = function(enabled) {
93 var selector = '#content-settings-page input[type=radio][value=' + 93 var selector = '#content-settings-page input[type=radio][value=' +
94 (enabled ? 'allow' : 'block') + '].handler-radio'; 94 (enabled ? 'allow' : 'block') + '].handler-radio';
95 document.querySelector(selector).checked = true; 95 document.querySelector(selector).checked = true;
96 }; 96 };
97 97
98 /** 98 /**
99 * Sets the values for all the content settings radios and labels. 99 * Sets the values for all the content settings radios and labels.
100 * @param {Object<{managedBy: string, value: string}>} dict A mapping from 100 * @param {Object<{managedBy: string, value: string}>} dict A mapping from
101 * radio groups to the checked value for that group. 101 * radio groups to the checked value for that group.
102 */ 102 */
103 ContentSettings.setContentFilterSettingsValue = function(dict) { 103 ContentSettings.setContentFilterSettingsValue = function(dict) {
104 for (var group in dict) { 104 for (var group in dict) {
105 var managedBy = dict[group].managedBy; 105 var managedBy = dict[group].managedBy;
106 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ? 106 var controlledBy =
107 managedBy : null; 107 managedBy == 'policy' || managedBy == 'extension' ? managedBy : null;
108 document.querySelector('input[type=radio][name=' + group + '][value=' + 108 document
109 dict[group].value + ']').checked = true; 109 .querySelector(
110 var radios = document.querySelectorAll('input[type=radio][name=' + 110 'input[type=radio][name=' + group +
111 group + ']'); 111 '][value=' + dict[group].value + ']')
112 .checked = true;
113 var radios =
114 document.querySelectorAll('input[type=radio][name=' + group + ']');
112 for (var i = 0, len = radios.length; i < len; i++) { 115 for (var i = 0, len = radios.length; i < len; i++) {
113 radios[i].disabled = (managedBy != 'default'); 116 radios[i].disabled = (managedBy != 'default');
114 radios[i].controlledBy = controlledBy; 117 radios[i].controlledBy = controlledBy;
115 } 118 }
116 var indicators = document.querySelectorAll( 119 var indicators = document.querySelectorAll(
117 'span.controlled-setting-indicator[content-setting=' + group + ']'); 120 'span.controlled-setting-indicator[content-setting=' + group + ']');
118 if (indicators.length == 0) 121 if (indicators.length == 0)
119 continue; 122 continue;
120 // Create a synthetic pref change event decorated as 123 // Create a synthetic pref change event decorated as
121 // CoreOptionsHandler::CreateValueForPref() does. 124 // CoreOptionsHandler::CreateValueForPref() does.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 165
163 /** 166 /**
164 * @param {string} type The type of exceptions (e.g. "location") to get. 167 * @param {string} type The type of exceptions (e.g. "location") to get.
165 * @param {string} mode The mode of the desired exceptions list (e.g. otr). 168 * @param {string} mode The mode of the desired exceptions list (e.g. otr).
166 * @return {?options.contentSettings.ExceptionsList} The corresponding 169 * @return {?options.contentSettings.ExceptionsList} The corresponding
167 * exceptions list or null. 170 * exceptions list or null.
168 */ 171 */
169 ContentSettings.getExceptionsList = function(type, mode) { 172 ContentSettings.getExceptionsList = function(type, mode) {
170 var exceptionsList = document.querySelector( 173 var exceptionsList = document.querySelector(
171 'div[contentType=' + type + '] list[mode=' + mode + ']'); 174 'div[contentType=' + type + '] list[mode=' + mode + ']');
172 return !exceptionsList ? null : 175 return !exceptionsList ?
173 assertInstanceof(exceptionsList, 176 null :
174 options.contentSettings.ExceptionsList); 177 assertInstanceof(
178 exceptionsList, options.contentSettings.ExceptionsList);
175 }; 179 };
176 180
177 /** 181 /**
178 * The browser's response to a request to check the validity of a given URL 182 * The browser's response to a request to check the validity of a given URL
179 * pattern. 183 * pattern.
180 * @param {string} type The content type. 184 * @param {string} type The content type.
181 * @param {string} mode The browser mode. 185 * @param {string} mode The browser mode.
182 * @param {string} pattern The pattern. 186 * @param {string} pattern The pattern.
183 * @param {boolean} valid Whether said pattern is valid in the context of 187 * @param {boolean} valid Whether said pattern is valid in the context of
184 * a content exception setting. 188 * a content exception setting.
185 */ 189 */
186 ContentSettings.patternValidityCheckComplete = 190 ContentSettings.patternValidityCheckComplete = function(
187 function(type, mode, pattern, valid) { 191 type, mode, pattern, valid) {
188 this.getExceptionsList(type, mode).patternValidityCheckComplete(pattern, 192 this.getExceptionsList(type, mode)
189 valid); 193 .patternValidityCheckComplete(pattern, valid);
190 }; 194 };
191 195
192 /** 196 /**
193 * Shows/hides the link to the Pepper Flash camera or microphone, 197 * Shows/hides the link to the Pepper Flash camera or microphone,
194 * default or exceptions settings. 198 * default or exceptions settings.
195 * Please note that whether the link is actually showed or not is also 199 * Please note that whether the link is actually showed or not is also
196 * affected by the style class pepper-flash-settings. 200 * affected by the style class pepper-flash-settings.
197 * @param {string} linkType Can be 'default' or 'exceptions'. 201 * @param {string} linkType Can be 'default' or 'exceptions'.
198 * @param {string} contentType Can be 'mic' or 'camera'. 202 * @param {string} contentType Can be 'mic' or 'camera'.
199 * @param {boolean} show Whether to show (or hide) the link. 203 * @param {boolean} show Whether to show (or hide) the link.
200 */ 204 */
201 ContentSettings.showMediaPepperFlashLink = 205 ContentSettings.showMediaPepperFlashLink = function(
202 function(linkType, contentType, show) { 206 linkType, contentType, show) {
203 assert(['default', 'exceptions'].indexOf(linkType) >= 0); 207 assert(['default', 'exceptions'].indexOf(linkType) >= 0);
204 assert(['mic', 'camera'].indexOf(contentType) >= 0); 208 assert(['mic', 'camera'].indexOf(contentType) >= 0);
205 $('media-pepper-flash-' + linkType + '-' + contentType).hidden = !show; 209 $('media-pepper-flash-' + linkType + '-' + contentType).hidden = !show;
206 }; 210 };
207 211
208 /** 212 /**
209 * Updates the microphone/camera devices menu with the given entries. 213 * Updates the microphone/camera devices menu with the given entries.
210 * @param {string} type The device type. 214 * @param {string} type The device type.
211 * @param {Array} devices List of available devices. 215 * @param {Array} devices List of available devices.
212 * @param {string} defaultdevice The unique id of the current default device. 216 * @param {string} defaultdevice The unique id of the current default device.
213 */ 217 */
214 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) { 218 ContentSettings.updateDevicesMenu = function(type, devices, defaultdevice) {
215 var deviceSelect = ''; 219 var deviceSelect = '';
216 if (type == 'mic') { 220 if (type == 'mic') {
217 deviceSelect = $('media-select-mic'); 221 deviceSelect = $('media-select-mic');
218 } else if (type == 'camera') { 222 } else if (type == 'camera') {
219 deviceSelect = $('media-select-camera'); 223 deviceSelect = $('media-select-camera');
220 } else { 224 } else {
221 console.error('Unknown device type for <device select> UI element: ' + 225 console.error(
222 type); 226 'Unknown device type for <device select> UI element: ' + type);
223 return; 227 return;
224 } 228 }
225 229
226 deviceSelect.textContent = ''; 230 deviceSelect.textContent = '';
227 231
228 var deviceCount = devices.length; 232 var deviceCount = devices.length;
229 var defaultIndex = -1; 233 var defaultIndex = -1;
230 for (var i = 0; i < deviceCount; i++) { 234 for (var i = 0; i < deviceCount; i++) {
231 var device = devices[i]; 235 var device = devices[i];
232 var option = new Option(device.name, device.id); 236 var option = new Option(device.name, device.id);
233 if (option.value == defaultdevice) 237 if (option.value == defaultdevice)
234 defaultIndex = i; 238 defaultIndex = i;
235 deviceSelect.appendChild(option); 239 deviceSelect.appendChild(option);
236 } 240 }
237 if (defaultIndex >= 0) 241 if (defaultIndex >= 0)
238 deviceSelect.selectedIndex = defaultIndex; 242 deviceSelect.selectedIndex = defaultIndex;
239 }; 243 };
240 244
241 /** 245 /**
242 * Sets the visibility of the microphone/camera devices menu. 246 * Sets the visibility of the microphone/camera devices menu.
243 * @param {string} type The content settings type name of this device. 247 * @param {string} type The content settings type name of this device.
244 * @param {boolean} show Whether to show the menu. 248 * @param {boolean} show Whether to show the menu.
245 */ 249 */
246 ContentSettings.setDevicesMenuVisibility = function(type, show) { 250 ContentSettings.setDevicesMenuVisibility = function(type, show) {
247 assert(type == 'media-stream-mic' || type == 'media-stream-camera'); 251 assert(type == 'media-stream-mic' || type == 'media-stream-camera');
248 var deviceSelect = $(type == 'media-stream-mic' ? 'media-select-mic' : 252 var deviceSelect =
249 'media-select-camera'); 253 $(type == 'media-stream-mic' ? 'media-select-mic' :
254 'media-select-camera');
250 deviceSelect.hidden = !show; 255 deviceSelect.hidden = !show;
251 }; 256 };
252 257
253 /** 258 /**
254 * Enables/disables the protected content exceptions button. 259 * Enables/disables the protected content exceptions button.
255 * @param {boolean} enable Whether to enable the button. 260 * @param {boolean} enable Whether to enable the button.
256 */ 261 */
257 ContentSettings.enableProtectedContentExceptions = function(enable) { 262 ContentSettings.enableProtectedContentExceptions = function(enable) {
258 var exceptionsButton = $('protected-content-exceptions'); 263 var exceptionsButton = $('protected-content-exceptions');
259 if (exceptionsButton) 264 if (exceptionsButton)
(...skipping 12 matching lines...) Expand all
272 /** 277 /**
273 * Set the default camera device based on the popup selection. 278 * Set the default camera device based on the popup selection.
274 * @private 279 * @private
275 */ 280 */
276 ContentSettings.setDefaultCamera_ = function() { 281 ContentSettings.setDefaultCamera_ = function() {
277 var deviceSelect = $('media-select-camera'); 282 var deviceSelect = $('media-select-camera');
278 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]); 283 chrome.send('setDefaultCaptureDevice', ['camera', deviceSelect.value]);
279 }; 284 };
280 285
281 // Export 286 // Export
282 return { 287 return {ContentSettings: ContentSettings};
283 ContentSettings: ContentSettings
284 };
285 288
286 }); 289 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698