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/install_util.h" | |
21 #include "chrome/installer/util/util_constants.h" | 22 #include "chrome/installer/util/util_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "ui/gfx/icon_util.h" | 24 #include "ui/gfx/icon_util.h" |
24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/image/image_family.h" | 26 #include "ui/gfx/image/image_family.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const base::FilePath::CharType kIconChecksumFileExt[] = | 30 const base::FilePath::CharType kIconChecksumFileExt[] = |
30 FILE_PATH_LITERAL(".ico.md5"); | 31 FILE_PATH_LITERAL(".ico.md5"); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 162 } |
162 | 163 |
163 bool CreatePlatformShortcuts( | 164 bool CreatePlatformShortcuts( |
164 const base::FilePath& web_app_path, | 165 const base::FilePath& web_app_path, |
165 const ShellIntegration::ShortcutInfo& shortcut_info, | 166 const ShellIntegration::ShortcutInfo& shortcut_info, |
166 const ShellIntegration::ShortcutLocations& creation_locations) { | 167 const ShellIntegration::ShortcutLocations& creation_locations) { |
167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 168 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
168 | 169 |
169 // Shortcut paths under which to create shortcuts. | 170 // Shortcut paths under which to create shortcuts. |
170 std::vector<base::FilePath> shortcut_paths = | 171 std::vector<base::FilePath> shortcut_paths = |
171 GetShortcutPaths(creation_locations); | 172 GetShortcutPaths(creation_locations, ShellUtil::CURRENT_USER); |
172 | 173 |
173 bool pin_to_taskbar = creation_locations.in_quick_launch_bar && | 174 bool pin_to_taskbar = creation_locations.in_quick_launch_bar && |
174 (base::win::GetVersion() >= base::win::VERSION_WIN7); | 175 (base::win::GetVersion() >= base::win::VERSION_WIN7); |
175 | 176 |
176 // Create/update the shortcut in the web app path for the "Pin To Taskbar" | 177 // Create/update the shortcut in the web app path for the "Pin To Taskbar" |
177 // option in Win7. We use the web app path shortcut because we will overwrite | 178 // option in Win7. We use the web app path shortcut because we will overwrite |
178 // it rather than appending unique numbers if the shortcut already exists. | 179 // it rather than appending unique numbers if the shortcut already exists. |
179 // This prevents pinned apps from having unique numbers in their names. | 180 // This prevents pinned apps from having unique numbers in their names. |
180 if (pin_to_taskbar) | 181 if (pin_to_taskbar) |
181 shortcut_paths.push_back(web_app_path); | 182 shortcut_paths.push_back(web_app_path); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 void DeletePlatformShortcuts( | 286 void DeletePlatformShortcuts( |
286 const base::FilePath& web_app_path, | 287 const base::FilePath& web_app_path, |
287 const ShellIntegration::ShortcutInfo& shortcut_info) { | 288 const ShellIntegration::ShortcutInfo& shortcut_info) { |
288 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 289 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
289 | 290 |
290 // Get all possible locations for shortcuts. | 291 // Get all possible locations for shortcuts. |
291 ShellIntegration::ShortcutLocations all_shortcut_locations; | 292 ShellIntegration::ShortcutLocations all_shortcut_locations; |
292 all_shortcut_locations.in_applications_menu = true; | 293 all_shortcut_locations.in_applications_menu = true; |
293 all_shortcut_locations.in_quick_launch_bar = true; | 294 all_shortcut_locations.in_quick_launch_bar = true; |
294 all_shortcut_locations.on_desktop = true; | 295 all_shortcut_locations.on_desktop = true; |
295 std::vector<base::FilePath> shortcut_paths = GetShortcutPaths( | 296 std::vector<base::FilePath> shortcut_paths = |
296 all_shortcut_locations); | 297 GetShortcutPaths(all_shortcut_locations, ShellUtil::CURRENT_USER); |
297 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 298 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
298 shortcut_paths.push_back(web_app_path); | 299 shortcut_paths.push_back(web_app_path); |
299 | 300 |
300 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); | 301 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); |
301 i != shortcut_paths.end(); ++i) { | 302 i != shortcut_paths.end(); ++i) { |
302 std::vector<base::FilePath> shortcut_files = | 303 std::vector<base::FilePath> shortcut_files = |
303 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, | 304 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, |
304 shortcut_info.title); | 305 shortcut_info.title); |
305 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); | 306 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); |
306 j != shortcut_files.end(); ++j) { | 307 j != shortcut_files.end(); ++j) { |
307 // Any shortcut could have been pinned, either by chrome or the user, so | 308 // Any shortcut could have been pinned, either by chrome or the user, so |
308 // they are all unpinned. | 309 // they are all unpinned. |
309 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 310 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
310 file_util::Delete(*j, false); | 311 file_util::Delete(*j, false); |
311 } | 312 } |
312 } | 313 } |
313 } | 314 } |
314 | 315 |
315 std::vector<base::FilePath> GetShortcutPaths( | 316 std::vector<base::FilePath> GetShortcutPaths( |
316 const ShellIntegration::ShortcutLocations& creation_locations) { | 317 const ShellIntegration::ShortcutLocations& creation_locations, |
318 const ShellUtil::ShellChange install_level) { | |
317 // Shortcut paths under which to create shortcuts. | 319 // Shortcut paths under which to create shortcuts. |
318 std::vector<base::FilePath> shortcut_paths; | 320 std::vector<base::FilePath> shortcut_paths; |
319 // Locations to add to shortcut_paths. | 321 // Locations to add to shortcut_paths. |
320 struct { | 322 struct { |
321 bool use_this_location; | 323 bool use_this_location; |
322 int location_id; | 324 ShellUtil::ShortcutLocation location_id; |
323 const wchar_t* subdir; | 325 const wchar_t* subdir; |
324 } locations[] = { | 326 } locations[] = { |
325 { | 327 { |
326 creation_locations.on_desktop, | 328 creation_locations.on_desktop, |
327 base::DIR_USER_DESKTOP, | 329 ShellUtil::SHORTCUT_LOCATION_DESKTOP, |
328 NULL | 330 NULL |
329 }, { | 331 }, { |
330 creation_locations.in_applications_menu, | 332 creation_locations.in_applications_menu, |
331 base::DIR_START_MENU, | 333 ShellUtil::SHORTCUT_LOCATION_START_MENU, |
gab
2013/04/26 15:21:03
SHORTCUT_LOCATION_START_MENU_CHROME_DIR sounds goo
calamity
2013/04/29 07:20:05
mgiuca@ is making chrome app start menu shortcuts
| |
332 creation_locations.applications_menu_subdir.empty() ? NULL : | 334 creation_locations.applications_menu_subdir.empty() ? NULL : |
333 creation_locations.applications_menu_subdir.c_str() | 335 creation_locations.applications_menu_subdir.c_str() |
334 }, { | 336 }, { |
335 creation_locations.in_quick_launch_bar, | 337 // For Win7, in_quick_launch_bar means pinning to taskbar. This needs to |
gab
2013/04/26 15:21:03
I don't think that this comment is correct.
Quick
calamity
2013/04/29 07:20:05
Yes, in_quick_launch_bar is used as "pin to taskba
| |
336 // For Win7, in_quick_launch_bar means pinning to taskbar. Use | 338 // be handled by callers. |
337 // base::PATH_START as a flag for this case. | 339 creation_locations.in_quick_launch_bar && |
338 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 340 base::win::GetVersion() < base::win::VERSION_WIN7, |
339 base::PATH_START : base::DIR_APP_DATA, | 341 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, |
340 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 342 NULL |
341 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | |
342 } | 343 } |
343 }; | 344 }; |
345 | |
346 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
344 // Populate shortcut_paths. | 347 // Populate shortcut_paths. |
345 for (int i = 0; i < arraysize(locations); ++i) { | 348 for (int i = 0; i < arraysize(locations); ++i) { |
346 if (locations[i].use_this_location) { | 349 if (locations[i].use_this_location) { |
347 base::FilePath path; | 350 base::FilePath path; |
348 | 351 |
349 // Skip the Win7 case. | 352 if (!ShellUtil::GetShortcutPath(locations[i].location_id, |
350 if (locations[i].location_id == base::PATH_START) | 353 dist, |
351 continue; | 354 install_level, |
352 | 355 &path)) { |
353 if (!PathService::Get(locations[i].location_id, &path)) { | 356 NOTREACHED(); |
354 continue; | 357 continue; |
355 } | 358 } |
356 | 359 |
357 if (locations[i].subdir != NULL) | 360 if (locations[i].subdir != NULL) |
358 path = path.Append(locations[i].subdir); | 361 path = path.Append(locations[i].subdir); |
359 shortcut_paths.push_back(path); | 362 shortcut_paths.push_back(path); |
360 } | 363 } |
361 } | 364 } |
362 return shortcut_paths; | 365 return shortcut_paths; |
363 } | 366 } |
364 | 367 |
365 } // namespace internals | 368 } // namespace internals |
366 | 369 |
367 } // namespace web_app | 370 } // namespace web_app |
OLD | NEW |