OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 /** |
| 6 * @fileoverview |
| 7 * 'category-default-setting' is the polymer element for showing a certain |
| 8 * category under Site Settings. |
| 9 */ |
| 10 Polymer({ |
| 11 is: 'category-default-setting', |
| 12 |
| 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |
| 14 |
| 15 properties: { |
| 16 /** |
| 17 * Represents the state of the main toggle shown for the category. For |
| 18 * example, the Location category can be set to Block/Ask so false, in that |
| 19 * case, represents Block and true represents Ask. |
| 20 */ |
| 21 categoryEnabled: Boolean, |
| 22 |
| 23 /** |
| 24 * The description to be shown next to the slider. |
| 25 * @private |
| 26 */ |
| 27 sliderDescription_: String, |
| 28 |
| 29 /** |
| 30 * A sub-option toggle is used to represent tri-state categories. |
| 31 * @private |
| 32 */ |
| 33 subOptionEnabled_: { |
| 34 type: Boolean, |
| 35 value: true, |
| 36 }, |
| 37 }, |
| 38 |
| 39 observers: [ |
| 40 'onCategoryChanged_(category)', |
| 41 ], |
| 42 |
| 43 ready: function() { |
| 44 this.addWebUIListener('contentSettingCategoryChanged', |
| 45 this.defaultValueForCategoryChanged_.bind(this)); |
| 46 }, |
| 47 |
| 48 /** |
| 49 * Called when the default value for a category has been changed. |
| 50 * @param {number} category The category that changed. |
| 51 * @private |
| 52 */ |
| 53 defaultValueForCategoryChanged_: function(category) { |
| 54 if (category == this.category) |
| 55 this.onCategoryChanged_(); |
| 56 }, |
| 57 |
| 58 /** |
| 59 * A handler for changing the default permission value for a content type. |
| 60 * @private |
| 61 */ |
| 62 onChangePermissionControl_: function() { |
| 63 switch (this.category) { |
| 64 case settings.ContentSettingsTypes.BACKGROUND_SYNC: |
| 65 case settings.ContentSettingsTypes.IMAGES: |
| 66 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 67 case settings.ContentSettingsTypes.KEYGEN: |
| 68 case settings.ContentSettingsTypes.POPUPS: |
| 69 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS: |
| 70 // "Allowed" vs "Blocked". |
| 71 this.browserProxy.setDefaultValueForContentType( |
| 72 this.category, |
| 73 this.categoryEnabled ? |
| 74 settings.PermissionValues.ALLOW : |
| 75 settings.PermissionValues.BLOCK); |
| 76 break; |
| 77 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: |
| 78 case settings.ContentSettingsTypes.CAMERA: |
| 79 case settings.ContentSettingsTypes.GEOLOCATION: |
| 80 case settings.ContentSettingsTypes.MIC: |
| 81 case settings.ContentSettingsTypes.NOTIFICATIONS: |
| 82 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: |
| 83 // "Ask" vs "Blocked". |
| 84 this.browserProxy.setDefaultValueForContentType( |
| 85 this.category, |
| 86 this.categoryEnabled ? |
| 87 settings.PermissionValues.ASK : |
| 88 settings.PermissionValues.BLOCK); |
| 89 break; |
| 90 case settings.ContentSettingsTypes.COOKIES: |
| 91 // This category is tri-state: "Allow", "Block", "Keep data until |
| 92 // browser quits". |
| 93 var value = settings.PermissionValues.BLOCK; |
| 94 if (this.categoryEnabled) { |
| 95 value = this.subOptionEnabled_ ? |
| 96 settings.PermissionValues.SESSION_ONLY : |
| 97 settings.PermissionValues.ALLOW; |
| 98 } |
| 99 this.browserProxy.setDefaultValueForContentType(this.category, value); |
| 100 break; |
| 101 case settings.ContentSettingsTypes.PLUGINS: |
| 102 // This category is tri-state: "Allow", "Block", "Ask before running". |
| 103 var value = settings.PermissionValues.BLOCK; |
| 104 if (this.categoryEnabled) { |
| 105 value = this.subOptionEnabled_ ? |
| 106 settings.PermissionValues.IMPORTANT_CONTENT : |
| 107 settings.PermissionValues.ALLOW; |
| 108 } |
| 109 this.browserProxy.setDefaultValueForContentType(this.category, value); |
| 110 break; |
| 111 default: |
| 112 assertNotReached('Invalid category: ' + this.category); |
| 113 } |
| 114 }, |
| 115 |
| 116 /** |
| 117 * Handles changes to the category pref and the |category| member variable. |
| 118 * @private |
| 119 */ |
| 120 onCategoryChanged_: function() { |
| 121 this.browserProxy |
| 122 .getDefaultValueForContentType(this.category) |
| 123 .then(function(defaultValue) { |
| 124 var setting = defaultValue.setting; |
| 125 this.categoryEnabled = this.computeIsSettingEnabled(setting); |
| 126 |
| 127 // Flash only shows ALLOW or BLOCK descriptions on the slider. |
| 128 var sliderSetting = setting; |
| 129 if (this.category == settings.ContentSettingsTypes.PLUGINS && |
| 130 setting == settings.PermissionValues.IMPORTANT_CONTENT) { |
| 131 sliderSetting = settings.PermissionValues.ALLOW; |
| 132 } else if ( |
| 133 this.category == settings.ContentSettingsTypes.COOKIES && |
| 134 setting == settings.PermissionValues.SESSION_ONLY) { |
| 135 sliderSetting = settings.PermissionValues.ALLOW; |
| 136 } |
| 137 this.sliderDescription_ = |
| 138 this.computeCategoryDesc(this.category, sliderSetting, true); |
| 139 |
| 140 if (this.category == settings.ContentSettingsTypes.PLUGINS) { |
| 141 // The checkbox should only be cleared when the Flash setting |
| 142 // is explicitly set to ALLOW. |
| 143 if (setting == settings.PermissionValues.ALLOW) |
| 144 this.subOptionEnabled_ = false; |
| 145 if (setting == settings.PermissionValues.IMPORTANT_CONTENT) |
| 146 this.subOptionEnabled_ = true; |
| 147 } else if ( |
| 148 this.category == settings.ContentSettingsTypes.COOKIES) { |
| 149 if (setting == settings.PermissionValues.ALLOW) |
| 150 this.subOptionEnabled_ = false; |
| 151 else if (setting == settings.PermissionValues.SESSION_ONLY) |
| 152 this.subOptionEnabled_ = true; |
| 153 } |
| 154 }.bind(this)); |
| 155 }, |
| 156 }); |
OLD | NEW |