summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 18:24:43 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 18:24:43 +0000
commit796646b312c38fe581d1822cb60c5d06e84cd30e (patch)
treed43c82346b266b223dcc1eecc44d1bf7e960afb7
parent1408743dd10f24984d0c9409edb21b02cea101cb (diff)
downloadchromium_src-796646b312c38fe581d1822cb60c5d06e84cd30e.zip
chromium_src-796646b312c38fe581d1822cb60c5d06e84cd30e.tar.gz
chromium_src-796646b312c38fe581d1822cb60c5d06e84cd30e.tar.bz2
[Mac] Fix keyword editor-related crashes
* Adjust the edit buttons after adding a new keyword. * Don't make NSPointerArray calls which cause exceptions. Patch from rsesek@chromium.org http://codereview.chromium.org/262028 BUG=23350, 22545 TEST=Preferences-->Manage. Add a search engine. Click "Make Default", delete it ("-)". Crash. Review URL: http://codereview.chromium.org/319006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29910 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/keyword_editor_cocoa_controller.h4
-rw-r--r--chrome/browser/cocoa/keyword_editor_cocoa_controller.mm41
2 files changed, 28 insertions, 17 deletions
diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.h b/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
index 0757e69..6aac616 100644
--- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
+++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
@@ -44,10 +44,6 @@ class KeywordEditorModelObserver : public TemplateURLModelObserver,
// Lazily converts the image at the given row and caches it in |iconImages_|.
NSImage* GetImageForRow(int row);
- protected:
- // Invalidates a range of the |iconImages_| cache.
- void InvalidateIconCache(int start, int length);
-
private:
KeywordEditorCocoaController* controller_;
diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
index 032ffbb..86b7e56 100644
--- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
+++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
@@ -57,35 +57,54 @@ void KeywordEditorModelObserver::OnEditedKeyword(
}
void KeywordEditorModelObserver::OnModelChanged() {
- InvalidateIconCache(0, [iconImages_ count]);
int count = [controller_ controller]->table_model()->RowCount();
+ [iconImages_ setCount:0];
[iconImages_ setCount:count];
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsChanged(int start, int length) {
- InvalidateIconCache(start, length);
+ DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
+ for (int i = start; i < (start + length); ++i) {
+ [iconImages_ replacePointerAtIndex:i withPointer:NULL];
+ }
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsAdded(int start, int length) {
DCHECK_LE(start, static_cast<int>([iconImages_ count]));
- for (int i = 0; i < length; ++i) {
- [iconImages_ insertPointer:NULL atIndex:start]; // Values slide down.
+
+ // -[NSPointerArray insertPointer:atIndex:] throws if index == count.
+ // Instead expand the array with NULLs.
+ if (start == static_cast<int>([iconImages_ count])) {
+ [iconImages_ setCount:start + length];
+ } else {
+ for (int i = 0; i < length; ++i) {
+ [iconImages_ insertPointer:NULL atIndex:start]; // Values slide up.
+ }
}
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsRemoved(int start, int length) {
DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
for (int i = 0; i < length; ++i) {
- [iconImages_ removePointerAtIndex:start]; // Values slide up.
+ [iconImages_ removePointerAtIndex:start]; // Values slide down.
}
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
NSImage* KeywordEditorModelObserver::GetImageForRow(int row) {
- DCHECK(row >= 0 && row < static_cast<int>([iconImages_ count]));
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
+ DCHECK_GE(row, 0);
+ DCHECK_LT(row, static_cast<int>([iconImages_ count]));
NSImage* image = static_cast<NSImage*>([iconImages_ pointerAtIndex:row]);
if (!image) {
const SkBitmap bitmapIcon =
@@ -99,13 +118,6 @@ NSImage* KeywordEditorModelObserver::GetImageForRow(int row) {
return image;
}
-void KeywordEditorModelObserver::InvalidateIconCache(int start, int length) {
- DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
- for (int i = start; i < (start + length); ++i) {
- [iconImages_ replacePointerAtIndex:i withPointer:NULL];
- }
-}
-
// KeywordEditorCocoaController -----------------------------------------------
namespace {
@@ -170,6 +182,8 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
- (void)dealloc {
controller_->table_model()->SetObserver(NULL);
controller_->url_model()->RemoveObserver(observer_.get());
+ [tableView_ setTarget:nil];
+ observer_.reset();
[super dealloc];
}
@@ -221,6 +235,7 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
- (void)modelChanged {
[tableView_ reloadData];
+ [self adjustEditingButtons];
}
- (KeywordEditorController*)controller {