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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 Polymer({ 5 Polymer({
6 is: 'bookmarks-edit-dialog', 6 is: 'bookmarks-edit-dialog',
7 7
8 behaviors: [ 8 behaviors: [
9 Polymer.IronA11yKeysBehavior, 9 Polymer.IronA11yKeysBehavior,
10 ], 10 ],
(...skipping 15 matching lines...) Expand all
26 keyBindings: { 26 keyBindings: {
27 'enter': 'onSaveButtonTap_', 27 'enter': 'onSaveButtonTap_',
28 }, 28 },
29 29
30 /** @param {BookmarkNode} editItem */ 30 /** @param {BookmarkNode} editItem */
31 showEditDialog: function(editItem) { 31 showEditDialog: function(editItem) {
32 this.editItem_ = editItem; 32 this.editItem_ = editItem;
33 this.isFolder_ = !editItem.url; 33 this.isFolder_ = !editItem.url;
34 34
35 this.titleValue_ = editItem.title; 35 this.titleValue_ = editItem.title;
36 if (!this.isFolder_) 36 if (!this.isFolder_) {
37 this.$.url.invalid = false;
37 this.urlValue_ = assert(editItem.url); 38 this.urlValue_ = assert(editItem.url);
39 }
38 40
39 this.$.dialog.showModal(); 41 this.$.dialog.showModal();
40 }, 42 },
41 43
42 /** 44 /**
43 * @param {boolean} isFolder 45 * @param {boolean} isFolder
44 * @return {string} 46 * @return {string}
45 * @private 47 * @private
46 */ 48 */
47 getDialogTitle_: function(isFolder) { 49 getDialogTitle_: function(isFolder) {
48 return loadTimeData.getString( 50 return loadTimeData.getString(
49 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle'); 51 isFolder ? 'renameFolderTitle' : 'editBookmarkTitle');
50 }, 52 },
51 53
54 /**
55 * Validates the value of the URL field, returning true if it is a valid URL.
56 * May modify the value by prepending 'http://' in order to make it valid.
57 * @return {boolean}
58 * @private
59 */
60 validateUrl_: function() {
61 var urlInput = /** @type {PaperInputElement} */ (this.$.url);
62 var originalValue = this.urlValue_;
63
64 if (urlInput.validate())
65 return true;
66
67 this.urlValue_ = 'http://' + originalValue;
68
69 if (urlInput.validate())
70 return true;
71
72 this.urlValue_ = originalValue;
73 return false;
74 },
75
52 /** @private */ 76 /** @private */
53 onSaveButtonTap_: function() { 77 onSaveButtonTap_: function() {
54 // TODO(tsergeant): Verify values.
55 var edit = {'title': this.titleValue_}; 78 var edit = {'title': this.titleValue_};
56 if (!this.isFolder_) 79 if (!this.isFolder_) {
80 if (!this.validateUrl_())
81 return;
82
57 edit['url'] = this.urlValue_; 83 edit['url'] = this.urlValue_;
84 }
58 85
59 chrome.bookmarks.update(this.editItem_.id, edit); 86 chrome.bookmarks.update(this.editItem_.id, edit);
60 this.$.dialog.close(); 87 this.$.dialog.close();
61 }, 88 },
62 89
63 /** @private */ 90 /** @private */
64 onCancelButtonTap_: function() { 91 onCancelButtonTap_: function() {
65 this.$.dialog.cancel(); 92 this.$.dialog.cancel();
66 }, 93 },
67 }); 94 });
OLDNEW
« 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