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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "extensions/browser/app_window/app_window.h" | 29 #include "extensions/browser/app_window/app_window.h" |
30 #include "extensions/browser/app_window/app_window_registry.h" | 30 #include "extensions/browser/app_window/app_window_registry.h" |
31 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
32 #include "extensions/browser/extension_util.h" | 32 #include "extensions/browser/extension_util.h" |
33 #endif | 33 #endif |
34 | 34 |
35 using content::BrowserThread; | 35 using content::BrowserThread; |
36 | 36 |
| 37 namespace extensions { |
| 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 void PrintPackExtensionMessage(const std::string& message) { | 41 void PrintPackExtensionMessage(const std::string& message) { |
40 VLOG(1) << message; | 42 VLOG(1) << message; |
41 } | 43 } |
42 | 44 |
43 // On Windows, the jumplist action for installing an ephemeral app has to use | 45 // On Windows, the jumplist action for installing an ephemeral app has to use |
44 // the --install-from-webstore command line arg to initiate an install. | 46 // the --install-ephemeral-app-from-webstore command line arg to initiate an |
45 scoped_refptr<extensions::WebstoreStandaloneInstaller> | 47 // install. |
46 CreateEphemeralAppInstaller( | 48 scoped_refptr<WebstoreStandaloneInstaller> CreateEphemeralAppInstaller( |
47 Profile* profile, | 49 Profile* profile, |
48 const std::string& app_id, | 50 const std::string& app_id, |
49 extensions::WebstoreStandaloneInstaller::Callback callback) { | 51 WebstoreStandaloneInstaller::Callback callback) { |
50 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer; | 52 scoped_refptr<WebstoreStandaloneInstaller> installer; |
51 | 53 |
52 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
53 using extensions::ExtensionRegistry; | |
54 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 55 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
55 DCHECK(registry); | 56 DCHECK(registry); |
56 if (!registry->GetExtensionById(app_id, ExtensionRegistry::EVERYTHING) || | 57 if (!registry->GetExtensionById(app_id, ExtensionRegistry::EVERYTHING) || |
57 !extensions::util::IsEphemeralApp(app_id, profile)) { | 58 !util::IsEphemeralApp(app_id, profile)) { |
58 return installer; | 59 return installer; |
59 } | 60 } |
60 | 61 |
61 extensions::AppWindowRegistry* app_window_registry = | 62 AppWindowRegistry* app_window_registry = AppWindowRegistry::Get(profile); |
62 extensions::AppWindowRegistry::Get(profile); | |
63 DCHECK(app_window_registry); | 63 DCHECK(app_window_registry); |
64 extensions::AppWindow* app_window = | 64 AppWindow* app_window = |
65 app_window_registry->GetCurrentAppWindowForApp(app_id); | 65 app_window_registry->GetCurrentAppWindowForApp(app_id); |
66 if (!app_window) | 66 if (!app_window) |
67 return installer; | 67 return installer; |
68 | 68 |
69 installer = new extensions::WebstoreInstallWithPrompt( | 69 installer = new WebstoreInstallWithPrompt( |
70 app_id, profile, app_window->GetNativeWindow(), callback); | 70 app_id, profile, app_window->GetNativeWindow(), callback); |
71 #endif | 71 #endif |
72 | 72 |
73 return installer; | 73 return installer; |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 namespace extensions { | |
79 | |
80 StartupHelper::StartupHelper() : pack_job_succeeded_(false) { | 78 StartupHelper::StartupHelper() : pack_job_succeeded_(false) { |
81 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); | 79 ExtensionsClient::Set(ChromeExtensionsClient::GetInstance()); |
82 } | 80 } |
83 | 81 |
84 void StartupHelper::OnPackSuccess( | 82 void StartupHelper::OnPackSuccess( |
85 const base::FilePath& crx_path, | 83 const base::FilePath& crx_path, |
86 const base::FilePath& output_private_key_path) { | 84 const base::FilePath& output_private_key_path) { |
87 pack_job_succeeded_ = true; | 85 pack_job_succeeded_ = true; |
88 PrintPackExtensionMessage( | 86 PrintPackExtensionMessage( |
89 base::UTF16ToUTF8( | 87 base::UTF16ToUTF8( |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 const std::string& id, | 279 const std::string& id, |
282 bool show_prompt, | 280 bool show_prompt, |
283 DoneCallback done_callback) { | 281 DoneCallback done_callback) { |
284 done_callback_ = done_callback; | 282 done_callback_ = done_callback; |
285 | 283 |
286 WebstoreStandaloneInstaller::Callback callback = | 284 WebstoreStandaloneInstaller::Callback callback = |
287 base::Bind(&AppInstallHelper::OnAppInstallComplete, | 285 base::Bind(&AppInstallHelper::OnAppInstallComplete, |
288 base::Unretained(this)); | 286 base::Unretained(this)); |
289 | 287 |
290 installer_ = CreateEphemeralAppInstaller(profile, id, callback); | 288 installer_ = CreateEphemeralAppInstaller(profile, id, callback); |
291 if (!installer_.get()) { | 289 if (installer_.get()) { |
292 installer_ = | 290 installer_->BeginInstall(); |
293 new WebstoreStartupInstaller(id, profile, show_prompt, callback); | 291 } else { |
| 292 error_ = "Not a supported ephemeral app installation."; |
| 293 done_callback_.Run(); |
294 } | 294 } |
295 installer_->BeginInstall(); | |
296 } | 295 } |
297 | 296 |
298 void AppInstallHelper::OnAppInstallComplete(bool success, | 297 void AppInstallHelper::OnAppInstallComplete(bool success, |
299 const std::string& error, | 298 const std::string& error, |
300 webstore_install::Result result) { | 299 webstore_install::Result result) { |
301 success_ = success; | 300 success_ = success; |
302 error_= error; | 301 error_= error; |
303 done_callback_.Run(); | 302 done_callback_.Run(); |
304 } | 303 } |
305 | 304 |
306 void DeleteHelperAndRunCallback(AppInstallHelper* helper, | |
307 base::Callback<void()> callback) { | |
308 delete helper; | |
309 callback.Run(); | |
310 } | |
311 | |
312 } // namespace | 305 } // namespace |
313 | 306 |
314 bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, | 307 bool StartupHelper::InstallEphemeralApp(const CommandLine& cmd_line, |
315 Profile* profile) { | 308 Profile* profile) { |
316 std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore); | 309 std::string id = |
| 310 cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore); |
317 if (!crx_file::id_util::IdIsValid(id)) { | 311 if (!crx_file::id_util::IdIsValid(id)) { |
318 LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore | 312 LOG(ERROR) << "Invalid id for " |
319 << " : '" << id << "'"; | 313 << switches::kInstallEphemeralAppFromWebstore << " : '" << id << "'"; |
320 return false; | 314 return false; |
321 } | 315 } |
322 | 316 |
323 AppInstallHelper helper; | 317 AppInstallHelper helper; |
324 base::RunLoop run_loop; | 318 base::RunLoop run_loop; |
325 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); | 319 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); |
326 run_loop.Run(); | 320 run_loop.Run(); |
327 | 321 |
328 if (!helper.success()) | 322 if (!helper.success()) |
329 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); | 323 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); |
330 return helper.success(); | 324 return helper.success(); |
331 } | 325 } |
332 | 326 |
333 void StartupHelper::LimitedInstallFromWebstore( | |
334 const CommandLine& cmd_line, | |
335 Profile* profile, | |
336 base::Callback<void()> done_callback) { | |
337 std::string id = WebStoreIdFromLimitedInstallCmdLine(cmd_line); | |
338 if (!crx_file::id_util::IdIsValid(id)) { | |
339 LOG(ERROR) << "Invalid index for " << switches::kLimitedInstallFromWebstore; | |
340 done_callback.Run(); | |
341 return; | |
342 } | |
343 | |
344 AppInstallHelper* helper = new AppInstallHelper(); | |
345 helper->BeginInstall(profile, id, false /*show_prompt*/, | |
346 base::Bind(&DeleteHelperAndRunCallback, | |
347 helper, done_callback)); | |
348 } | |
349 | |
350 std::string StartupHelper::WebStoreIdFromLimitedInstallCmdLine( | |
351 const CommandLine& cmd_line) { | |
352 std::string index = cmd_line.GetSwitchValueASCII( | |
353 switches::kLimitedInstallFromWebstore); | |
354 std::string id; | |
355 if (index == "1") { | |
356 id = "nckgahadagoaajjgafhacjanaoiihapd"; | |
357 } else if (index == "2") { | |
358 id = "ecglahbcnmdpdciemllbhojghbkagdje"; | |
359 } | |
360 return id; | |
361 } | |
362 | |
363 StartupHelper::~StartupHelper() { | 327 StartupHelper::~StartupHelper() { |
364 if (pack_job_.get()) | 328 if (pack_job_.get()) |
365 pack_job_->ClearClient(); | 329 pack_job_->ClearClient(); |
366 } | 330 } |
367 | 331 |
368 } // namespace extensions | 332 } // namespace extensions |
OLD | NEW |