| 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/browser/shell_extension_system.h" | 5 #include "apps/shell/browser/shell_extension_system.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "apps/shell/browser/api/shell/shell_api.h" | 9 #include "apps/shell/browser/api/shell/shell_api.h" |
| 10 #include "base/file_util.h" | 10 #include "base/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::LoadAndLaunchApp(const base::FilePath& app_dir) { | 40 bool 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 scoped_refptr<Extension> extension = file_util::LoadExtension( | 47 extension_ = file_util::LoadExtension( |
| 48 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); | 48 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); |
| 49 if (!extension) { | 49 if (!extension_) { |
| 50 LOG(ERROR) << "Loading extension at " << app_dir.value() | 50 LOG(ERROR) << "Loading extension at " << app_dir.value() |
| 51 << " failed with: " << load_error; | 51 << " failed with: " << load_error; |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 app_id_ = extension->id(); | 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_INSTALLED_DEPRECATED. | 61 // * Send NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED. |
| 62 | 62 |
| 63 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension); | 63 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension_); |
| 64 | 64 |
| 65 RegisterExtensionWithRequestContexts(extension); | 65 RegisterExtensionWithRequestContexts(extension_); |
| 66 | 66 |
| 67 content::NotificationService::current()->Notify( | 67 content::NotificationService::current()->Notify( |
| 68 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 68 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 69 content::Source<BrowserContext>(browser_context_), | 69 content::Source<BrowserContext>(browser_context_), |
| 70 content::Details<const Extension>(extension)); | 70 content::Details<const Extension>(extension_)); |
| 71 | 71 |
| 72 // Inform the rest of the extensions system to start. | 72 // Inform the rest of the extensions system to start. |
| 73 ready_.Signal(); | 73 ready_.Signal(); |
| 74 content::NotificationService::current()->Notify( | 74 content::NotificationService::current()->Notify( |
| 75 chrome::NOTIFICATION_EXTENSIONS_READY, | 75 chrome::NOTIFICATION_EXTENSIONS_READY, |
| 76 content::Source<BrowserContext>(browser_context_), | 76 content::Source<BrowserContext>(browser_context_), |
| 77 content::NotificationService::NoDetails()); | 77 content::NotificationService::NoDetails()); |
| 78 | |
| 79 // Send the onLaunched event. | |
| 80 apps::ShellAPI::DispatchOnLaunchedEvent(event_router_.get(), extension.get()); | |
| 81 | |
| 82 return true; | 78 return true; |
| 83 } | 79 } |
| 84 | 80 |
| 81 void ShellExtensionSystem::LaunchApp() { |
| 82 // Send the onLaunched event. |
| 83 DCHECK(extension_.get()); |
| 84 apps::ShellAPI::DispatchOnLaunchedEvent(event_router_.get(), |
| 85 extension_.get()); |
| 86 } |
| 87 |
| 85 void ShellExtensionSystem::Shutdown() { | 88 void ShellExtensionSystem::Shutdown() { |
| 86 } | 89 } |
| 87 | 90 |
| 88 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { | 91 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { |
| 89 runtime_data_.reset( | 92 runtime_data_.reset( |
| 90 new RuntimeData(ExtensionRegistry::Get(browser_context_))); | 93 new RuntimeData(ExtensionRegistry::Get(browser_context_))); |
| 91 lazy_background_task_queue_.reset( | 94 lazy_background_task_queue_.reset( |
| 92 new LazyBackgroundTaskQueue(browser_context_)); | 95 new LazyBackgroundTaskQueue(browser_context_)); |
| 93 event_router_.reset( | 96 event_router_.reset( |
| 94 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); | 97 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 177 |
| 175 const OneShotEvent& ShellExtensionSystem::ready() const { | 178 const OneShotEvent& ShellExtensionSystem::ready() const { |
| 176 return ready_; | 179 return ready_; |
| 177 } | 180 } |
| 178 | 181 |
| 179 ContentVerifier* ShellExtensionSystem::content_verifier() { | 182 ContentVerifier* ShellExtensionSystem::content_verifier() { |
| 180 return NULL; | 183 return NULL; |
| 181 } | 184 } |
| 182 | 185 |
| 183 } // namespace extensions | 186 } // namespace extensions |
| OLD | NEW |