2019-07-24 23:01:08 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/common/extensions/electron_extensions_api_provider.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-01-15 00:20:30 +00:00
|
|
|
#include <memory>
|
2019-07-24 23:01:08 +00:00
|
|
|
#include <string>
|
2020-01-15 00:20:30 +00:00
|
|
|
#include <utility>
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-01-15 00:20:30 +00:00
|
|
|
#include "base/containers/span.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "chrome/common/extensions/chrome_manifest_url_handlers.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2020-01-15 23:11:51 +00:00
|
|
|
#include "electron/shell/common/extensions/api/generated_schemas.h"
|
2020-01-15 00:20:30 +00:00
|
|
|
#include "extensions/common/alias.h"
|
2020-01-15 23:11:51 +00:00
|
|
|
#include "extensions/common/features/feature_provider.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/common/features/json_feature_provider_source.h"
|
2020-01-15 23:11:51 +00:00
|
|
|
#include "extensions/common/features/simple_feature.h"
|
2020-01-15 00:20:30 +00:00
|
|
|
#include "extensions/common/manifest_constants.h"
|
|
|
|
#include "extensions/common/manifest_handler.h"
|
|
|
|
#include "extensions/common/manifest_handlers/permissions_parser.h"
|
|
|
|
#include "extensions/common/manifest_url_handlers.h"
|
|
|
|
#include "extensions/common/permissions/permissions_info.h"
|
2020-01-15 23:11:51 +00:00
|
|
|
#include "shell/common/extensions/api/api_features.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "shell/common/extensions/api/manifest_features.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "shell/common/extensions/api/permission_features.h"
|
2020-01-15 00:20:30 +00:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
namespace keys = manifest_keys;
|
|
|
|
namespace errors = manifest_errors;
|
|
|
|
|
|
|
|
constexpr APIPermissionInfo::InitInfo permissions_to_register[] = {
|
|
|
|
{APIPermission::kDevtools, "devtools",
|
|
|
|
APIPermissionInfo::kFlagImpliesFullURLAccess |
|
|
|
|
APIPermissionInfo::kFlagCannotBeOptional |
|
|
|
|
APIPermissionInfo::kFlagInternal},
|
2020-02-13 00:39:12 +00:00
|
|
|
{APIPermission::kResourcesPrivate, "resourcesPrivate",
|
|
|
|
APIPermissionInfo::kFlagCannotBeOptional},
|
2020-01-15 00:20:30 +00:00
|
|
|
};
|
|
|
|
base::span<const APIPermissionInfo::InitInfo> GetPermissionInfos() {
|
|
|
|
return base::make_span(permissions_to_register);
|
|
|
|
}
|
|
|
|
base::span<const Alias> GetPermissionAliases() {
|
|
|
|
return base::span<const Alias>();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsAPIProvider::ElectronExtensionsAPIProvider() = default;
|
|
|
|
ElectronExtensionsAPIProvider::~ElectronExtensionsAPIProvider() = default;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::AddAPIFeatures(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::FeatureProvider* provider) {
|
2020-01-15 23:11:51 +00:00
|
|
|
extensions::AddElectronAPIFeatures(provider);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::AddManifestFeatures(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::FeatureProvider* provider) {
|
2020-01-15 23:11:51 +00:00
|
|
|
extensions::AddElectronManifestFeatures(provider);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::AddPermissionFeatures(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::FeatureProvider* provider) {
|
2020-02-13 00:39:12 +00:00
|
|
|
extensions::AddElectronPermissionFeatures(provider);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::AddBehaviorFeatures(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::FeatureProvider* provider) {
|
|
|
|
// No shell-specific behavior features.
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::AddAPIJSONSources(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::JSONFeatureProviderSource* json_source) {
|
|
|
|
// json_source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsAPIProvider::IsAPISchemaGenerated(
|
|
|
|
const std::string& name) {
|
2020-01-15 23:11:51 +00:00
|
|
|
return extensions::api::ElectronGeneratedSchemas::IsGenerated(name);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
base::StringPiece ElectronExtensionsAPIProvider::GetAPISchema(
|
2019-07-24 23:01:08 +00:00
|
|
|
const std::string& name) {
|
2020-01-15 23:11:51 +00:00
|
|
|
return extensions::api::ElectronGeneratedSchemas::Get(name);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::RegisterPermissions(
|
2020-01-15 00:20:30 +00:00
|
|
|
extensions::PermissionsInfo* permissions_info) {
|
|
|
|
permissions_info->RegisterPermissions(extensions::GetPermissionInfos(),
|
|
|
|
extensions::GetPermissionAliases());
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsAPIProvider::RegisterManifestHandlers() {
|
2020-01-15 00:20:30 +00:00
|
|
|
extensions::ManifestHandlerRegistry* registry =
|
|
|
|
extensions::ManifestHandlerRegistry::Get();
|
|
|
|
registry->RegisterHandler(
|
|
|
|
std::make_unique<extensions::DevToolsPageHandler>());
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
} // namespace electron
|