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..9c5e7593b2579d7854c577f4c7486246a717b0dd 100644 |
--- a/chrome/browser/extensions/browser_event_router.cc |
+++ b/chrome/browser/extensions/browser_event_router.cc |
@@ -217,48 +217,28 @@ void BrowserEventRouter::TabInsertedAt(WebContents* contents, |
void BrowserEventRouter::TabDetachedAt(WebContents* contents, int index) { |
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. |
+ if (contents->GetWebContentsDetachedToClose()) { |
+ int tab_id = ExtensionTabUtil::GetTabId(contents); |
+ // TODO BEFORE COMITTING: pass tab_strip_model->closing_all() as last |
+ // parameter. |
+ DispatchTabRemovedAndUnregisterNotifications(contents, tab_id, false); |
+ } 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 +458,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) { |