From 3b98246a35f25df934bcc1263c266f8b3c04e3be Mon Sep 17 00:00:00 2001 From: "beng@google.com" Date: Tue, 9 Sep 2008 23:28:28 +0000 Subject: Bounds check the tab index before attempting to index into the TabStripModel using it. Under some circumstances, it seems like it's possible for the user to close or otherwise manipulate a Tab whose corresponding entry has already been removed from the model. This might be related to animations and performance constraints. B=1366019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1949 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/tabs/tab_strip.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chrome/browser/tabs/tab_strip.cc b/chrome/browser/tabs/tab_strip.cc index 03f6c2e..57a8e32 100644 --- a/chrome/browser/tabs/tab_strip.cc +++ b/chrome/browser/tabs/tab_strip.cc @@ -881,13 +881,13 @@ bool TabStrip::IsTabSelected(const Tab* tab) const { void TabStrip::SelectTab(Tab* tab) { int index = GetIndexOfTab(tab); - if (index != -1) + if (model_->ContainsIndex(index)) model_->SelectTabContentsAt(index, true); } void TabStrip::CloseTab(Tab* tab) { int tab_index = GetIndexOfTab(tab); - if (tab_index != -1) { + if (model_->ContainsIndex(tab_index)) { TabContents* contents = model_->GetTabContentsAt(tab_index); if (contents) UserMetrics::RecordAction(L"CloseTab_Mouse", contents->profile()); @@ -905,7 +905,7 @@ void TabStrip::CloseTab(Tab* tab) { bool TabStrip::IsCommandEnabledForTab( TabStripModel::ContextMenuCommand command_id, const Tab* tab) const { int index = GetIndexOfTab(tab); - if (index != -1) + if (model_->ContainsIndex(index)) return model_->IsContextMenuCommandEnabled(index, command_id); return false; } @@ -913,7 +913,7 @@ bool TabStrip::IsCommandEnabledForTab( void TabStrip::ExecuteCommandForTab( TabStripModel::ContextMenuCommand command_id, Tab* tab) { int index = GetIndexOfTab(tab); - if (index != -1) + if (model_->ContainsIndex(index)) model_->ExecuteContextMenuCommand(index, command_id); } @@ -921,7 +921,7 @@ void TabStrip::StartHighlightTabsForCommand( TabStripModel::ContextMenuCommand command_id, Tab* tab) { if (command_id == TabStripModel::CommandCloseTabsOpenedBy) { int index = GetIndexOfTab(tab); - if (index != -1) { + if (model_->ContainsIndex(index)) { std::vector indices = model_->GetIndexesOpenedBy(index); std::vector::const_iterator iter = indices.begin(); for (; iter != indices.end(); ++iter) { @@ -933,7 +933,7 @@ void TabStrip::StartHighlightTabsForCommand( } } else if (command_id == TabStripModel::CommandCloseTabsToRight) { int index = GetIndexOfTab(tab); - if (index != -1) { + if (model_->ContainsIndex(index)) { for (int i = index + 1; i < GetTabCount(); ++i) { Tab* current_tab = GetTabAt(i); current_tab->StartPulse(); -- cgit v1.1