| 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 * 'add-site-dialog' provides a dialog to add exceptions for a given Content |
| 8 * Settings category. |
| 9 */ |
| 10 Polymer({ |
| 11 is: 'add-site-dialog', |
| 12 |
| 13 behaviors: [SiteSettingsBehavior], |
| 14 |
| 15 properties: { |
| 16 /** |
| 17 * The site to add an exception for. |
| 18 * @private |
| 19 */ |
| 20 site_: String, |
| 21 }, |
| 22 |
| 23 /** Opens the dialog. */ |
| 24 open: function() { |
| 25 this.$.dialog.open(); |
| 26 }, |
| 27 |
| 28 /** |
| 29 * Validates that the pattern entered is valid. |
| 30 * @private |
| 31 */ |
| 32 validate_: function() { |
| 33 var pattern = this.addPatternWildcard_(this.site_); |
| 34 this.browserProxy.isPatternValid(pattern).then(function(isValid) { |
| 35 this.$.add.disabled = !isValid; |
| 36 }.bind(this)); |
| 37 }, |
| 38 |
| 39 /** |
| 40 * Adds the wildcard prefix to a pattern string. |
| 41 * @param {string} pattern The pattern to add the wildcard to. |
| 42 * @return {string} The resulting pattern. |
| 43 * @private |
| 44 */ |
| 45 addPatternWildcard_: function(pattern) { |
| 46 if (pattern.startsWith('http://')) |
| 47 return pattern.replace('http://', 'http://[*.]'); |
| 48 else if (pattern.startsWith('https://')) |
| 49 return pattern.replace('https://', 'https://[*.]'); |
| 50 else |
| 51 return '[*.]' + pattern; |
| 52 }, |
| 53 |
| 54 /** |
| 55 * The tap handler for the Add [Site] button (adds the pattern and closes |
| 56 * the dialog). |
| 57 * @private |
| 58 */ |
| 59 onAddTap_: function() { |
| 60 var pattern = this.addPatternWildcard_(this.site_); |
| 61 this.setCategoryPermissionForOrigin( |
| 62 pattern, pattern, this.category, settings.PermissionValues.ALLOW); |
| 63 this.$.dialog.close(); |
| 64 }, |
| 65 }); |
| OLD | NEW |