1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/common/shell_extensions_client.h"
#include <memory>
#include <string>
#include "base/check.h"
#include "base/lazy_instance.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "components/version_info/version_info.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"
#include "extensions/shell/common/shell_extensions_api_provider.h"
namespace extensions {
namespace {
// TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share
// code. For now, this implementation does nothing.
class ShellPermissionMessageProvider : public PermissionMessageProvider {
public:
ShellPermissionMessageProvider() = default;
ShellPermissionMessageProvider(const ShellPermissionMessageProvider&) =
delete;
ShellPermissionMessageProvider& operator=(
const ShellPermissionMessageProvider&) = delete;
~ShellPermissionMessageProvider() override = default;
// PermissionMessageProvider implementation.
PermissionMessages GetPermissionMessages(
const PermissionIDSet& permissions) const override {
return PermissionMessages();
}
bool IsPrivilegeIncrease(const PermissionSet& granted_permissions,
const PermissionSet& requested_permissions,
Manifest::Type extension_type) const override {
// Ensure we implement this before shipping.
NOTREACHED();
}
PermissionIDSet GetAllPermissionIDs(
const PermissionSet& permissions,
Manifest::Type extension_type) const override {
return PermissionIDSet();
}
};
base::LazyInstance<ShellPermissionMessageProvider>::DestructorAtExit
g_permission_message_provider = LAZY_INSTANCE_INITIALIZER;
} // namespace
ShellExtensionsClient::ShellExtensionsClient()
: webstore_base_url_(extension_urls::kChromeWebstoreBaseURL),
new_webstore_base_url_(extension_urls::kNewChromeWebstoreBaseURL),
webstore_update_url_(extension_urls::kChromeWebstoreUpdateURL) {
AddAPIProvider(std::make_unique<CoreExtensionsAPIProvider>());
AddAPIProvider(std::make_unique<ShellExtensionsAPIProvider>());
}
ShellExtensionsClient::~ShellExtensionsClient() {
}
void ShellExtensionsClient::Initialize() {
// TODO(jamescook): Do we need to whitelist any extensions?
}
void ShellExtensionsClient::InitializeWebStoreUrls(
base::CommandLine* command_line) {}
const PermissionMessageProvider&
ShellExtensionsClient::GetPermissionMessageProvider() const {
NOTIMPLEMENTED();
return g_permission_message_provider.Get();
}
const std::string ShellExtensionsClient::GetProductName() {
return "app_shell";
}
void ShellExtensionsClient::FilterHostPermissions(
const URLPatternSet& hosts,
URLPatternSet* new_hosts,
PermissionIDSet* permissions) const {
NOTIMPLEMENTED();
}
void ShellExtensionsClient::SetScriptingAllowlist(
const ScriptingAllowlist& allowlist) {
scripting_allowlist_ = allowlist;
}
const ExtensionsClient::ScriptingAllowlist&
ShellExtensionsClient::GetScriptingAllowlist() const {
// TODO(jamescook): Real allowlist.
return scripting_allowlist_;
}
URLPatternSet ShellExtensionsClient::GetPermittedChromeSchemeHosts(
const Extension* extension,
const APIPermissionSet& api_permissions) const {
NOTIMPLEMENTED();
return URLPatternSet();
}
bool ShellExtensionsClient::IsScriptableURL(const GURL& url,
std::string* error) const {
// No restrictions on URLs.
return true;
}
const GURL& ShellExtensionsClient::GetWebstoreBaseURL() const {
return webstore_base_url_;
}
const GURL& ShellExtensionsClient::GetNewWebstoreBaseURL() const {
return new_webstore_base_url_;
}
const GURL& ShellExtensionsClient::GetWebstoreUpdateURL() const {
return webstore_update_url_;
}
bool ShellExtensionsClient::IsBlocklistUpdateURL(const GURL& url) const {
// TODO(rockot): Maybe we want to do something else here. For now we accept
// any URL as a blocklist URL because we don't really care.
return true;
}
} // namespace extensions
|