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

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

Issue 17382005: Unbreak tabs.onRemove extension API in face of fast tab closure Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't modify content Created 7 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
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 d2c8b5de13864b2abdf83a05844bff928db3f5b0..2caecc41af66170f6971bfdbde48216cb9a33ab3 100644
--- a/chrome/browser/extensions/browser_event_router.cc
+++ b/chrome/browser/extensions/browser_event_router.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
@@ -215,50 +216,31 @@ void BrowserEventRouter::TabInsertedAt(WebContents* contents,
EventRouter::USER_GESTURE_UNKNOWN);
}
-void BrowserEventRouter::TabDetachedAt(WebContents* contents, int index) {
+void BrowserEventRouter::TabDetachedAt(WebContents* contents,
+ int index,
+ bool closing_all) {
if (!GetTabEntry(contents)) {
- // The tab was removed. Don't send detach event.
+ // The tab was removed. Don't send detach/remove event.
return;
}
- scoped_ptr<ListValue> args(new ListValue());
- args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
-
- DictionaryValue* object_args = new DictionaryValue();
- object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue(
- ExtensionTabUtil::GetWindowIdOfTab(contents)));
- object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue(
- index));
- args->Append(object_args);
-
- Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
- DispatchEvent(profile, events::kOnTabDetached, args.Pass(),
- EventRouter::USER_GESTURE_UNKNOWN);
+ // If this detach is occuring as part of the process of closing |contents|
+ // then dispatch a remove event rather than a detach event.
+ CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents);
+ if (core_tab_helper->GetWebContentsDetachedToClose()) {
+ int tab_id = ExtensionTabUtil::GetTabId(contents);
+ DispatchTabRemovedAndUnregisterNotifications(contents, tab_id, closing_all);
+ } else {
+ DispatchTabDetached(contents, index);
+ }
}
void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
WebContents* contents,
int index) {
int tab_id = ExtensionTabUtil::GetTabId(contents);
-
- scoped_ptr<ListValue> args(new ListValue());
- args->Append(Value::CreateIntegerValue(tab_id));
-
- DictionaryValue* object_args = new DictionaryValue();
- object_args->SetInteger(tab_keys::kWindowIdKey,
- ExtensionTabUtil::GetWindowIdOfTab(contents));
- object_args->SetBoolean(tab_keys::kWindowClosing,
- tab_strip_model->closing_all());
- args->Append(object_args);
-
- Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
- DispatchEvent(profile, events::kOnTabRemoved, args.Pass(),
- EventRouter::USER_GESTURE_UNKNOWN);
-
- int removed_count = tab_entries_.erase(tab_id);
- DCHECK_GT(removed_count, 0);
-
- UnregisterForTabNotifications(contents);
+ DispatchTabRemovedAndUnregisterNotifications(contents, tab_id,
+ tab_strip_model->closing_all());
}
void BrowserEventRouter::ActiveTabChanged(WebContents* old_contents,
@@ -478,6 +460,44 @@ BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry(
return &i->second;
}
+void BrowserEventRouter::DispatchTabDetached(WebContents* contents,
+ int index) {
+ scoped_ptr<ListValue> args(new ListValue());
+ args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
+
+ DictionaryValue* object_args = new DictionaryValue();
+ object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue(
+ ExtensionTabUtil::GetWindowIdOfTab(contents)));
+ object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue(
+ index));
+ args->Append(object_args);
+
+ Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
+ DispatchEvent(profile, events::kOnTabDetached, args.Pass(),
+ EventRouter::USER_GESTURE_UNKNOWN);
+}
+
+void BrowserEventRouter::DispatchTabRemovedAndUnregisterNotifications(
+ WebContents* contents, int tab_id, bool window_closing) {
+ scoped_ptr<ListValue> args(new ListValue());
+ args->Append(Value::CreateIntegerValue(tab_id));
+
+ DictionaryValue* object_args = new DictionaryValue();
+ object_args->SetInteger(tab_keys::kWindowIdKey,
+ ExtensionTabUtil::GetWindowIdOfTab(contents));
+ object_args->SetBoolean(tab_keys::kWindowClosing,
+ window_closing);
+ args->Append(object_args);
+
+ Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
+ DispatchEvent(profile, events::kOnTabRemoved, args.Pass(),
+ EventRouter::USER_GESTURE_UNKNOWN);
+
+ int removed_count = tab_entries_.erase(tab_id);
+ DCHECK_GT(removed_count, 0);
+ UnregisterForTabNotifications(contents);
+}
+
void BrowserEventRouter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {

Powered by Google App Engine
This is Rietveld 408576698