| 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], | 13 behaviors: [SiteSettingsBehavior], |
| 14 | 14 |
| 15 properties: { | 15 properties: { |
| 16 /** | 16 /** |
| 17 * The site to add an exception for. | 17 * The site to add an exception for. |
| 18 * @private | 18 * @private |
| 19 */ | 19 */ |
| 20 site_: String, | 20 site_: String, |
| 21 |
| 22 /** |
| 23 * Whether this is an allow exception this dialog is adding. |
| 24 */ |
| 25 allowException: Boolean, |
| 21 }, | 26 }, |
| 22 | 27 |
| 23 /** Opens the dialog. */ | 28 /** |
| 24 open: function() { | 29 * Opens the dialog. |
| 30 * @param {string} type Whether this was launched from an Allow list or a |
| 31 * Block list. |
| 32 */ |
| 33 open: function(type) { |
| 34 this.allowException = type == settings.PermissionValues.ALLOW; |
| 25 this.$.dialog.open(); | 35 this.$.dialog.open(); |
| 26 }, | 36 }, |
| 27 | 37 |
| 28 /** | 38 /** |
| 29 * Validates that the pattern entered is valid. | 39 * Validates that the pattern entered is valid. |
| 30 * @private | 40 * @private |
| 31 */ | 41 */ |
| 32 validate_: function() { | 42 validate_: function() { |
| 33 var pattern = this.addPatternWildcard_(this.site_); | 43 var pattern = this.addPatternWildcard_(this.site_); |
| 34 this.browserProxy.isPatternValid(pattern).then(function(isValid) { | 44 this.browserProxy.isPatternValid(pattern).then(function(isValid) { |
| 35 this.$.add.disabled = !isValid; | 45 this.$.add.disabled = !isValid; |
| 36 }.bind(this)); | 46 }.bind(this)); |
| 37 }, | 47 }, |
| 38 | 48 |
| 39 /** | 49 /** |
| 40 * The tap handler for the Add [Site] button (adds the pattern and closes | 50 * The tap handler for the Add [Site] button (adds the pattern and closes |
| 41 * the dialog). | 51 * the dialog). |
| 42 * @private | 52 * @private |
| 43 */ | 53 */ |
| 44 onAddTap_: function() { | 54 onSubmit_: function() { |
| 55 if (this.$.add.disabled) |
| 56 return; // Can happen when Enter is pressed. |
| 45 var pattern = this.addPatternWildcard_(this.site_); | 57 var pattern = this.addPatternWildcard_(this.site_); |
| 46 this.setCategoryPermissionForOrigin( | 58 this.setCategoryPermissionForOrigin( |
| 47 pattern, '', this.category, settings.PermissionValues.ALLOW); | 59 pattern, '', this.category, this.allowException ? |
| 60 settings.PermissionValues.ALLOW : settings.PermissionValues.BLOCK); |
| 48 this.$.dialog.close(); | 61 this.$.dialog.close(); |
| 49 }, | 62 }, |
| 50 }); | 63 }); |
| OLD | NEW |