Commit a60a2e6a authored by sangwoo.ko's avatar sangwoo.ko Committed by Commit Bot

Use TabStripModelObserver's new API in chrome/browser/extensions

Replace old API with new API. In order to do this, changed
the API a little bit.

* Notify before deleting web conents when tabs are closed.
* Pass TabStripModel* in OnTabStripModelChanged().

This CL has no intended behavior change. Reordered methods
definitions so that they match with declarartion order.

Change-Id: I704cfb3418d06a7539096307aefab916338c65e9
Bug: 842194
Reviewed-on: https://chromium-review.googlesource.com/1171963
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582840}
parent cbfffdd5
...@@ -16,6 +16,7 @@ DevToolsAutoOpener::~DevToolsAutoOpener() { ...@@ -16,6 +16,7 @@ DevToolsAutoOpener::~DevToolsAutoOpener() {
} }
void DevToolsAutoOpener::OnTabStripModelChanged( void DevToolsAutoOpener::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) { const TabStripSelectionChange& selection) {
if (change.type() != TabStripModelChange::kInserted) if (change.type() != TabStripModelChange::kInserted)
......
...@@ -16,6 +16,7 @@ class DevToolsAutoOpener : public TabStripModelObserver { ...@@ -16,6 +16,7 @@ class DevToolsAutoOpener : public TabStripModelObserver {
private: private:
// TabStripModelObserver overrides. // TabStripModelObserver overrides.
void OnTabStripModelChanged( void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) override; const TabStripSelectionChange& selection) override;
......
...@@ -178,6 +178,7 @@ GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { ...@@ -178,6 +178,7 @@ GlobalConfirmInfoBar::~GlobalConfirmInfoBar() {
} }
void GlobalConfirmInfoBar::OnTabStripModelChanged( void GlobalConfirmInfoBar::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) { const TabStripSelectionChange& selection) {
if (change.type() != TabStripModelChange::kInserted) if (change.type() != TabStripModelChange::kInserted)
......
...@@ -44,6 +44,7 @@ class GlobalConfirmInfoBar : public TabStripModelObserver, ...@@ -44,6 +44,7 @@ class GlobalConfirmInfoBar : public TabStripModelObserver,
// TabStripModelObserver: // TabStripModelObserver:
void OnTabStripModelChanged( void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) override; const TabStripSelectionChange& selection) override;
void TabChangedAt(content::WebContents* web_contents, void TabChangedAt(content::WebContents* web_contents,
......
...@@ -63,6 +63,23 @@ bool WillDispatchTabUpdatedEvent( ...@@ -63,6 +63,23 @@ bool WillDispatchTabUpdatedEvent(
return true; return true;
} }
bool WillDispatchTabCreatedEvent(WebContents* contents,
bool active,
content::BrowserContext* context,
const Extension* extension,
Event* event,
const base::DictionaryValue* listener_filter) {
event->event_args->Clear();
std::unique_ptr<base::DictionaryValue> tab_value =
ExtensionTabUtil::CreateTabObject(contents, ExtensionTabUtil::kScrubTab,
extension)
->ToValue();
tab_value->SetBoolean(tabs_constants::kSelectedKey, active);
tab_value->SetBoolean(tabs_constants::kActiveKey, active);
event->event_args->Append(std::move(tab_value));
return true;
}
} // namespace } // namespace
TabsEventRouter::TabEntry::TabEntry(TabsEventRouter* router, TabsEventRouter::TabEntry::TabEntry(TabsEventRouter* router,
...@@ -155,71 +172,140 @@ bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) { ...@@ -155,71 +172,140 @@ bool TabsEventRouter::ShouldTrackBrowser(Browser* browser) {
ExtensionTabUtil::BrowserSupportsTabs(browser); ExtensionTabUtil::BrowserSupportsTabs(browser);
} }
void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) { void TabsEventRouter::OnBrowserSetLastActive(Browser* browser) {
favicon_scoped_observer_.Add( TabsWindowsAPI* tabs_window_api = TabsWindowsAPI::Get(profile_);
favicon::ContentFaviconDriver::FromWebContents(contents)); if (tabs_window_api) {
tabs_window_api->windows_event_router()->OnActiveWindowChanged(
browser ? browser->extension_window_controller() : NULL);
}
}
ZoomController::FromWebContents(contents)->AddObserver(this); void TabsEventRouter::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
switch (change.type()) {
case TabStripModelChange::kInserted: {
for (const auto& delta : change.deltas()) {
DispatchTabInsertedAt(tab_strip_model, delta.insert.contents,
delta.insert.index,
selection.new_contents == delta.insert.contents);
}
break;
}
case TabStripModelChange::kRemoved: {
for (const auto& delta : change.deltas()) {
if (delta.remove.will_be_deleted)
DispatchTabClosingAt(tab_strip_model, delta.remove.contents,
delta.remove.index);
DispatchTabDetachedAt(delta.remove.contents, delta.remove.index,
selection.old_contents == delta.remove.contents);
}
break;
}
case TabStripModelChange::kMoved: {
for (const auto& delta : change.deltas()) {
DispatchTabMoved(delta.move.contents, delta.move.from_index,
delta.move.to_index);
}
break;
}
case TabStripModelChange::kReplaced: {
for (const auto& delta : change.deltas()) {
DispatchTabReplacedAt(delta.replace.old_contents,
delta.replace.new_contents, delta.replace.index);
}
break;
}
case TabStripModelChange::kSelectionOnly:
break;
}
int tab_id = ExtensionTabUtil::GetTabId(contents); if (tab_strip_model->empty())
DCHECK(tab_entries_.find(tab_id) == tab_entries_.end()); return;
tab_entries_[tab_id] = std::make_unique<TabEntry>(this, contents);
if (selection.active_tab_changed()) {
DispatchActiveTabChanged(selection.old_contents, selection.new_contents,
selection.new_model.active(), selection.reason);
}
if (selection.selection_changed()) {
DispatchTabSelectionChanged(tab_strip_model, selection.old_model);
}
} }
void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) { void TabsEventRouter::TabChangedAt(WebContents* contents,
favicon_scoped_observer_.Remove( int index,
favicon::ContentFaviconDriver::FromWebContents(contents)); TabChangeType change_type) {
TabEntry* entry = GetTabEntry(contents);
// TabClosingAt() may have already removed the entry for |contents| even
// though the tab has not yet been detached.
if (entry)
TabUpdated(entry, entry->UpdateLoadState());
}
ZoomController::FromWebContents(contents)->RemoveObserver(this); void TabsEventRouter::TabPinnedStateChanged(TabStripModel* tab_strip_model,
WebContents* contents,
int index) {
std::set<std::string> changed_property_names;
changed_property_names.insert(tabs_constants::kPinnedKey);
DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
}
int tab_id = ExtensionTabUtil::GetTabId(contents); void TabsEventRouter::OnZoomChanged(
int removed_count = tab_entries_.erase(tab_id); const ZoomController::ZoomChangedEventData& data) {
DCHECK_GT(removed_count, 0); DCHECK(data.web_contents);
int tab_id = ExtensionTabUtil::GetTabId(data.web_contents);
if (tab_id < 0)
return;
// Prepare the zoom change information.
api::tabs::OnZoomChange::ZoomChangeInfo zoom_change_info;
zoom_change_info.tab_id = tab_id;
zoom_change_info.old_zoom_factor =
content::ZoomLevelToZoomFactor(data.old_zoom_level);
zoom_change_info.new_zoom_factor =
content::ZoomLevelToZoomFactor(data.new_zoom_level);
ZoomModeToZoomSettings(data.zoom_mode, &zoom_change_info.zoom_settings);
// Dispatch the |onZoomChange| event.
Profile* profile =
Profile::FromBrowserContext(data.web_contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_ZOOM_CHANGE,
api::tabs::OnZoomChange::kEventName,
api::tabs::OnZoomChange::Create(zoom_change_info),
EventRouter::USER_GESTURE_UNKNOWN);
} }
void TabsEventRouter::OnBrowserSetLastActive(Browser* browser) { void TabsEventRouter::OnFaviconUpdated(
TabsWindowsAPI* tabs_window_api = TabsWindowsAPI::Get(profile_); favicon::FaviconDriver* favicon_driver,
if (tabs_window_api) { NotificationIconType notification_icon_type,
tabs_window_api->windows_event_router()->OnActiveWindowChanged( const GURL& icon_url,
browser ? browser->extension_window_controller() : NULL); bool icon_url_changed,
const gfx::Image& image) {
if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) {
favicon::ContentFaviconDriver* content_favicon_driver =
static_cast<favicon::ContentFaviconDriver*>(favicon_driver);
FaviconUrlUpdated(content_favicon_driver->web_contents());
} }
} }
static bool WillDispatchTabCreatedEvent( void TabsEventRouter::OnDiscardedStateChange(WebContents* contents,
WebContents* contents, bool is_discarded) {
bool active, std::set<std::string> changed_property_names;
content::BrowserContext* context, changed_property_names.insert(tabs_constants::kDiscardedKey);
const Extension* extension, DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
Event* event,
const base::DictionaryValue* listener_filter) {
event->event_args->Clear();
std::unique_ptr<base::DictionaryValue> tab_value =
ExtensionTabUtil::CreateTabObject(contents, ExtensionTabUtil::kScrubTab,
extension)
->ToValue();
tab_value->SetBoolean(tabs_constants::kSelectedKey, active);
tab_value->SetBoolean(tabs_constants::kActiveKey, active);
event->event_args->Append(std::move(tab_value));
return true;
} }
void TabsEventRouter::TabCreatedAt(WebContents* contents, void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents,
int index, bool is_auto_discardable) {
bool active) { std::set<std::string> changed_property_names;
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); changed_property_names.insert(tabs_constants::kAutoDiscardableKey);
std::unique_ptr<base::ListValue> args(new base::ListValue); DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
auto event = std::make_unique<Event>(events::TABS_ON_CREATED,
api::tabs::OnCreated::kEventName,
std::move(args), profile);
event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
event->will_dispatch_callback =
base::Bind(&WillDispatchTabCreatedEvent, contents, active);
EventRouter::Get(profile)->BroadcastEvent(std::move(event));
RegisterForTabNotifications(contents);
} }
void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model, void TabsEventRouter::DispatchTabInsertedAt(TabStripModel* tab_strip_model,
WebContents* contents, WebContents* contents,
int index, int index,
bool active) { bool active) {
...@@ -252,7 +338,31 @@ void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model, ...@@ -252,7 +338,31 @@ void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model,
EventRouter::USER_GESTURE_UNKNOWN); EventRouter::USER_GESTURE_UNKNOWN);
} }
void TabsEventRouter::TabDetachedAt(WebContents* contents, void TabsEventRouter::DispatchTabClosingAt(TabStripModel* tab_strip_model,
WebContents* contents,
int index) {
int tab_id = ExtensionTabUtil::GetTabId(contents);
std::unique_ptr<base::ListValue> args(new base::ListValue);
args->AppendInteger(tab_id);
std::unique_ptr<base::DictionaryValue> object_args(
new base::DictionaryValue());
object_args->SetInteger(tabs_constants::kWindowIdKey,
ExtensionTabUtil::GetWindowIdOfTab(contents));
object_args->SetBoolean(tabs_constants::kWindowClosing,
tab_strip_model->closing_all());
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_REMOVED,
api::tabs::OnRemoved::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(contents);
}
void TabsEventRouter::DispatchTabDetachedAt(WebContents* contents,
int index, int index,
bool was_active) { bool was_active) {
if (!GetTabEntry(contents)) { if (!GetTabEntry(contents)) {
...@@ -278,31 +388,7 @@ void TabsEventRouter::TabDetachedAt(WebContents* contents, ...@@ -278,31 +388,7 @@ void TabsEventRouter::TabDetachedAt(WebContents* contents,
EventRouter::USER_GESTURE_UNKNOWN); EventRouter::USER_GESTURE_UNKNOWN);
} }
void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, void TabsEventRouter::DispatchActiveTabChanged(WebContents* old_contents,
WebContents* contents,
int index) {
int tab_id = ExtensionTabUtil::GetTabId(contents);
std::unique_ptr<base::ListValue> args(new base::ListValue);
args->AppendInteger(tab_id);
std::unique_ptr<base::DictionaryValue> object_args(
new base::DictionaryValue());
object_args->SetInteger(tabs_constants::kWindowIdKey,
ExtensionTabUtil::GetWindowIdOfTab(contents));
object_args->SetBoolean(tabs_constants::kWindowClosing,
tab_strip_model->closing_all());
args->Append(std::move(object_args));
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_REMOVED,
api::tabs::OnRemoved::kEventName, std::move(args),
EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(contents);
}
void TabsEventRouter::ActiveTabChanged(WebContents* old_contents,
WebContents* new_contents, WebContents* new_contents,
int index, int index,
int reason) { int reason) {
...@@ -340,7 +426,7 @@ void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, ...@@ -340,7 +426,7 @@ void TabsEventRouter::ActiveTabChanged(WebContents* old_contents,
std::move(on_activated_args), gesture); std::move(on_activated_args), gesture);
} }
void TabsEventRouter::TabSelectionChanged( void TabsEventRouter::DispatchTabSelectionChanged(
TabStripModel* tab_strip_model, TabStripModel* tab_strip_model,
const ui::ListSelectionModel& old_model) { const ui::ListSelectionModel& old_model) {
ui::ListSelectionModel::SelectedIndices new_selection = ui::ListSelectionModel::SelectedIndices new_selection =
...@@ -378,7 +464,7 @@ void TabsEventRouter::TabSelectionChanged( ...@@ -378,7 +464,7 @@ void TabsEventRouter::TabSelectionChanged(
EventRouter::USER_GESTURE_UNKNOWN); EventRouter::USER_GESTURE_UNKNOWN);
} }
void TabsEventRouter::TabMoved(WebContents* contents, void TabsEventRouter::DispatchTabMoved(WebContents* contents,
int from_index, int from_index,
int to_index) { int to_index) {
std::unique_ptr<base::ListValue> args(new base::ListValue); std::unique_ptr<base::ListValue> args(new base::ListValue);
...@@ -400,6 +486,43 @@ void TabsEventRouter::TabMoved(WebContents* contents, ...@@ -400,6 +486,43 @@ void TabsEventRouter::TabMoved(WebContents* contents,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN); std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
} }
void TabsEventRouter::DispatchTabReplacedAt(WebContents* old_contents,
WebContents* new_contents,
int index) {
// Notify listeners that the next tabs closing or being added are due to
// WebContents being swapped.
const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents);
const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents);
std::unique_ptr<base::ListValue> args(new base::ListValue);
args->AppendInteger(new_tab_id);
args->AppendInteger(old_tab_id);
DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()),
events::TABS_ON_REPLACED, api::tabs::OnReplaced::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(old_contents);
if (!GetTabEntry(new_contents))
RegisterForTabNotifications(new_contents);
}
void TabsEventRouter::TabCreatedAt(WebContents* contents,
int index,
bool active) {
Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
std::unique_ptr<base::ListValue> args(new base::ListValue);
auto event = std::make_unique<Event>(events::TABS_ON_CREATED,
api::tabs::OnCreated::kEventName,
std::move(args), profile);
event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
event->will_dispatch_callback =
base::Bind(&WillDispatchTabCreatedEvent, contents, active);
EventRouter::Get(profile)->BroadcastEvent(std::move(event));
RegisterForTabNotifications(contents);
}
void TabsEventRouter::TabUpdated(TabEntry* entry, void TabsEventRouter::TabUpdated(TabEntry* entry,
std::set<std::string> changed_property_names) { std::set<std::string> changed_property_names) {
auto* audible_helper = auto* audible_helper =
...@@ -476,103 +599,32 @@ void TabsEventRouter::DispatchTabUpdatedEvent( ...@@ -476,103 +599,32 @@ void TabsEventRouter::DispatchTabUpdatedEvent(
EventRouter::Get(profile)->BroadcastEvent(std::move(event)); EventRouter::Get(profile)->BroadcastEvent(std::move(event));
} }
TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) {
const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); favicon_scoped_observer_.Add(
favicon::ContentFaviconDriver::FromWebContents(contents));
return it == tab_entries_.end() ? nullptr : it->second.get();
}
void TabsEventRouter::TabChangedAt(WebContents* contents,
int index,
TabChangeType change_type) {
TabEntry* entry = GetTabEntry(contents);
// TabClosingAt() may have already removed the entry for |contents| even
// though the tab has not yet been detached.
if (entry)
TabUpdated(entry, entry->UpdateLoadState());
}
void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
WebContents* old_contents,
WebContents* new_contents,
int index) {
// Notify listeners that the next tabs closing or being added are due to
// WebContents being swapped.
const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents);
const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents);
std::unique_ptr<base::ListValue> args(new base::ListValue);
args->AppendInteger(new_tab_id);
args->AppendInteger(old_tab_id);
DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()),
events::TABS_ON_REPLACED, api::tabs::OnReplaced::kEventName,
std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
UnregisterForTabNotifications(old_contents);
if (!GetTabEntry(new_contents)) ZoomController::FromWebContents(contents)->AddObserver(this);
RegisterForTabNotifications(new_contents);
}
void TabsEventRouter::TabPinnedStateChanged(TabStripModel* tab_strip_model, int tab_id = ExtensionTabUtil::GetTabId(contents);
WebContents* contents, DCHECK(tab_entries_.find(tab_id) == tab_entries_.end());
int index) { tab_entries_[tab_id] = std::make_unique<TabEntry>(this, contents);
std::set<std::string> changed_property_names;
changed_property_names.insert(tabs_constants::kPinnedKey);
DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
} }
void TabsEventRouter::OnZoomChanged( void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
const ZoomController::ZoomChangedEventData& data) { favicon_scoped_observer_.Remove(
DCHECK(data.web_contents); favicon::ContentFaviconDriver::FromWebContents(contents));
int tab_id = ExtensionTabUtil::GetTabId(data.web_contents);
if (tab_id < 0)
return;
// Prepare the zoom change information.
api::tabs::OnZoomChange::ZoomChangeInfo zoom_change_info;
zoom_change_info.tab_id = tab_id;
zoom_change_info.old_zoom_factor =
content::ZoomLevelToZoomFactor(data.old_zoom_level);
zoom_change_info.new_zoom_factor =
content::ZoomLevelToZoomFactor(data.new_zoom_level);
ZoomModeToZoomSettings(data.zoom_mode,
&zoom_change_info.zoom_settings);
// Dispatch the |onZoomChange| event. ZoomController::FromWebContents(contents)->RemoveObserver(this);
Profile* profile = Profile::FromBrowserContext(
data.web_contents->GetBrowserContext());
DispatchEvent(profile, events::TABS_ON_ZOOM_CHANGE,
api::tabs::OnZoomChange::kEventName,
api::tabs::OnZoomChange::Create(zoom_change_info),
EventRouter::USER_GESTURE_UNKNOWN);
}
void TabsEventRouter::OnFaviconUpdated( int tab_id = ExtensionTabUtil::GetTabId(contents);
favicon::FaviconDriver* favicon_driver, int removed_count = tab_entries_.erase(tab_id);
NotificationIconType notification_icon_type, DCHECK_GT(removed_count, 0);
const GURL& icon_url,
bool icon_url_changed,
const gfx::Image& image) {
if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) {
favicon::ContentFaviconDriver* content_favicon_driver =
static_cast<favicon::ContentFaviconDriver*>(favicon_driver);
FaviconUrlUpdated(content_favicon_driver->web_contents());
}
} }
void TabsEventRouter::OnDiscardedStateChange(WebContents* contents, TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) {
bool is_discarded) { const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents));
std::set<std::string> changed_property_names;
changed_property_names.insert(tabs_constants::kDiscardedKey);
DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
}
void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents, return it == tab_entries_.end() ? nullptr : it->second.get();
bool is_auto_discardable) {
std::set<std::string> changed_property_names;
changed_property_names.insert(tabs_constants::kAutoDiscardableKey);
DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
} }
} // namespace extensions } // namespace extensions
...@@ -54,32 +54,14 @@ class TabsEventRouter : public TabStripModelObserver, ...@@ -54,32 +54,14 @@ class TabsEventRouter : public TabStripModelObserver,
void OnBrowserSetLastActive(Browser* browser) override; void OnBrowserSetLastActive(Browser* browser) override;
// TabStripModelObserver: // TabStripModelObserver:
void TabInsertedAt(TabStripModel* tab_strip_model, void OnTabStripModelChanged(
content::WebContents* contents, TabStripModel* tab_strip_model,
int index, const TabStripModelChange& change,
bool active) override; const TabStripSelectionChange& selection) override;
void TabClosingAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index) override;
void TabDetachedAt(content::WebContents* contents,
int index,
bool was_active) override;
void ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) override;
void TabSelectionChanged(TabStripModel* tab_strip_model,
const ui::ListSelectionModel& old_model) override;
void TabMoved(content::WebContents* contents,
int from_index,
int to_index) override;
void TabChangedAt(content::WebContents* contents, void TabChangedAt(content::WebContents* contents,
int index, int index,
TabChangeType change_type) override; TabChangeType change_type) override;
void TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) override;
void TabPinnedStateChanged(TabStripModel* tab_strip_model, void TabPinnedStateChanged(TabStripModel* tab_strip_model,
content::WebContents* contents, content::WebContents* contents,
int index) override; int index) override;
...@@ -102,7 +84,32 @@ class TabsEventRouter : public TabStripModelObserver, ...@@ -102,7 +84,32 @@ class TabsEventRouter : public TabStripModelObserver,
bool is_auto_discardable) override; bool is_auto_discardable) override;
private: private:
// "Synthetic" event. Called from TabInsertedAt if new tab is detected. // Methods called from OnTabStripModelChanged.
void DispatchTabInsertedAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index,
bool active);
void DispatchTabClosingAt(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index);
void DispatchTabDetachedAt(content::WebContents* contents,
int index,
bool was_active);
void DispatchActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason);
void DispatchTabSelectionChanged(TabStripModel* tab_strip_model,
const ui::ListSelectionModel& old_model);
void DispatchTabMoved(content::WebContents* contents,
int from_index,
int to_index);
void DispatchTabReplacedAt(content::WebContents* old_contents,
content::WebContents* new_contents,
int index);
// "Synthetic" event. Called from DispatchTabInsertedAt if new tab is
// detected.
void TabCreatedAt(content::WebContents* contents, int index, bool active); void TabCreatedAt(content::WebContents* contents, int index, bool active);
// Internal processing of tab updated events. Intended to be called when // Internal processing of tab updated events. Intended to be called when
...@@ -123,12 +130,6 @@ class TabsEventRouter : public TabStripModelObserver, ...@@ -123,12 +130,6 @@ class TabsEventRouter : public TabStripModelObserver,
std::unique_ptr<base::ListValue> args, std::unique_ptr<base::ListValue> args,
EventRouter::UserGestureState user_gesture); EventRouter::UserGestureState user_gesture);
void DispatchEventsAcrossIncognito(
Profile* profile,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args,
std::unique_ptr<base::ListValue> cross_incognito_args);
// Packages |changed_property_names| as a tab updated event for the tab // Packages |changed_property_names| as a tab updated event for the tab
// |contents| and dispatches the event to the extension. // |contents| and dispatches the event to the extension.
void DispatchTabUpdatedEvent( void DispatchTabUpdatedEvent(
......
...@@ -83,7 +83,8 @@ void BrowserTabStripTracker::MaybeTrackBrowser(Browser* browser) { ...@@ -83,7 +83,8 @@ void BrowserTabStripTracker::MaybeTrackBrowser(Browser* browser) {
TabStripModelChange change(TabStripModelChange::kInserted, deltas); TabStripModelChange change(TabStripModelChange::kInserted, deltas);
TabStripSelectionChange selection(tab_strip_model->GetActiveWebContents(), TabStripSelectionChange selection(tab_strip_model->GetActiveWebContents(),
tab_strip_model->selection_model()); tab_strip_model->selection_model());
tab_strip_model_observer_->OnTabStripModelChanged(change, selection); tab_strip_model_observer_->OnTabStripModelChanged(tab_strip_model, change,
selection);
} }
void BrowserTabStripTracker::OnBrowserAdded(Browser* browser) { void BrowserTabStripTracker::OnBrowserAdded(Browser* browser) {
......
...@@ -358,7 +358,7 @@ void TabStripModel::InsertWebContentsAt(int index, ...@@ -358,7 +358,7 @@ void TabStripModel::InsertWebContentsAt(int index,
TabStripModelChange::kInserted, TabStripModelChange::kInserted,
TabStripModelChange::CreateInsertDelta(raw_contents, index)); TabStripModelChange::CreateInsertDelta(raw_contents, index));
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnTabStripModelChanged(change, selection); observer.OnTabStripModelChanged(this, change, selection);
} }
std::unique_ptr<content::WebContents> TabStripModel::ReplaceWebContentsAt( std::unique_ptr<content::WebContents> TabStripModel::ReplaceWebContentsAt(
...@@ -395,7 +395,7 @@ std::unique_ptr<content::WebContents> TabStripModel::ReplaceWebContentsAt( ...@@ -395,7 +395,7 @@ std::unique_ptr<content::WebContents> TabStripModel::ReplaceWebContentsAt(
TabStripModelChange::CreateReplaceDelta( TabStripModelChange::CreateReplaceDelta(
old_contents.get(), raw_new_contents, index)); old_contents.get(), raw_new_contents, index));
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnTabStripModelChanged(change, selection); observer.OnTabStripModelChanged(this, change, selection);
return old_contents; return old_contents;
} }
...@@ -514,6 +514,10 @@ void TabStripModel::SendDetachWebContentsNotifications( ...@@ -514,6 +514,10 @@ void TabStripModel::SendDetachWebContentsNotifications(
selection.new_model = selection_model_; selection.new_model = selection_model_;
selection.reason = TabStripModelObserver::CHANGE_REASON_NONE; selection.reason = TabStripModelObserver::CHANGE_REASON_NONE;
TabStripModelChange change(TabStripModelChange::kRemoved, deltas);
for (auto& observer : observers_)
observer.OnTabStripModelChanged(this, change, selection);
for (auto& dwc : notifications->detached_web_contents) { for (auto& dwc : notifications->detached_web_contents) {
if (notifications->selection_model.IsSelected( if (notifications->selection_model.IsSelected(
dwc->index_before_any_removals)) { dwc->index_before_any_removals)) {
...@@ -547,10 +551,6 @@ void TabStripModel::SendDetachWebContentsNotifications( ...@@ -547,10 +551,6 @@ void TabStripModel::SendDetachWebContentsNotifications(
for (auto& observer : observers_) for (auto& observer : observers_)
observer.TabStripEmpty(); observer.TabStripEmpty();
} }
TabStripModelChange change(TabStripModelChange::kRemoved, deltas);
for (auto& observer : observers_)
observer.OnTabStripModelChanged(change, selection);
} }
void TabStripModel::ActivateTabAt(int index, bool user_gesture) { void TabStripModel::ActivateTabAt(int index, bool user_gesture) {
...@@ -1529,7 +1529,7 @@ TabStripSelectionChange TabStripModel::SetSelection( ...@@ -1529,7 +1529,7 @@ TabStripSelectionChange TabStripModel::SetSelection(
(selection.active_tab_changed() || selection.selection_changed())) { (selection.active_tab_changed() || selection.selection_changed())) {
TabStripModelChange change; TabStripModelChange change;
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnTabStripModelChanged(change, selection); observer.OnTabStripModelChanged(this, change, selection);
} }
return selection; return selection;
...@@ -1575,7 +1575,7 @@ void TabStripModel::MoveWebContentsAtImpl(int index, ...@@ -1575,7 +1575,7 @@ void TabStripModel::MoveWebContentsAtImpl(int index,
TabStripModelChange::kMoved, TabStripModelChange::kMoved,
TabStripModelChange::CreateMoveDelta(web_contents, index, to_position)); TabStripModelChange::CreateMoveDelta(web_contents, index, to_position));
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnTabStripModelChanged(change, selection); observer.OnTabStripModelChanged(this, change, selection);
} }
void TabStripModel::MoveSelectedTabsToImpl(int index, void TabStripModel::MoveSelectedTabsToImpl(int index,
......
...@@ -74,6 +74,7 @@ TabStripModelObserver::TabStripModelObserver() { ...@@ -74,6 +74,7 @@ TabStripModelObserver::TabStripModelObserver() {
} }
void TabStripModelObserver::OnTabStripModelChanged( void TabStripModelObserver::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) {} const TabStripSelectionChange& selection) {}
......
...@@ -173,7 +173,8 @@ class TabStripModelObserver { ...@@ -173,7 +173,8 @@ class TabStripModelObserver {
// TabStripModel before the |change| and after the |change| are applied. // TabStripModel before the |change| and after the |change| are applied.
// When only selection/activation was changed without any change about // When only selection/activation was changed without any change about
// WebContents, |change| can be empty. // WebContents, |change| can be empty.
virtual void OnTabStripModelChanged(const TabStripModelChange& change, virtual void OnTabStripModelChanged(TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection); const TabStripSelectionChange& selection);
// A new WebContents was inserted into the TabStripModel at the // A new WebContents was inserted into the TabStripModel at the
......
...@@ -377,6 +377,7 @@ class NewTabStripModelObserver : public MockTabStripModelObserver { ...@@ -377,6 +377,7 @@ class NewTabStripModelObserver : public MockTabStripModelObserver {
// TabStripModelObserver implementation: // TabStripModelObserver implementation:
void OnTabStripModelChanged( void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) override { const TabStripSelectionChange& selection) override {
switch (change.type()) { switch (change.type()) {
......
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