Chromium Code Reviews| Index: chrome/browser/resources/settings/site_settings/add_site_dialog.js |
| diff --git a/chrome/browser/resources/settings/site_settings/add_site_dialog.js b/chrome/browser/resources/settings/site_settings/add_site_dialog.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2dc66633ee3027b9ec881cfdd78df116d37db754 |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/site_settings/add_site_dialog.js |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview |
| + * 'add-site-dialog' provides a dialog to add exceptions for a given Content |
| + * Settings category. |
| + * |
|
michaelpg
2016/04/24 19:58:40
nit: remove blank line
Finnur
2016/04/25 10:23:12
Done.
|
| + */ |
| +Polymer({ |
| + is: 'add-site-dialog', |
| + |
| + behaviors: [SiteSettingsBehavior], |
| + |
| + /** |
| + * Opens the dialog. |
|
michaelpg
2016/04/24 19:58:40
nit: /** Opens... */
Finnur
2016/04/25 10:23:13
Done.
|
| + */ |
| + open: function() { |
| + this.$.dialog.open(); |
| + }, |
| + |
| + /** |
| + * Validates that the pattern entered is valid. |
| + * @private |
| + */ |
| + validate_: function() { |
| + var pattern = this.ensurePatternWildcard_(this.site_); |
| + this.browserProxy.isPatternValid(pattern).then(function(isValid) { |
| + this.$.add.disabled = !isValid; |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| + * Adds the wildcard prefix to a pattern string. |
| + * @param {string} pattern The pattern to add the wildcard to. |
| + * @return {string} The resulting pattern. |
| + * @private |
| + */ |
| + ensurePatternWildcard_: function(pattern) { |
|
michaelpg
2016/04/24 19:58:40
nit... "ensure" is misleading, makes me think this
Finnur
2016/04/25 10:23:13
Done.
|
| + if (pattern.startsWith('http://')) |
| + return pattern.replace('http://', 'http://[*.]'); |
| + else if (pattern.startsWith('https://')) |
| + return pattern.replace('https://', 'https://[*.]'); |
| + else |
| + return '[*.]' + pattern; |
| + }, |
| + |
| + /** |
| + * The tap handler for the Add [Site] button (adds the pattern and closes |
| + * the dialog). |
| + * @private |
| + */ |
| + onAddTap_: function() { |
| + var pattern = this.ensurePatternWildcard_(this.site_); |
|
michaelpg
2016/04/24 19:58:40
add "site_: String" to |properties|, please
Finnur
2016/04/25 10:23:12
Done.
|
| + this.setCategoryPermissionForOrigin( |
| + pattern, pattern, this.category, settings.PermissionValues.ALLOW); |
| + |
| + // Make sure the text box is empty when you open it next time. |
|
michaelpg
2016/04/24 19:58:40
not needed if you create/remove the dialog on dema
Finnur
2016/04/25 10:23:13
Done.
|
| + this.site_ = ''; |
| + this.$.dialog.close(); |
| + }, |
| +}); |