Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4702)

Unified Diff: chrome/browser/tabs/tab_strip_model.cc

Issue 2821011: Removes phantom tabs. (Closed)
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.h ('k') | chrome/browser/tabs/tab_strip_model_order_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tabs/tab_strip_model.cc
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 7e0bcb7ccb6722146a5330d01518bd53db455883..b033a54b6ac59d77a76ed1e8478998b80e4171bc 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -80,14 +80,6 @@ void TabStripModel::RemoveObserver(TabStripModelObserver* observer) {
observers_.RemoveObserver(observer);
}
-bool TabStripModel::HasNonPhantomTabs() const {
- for (int i = 0; i < count(); i++) {
- if (!IsPhantomTab(i))
- return true;
- }
- return false;
-}
-
void TabStripModel::SetInsertionPolicy(InsertionPolicy policy) {
order_controller_->set_insertion_policy(policy);
}
@@ -173,19 +165,19 @@ TabContents* TabStripModel::DetachTabContentsAt(int index) {
DCHECK(ContainsIndex(index));
TabContents* removed_contents = GetContentsAt(index);
int next_selected_index =
- order_controller_->DetermineNewSelectedIndex(index, true);
+ order_controller_->DetermineNewSelectedIndex(index);
delete contents_data_.at(index);
contents_data_.erase(contents_data_.begin() + index);
- next_selected_index = IndexOfNextNonPhantomTab(next_selected_index, -1);
- if (!HasNonPhantomTabs())
+ next_selected_index = IndexOfNextTab(next_selected_index);
+ if (empty())
closing_all_ = true;
TabStripModelObservers::Iterator iter(observers_);
while (TabStripModelObserver* obs = iter.GetNext()) {
obs->TabDetachedAt(removed_contents, index);
- if (!HasNonPhantomTabs())
+ if (empty())
obs->TabStripEmpty();
}
- if (HasNonPhantomTabs()) {
+ if (!empty()) {
if (index == selected_index_) {
ChangeSelectedContentsFrom(removed_contents, next_selected_index, false);
} else if (index < selected_index_) {
@@ -296,17 +288,13 @@ int TabStripModel::GetIndexOfNextTabContentsOpenedBy(
// Check tabs after start_index first.
for (int i = start_index + 1; i < count(); ++i) {
- if (OpenerMatches(contents_data_[i], opener, use_group) &&
- !IsPhantomTab(i)) {
+ if (OpenerMatches(contents_data_[i], opener, use_group))
return i;
- }
}
// Then check tabs before start_index, iterating backwards.
for (int i = start_index - 1; i >= 0; --i) {
- if (OpenerMatches(contents_data_[i], opener, use_group) &&
- !IsPhantomTab(i)) {
+ if (OpenerMatches(contents_data_[i], opener, use_group))
return i;
- }
}
return kNoTab;
}
@@ -318,7 +306,7 @@ int TabStripModel::GetIndexOfFirstTabContentsOpenedBy(
DCHECK(ContainsIndex(start_index));
for (int i = 0; i < start_index; ++i) {
- if (contents_data_[i]->opener == opener && !IsPhantomTab(i))
+ if (contents_data_[i]->opener == opener)
return i;
}
return kNoTab;
@@ -337,10 +325,8 @@ int TabStripModel::GetIndexOfLastTabContentsOpenedBy(
next = iter - 1;
if (next == end)
break;
- if ((*next)->opener == opener &&
- !IsPhantomTab(static_cast<int>(next - contents_data_.begin()))) {
+ if ((*next)->opener == opener)
return static_cast<int>(next - contents_data_.begin());
- }
}
return kNoTab;
}
@@ -454,11 +440,6 @@ bool TabStripModel::IsToolbarVisible(int index) const {
return prefs->AreAppTabToolbarsVisible(extension_app->id());
}
-bool TabStripModel::IsPhantomTab(int index) const {
- return IsTabPinned(index) &&
- GetTabContentsAt(index)->controller().needs_reload();
-}
-
bool TabStripModel::IsTabBlocked(int index) const {
return contents_data_[index]->blocked;
}
@@ -694,14 +675,8 @@ void TabStripModel::ExecuteContextMenuCommand(
UserMetricsAction("TabContextMenu_TogglePinned"),
profile_);
- if (IsPhantomTab(context_index)) {
- // The tab is a phantom tab, close it.
- CloseTabContentsAt(context_index,
- CLOSE_USER_GESTURE | CLOSE_CREATE_HISTORICAL_TAB);
- } else {
- SelectTabContentsAt(context_index, true);
- SetTabPinned(context_index, !IsTabPinned(context_index));
- }
+ SelectTabContentsAt(context_index, true);
+ SetTabPinned(context_index, !IsTabPinned(context_index));
break;
}
case CommandToggleToolbar: {
@@ -797,13 +772,7 @@ void TabStripModel::Observe(NotificationType type,
if (index != TabStripModel::kNoTab) {
// Note that we only detach the contents here, not close it - it's
// already been closed. We just want to undo our bookkeeping.
- if (ShouldMakePhantomOnClose(index)) {
- // We don't actually allow pinned tabs to close. Instead they become
- // phantom.
- MakePhantom(index);
- } else {
- DetachTabContentsAt(index);
- }
+ DetachTabContentsAt(index);
}
break;
}
@@ -971,83 +940,16 @@ void TabStripModel::SelectRelativeTab(bool next) {
if (contents_data_.empty())
return;
- // Skip pinned-app-phantom tabs when iterating.
- int index = selected_index_;
int delta = next ? 1 : -1;
- do {
- index = (index + count() + delta) % count();
- } while (index != selected_index_ && IsPhantomTab(index));
+ int index = (selected_index_ + count() + delta) % count();
SelectTabContentsAt(index, true);
}
-int TabStripModel::IndexOfNextNonPhantomTab(int index,
- int ignore_index) {
- if (index == kNoTab)
- return kNoTab;
-
- if (empty())
- return index;
-
- index = std::min(count() - 1, std::max(0, index));
- int start = index;
- do {
- if (index != ignore_index && !IsPhantomTab(index))
- return index;
- index = (index + 1) % count();
- } while (index != start);
-
- // All phantom tabs.
- return start;
-}
-
-bool TabStripModel::ShouldMakePhantomOnClose(int index) {
- if (IsTabPinned(index) && !IsPhantomTab(index) && !closing_all_ &&
- profile()) {
- if (!IsAppTab(index))
- return true; // Always make non-app tabs go phantom.
-
- ExtensionsService* extension_service = profile()->GetExtensionsService();
- if (!extension_service)
- return false;
-
- Extension* extension_app = GetTabContentsAt(index)->extension_app();
- DCHECK(extension_app);
-
- // Only allow the tab to be made phantom if the extension still exists.
- return extension_service->GetExtensionById(extension_app->id(),
- false) != NULL;
- }
- return false;
+int TabStripModel::IndexOfNextTab(int index) {
+ return (index == kNoTab || empty()) ?
+ index : std::min(count() - 1, std::max(0, index));
}
-void TabStripModel::MakePhantom(int index) {
- TabContents* old_contents = GetContentsAt(index);
- TabContents* new_contents = old_contents->CloneAndMakePhantom();
-
- contents_data_[index]->contents = new_contents;
-
- // And notify observers.
- FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
- TabReplacedAt(old_contents, new_contents, index));
-
- if (selected_index_ == index && HasNonPhantomTabs()) {
- // Change the selection, otherwise we're going to force the phantom tab
- // to become selected.
- // NOTE: we must do this after the call to Replace otherwise browser's
- // TabSelectedAt will send out updates for the old TabContents which we've
- // already told observers has been closed (we sent out TabClosing at).
- int new_selected_index =
- order_controller_->DetermineNewSelectedIndex(index, false);
- new_selected_index = IndexOfNextNonPhantomTab(new_selected_index,
- index);
- SelectTabContentsAt(new_selected_index, true);
- }
-
- if (!HasNonPhantomTabs())
- FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabStripEmpty());
-}
-
-
void TabStripModel::MoveTabContentsAtImpl(int index, int to_position,
bool select_after_move) {
TabContentsData* moved_data = contents_data_.at(index);
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.h ('k') | chrome/browser/tabs/tab_strip_model_order_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698