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.
|
|
|
|
|
|
|
|
#include "shell/common/extensions/atom_extensions_api_provider.h"
|
|
|
|
|
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"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2020-01-15 00:20:30 +00:00
|
|
|
#include "extensions/common/alias.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/common/features/json_feature_provider_source.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"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "shell/common/extensions/api/manifest_features.h"
|
2020-01-15 00:20:30 +00:00
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
namespace keys = manifest_keys;
|
|
|
|
namespace errors = manifest_errors;
|
|
|
|
|
|
|
|
// Parses the "devtools_page" manifest key.
|
|
|
|
class DevToolsPageHandler : public ManifestHandler {
|
|
|
|
public:
|
|
|
|
DevToolsPageHandler() = default;
|
|
|
|
~DevToolsPageHandler() override = default;
|
|
|
|
|
|
|
|
bool Parse(Extension* extension, base::string16* error) override {
|
|
|
|
std::unique_ptr<ManifestURL> manifest_url(new ManifestURL);
|
|
|
|
std::string devtools_str;
|
|
|
|
if (!extension->manifest()->GetString(keys::kDevToolsPage, &devtools_str)) {
|
|
|
|
*error = base::ASCIIToUTF16(errors::kInvalidDevToolsPage);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
manifest_url->url_ = extension->GetResourceURL(devtools_str);
|
|
|
|
extension->SetManifestData(keys::kDevToolsPage, std::move(manifest_url));
|
|
|
|
PermissionsParser::AddAPIPermission(extension, APIPermission::kDevtools);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
base::span<const char* const> Keys() const override {
|
|
|
|
static constexpr const char* kKeys[] = {keys::kDevToolsPage};
|
|
|
|
return kKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(DevToolsPageHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr APIPermissionInfo::InitInfo permissions_to_register[] = {
|
|
|
|
{APIPermission::kDevtools, "devtools",
|
|
|
|
APIPermissionInfo::kFlagImpliesFullURLAccess |
|
|
|
|
APIPermissionInfo::kFlagCannotBeOptional |
|
|
|
|
APIPermissionInfo::kFlagInternal},
|
|
|
|
};
|
|
|
|
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 {
|
|
|
|
|
|
|
|
AtomExtensionsAPIProvider::AtomExtensionsAPIProvider() = default;
|
|
|
|
AtomExtensionsAPIProvider::~AtomExtensionsAPIProvider() = default;
|
|
|
|
|
|
|
|
// TODO(samuelmaddock): generate API features?
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::AddAPIFeatures(
|
|
|
|
extensions::FeatureProvider* provider) {
|
|
|
|
// AddShellAPIFeatures(provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::AddManifestFeatures(
|
|
|
|
extensions::FeatureProvider* provider) {
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
// TODO(samuelmaddock): why is the extensions namespace generated?
|
|
|
|
extensions::AddAtomManifestFeatures(provider);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::AddPermissionFeatures(
|
|
|
|
extensions::FeatureProvider* provider) {
|
|
|
|
// No shell-specific permission features.
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::AddBehaviorFeatures(
|
|
|
|
extensions::FeatureProvider* provider) {
|
|
|
|
// No shell-specific behavior features.
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::AddAPIJSONSources(
|
|
|
|
extensions::JSONFeatureProviderSource* json_source) {
|
|
|
|
// json_source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomExtensionsAPIProvider::IsAPISchemaGenerated(const std::string& name) {
|
|
|
|
// return shell::api::ShellGeneratedSchemas::IsGenerated(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::StringPiece AtomExtensionsAPIProvider::GetAPISchema(
|
|
|
|
const std::string& name) {
|
|
|
|
// return shell::api::ShellGeneratedSchemas::Get(name);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomExtensionsAPIProvider::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-01-15 00:20:30 +00:00
|
|
|
void AtomExtensionsAPIProvider::RegisterManifestHandlers() {
|
|
|
|
extensions::ManifestHandlerRegistry* registry =
|
|
|
|
extensions::ManifestHandlerRegistry::Get();
|
|
|
|
registry->RegisterHandler(
|
|
|
|
std::make_unique<extensions::DevToolsPageHandler>());
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
} // namespace electron
|