Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: chrome/browser/resources/settings/site_settings/add_site_dialog.js

Issue 1909413002: Site Settings: Implement dialog for adding site exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8abb0a7b658e4e9f5549cd6369f3e45b11d2da6e
--- /dev/null
+++ b/chrome/browser/resources/settings/site_settings/add_site_dialog.js
@@ -0,0 +1,65 @@
+// 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.
+ */
+Polymer({
+ is: 'add-site-dialog',
+
+ behaviors: [SiteSettingsBehavior],
+
+ properties: {
+ /**
+ * The site to add an exception for.
+ * @private
+ */
+ site_: String,
+ },
+
+ /** Opens the dialog. */
+ open: function() {
+ this.$.dialog.open();
+ },
+
+ /**
+ * Validates that the pattern entered is valid.
+ * @private
+ */
+ validate_: function() {
+ var pattern = this.addPatternWildcard_(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
+ */
+ addPatternWildcard_: function(pattern) {
+ 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.addPatternWildcard_(this.site_);
+ this.setCategoryPermissionForOrigin(
+ pattern, pattern, this.category, settings.PermissionValues.ALLOW);
+ this.$.dialog.close();
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698