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>
|
|
|
|
|
|
|
|
#include "base/lazy_instance.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/macros.h"
|
|
|
|
#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:
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronPermissionMessageProvider() {}
|
|
|
|
~ElectronPermissionMessageProvider() override {}
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-02-03 22:01:10 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElectronPermissionMessageProvider);
|
2019-07-24 23:01:08 +00:00
|
|
|
};
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
base::LazyInstance<ElectronPermissionMessageProvider>::DestructorAtExit
|
2019-07-24 23:01:08 +00:00
|
|
|
g_permission_message_provider = LAZY_INSTANCE_INITIALIZER;
|
|
|
|
|
|
|
|
} // 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),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsClient::~ElectronExtensionsClient() {}
|
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();
|
|
|
|
return g_permission_message_provider.Get();
|
|
|
|
}
|
|
|
|
|
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-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsClient::SetScriptingWhitelist(
|
2019-07-24 23:01:08 +00:00
|
|
|
const ExtensionsClient::ScriptingWhitelist& whitelist) {
|
|
|
|
scripting_whitelist_ = whitelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ExtensionsClient::ScriptingWhitelist&
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsClient::GetScriptingWhitelist() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
// TODO(jamescook): Real whitelist.
|
|
|
|
return scripting_whitelist_;
|
|
|
|
}
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
|
2019-07-24 23:01:08 +00:00
|
|
|
// 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 electron
|