summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/custom_home_pages_model.mm
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-27 18:46:46 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-27 18:46:46 +0000
commit752e0e629c3018868f3edf7bc2cbbda66c7c6f45 (patch)
treec749572df704bf2a4bc6254674086944756e1727 /chrome/browser/cocoa/custom_home_pages_model.mm
parent28b04e187d1757e2ad098524326bcefdfeb97108 (diff)
downloadchromium_src-752e0e629c3018868f3edf7bc2cbbda66c7c6f45.zip
chromium_src-752e0e629c3018868f3edf7bc2cbbda66c7c6f45.tar.gz
chromium_src-752e0e629c3018868f3edf7bc2cbbda66c7c6f45.tar.bz2
Fix a couple of bugs in the "custom home pages" list in the Preferences window.
1. It was possible to add empty rows to the list by repeatedly clicking the + button. 2. There was a crash when editing an existing item, clearing the text and pressing enter. CustomHomePagesEntry::setURL didn't handle a nil NSString passed to it in this condition. I added a controlTextDidEndEditing method to PreferencesWindowController that forces a revalidation of the contents of the model backing the TableView. http://crbug.com/19555 TEST=Click the + button below the custom home pages table view in the Basics page of Preferences. You should get an active edit but not add the item if you don't type anything. Also, try adding a few valid URLs, then click one to edit and delete the URL, then press enter. It should be removed from the table. See also attached unit test. Review URL: http://codereview.chromium.org/174173 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/custom_home_pages_model.mm')
-rw-r--r--chrome/browser/cocoa/custom_home_pages_model.mm15
1 files changed, 14 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/custom_home_pages_model.mm b/chrome/browser/cocoa/custom_home_pages_model.mm
index 1204ac6..4232e4d 100644
--- a/chrome/browser/cocoa/custom_home_pages_model.mm
+++ b/chrome/browser/cocoa/custom_home_pages_model.mm
@@ -57,7 +57,6 @@ NSString* const kHomepageEntryChangedNotification =
// Get/set the urls the model currently contains as a group. These will weed
// out any URLs that are empty and not add them to the model. As a result,
// the next time they're persisted to the prefs backend, they'll disappear.
-
- (std::vector<GURL>)URLs {
std::vector<GURL> urls;
for (CustomHomePageEntry* entry in entries_.get()) {
@@ -85,6 +84,16 @@ NSString* const kHomepageEntryChangedNotification =
[self didChangeValueForKey:@"customHomePages"];
}
+- (void)validateURLs {
+ [self setURLs:[self URLs]];
+}
+
+- (void)setURLStringEmptyAt:(NSUInteger)index {
+ // This replaces the data at |index| with an empty (invalid) URL string.
+ CustomHomePageEntry* entry = [entries_ objectAtIndex:index];
+ [entry setURL:[NSString stringWithString:@""]];
+}
+
@end
//---------------------------------------------------------------------------
@@ -92,6 +101,10 @@ NSString* const kHomepageEntryChangedNotification =
@implementation CustomHomePageEntry
- (void)setURL:(NSString*)url {
+ // |url| can be nil if the user cleared the text from the edit field.
+ if (!url)
+ url = [NSString stringWithString:@""];
+
// Make sure the url is valid before setting it by fixing it up.
std::string urlToFix(base::SysNSStringToUTF8(url));
urlToFix = URLFixerUpper::FixupURL(urlToFix, "");