electron/shell/common/extensions/electron_extensions_api_provider.cc
Charles Kerr 60c4c9fec6
chore: remove unused #includes (#42971)
* chore: iwyu buildflags.h

* chore: iwyu dictionary.h

* chore: iwyu arguments.h

* chore: iwyu values.h

* chore: iwyu compiler_specific.h

* chore: iwyu binder_map.h

* chore: iwyu <vector>

* chore: iwyu <set>

* chore: iwyu raw_ptr

* chore: iwyu gfx/canvas.h

* chore: iwyu gfx/color_utils.h

* chore: iwyu base/strings/stringprintf.h

* chore: iwyu base/task/thread_pool.h

* chore: iwyu base/no_destructor.h

* chore: iwyu base/path_service.h

* chore: iwyu base/files/file_pathh

* chore: iwyu base/strings/sys_string_conversions.h

* chore: iwyu base/logging.h

* chore: iwyu base/command_line.h

* chore: iwyu base/files/file_util.h

* chore: iwyu base/files/scoped_file.h

* chore: iwyu base/strings/utf_string_conversions.h

* chore: iwyu base/environment.h

* chore: iwyu base/scoped_observation.h

* chore: iwyu base/strings/string_split.h

* chore: iwyu base/strings/pattern.h

* chore: iwyu base/json/string_escape.h

* chore: iwyu base/json/json_reader.h

* chore: iwyu base/memory/singleton.h

* chore: iwyu base/observer_list.h

* chore: iwyu base/timer/timer.h

* fixup! chore: iwyu values.h

* chore: iwyu shell/browser/browser.h

* chore: iwyu base/stl_util.h

* chore: iwyu base/strings/string_util.h

* chore: iwyu shell/browser/javascript_environment.h

* chore: iwyu base/memory/ref_counted.h

* chore: iwyu base/environment.h

* chore: iwyu content/public/browser/browser_thread.h

* chore: remove unused typedef gin_helper::EventEmitter::ValueArray

* chore: iwyu gin/wrappable.h

* chore: iwyu shell/common/gin_helper/function_template_extensions.h

* chore: iwyu shell/common/gin_converters/login_item_settings_converter.h

* chore: iwyu shell/common/gin_helper/arguments.h

* chore: iwyu ui/gfx/skia_util.h

* chore: iwyu ui/gfx/geometry/rect.h

* chore: iwyu ui/gfx/image/image.h

* chore: iwyu base/strings/strcat.h

* chore: iwyu ui/native_theme/native_theme.h

* fixup! chore: iwyu shell/browser/javascript_environment.h

* fixup! chore: iwyu gfx/canvas.h

* fixup! chore: iwyu content/public/browser/browser_thread.h

* fixup! chore: iwyu ui/native_theme/native_theme.h

* fixup! chore: iwyu ui/native_theme/native_theme.h
2024-07-22 11:31:32 +02:00

111 lines
4.2 KiB
C++

// 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.
#include "shell/common/extensions/electron_extensions_api_provider.h"
#include <memory>
#include <string>
#include "base/containers/span.h"
#include "chrome/common/extensions/chrome_manifest_url_handlers.h"
#include "chrome/common/extensions/manifest_handlers/minimum_chrome_version_checker.h"
#include "electron/buildflags/buildflags.h"
#include "electron/shell/common/extensions/api/generated_schemas.h"
#include "extensions/common/alias.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/features/json_feature_provider_source.h"
#include "extensions/common/features/simple_feature.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handler.h"
#include "extensions/common/manifest_handler_registry.h"
#include "extensions/common/manifest_handlers/permissions_parser.h"
#include "extensions/common/manifest_url_handlers.h"
#include "extensions/common/permissions/permissions_info.h"
#include "shell/common/extensions/api/api_features.h"
#include "shell/common/extensions/api/manifest_features.h"
#include "shell/common/extensions/api/permission_features.h"
namespace extensions {
constexpr APIPermissionInfo::InitInfo permissions_to_register[] = {
{mojom::APIPermissionID::kDevtools, "devtools",
APIPermissionInfo::kFlagImpliesFullURLAccess |
APIPermissionInfo::kFlagCannotBeOptional |
APIPermissionInfo::kFlagInternal},
{mojom::APIPermissionID::kResourcesPrivate, "resourcesPrivate",
APIPermissionInfo::kFlagCannotBeOptional},
#if BUILDFLAG(ENABLE_PDF_VIEWER)
{mojom::APIPermissionID::kPdfViewerPrivate, "pdfViewerPrivate"},
#endif
{mojom::APIPermissionID::kManagement, "management"},
{mojom::APIPermissionID::kTab, "tabs",
APIPermissionInfo::kFlagRequiresManagementUIWarning},
{mojom::APIPermissionID::kScripting, "scripting",
APIPermissionInfo::kFlagRequiresManagementUIWarning},
};
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
namespace electron {
ElectronExtensionsAPIProvider::ElectronExtensionsAPIProvider() = default;
ElectronExtensionsAPIProvider::~ElectronExtensionsAPIProvider() = default;
void ElectronExtensionsAPIProvider::AddAPIFeatures(
extensions::FeatureProvider* provider) {
extensions::AddElectronAPIFeatures(provider);
}
void ElectronExtensionsAPIProvider::AddManifestFeatures(
extensions::FeatureProvider* provider) {
extensions::AddElectronManifestFeatures(provider);
}
void ElectronExtensionsAPIProvider::AddPermissionFeatures(
extensions::FeatureProvider* provider) {
extensions::AddElectronPermissionFeatures(provider);
}
void ElectronExtensionsAPIProvider::AddBehaviorFeatures(
extensions::FeatureProvider* provider) {
// No shell-specific behavior features.
}
void ElectronExtensionsAPIProvider::AddAPIJSONSources(
extensions::JSONFeatureProviderSource* json_source) {
// json_source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
}
bool ElectronExtensionsAPIProvider::IsAPISchemaGenerated(
const std::string& name) {
return extensions::api::ElectronGeneratedSchemas::IsGenerated(name);
}
std::string_view ElectronExtensionsAPIProvider::GetAPISchema(
const std::string& name) {
return extensions::api::ElectronGeneratedSchemas::Get(name);
}
void ElectronExtensionsAPIProvider::RegisterPermissions(
extensions::PermissionsInfo* permissions_info) {
permissions_info->RegisterPermissions(extensions::GetPermissionInfos(),
extensions::GetPermissionAliases());
}
void ElectronExtensionsAPIProvider::RegisterManifestHandlers() {
extensions::ManifestHandlerRegistry* registry =
extensions::ManifestHandlerRegistry::Get();
registry->RegisterHandler(
std::make_unique<extensions::DevToolsPageHandler>());
registry->RegisterHandler(
std::make_unique<extensions::MinimumChromeVersionChecker>());
}
} // namespace electron