Skip to content

Commit

Permalink
Consolidate handling unloaded extensions in Browser.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none


Review URL: https://chromiumcodereview.appspot.com/11360258

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169596 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
avi@chromium.org committed Nov 27, 2012
1 parent 260ea45 commit e344b5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
16 changes: 13 additions & 3 deletions chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1915,11 +1915,21 @@ void Browser::Observe(int type,
const Extension* extension =
content::Details<extensions::UnloadedExtensionInfo>(
details)->extension;
// Iterate backwards as we may remove items while iterating.
for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
if (web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
web_contents->GetURL().host() == extension->id())
chrome::CloseWebContents(this, web_contents);
// Two cases are handled here:
// - The scheme check is for when an extension page is loaded in a
// tab, e.g. chrome-extension://id/page.html.
// - The extension_app check is for apps, which can have non-extension
// schemes, e.g. https://mail.google.com if you have the Gmail app
// installed.
if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
web_contents->GetURL().host() == extension->id()) ||
(extensions::TabHelper::FromWebContents(
web_contents)->extension_app() == extension)) {
tab_strip_model_->CloseTabContentsAt(i, TabStripModel::CLOSE_NONE);
}
}
}
break;
Expand Down
23 changes: 1 addition & 22 deletions chrome/browser/ui/tabs/tab_strip_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
Expand Down Expand Up @@ -57,8 +57,6 @@ TabStripModel::TabStripModel(TabStripModelDelegate* delegate, Profile* profile)
DCHECK(delegate_);
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile_));
order_controller_.reset(new TabStripModelOrderController(this));
}

Expand Down Expand Up @@ -941,25 +939,6 @@ void TabStripModel::Observe(int type,
break;
}

case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
const extensions::Extension* extension =
content::Details<extensions::UnloadedExtensionInfo>(
details)->extension;
// Iterate backwards as we may remove items while iterating.
for (int i = count() - 1; i >= 0; i--) {
WebContents* contents = GetWebContentsAtImpl(i);
if (extensions::TabHelper::FromWebContents(contents)->
extension_app() == extension) {
// The extension an app tab was created from has been nuked. Delete
// the WebContents. Deleting a WebContents results in a notification
// of type NOTIFICATION_WEB_CONTENTS_DESTROYED; we do the necessary
// cleanup in handling that notification.
InternalCloseTab(contents, i, false);
}
}
break;
}

default:
NOTREACHED();
}
Expand Down

0 comments on commit e344b5a

Please sign in to comment.