| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'add-site-dialog' provides a dialog to add exceptions for a given Content | 7 * 'add-site-dialog' provides a dialog to add exceptions for a given Content |
| 8 * Settings category. | 8 * Settings category. |
| 9 */ | 9 */ |
| 10 Polymer({ | 10 Polymer({ |
| 11 is: 'add-site-dialog', | 11 is: 'add-site-dialog', |
| 12 | 12 |
| 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |
| 14 | 14 |
| 15 properties: { | 15 properties: { |
| 16 /** | 16 /** |
| 17 * What kind of setting, e.g. Location, Camera, Cookies, and so on. | 17 * What kind of setting, e.g. Location, Camera, Cookies, and so on. |
| 18 * @type {settings.ContentSettingsTypes} | 18 * @type {settings.ContentSettingsTypes} |
| 19 */ | 19 */ |
| 20 category: String, | 20 category: String, |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Whether this is about an Allow, Block, SessionOnly, or other. | 23 * Whether this is about an Allow, Block, SessionOnly, or other. |
| 24 * @type {settings.PermissionValues} | 24 * @type {settings.PermissionValues} |
| 25 */ | 25 */ |
| 26 contentSetting: String, | 26 contentSetting: String, |
| 27 | 27 |
| 28 /** @private */ |
| 29 isIncognitoActive_: Boolean, |
| 30 |
| 28 /** | 31 /** |
| 29 * The site to add an exception for. | 32 * The site to add an exception for. |
| 30 * @private | 33 * @private |
| 31 */ | 34 */ |
| 32 site_: String, | 35 site_: String, |
| 33 }, | 36 }, |
| 34 | 37 |
| 35 /** @override */ | 38 /** @override */ |
| 36 attached: function() { | 39 attached: function() { |
| 37 assert(this.category); | 40 assert(this.category); |
| 38 assert(this.contentSetting); | 41 assert(this.contentSetting); |
| 39 }, | 42 }, |
| 40 | 43 |
| 41 /** | 44 /** |
| 42 * Opens the dialog. | 45 * Opens the dialog. |
| 43 * @param {string} type Whether this was launched from an Allow list or a | 46 * @param {string} type Whether this was launched from an Allow list or a |
| 44 * Block list. | 47 * Block list. |
| 45 */ | 48 */ |
| 46 open: function(type) { | 49 open: function(type) { |
| 47 this.addWebUIListener('onIncognitoStatusChanged', | 50 this.addWebUIListener('onIncognitoStatusChanged', function(isActive) { |
| 48 this.onIncognitoStatusChanged_.bind(this)); | 51 this.isIncognitoActive_ = isActive; |
| 52 }.bind(this)); |
| 49 this.browserProxy.updateIncognitoStatus(); | 53 this.browserProxy.updateIncognitoStatus(); |
| 50 this.$.dialog.showModal(); | 54 this.$.dialog.showModal(); |
| 51 }, | 55 }, |
| 52 | 56 |
| 53 /** | 57 /** |
| 54 * Validates that the pattern entered is valid. | 58 * Validates that the pattern entered is valid. |
| 55 * @private | 59 * @private |
| 56 */ | 60 */ |
| 57 validate_: function() { | 61 validate_: function() { |
| 58 // If input is empty, disable the action button, but don't show the red | 62 // If input is empty, disable the action button, but don't show the red |
| 59 // invalid message. | 63 // invalid message. |
| 60 if (this.$.site.value.trim() == '') { | 64 if (this.$.site.value.trim() == '') { |
| 61 this.$.site.invalid = false; | 65 this.$.site.invalid = false; |
| 62 this.$.add.disabled = true; | 66 this.$.add.disabled = true; |
| 63 return; | 67 return; |
| 64 } | 68 } |
| 65 | 69 |
| 66 this.browserProxy.isPatternValid(this.site_).then(function(isValid) { | 70 this.browserProxy.isPatternValid(this.site_).then(function(isValid) { |
| 67 this.$.site.invalid = !isValid; | 71 this.$.site.invalid = !isValid; |
| 68 this.$.add.disabled = !isValid; | 72 this.$.add.disabled = !isValid; |
| 69 }.bind(this)); | 73 }.bind(this)); |
| 70 }, | 74 }, |
| 71 | 75 |
| 72 /** @private */ | 76 /** @private */ |
| 73 onCancelTap_: function() { | 77 onCancelTap_: function() { |
| 74 this.$.dialog.cancel(); | 78 this.$.dialog.cancel(); |
| 75 }, | 79 }, |
| 76 | 80 |
| 77 /** | 81 /** |
| 78 * A handler for when we get notified of the current profile creating or | |
| 79 * destroying their incognito counterpart. | |
| 80 * @param {boolean} incognitoEnabled Whether the current profile has an | |
| 81 * incognito profile. | |
| 82 * @private | |
| 83 */ | |
| 84 onIncognitoStatusChanged_: function(incognitoEnabled) { | |
| 85 this.$.incognito.disabled = !incognitoEnabled; | |
| 86 if (!incognitoEnabled) | |
| 87 this.$.incognito.checked = false; | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * The tap handler for the Add [Site] button (adds the pattern and closes | 82 * The tap handler for the Add [Site] button (adds the pattern and closes |
| 92 * the dialog). | 83 * the dialog). |
| 93 * @private | 84 * @private |
| 94 */ | 85 */ |
| 95 onSubmit_: function() { | 86 onSubmit_: function() { |
| 96 if (this.$.add.disabled) | 87 if (this.$.add.disabled) |
| 97 return; // Can happen when Enter is pressed. | 88 return; // Can happen when Enter is pressed. |
| 98 this.browserProxy.setCategoryPermissionForOrigin( | 89 this.browserProxy.setCategoryPermissionForOrigin( |
| 99 this.site_, this.site_, this.category, this.contentSetting, | 90 this.site_, this.site_, this.category, this.contentSetting, |
| 100 this.$.incognito.checked); | 91 this.$.incognito.checked); |
| 101 this.$.dialog.close(); | 92 this.$.dialog.close(); |
| 102 }, | 93 }, |
| 103 }); | 94 }); |
| OLD | NEW |