2015-07-16 23:40:01 +02:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/common/extensions/extensions_client.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2016-07-20 20:03:38 +02:00
|
|
|
#include "libcef/common/extensions/chrome_generated_schemas.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "cef/grit/cef_resources.h"
|
2016-07-20 20:03:38 +02:00
|
|
|
//#include "cef/libcef/common/extensions/api/generated_schemas.h"
|
2016-08-31 13:25:56 +02:00
|
|
|
#include "cef/libcef/common/extensions/api/cef_api_features.h"
|
|
|
|
#include "cef/libcef/common/extensions/api/cef_manifest_features.h"
|
|
|
|
#include "cef/libcef/common/extensions/api/cef_permission_features.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "chrome/common/extensions/chrome_aliases.h"
|
2016-07-20 20:03:38 +02:00
|
|
|
#include "chrome/common/extensions/chrome_manifest_handlers.h"
|
|
|
|
#include "chrome/grit/common_resources.h"
|
2018-07-24 00:32:02 +02:00
|
|
|
#include "extensions/common/api/api_features.h"
|
|
|
|
#include "extensions/common/api/behavior_features.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/common/api/generated_schemas.h"
|
2018-07-24 00:32:02 +02:00
|
|
|
#include "extensions/common/api/manifest_features.h"
|
|
|
|
#include "extensions/common/api/permission_features.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/common/common_manifest_handlers.h"
|
|
|
|
#include "extensions/common/extension_urls.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "extensions/common/extensions_aliases.h"
|
2018-07-24 00:32:02 +02:00
|
|
|
#include "extensions/common/features/feature_provider.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/common/features/json_feature_provider_source.h"
|
|
|
|
#include "extensions/common/features/simple_feature.h"
|
|
|
|
#include "extensions/common/manifest_handler.h"
|
|
|
|
#include "extensions/common/permissions/permission_message_provider.h"
|
|
|
|
#include "extensions/common/permissions/permissions_info.h"
|
|
|
|
#include "extensions/common/permissions/permissions_provider.h"
|
|
|
|
#include "extensions/common/url_pattern_set.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "extensions/grit/extensions_resources.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <class FeatureClass>
|
|
|
|
SimpleFeature* CreateFeature() {
|
|
|
|
return new FeatureClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
CefExtensionsClient::CefExtensionsClient()
|
2017-05-17 11:29:28 +02:00
|
|
|
: webstore_base_url_(extension_urls::kChromeWebstoreBaseURL),
|
|
|
|
webstore_update_url_(extension_urls::kChromeWebstoreUpdateURL) {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefExtensionsClient::~CefExtensionsClient() {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
void CefExtensionsClient::Initialize() {
|
|
|
|
RegisterCommonManifestHandlers();
|
2016-07-20 20:03:38 +02:00
|
|
|
RegisterChromeManifestHandlers();
|
2015-07-16 23:40:01 +02:00
|
|
|
ManifestHandler::FinalizeRegistration();
|
|
|
|
// TODO(jamescook): Do we need to whitelist any extensions?
|
|
|
|
|
2016-07-20 20:03:38 +02:00
|
|
|
// Set up permissions.
|
2016-11-23 21:54:29 +01:00
|
|
|
PermissionsInfo::GetInstance()->AddProvider(chrome_api_permissions_,
|
|
|
|
GetChromePermissionAliases());
|
|
|
|
PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_,
|
|
|
|
GetExtensionsPermissionAliases());
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
void CefExtensionsClient::InitializeWebStoreUrls(
|
|
|
|
base::CommandLine* command_line) {}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
const PermissionMessageProvider&
|
|
|
|
CefExtensionsClient::GetPermissionMessageProvider() const {
|
2016-07-20 20:03:38 +02:00
|
|
|
return permission_message_provider_;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string CefExtensionsClient::GetProductName() {
|
|
|
|
return "cef";
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<FeatureProvider> CefExtensionsClient::CreateFeatureProvider(
|
2015-07-16 23:40:01 +02:00
|
|
|
const std::string& name) const {
|
2018-07-24 00:32:02 +02:00
|
|
|
auto provider = std::make_unique<FeatureProvider>();
|
2015-07-16 23:40:01 +02:00
|
|
|
if (name == "api") {
|
2018-07-24 00:32:02 +02:00
|
|
|
AddCoreAPIFeatures(provider.get());
|
|
|
|
AddCEFAPIFeatures(provider.get());
|
2015-07-16 23:40:01 +02:00
|
|
|
} else if (name == "manifest") {
|
2018-07-24 00:32:02 +02:00
|
|
|
AddCoreManifestFeatures(provider.get());
|
|
|
|
AddCEFManifestFeatures(provider.get());
|
2015-07-16 23:40:01 +02:00
|
|
|
} else if (name == "permission") {
|
2018-07-24 00:32:02 +02:00
|
|
|
AddCorePermissionFeatures(provider.get());
|
|
|
|
AddCEFPermissionFeatures(provider.get());
|
2015-07-16 23:40:01 +02:00
|
|
|
} else if (name == "behavior") {
|
2018-07-24 00:32:02 +02:00
|
|
|
// Note: There are no CEF-specific behavior features.
|
|
|
|
AddCoreBehaviorFeatures(provider.get());
|
2015-07-16 23:40:01 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
2016-01-06 20:20:54 +01:00
|
|
|
return provider;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<JSONFeatureProviderSource>
|
2016-08-31 13:25:56 +02:00
|
|
|
CefExtensionsClient::CreateAPIFeatureSource() const {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<JSONFeatureProviderSource> source(
|
2016-08-31 13:25:56 +02:00
|
|
|
new JSONFeatureProviderSource("api"));
|
|
|
|
source->LoadJSON(IDR_EXTENSION_API_FEATURES);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
// Extension API features specific to CEF. See
|
|
|
|
// libcef/common/extensions/api/README.txt for additional details.
|
|
|
|
source->LoadJSON(IDR_CEF_EXTENSION_API_FEATURES);
|
2016-07-20 20:03:38 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
return source;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionsClient::FilterHostPermissions(
|
|
|
|
const URLPatternSet& hosts,
|
|
|
|
URLPatternSet* new_hosts,
|
|
|
|
PermissionIDSet* permissions) const {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionsClient::SetScriptingWhitelist(
|
|
|
|
const ScriptingWhitelist& whitelist) {
|
|
|
|
scripting_whitelist_ = whitelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ExtensionsClient::ScriptingWhitelist&
|
|
|
|
CefExtensionsClient::GetScriptingWhitelist() const {
|
|
|
|
// TODO(jamescook): Real whitelist.
|
|
|
|
return scripting_whitelist_;
|
|
|
|
}
|
|
|
|
|
|
|
|
URLPatternSet CefExtensionsClient::GetPermittedChromeSchemeHosts(
|
|
|
|
const Extension* extension,
|
|
|
|
const APIPermissionSet& api_permissions) const {
|
|
|
|
return URLPatternSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsClient::IsScriptableURL(const GURL& url,
|
|
|
|
std::string* error) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefExtensionsClient::IsAPISchemaGenerated(const std::string& name) const {
|
2016-07-20 20:03:38 +02:00
|
|
|
// Schema for CEF-only APIs.
|
|
|
|
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
|
|
|
|
// libcef/common/extensions/api/README.txt for details.
|
2017-05-17 11:29:28 +02:00
|
|
|
// if (api::cef::CefGeneratedSchemas::IsGenerated(name))
|
|
|
|
// return true;
|
2016-07-20 20:03:38 +02:00
|
|
|
|
|
|
|
// Chrome APIs whitelisted by CEF.
|
|
|
|
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Core extensions APIs.
|
|
|
|
if (api::GeneratedSchemas::IsGenerated(name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
base::StringPiece CefExtensionsClient::GetAPISchema(
|
|
|
|
const std::string& name) const {
|
|
|
|
// Schema for CEF-only APIs.
|
2016-07-20 20:03:38 +02:00
|
|
|
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
|
|
|
|
// libcef/common/extensions/api/README.txt for details.
|
2017-05-17 11:29:28 +02:00
|
|
|
// if (api::cef::CefGeneratedSchemas::IsGenerated(name))
|
|
|
|
// return api::cef::CefGeneratedSchemas::Get(name);
|
2016-07-20 20:03:38 +02:00
|
|
|
|
|
|
|
// Chrome APIs whitelisted by CEF.
|
|
|
|
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name))
|
|
|
|
return api::cef::ChromeGeneratedSchemas::Get(name);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Core extensions APIs.
|
2015-08-14 16:41:08 +02:00
|
|
|
return api::GeneratedSchemas::Get(name);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsClient::ShouldSuppressFatalErrors() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefExtensionsClient::RecordDidSuppressFatalError() {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
const GURL& CefExtensionsClient::GetWebstoreBaseURL() const {
|
|
|
|
return webstore_base_url_;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
const GURL& CefExtensionsClient::GetWebstoreUpdateURL() const {
|
|
|
|
return webstore_update_url_;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
|
|
|
|
// TODO(rockot): Maybe we want to do something else here. For now we accept
|
|
|
|
// any URL as a blacklist URL because we don't really care.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|