Close crashed incognito-mode app's shell window.
[chromium-blink-merge.git] / apps / shell / shell_extension_system.cc
blob1e009a34913ad28e84d8d9f18064d9404b50d71e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "apps/shell/shell_extension_system.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/common/extensions/extension_file_util.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h"
18 #include "extensions/browser/event_router.h"
19 #include "extensions/browser/extension_prefs.h"
20 #include "extensions/browser/extension_prefs_factory.h"
21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_registry_factory.h"
23 #include "extensions/browser/info_map.h"
24 #include "extensions/browser/lazy_background_task_queue.h"
25 #include "extensions/browser/process_manager.h"
26 #include "extensions/browser/runtime_data.h"
28 using content::BrowserContext;
29 using content::BrowserThread;
31 namespace extensions {
33 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
34 : browser_context_(browser_context) {
37 ShellExtensionSystem::~ShellExtensionSystem() {
40 // static
41 std::vector<BrowserContextKeyedServiceFactory*>
42 ShellExtensionSystem::GetDependencies() {
43 std::vector<BrowserContextKeyedServiceFactory*> depends_on;
44 depends_on.push_back(ExtensionPrefsFactory::GetInstance());
45 depends_on.push_back(ExtensionRegistryFactory::GetInstance());
46 return depends_on;
49 bool ShellExtensionSystem::LoadAndLaunchApp(const base::FilePath& app_dir) {
50 std::string load_error;
51 scoped_refptr<Extension> extension =
52 extension_file_util::LoadExtension(app_dir,
53 extensions::Manifest::COMMAND_LINE,
54 Extension::NO_FLAGS,
55 &load_error);
56 if (!extension) {
57 LOG(ERROR) << "Loading extension at " << app_dir.value()
58 << " failed with: " << load_error;
59 return false;
62 // TODO(jamescook): We may want to do some of these things here:
63 // * Create a PermissionsUpdater.
64 // * Call PermissionsUpdater::GrantActivePermissions().
65 // * Call ExtensionService::SatisfyImports().
66 // * Call ExtensionPrefs::OnExtensionInstalled().
67 // * Send NOTIFICATION_EXTENSION_INSTALLED.
69 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension);
71 RegisterExtensionWithRequestContexts(extension);
73 content::NotificationService::current()->Notify(
74 chrome::NOTIFICATION_EXTENSION_LOADED,
75 content::Source<BrowserContext>(browser_context_),
76 content::Details<const Extension>(extension));
78 // Inform the rest of the extensions system to start.
79 ready_.Signal();
80 content::NotificationService::current()->Notify(
81 chrome::NOTIFICATION_EXTENSIONS_READY,
82 content::Source<BrowserContext>(browser_context_),
83 content::NotificationService::NoDetails());
85 return true;
88 void ShellExtensionSystem::Shutdown() {
91 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
92 runtime_data_.reset(
93 new RuntimeData(ExtensionRegistry::Get(browser_context_)));
94 lazy_background_task_queue_.reset(
95 new LazyBackgroundTaskQueue(browser_context_));
96 event_router_.reset(
97 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_)));
98 process_manager_.reset(ProcessManager::Create(browser_context_));
101 ExtensionService* ShellExtensionSystem::extension_service() {
102 return NULL;
105 RuntimeData* ShellExtensionSystem::runtime_data() {
106 return runtime_data_.get();
109 ManagementPolicy* ShellExtensionSystem::management_policy() {
110 return NULL;
113 UserScriptMaster* ShellExtensionSystem::user_script_master() {
114 return NULL;
117 ProcessManager* ShellExtensionSystem::process_manager() {
118 return process_manager_.get();
121 StateStore* ShellExtensionSystem::state_store() {
122 return NULL;
125 StateStore* ShellExtensionSystem::rules_store() {
126 return NULL;
129 InfoMap* ShellExtensionSystem::info_map() {
130 if (!info_map_.get())
131 info_map_ = new InfoMap;
132 return info_map_;
135 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() {
136 return lazy_background_task_queue_.get();
139 EventRouter* ShellExtensionSystem::event_router() {
140 return event_router_.get();
143 ExtensionWarningService* ShellExtensionSystem::warning_service() {
144 return NULL;
147 Blacklist* ShellExtensionSystem::blacklist() {
148 return NULL;
151 ErrorConsole* ShellExtensionSystem::error_console() {
152 return NULL;
155 InstallVerifier* ShellExtensionSystem::install_verifier() {
156 return NULL;
159 void ShellExtensionSystem::RegisterExtensionWithRequestContexts(
160 const Extension* extension) {
161 BrowserThread::PostTask(
162 BrowserThread::IO, FROM_HERE,
163 base::Bind(&InfoMap::AddExtension, info_map(),
164 make_scoped_refptr(extension), base::Time::Now(),
165 false, false));
168 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts(
169 const std::string& extension_id,
170 const UnloadedExtensionInfo::Reason reason) {
173 const OneShotEvent& ShellExtensionSystem::ready() const {
174 return ready_;
177 } // namespace extensions