This source file includes following definitions.
- CreateViewHostForExtension
- CreateViewHostForIncognito
- GetExtensionForUrl
- CreateViewHost
- CreatePopupHost
- CreateInfobarHost
- CreateDialogHost
#include "chrome/browser/extensions/extension_view_host_factory.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_view_host.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/url_constants.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
#include "extensions/common/view_type.h"
#if defined(OS_MACOSX)
#include "chrome/browser/extensions/extension_view_host_mac.h"
#endif
namespace extensions {
namespace {
ExtensionViewHost* CreateViewHostForExtension(const Extension* extension,
const GURL& url,
Profile* profile,
Browser* browser,
ViewType view_type) {
DCHECK(profile);
DCHECK(browser || view_type == VIEW_TYPE_EXTENSION_DIALOG);
ProcessManager* pm =
ExtensionSystem::Get(profile)->process_manager();
content::SiteInstance* site_instance = pm->GetSiteInstanceForURL(url);
ExtensionViewHost* host =
#if defined(OS_MACOSX)
new ExtensionViewHostMac(extension, site_instance, url, view_type);
#else
new ExtensionViewHost(extension, site_instance, url, view_type);
#endif
host->CreateView(browser);
return host;
}
ExtensionViewHost* CreateViewHostForIncognito(const Extension* extension,
const GURL& url,
Profile* profile,
Browser* browser,
ViewType view_type) {
DCHECK(extension);
DCHECK(profile->IsOffTheRecord());
if (!IncognitoInfo::IsSplitMode(extension)) {
Profile* original_profile = profile->GetOriginalProfile();
return CreateViewHostForExtension(
extension, url, original_profile, browser, view_type);
}
if (util::IsIncognitoEnabled(extension->id(), profile)) {
return CreateViewHostForExtension(
extension, url, profile, browser, view_type);
}
NOTREACHED() <<
"We shouldn't be trying to create an incognito extension view unless "
"it has been enabled for incognito.";
return NULL;
}
const Extension* GetExtensionForUrl(Profile* profile, const GURL& url) {
ExtensionService* service =
ExtensionSystem::Get(profile)->extension_service();
if (!service)
return NULL;
std::string extension_id = url.host();
if (url.SchemeIs(content::kChromeUIScheme) &&
url.host() == chrome::kChromeUIExtensionInfoHost)
extension_id = url.path().substr(1);
return service->extensions()->GetByID(extension_id);
}
ExtensionViewHost* CreateViewHost(const GURL& url,
Profile* profile,
Browser* browser,
extensions::ViewType view_type) {
DCHECK(profile);
DCHECK(browser || view_type == VIEW_TYPE_EXTENSION_DIALOG);
const Extension* extension = GetExtensionForUrl(profile, url);
if (!extension)
return NULL;
if (profile->IsOffTheRecord()) {
return CreateViewHostForIncognito(
extension, url, profile, browser, view_type);
}
return CreateViewHostForExtension(
extension, url, profile, browser, view_type);
}
}
ExtensionViewHost* ExtensionViewHostFactory::CreatePopupHost(const GURL& url,
Browser* browser) {
DCHECK(browser);
return CreateViewHost(
url, browser->profile(), browser, VIEW_TYPE_EXTENSION_POPUP);
}
ExtensionViewHost* ExtensionViewHostFactory::CreateInfobarHost(
const GURL& url,
Browser* browser) {
DCHECK(browser);
return CreateViewHost(
url, browser->profile(), browser, VIEW_TYPE_EXTENSION_INFOBAR);
}
ExtensionViewHost* ExtensionViewHostFactory::CreateDialogHost(
const GURL& url,
Profile* profile) {
DCHECK(profile);
return CreateViewHost(url, profile, NULL, VIEW_TYPE_EXTENSION_DIALOG);
}
}