Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/shell/browser/shell_extension_system.h" | 5 #include "extensions/shell/browser/shell_extension_system.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 namespace extensions { | 31 namespace extensions { |
| 32 | 32 |
| 33 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) | 33 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) |
| 34 : browser_context_(browser_context) { | 34 : browser_context_(browser_context) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 ShellExtensionSystem::~ShellExtensionSystem() { | 37 ShellExtensionSystem::~ShellExtensionSystem() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) { | 40 const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) { |
| 41 // app_shell only supports unpacked extensions. | 41 // app_shell only supports unpacked extensions. |
| 42 // NOTE: If you add packed extension support consider removing the flag | 42 // NOTE: If you add packed extension support consider removing the flag |
| 43 // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks. | 43 // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks. |
| 44 CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe(); | 44 CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe(); |
| 45 int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE; | 45 int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE; |
| 46 std::string load_error; | 46 std::string load_error; |
| 47 extension_ = file_util::LoadExtension( | 47 scoped_refptr<Extension> extension_refptr = file_util::LoadExtension( |
|
James Cook
2014/10/23 21:29:52
nit: I find it awkward to have both extension_refp
lfg
2014/10/23 22:04:05
Done.
| |
| 48 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); | 48 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); |
| 49 if (!extension_.get()) { | 49 Extension* extension = extension_refptr.get(); |
| 50 if (!extension) { | |
| 50 LOG(ERROR) << "Loading extension at " << app_dir.value() | 51 LOG(ERROR) << "Loading extension at " << app_dir.value() |
| 51 << " failed with: " << load_error; | 52 << " failed with: " << load_error; |
| 52 return false; | 53 return nullptr; |
| 53 } | 54 } |
| 54 app_id_ = extension_->id(); | |
| 55 | 55 |
| 56 // TODO(jamescook): We may want to do some of these things here: | 56 // TODO(jamescook): We may want to do some of these things here: |
| 57 // * Create a PermissionsUpdater. | 57 // * Create a PermissionsUpdater. |
| 58 // * Call PermissionsUpdater::GrantActivePermissions(). | 58 // * Call PermissionsUpdater::GrantActivePermissions(). |
| 59 // * Call ExtensionService::SatisfyImports(). | 59 // * Call ExtensionService::SatisfyImports(). |
| 60 // * Call ExtensionPrefs::OnExtensionInstalled(). | 60 // * Call ExtensionPrefs::OnExtensionInstalled(). |
| 61 // * Send NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED. | 61 // * Send NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED. |
| 62 | 62 |
| 63 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension_); | 63 extensions_.Insert(extension_refptr); |
|
James Cook
2014/10/23 21:29:53
Do you need extensions_ at all? Can you just get t
lfg
2014/10/23 22:04:05
Indeed, that is not necessary. Removed.
| |
| 64 | 64 |
| 65 RegisterExtensionWithRequestContexts(extension_.get()); | 65 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension_refptr); |
| 66 | |
| 67 RegisterExtensionWithRequestContexts(extension); | |
| 66 | 68 |
| 67 content::NotificationService::current()->Notify( | 69 content::NotificationService::current()->Notify( |
| 68 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 70 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 69 content::Source<BrowserContext>(browser_context_), | 71 content::Source<BrowserContext>(browser_context_), |
| 70 content::Details<const Extension>(extension_.get())); | 72 content::Details<const Extension>(extension)); |
| 71 | 73 |
| 74 return extension; | |
| 75 } | |
| 76 | |
| 77 bool ShellExtensionSystem::Init() { | |
| 72 // Inform the rest of the extensions system to start. | 78 // Inform the rest of the extensions system to start. |
| 73 ready_.Signal(); | 79 ready_.Signal(); |
| 74 content::NotificationService::current()->Notify( | 80 content::NotificationService::current()->Notify( |
| 75 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 81 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 76 content::Source<BrowserContext>(browser_context_), | 82 content::Source<BrowserContext>(browser_context_), |
| 77 content::NotificationService::NoDetails()); | 83 content::NotificationService::NoDetails()); |
| 78 return true; | 84 return true; |
| 79 } | 85 } |
| 80 | 86 |
| 81 void ShellExtensionSystem::LaunchApp() { | 87 void ShellExtensionSystem::LaunchApp(const ExtensionId& extension_id) { |
| 82 // Send the onLaunched event. | 88 // Send the onLaunched event. |
| 83 DCHECK(extension_.get()); | 89 DCHECK(extensions_.Contains(extension_id)); |
| 84 AppRuntimeEventRouter::DispatchOnLaunchedEvent(browser_context_, | 90 const Extension* extension = extensions_.GetByID(extension_id); |
| 85 extension_.get()); | 91 AppRuntimeEventRouter::DispatchOnLaunchedEvent(browser_context_, extension); |
| 86 } | 92 } |
| 87 | 93 |
| 88 void ShellExtensionSystem::Shutdown() { | 94 void ShellExtensionSystem::Shutdown() { |
| 89 } | 95 } |
| 90 | 96 |
| 91 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { | 97 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { |
| 92 runtime_data_.reset( | 98 runtime_data_.reset( |
| 93 new RuntimeData(ExtensionRegistry::Get(browser_context_))); | 99 new RuntimeData(ExtensionRegistry::Get(browser_context_))); |
| 94 lazy_background_task_queue_.reset( | 100 lazy_background_task_queue_.reset( |
| 95 new LazyBackgroundTaskQueue(browser_context_)); | 101 new LazyBackgroundTaskQueue(browser_context_)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 return make_scoped_ptr(new ExtensionSet()); | 197 return make_scoped_ptr(new ExtensionSet()); |
| 192 } | 198 } |
| 193 | 199 |
| 194 DeclarativeUserScriptMaster* | 200 DeclarativeUserScriptMaster* |
| 195 ShellExtensionSystem::GetDeclarativeUserScriptMasterByExtension( | 201 ShellExtensionSystem::GetDeclarativeUserScriptMasterByExtension( |
| 196 const ExtensionId& extension_id) { | 202 const ExtensionId& extension_id) { |
| 197 return NULL; | 203 return NULL; |
| 198 } | 204 } |
| 199 | 205 |
| 200 } // namespace extensions | 206 } // namespace extensions |
| OLD | NEW |