| 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()));
|
|
|