This source file includes following definitions.
- profile_
- GetURL
- CloseContents
- ShouldSuppressDialogs
- DidNavigateMainFramePostCommit
- AddNewContents
- RenderProcessGone
- Observe
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/background/background_contents_service.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/session_storage_namespace.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/view_type_utils.h"
#include "ui/gfx/rect.h"
using content::SiteInstance;
using content::WebContents;
BackgroundContents::BackgroundContents(
SiteInstance* site_instance,
int routing_id,
Delegate* delegate,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace)
: delegate_(delegate) {
profile_ = Profile::FromBrowserContext(
site_instance->GetBrowserContext());
WebContents::CreateParams create_params(profile_, site_instance);
create_params.routing_id = routing_id;
if (session_storage_namespace) {
content::SessionStorageNamespaceMap session_storage_namespace_map;
session_storage_namespace_map.insert(
std::make_pair(partition_id, session_storage_namespace));
web_contents_.reset(WebContents::CreateWithSessionStorage(
create_params, session_storage_namespace_map));
} else {
web_contents_.reset(WebContents::Create(create_params));
}
extensions::SetViewType(
web_contents_.get(), extensions::VIEW_TYPE_BACKGROUND_CONTENTS);
web_contents_->SetDelegate(this);
content::WebContentsObserver::Observe(web_contents_.get());
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
web_contents_.get());
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_));
}
BackgroundContents::BackgroundContents()
: delegate_(NULL),
profile_(NULL) {
}
BackgroundContents::~BackgroundContents() {
if (!web_contents_.get())
return;
registrar_.RemoveAll();
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
content::Source<Profile>(profile_),
content::Details<BackgroundContents>(this));
}
const GURL& BackgroundContents::GetURL() const {
return web_contents_.get() ? web_contents_->GetURL() : GURL::EmptyGURL();
}
void BackgroundContents::CloseContents(WebContents* source) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED,
content::Source<Profile>(profile_),
content::Details<BackgroundContents>(this));
delete this;
}
bool BackgroundContents::ShouldSuppressDialogs() {
return true;
}
void BackgroundContents::DidNavigateMainFramePostCommit(WebContents* tab) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
content::Source<Profile>(profile_),
content::Details<BackgroundContents>(this));
}
void BackgroundContents::AddNewContents(WebContents* source,
WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture,
bool* was_blocked) {
delegate_->AddWebContents(
new_contents, disposition, initial_pos, user_gesture, was_blocked);
}
void BackgroundContents::RenderProcessGone(base::TerminationStatus status) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED,
content::Source<Profile>(profile_),
content::Details<BackgroundContents>(this));
delete this;
}
void BackgroundContents::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_DESTROYED:
case chrome::NOTIFICATION_APP_TERMINATING: {
delete this;
break;
}
default:
NOTREACHED() << "Unexpected notification sent.";
break;
}
}