2019-07-24 23:01:08 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/common/extensions/electron_extensions_client.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2024-01-12 13:50:29 +00:00
|
|
|
#include "base/no_destructor.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "components/version_info/version_info.h"
|
|
|
|
#include "content/public/common/user_agent.h"
|
|
|
|
#include "extensions/common/core_extensions_api_provider.h"
|
|
|
|
#include "extensions/common/extension_urls.h"
|
|
|
|
#include "extensions/common/features/simple_feature.h"
|
|
|
|
#include "extensions/common/permissions/permission_message_provider.h"
|
|
|
|
#include "extensions/common/url_pattern_set.h"
|
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
|
|
|
|
|
|
|
using extensions::ExtensionsClient;
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share
|
|
|
|
// code. For now, this implementation does nothing.
|
2020-02-03 22:01:10 +00:00
|
|
|
class ElectronPermissionMessageProvider
|
2019-07-24 23:01:08 +00:00
|
|
|
: public extensions::PermissionMessageProvider {
|
|
|
|
public:
|
2021-06-04 04:16:13 +00:00
|
|
|
ElectronPermissionMessageProvider() = default;
|
|
|
|
~ElectronPermissionMessageProvider() override = default;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronPermissionMessageProvider(const ElectronPermissionMessageProvider&) =
|
|
|
|
delete;
|
|
|
|
ElectronPermissionMessageProvider& operator=(
|
|
|
|
const ElectronPermissionMessageProvider&) = delete;
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
// PermissionMessageProvider implementation.
|
|
|
|
extensions::PermissionMessages GetPermissionMessages(
|
|
|
|
const extensions::PermissionIDSet& permissions) const override {
|
|
|
|
return extensions::PermissionMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPrivilegeIncrease(
|
|
|
|
const extensions::PermissionSet& granted_permissions,
|
|
|
|
const extensions::PermissionSet& requested_permissions,
|
|
|
|
extensions::Manifest::Type extension_type) const override {
|
|
|
|
// Ensure we implement this before shipping.
|
|
|
|
CHECK(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
extensions::PermissionIDSet GetAllPermissionIDs(
|
|
|
|
const extensions::PermissionSet& permissions,
|
|
|
|
extensions::Manifest::Type extension_type) const override {
|
|
|
|
return extensions::PermissionIDSet();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsClient::ElectronExtensionsClient()
|
2019-07-24 23:01:08 +00:00
|
|
|
: webstore_base_url_(extension_urls::kChromeWebstoreBaseURL),
|
2022-09-07 07:46:37 +00:00
|
|
|
new_webstore_base_url_(extension_urls::kNewChromeWebstoreBaseURL),
|
2019-07-24 23:01:08 +00:00
|
|
|
webstore_update_url_(extension_urls::kChromeWebstoreUpdateURL) {
|
|
|
|
AddAPIProvider(std::make_unique<extensions::CoreExtensionsAPIProvider>());
|
2020-02-03 22:01:10 +00:00
|
|
|
AddAPIProvider(std::make_unique<ElectronExtensionsAPIProvider>());
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 04:16:13 +00:00
|
|
|
ElectronExtensionsClient::~ElectronExtensionsClient() = default;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsClient::Initialize() {
|
2019-07-24 23:01:08 +00:00
|
|
|
// TODO(jamescook): Do we need to whitelist any extensions?
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsClient::InitializeWebStoreUrls(
|
2019-07-24 23:01:08 +00:00
|
|
|
base::CommandLine* command_line) {}
|
|
|
|
|
|
|
|
const extensions::PermissionMessageProvider&
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsClient::GetPermissionMessageProvider() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
NOTIMPLEMENTED();
|
2024-01-12 13:50:29 +00:00
|
|
|
|
|
|
|
static base::NoDestructor<ElectronPermissionMessageProvider> instance;
|
|
|
|
return *instance;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
const std::string ElectronExtensionsClient::GetProductName() {
|
2019-07-24 23:01:08 +00:00
|
|
|
// TODO(samuelmaddock):
|
|
|
|
return "app_shell";
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsClient::FilterHostPermissions(
|
2019-07-24 23:01:08 +00:00
|
|
|
const extensions::URLPatternSet& hosts,
|
|
|
|
extensions::URLPatternSet* new_hosts,
|
|
|
|
extensions::PermissionIDSet* permissions) const {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
void ElectronExtensionsClient::SetScriptingAllowlist(
|
|
|
|
const ExtensionsClient::ScriptingAllowlist& allowlist) {
|
|
|
|
scripting_allowlist_ = allowlist;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
const ExtensionsClient::ScriptingAllowlist&
|
|
|
|
ElectronExtensionsClient::GetScriptingAllowlist() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
// TODO(jamescook): Real whitelist.
|
2020-07-14 01:13:34 +00:00
|
|
|
return scripting_allowlist_;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
extensions::URLPatternSet
|
|
|
|
ElectronExtensionsClient::GetPermittedChromeSchemeHosts(
|
2019-07-24 23:01:08 +00:00
|
|
|
const extensions::Extension* extension,
|
|
|
|
const extensions::APIPermissionSet& api_permissions) const {
|
|
|
|
return extensions::URLPatternSet();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsClient::IsScriptableURL(const GURL& url,
|
|
|
|
std::string* error) const {
|
2019-07-24 23:01:08 +00:00
|
|
|
// No restrictions on URLs.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
const GURL& ElectronExtensionsClient::GetWebstoreBaseURL() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
return webstore_base_url_;
|
|
|
|
}
|
|
|
|
|
2022-09-07 07:46:37 +00:00
|
|
|
const GURL& ElectronExtensionsClient::GetNewWebstoreBaseURL() const {
|
|
|
|
return new_webstore_base_url_;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
const GURL& ElectronExtensionsClient::GetWebstoreUpdateURL() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
return webstore_update_url_;
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
bool ElectronExtensionsClient::IsBlocklistUpdateURL(const GURL& url) const {
|
2020-12-18 23:11:43 +00:00
|
|
|
return false;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|