[OriginChip] Show the default search provider in the Omnibox hint text.
[chromium-blink-merge.git] / apps / shell / browser / shell_extension_system.cc
blob324368fa76c7681a133da40b0223391447accf41
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/browser/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/quota_service.h"
27 #include "extensions/browser/runtime_data.h"
29 using content::BrowserContext;
30 using content::BrowserThread;
32 namespace extensions {
34 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
35 : browser_context_(browser_context) {
38 ShellExtensionSystem::~ShellExtensionSystem() {
41 // static
42 std::vector<BrowserContextKeyedServiceFactory*>
43 ShellExtensionSystem::GetDependencies() {
44 std::vector<BrowserContextKeyedServiceFactory*> depends_on;
45 depends_on.push_back(ExtensionPrefsFactory::GetInstance());
46 depends_on.push_back(ExtensionRegistryFactory::GetInstance());
47 return depends_on;
50 bool ShellExtensionSystem::LoadAndLaunchApp(const base::FilePath& app_dir) {
51 std::string load_error;
52 scoped_refptr<Extension> extension =
53 extension_file_util::LoadExtension(app_dir,
54 extensions::Manifest::COMMAND_LINE,
55 Extension::NO_FLAGS,
56 &load_error);
57 if (!extension) {
58 LOG(ERROR) << "Loading extension at " << app_dir.value()
59 << " failed with: " << load_error;
60 return false;
63 // TODO(jamescook): We may want to do some of these things here:
64 // * Create a PermissionsUpdater.
65 // * Call PermissionsUpdater::GrantActivePermissions().
66 // * Call ExtensionService::SatisfyImports().
67 // * Call ExtensionPrefs::OnExtensionInstalled().
68 // * Send NOTIFICATION_EXTENSION_INSTALLED.
70 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension);
72 RegisterExtensionWithRequestContexts(extension);
74 content::NotificationService::current()->Notify(
75 chrome::NOTIFICATION_EXTENSION_LOADED,
76 content::Source<BrowserContext>(browser_context_),
77 content::Details<const Extension>(extension));
79 // Inform the rest of the extensions system to start.
80 ready_.Signal();
81 content::NotificationService::current()->Notify(
82 chrome::NOTIFICATION_EXTENSIONS_READY,
83 content::Source<BrowserContext>(browser_context_),
84 content::NotificationService::NoDetails());
86 // This is effectively the same behavior as
87 // extensions::AppEventRouter::DispatchOnLaunchedEvent without any dependency
88 // on ExtensionSystem or Profile.
89 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue());
90 launch_data->SetBoolean("isKioskSession", false);
91 scoped_ptr<base::ListValue> event_args(new base::ListValue());
92 event_args->Append(launch_data.release());
93 scoped_ptr<Event> event(
94 new Event("app.runtime.onLaunched", event_args.Pass()));
95 event_router_->DispatchEventWithLazyListener(extension->id(), event.Pass());
97 return true;
100 void ShellExtensionSystem::Shutdown() {
103 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
104 runtime_data_.reset(
105 new RuntimeData(ExtensionRegistry::Get(browser_context_)));
106 lazy_background_task_queue_.reset(
107 new LazyBackgroundTaskQueue(browser_context_));
108 event_router_.reset(
109 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_)));
110 process_manager_.reset(ProcessManager::Create(browser_context_));
111 quota_service_.reset(new QuotaService);
114 ExtensionService* ShellExtensionSystem::extension_service() {
115 return NULL;
118 RuntimeData* ShellExtensionSystem::runtime_data() {
119 return runtime_data_.get();
122 ManagementPolicy* ShellExtensionSystem::management_policy() {
123 return NULL;
126 UserScriptMaster* ShellExtensionSystem::user_script_master() {
127 return NULL;
130 ProcessManager* ShellExtensionSystem::process_manager() {
131 return process_manager_.get();
134 StateStore* ShellExtensionSystem::state_store() {
135 return NULL;
138 StateStore* ShellExtensionSystem::rules_store() {
139 return NULL;
142 InfoMap* ShellExtensionSystem::info_map() {
143 if (!info_map_.get())
144 info_map_ = new InfoMap;
145 return info_map_;
148 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() {
149 return lazy_background_task_queue_.get();
152 EventRouter* ShellExtensionSystem::event_router() {
153 return event_router_.get();
156 ExtensionWarningService* ShellExtensionSystem::warning_service() {
157 return NULL;
160 Blacklist* ShellExtensionSystem::blacklist() {
161 return NULL;
164 ErrorConsole* ShellExtensionSystem::error_console() {
165 return NULL;
168 InstallVerifier* ShellExtensionSystem::install_verifier() {
169 return NULL;
172 QuotaService* ShellExtensionSystem::quota_service() {
173 return quota_service_.get();
176 void ShellExtensionSystem::RegisterExtensionWithRequestContexts(
177 const Extension* extension) {
178 BrowserThread::PostTask(
179 BrowserThread::IO, FROM_HERE,
180 base::Bind(&InfoMap::AddExtension, info_map(),
181 make_scoped_refptr(extension), base::Time::Now(),
182 false, false));
185 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts(
186 const std::string& extension_id,
187 const UnloadedExtensionInfo::Reason reason) {
190 const OneShotEvent& ShellExtensionSystem::ready() const {
191 return ready_;
194 } // namespace extensions