This source file includes following definitions.
- Initialize
- GetPermissionsProvider
- GetPermissionMessageProvider
- GetFeatureProviderByName
- FilterHostPermissions
- SetScriptingWhitelist
- GetScriptingWhitelist
- GetPermittedChromeSchemeHosts
- IsScriptableURL
- IsAPISchemaGenerated
- GetAPISchema
- AddExtraFeatureFilters
- GetInstance
#include "chrome/common/extensions/chrome_extensions_client.h"
#include "apps/common/api/generated_schemas.h"
#include "base/command_line.h"
#include "chrome/common/extensions/api/generated_schemas.h"
#include "chrome/common/extensions/chrome_manifest_handlers.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/features/chrome_channel_feature_filter.h"
#include "chrome/common/url_constants.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/api/generated_schemas.h"
#include "extensions/common/common_manifest_handlers.h"
#include "extensions/common/extension.h"
#include "extensions/common/features/base_feature_provider.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handler.h"
#include "extensions/common/permissions/api_permission_set.h"
#include "extensions/common/permissions/permission_message.h"
#include "extensions/common/switches.h"
#include "extensions/common/url_pattern.h"
#include "extensions/common/url_pattern_set.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
namespace {
const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh";
}
namespace extensions {
static base::LazyInstance<ChromeExtensionsClient> g_client =
LAZY_INSTANCE_INITIALIZER;
ChromeExtensionsClient::ChromeExtensionsClient()
: chrome_api_permissions_(ChromeAPIPermissions()) {
}
ChromeExtensionsClient::~ChromeExtensionsClient() {
}
void ChromeExtensionsClient::Initialize() {
if (!ManifestHandler::IsRegistrationFinalized()) {
RegisterCommonManifestHandlers();
RegisterChromeManifestHandlers();
ManifestHandler::FinalizeRegistration();
}
scripting_whitelist_.push_back(extension_misc::kChromeVoxExtensionId);
scripting_whitelist_.push_back("angkfkebojeancgemegoedelbnjgcgme");
}
const PermissionsProvider&
ChromeExtensionsClient::GetPermissionsProvider() const {
return chrome_api_permissions_;
}
const PermissionMessageProvider&
ChromeExtensionsClient::GetPermissionMessageProvider() const {
return permission_message_provider_;
}
FeatureProvider* ChromeExtensionsClient::GetFeatureProviderByName(
const std::string& name) const {
return BaseFeatureProvider::GetByName(name);
}
void ChromeExtensionsClient::FilterHostPermissions(
const URLPatternSet& hosts,
URLPatternSet* new_hosts,
std::set<PermissionMessage>* messages) const {
for (URLPatternSet::const_iterator i = hosts.begin();
i != hosts.end(); ++i) {
if (i->scheme() == content::kChromeUIScheme) {
if (GURL(chrome::kChromeUIFaviconURL).host() != i->host())
continue;
messages->insert(PermissionMessage(
PermissionMessage::kFavicon,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FAVICON)));
} else {
new_hosts->AddPattern(*i);
}
}
}
void ChromeExtensionsClient::SetScriptingWhitelist(
const ExtensionsClient::ScriptingWhitelist& whitelist) {
scripting_whitelist_ = whitelist;
}
const ExtensionsClient::ScriptingWhitelist&
ChromeExtensionsClient::GetScriptingWhitelist() const {
return scripting_whitelist_;
}
URLPatternSet ChromeExtensionsClient::GetPermittedChromeSchemeHosts(
const Extension* extension,
const APIPermissionSet& api_permissions) const {
URLPatternSet hosts;
hosts.AddPattern(URLPattern(URLPattern::SCHEME_CHROMEUI,
chrome::kChromeUIFaviconURL));
if ((api_permissions.find(APIPermission::kExperimental) !=
api_permissions.end()) ||
(extension->id() == kThumbsWhiteListedExtension &&
extension->from_webstore())) {
hosts.AddPattern(URLPattern(URLPattern::SCHEME_CHROMEUI,
chrome::kChromeUIThumbnailURL));
}
return hosts;
}
bool ChromeExtensionsClient::IsScriptableURL(
const GURL& url, std::string* error) const {
GURL store_url(extension_urls::GetWebstoreLaunchURL());
if (url.host() == store_url.host()) {
if (error)
*error = manifest_errors::kCannotScriptGallery;
return false;
}
return true;
}
bool ChromeExtensionsClient::IsAPISchemaGenerated(
const std::string& name) const {
return extensions::api::GeneratedSchemas::IsGenerated(name) ||
extensions::core_api::GeneratedSchemas::IsGenerated(name) ||
apps::api::GeneratedSchemas::IsGenerated(name);
}
base::StringPiece ChromeExtensionsClient::GetAPISchema(
const std::string& name) const {
if (extensions::api::GeneratedSchemas::IsGenerated(name))
return extensions::api::GeneratedSchemas::Get(name);
if (extensions::core_api::GeneratedSchemas::IsGenerated(name))
return extensions::core_api::GeneratedSchemas::Get(name);
return apps::api::GeneratedSchemas::Get(name);
}
void ChromeExtensionsClient::AddExtraFeatureFilters(
SimpleFeature* feature) const {
feature->AddFilter(
scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature)));
}
ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() {
return g_client.Pointer();
}
}