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::LoadAndLaunchApp(const base::FilePath& app_dir) { |
James Cook
2014/06/09 21:59:30
I suggest getting rid of this method and just call
Jun Mukai
2014/06/09 22:04:08
Done.
| |
41 if (!extension_) { | |
42 if (!LoadApp(app_dir)) | |
43 return false; | |
44 } | |
45 LaunchApp(); | |
46 return true; | |
47 } | |
48 | |
49 bool ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) { | |
41 // app_shell only supports unpacked extensions. | 50 // app_shell only supports unpacked extensions. |
42 // NOTE: If you add packed extension support consider removing the flag | 51 // NOTE: If you add packed extension support consider removing the flag |
43 // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks. | 52 // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks. |
44 CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe(); | 53 CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe(); |
45 int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE; | 54 int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE; |
46 std::string load_error; | 55 std::string load_error; |
47 scoped_refptr<Extension> extension = file_util::LoadExtension( | 56 extension_ = file_util::LoadExtension( |
48 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); | 57 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error); |
49 if (!extension) { | 58 if (!extension_) { |
50 LOG(ERROR) << "Loading extension at " << app_dir.value() | 59 LOG(ERROR) << "Loading extension at " << app_dir.value() |
51 << " failed with: " << load_error; | 60 << " failed with: " << load_error; |
52 return false; | 61 return false; |
53 } | 62 } |
54 app_id_ = extension->id(); | 63 app_id_ = extension_->id(); |
55 | 64 |
56 // TODO(jamescook): We may want to do some of these things here: | 65 // TODO(jamescook): We may want to do some of these things here: |
57 // * Create a PermissionsUpdater. | 66 // * Create a PermissionsUpdater. |
58 // * Call PermissionsUpdater::GrantActivePermissions(). | 67 // * Call PermissionsUpdater::GrantActivePermissions(). |
59 // * Call ExtensionService::SatisfyImports(). | 68 // * Call ExtensionService::SatisfyImports(). |
60 // * Call ExtensionPrefs::OnExtensionInstalled(). | 69 // * Call ExtensionPrefs::OnExtensionInstalled(). |
61 // * Send NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED. | 70 // * Send NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED. |
62 | 71 |
63 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension); | 72 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension_); |
64 | 73 |
65 RegisterExtensionWithRequestContexts(extension); | 74 RegisterExtensionWithRequestContexts(extension_); |
66 | 75 |
67 content::NotificationService::current()->Notify( | 76 content::NotificationService::current()->Notify( |
68 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 77 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
69 content::Source<BrowserContext>(browser_context_), | 78 content::Source<BrowserContext>(browser_context_), |
70 content::Details<const Extension>(extension)); | 79 content::Details<const Extension>(extension_)); |
71 | 80 |
72 // Inform the rest of the extensions system to start. | 81 // Inform the rest of the extensions system to start. |
73 ready_.Signal(); | 82 ready_.Signal(); |
74 content::NotificationService::current()->Notify( | 83 content::NotificationService::current()->Notify( |
75 chrome::NOTIFICATION_EXTENSIONS_READY, | 84 chrome::NOTIFICATION_EXTENSIONS_READY, |
76 content::Source<BrowserContext>(browser_context_), | 85 content::Source<BrowserContext>(browser_context_), |
77 content::NotificationService::NoDetails()); | 86 content::NotificationService::NoDetails()); |
78 | |
79 // Send the onLaunched event. | |
80 apps::ShellAPI::DispatchOnLaunchedEvent(event_router_.get(), extension.get()); | |
81 | |
82 return true; | 87 return true; |
83 } | 88 } |
84 | 89 |
90 void ShellExtensionSystem::LaunchApp() { | |
91 // Send the onLaunched event. | |
James Cook
2014/06/09 21:59:30
DCHECK(extension_.get()) ?
Jun Mukai
2014/06/09 22:04:08
Done.
| |
92 apps::ShellAPI::DispatchOnLaunchedEvent(event_router_.get(), | |
93 extension_.get()); | |
94 } | |
95 | |
85 void ShellExtensionSystem::Shutdown() { | 96 void ShellExtensionSystem::Shutdown() { |
86 } | 97 } |
87 | 98 |
88 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { | 99 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { |
89 runtime_data_.reset( | 100 runtime_data_.reset( |
90 new RuntimeData(ExtensionRegistry::Get(browser_context_))); | 101 new RuntimeData(ExtensionRegistry::Get(browser_context_))); |
91 lazy_background_task_queue_.reset( | 102 lazy_background_task_queue_.reset( |
92 new LazyBackgroundTaskQueue(browser_context_)); | 103 new LazyBackgroundTaskQueue(browser_context_)); |
93 event_router_.reset( | 104 event_router_.reset( |
94 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); | 105 new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 | 185 |
175 const OneShotEvent& ShellExtensionSystem::ready() const { | 186 const OneShotEvent& ShellExtensionSystem::ready() const { |
176 return ready_; | 187 return ready_; |
177 } | 188 } |
178 | 189 |
179 ContentVerifier* ShellExtensionSystem::content_verifier() { | 190 ContentVerifier* ShellExtensionSystem::content_verifier() { |
180 return NULL; | 191 return NULL; |
181 } | 192 } |
182 | 193 |
183 } // namespace extensions | 194 } // namespace extensions |
OLD | NEW |