| 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" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model.h" | 15 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
| 17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 19 #include "chrome/browser/metrics/user_metrics.h" | 20 #include "chrome/browser/metrics/user_metrics.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sessions/tab_restore_service.h" | 22 #include "chrome/browser/sessions/tab_restore_service.h" |
| 22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 23 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
| 23 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 24 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
| 28 #include "content/browser/tab_contents/navigation_controller.h" | 29 #include "content/browser/tab_contents/navigation_controller.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 InsertTabContentsAt(index, contents, | 111 InsertTabContentsAt(index, contents, |
| 111 foreground ? (ADD_INHERIT_GROUP | ADD_SELECTED) : | 112 foreground ? (ADD_INHERIT_GROUP | ADD_SELECTED) : |
| 112 ADD_NONE); | 113 ADD_NONE); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void TabStripModel::InsertTabContentsAt(int index, | 116 void TabStripModel::InsertTabContentsAt(int index, |
| 116 TabContentsWrapper* contents, | 117 TabContentsWrapper* contents, |
| 117 int add_types) { | 118 int add_types) { |
| 118 bool foreground = add_types & ADD_SELECTED; | 119 bool foreground = add_types & ADD_SELECTED; |
| 119 // Force app tabs to be pinned. | 120 // Force app tabs to be pinned. |
| 120 bool pin = contents->is_app() || add_types & ADD_PINNED; | 121 bool pin = |
| 122 contents->extension_tab_helper()->is_app() || add_types & ADD_PINNED; |
| 121 index = ConstrainInsertionIndex(index, pin); | 123 index = ConstrainInsertionIndex(index, pin); |
| 122 | 124 |
| 123 // In tab dragging situations, if the last tab in the window was detached | 125 // In tab dragging situations, if the last tab in the window was detached |
| 124 // then the user aborted the drag, we will have the |closing_all_| member | 126 // then the user aborted the drag, we will have the |closing_all_| member |
| 125 // set (see DetachTabContentsAt) which will mess with our mojo here. We need | 127 // set (see DetachTabContentsAt) which will mess with our mojo here. We need |
| 126 // to clear this bit. | 128 // to clear this bit. |
| 127 closing_all_ = false; | 129 closing_all_ = false; |
| 128 | 130 |
| 129 // Have to get the selected contents before we monkey with |contents_| | 131 // Have to get the selected contents before we monkey with |contents_| |
| 130 // otherwise we run into problems when we try to change the selected contents | 132 // otherwise we run into problems when we try to change the selected contents |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 DCHECK(ContainsIndex(index)); | 540 DCHECK(ContainsIndex(index)); |
| 539 return contents_data_[index]->pinned; | 541 return contents_data_[index]->pinned; |
| 540 } | 542 } |
| 541 | 543 |
| 542 bool TabStripModel::IsMiniTab(int index) const { | 544 bool TabStripModel::IsMiniTab(int index) const { |
| 543 return IsTabPinned(index) || IsAppTab(index); | 545 return IsTabPinned(index) || IsAppTab(index); |
| 544 } | 546 } |
| 545 | 547 |
| 546 bool TabStripModel::IsAppTab(int index) const { | 548 bool TabStripModel::IsAppTab(int index) const { |
| 547 TabContentsWrapper* contents = GetTabContentsAt(index); | 549 TabContentsWrapper* contents = GetTabContentsAt(index); |
| 548 return contents && contents->is_app(); | 550 return contents && contents->extension_tab_helper()->is_app(); |
| 549 } | 551 } |
| 550 | 552 |
| 551 bool TabStripModel::IsTabBlocked(int index) const { | 553 bool TabStripModel::IsTabBlocked(int index) const { |
| 552 return contents_data_[index]->blocked; | 554 return contents_data_[index]->blocked; |
| 553 } | 555 } |
| 554 | 556 |
| 555 int TabStripModel::IndexOfFirstNonMiniTab() const { | 557 int TabStripModel::IndexOfFirstNonMiniTab() const { |
| 556 for (size_t i = 0; i < contents_data_.size(); ++i) { | 558 for (size_t i = 0; i < contents_data_.size(); ++i) { |
| 557 if (!IsMiniTab(static_cast<int>(i))) | 559 if (!IsMiniTab(static_cast<int>(i))) |
| 558 return static_cast<int>(i); | 560 return static_cast<int>(i); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 } | 992 } |
| 991 break; | 993 break; |
| 992 } | 994 } |
| 993 | 995 |
| 994 case NotificationType::EXTENSION_UNLOADED: { | 996 case NotificationType::EXTENSION_UNLOADED: { |
| 995 const Extension* extension = | 997 const Extension* extension = |
| 996 Details<UnloadedExtensionInfo>(details)->extension; | 998 Details<UnloadedExtensionInfo>(details)->extension; |
| 997 // Iterate backwards as we may remove items while iterating. | 999 // Iterate backwards as we may remove items while iterating. |
| 998 for (int i = count() - 1; i >= 0; i--) { | 1000 for (int i = count() - 1; i >= 0; i--) { |
| 999 TabContentsWrapper* contents = GetTabContentsAt(i); | 1001 TabContentsWrapper* contents = GetTabContentsAt(i); |
| 1000 if (contents->extension_app() == extension) { | 1002 if (contents->extension_tab_helper()->extension_app() == extension) { |
| 1001 // The extension an app tab was created from has been nuked. Delete | 1003 // The extension an app tab was created from has been nuked. Delete |
| 1002 // the TabContents. Deleting a TabContents results in a notification | 1004 // the TabContents. Deleting a TabContents results in a notification |
| 1003 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in | 1005 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in |
| 1004 // handling that notification. | 1006 // handling that notification. |
| 1005 | 1007 |
| 1006 InternalCloseTab(contents, i, false); | 1008 InternalCloseTab(contents, i, false); |
| 1007 } | 1009 } |
| 1008 } | 1010 } |
| 1009 break; | 1011 break; |
| 1010 } | 1012 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1311 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1310 const NavigationController* tab) { | 1312 const NavigationController* tab) { |
| 1311 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1313 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1312 i != contents_data_.end(); ++i) { | 1314 i != contents_data_.end(); ++i) { |
| 1313 if ((*i)->group == tab) | 1315 if ((*i)->group == tab) |
| 1314 (*i)->group = NULL; | 1316 (*i)->group = NULL; |
| 1315 if ((*i)->opener == tab) | 1317 if ((*i)->opener == tab) |
| 1316 (*i)->opener = NULL; | 1318 (*i)->opener = NULL; |
| 1317 } | 1319 } |
| 1318 } | 1320 } |
| OLD | NEW |