| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/tabs/tab_strip_model.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 InsertTabContentsAt(index, contents, | 113 InsertTabContentsAt(index, contents, |
| 114 foreground ? (ADD_INHERIT_GROUP | ADD_ACTIVE) : | 114 foreground ? (ADD_INHERIT_GROUP | ADD_ACTIVE) : |
| 115 ADD_NONE); | 115 ADD_NONE); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void TabStripModel::InsertTabContentsAt(int index, | 118 void TabStripModel::InsertTabContentsAt(int index, |
| 119 TabContents* contents, | 119 TabContents* contents, |
| 120 int add_types) { | 120 int add_types) { |
| 121 bool active = add_types & ADD_ACTIVE; | 121 bool active = add_types & ADD_ACTIVE; |
| 122 // Force app tabs to be pinned. | 122 // Force app tabs to be pinned. |
| 123 bool pin = | 123 extensions::TabHelper* extensions_tab_helper = |
| 124 contents->extension_tab_helper()->is_app() || add_types & ADD_PINNED; | 124 extensions::TabHelper::FromWebContents(contents->web_contents()); |
| 125 bool pin = extensions_tab_helper->is_app() || add_types & ADD_PINNED; |
| 125 index = ConstrainInsertionIndex(index, pin); | 126 index = ConstrainInsertionIndex(index, pin); |
| 126 | 127 |
| 127 // In tab dragging situations, if the last tab in the window was detached | 128 // In tab dragging situations, if the last tab in the window was detached |
| 128 // then the user aborted the drag, we will have the |closing_all_| member | 129 // then the user aborted the drag, we will have the |closing_all_| member |
| 129 // set (see DetachTabContentsAt) which will mess with our mojo here. We need | 130 // set (see DetachTabContentsAt) which will mess with our mojo here. We need |
| 130 // to clear this bit. | 131 // to clear this bit. |
| 131 closing_all_ = false; | 132 closing_all_ = false; |
| 132 | 133 |
| 133 // Have to get the active contents before we monkey with |contents_| | 134 // Have to get the active contents before we monkey with |contents_| |
| 134 // otherwise we run into problems when we try to change the active contents | 135 // otherwise we run into problems when we try to change the active contents |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 bool TabStripModel::IsTabPinned(int index) const { | 559 bool TabStripModel::IsTabPinned(int index) const { |
| 559 DCHECK(ContainsIndex(index)); | 560 DCHECK(ContainsIndex(index)); |
| 560 return contents_data_[index]->pinned; | 561 return contents_data_[index]->pinned; |
| 561 } | 562 } |
| 562 | 563 |
| 563 bool TabStripModel::IsMiniTab(int index) const { | 564 bool TabStripModel::IsMiniTab(int index) const { |
| 564 return IsTabPinned(index) || IsAppTab(index); | 565 return IsTabPinned(index) || IsAppTab(index); |
| 565 } | 566 } |
| 566 | 567 |
| 567 bool TabStripModel::IsAppTab(int index) const { | 568 bool TabStripModel::IsAppTab(int index) const { |
| 568 TabContents* contents = GetTabContentsAt(index); | 569 WebContents* contents = GetTabContentsAt(index)->web_contents(); |
| 569 return contents && contents->extension_tab_helper()->is_app(); | 570 return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); |
| 570 } | 571 } |
| 571 | 572 |
| 572 bool TabStripModel::IsTabBlocked(int index) const { | 573 bool TabStripModel::IsTabBlocked(int index) const { |
| 573 return contents_data_[index]->blocked; | 574 return contents_data_[index]->blocked; |
| 574 } | 575 } |
| 575 | 576 |
| 576 bool TabStripModel::IsTabDiscarded(int index) const { | 577 bool TabStripModel::IsTabDiscarded(int index) const { |
| 577 return contents_data_[index]->discarded; | 578 return contents_data_[index]->discarded; |
| 578 } | 579 } |
| 579 | 580 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 break; | 993 break; |
| 993 } | 994 } |
| 994 | 995 |
| 995 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 996 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 996 const extensions::Extension* extension = | 997 const extensions::Extension* extension = |
| 997 content::Details<extensions::UnloadedExtensionInfo>( | 998 content::Details<extensions::UnloadedExtensionInfo>( |
| 998 details)->extension; | 999 details)->extension; |
| 999 // Iterate backwards as we may remove items while iterating. | 1000 // Iterate backwards as we may remove items while iterating. |
| 1000 for (int i = count() - 1; i >= 0; i--) { | 1001 for (int i = count() - 1; i >= 0; i--) { |
| 1001 TabContents* contents = GetTabContentsAt(i); | 1002 TabContents* contents = GetTabContentsAt(i); |
| 1002 if (contents->extension_tab_helper()->extension_app() == extension) { | 1003 if (extensions::TabHelper::FromWebContents(contents->web_contents())-> |
| 1004 extension_app() == extension) { |
| 1003 // The extension an app tab was created from has been nuked. Delete | 1005 // The extension an app tab was created from has been nuked. Delete |
| 1004 // the WebContents. Deleting a WebContents results in a notification | 1006 // the WebContents. Deleting a WebContents results in a notification |
| 1005 // of type NOTIFICATION_WEB_CONTENTS_DESTROYED; we do the necessary | 1007 // of type NOTIFICATION_WEB_CONTENTS_DESTROYED; we do the necessary |
| 1006 // cleanup in handling that notification. | 1008 // cleanup in handling that notification. |
| 1007 | 1009 |
| 1008 InternalCloseTab(contents, i, false); | 1010 InternalCloseTab(contents, i, false); |
| 1009 } | 1011 } |
| 1010 } | 1012 } |
| 1011 break; | 1013 break; |
| 1012 } | 1014 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1313 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1312 const NavigationController* tab) { | 1314 const NavigationController* tab) { |
| 1313 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1315 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1314 i != contents_data_.end(); ++i) { | 1316 i != contents_data_.end(); ++i) { |
| 1315 if ((*i)->group == tab) | 1317 if ((*i)->group == tab) |
| 1316 (*i)->group = NULL; | 1318 (*i)->group = NULL; |
| 1317 if ((*i)->opener == tab) | 1319 if ((*i)->opener == tab) |
| 1318 (*i)->opener = NULL; | 1320 (*i)->opener = NULL; |
| 1319 } | 1321 } |
| 1320 } | 1322 } |
| OLD | NEW |