summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/tab_strip_controller.mm
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 00:16:45 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 00:16:45 +0000
commit8ad85c0ef39433a26a0093853f34d7eec9be0706 (patch)
treec34f4d0d804bac6cff8d164175eebc62b82fe926 /chrome/browser/cocoa/tab_strip_controller.mm
parent1bc830627e73b76f82679a3eff39e44172f9e145 (diff)
downloadchromium_src-8ad85c0ef39433a26a0093853f34d7eec9be0706.zip
chromium_src-8ad85c0ef39433a26a0093853f34d7eec9be0706.tar.gz
chromium_src-8ad85c0ef39433a26a0093853f34d7eec9be0706.tar.bz2
Make sure tab contents get cleaned up and dealloc'd correctly when a tab closes.
Review URL: http://codereview.chromium.org/20117 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_strip_controller.mm')
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm20
1 files changed, 15 insertions, 5 deletions
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index eee4cbe..d21a64c 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -109,9 +109,16 @@ class TabStripBridge : public TabStripModelObserver {
[newView setFrame:frame];
// Remove the old view from the view hierarchy. We know there's only one
- // child of the contentView because we're the one who put it there.
- NSView* oldView = [[contentView subviews] objectAtIndex:0];
- [contentView replaceSubview:oldView with:newView];
+ // child of the contentView because we're the one who put it there. There
+ // may not be any children in the case of a tab that's been closed, in
+ // which case there's no swapping going on.
+ NSArray* subviews = [contentView subviews];
+ if ([subviews count]) {
+ NSView* oldView = [subviews objectAtIndex:0];
+ [contentView replaceSubview:oldView with:newView];
+ } else {
+ [contentView addSubview:newView];
+ }
}
// Create a new tab view and set its cell correctly so it draws the way we
@@ -239,10 +246,13 @@ class TabStripBridge : public TabStripModelObserver {
// controller and remove the view from the strip.
- (void)tabDetachedWithContents:(TabContents*)contents
atIndex:(NSInteger)index {
- // Release the tab contents controller so those views get destroyed.
+ // Release the tab contents controller so those views get destroyed. This
+ // will remove all the tab content Cocoa views from the hierarchy. A
+ // subsequent "select tab" notification will follow from the model. To
+ // tell us what to swap in in its absence.
NSValue* key = [NSValue valueWithPointer:contents];
[tabContentsToController_ removeObjectForKey:key];
-
+
// Remove the |index|th view from the tab strip
NSView* tab = [[tabView_ subviews] objectAtIndex:index];
NSInteger tabWidth = [tab frame].size.width;