| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/shell/shell_extension_system.h" | 5 #include "apps/shell/shell_extension_system.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/common/extensions/extension_file_util.h" | 13 #include "chrome/common/extensions/extension_file_util.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 18 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/info_map.h" |
| 20 #include "extensions/browser/lazy_background_task_queue.h" | 22 #include "extensions/browser/lazy_background_task_queue.h" |
| 21 #include "extensions/browser/process_manager.h" | 23 #include "extensions/browser/process_manager.h" |
| 22 | 24 |
| 23 using content::BrowserContext; | 25 using content::BrowserContext; |
| 26 using content::BrowserThread; |
| 24 | 27 |
| 25 namespace extensions { | 28 namespace extensions { |
| 26 | 29 |
| 27 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) | 30 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) |
| 28 : browser_context_(browser_context) { | 31 : browser_context_(browser_context) { |
| 29 } | 32 } |
| 30 | 33 |
| 31 ShellExtensionSystem::~ShellExtensionSystem() { | 34 ShellExtensionSystem::~ShellExtensionSystem() { |
| 32 } | 35 } |
| 33 | 36 |
| 34 bool ShellExtensionSystem::LoadAndLaunchApp(const base::FilePath& app_dir) { | 37 bool ShellExtensionSystem::LoadAndLaunchApp(const base::FilePath& app_dir) { |
| 35 std::string load_error; | 38 std::string load_error; |
| 36 scoped_refptr<Extension> extension = | 39 scoped_refptr<Extension> extension = |
| 37 extension_file_util::LoadExtension(app_dir, | 40 extension_file_util::LoadExtension(app_dir, |
| 38 extensions::Manifest::COMMAND_LINE, | 41 extensions::Manifest::COMMAND_LINE, |
| 39 Extension::NO_FLAGS, | 42 Extension::NO_FLAGS, |
| 40 &load_error); | 43 &load_error); |
| 41 if (!extension) { | 44 if (!extension) { |
| 42 LOG(ERROR) << "Loading extension at " << app_dir.value() | 45 LOG(ERROR) << "Loading extension at " << app_dir.value() |
| 43 << " failed with: " << load_error; | 46 << " failed with: " << load_error; |
| 44 return false; | 47 return false; |
| 45 } | 48 } |
| 46 | 49 |
| 50 // TODO(jamescook): We may want to do some of these things here: |
| 51 // * Create a PermissionsUpdater. |
| 52 // * Call PermissionsUpdater::GrantActivePermissions(). |
| 53 // * Call ExtensionService::SatisfyImports(). |
| 54 // * Call ExtensionPrefs::OnExtensionInstalled(). |
| 55 // * Send NOTIFICATION_EXTENSION_INSTALLED. |
| 56 |
| 47 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension); | 57 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension); |
| 48 | 58 |
| 49 // TODO(jamescook): If RegisterExtensionWithRequestContexts() did something, | 59 RegisterExtensionWithRequestContexts(extension); |
| 50 // this would be the place to call it. | |
| 51 | 60 |
| 52 content::NotificationService::current()->Notify( | 61 content::NotificationService::current()->Notify( |
| 53 chrome::NOTIFICATION_EXTENSION_LOADED, | 62 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 54 content::Source<BrowserContext>(browser_context_), | 63 content::Source<BrowserContext>(browser_context_), |
| 55 content::Details<const Extension>(extension)); | 64 content::Details<const Extension>(extension)); |
| 56 | 65 |
| 57 // Inform the rest of the extensions system to start. | 66 // Inform the rest of the extensions system to start. |
| 58 ready_.Signal(); | 67 ready_.Signal(); |
| 59 LOG(WARNING) << "-----------------------------------"; | |
| 60 LOG(WARNING) << "app_shell is expected to crash now."; | |
| 61 LOG(WARNING) << "-----------------------------------"; | |
| 62 content::NotificationService::current()->Notify( | 68 content::NotificationService::current()->Notify( |
| 63 chrome::NOTIFICATION_EXTENSIONS_READY, | 69 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 64 content::Source<BrowserContext>(browser_context_), | 70 content::Source<BrowserContext>(browser_context_), |
| 65 content::NotificationService::NoDetails()); | 71 content::NotificationService::NoDetails()); |
| 66 | 72 |
| 67 return true; | 73 return true; |
| 68 } | 74 } |
| 69 | 75 |
| 70 void ShellExtensionSystem::Shutdown() { | 76 void ShellExtensionSystem::Shutdown() { |
| 71 } | 77 } |
| 72 | 78 |
| 73 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { | 79 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { |
| 74 lazy_background_task_queue_.reset( | 80 lazy_background_task_queue_.reset( |
| 75 new LazyBackgroundTaskQueue(browser_context_)); | 81 new LazyBackgroundTaskQueue(browser_context_)); |
| 76 event_router_.reset( | 82 event_router_.reset( |
| 77 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); | 83 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); |
| 78 process_manager_.reset(ProcessManager::Create(browser_context_)); | 84 process_manager_.reset(ProcessManager::Create(browser_context_)); |
| 79 } | 85 } |
| 80 | 86 |
| 81 ExtensionService* ShellExtensionSystem::extension_service() { | 87 ExtensionService* ShellExtensionSystem::extension_service() { |
| 82 NOTREACHED(); | |
| 83 return NULL; | 88 return NULL; |
| 84 } | 89 } |
| 85 | 90 |
| 86 ManagementPolicy* ShellExtensionSystem::management_policy() { | 91 ManagementPolicy* ShellExtensionSystem::management_policy() { |
| 87 return NULL; | 92 return NULL; |
| 88 } | 93 } |
| 89 | 94 |
| 90 UserScriptMaster* ShellExtensionSystem::user_script_master() { | 95 UserScriptMaster* ShellExtensionSystem::user_script_master() { |
| 91 return NULL; | 96 return NULL; |
| 92 } | 97 } |
| 93 | 98 |
| 94 ProcessManager* ShellExtensionSystem::process_manager() { | 99 ProcessManager* ShellExtensionSystem::process_manager() { |
| 95 return process_manager_.get(); | 100 return process_manager_.get(); |
| 96 } | 101 } |
| 97 | 102 |
| 98 StateStore* ShellExtensionSystem::state_store() { | 103 StateStore* ShellExtensionSystem::state_store() { |
| 99 return NULL; | 104 return NULL; |
| 100 } | 105 } |
| 101 | 106 |
| 102 StateStore* ShellExtensionSystem::rules_store() { | 107 StateStore* ShellExtensionSystem::rules_store() { |
| 103 return NULL; | 108 return NULL; |
| 104 } | 109 } |
| 105 | 110 |
| 106 InfoMap* ShellExtensionSystem::info_map() { | 111 InfoMap* ShellExtensionSystem::info_map() { |
| 107 return NULL; | 112 if (!info_map_.get()) |
| 113 info_map_ = new InfoMap; |
| 114 return info_map_; |
| 108 } | 115 } |
| 109 | 116 |
| 110 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() { | 117 LazyBackgroundTaskQueue* ShellExtensionSystem::lazy_background_task_queue() { |
| 111 return lazy_background_task_queue_.get(); | 118 return lazy_background_task_queue_.get(); |
| 112 } | 119 } |
| 113 | 120 |
| 114 EventRouter* ShellExtensionSystem::event_router() { | 121 EventRouter* ShellExtensionSystem::event_router() { |
| 115 return event_router_.get(); | 122 return event_router_.get(); |
| 116 } | 123 } |
| 117 | 124 |
| 118 ExtensionWarningService* ShellExtensionSystem::warning_service() { | 125 ExtensionWarningService* ShellExtensionSystem::warning_service() { |
| 119 return NULL; | 126 return NULL; |
| 120 } | 127 } |
| 121 | 128 |
| 122 Blacklist* ShellExtensionSystem::blacklist() { | 129 Blacklist* ShellExtensionSystem::blacklist() { |
| 123 return NULL; | 130 return NULL; |
| 124 } | 131 } |
| 125 | 132 |
| 126 ErrorConsole* ShellExtensionSystem::error_console() { | 133 ErrorConsole* ShellExtensionSystem::error_console() { |
| 127 return NULL; | 134 return NULL; |
| 128 } | 135 } |
| 129 | 136 |
| 130 InstallVerifier* ShellExtensionSystem::install_verifier() { | 137 InstallVerifier* ShellExtensionSystem::install_verifier() { |
| 131 return NULL; | 138 return NULL; |
| 132 } | 139 } |
| 133 | 140 |
| 134 void ShellExtensionSystem::RegisterExtensionWithRequestContexts( | 141 void ShellExtensionSystem::RegisterExtensionWithRequestContexts( |
| 135 const Extension* extension) { | 142 const Extension* extension) { |
| 143 BrowserThread::PostTask( |
| 144 BrowserThread::IO, FROM_HERE, |
| 145 base::Bind(&InfoMap::AddExtension, info_map(), |
| 146 make_scoped_refptr(extension), base::Time::Now(), |
| 147 false, false)); |
| 136 } | 148 } |
| 137 | 149 |
| 138 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts( | 150 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts( |
| 139 const std::string& extension_id, | 151 const std::string& extension_id, |
| 140 const UnloadedExtensionInfo::Reason reason) { | 152 const UnloadedExtensionInfo::Reason reason) { |
| 141 } | 153 } |
| 142 | 154 |
| 143 const OneShotEvent& ShellExtensionSystem::ready() const { | 155 const OneShotEvent& ShellExtensionSystem::ready() const { |
| 144 return ready_; | 156 return ready_; |
| 145 } | 157 } |
| 146 | 158 |
| 147 } // namespace extensions | 159 } // namespace extensions |
| OLD | NEW |