OLD | NEW |
| (Empty) |
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 cr.define('options', function() { | |
6 /** @const */ var OptionsPage = options.OptionsPage; | |
7 | |
8 ////////////////////////////////////////////////////////////////////////////// | |
9 // ContentSettings class: | |
10 | |
11 /** | |
12 * Encapsulated handling of content settings page. | |
13 * @constructor | |
14 */ | |
15 function ContentSettings() { | |
16 this.activeNavTab = null; | |
17 OptionsPage.call(this, 'content', | |
18 loadTimeData.getString('contentSettingsPageTabTitle'), | |
19 'content-settings-page'); | |
20 } | |
21 | |
22 cr.addSingletonGetter(ContentSettings); | |
23 | |
24 ContentSettings.prototype = { | |
25 __proto__: OptionsPage.prototype, | |
26 | |
27 initializePage: function() { | |
28 OptionsPage.prototype.initializePage.call(this); | |
29 | |
30 chrome.send('getContentFilterSettings'); | |
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.target.getAttribute('contentType'); | |
41 var url = page.name + '#' + hash; | |
42 window.history.replaceState({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.navigateToPage('contentExceptions'); | |
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 $('show-app-cookies-button').onclick = function(event) { | |
76 OptionsPage.navigateToPage('app-cookies'); | |
77 }; | |
78 | |
79 var intentsSection = $('intents-section'); | |
80 if (!loadTimeData.getBoolean('enable_web_intents') && intentsSection) | |
81 intentsSection.parentNode.removeChild(intentsSection); | |
82 | |
83 $('content-settings-overlay-confirm').onclick = | |
84 OptionsPage.closeOverlay.bind(OptionsPage); | |
85 | |
86 $('pepper-flash-cameramic-section').style.display = 'none'; | |
87 $('pepper-flash-cameramic-exceptions-div').style.display = 'none'; | |
88 }, | |
89 }; | |
90 | |
91 ContentSettings.updateHandlersEnabledRadios = function(enabled) { | |
92 var selector = '#content-settings-page input[type=radio][value=' + | |
93 (enabled ? 'allow' : 'block') + '].handler-radio'; | |
94 document.querySelector(selector).checked = true; | |
95 }; | |
96 | |
97 /** | |
98 * Sets the values for all the content settings radios. | |
99 * @param {Object} dict A mapping from radio groups to the checked value for | |
100 * that group. | |
101 */ | |
102 ContentSettings.setContentFilterSettingsValue = function(dict) { | |
103 for (var group in dict) { | |
104 document.querySelector('input[type=radio][name=' + group + '][value=' + | |
105 dict[group]['value'] + ']').checked = true; | |
106 var radios = document.querySelectorAll('input[type=radio][name=' + | |
107 group + ']'); | |
108 var managedBy = dict[group]['managedBy']; | |
109 for (var i = 0, len = radios.length; i < len; i++) { | |
110 radios[i].disabled = (managedBy != 'default'); | |
111 radios[i].controlledBy = managedBy; | |
112 } | |
113 } | |
114 OptionsPage.updateManagedBannerVisibility(); | |
115 }; | |
116 | |
117 /** | |
118 * Initializes an exceptions list. | |
119 * @param {string} type The content type that we are setting exceptions for. | |
120 * @param {Array} list An array of pairs, where the first element of each pair | |
121 * is the filter string, and the second is the setting (allow/block). | |
122 */ | |
123 ContentSettings.setExceptions = function(type, list) { | |
124 var exceptionsList = | |
125 document.querySelector('div[contentType=' + type + ']' + | |
126 ' list[mode=normal]'); | |
127 exceptionsList.setExceptions(list); | |
128 }; | |
129 | |
130 ContentSettings.setHandlers = function(list) { | |
131 $('handlers-list').setHandlers(list); | |
132 }; | |
133 | |
134 ContentSettings.setIgnoredHandlers = function(list) { | |
135 $('ignored-handlers-list').setHandlers(list); | |
136 }; | |
137 | |
138 ContentSettings.setOTRExceptions = function(type, list) { | |
139 var exceptionsList = | |
140 document.querySelector('div[contentType=' + type + ']' + | |
141 ' list[mode=otr]'); | |
142 | |
143 exceptionsList.parentNode.hidden = false; | |
144 exceptionsList.setExceptions(list); | |
145 }; | |
146 | |
147 /** | |
148 * The browser's response to a request to check the validity of a given URL | |
149 * pattern. | |
150 * @param {string} type The content type. | |
151 * @param {string} mode The browser mode. | |
152 * @param {string} pattern The pattern. | |
153 * @param {bool} valid Whether said pattern is valid in the context of | |
154 * a content exception setting. | |
155 */ | |
156 ContentSettings.patternValidityCheckComplete = | |
157 function(type, mode, pattern, valid) { | |
158 var exceptionsList = | |
159 document.querySelector('div[contentType=' + type + '] ' + | |
160 'list[mode=' + mode + ']'); | |
161 exceptionsList.patternValidityCheckComplete(pattern, valid); | |
162 }; | |
163 | |
164 /** | |
165 * Enables the Pepper Flash camera and microphone settings. | |
166 * Please note that whether the settings are actually showed or not is also | |
167 * affected by the style class pepper-flash-settings. | |
168 */ | |
169 ContentSettings.enablePepperFlashCameraMicSettings = function() { | |
170 $('pepper-flash-cameramic-section').style.display = ''; | |
171 $('pepper-flash-cameramic-exceptions-div').style.display = ''; | |
172 } | |
173 | |
174 // Export | |
175 return { | |
176 ContentSettings: ContentSettings | |
177 }; | |
178 | |
179 }); | |
OLD | NEW |