| 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..beb7ce96e510cef333f3d25eaab22c3f9e79a4dc 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,16 @@ 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(WARNING) << "Closing existing BackgroundContents for " << opener_url;
|
| + existing->render_view_host()->ClosePage();
|
| + 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()));
|
|
|