Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/installer/setup/install_worker.cc

Issue 10160011: Create VisualElementsManifest.xml from template -- install VisualElements in the version directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rewording Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This file contains the definitions of the installer functions that build 5 // This file contains the definitions of the installer functions that build
6 // the WorkItemList used to install the application. 6 // the WorkItemList used to install the application.
7 7
8 #include "chrome/installer/setup/install_worker.h" 8 #include "chrome/installer/setup/install_worker.h"
9 9
10 #include <oaidl.h> 10 #include <oaidl.h>
11 #include <shlobj.h> 11 #include <shlobj.h>
12 #include <time.h> 12 #include <time.h>
13
14 #include <string>
13 #include <vector> 15 #include <vector>
14 16
15 #include "base/command_line.h" 17 #include "base/command_line.h"
16 #include "base/file_path.h" 18 #include "base/file_path.h"
17 #include "base/file_util.h" 19 #include "base/file_util.h"
18 #include "base/logging.h" 20 #include "base/logging.h"
19 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/string16.h"
20 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "base/stringprintf.h"
21 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
22 #include "base/version.h" 26 #include "base/version.h"
23 #include "base/win/registry.h" 27 #include "base/win/registry.h"
24 #include "base/win/windows_version.h" 28 #include "base/win/windows_version.h"
25 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
26 #include "chrome/installer/setup/install.h" 30 #include "chrome/installer/setup/install.h"
27 #include "chrome/installer/setup/setup_constants.h" 31 #include "chrome/installer/setup/setup_constants.h"
28 #include "chrome/installer/util/conditional_work_item_list.h" 32 #include "chrome/installer/util/conditional_work_item_list.h"
29 #include "chrome/installer/util/create_reg_key_work_item.h" 33 #include "chrome/installer/util/create_reg_key_work_item.h"
30 #include "chrome/installer/util/google_update_constants.h" 34 #include "chrome/installer/util/google_update_constants.h"
31 #include "chrome/installer/util/helper.h" 35 #include "chrome/installer/util/helper.h"
32 #include "chrome/installer/util/installation_state.h" 36 #include "chrome/installer/util/installation_state.h"
33 #include "chrome/installer/util/installer_state.h" 37 #include "chrome/installer/util/installer_state.h"
34 #include "chrome/installer/util/install_util.h" 38 #include "chrome/installer/util/install_util.h"
35 #include "chrome/installer/util/l10n_string_util.h" 39 #include "chrome/installer/util/l10n_string_util.h"
36 #include "chrome/installer/util/product.h" 40 #include "chrome/installer/util/product.h"
37 #include "chrome/installer/util/set_reg_value_work_item.h" 41 #include "chrome/installer/util/set_reg_value_work_item.h"
38 #include "chrome/installer/util/shell_util.h" 42 #include "chrome/installer/util/shell_util.h"
39 #include "chrome/installer/util/util_constants.h" 43 #include "chrome/installer/util/util_constants.h"
40 #include "chrome/installer/util/work_item_list.h" 44 #include "chrome/installer/util/work_item_list.h"
41 #include "chrome_frame/chrome_tab.h" 45 #include "chrome_frame/chrome_tab.h"
42 46
43 using base::win::RegKey; 47 using base::win::RegKey;
44 48
49 namespace {
50
51 // Elements that make up install target paths.
52 const wchar_t kVisualElementsManifest[] = L"VisualElementsManifest.xml";
53 const wchar_t kWowHelperExe[] = L"wow_helper.exe";
54
55 // Adds work items to |install_list| to lay down a version specific
56 // VisualElementsManifest.xml beside chrome.exe.
57 void AddVisualElementsInstallWorkItems(const FilePath& src_path,
58 const FilePath& target_path,
59 const FilePath& temp_path,
60 const Version& new_version,
61 WorkItemList* install_list) {
62 DCHECK(install_list);
63
64 // Construct the relative path to the Images directory.
grt (UTC plus 2) 2012/05/02 15:09:44 "Images" -> "versioned VisualElements"
gab 2012/05/02 20:55:58 Done. (I Know patch set 7 says "version" --> fixed
65 string16 images_dir(ASCIIToUTF16(new_version.GetString()));
grt (UTC plus 2) 2012/05/02 15:09:44 images_dir -> elements_dir
gab 2012/05/02 20:55:58 Done.
66 images_dir.push_back(FilePath::kSeparators[0]);
67 images_dir.append(L"VisualElements");
68
69 // Some distributions of Chromium may not include visual elements. Only
70 // proceed if this distribution does.
71 if (!file_util::PathExists(src_path.Append(images_dir))) {
72 VLOG(1) << "No visual elements found, skipping related work items.";
73 } else {
74 // A printf_p-style format string for generating the visual elements
75 // manifest. Required arguments, in order, are:
76 // - Localized display name for the product.
77 // - Relative path to the Images directory.
grt (UTC plus 2) 2012/05/02 15:09:44 Images -> VisualElements
gab 2012/05/02 20:55:58 Done.
78 static const char manifest_template[] =
grt (UTC plus 2) 2012/05/02 15:09:44 manifest_template -> kManifestTemplate
gab 2012/05/02 20:55:58 Done.
79 "<Application>\r\n"
80 " <VisualElements\r\n"
81 " DisplayName='%1$ls'\r\n"
82 " Logo='%2$ls\\Logo.png'\r\n"
83 " SmallLogo='%2$ls\\SmallLogo.png'\r\n"
84 " ForegroundText='light'\r\n"
85 " BackgroundColor='white'>\r\n"
86 " <DefaultTile ShowName='allLogos'/>\r\n"
87 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
88 " </VisualElements>\r\n"
89 "</Application>";
90
91 // Fill the manifest with the desired values.
92 const string16 manifest_template16 = ASCIIToUTF16(manifest_template);
grt (UTC plus 2) 2012/05/02 15:09:44 manifest_template(ASCIIToUTF16(kManifestTemplate))
gab 2012/05/02 20:55:58 Arg! I always forget about this style rule!
93 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
grt (UTC plus 2) 2012/05/02 15:13:09 please move this comment down one line so that it
gab 2012/05/02 20:55:58 Done.
94 // resource for |display_name|.
95 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
96 string16 display_name = dist->GetAppShortCutName();
grt (UTC plus 2) 2012/05/02 15:09:44 display_name(dist->GetAppShortCutName())
gab 2012/05/02 20:55:58 Done.
97 // XMLEscape |display_name| to be safe. We do not need to escape double
grt (UTC plus 2) 2012/05/02 15:09:44 // Escape the display name as per the XML AttValue
gab 2012/05/02 20:55:58 I like. Done.
98 // quotes as this will be written within single quotes. We can also avoid
99 // escaping '>' as it is a legal character in an XML attribute value.
100 ReplaceChars(display_name, L"&", string16(L"&amp"), &display_name);
grt (UTC plus 2) 2012/05/02 15:09:44 string16(L"&amp") -> L"&amp;"
gab 2012/05/02 20:55:58 I was under the impression that Chromium style did
grt (UTC plus 2) 2012/05/03 17:49:37 yeah. iirc, the guidance is not to introduce impl
101 ReplaceChars(display_name, L"'", string16(L"&apos"), &display_name);
grt (UTC plus 2) 2012/05/02 15:09:44 string16(L"&apos") -> L"&apos;"
gab 2012/05/02 20:55:58 Done.
102 ReplaceChars(display_name, L"<", string16(L"&lt"), &display_name);
grt (UTC plus 2) 2012/05/02 15:09:44 string16(L"&lt") -> L"&lt;"
gab 2012/05/02 20:55:58 Done.
103 string16 manifest16 = base::StringPrintf(manifest_template16.c_str(),
grt (UTC plus 2) 2012/05/02 15:09:44 manifest16(base::StringPrintf(...))
gab 2012/05/02 20:55:58 Done.
104 display_name.c_str(),
105 images_dir.c_str());
106
107 // Write the manifest to the directory where the archive was extracted.
108 const std::string manifest = UTF16ToUTF8(manifest16);
grt (UTC plus 2) 2012/05/02 15:09:44 manifest(UTF...
gab 2012/05/02 20:55:58 Done :).
109 if (!file_util::WriteFile(src_path.Append(kVisualElementsManifest),
110 manifest.c_str(), manifest.size())) {
111 LOG(ERROR) << "Error writing " << kVisualElementsManifest
grt (UTC plus 2) 2012/05/02 15:09:44 PLOG(ERROR)
gab 2012/05/02 20:55:58 Right, done.
112 << "to" << src_path.value();
113 // TODO(gab) RETURN FALSE WHEN THE FUNCTION HAS A RETURN :)!
114 return;
115 }
116
117 // Add a work item to move the new manifest to |target_path|.
118 install_list->AddMoveTreeWorkItem(
119 src_path.Append(kVisualElementsManifest).value(),
120 target_path.Append(kVisualElementsManifest).value(),
121 temp_path.value(),
122 WorkItem::ALWAYS_MOVE);
123 }
124 }
125
126 } // namespace
127
45 namespace installer { 128 namespace installer {
46 129
47 // Local helper to call AddRegisterComDllWorkItems for all DLLs in a set of 130 // Local helper to call AddRegisterComDllWorkItems for all DLLs in a set of
48 // products managed by a given package. 131 // products managed by a given package.
49 void AddRegisterComDllWorkItemsForPackage(const InstallerState& installer_state, 132 void AddRegisterComDllWorkItemsForPackage(const InstallerState& installer_state,
50 const Version* old_version, 133 const Version* old_version,
51 const Version& new_version, 134 const Version& new_version,
52 WorkItemList* work_item_list) { 135 WorkItemList* work_item_list) {
53 // First collect the list of DLLs to be registered from each product. 136 // First collect the list of DLLs to be registered from each product.
54 std::vector<FilePath> com_dll_list; 137 std::vector<FilePath> com_dll_list;
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 845 }
763 846
764 // Extra executable for 64 bit systems. 847 // Extra executable for 64 bit systems.
765 // NOTE: We check for "not disabled" so that if the API call fails, we play it 848 // NOTE: We check for "not disabled" so that if the API call fails, we play it
766 // safe and copy the executable anyway. 849 // safe and copy the executable anyway.
767 // NOTE: the file wow_helper.exe is only needed for Vista and below. 850 // NOTE: the file wow_helper.exe is only needed for Vista and below.
768 if (base::win::OSInfo::GetInstance()->wow64_status() != 851 if (base::win::OSInfo::GetInstance()->wow64_status() !=
769 base::win::OSInfo::WOW64_DISABLED && 852 base::win::OSInfo::WOW64_DISABLED &&
770 base::win::GetVersion() <= base::win::VERSION_VISTA) { 853 base::win::GetVersion() <= base::win::VERSION_VISTA) {
771 install_list->AddMoveTreeWorkItem( 854 install_list->AddMoveTreeWorkItem(
772 src_path.Append(installer::kWowHelperExe).value(), 855 src_path.Append(kWowHelperExe).value(),
773 target_path.Append(installer::kWowHelperExe).value(), 856 target_path.Append(kWowHelperExe).value(),
774 temp_path.value(), 857 temp_path.value(),
775 WorkItem::ALWAYS_MOVE); 858 WorkItem::ALWAYS_MOVE);
776 } 859 }
777 860
778 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 861 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
779 // Desktop only (i.e. not supporting Metro) versions of Chromium do not have 862 AddVisualElementsInstallWorkItems(src_path, target_path, temp_path,
780 // to include visual elements. 863 new_version, install_list);
781 scoped_ptr<WorkItemList> win8_work_items(
782 WorkItem::CreateConditionalWorkItemList(new ConditionRunIfFileExists(
783 src_path.Append(L"visualelementsmanifest.xml"))));
784 // TODO (gab): All of these hard-coded strings are temporary and will be
785 // deleted in the patch following this one.
786 win8_work_items->AddMoveTreeWorkItem(
787 src_path.Append(L"visualelementsmanifest.xml").value(),
788 target_path.Append(L"visualelementsmanifest.xml").value(),
789 temp_path.value(),
790 WorkItem::ALWAYS_MOVE);
791 win8_work_items->AddMoveTreeWorkItem(
792 src_path.Append(L"logo.png").value(),
793 target_path.Append(L"logo.png").value(),
794 temp_path.value(),
795 WorkItem::ALWAYS_MOVE);
796 win8_work_items->AddMoveTreeWorkItem(
797 src_path.Append(L"smalllogo.png").value(),
798 target_path.Append(L"smalllogo.png").value(),
799 temp_path.value(),
800 WorkItem::ALWAYS_MOVE);
801 win8_work_items->AddMoveTreeWorkItem(
802 src_path.Append(L"splash-620x300.png").value(),
803 target_path.Append(L"splash-620x300.png").value(),
804 temp_path.value(),
805 WorkItem::ALWAYS_MOVE);
806 install_list->AddWorkItem(win8_work_items.release());
807 } 864 }
808 865
809 // In the past, we copied rather than moved for system level installs so that 866 // In the past, we copied rather than moved for system level installs so that
810 // the permissions of %ProgramFiles% would be picked up. Now that |temp_path| 867 // the permissions of %ProgramFiles% would be picked up. Now that |temp_path|
811 // is in %ProgramFiles% for system level installs (and in %LOCALAPPDATA% 868 // is in %ProgramFiles% for system level installs (and in %LOCALAPPDATA%
812 // otherwise), there is no need to do this. 869 // otherwise), there is no need to do this.
813 // Note that we pass true for check_duplicates to avoid failing on in-use 870 // Note that we pass true for check_duplicates to avoid failing on in-use
814 // repair runs if the current_version is the same as the new_version. 871 // repair runs if the current_version is the same as the new_version.
815 bool check_for_duplicates = 872 bool check_for_duplicates =
816 (current_version != NULL && current_version->get() != NULL && 873 (current_version != NULL && current_version->get() != NULL &&
817 current_version->get()->Equals(new_version)); 874 current_version->get()->Equals(new_version));
818 install_list->AddMoveTreeWorkItem( 875 install_list->AddMoveTreeWorkItem(
819 src_path.AppendASCII(new_version.GetString()).value(), 876 src_path.AppendASCII(new_version.GetString()).value(),
820 target_path.AppendASCII(new_version.GetString()).value(), 877 target_path.AppendASCII(new_version.GetString()).value(),
821 temp_path.value(), 878 temp_path.value(),
822 check_for_duplicates ? WorkItem::CHECK_DUPLICATES : 879 check_for_duplicates ? WorkItem::CHECK_DUPLICATES :
823 WorkItem::ALWAYS_MOVE); 880 WorkItem::ALWAYS_MOVE);
824 881
825 // Copy the default Dictionaries only if the folder doesn't exist already.
826 // TODO(grt): Use AddMoveTreeWorkItem in a conditional WorkItemList, which
827 // will be more efficient in space and time.
828 install_list->AddCopyTreeWorkItem(
829 src_path.Append(installer::kDictionaries).value(),
830 target_path.Append(installer::kDictionaries).value(),
831 temp_path.value(), WorkItem::IF_NOT_PRESENT);
832
833 // Delete any old_chrome.exe if present (ignore failure if it's in use). 882 // Delete any old_chrome.exe if present (ignore failure if it's in use).
834 install_list->AddDeleteTreeWorkItem( 883 install_list->AddDeleteTreeWorkItem(
835 target_path.Append(installer::kChromeOldExe), temp_path) 884 target_path.Append(installer::kChromeOldExe), temp_path)
836 ->set_ignore_failure(true); 885 ->set_ignore_failure(true);
837 886
838 // Copy installer in install directory and 887 // Copy installer in install directory and
839 // add shortcut in Control Panel->Add/Remove Programs. 888 // add shortcut in Control Panel->Add/Remove Programs.
840 AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_path, 889 AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_path,
841 new_version, install_list); 890 new_version, install_list);
842 891
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 } else { 1474 } else {
1426 DCHECK(operation == REMOVE_COMMAND); 1475 DCHECK(operation == REMOVE_COMMAND);
1427 work_item_list->AddDeleteRegKeyWorkItem(installer_state.root_key(), 1476 work_item_list->AddDeleteRegKeyWorkItem(installer_state.root_key(),
1428 cmd_key)->set_log_message( 1477 cmd_key)->set_log_message(
1429 "removing quick-enable-cf command"); 1478 "removing quick-enable-cf command");
1430 } 1479 }
1431 } 1480 }
1432 } 1481 }
1433 1482
1434 } // namespace installer 1483 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698