This source file includes following definitions.
- IsShuttingDown
- AreExtensionsDisabled
- IsValidContext
- IsSameContext
- HasOffTheRecordContext
- GetOffTheRecordContext
- GetOriginalContext
- IsGuestSession
- IsExtensionIncognitoEnabled
- CanExtensionCrossIncognito
- GetPrefServiceForContext
- GetEarlyExtensionPrefsObservers
- DeferLoadingBackgroundHosts
- IsBackgroundPageAllowed
- CreateExtensionHostDelegate
- DidVersionUpdate
- CreateAppSorting
- IsRunningInForcedAppMode
- GetApiActivityMonitor
- GetExtensionSystemFactory
- RegisterExtensionFunctions
#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
#include "apps/common/api/generated_api.h"
#include "base/command_line.h"
#include "base/version.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
#include "chrome/browser/extensions/api/preference/preference_api.h"
#include "chrome/browser/extensions/api/web_request/web_request_api.h"
#include "chrome/browser/extensions/chrome_app_sorting.h"
#include "chrome/browser/extensions/chrome_extension_host_delegate.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/api/generated_api.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/pref_names.h"
#include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/api/generated_api.h"
#if defined(OS_CHROMEOS)
#include "chromeos/chromeos_switches.h"
#endif
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
#endif
namespace extensions {
ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() {
#if defined(ENABLE_EXTENSIONS)
api_client_.reset(new ChromeExtensionsAPIClient);
#endif
if (GetCurrentChannel() == GetDefaultChannel())
SetCurrentChannel(chrome::VersionInfo::GetChannel());
}
ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() {}
bool ChromeExtensionsBrowserClient::IsShuttingDown() {
return g_browser_process->IsShuttingDown();
}
bool ChromeExtensionsBrowserClient::AreExtensionsDisabled(
const CommandLine& command_line,
content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context);
return command_line.HasSwitch(switches::kDisableExtensions) ||
profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions);
}
bool ChromeExtensionsBrowserClient::IsValidContext(
content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context);
return g_browser_process->profile_manager()->IsValidProfile(profile);
}
bool ChromeExtensionsBrowserClient::IsSameContext(
content::BrowserContext* first,
content::BrowserContext* second) {
return static_cast<Profile*>(first)->IsSameProfile(
static_cast<Profile*>(second));
}
bool ChromeExtensionsBrowserClient::HasOffTheRecordContext(
content::BrowserContext* context) {
return static_cast<Profile*>(context)->HasOffTheRecordProfile();
}
content::BrowserContext* ChromeExtensionsBrowserClient::GetOffTheRecordContext(
content::BrowserContext* context) {
return static_cast<Profile*>(context)->GetOffTheRecordProfile();
}
content::BrowserContext* ChromeExtensionsBrowserClient::GetOriginalContext(
content::BrowserContext* context) {
return static_cast<Profile*>(context)->GetOriginalProfile();
}
bool ChromeExtensionsBrowserClient::IsGuestSession(
content::BrowserContext* context) const {
return static_cast<Profile*>(context)->IsGuestSession();
}
bool ChromeExtensionsBrowserClient::IsExtensionIncognitoEnabled(
const std::string& extension_id,
content::BrowserContext* context) const {
return IsGuestSession(context)
|| util::IsIncognitoEnabled(extension_id, context);
}
bool ChromeExtensionsBrowserClient::CanExtensionCrossIncognito(
const extensions::Extension* extension,
content::BrowserContext* context) const {
return IsGuestSession(context)
|| util::CanCrossIncognito(extension, context);
}
PrefService* ChromeExtensionsBrowserClient::GetPrefServiceForContext(
content::BrowserContext* context) {
return static_cast<Profile*>(context)->GetPrefs();
}
void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
content::BrowserContext* context,
std::vector<ExtensionPrefsObserver*>* observers) const {
#if defined(ENABLE_EXTENSIONS)
observers->push_back(ContentSettingsService::Get(context));
#endif
}
bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return true;
#if defined(OS_ANDROID)
return false;
#else
return chrome::GetTotalBrowserCountForProfile(profile) == 0 &&
CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList);
#endif
}
bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed(
content::BrowserContext* context) const {
return !static_cast<Profile*>(context)->IsGuestSession() ||
context->IsOffTheRecord();
}
scoped_ptr<ExtensionHostDelegate>
ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() {
return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate);
}
bool ChromeExtensionsBrowserClient::DidVersionUpdate(
content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context);
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);
if (!extension_prefs)
return false;
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
return false;
PrefService* pref_service = extension_prefs->pref_service();
base::Version last_version;
if (pref_service->HasPrefPath(pref_names::kLastChromeVersion)) {
std::string last_version_str =
pref_service->GetString(pref_names::kLastChromeVersion);
last_version = base::Version(last_version_str);
}
chrome::VersionInfo current_version_info;
std::string current_version = current_version_info.Version();
pref_service->SetString(pref_names::kLastChromeVersion,
current_version);
if (!last_version.IsValid())
return true;
return last_version.IsOlderThan(current_version);
}
scoped_ptr<AppSorting> ChromeExtensionsBrowserClient::CreateAppSorting() {
return scoped_ptr<AppSorting>(new ChromeAppSorting());
}
bool ChromeExtensionsBrowserClient::IsRunningInForcedAppMode() {
return chrome::IsRunningInForcedAppMode();
}
ApiActivityMonitor* ChromeExtensionsBrowserClient::GetApiActivityMonitor(
content::BrowserContext* context) {
return ActivityLog::GetInstance(context);
}
ExtensionSystemProvider*
ChromeExtensionsBrowserClient::GetExtensionSystemFactory() {
return ExtensionSystemFactory::GetInstance();
}
void ChromeExtensionsBrowserClient::RegisterExtensionFunctions(
ExtensionFunctionRegistry* registry) const {
#if defined(ENABLE_EXTENSIONS)
registry->RegisterFunction<WebRequestAddEventListener>();
registry->RegisterFunction<WebRequestEventHandled>();
registry->RegisterFunction<extensions::GetPreferenceFunction>();
registry->RegisterFunction<extensions::SetPreferenceFunction>();
registry->RegisterFunction<extensions::ClearPreferenceFunction>();
registry->RegisterFunction<
extensions::chromedirectsetting::GetDirectSettingFunction>();
registry->RegisterFunction<
extensions::chromedirectsetting::SetDirectSettingFunction>();
registry->RegisterFunction<
extensions::chromedirectsetting::ClearDirectSettingFunction>();
extensions::core_api::GeneratedFunctionRegistry::RegisterAll(registry);
apps::api::GeneratedFunctionRegistry::RegisterAll(registry);
extensions::api::GeneratedFunctionRegistry::RegisterAll(registry);
#endif
}
}