This source file includes following definitions.
- IsIncognitoEnabled
- SetIsIncognitoEnabled
- CanCrossIncognito
- CanLoadInIncognito
- AllowFileAccess
- SetAllowFileAccess
- IsAppLaunchable
- IsAppLaunchableWithoutEnabling
- IsExtensionIdle
- IsExtensionInstalledPermanently
- GetSiteForExtensionId
- GetExtensionInfo
- HasIsolatedStorage
- SiteHasIsolatedStorage
#include "chrome/browser/extensions/extension_util.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_sync_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_icon_set.h"
#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
#include "chrome/common/extensions/sync_helper.h"
#include "content/public/browser/site_instance.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
namespace extensions {
namespace util {
bool IsIncognitoEnabled(const std::string& extension_id,
content::BrowserContext* context) {
const Extension* extension = ExtensionRegistry::Get(context)->
GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
if (extension) {
if (!extension->can_be_incognito_enabled())
return false;
if (extension->location() == Manifest::COMPONENT)
return true;
}
return ExtensionPrefs::Get(context)->IsIncognitoEnabled(extension_id);
}
void SetIsIncognitoEnabled(const std::string& extension_id,
content::BrowserContext* context,
bool enabled) {
ExtensionService* service =
ExtensionSystem::Get(context)->extension_service();
CHECK(service);
const Extension* extension = service->GetInstalledExtension(extension_id);
if (extension) {
if (!extension->can_be_incognito_enabled())
return;
if (extension->location() == Manifest::COMPONENT) {
DCHECK(sync_helper::IsSyncable(extension));
DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id, service->profile()));
return;
}
}
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(service->profile());
bool old_enabled = extension_prefs->IsIncognitoEnabled(extension_id);
if (enabled == old_enabled)
return;
extension_prefs->SetIsIncognitoEnabled(extension_id, enabled);
bool extension_is_enabled = service->extensions()->Contains(extension_id);
std::string id = extension_id;
if (extension_is_enabled)
service->ReloadExtension(id);
extension = service->GetInstalledExtension(id);
if (extension) {
ExtensionSyncService::Get(service->profile())->
SyncExtensionChangeIfNeeded(*extension);
}
}
bool CanCrossIncognito(const Extension* extension,
content::BrowserContext* context) {
CHECK(extension);
return IsIncognitoEnabled(extension->id(), context) &&
!IncognitoInfo::IsSplitMode(extension);
}
bool CanLoadInIncognito(const Extension* extension,
content::BrowserContext* context) {
CHECK(extension);
if (extension->is_hosted_app())
return true;
return IncognitoInfo::IsSplitMode(extension) &&
IsIncognitoEnabled(extension->id(), context);
}
bool AllowFileAccess(const std::string& extension_id,
content::BrowserContext* context) {
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableExtensionsFileAccessCheck) ||
ExtensionPrefs::Get(context)->AllowFileAccess(extension_id);
}
void SetAllowFileAccess(const std::string& extension_id,
content::BrowserContext* context,
bool allow) {
ExtensionService* service =
ExtensionSystem::Get(context)->extension_service();
CHECK(service);
if (allow == AllowFileAccess(extension_id, context))
return;
ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow);
bool extension_is_enabled = service->extensions()->Contains(extension_id);
if (extension_is_enabled)
service->ReloadExtension(extension_id);
}
bool IsAppLaunchable(const std::string& extension_id,
content::BrowserContext* context) {
return !(ExtensionPrefs::Get(context)->GetDisableReasons(extension_id) &
Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
}
bool IsAppLaunchableWithoutEnabling(const std::string& extension_id,
content::BrowserContext* context) {
return ExtensionRegistry::Get(context)->GetExtensionById(
extension_id, ExtensionRegistry::ENABLED) != NULL;
}
bool IsExtensionIdle(const std::string& extension_id,
content::BrowserContext* context) {
ProcessManager* process_manager =
ExtensionSystem::Get(context)->process_manager();
DCHECK(process_manager);
ExtensionHost* host =
process_manager->GetBackgroundHostForExtension(extension_id);
if (host)
return false;
content::SiteInstance* site_instance = process_manager->GetSiteInstanceForURL(
Extension::GetBaseURLFromExtensionId(extension_id));
if (site_instance && site_instance->HasProcess())
return false;
return process_manager->GetRenderViewHostsForExtension(extension_id).empty();
}
bool IsExtensionInstalledPermanently(const std::string& extension_id,
content::BrowserContext* context) {
const Extension* extension = ExtensionRegistry::Get(context)->
GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
return extension && !extension->is_ephemeral();
}
GURL GetSiteForExtensionId(const std::string& extension_id,
content::BrowserContext* context) {
return content::SiteInstance::GetSiteForURL(
context, Extension::GetBaseURLFromExtensionId(extension_id));
}
scoped_ptr<base::DictionaryValue> GetExtensionInfo(const Extension* extension) {
DCHECK(extension);
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
dict->SetString("id", extension->id());
dict->SetString("name", extension->name());
GURL icon = extensions::ExtensionIconSource::GetIconURL(
extension,
extension_misc::EXTENSION_ICON_SMALLISH,
ExtensionIconSet::MATCH_BIGGER,
false,
NULL);
dict->SetString("icon", icon.spec());
return dict.Pass();
}
bool HasIsolatedStorage(const ExtensionInfo& info) {
if (!info.extension_manifest.get())
return false;
std::string error;
scoped_refptr<const Extension> extension(Extension::Create(
info.extension_path,
info.extension_location,
*info.extension_manifest,
Extension::NO_FLAGS,
info.extension_id,
&error));
if (!extension.get())
return false;
return AppIsolationInfo::HasIsolatedStorage(extension.get());
}
bool SiteHasIsolatedStorage(const GURL& extension_site_url,
content::BrowserContext* context) {
const Extension* extension = ExtensionRegistry::Get(context)->
enabled_extensions().GetExtensionOrAppByURL(extension_site_url);
if (extension)
return AppIsolationInfo::HasIsolatedStorage(extension);
if (extension_site_url.SchemeIs(kExtensionScheme)) {
ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
DCHECK(prefs);
scoped_ptr<ExtensionInfo> info = prefs->GetEvictedEphemeralAppInfo(
extension_site_url.host());
if (info.get())
return HasIsolatedStorage(*info);
}
return false;
}
}
}