Commit 9775aabe authored by sangwoo.ko's avatar sangwoo.ko Committed by Commit Bot

Deprecate old TabStripModelObserver API

Stop notifying events via old api and replace old API with new API.
This CL is a refactor and has no intended behavior change.

Bug: 842194
Change-Id: I5e11e7323940acbbdc31bd73d599480c7312e8b9
Reviewed-on: https://chromium-review.googlesource.com/c/1314508
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605584}
parent d9966951
......@@ -521,10 +521,13 @@ class TabActivationWaiter : public TabStripModelObserver {
}
// TabStripModelObserver overrides.
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override {
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override {
if (tab_strip_model->empty() || !selection.active_tab_changed())
return;
number_of_unconsumed_active_tab_changes_++;
DCHECK_EQ(1, number_of_unconsumed_active_tab_changes_);
if (message_loop_runner_)
......
......@@ -19,10 +19,15 @@ IntentPickerController::~IntentPickerController() {
browser_->tab_strip_model()->RemoveObserver(this);
}
void IntentPickerController::TabSelectionChanged(
TabStripModel* model,
const ui::ListSelectionModel& old_model) {
ResetVisibility();
void IntentPickerController::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (tab_strip_model->empty())
return;
if (selection.selection_changed())
ResetVisibility();
}
void IntentPickerController::ResetVisibility() {
......
......@@ -9,8 +9,6 @@
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
class Browser;
class ListSelectionModel;
class TabStripModel;
namespace arc {
......@@ -23,8 +21,10 @@ class IntentPickerController : public TabStripModelObserver {
private:
// TabStripModelObserver:
void TabSelectionChanged(TabStripModel* model,
const ui::ListSelectionModel& old_model) override;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void ResetVisibility();
......
......@@ -136,61 +136,30 @@ void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
UpdateBrowserItemState();
}
void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
Browser* browser = NULL;
// Use |new_contents|. |old_contents| could be NULL.
DCHECK(new_contents);
browser = chrome::FindBrowserWithWebContents(new_contents);
// Update immediately on a tab change.
if (old_contents &&
(TabStripModel::kNoTab !=
browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) {
UpdateAppItemState(old_contents, false /*remove*/);
}
if (new_contents) {
UpdateAppItemState(new_contents, false /*remove*/);
UpdateBrowserItemState();
SetShelfIDForBrowserWindowContents(browser, new_contents);
void BrowserStatusMonitor::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (change.type() == TabStripModelChange::kInserted) {
for (const auto& delta : change.deltas())
OnTabInserted(delta.insert.contents);
} else if (change.type() == TabStripModelChange::kRemoved) {
for (const auto& delta : change.deltas()) {
if (delta.remove.will_be_deleted)
OnTabClosing(delta.remove.contents);
}
} else if (change.type() == TabStripModelChange::kReplaced) {
for (const auto& delta : change.deltas()) {
OnTabReplaced(tab_strip_model, delta.replace.old_contents,
delta.replace.new_contents);
}
}
}
void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) {
DCHECK(old_contents && new_contents);
Browser* browser = chrome::FindBrowserWithWebContents(new_contents);
UpdateAppItemState(old_contents, true /*remove*/);
RemoveWebContentsObserver(old_contents);
UpdateAppItemState(new_contents, false /*remove*/);
UpdateBrowserItemState();
if (tab_strip_model->GetActiveWebContents() == new_contents)
SetShelfIDForBrowserWindowContents(browser, new_contents);
AddWebContentsObserver(new_contents);
}
void BrowserStatusMonitor::TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) {
UpdateAppItemState(contents, false /*remove*/);
AddWebContentsObserver(contents);
}
if (tab_strip_model->empty())
return;
void BrowserStatusMonitor::TabClosingAt(TabStripModel* tab_strip_mode,
content::WebContents* contents,
int index) {
UpdateAppItemState(contents, true /*remove*/);
RemoveWebContentsObserver(contents);
if (selection.active_tab_changed())
OnActiveTabChanged(selection.old_contents, selection.new_contents);
}
void BrowserStatusMonitor::WebContentsDestroyed(
......@@ -236,6 +205,56 @@ bool BrowserStatusMonitor::IsV1AppInShelfWithAppId(const std::string& app_id) {
return false;
}
void BrowserStatusMonitor::OnActiveTabChanged(
content::WebContents* old_contents,
content::WebContents* new_contents) {
Browser* browser = nullptr;
// Use |new_contents|. |old_contents| could be nullptr.
DCHECK(new_contents);
browser = chrome::FindBrowserWithWebContents(new_contents);
// Update immediately on a tab change.
if (old_contents &&
(TabStripModel::kNoTab !=
browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) {
UpdateAppItemState(old_contents, false /*remove*/);
}
if (new_contents) {
UpdateAppItemState(new_contents, false /*remove*/);
UpdateBrowserItemState();
SetShelfIDForBrowserWindowContents(browser, new_contents);
}
}
void BrowserStatusMonitor::OnTabReplaced(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents) {
DCHECK(old_contents && new_contents);
Browser* browser = chrome::FindBrowserWithWebContents(new_contents);
UpdateAppItemState(old_contents, true /*remove*/);
RemoveWebContentsObserver(old_contents);
UpdateAppItemState(new_contents, false /*remove*/);
UpdateBrowserItemState();
if (tab_strip_model->GetActiveWebContents() == new_contents)
SetShelfIDForBrowserWindowContents(browser, new_contents);
AddWebContentsObserver(new_contents);
}
void BrowserStatusMonitor::OnTabInserted(content::WebContents* contents) {
UpdateAppItemState(contents, false /*remove*/);
AddWebContentsObserver(contents);
}
void BrowserStatusMonitor::OnTabClosing(content::WebContents* contents) {
UpdateAppItemState(contents, true /*remove*/);
RemoveWebContentsObserver(contents);
}
void BrowserStatusMonitor::AddWebContentsObserver(
content::WebContents* contents) {
if (webcontents_to_observer_map_.find(contents) ==
......
......@@ -55,21 +55,10 @@ class BrowserStatusMonitor : public BrowserTabStripTrackerDelegate,
void OnBrowserRemoved(Browser* browser) override;
// TabStripModelObserver overrides:
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
void TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) override;
void TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) override;
void TabClosingAt(TabStripModel* tab_strip_mode,
content::WebContents* contents,
int index) override;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
// Called from our own |LocalWebContentsObserver| when web contents did go
// away without any other notification. This might happen in case of
......@@ -92,6 +81,15 @@ class BrowserStatusMonitor : public BrowserTabStripTrackerDelegate,
private:
class LocalWebContentsObserver;
// Called by TabStripModelChanged()
void OnActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents);
void OnTabReplaced(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents);
void OnTabInserted(content::WebContents* contents);
void OnTabClosing(content::WebContents* contents);
// Create LocalWebContentsObserver for |contents|.
void AddWebContentsObserver(content::WebContents* contents);
......
......@@ -224,11 +224,14 @@ class TabScrubberTest : public InProcessBrowserTest,
}
// TabStripModelObserver overrides.
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override {
activation_order_.push_back(index);
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override {
if (tab_strip_model->empty() || !selection.active_tab_changed())
return;
activation_order_.push_back(selection.new_model.active());
}
// History of tab activation. Scrub() resets it.
......
......@@ -84,16 +84,20 @@ bool TabletModeClient::ShouldTrackBrowser(Browser* browser) {
return tablet_mode_enabled_;
}
void TabletModeClient::TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) {
void TabletModeClient::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (change.type() != TabStripModelChange::kInserted)
return;
// We limit the mobile-like behavior to webcontents in tabstrips since many
// apps and extensions draw their own caption buttons and header frames. We
// don't want those to shrink down and resize to fit the width of their
// windows like webpages on mobile do. So this behavior is limited to webpages
// in tabs and packaged apps.
contents->NotifyPreferencesChanged();
for (const auto& delta : change.deltas())
delta.insert.contents->NotifyPreferencesChanged();
}
void TabletModeClient::FlushForTesting() {
......
......@@ -49,10 +49,10 @@ class TabletModeClient : public ash::mojom::TabletModeClient,
bool ShouldTrackBrowser(Browser* browser) override;
// TabStripModelObserver:
void TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) override;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
// Flushes the mojo pipe to ash.
void FlushForTesting();
......
......@@ -67,15 +67,9 @@ void BrowserTabStripTracker::MaybeTrackBrowser(Browser* browser) {
TabStripModel* tab_strip_model = browser->tab_strip_model();
tab_strip_model->AddObserver(tab_strip_model_observer_);
const int active_index = tab_strip_model->active_index();
std::vector<TabStripModelChange::Delta> deltas;
for (int i = 0; i < tab_strip_model->count(); ++i) {
// TODO(sangwoo108): Delete this. https://crbug.com/842194.
tab_strip_model_observer_->TabInsertedAt(
tab_strip_model, tab_strip_model->GetWebContentsAt(i), i,
i == active_index);
deltas.push_back(TabStripModelChange::CreateInsertDelta(
tab_strip_model->GetWebContentsAt(i), i));
}
......
......@@ -40,13 +40,15 @@ void HandoffActiveURLObserver::OnBrowserRemoved(Browser* removed_browser) {
delegate_->HandoffActiveURLChanged(GetActiveWebContents());
}
void HandoffActiveURLObserver::ActiveTabChanged(
content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
StartObservingWebContents(new_contents);
delegate_->HandoffActiveURLChanged(new_contents);
void HandoffActiveURLObserver::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (tab_strip_model->empty() || !selection.active_tab_changed())
return;
StartObservingWebContents(selection.new_contents);
delegate_->HandoffActiveURLChanged(selection.new_contents);
}
void HandoffActiveURLObserver::DidFinishNavigation(
......
......@@ -33,10 +33,10 @@ class HandoffActiveURLObserver : public BrowserListObserver,
void OnBrowserRemoved(Browser* browser) override;
// TabStripModelObserver
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
// content::WebContentsObserver
void DidFinishNavigation(
......
......@@ -47,12 +47,15 @@ class API_AVAILABLE(macos(10.12.2)) WebContentsNotificationBridge
}
// TabStripModelObserver:
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override {
UpdateWebContents(new_contents);
contents_ = new_contents;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override {
if (tab_strip_model->empty() || !selection.active_tab_changed())
return;
UpdateWebContents(selection.new_contents);
contents_ = selection.new_contents;
}
content::WebContents* contents() const { return contents_; }
......
......@@ -338,9 +338,6 @@ void TabStripModel::InsertWebContentsAt(int index,
selection_model_.IncrementFrom(index);
for (auto& observer : observers_)
observer.TabInsertedAt(this, raw_contents, index, active);
if (active) {
ui::ListSelectionModel new_model = selection_model_;
new_model.SetSelectedIndex(index);
......@@ -370,20 +367,12 @@ std::unique_ptr<content::WebContents> TabStripModel::ReplaceWebContentsAt(
std::unique_ptr<WebContents> old_contents =
contents_data_[index]->ReplaceWebContents(std::move(new_contents));
for (auto& observer : observers_)
observer.TabReplacedAt(this, old_contents.get(), raw_new_contents, index);
// When the active WebContents is replaced send out a selection notification
// too. We do this as nearly all observers need to treat a replacement of the
// selected contents as the selection changing.
if (active_index() == index) {
selection.new_contents = raw_new_contents;
selection.reason = TabStripModelObserver::CHANGE_REASON_REPLACED;
for (auto& observer : observers_) {
observer.ActiveTabChanged(selection.old_contents, selection.new_contents,
index,
TabStripModelObserver::CHANGE_REASON_REPLACED);
}
}
TabStripModelChange change(TabStripModelChange::kReplaced,
......@@ -479,24 +468,6 @@ void TabStripModel::SendDetachWebContentsNotifications(
dwc2->index_before_any_removals;
});
for (auto& dwc : notifications->detached_web_contents) {
// TabClosingAt() must be sent before TabDetachedAt(), since some observers
// use the former to change the behavior of the latter.
// TODO(erikchen): Combine these notifications. https://crbug.com/842194.
if (notifications->will_delete) {
for (auto& observer : observers_) {
observer.TabClosingAt(this, dwc->contents.get(),
dwc->index_before_any_removals);
}
}
// TabDetachedAt() allows observers that keep their own model of
// |contents_data_| to keep that model in sync.
for (auto& observer : observers_) {
observer.TabDetachedAt(
dwc->contents.get(), dwc->index_before_any_removals,
notifications->initially_active_web_contents == dwc->contents.get());
}
deltas.push_back(TabStripModelChange::CreateRemoveDelta(
dwc->contents.get(), dwc->index_before_any_removals,
notifications->will_delete));
......@@ -521,12 +492,8 @@ void TabStripModel::SendDetachWebContentsNotifications(
if (notifications->initially_active_web_contents &&
dwc->contents.get() == notifications->initially_active_web_contents) {
for (auto& observer : observers_)
observer.TabDeactivated(notifications->initially_active_web_contents);
if (!empty()) {
NotifyIfActiveTabChanged(selection);
}
if (!empty())
InstallRenderWigetVisibilityTracker(selection);
notifications->initially_active_web_contents = nullptr;
}
......@@ -537,11 +504,6 @@ void TabStripModel::SendDetachWebContentsNotifications(
}
}
if (!empty() && was_any_tab_selected) {
for (auto& observer : observers_)
observer.TabSelectionChanged(this, notifications->selection_model);
}
if (empty()) {
for (auto& observer : observers_)
observer.TabStripEmpty();
......@@ -1397,7 +1359,7 @@ WebContents* TabStripModel::GetWebContentsAtImpl(int index) const {
return contents_data_[index]->web_contents();
}
void TabStripModel::NotifyIfActiveTabChanged(
void TabStripModel::InstallRenderWigetVisibilityTracker(
const TabStripSelectionChange& selection) {
if (!selection.active_tab_changed())
return;
......@@ -1409,21 +1371,6 @@ void TabStripModel::NotifyIfActiveTabChanged(
->GetRenderWidgetHost();
}
RenderWidgetHostVisibilityTracker tracker(track_host);
for (auto& observer : observers_) {
observer.ActiveTabChanged(selection.old_contents, selection.new_contents,
active_index(), selection.reason);
}
}
void TabStripModel::NotifyIfActiveOrSelectionChanged(
const TabStripSelectionChange& selection) {
NotifyIfActiveTabChanged(selection);
if (selection.selection_changed()) {
for (auto& observer : observers_)
observer.TabSelectionChanged(this, selection.old_model);
}
}
TabStripSelectionChange TabStripModel::SetSelection(
......@@ -1436,19 +1383,13 @@ TabStripSelectionChange TabStripModel::SetSelection(
selection.new_model = new_model;
selection.reason = reason;
if (selection.old_contents &&
selection.old_model.active() != selection.new_model.active()) {
for (auto& observer : observers_)
observer.TabDeactivated(selection.old_contents);
}
// This is done after notifying TabDeactivated() because caller can assume
// that TabStripModel::active_index() would return the index for
// |selection.old_contents|.
selection_model_ = new_model;
selection.new_contents = GetActiveWebContents();
NotifyIfActiveOrSelectionChanged(selection);
InstallRenderWigetVisibilityTracker(selection);
if (!triggered_by_other_operation &&
(selection.active_tab_changed() || selection.selection_changed())) {
......@@ -1487,15 +1428,10 @@ void TabStripModel::MoveWebContentsAtImpl(int index,
std::move(moved_data));
selection_model_.Move(index, to_position, 1);
if (!selection_model_.IsSelected(to_position) && select_after_move) {
// TODO(sky): why doesn't this code notify observers?
if (!selection_model_.IsSelected(to_position) && select_after_move)
selection_model_.SetSelectedIndex(to_position);
}
selection.new_model = selection_model_;
for (auto& observer : observers_)
observer.TabMoved(web_contents, index, to_position);
TabStripModelChange change(
TabStripModelChange::kMoved,
TabStripModelChange::CreateMoveDelta(web_contents, index, to_position));
......
......@@ -481,14 +481,8 @@ class TabStripModel {
std::vector<content::WebContents*> GetWebContentsesByIndices(
const std::vector<int>& indices);
// Notifies the observers if the active tab has changed.
void NotifyIfActiveTabChanged(const TabStripSelectionChange& selection);
// Notifies the observers if the active tab or the tab selection has changed.
// |old_model| is a snapshot of |selection_model_| before the change.
// Note: This function might end up sending 0 to 2 notifications in the
// following order: ActiveTabChanged, TabSelectionChanged.
void NotifyIfActiveOrSelectionChanged(
// Intalls RenderWidgetVisibilityTracker when the active tab has changed.
void InstallRenderWigetVisibilityTracker(
const TabStripSelectionChange& selection);
// Sets the selection to |new_model| and notifies any observers.
......
......@@ -78,51 +78,11 @@ void TabStripModelObserver::OnTabStripModelChanged(
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {}
void TabStripModelObserver::TabInsertedAt(TabStripModel* tab_strip_model,
WebContents* contents,
int index,
bool foreground) {
}
void TabStripModelObserver::TabClosingAt(TabStripModel* tab_strip_model,
WebContents* contents,
int index) {
}
void TabStripModelObserver::TabDetachedAt(WebContents* contents,
int index,
bool was_active) {}
void TabStripModelObserver::TabDeactivated(WebContents* contents) {
}
void TabStripModelObserver::ActiveTabChanged(WebContents* old_contents,
WebContents* new_contents,
int index,
int reason) {
}
void TabStripModelObserver::TabSelectionChanged(
TabStripModel* tab_strip_model,
const ui::ListSelectionModel& model) {
}
void TabStripModelObserver::TabMoved(WebContents* contents,
int from_index,
int to_index) {
}
void TabStripModelObserver::TabChangedAt(WebContents* contents,
int index,
TabChangeType change_type) {
}
void TabStripModelObserver::TabReplacedAt(TabStripModel* tab_strip_model,
WebContents* old_contents,
WebContents* new_contents,
int index) {
}
void TabStripModelObserver::TabPinnedStateChanged(
TabStripModel* tab_strip_model,
WebContents* contents,
......
......@@ -177,81 +177,6 @@ class TabStripModelObserver {
const TabStripModelChange& change,
const TabStripSelectionChange& selection);
// A new WebContents was inserted into the TabStripModel at the
// specified index. |foreground| is whether or not it was opened in the
// foreground (selected).
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground);
// The specified WebContents at |index| is being closed (and eventually
// destroyed). |tab_strip_model| is the TabStripModel that contained the tab.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(erikchen): |index| is not used outside of tests. Do not use it. It
// will be removed soon. https://crbug.com/842194.
virtual void TabClosingAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index);
// The specified WebContents at |previous_index| has been detached, perhaps to
// be inserted in another TabStripModel. The implementer should take whatever
// action is necessary to deal with the WebContents no longer being present.
// |previous_index| cannot be used to index into the current state of the
// TabStripModel.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabDetachedAt(content::WebContents* contents,
int previous_index,
bool was_active);
// The active WebContents is about to change from |old_contents|.
// This gives observers a chance to prepare for an impending switch before it
// happens.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabDeactivated(content::WebContents* contents);
// Sent when the active tab changes. The previously active tab is identified
// by |old_contents| and the newly active tab by |new_contents|. |index| is
// the index of |new_contents|. If |reason| has CHANGE_REASON_REPLACED set
// then the web contents was replaced (see TabChangedAt). If |reason| has
// CHANGE_REASON_USER_GESTURE set then the web contents was changed due to a
// user input event (e.g. clicking on a tab, keystroke).
// Note: It is possible for the selection to change while the active tab
// remains unchanged. For example, control-click may not change the active tab
// but does change the selection. In this case |ActiveTabChanged| is not sent.
// If you care about any changes to the selection, override
// TabSelectionChanged.
// Note: |old_contents| will be NULL if there was no contents previously
// active.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason);
// Sent when the selection changes in |tab_strip_model|. More precisely when
// selected tabs, anchor tab or active tab change. |old_model| is a snapshot
// of the selection model before the change. See also ActiveTabChanged for
// details.
// TODO(erikchen): |old_model| is not used outside of tests. Do not use it. It
// will be removed soon. https://crbug.com/842194.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabSelectionChanged(TabStripModel* tab_strip_model,
const ui::ListSelectionModel& old_model);
// The specified WebContents at |from_index| was moved to |to_index|.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabMoved(content::WebContents* contents,
int from_index,
int to_index);
// The specified WebContents at |index| changed in some way. |contents|
// may be an entirely different object and the old value is no longer
// available by the time this message is delivered.
......@@ -261,15 +186,6 @@ class TabStripModelObserver {
int index,
TabChangeType change_type);
// The WebContents was replaced at the specified index. This is invoked when
// prerendering swaps in a prerendered WebContents.
// DEPRECATED, use OnTabStripChanged() above.
// TODO(crbug.com/842194): Delete this and migrate callsites.
virtual void TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index);
// Invoked when the pinned state of a tab changes.
virtual void TabPinnedStateChanged(TabStripModel* tab_strip_model,
content::WebContents* contents,
......
......@@ -440,53 +440,44 @@ void TopControlsSlideControllerChromeOS::OnTabletModeToggled(
OnEnabledStateChanged(CanEnable(base::nullopt));
}
void TopControlsSlideControllerChromeOS::TabInsertedAt(
void TopControlsSlideControllerChromeOS::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) {
DCHECK(contents);
observed_tabs_.emplace(
contents, std::make_unique<TopControlsSlideTabObserver>(contents, this));
}
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (change.type() == TabStripModelChange::kInserted) {
for (const auto& delta : change.deltas()) {
content::WebContents* contents = delta.insert.contents;
observed_tabs_.emplace(
contents,
std::make_unique<TopControlsSlideTabObserver>(contents, this));
}
} else if (change.type() == TabStripModelChange::kRemoved) {
for (const auto& delta : change.deltas())
observed_tabs_.erase(delta.remove.contents);
} else if (change.type() == TabStripModelChange::kReplaced) {
for (const auto& delta : change.deltas()) {
observed_tabs_.erase(delta.replace.old_contents);
DCHECK(!observed_tabs_.count(delta.replace.new_contents));
observed_tabs_.emplace(delta.replace.new_contents,
std::make_unique<TopControlsSlideTabObserver>(
delta.replace.new_contents, this));
}
}
void TopControlsSlideControllerChromeOS::TabDetachedAt(
content::WebContents* contents,
int previous_index,
bool was_active) {
DCHECK(contents);
observed_tabs_.erase(contents);
}
if (tab_strip_model->empty() || !selection.active_tab_changed())
return;
void TopControlsSlideControllerChromeOS::ActiveTabChanged(
content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
DCHECK(new_contents);
DCHECK(observed_tabs_.count(new_contents));
content::WebContents* new_active_contents = selection.new_contents;
DCHECK(observed_tabs_.count(new_active_contents));
DCHECK(!is_gesture_scrolling_in_progress_);
// Restore the newly-activated tab's shown ratio. If this is a newly inserted
// tab, its |shown_ratio_| is 1.0f.
SetShownRatio(new_contents, observed_tabs_[new_contents]->shown_ratio());
UpdateBrowserControlsStateShown(new_contents, true /* animate */);
}
void TopControlsSlideControllerChromeOS::TabReplacedAt(
TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) {
DCHECK(old_contents);
DCHECK(new_contents);
observed_tabs_.erase(old_contents);
DCHECK(!observed_tabs_.count(new_contents));
observed_tabs_.emplace(
new_contents,
std::make_unique<TopControlsSlideTabObserver>(new_contents, this));
SetShownRatio(new_active_contents,
observed_tabs_[new_active_contents]->shown_ratio());
UpdateBrowserControlsStateShown(new_active_contents, true /* animate */);
}
void TopControlsSlideControllerChromeOS::SetTabNeedsAttentionAt(
......
......@@ -59,23 +59,10 @@ class TopControlsSlideControllerChromeOS
void OnTabletModeToggled(bool tablet_mode_enabled) override;
// TabStripModelObserver:
// TODO(afakhry): The below overrides are deprecated, but we have to keep
// using them until Browser and BrowserView are migrated to the new API.
void TabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool foreground) override;
void TabDetachedAt(content::WebContents* contents,
int previous_index,
bool was_active) override;
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
void TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) override;
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void SetTabNeedsAttentionAt(int index, bool attention) override;
// content::NotificationObserver:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment