| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 | |
| 7 var OptionsPage = options.OptionsPage; | |
| 8 | |
| 9 ////////////////////////////////////////////////////////////////////////////// | |
| 10 // ContentSettings class: | |
| 11 | |
| 12 /** | |
| 13 * Encapsulated handling of content settings page. | |
| 14 * @constructor | |
| 15 */ | |
| 16 function ContentSettings() { | |
| 17 this.activeNavTab = null; | |
| 18 OptionsPage.call(this, 'content', templateData.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 page.showList( | |
| 38 event.target.getAttribute('contentType')); | |
| 39 OptionsPage.navigateToPage('contentExceptions'); | |
| 40 // Add on the proper hash for the content type, and store that in the | |
| 41 // history so back/forward and tab restore works. | |
| 42 var hash = event.target.getAttribute('contentType'); | |
| 43 window.history.replaceState({pageName: page.name}, page.title, | |
| 44 '/' + page.name + "#" + hash); | |
| 45 }; | |
| 46 } | |
| 47 | |
| 48 var manageHandlersButton = $('manage-handlers-button'); | |
| 49 if (manageHandlersButton) { | |
| 50 manageHandlersButton.onclick = function(event) { | |
| 51 OptionsPage.navigateToPage('handlers'); | |
| 52 }; | |
| 53 } | |
| 54 | |
| 55 var manageIntentsButton = $('manage-intents-button'); | |
| 56 if (manageIntentsButton) { | |
| 57 manageIntentsButton.onclick = function(event) { | |
| 58 OptionsPage.navigateToPage('intents'); | |
| 59 }; | |
| 60 } | |
| 61 | |
| 62 // Cookies filter page --------------------------------------------------- | |
| 63 $('show-cookies-button').onclick = function(event) { | |
| 64 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowCookies']); | |
| 65 OptionsPage.navigateToPage('cookies'); | |
| 66 }; | |
| 67 | |
| 68 if (!templateData.enable_click_to_play) | |
| 69 $('click_to_play').hidden = true; | |
| 70 | |
| 71 if (!templateData.enable_web_intents && $('intent-section')) | |
| 72 $('intent-section').hidden = true; | |
| 73 }, | |
| 74 }; | |
| 75 | |
| 76 ContentSettings.updateHandlersEnabledRadios = function(enabled) { | |
| 77 var selector = '#content-settings-page input[type=radio][value=' + | |
| 78 (enabled ? 'allow' : 'block') + '].handler-radio'; | |
| 79 document.querySelector(selector).checked = true; | |
| 80 }; | |
| 81 | |
| 82 /** | |
| 83 * Sets the values for all the content settings radios. | |
| 84 * @param {Object} dict A mapping from radio groups to the checked value for | |
| 85 * that group. | |
| 86 */ | |
| 87 ContentSettings.setContentFilterSettingsValue = function(dict) { | |
| 88 for (var group in dict) { | |
| 89 document.querySelector('input[type=radio][name=' + group + '][value=' + | |
| 90 dict[group]['value'] + ']').checked = true; | |
| 91 var radios = document.querySelectorAll('input[type=radio][name=' + | |
| 92 group + ']'); | |
| 93 var managedBy = dict[group]['managedBy']; | |
| 94 for (var i = 0, len = radios.length; i < len; i++) { | |
| 95 radios[i].disabled = (managedBy != 'default'); | |
| 96 radios[i].controlledBy = managedBy; | |
| 97 } | |
| 98 } | |
| 99 OptionsPage.updateManagedBannerVisibility(); | |
| 100 }; | |
| 101 | |
| 102 /** | |
| 103 * Initializes an exceptions list. | |
| 104 * @param {string} type The content type that we are setting exceptions for. | |
| 105 * @param {Array} list An array of pairs, where the first element of each pair | |
| 106 * is the filter string, and the second is the setting (allow/block). | |
| 107 */ | |
| 108 ContentSettings.setExceptions = function(type, list) { | |
| 109 var exceptionsList = | |
| 110 document.querySelector('div[contentType=' + type + ']' + | |
| 111 ' list[mode=normal]'); | |
| 112 exceptionsList.setExceptions(list); | |
| 113 }; | |
| 114 | |
| 115 ContentSettings.setHandlers = function(list) { | |
| 116 $('handlers-list').setHandlers(list); | |
| 117 }; | |
| 118 | |
| 119 ContentSettings.setIgnoredHandlers = function(list) { | |
| 120 $('ignored-handlers-list').setHandlers(list); | |
| 121 }; | |
| 122 | |
| 123 ContentSettings.setOTRExceptions = function(type, list) { | |
| 124 var exceptionsList = | |
| 125 document.querySelector('div[contentType=' + type + ']' + | |
| 126 ' list[mode=otr]'); | |
| 127 | |
| 128 exceptionsList.parentNode.hidden = false; | |
| 129 exceptionsList.setExceptions(list); | |
| 130 }; | |
| 131 | |
| 132 /** | |
| 133 * The browser's response to a request to check the validity of a given URL | |
| 134 * pattern. | |
| 135 * @param {string} type The content type. | |
| 136 * @param {string} mode The browser mode. | |
| 137 * @param {string} pattern The pattern. | |
| 138 * @param {bool} valid Whether said pattern is valid in the context of | |
| 139 * a content exception setting. | |
| 140 */ | |
| 141 ContentSettings.patternValidityCheckComplete = | |
| 142 function(type, mode, pattern, valid) { | |
| 143 var exceptionsList = | |
| 144 document.querySelector('div[contentType=' + type + '] ' + | |
| 145 'list[mode=' + mode + ']'); | |
| 146 exceptionsList.patternValidityCheckComplete(pattern, valid); | |
| 147 }; | |
| 148 | |
| 149 // Export | |
| 150 return { | |
| 151 ContentSettings: ContentSettings | |
| 152 }; | |
| 153 | |
| 154 }); | |
| OLD | NEW |