• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 //
5 // This file defines a class that contains various method related to branding.
6 // It provides only default implementations of these methods. Usually to add
7 // specific branding, we will need to extend this class with a custom
8 // implementation.
9 
10 #include "chrome/installer/util/browser_distribution.h"
11 
12 #include "base/atomicops.h"
13 #include "base/command_line.h"
14 #include "base/files/file_path.h"
15 #include "base/logging.h"
16 #include "base/path_service.h"
17 #include "base/win/registry.h"
18 #include "base/win/windows_version.h"
19 #include "chrome/common/env_vars.h"
20 #include "chrome/installer/util/chrome_app_host_distribution.h"
21 #include "chrome/installer/util/chrome_frame_distribution.h"
22 #include "chrome/installer/util/chromium_binaries_distribution.h"
23 #include "chrome/installer/util/google_chrome_binaries_distribution.h"
24 #include "chrome/installer/util/google_chrome_distribution.h"
25 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
26 #include "chrome/installer/util/install_util.h"
27 #include "chrome/installer/util/l10n_string_util.h"
28 #include "chrome/installer/util/master_preferences.h"
29 
30 #include "installer_util_strings.h"  // NOLINT
31 
32 using installer::MasterPreferences;
33 
34 namespace {
35 
36 const wchar_t kChromiumActiveSetupGuid[] =
37     L"{7D2B3E1D-D096-4594-9D8F-A6667F12E0AC}";
38 
39 const wchar_t kCommandExecuteImplUuid[] =
40     L"{A2DF06F9-A21A-44A8-8A99-8B9C84F29160}";
41 
42 // The Chromium App Launcher icon is index 1; see chrome_exe.rc.
43 const int kAppLauncherIconIndex = 1;
44 
45 // The BrowserDistribution objects are never freed.
46 BrowserDistribution* g_browser_distribution = NULL;
47 BrowserDistribution* g_chrome_frame_distribution = NULL;
48 BrowserDistribution* g_binaries_distribution = NULL;
49 BrowserDistribution* g_chrome_app_host_distribution = NULL;
50 
51 // Returns true if currently running in npchrome_frame.dll
IsChromeFrameModule()52 bool IsChromeFrameModule() {
53   base::FilePath module_path;
54   PathService::Get(base::FILE_MODULE, &module_path);
55   return base::FilePath::CompareEqualIgnoreCase(module_path.BaseName().value(),
56                                           installer::kChromeFrameDll);
57 }
58 
GetCurrentDistributionType()59 BrowserDistribution::Type GetCurrentDistributionType() {
60   // TODO(erikwright): If the app host is installed, but not Chrome, perhaps
61   // this should return CHROME_APP_HOST.
62   return BrowserDistribution::CHROME_BROWSER;
63 }
64 
65 }  // end namespace
66 
BrowserDistribution()67 BrowserDistribution::BrowserDistribution()
68     : type_(CHROME_BROWSER) {
69 }
70 
BrowserDistribution(Type type)71 BrowserDistribution::BrowserDistribution(Type type)
72     : type_(type) {
73 }
74 
75 template<class DistributionClass>
GetOrCreateBrowserDistribution(BrowserDistribution ** dist)76 BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution(
77     BrowserDistribution** dist) {
78   if (!*dist) {
79     DistributionClass* temp = new DistributionClass();
80     if (base::subtle::NoBarrier_CompareAndSwap(
81             reinterpret_cast<base::subtle::AtomicWord*>(dist), NULL,
82             reinterpret_cast<base::subtle::AtomicWord>(temp)) != NULL)
83       delete temp;
84   }
85 
86   return *dist;
87 }
88 
GetDistribution()89 BrowserDistribution* BrowserDistribution::GetDistribution() {
90   return GetSpecificDistribution(GetCurrentDistributionType());
91 }
92 
93 // static
GetSpecificDistribution(BrowserDistribution::Type type)94 BrowserDistribution* BrowserDistribution::GetSpecificDistribution(
95     BrowserDistribution::Type type) {
96   BrowserDistribution* dist = NULL;
97 
98   switch (type) {
99     case CHROME_BROWSER:
100 #if defined(GOOGLE_CHROME_BUILD)
101       if (InstallUtil::IsChromeSxSProcess()) {
102         dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>(
103             &g_browser_distribution);
104       } else {
105         dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>(
106             &g_browser_distribution);
107       }
108 #else
109       dist = GetOrCreateBrowserDistribution<BrowserDistribution>(
110           &g_browser_distribution);
111 #endif
112       break;
113 
114     case CHROME_FRAME:
115       dist = GetOrCreateBrowserDistribution<ChromeFrameDistribution>(
116           &g_chrome_frame_distribution);
117       break;
118 
119     case CHROME_APP_HOST:
120       dist = GetOrCreateBrowserDistribution<ChromeAppHostDistribution>(
121           &g_chrome_app_host_distribution);
122       break;
123 
124     default:
125       DCHECK_EQ(CHROME_BINARIES, type);
126 #if defined(GOOGLE_CHROME_BUILD)
127       dist = GetOrCreateBrowserDistribution<GoogleChromeBinariesDistribution>(
128           &g_binaries_distribution);
129 #else
130       dist = GetOrCreateBrowserDistribution<ChromiumBinariesDistribution>(
131           &g_binaries_distribution);
132 #endif
133   }
134 
135   return dist;
136 }
137 
DoPostUninstallOperations(const Version & version,const base::FilePath & local_data_path,const string16 & distribution_data)138 void BrowserDistribution::DoPostUninstallOperations(
139     const Version& version, const base::FilePath& local_data_path,
140     const string16& distribution_data) {
141 }
142 
GetActiveSetupGuid()143 string16 BrowserDistribution::GetActiveSetupGuid() {
144   return kChromiumActiveSetupGuid;
145 }
146 
GetAppGuid()147 string16 BrowserDistribution::GetAppGuid() {
148   return L"";
149 }
150 
GetBaseAppName()151 string16 BrowserDistribution::GetBaseAppName() {
152   return L"Chromium";
153 }
154 
GetDisplayName()155 string16 BrowserDistribution::GetDisplayName() {
156   return GetShortcutName(SHORTCUT_CHROME);
157 }
158 
GetShortcutName(ShortcutType shortcut_type)159 string16 BrowserDistribution::GetShortcutName(ShortcutType shortcut_type) {
160   switch (shortcut_type) {
161     case SHORTCUT_CHROME_ALTERNATE:
162       // TODO(calamity): Change IDS_OEM_MAIN_SHORTCUT_NAME in
163       // chromium_strings.grd to "The Internet" (so that it doesn't collide with
164       // the value in google_chrome_strings.grd) then change this to
165       // installer::GetLocalizedString(IDS_OEM_MAIN_SHORTCUT_NAME_BASE)
166       return L"The Internet";
167     case SHORTCUT_APP_LAUNCHER:
168       return installer::GetLocalizedString(IDS_APP_LIST_SHORTCUT_NAME_BASE);
169     default:
170       DCHECK_EQ(shortcut_type, SHORTCUT_CHROME);
171       return GetBaseAppName();
172   }
173 }
174 
GetIconIndex(ShortcutType shortcut_type)175 int BrowserDistribution::GetIconIndex(ShortcutType shortcut_type) {
176   if (shortcut_type == SHORTCUT_APP_LAUNCHER)
177     return kAppLauncherIconIndex;
178   DCHECK(shortcut_type == SHORTCUT_CHROME ||
179          shortcut_type == SHORTCUT_CHROME_ALTERNATE) << shortcut_type;
180   return 0;
181 }
182 
GetIconFilename()183 string16 BrowserDistribution::GetIconFilename() {
184   return installer::kChromeExe;
185 }
186 
GetStartMenuShortcutSubfolder(Subfolder subfolder_type)187 string16 BrowserDistribution::GetStartMenuShortcutSubfolder(
188     Subfolder subfolder_type) {
189   switch (subfolder_type) {
190     case SUBFOLDER_APPS:
191       return installer::GetLocalizedString(IDS_APP_SHORTCUTS_SUBDIR_NAME_BASE);
192     default:
193       DCHECK_EQ(subfolder_type, SUBFOLDER_CHROME);
194       return GetShortcutName(SHORTCUT_CHROME);
195   }
196 }
197 
GetBaseAppId()198 string16 BrowserDistribution::GetBaseAppId() {
199   return L"Chromium";
200 }
201 
GetBrowserProgIdPrefix()202 string16 BrowserDistribution::GetBrowserProgIdPrefix() {
203   // This used to be "ChromiumHTML", but was forced to become "ChromiumHTM"
204   // because of http://crbug.com/153349.  See the declaration of this function
205   // in the header file for more details.
206   return L"ChromiumHTM";
207 }
208 
GetBrowserProgIdDesc()209 string16 BrowserDistribution::GetBrowserProgIdDesc() {
210   return L"Chromium HTML Document";
211 }
212 
213 
GetInstallSubDir()214 string16 BrowserDistribution::GetInstallSubDir() {
215   return L"Chromium";
216 }
217 
GetPublisherName()218 string16 BrowserDistribution::GetPublisherName() {
219   return L"Chromium";
220 }
221 
GetAppDescription()222 string16 BrowserDistribution::GetAppDescription() {
223   return L"Browse the web";
224 }
225 
GetLongAppDescription()226 string16 BrowserDistribution::GetLongAppDescription() {
227   const string16& app_description =
228       installer::GetLocalizedString(IDS_PRODUCT_DESCRIPTION_BASE);
229   return app_description;
230 }
231 
GetSafeBrowsingName()232 std::string BrowserDistribution::GetSafeBrowsingName() {
233   return "chromium";
234 }
235 
GetStateKey()236 string16 BrowserDistribution::GetStateKey() {
237   return L"Software\\Chromium";
238 }
239 
GetStateMediumKey()240 string16 BrowserDistribution::GetStateMediumKey() {
241   return L"Software\\Chromium";
242 }
243 
GetNetworkStatsServer() const244 std::string BrowserDistribution::GetNetworkStatsServer() const {
245   return "";
246 }
247 
GetHttpPipeliningTestServer() const248 std::string BrowserDistribution::GetHttpPipeliningTestServer() const {
249   return "";
250 }
251 
GetDistributionData(HKEY root_key)252 string16 BrowserDistribution::GetDistributionData(HKEY root_key) {
253   return L"";
254 }
255 
GetUninstallLinkName()256 string16 BrowserDistribution::GetUninstallLinkName() {
257   return L"Uninstall Chromium";
258 }
259 
GetUninstallRegPath()260 string16 BrowserDistribution::GetUninstallRegPath() {
261   return L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Chromium";
262 }
263 
GetVersionKey()264 string16 BrowserDistribution::GetVersionKey() {
265   return L"Software\\Chromium";
266 }
267 
268 BrowserDistribution::DefaultBrowserControlPolicy
GetDefaultBrowserControlPolicy()269     BrowserDistribution::GetDefaultBrowserControlPolicy() {
270   return DEFAULT_BROWSER_FULL_CONTROL;
271 }
272 
CanCreateDesktopShortcuts()273 bool BrowserDistribution::CanCreateDesktopShortcuts() {
274   return true;
275 }
276 
GetChromeChannel(string16 * channel)277 bool BrowserDistribution::GetChromeChannel(string16* channel) {
278   return false;
279 }
280 
GetCommandExecuteImplClsid(string16 * handler_class_uuid)281 bool BrowserDistribution::GetCommandExecuteImplClsid(
282     string16* handler_class_uuid) {
283   if (handler_class_uuid)
284     *handler_class_uuid = kCommandExecuteImplUuid;
285   return true;
286 }
287 
AppHostIsSupported()288 bool BrowserDistribution::AppHostIsSupported() {
289   return false;
290 }
291 
UpdateInstallStatus(bool system_install,installer::ArchiveType archive_type,installer::InstallStatus install_status)292 void BrowserDistribution::UpdateInstallStatus(bool system_install,
293     installer::ArchiveType archive_type,
294     installer::InstallStatus install_status) {
295 }
296 
ShouldSetExperimentLabels()297 bool BrowserDistribution::ShouldSetExperimentLabels() {
298   return false;
299 }
300 
HasUserExperiments()301 bool BrowserDistribution::HasUserExperiments() {
302   return false;
303 }
304