| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "apps/shell/shell_extension_system.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 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" | |
| 27 | |
| 28 using content::BrowserContext; | |
| 29 using content::BrowserThread; | |
| 30 | |
| 31 namespace extensions { | |
| 32 | |
| 33 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) | |
| 34 : browser_context_(browser_context) { | |
| 35 } | |
| 36 | |
| 37 ShellExtensionSystem::~ShellExtensionSystem() { | |
| 38 } | |
| 39 | |
| 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; | |
| 47 } | |
| 48 | |
| 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; | |
| 60 } | |
| 61 | |
| 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. | |
| 68 | |
| 69 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension); | |
| 70 | |
| 71 RegisterExtensionWithRequestContexts(extension); | |
| 72 | |
| 73 content::NotificationService::current()->Notify( | |
| 74 chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 75 content::Source<BrowserContext>(browser_context_), | |
| 76 content::Details<const Extension>(extension)); | |
| 77 | |
| 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()); | |
| 84 | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 void ShellExtensionSystem::Shutdown() { | |
| 89 } | |
| 90 | |
| 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_)); | |
| 99 } | |
| 100 | |
| 101 ExtensionService* ShellExtensionSystem::extension_service() { | |
| 102 return NULL; | |
| 103 } | |
| 104 | |
| 105 RuntimeData* ShellExtensionSystem::runtime_data() { | |
| 106 return runtime_data_.get(); | |
| 107 } | |
| 108 | |
| 109 ManagementPolicy* ShellExtensionSystem::management_policy() { | |
| 110 return NULL; | |
| 111 } | |
| 112 | |
| 113 UserScriptMaster* ShellExtensionSystem::user_script_master() { | |
| 114 return NULL; | |
| 115 } | |
| 116 | |
| 117 ProcessManager* ShellExtensionSystem::process_manager() { | |
| 118 return process_manager_.get(); | |
| 119 } | |
| 120 | |
| 121 StateStore* ShellExtensionSystem::state_store() { | |
| 122 return NULL; | |
| 123 } | |
| 124 | |
| 125 StateStore* ShellExtensionSystem::rules_store() { | |
| 126 return NULL; | |
| 127 } | |
| 128 | |
| 129 InfoMap* ShellExtensionSystem::info_map() { | |
| 130 if (!info_map_.get()) | |
| 131 info_map_ = new InfoMap; | |
| 132 return info_map_; | |
| 133 } | |
| 134 | |
| 135 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() { | |
| 136 return lazy_background_task_queue_.get(); | |
| 137 } | |
| 138 | |
| 139 EventRouter* ShellExtensionSystem::event_router() { | |
| 140 return event_router_.get(); | |
| 141 } | |
| 142 | |
| 143 ExtensionWarningService* ShellExtensionSystem::warning_service() { | |
| 144 return NULL; | |
| 145 } | |
| 146 | |
| 147 Blacklist* ShellExtensionSystem::blacklist() { | |
| 148 return NULL; | |
| 149 } | |
| 150 | |
| 151 ErrorConsole* ShellExtensionSystem::error_console() { | |
| 152 return NULL; | |
| 153 } | |
| 154 | |
| 155 InstallVerifier* ShellExtensionSystem::install_verifier() { | |
| 156 return NULL; | |
| 157 } | |
| 158 | |
| 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)); | |
| 166 } | |
| 167 | |
| 168 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts( | |
| 169 const std::string& extension_id, | |
| 170 const UnloadedExtensionInfo::Reason reason) { | |
| 171 } | |
| 172 | |
| 173 const OneShotEvent& ShellExtensionSystem::ready() const { | |
| 174 return ready_; | |
| 175 } | |
| 176 | |
| 177 } // namespace extensions | |
| OLD | NEW |