OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/startup_helper.h" | 5 #include "chrome/browser/extensions/startup_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
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 "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 17 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
18 #include "chrome/browser/extensions/webstore_startup_installer.h" | 18 #include "chrome/browser/extensions/webstore_startup_installer.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/extensions/chrome_extensions_client.h" | 21 #include "chrome/common/extensions/chrome_extensions_client.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
25 #include "ipc/ipc_message.h" | 25 #include "ipc/ipc_message.h" |
26 | 26 |
| 27 #if defined(OS_WIN) |
| 28 #include "apps/app_window.h" |
| 29 #include "apps/app_window_registry.h" |
| 30 #include "extensions/browser/extension_registry.h" |
| 31 #include "extensions/browser/extension_util.h" |
| 32 #endif |
| 33 |
27 using content::BrowserThread; | 34 using content::BrowserThread; |
28 | 35 |
29 namespace { | 36 namespace { |
30 | 37 |
31 void PrintPackExtensionMessage(const std::string& message) { | 38 void PrintPackExtensionMessage(const std::string& message) { |
32 VLOG(1) << message; | 39 VLOG(1) << message; |
33 } | 40 } |
34 | 41 |
| 42 // On Windows, the jumplist action for installing an ephemeral app has to use |
| 43 // the --install-from-webstore command line arg to initiate an install. |
| 44 scoped_refptr<extensions::WebstoreStandaloneInstaller> |
| 45 CreateEphemeralAppInstaller( |
| 46 Profile* profile, |
| 47 const std::string& app_id, |
| 48 extensions::WebstoreStandaloneInstaller::Callback callback) { |
| 49 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer; |
| 50 |
| 51 #if defined(OS_WIN) |
| 52 using extensions::ExtensionRegistry; |
| 53 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
| 54 DCHECK(registry); |
| 55 if (!registry->GetExtensionById(app_id, ExtensionRegistry::EVERYTHING) || |
| 56 !extensions::util::IsEphemeralApp(app_id, profile)) { |
| 57 return installer; |
| 58 } |
| 59 |
| 60 apps::AppWindowRegistry* app_window_registry = |
| 61 apps::AppWindowRegistry::Get(profile); |
| 62 DCHECK(app_window_registry); |
| 63 apps::AppWindow* app_window = |
| 64 app_window_registry->GetCurrentAppWindowForApp(app_id); |
| 65 if (!app_window) |
| 66 return installer; |
| 67 |
| 68 installer = new extensions::WebstoreInstallWithPrompt( |
| 69 app_id, profile, app_window->GetNativeWindow(), callback); |
| 70 #endif |
| 71 |
| 72 return installer; |
| 73 } |
| 74 |
35 } // namespace | 75 } // namespace |
36 | 76 |
37 namespace extensions { | 77 namespace extensions { |
38 | 78 |
39 StartupHelper::StartupHelper() : pack_job_succeeded_(false) { | 79 StartupHelper::StartupHelper() : pack_job_succeeded_(false) { |
40 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); | 80 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); |
41 } | 81 } |
42 | 82 |
43 void StartupHelper::OnPackSuccess( | 83 void StartupHelper::OnPackSuccess( |
44 const base::FilePath& crx_path, | 84 const base::FilePath& crx_path, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void AppInstallHelper::BeginInstall( | 278 void AppInstallHelper::BeginInstall( |
239 Profile* profile, | 279 Profile* profile, |
240 const std::string& id, | 280 const std::string& id, |
241 bool show_prompt, | 281 bool show_prompt, |
242 DoneCallback done_callback) { | 282 DoneCallback done_callback) { |
243 done_callback_ = done_callback; | 283 done_callback_ = done_callback; |
244 | 284 |
245 WebstoreStandaloneInstaller::Callback callback = | 285 WebstoreStandaloneInstaller::Callback callback = |
246 base::Bind(&AppInstallHelper::OnAppInstallComplete, | 286 base::Bind(&AppInstallHelper::OnAppInstallComplete, |
247 base::Unretained(this)); | 287 base::Unretained(this)); |
248 installer_ = new WebstoreStartupInstaller( | 288 |
249 id, | 289 installer_ = CreateEphemeralAppInstaller(profile, id, callback); |
250 profile, | 290 if (!installer_.get()) { |
251 show_prompt, | 291 installer_ = |
252 callback); | 292 new WebstoreStartupInstaller(id, profile, show_prompt, callback); |
| 293 } |
253 installer_->BeginInstall(); | 294 installer_->BeginInstall(); |
254 } | 295 } |
255 | 296 |
256 void AppInstallHelper::OnAppInstallComplete(bool success, | 297 void AppInstallHelper::OnAppInstallComplete(bool success, |
257 const std::string& error, | 298 const std::string& error, |
258 webstore_install::Result result) { | 299 webstore_install::Result result) { |
259 success_ = success; | 300 success_ = success; |
260 error_= error; | 301 error_= error; |
261 done_callback_.Run(); | 302 done_callback_.Run(); |
262 } | 303 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 358 } |
318 return id; | 359 return id; |
319 } | 360 } |
320 | 361 |
321 StartupHelper::~StartupHelper() { | 362 StartupHelper::~StartupHelper() { |
322 if (pack_job_.get()) | 363 if (pack_job_.get()) |
323 pack_job_->ClearClient(); | 364 pack_job_->ClearClient(); |
324 } | 365 } |
325 | 366 |
326 } // namespace extensions | 367 } // namespace extensions |
OLD | NEW |