OLD | NEW |
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.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var OptionsPage = options.OptionsPage; |
7 | 7 |
8 ////////////////////////////////////////////////////////////////////////////// | 8 ////////////////////////////////////////////////////////////////////////////// |
9 // ContentSettings class: | 9 // ContentSettings class: |
10 | 10 |
11 /** | 11 /** |
12 * Encapsulated handling of content settings page. | 12 * Encapsulated handling of content settings page. |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 function ContentSettings() { | 15 function ContentSettings() { |
16 this.activeNavTab = null; | 16 this.activeNavTab = null; |
17 this.sessionRestoreEnabled = false; | |
18 this.sessionRestoreSelected = false; | |
19 OptionsPage.call(this, 'content', | 17 OptionsPage.call(this, 'content', |
20 loadTimeData.getString('contentSettingsPageTabTitle'), | 18 loadTimeData.getString('contentSettingsPageTabTitle'), |
21 'content-settings-page'); | 19 'content-settings-page'); |
22 | |
23 // Keep track of the real value of the "clear on exit" preference. (The UI | |
24 // might override it if the "continue where I left off" setting is | |
25 // selected.) | |
26 var self = this; | |
27 Preferences.getInstance().addEventListener( | |
28 'profile.clear_site_data_on_exit', | |
29 function(event) { | |
30 if (event.value && typeof event.value['value'] != 'undefined') { | |
31 self.clearCookiesOnExit = event.value['value'] == true; | |
32 } | |
33 }); | |
34 Preferences.getInstance().addEventListener( | |
35 'session.restore_on_startup', | |
36 this.onSessionRestoreSelectedChanged.bind(this)); | |
37 } | 20 } |
38 | 21 |
39 cr.addSingletonGetter(ContentSettings); | 22 cr.addSingletonGetter(ContentSettings); |
40 | 23 |
41 ContentSettings.prototype = { | 24 ContentSettings.prototype = { |
42 __proto__: OptionsPage.prototype, | 25 __proto__: OptionsPage.prototype, |
43 | 26 |
44 initializePage: function() { | 27 initializePage: function() { |
45 OptionsPage.prototype.initializePage.call(this); | 28 OptionsPage.prototype.initializePage.call(this); |
46 | 29 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // Cookies filter page --------------------------------------------------- | 70 // Cookies filter page --------------------------------------------------- |
88 $('show-cookies-button').onclick = function(event) { | 71 $('show-cookies-button').onclick = function(event) { |
89 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']); | 72 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']); |
90 OptionsPage.navigateToPage('cookies'); | 73 OptionsPage.navigateToPage('cookies'); |
91 }; | 74 }; |
92 | 75 |
93 var intentsSection = $('intents-section'); | 76 var intentsSection = $('intents-section'); |
94 if (!loadTimeData.getBoolean('enable_web_intents') && intentsSection) | 77 if (!loadTimeData.getBoolean('enable_web_intents') && intentsSection) |
95 intentsSection.parentNode.removeChild(intentsSection); | 78 intentsSection.parentNode.removeChild(intentsSection); |
96 | 79 |
97 if (loadTimeData.getBoolean('enable_restore_session_state')) { | |
98 this.sessionRestoreEnabled = true; | |
99 this.updateSessionRestoreContentSettings(); | |
100 } | |
101 | |
102 $('content-settings-overlay-confirm').onclick = | 80 $('content-settings-overlay-confirm').onclick = |
103 OptionsPage.closeOverlay.bind(OptionsPage); | 81 OptionsPage.closeOverlay.bind(OptionsPage); |
104 | 82 |
105 $('pepper-flash-cameramic-section').style.display = 'none'; | 83 $('pepper-flash-cameramic-section').style.display = 'none'; |
106 $('pepper-flash-cameramic-exceptions-div').style.display = 'none'; | 84 $('pepper-flash-cameramic-exceptions-div').style.display = 'none'; |
107 }, | 85 }, |
108 | |
109 /** | |
110 * Called when the value of the "On startup" setting changes. | |
111 * @param {Event} event Change event. | |
112 * @private | |
113 */ | |
114 onSessionRestoreSelectedChanged: function(event) { | |
115 if (!event.value || typeof event.value['value'] == 'undefined') | |
116 return; | |
117 | |
118 this.sessionRestoreSelected = event.value['value'] == 1; | |
119 | |
120 if (this.sessionRestoreSelected) | |
121 this.updateSessionRestoreContentSettings(); | |
122 else | |
123 this.restoreContentSettings(); | |
124 }, | |
125 | |
126 // If the "continue where I left off" setting is selected, disable the | |
127 // "clear on exit" checkbox, and the "session only" setting for cookies. | |
128 updateSessionRestoreContentSettings: function() { | |
129 // This feature is behind a command line flag. | |
130 if (this.sessionRestoreEnabled && this.sessionRestoreSelected) { | |
131 $('clear-cookies-on-exit').checked = false; | |
132 $('clear-cookies-on-exit').setDisabled('sessionrestore', true); | |
133 | |
134 if ($('cookies-session').checked) { | |
135 $('cookies-allow').checked = true; | |
136 } | |
137 $('cookies-session').disabled = true; | |
138 } | |
139 }, | |
140 | |
141 // Restore the values of the UI elements based on the real values of the | |
142 // preferences. | |
143 restoreContentSettings: function() { | |
144 $('clear-cookies-on-exit').checked = this.clearCookiesOnExit; | |
145 $('clear-cookies-on-exit').setDisabled('sessionrestore', false); | |
146 | |
147 if (this.cookiesSession && $('cookies-allow').checked) { | |
148 $('cookies-session').checked = true; | |
149 } | |
150 $('cookies-session').disabled = false; | |
151 }, | |
152 | |
153 }; | 86 }; |
154 | 87 |
155 ContentSettings.updateHandlersEnabledRadios = function(enabled) { | 88 ContentSettings.updateHandlersEnabledRadios = function(enabled) { |
156 var selector = '#content-settings-page input[type=radio][value=' + | 89 var selector = '#content-settings-page input[type=radio][value=' + |
157 (enabled ? 'allow' : 'block') + '].handler-radio'; | 90 (enabled ? 'allow' : 'block') + '].handler-radio'; |
158 document.querySelector(selector).checked = true; | 91 document.querySelector(selector).checked = true; |
159 }; | 92 }; |
160 | 93 |
161 /** | 94 /** |
162 * Sets the values for all the content settings radios. | 95 * Sets the values for all the content settings radios. |
163 * @param {Object} dict A mapping from radio groups to the checked value for | 96 * @param {Object} dict A mapping from radio groups to the checked value for |
164 * that group. | 97 * that group. |
165 */ | 98 */ |
166 ContentSettings.setContentFilterSettingsValue = function(dict) { | 99 ContentSettings.setContentFilterSettingsValue = function(dict) { |
167 for (var group in dict) { | 100 for (var group in dict) { |
168 document.querySelector('input[type=radio][name=' + group + '][value=' + | 101 document.querySelector('input[type=radio][name=' + group + '][value=' + |
169 dict[group]['value'] + ']').checked = true; | 102 dict[group]['value'] + ']').checked = true; |
170 var radios = document.querySelectorAll('input[type=radio][name=' + | 103 var radios = document.querySelectorAll('input[type=radio][name=' + |
171 group + ']'); | 104 group + ']'); |
172 var managedBy = dict[group]['managedBy']; | 105 var managedBy = dict[group]['managedBy']; |
173 for (var i = 0, len = radios.length; i < len; i++) { | 106 for (var i = 0, len = radios.length; i < len; i++) { |
174 radios[i].disabled = (managedBy != 'default'); | 107 radios[i].disabled = (managedBy != 'default'); |
175 radios[i].controlledBy = managedBy; | 108 radios[i].controlledBy = managedBy; |
176 } | 109 } |
177 } | 110 } |
178 // Keep track of the real cookie content setting. (The UI might override it | |
179 // if the reopen last pages setting is selected.) | |
180 if ('cookies' in dict && 'value' in dict['cookies']) { | |
181 ContentSettings.getInstance().cookiesSession = | |
182 dict['cookies']['value'] == 'session'; | |
183 } | |
184 ContentSettings.getInstance().updateSessionRestoreContentSettings(); | |
185 OptionsPage.updateManagedBannerVisibility(); | 111 OptionsPage.updateManagedBannerVisibility(); |
186 }; | 112 }; |
187 | 113 |
188 /** | 114 /** |
189 * Initializes an exceptions list. | 115 * Initializes an exceptions list. |
190 * @param {string} type The content type that we are setting exceptions for. | 116 * @param {string} type The content type that we are setting exceptions for. |
191 * @param {Array} list An array of pairs, where the first element of each pair | 117 * @param {Array} list An array of pairs, where the first element of each pair |
192 * is the filter string, and the second is the setting (allow/block). | 118 * is the filter string, and the second is the setting (allow/block). |
193 */ | 119 */ |
194 ContentSettings.setExceptions = function(type, list) { | 120 ContentSettings.setExceptions = function(type, list) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 $('pepper-flash-cameramic-section').style.display = ''; | 167 $('pepper-flash-cameramic-section').style.display = ''; |
242 $('pepper-flash-cameramic-exceptions-div').style.display = ''; | 168 $('pepper-flash-cameramic-exceptions-div').style.display = ''; |
243 } | 169 } |
244 | 170 |
245 // Export | 171 // Export |
246 return { | 172 return { |
247 ContentSettings: ContentSettings | 173 ContentSettings: ContentSettings |
248 }; | 174 }; |
249 | 175 |
250 }); | 176 }); |
OLD | NEW |