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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
// 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.
#include "extensions/shell/browser/shell_extension_system.h"
#include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/api/app_runtime/app_runtime_api.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/null_app_sorting.h"
#include "extensions/browser/quota_service.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/browser/service_worker_manager.h"
#include "extensions/browser/value_store/value_store_factory_impl.h"
#include "extensions/common/api/app_runtime.h"
#include "extensions/common/constants.h"
#include "extensions/common/file_util.h"
using content::BrowserContext;
using content::BrowserThread;
namespace extensions {
ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
: browser_context_(browser_context),
store_factory_(new ValueStoreFactoryImpl(browser_context->GetPath())),
weak_factory_(this) {}
ShellExtensionSystem::~ShellExtensionSystem() {
}
const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
// app_shell only supports unpacked extensions.
// NOTE: If you add packed extension support consider removing the flag
// FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks.
CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe();
int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
std::string load_error;
scoped_refptr<Extension> extension = file_util::LoadExtension(
app_dir, Manifest::COMMAND_LINE, load_flags, &load_error);
if (!extension.get()) {
LOG(ERROR) << "Loading extension at " << app_dir.value()
<< " failed with: " << load_error;
return nullptr;
}
// Log warnings.
if (extension->install_warnings().size()) {
LOG(WARNING) << "Warnings loading extension at " << app_dir.value() << ":";
for (const auto& warning : extension->install_warnings())
LOG(WARNING) << warning.message;
}
// TODO(jamescook): We may want to do some of these things here:
// * Create a PermissionsUpdater.
// * Call PermissionsUpdater::GrantActivePermissions().
// * Call ExtensionService::SatisfyImports().
// * Call ExtensionPrefs::OnExtensionInstalled().
// * Call ExtensionRegistryObserver::OnExtensionWillbeInstalled().
ExtensionRegistry::Get(browser_context_)->AddEnabled(extension.get());
RegisterExtensionWithRequestContexts(
extension.get(),
base::Bind(
&ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts,
weak_factory_.GetWeakPtr(), extension));
content::NotificationService::current()->Notify(
NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<BrowserContext>(browser_context_),
content::Details<const Extension>(extension.get()));
return extension.get();
}
void ShellExtensionSystem::Init() {
// Inform the rest of the extensions system to start.
ready_.Signal();
content::NotificationService::current()->Notify(
NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
content::Source<BrowserContext>(browser_context_),
content::NotificationService::NoDetails());
}
void ShellExtensionSystem::LaunchApp(const ExtensionId& extension_id) {
// Send the onLaunched event.
DCHECK(ExtensionRegistry::Get(browser_context_)
->enabled_extensions()
.Contains(extension_id));
const Extension* extension = ExtensionRegistry::Get(browser_context_)
->enabled_extensions()
.GetByID(extension_id);
AppRuntimeEventRouter::DispatchOnLaunchedEvent(browser_context_, extension,
SOURCE_UNTRACKED, nullptr);
}
void ShellExtensionSystem::Shutdown() {
}
void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
service_worker_manager_.reset(new ServiceWorkerManager(browser_context_));
runtime_data_.reset(
new RuntimeData(ExtensionRegistry::Get(browser_context_)));
quota_service_.reset(new QuotaService);
app_sorting_.reset(new NullAppSorting);
}
ExtensionService* ShellExtensionSystem::extension_service() {
return nullptr;
}
RuntimeData* ShellExtensionSystem::runtime_data() {
return runtime_data_.get();
}
ManagementPolicy* ShellExtensionSystem::management_policy() {
return nullptr;
}
ServiceWorkerManager* ShellExtensionSystem::service_worker_manager() {
return service_worker_manager_.get();
}
SharedUserScriptMaster* ShellExtensionSystem::shared_user_script_master() {
return nullptr;
}
StateStore* ShellExtensionSystem::state_store() {
return nullptr;
}
StateStore* ShellExtensionSystem::rules_store() {
return nullptr;
}
scoped_refptr<ValueStoreFactory> ShellExtensionSystem::store_factory() {
return store_factory_;
}
InfoMap* ShellExtensionSystem::info_map() {
if (!info_map_.get())
info_map_ = new InfoMap;
return info_map_.get();
}
QuotaService* ShellExtensionSystem::quota_service() {
return quota_service_.get();
}
AppSorting* ShellExtensionSystem::app_sorting() {
return app_sorting_.get();
}
void ShellExtensionSystem::RegisterExtensionWithRequestContexts(
const Extension* extension,
const base::Closure& callback) {
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&InfoMap::AddExtension, info_map(),
base::RetainedRef(extension), base::Time::Now(), false, false),
callback);
}
void ShellExtensionSystem::UnregisterExtensionWithRequestContexts(
const std::string& extension_id,
const UnloadedExtensionInfo::Reason reason) {
}
const OneShotEvent& ShellExtensionSystem::ready() const {
return ready_;
}
ContentVerifier* ShellExtensionSystem::content_verifier() {
return nullptr;
}
std::unique_ptr<ExtensionSet> ShellExtensionSystem::GetDependentExtensions(
const Extension* extension) {
return base::MakeUnique<ExtensionSet>();
}
void ShellExtensionSystem::InstallUpdate(const std::string& extension_id,
const base::FilePath& temp_dir) {
NOTREACHED();
base::DeleteFile(temp_dir, true /* recursive */);
}
void ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts(
scoped_refptr<Extension> extension) {
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
registry->AddReady(extension);
registry->TriggerOnReady(extension.get());
}
} // namespace extensions
|