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

Unified Diff: chrome/browser/extensions/browser_event_router.cc

Issue 11607012: Add tabs.onReplaced event to notify listeners of tabs being swapped due to prerendering or instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some other stuff in tabs.json. Created 7 years, 12 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
Index: chrome/browser/extensions/browser_event_router.cc
diff --git a/chrome/browser/extensions/browser_event_router.cc b/chrome/browser/extensions/browser_event_router.cc
index 5947c58687ac048ea50c8758ca34ec387f7a854c..7b38ef9d15ff2051d646613892928bc518310c53 100644
--- a/chrome/browser/extensions/browser_event_router.cc
+++ b/chrome/browser/extensions/browser_event_router.cc
@@ -471,8 +471,28 @@ void BrowserEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
WebContents* old_contents,
WebContents* new_contents,
int index) {
- TabClosingAt(tab_strip_model, old_contents, index);
- TabInsertedAt(new_contents, index, tab_strip_model->active_index() == 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);
+ scoped_ptr<ListValue> args(new ListValue());
+ args->Append(Value::CreateIntegerValue(new_tab_id));
+ args->Append(Value::CreateIntegerValue(old_tab_id));
+
+ DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()),
+ events::kOnTabReplaced,
+ args.Pass(),
+ EventRouter::USER_GESTURE_UNKNOWN);
+
+ // Update tab_entries_.
+ const int removed_count = tab_entries_.erase(old_tab_id);
+ DCHECK_GT(removed_count, 0);
+ UnregisterForTabNotifications(old_contents);
+
+ if (!GetTabEntry(new_contents)) {
+ tab_entries_[new_tab_id] = TabEntry();
+ RegisterForTabNotifications(new_contents);
+ }
}
void BrowserEventRouter::TabPinnedStateChanged(WebContents* contents,
« no previous file with comments | « no previous file | chrome/browser/extensions/event_names.h » ('j') | chrome/browser/prerender/prerender_browsertest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698