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/installer/setup/install.h" | 5 #include "chrome/installer/setup/install.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 #include <time.h> | 8 #include <time.h> |
9 #include <winuser.h> | 9 #include <winuser.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "base/win/shortcut.h" | 22 #include "base/win/shortcut.h" |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_switches.h" | |
25 #include "chrome/installer/setup/setup_constants.h" | 26 #include "chrome/installer/setup/setup_constants.h" |
26 #include "chrome/installer/setup/install_worker.h" | 27 #include "chrome/installer/setup/install_worker.h" |
27 #include "chrome/installer/util/auto_launch_util.h" | 28 #include "chrome/installer/util/auto_launch_util.h" |
28 #include "chrome/installer/util/browser_distribution.h" | 29 #include "chrome/installer/util/browser_distribution.h" |
29 #include "chrome/installer/util/create_reg_key_work_item.h" | 30 #include "chrome/installer/util/create_reg_key_work_item.h" |
30 #include "chrome/installer/util/delete_after_reboot_helper.h" | 31 #include "chrome/installer/util/delete_after_reboot_helper.h" |
31 #include "chrome/installer/util/google_update_constants.h" | 32 #include "chrome/installer/util/google_update_constants.h" |
32 #include "chrome/installer/util/helper.h" | 33 #include "chrome/installer/util/helper.h" |
33 #include "chrome/installer/util/install_util.h" | 34 #include "chrome/installer/util/install_util.h" |
35 #include "chrome/installer/util/installation_state.h" | |
34 #include "chrome/installer/util/master_preferences.h" | 36 #include "chrome/installer/util/master_preferences.h" |
35 #include "chrome/installer/util/master_preferences_constants.h" | 37 #include "chrome/installer/util/master_preferences_constants.h" |
36 #include "chrome/installer/util/set_reg_value_work_item.h" | 38 #include "chrome/installer/util/set_reg_value_work_item.h" |
37 #include "chrome/installer/util/shell_util.h" | 39 #include "chrome/installer/util/shell_util.h" |
38 #include "chrome/installer/util/util_constants.h" | 40 #include "chrome/installer/util/util_constants.h" |
39 #include "chrome/installer/util/work_item_list.h" | 41 #include "chrome/installer/util/work_item_list.h" |
40 | 42 |
41 // Build-time generated include file. | 43 // Build-time generated include file. |
42 #include "registered_dlls.h" // NOLINT | 44 #include "registered_dlls.h" // NOLINT |
43 | 45 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ? | 265 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ? |
264 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER; | 266 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER; |
265 FilePath uninstall_shortcut_path; | 267 FilePath uninstall_shortcut_path; |
266 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist, | 268 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_START_MENU, dist, |
267 shortcut_level, &uninstall_shortcut_path); | 269 shortcut_level, &uninstall_shortcut_path); |
268 uninstall_shortcut_path = uninstall_shortcut_path.Append( | 270 uninstall_shortcut_path = uninstall_shortcut_path.Append( |
269 dist->GetUninstallLinkName() + installer::kLnkExt); | 271 dist->GetUninstallLinkName() + installer::kLnkExt); |
270 file_util::Delete(uninstall_shortcut_path, false); | 272 file_util::Delete(uninstall_shortcut_path, false); |
271 } | 273 } |
272 | 274 |
275 // Returns the appropriate shortcut operations for App Launcher, | |
276 // based on state of installation and master preference. | |
277 installer::InstallShortcutOperation GetAppLauncherShortcutOperation( | |
278 const InstallationState& original_state, | |
279 const InstallerState& installer_state, | |
280 int version_compare) { | |
281 const installer::ProductState* original_app_host_state = | |
282 original_state.GetProductState(installer_state.system_install(), | |
283 BrowserDistribution::CHROME_APP_HOST); | |
284 bool already_had_app_launcher = original_app_host_state && | |
285 original_app_host_state->channel().IsAppLauncher(); | |
grt (UTC plus 2)
2012/10/25 14:46:53
using the channel id like this will lead to proble
huangs
2012/10/29 21:15:16
Done.
| |
286 | |
287 if (!already_had_app_launcher) | |
288 return installer::INSTALL_SHORTCUT_CREATE_ALL; | |
289 | |
290 if (version_compare >= 0) | |
291 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING; | |
292 | |
293 LOG(ERROR) << "Not sure how we got here"; | |
294 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING; | |
295 } | |
296 | |
273 } // end namespace | 297 } // end namespace |
274 | 298 |
275 namespace installer { | 299 namespace installer { |
276 | 300 |
277 void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) { | 301 void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) { |
278 ReplaceChars(*att_value, L"&", L"&", att_value); | 302 ReplaceChars(*att_value, L"&", L"&", att_value); |
279 ReplaceChars(*att_value, L"'", L"'", att_value); | 303 ReplaceChars(*att_value, L"'", L"'", att_value); |
280 ReplaceChars(*att_value, L"<", L"<", att_value); | 304 ReplaceChars(*att_value, L"<", L"<", att_value); |
281 } | 305 } |
282 | 306 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 << " to " << src_path.value(); | 358 << " to " << src_path.value(); |
335 return true; | 359 return true; |
336 } else { | 360 } else { |
337 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest | 361 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest |
338 << " to " << src_path.value(); | 362 << " to " << src_path.value(); |
339 return false; | 363 return false; |
340 } | 364 } |
341 } | 365 } |
342 } | 366 } |
343 | 367 |
344 void CreateOrUpdateShortcuts(const InstallerState& installer_state, | 368 void CreateOrUpdateShortcuts(const InstallerState& installer_state, |
grt (UTC plus 2)
2012/10/25 14:46:53
this function was written to very specifically han
huangs
2012/10/29 21:15:16
Decided to do shortcut creation as a separate CL.
| |
345 const FilePath& setup_exe, | 369 const FilePath& setup_exe, |
346 const Product& product, | 370 const Product& product, |
347 InstallShortcutOperation install_operation, | 371 InstallShortcutOperation install_operation, |
348 bool alternate_desktop_shortcut) { | 372 bool alternate_desktop_shortcut) { |
349 // TODO(tommi): Change this function to use WorkItemList. | 373 // TODO(tommi): Change this function to use WorkItemList. |
350 DCHECK(product.is_chrome()); | 374 DCHECK(product.is_chrome() || product.is_chrome_app_host()); |
351 | 375 |
352 BrowserDistribution* dist = product.distribution(); | 376 BrowserDistribution* dist = product.distribution(); |
353 const FilePath chrome_exe( | |
354 installer_state.target_path().Append(installer::kChromeExe)); | |
355 ShellUtil::ShellChange install_level = | 377 ShellUtil::ShellChange install_level = |
356 installer_state.system_install() ? ShellUtil::SYSTEM_LEVEL : | 378 installer_state.system_install() ? ShellUtil::SYSTEM_LEVEL : |
357 ShellUtil::CURRENT_USER; | 379 ShellUtil::CURRENT_USER; |
380 // |base_properties|: The basic properties to set on every shortcut installed | |
381 // (to be refined on a per-shortcut basis). | |
382 ShellUtil::ChromeShortcutProperties base_properties(install_level); | |
383 | |
384 base_properties.set_chrome_exe( | |
385 installer_state.target_path().Append(installer::kChromeExe)); | |
386 if (product.is_chrome_app_host()) { | |
erikwright (departed)
2012/10/25 02:23:03
needs to be app_host.exe, not chrome.exe
huangs
2012/10/29 21:15:16
Done. (Deferring to different CL).
| |
387 // Should consult AppListController::GetAppListCommandLine(). | |
388 // TODO(huangs): Append switches::kUserDataDir, perhaps? | |
benwells
2012/10/25 04:50:51
I don't think you can put kUserDataDir here as you
huangs
2012/10/29 21:15:16
Nope. I was looking at
AppListController::GetAppL
| |
389 base_properties.set_arguments( | |
390 string16(L"--").append(ASCIIToUTF16(::switches::kShowAppList))); | |
grt (UTC plus 2)
2012/10/25 14:46:53
i don't like this hacky prepend. please use Comma
huangs
2012/10/29 21:15:16
Done. However, note that this leads to 2 spaces,
grt (UTC plus 2)
2012/10/30 13:02:55
If the spaces cause no harm, just do the simple th
| |
391 } | |
358 | 392 |
359 // The default operation on update is to overwrite shortcuts with the | 393 // The default operation on update is to overwrite shortcuts with the |
360 // currently desired properties, but do so only for shortcuts that still | 394 // currently desired properties, but do so only for shortcuts that still |
361 // exist. | 395 // exist. |
362 ShellUtil::ChromeShortcutOperation shortcut_operation = | 396 ShellUtil::ChromeShortcutOperation shortcut_operation = |
363 ShellUtil::SHORTCUT_REPLACE_EXISTING; | 397 ShellUtil::SHORTCUT_REPLACE_EXISTING; |
364 | |
365 // |base_properties|: The basic properties to set on every shortcut installed | |
366 // (to be refined on a per-shortcut basis). | |
367 ShellUtil::ChromeShortcutProperties base_properties(install_level); | |
368 base_properties.set_chrome_exe(chrome_exe); | |
369 | |
370 // If |install_operation| is INSTALL_SHORTCUT_CREATE_ALL, create optional | 398 // If |install_operation| is INSTALL_SHORTCUT_CREATE_ALL, create optional |
371 // shortcuts (Desktop and Quick Launch) immediately; otherwise delay their | 399 // shortcuts (Desktop and Quick Launch) immediately; otherwise delay their |
372 // creation until first run. | 400 // creation until first run. |
373 if (install_operation == INSTALL_SHORTCUT_CREATE_ALL) | 401 if (install_operation == INSTALL_SHORTCUT_CREATE_ALL) |
374 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS; | 402 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS; |
375 | 403 |
376 ShellUtil::ChromeShortcutProperties desktop_properties(base_properties); | 404 ShellUtil::ChromeShortcutProperties desktop_properties(base_properties); |
377 if (alternate_desktop_shortcut) | 405 if (alternate_desktop_shortcut) |
378 desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName()); | 406 desktop_properties.set_shortcut_name(dist->GetAlternateApplicationName()); |
379 ExecuteAndLogShortcutOperation( | 407 ExecuteAndLogShortcutOperation( |
(...skipping 14 matching lines...) Expand all Loading... | |
394 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist, user_ql_properties, | 422 ShellUtil::SHORTCUT_QUICK_LAUNCH, dist, user_ql_properties, |
395 shortcut_operation); | 423 shortcut_operation); |
396 } | 424 } |
397 | 425 |
398 // Turn on shortcut creation for mandatory shortcuts if requested. | 426 // Turn on shortcut creation for mandatory shortcuts if requested. |
399 if (install_operation == INSTALL_SHORTCUT_CREATE_MANDATORY) | 427 if (install_operation == INSTALL_SHORTCUT_CREATE_MANDATORY) |
400 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS; | 428 shortcut_operation = ShellUtil::SHORTCUT_CREATE_ALWAYS; |
401 | 429 |
402 ShellUtil::ChromeShortcutProperties start_menu_properties(base_properties); | 430 ShellUtil::ChromeShortcutProperties start_menu_properties(base_properties); |
403 // IMPORTANT: Only the default (no arguments and default browserappid) browser | 431 // IMPORTANT: Only the default (no arguments and default browserappid) browser |
404 // shortcut in the Start menu (Start screen on Win8+) should be made dual | 432 // shortcut in the Start menu (Start screen on Win8+) should be made dual |
405 // mode. | 433 // mode. |
406 start_menu_properties.set_dual_mode(true); | 434 start_menu_properties.set_dual_mode(true); |
407 if (shortcut_operation == ShellUtil::SHORTCUT_CREATE_ALWAYS) | 435 if (shortcut_operation == ShellUtil::SHORTCUT_CREATE_ALWAYS) |
408 start_menu_properties.set_pin_to_taskbar(true); | 436 start_menu_properties.set_pin_to_taskbar(true); |
409 ExecuteAndLogShortcutOperation( | 437 ExecuteAndLogShortcutOperation( |
410 ShellUtil::SHORTCUT_START_MENU, dist, start_menu_properties, | 438 ShellUtil::SHORTCUT_START_MENU, dist, start_menu_properties, |
411 shortcut_operation); | 439 shortcut_operation); |
412 } | 440 } |
413 | 441 |
414 void RegisterChromeOnMachine(const InstallerState& installer_state, | 442 void RegisterChromeOnMachine(const InstallerState& installer_state, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 518 |
491 // Update the modifiers on the channel values for the product(s) being | 519 // Update the modifiers on the channel values for the product(s) being |
492 // installed and for the binaries in case of multi-install. | 520 // installed and for the binaries in case of multi-install. |
493 installer_state.UpdateChannels(); | 521 installer_state.UpdateChannels(); |
494 | 522 |
495 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); | 523 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); |
496 | 524 |
497 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) | 525 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) |
498 CopyPreferenceFileForFirstRun(installer_state, prefs_path); | 526 CopyPreferenceFileForFirstRun(installer_state, prefs_path); |
499 | 527 |
500 // Currently this only creates shortcuts for Chrome, but for other products | 528 FilePath setup_exe(installer_state.GetInstallerDirectory(new_version) |
501 // we might want to create shortcuts. | 529 .Append(setup_path.BaseName())); |
530 | |
531 // Creates shortcuts for App Launcher. | |
532 const Product* app_host_install = | |
533 installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST); | |
534 if (app_host_install && app_host_install->HasOption(kOptionAppLauncher)) { | |
535 installer_state.UpdateStage(installer::CREATING_SHORTCUTS); | |
536 | |
537 InstallShortcutOperation app_launcher_shortcut_operation = | |
538 GetAppLauncherShortcutOperation( | |
539 original_state, installer_state, | |
540 new_version.CompareTo(*existing_version)); | |
541 | |
542 bool alt_shortcut = false; | |
543 prefs.GetBool(master_preferences::kAltShortcutText, &alt_shortcut); | |
544 | |
545 CreateOrUpdateShortcuts(installer_state, setup_exe, *app_host_install, | |
546 app_launcher_shortcut_operation, alt_shortcut); | |
547 } | |
548 | |
549 // Creates shortcuts for Chrome. | |
502 const Product* chrome_install = | 550 const Product* chrome_install = |
503 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); | 551 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); |
504 if (chrome_install) { | 552 if (chrome_install) { |
505 installer_state.UpdateStage(installer::CREATING_SHORTCUTS); | 553 installer_state.UpdateStage(installer::CREATING_SHORTCUTS); |
506 | 554 |
507 BrowserDistribution* dist = chrome_install->distribution(); | 555 BrowserDistribution* dist = chrome_install->distribution(); |
508 CleanupLegacyShortcuts(installer_state, dist); | 556 CleanupLegacyShortcuts(installer_state, dist); |
509 | 557 |
510 bool create_all_shortcuts = false; | 558 bool create_all_shortcuts = false; |
511 prefs.GetBool(master_preferences::kCreateAllShortcuts, | 559 prefs.GetBool(master_preferences::kCreateAllShortcuts, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 634 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
587 VLOG(1) << "Updating and registering shortcuts."; | 635 VLOG(1) << "Updating and registering shortcuts."; |
588 CreateOrUpdateShortcuts( | 636 CreateOrUpdateShortcuts( |
589 installer_state, setup_exe, chrome, INSTALL_SHORTCUT_REPLACE_EXISTING, | 637 installer_state, setup_exe, chrome, INSTALL_SHORTCUT_REPLACE_EXISTING, |
590 false); | 638 false); |
591 RegisterChromeOnMachine(installer_state, chrome, false); | 639 RegisterChromeOnMachine(installer_state, chrome, false); |
592 } | 640 } |
593 } | 641 } |
594 | 642 |
595 } // namespace installer | 643 } // namespace installer |
OLD | NEW |