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

Unified Diff: chrome/browser/resources/md_bookmarks/edit_dialog.js

Issue 2769863002: MD Bookmarks: Validate URL input when editing a bookmark (Closed)
Patch Set: Rebase Created 3 years, 9 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/md_bookmarks/edit_dialog.js
diff --git a/chrome/browser/resources/md_bookmarks/edit_dialog.js b/chrome/browser/resources/md_bookmarks/edit_dialog.js
index 6f7bccdd4546838822246e5a0aa1f0bdf69adf80..6c3d635af1ee0bbb2139454b722a24d07b2eaf9e 100644
--- a/chrome/browser/resources/md_bookmarks/edit_dialog.js
+++ b/chrome/browser/resources/md_bookmarks/edit_dialog.js
@@ -33,8 +33,10 @@ Polymer({
this.isFolder_ = !editItem.url;
this.titleValue_ = editItem.title;
- if (!this.isFolder_)
+ if (!this.isFolder_) {
+ this.$.url.invalid = false;
this.urlValue_ = assert(editItem.url);
+ }
this.$.dialog.showModal();
},
@@ -49,12 +51,37 @@ Polymer({
isFolder ? 'renameFolderTitle' : 'editBookmarkTitle');
},
+ /**
+ * Validates the value of the URL field, returning true if it is a valid URL.
+ * May modify the value by prepending 'http://' in order to make it valid.
+ * @return {boolean}
+ * @private
+ */
+ validateUrl_: function() {
+ var urlInput = /** @type {PaperInputElement} */ (this.$.url);
+ var originalValue = this.urlValue_;
+
+ if (urlInput.validate())
+ return true;
+
+ this.urlValue_ = 'http://' + originalValue;
+
+ if (urlInput.validate())
+ return true;
+
+ this.urlValue_ = originalValue;
+ return false;
+ },
+
/** @private */
onSaveButtonTap_: function() {
- // TODO(tsergeant): Verify values.
var edit = {'title': this.titleValue_};
- if (!this.isFolder_)
+ if (!this.isFolder_) {
+ if (!this.validateUrl_())
+ return;
+
edit['url'] = this.urlValue_;
+ }
chrome.bookmarks.update(this.editItem_.id, edit);
this.$.dialog.close();
« no previous file with comments | « chrome/browser/resources/md_bookmarks/edit_dialog.html ('k') | chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698