| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
| 61 // TabStripModel, public: | 61 // TabStripModel, public: |
| 62 | 62 |
| 63 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile) | 63 TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile) |
| 64 : delegate_(delegate), | 64 : delegate_(delegate), |
| 65 profile_(profile), | 65 profile_(profile), |
| 66 closing_all_(false), | 66 closing_all_(false), |
| 67 order_controller_(NULL) { | 67 order_controller_(NULL), |
| 68 magic_id_(0) { |
| 68 DCHECK(delegate_); | 69 DCHECK(delegate_); |
| 69 registrar_.Add(this, | 70 registrar_.Add(this, |
| 70 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 71 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 71 NotificationService::AllBrowserContextsAndSources()); | 72 NotificationService::AllBrowserContextsAndSources()); |
| 72 registrar_.Add(this, | 73 registrar_.Add(this, |
| 73 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 74 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 74 Source<Profile>(profile_)); | 75 Source<Profile>(profile_)); |
| 75 order_controller_ = new TabStripModelOrderController(this); | 76 order_controller_ = new TabStripModelOrderController(this); |
| 76 } | 77 } |
| 77 | 78 |
| 78 TabStripModel::~TabStripModel() { | 79 TabStripModel::~TabStripModel() { |
| 80 magic_id_ = 0x1234567; |
| 79 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 81 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
| 80 TabStripModelDeleted()); | 82 TabStripModelDeleted()); |
| 81 STLDeleteContainerPointers(contents_data_.begin(), contents_data_.end()); | 83 STLDeleteElements(&contents_data_); |
| 82 delete order_controller_; | 84 delete order_controller_; |
| 85 order_controller_ = NULL; |
| 86 magic_id_ = 0x76543210; |
| 83 } | 87 } |
| 84 | 88 |
| 85 void TabStripModel::AddObserver(TabStripModelObserver* observer) { | 89 void TabStripModel::AddObserver(TabStripModelObserver* observer) { |
| 86 observers_.AddObserver(observer); | 90 observers_.AddObserver(observer); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void TabStripModel::RemoveObserver(TabStripModelObserver* observer) { | 93 void TabStripModel::RemoveObserver(TabStripModelObserver* observer) { |
| 90 observers_.RemoveObserver(observer); | 94 observers_.RemoveObserver(observer); |
| 91 } | 95 } |
| 92 | 96 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 110 bool foreground) { | 114 bool foreground) { |
| 111 int index = order_controller_->DetermineInsertionIndexForAppending(); | 115 int index = order_controller_->DetermineInsertionIndexForAppending(); |
| 112 InsertTabContentsAt(index, contents, | 116 InsertTabContentsAt(index, contents, |
| 113 foreground ? (ADD_INHERIT_GROUP | ADD_ACTIVE) : | 117 foreground ? (ADD_INHERIT_GROUP | ADD_ACTIVE) : |
| 114 ADD_NONE); | 118 ADD_NONE); |
| 115 } | 119 } |
| 116 | 120 |
| 117 void TabStripModel::InsertTabContentsAt(int index, | 121 void TabStripModel::InsertTabContentsAt(int index, |
| 118 TabContentsWrapper* contents, | 122 TabContentsWrapper* contents, |
| 119 int add_types) { | 123 int add_types) { |
| 124 CHECK(wrapper); |
| 120 bool active = add_types & ADD_ACTIVE; | 125 bool active = add_types & ADD_ACTIVE; |
| 121 // Force app tabs to be pinned. | 126 // Force app tabs to be pinned. |
| 122 bool pin = | 127 bool pin = |
| 123 contents->extension_tab_helper()->is_app() || add_types & ADD_PINNED; | 128 contents->extension_tab_helper()->is_app() || add_types & ADD_PINNED; |
| 124 index = ConstrainInsertionIndex(index, pin); | 129 index = ConstrainInsertionIndex(index, pin); |
| 125 | 130 |
| 126 // In tab dragging situations, if the last tab in the window was detached | 131 // In tab dragging situations, if the last tab in the window was detached |
| 127 // then the user aborted the drag, we will have the |closing_all_| member | 132 // then the user aborted the drag, we will have the |closing_all_| member |
| 128 // set (see DetachTabContentsAt) which will mess with our mojo here. We need | 133 // set (see DetachTabContentsAt) which will mess with our mojo here. We need |
| 129 // to clear this bit. | 134 // to clear this bit. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 old_model.Copy(selection_model_); | 167 old_model.Copy(selection_model_); |
| 163 if (active) { | 168 if (active) { |
| 164 selection_model_.SetSelectedIndex(index); | 169 selection_model_.SetSelectedIndex(index); |
| 165 NotifyIfActiveOrSelectionChanged(selected_contents, false, old_model); | 170 NotifyIfActiveOrSelectionChanged(selected_contents, false, old_model); |
| 166 } | 171 } |
| 167 } | 172 } |
| 168 | 173 |
| 169 TabContentsWrapper* TabStripModel::ReplaceTabContentsAt( | 174 TabContentsWrapper* TabStripModel::ReplaceTabContentsAt( |
| 170 int index, | 175 int index, |
| 171 TabContentsWrapper* new_contents) { | 176 TabContentsWrapper* new_contents) { |
| 172 DCHECK(ContainsIndex(index)); | 177 CHECK(new_contents); |
| 178 CHECK(ContainsIndex(index)); |
| 173 TabContentsWrapper* old_contents = GetContentsAt(index); | 179 TabContentsWrapper* old_contents = GetContentsAt(index); |
| 174 | 180 |
| 175 ForgetOpenersAndGroupsReferencing(&(old_contents->controller())); | 181 ForgetOpenersAndGroupsReferencing(&(old_contents->controller())); |
| 176 | 182 |
| 177 contents_data_[index]->contents = new_contents; | 183 contents_data_[index]->contents = new_contents; |
| 178 | 184 |
| 179 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 185 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
| 180 TabReplacedAt(this, old_contents, new_contents, index)); | 186 TabReplacedAt(this, old_contents, new_contents, index)); |
| 181 | 187 |
| 182 // When the active tab contents is replaced send out selected notification | 188 // When the active tab contents is replaced send out selected notification |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 if ((*iter)->contents == contents) | 337 if ((*iter)->contents == contents) |
| 332 return index; | 338 return index; |
| 333 } | 339 } |
| 334 return kNoTab; | 340 return kNoTab; |
| 335 } | 341 } |
| 336 | 342 |
| 337 int TabStripModel::GetWrapperIndex(const TabContents* contents) const { | 343 int TabStripModel::GetWrapperIndex(const TabContents* contents) const { |
| 338 int index = 0; | 344 int index = 0; |
| 339 TabContentsDataVector::const_iterator iter = contents_data_.begin(); | 345 TabContentsDataVector::const_iterator iter = contents_data_.begin(); |
| 340 for (; iter != contents_data_.end(); ++iter, ++index) { | 346 for (; iter != contents_data_.end(); ++iter, ++index) { |
| 347 CHECK(*iter) << magic_id_; |
| 348 CHECK((*iter)->contents) << magic_id_; |
| 341 if ((*iter)->contents->tab_contents() == contents) | 349 if ((*iter)->contents->tab_contents() == contents) |
| 342 return index; | 350 return index; |
| 343 } | 351 } |
| 344 return kNoTab; | 352 return kNoTab; |
| 345 } | 353 } |
| 346 | 354 |
| 347 int TabStripModel::GetIndexOfController( | 355 int TabStripModel::GetIndexOfController( |
| 348 const NavigationController* controller) const { | 356 const NavigationController* controller) const { |
| 349 int index = 0; | 357 int index = 0; |
| 350 TabContentsDataVector::const_iterator iter = contents_data_.begin(); | 358 TabContentsDataVector::const_iterator iter = contents_data_.begin(); |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1326 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1319 const NavigationController* tab) { | 1327 const NavigationController* tab) { |
| 1320 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1328 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1321 i != contents_data_.end(); ++i) { | 1329 i != contents_data_.end(); ++i) { |
| 1322 if ((*i)->group == tab) | 1330 if ((*i)->group == tab) |
| 1323 (*i)->group = NULL; | 1331 (*i)->group = NULL; |
| 1324 if ((*i)->opener == tab) | 1332 if ((*i)->opener == tab) |
| 1325 (*i)->opener = NULL; | 1333 (*i)->opener = NULL; |
| 1326 } | 1334 } |
| 1327 } | 1335 } |
| OLD | NEW |