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/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/md5.h" | 12 #include "base/md5.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/win/shortcut.h" | 16 #include "base/win/shortcut.h" |
17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
20 #include "chrome/installer/util/browser_distribution.h" | 20 #include "chrome/installer/util/browser_distribution.h" |
21 #include "chrome/installer/util/util_constants.h" | |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "ui/gfx/icon_util.h" | 23 #include "ui/gfx/icon_util.h" |
23 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
24 #include "ui/gfx/image/image_family.h" | 25 #include "ui/gfx/image/image_family.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const base::FilePath::CharType kIconChecksumFileExt[] = | 29 const base::FilePath::CharType kIconChecksumFileExt[] = |
29 FILE_PATH_LITERAL(".ico.md5"); | 30 FILE_PATH_LITERAL(".ico.md5"); |
30 | 31 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 return true; | 74 return true; |
74 | 75 |
75 base::MD5Digest downloaded_image_checksum; | 76 base::MD5Digest downloaded_image_checksum; |
76 GetImageCheckSum(image, &downloaded_image_checksum); | 77 GetImageCheckSum(image, &downloaded_image_checksum); |
77 | 78 |
78 // Update icon if checksums are not equal. | 79 // Update icon if checksums are not equal. |
79 return memcmp(&persisted_image_checksum, &downloaded_image_checksum, | 80 return memcmp(&persisted_image_checksum, &downloaded_image_checksum, |
80 sizeof(base::MD5Digest)) != 0; | 81 sizeof(base::MD5Digest)) != 0; |
81 } | 82 } |
82 | 83 |
83 std::vector<base::FilePath> GetShortcutPaths( | |
84 const ShellIntegration::ShortcutLocations& creation_locations) { | |
85 // Shortcut paths under which to create shortcuts. | |
86 std::vector<base::FilePath> shortcut_paths; | |
87 | |
88 // Locations to add to shortcut_paths. | |
89 struct { | |
90 bool use_this_location; | |
91 int location_id; | |
92 const wchar_t* sub_dir; | |
93 } locations[] = { | |
94 { | |
95 creation_locations.on_desktop, | |
96 base::DIR_USER_DESKTOP, | |
97 NULL | |
98 }, { | |
99 creation_locations.in_applications_menu, | |
100 base::DIR_START_MENU, | |
101 NULL | |
102 }, { | |
103 creation_locations.in_quick_launch_bar, | |
104 // For Win7, create_in_quick_launch_bar means pinning to taskbar. Use | |
105 // base::PATH_START as a flag for this case. | |
106 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | |
107 base::PATH_START : base::DIR_APP_DATA, | |
108 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | |
109 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | |
110 } | |
111 }; | |
112 | |
113 // Populate shortcut_paths. | |
114 for (int i = 0; i < arraysize(locations); ++i) { | |
115 if (locations[i].use_this_location) { | |
116 base::FilePath path; | |
117 | |
118 // Skip the Win7 case. | |
119 if (locations[i].location_id == base::PATH_START) | |
120 continue; | |
121 | |
122 if (!PathService::Get(locations[i].location_id, &path)) { | |
123 continue; | |
124 } | |
125 | |
126 if (locations[i].sub_dir != NULL) | |
127 path = path.Append(locations[i].sub_dir); | |
128 | |
129 shortcut_paths.push_back(path); | |
130 } | |
131 } | |
132 | |
133 return shortcut_paths; | |
134 } | |
135 | |
136 bool ShortcutIsForProfile(const base::FilePath& shortcut_file_name, | 84 bool ShortcutIsForProfile(const base::FilePath& shortcut_file_name, |
137 const base::FilePath& profile_path) { | 85 const base::FilePath& profile_path) { |
138 string16 cmd_line_string; | 86 string16 cmd_line_string; |
139 if (base::win::ResolveShortcut(shortcut_file_name, NULL, &cmd_line_string)) { | 87 if (base::win::ResolveShortcut(shortcut_file_name, NULL, &cmd_line_string)) { |
140 cmd_line_string = L"program " + cmd_line_string; | 88 cmd_line_string = L"program " + cmd_line_string; |
141 CommandLine shortcut_cmd_line = CommandLine::FromString(cmd_line_string); | 89 CommandLine shortcut_cmd_line = CommandLine::FromString(cmd_line_string); |
142 return shortcut_cmd_line.HasSwitch(switches::kProfileDirectory) && | 90 return shortcut_cmd_line.HasSwitch(switches::kProfileDirectory) && |
143 shortcut_cmd_line.GetSwitchValuePath(switches::kProfileDirectory) == | 91 shortcut_cmd_line.GetSwitchValuePath(switches::kProfileDirectory) == |
144 profile_path.BaseName(); | 92 profile_path.BaseName(); |
145 } | 93 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 description.resize(MAX_PATH - 1); | 222 description.resize(MAX_PATH - 1); |
275 | 223 |
276 // Generates app id from web app url and profile path. | 224 // Generates app id from web app url and profile path. |
277 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); | 225 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); |
278 string16 app_id(ShellIntegration::GetAppModelIdForProfile( | 226 string16 app_id(ShellIntegration::GetAppModelIdForProfile( |
279 UTF8ToUTF16(app_name), shortcut_info.profile_path)); | 227 UTF8ToUTF16(app_name), shortcut_info.profile_path)); |
280 | 228 |
281 bool success = true; | 229 bool success = true; |
282 for (size_t i = 0; i < shortcut_paths.size(); ++i) { | 230 for (size_t i = 0; i < shortcut_paths.size(); ++i) { |
283 base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). | 231 base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). |
284 AddExtension(FILE_PATH_LITERAL(".lnk")); | 232 AddExtension(installer::kLnkExt); |
285 if (shortcut_paths[i] != web_app_path) { | 233 if (shortcut_paths[i] != web_app_path) { |
286 int unique_number = | 234 int unique_number = |
287 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); | 235 file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); |
288 if (unique_number == -1) { | 236 if (unique_number == -1) { |
289 success = false; | 237 success = false; |
290 continue; | 238 continue; |
291 } else if (unique_number > 0) { | 239 } else if (unique_number > 0) { |
292 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( | 240 shortcut_file = shortcut_file.InsertBeforeExtensionASCII( |
293 base::StringPrintf(" (%d)", unique_number)); | 241 base::StringPrintf(" (%d)", unique_number)); |
294 } | 242 } |
295 } | 243 } |
296 base::win::ShortcutProperties shortcut_properties; | 244 base::win::ShortcutProperties shortcut_properties; |
297 shortcut_properties.set_target(target_exe); | 245 shortcut_properties.set_target(target_exe); |
298 shortcut_properties.set_working_dir(working_dir); | 246 shortcut_properties.set_working_dir(working_dir); |
299 shortcut_properties.set_arguments(wide_switches); | 247 shortcut_properties.set_arguments(wide_switches); |
300 shortcut_properties.set_description(description); | 248 shortcut_properties.set_description(description); |
301 shortcut_properties.set_icon(icon_file, 0); | 249 shortcut_properties.set_icon(icon_file, 0); |
302 shortcut_properties.set_app_id(app_id); | 250 shortcut_properties.set_app_id(app_id); |
303 shortcut_properties.set_dual_mode(false); | 251 shortcut_properties.set_dual_mode(false); |
304 success = base::win::CreateOrUpdateShortcutLink( | 252 success = base::win::CreateOrUpdateShortcutLink( |
305 shortcut_file, shortcut_properties, | 253 shortcut_file, shortcut_properties, |
306 base::win::SHORTCUT_CREATE_ALWAYS) && success; | 254 base::win::SHORTCUT_CREATE_ALWAYS) && success; |
307 } | 255 } |
308 | 256 |
309 if (success && pin_to_taskbar) { | 257 if (success && pin_to_taskbar) { |
310 // Use the web app path shortcut for pinning to avoid having unique numbers | 258 // Use the web app path shortcut for pinning to avoid having unique numbers |
311 // in the application name. | 259 // in the application name. |
312 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 260 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
313 AddExtension(FILE_PATH_LITERAL(".lnk")); | 261 AddExtension(installer::kLnkExt); |
314 success = base::win::TaskbarPinShortcutLink( | 262 success = base::win::TaskbarPinShortcutLink( |
315 shortcut_to_pin.value().c_str()) && success; | 263 shortcut_to_pin.value().c_str()) && success; |
316 } | 264 } |
317 | 265 |
318 return success; | 266 return success; |
319 } | 267 } |
320 | 268 |
321 void UpdatePlatformShortcuts( | 269 void UpdatePlatformShortcuts( |
322 const base::FilePath& web_app_path, | 270 const base::FilePath& web_app_path, |
323 const ShellIntegration::ShortcutInfo& shortcut_info) { | 271 const ShellIntegration::ShortcutInfo& shortcut_info) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); | 305 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); |
358 j != shortcut_files.end(); ++j) { | 306 j != shortcut_files.end(); ++j) { |
359 // Any shortcut could have been pinned, either by chrome or the user, so | 307 // Any shortcut could have been pinned, either by chrome or the user, so |
360 // they are all unpinned. | 308 // they are all unpinned. |
361 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 309 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
362 file_util::Delete(*j, false); | 310 file_util::Delete(*j, false); |
363 } | 311 } |
364 } | 312 } |
365 } | 313 } |
366 | 314 |
315 std::vector<base::FilePath> GetShortcutPaths( | |
gab
2013/04/23 17:59:57
These locations are wrong if this is a system-leve
calamity
2013/04/26 04:38:49
Just making sure: if Chrome is a system install, i
| |
316 const ShellIntegration::ShortcutLocations& creation_locations) { | |
317 // Shortcut paths under which to create shortcuts. | |
318 std::vector<base::FilePath> shortcut_paths; | |
319 // Locations to add to shortcut_paths. | |
320 struct { | |
321 bool use_this_location; | |
322 int location_id; | |
323 const wchar_t* subdir; | |
324 } locations[] = { | |
325 { | |
326 creation_locations.on_desktop, | |
327 base::DIR_USER_DESKTOP, | |
328 NULL | |
329 }, { | |
330 creation_locations.in_applications_menu, | |
331 base::DIR_START_MENU, | |
332 creation_locations.applications_menu_subdir.empty() ? NULL : | |
333 creation_locations.applications_menu_subdir.c_str() | |
334 }, { | |
335 creation_locations.in_quick_launch_bar, | |
gab
2013/04/23 17:59:57
Why not simply make this
creation_locations.in_qui
calamity
2013/04/26 04:38:49
Left the special casing in. Seems messy to create
| |
336 // For Win7, in_quick_launch_bar means pinning to taskbar. Use | |
337 // base::PATH_START as a flag for this case. | |
338 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | |
339 base::PATH_START : base::DIR_APP_DATA, | |
gab
2013/04/23 17:59:57
There is base::DIR_USER_QUICK_LAUNCH, no need for
calamity
2013/04/26 04:38:49
Done.
| |
340 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | |
341 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | |
342 } | |
343 }; | |
344 // Populate shortcut_paths. | |
345 for (int i = 0; i < arraysize(locations); ++i) { | |
346 if (locations[i].use_this_location) { | |
347 base::FilePath path; | |
348 | |
349 // Skip the Win7 case. | |
350 if (locations[i].location_id == base::PATH_START) | |
gab
2013/04/23 17:59:57
Remove this (see comment above).
calamity
2013/04/26 04:38:49
Done.
| |
351 continue; | |
352 | |
353 if (!PathService::Get(locations[i].location_id, &path)) { | |
354 continue; | |
gab
2013/04/23 17:59:57
+
NOTREACHED();
calamity
2013/04/26 04:38:49
Done.
| |
355 } | |
356 | |
357 if (locations[i].subdir != NULL) | |
358 path = path.Append(locations[i].subdir); | |
359 shortcut_paths.push_back(path); | |
360 } | |
361 } | |
362 return shortcut_paths; | |
363 } | |
364 | |
367 } // namespace internals | 365 } // namespace internals |
368 | 366 |
369 } // namespace web_app | 367 } // namespace web_app |
OLD | NEW |