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

Unified Diff: chrome/browser/tab_contents/render_view_host_delegate_helper.cc

Issue 8116015: Now closes existing background contents if app opens a new one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed presubmit error (added license header to js file) Created 9 years, 2 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/tab_contents/render_view_host_delegate_helper.cc
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
index 4f1afa9f3cabec79ac868870aca66ae923cef978..00d95b3d67cbf35494a45a4e6ba53514a4fb7e1d 100644
--- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
@@ -107,11 +107,10 @@ RenderViewHostDelegateViewHelper::MaybeCreateBackgroundContents(
if (extension->background_url().is_valid())
return NULL;
- // Only allow a single background contents per app.
+ // No BackgroundContents allowed if BackgroundContentsService doesn't exist.
BackgroundContentsService* service =
BackgroundContentsServiceFactory::GetForProfile(profile);
- if (!service || service->GetAppBackgroundContents(
- ASCIIToUTF16(extension->id())))
+ if (!service)
return NULL;
// Ensure that we're trying to open this from the extension's process.
@@ -121,6 +120,15 @@ RenderViewHostDelegateViewHelper::MaybeCreateBackgroundContents(
site->GetProcess() != process_manager->GetExtensionProcess(opener_url))
return NULL;
+ // Only allow a single background contents per app. If one already exists,
+ // close it.
+ BackgroundContents* existing =
+ service->GetAppBackgroundContents(ASCIIToUTF16(extension->id()));
+ if (existing) {
+ DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url;
+ delete existing;
+ }
+
// Passed all the checks, so this should be created as a BackgroundContents.
return service->CreateBackgroundContents(site, route_id, profile, frame_name,
ASCIIToUTF16(extension->id()));

Powered by Google App Engine
This is Rietveld 408576698