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/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/win/shortcut.h" | 17 #include "base/win/shortcut.h" |
18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 20 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
21 #include "chrome/installer/util/browser_distribution.h" | |
22 #include "chrome/installer/util/shell_util.h" | |
21 #include "chrome/installer/util/util_constants.h" | 23 #include "chrome/installer/util/util_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
23 #include "ui/gfx/icon_util.h" | 25 #include "ui/gfx/icon_util.h" |
24 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/image/image_family.h" | 27 #include "ui/gfx/image/image_family.h" |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 const base::FilePath::CharType kIconChecksumFileExt[] = | 31 const base::FilePath::CharType kIconChecksumFileExt[] = |
30 FILE_PATH_LITERAL(".ico.md5"); | 32 FILE_PATH_LITERAL(".ico.md5"); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 } | 289 } |
288 } | 290 } |
289 | 291 |
290 void DeletePlatformShortcuts( | 292 void DeletePlatformShortcuts( |
291 const base::FilePath& web_app_path, | 293 const base::FilePath& web_app_path, |
292 const ShellIntegration::ShortcutInfo& shortcut_info) { | 294 const ShellIntegration::ShortcutInfo& shortcut_info) { |
293 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 295 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
294 | 296 |
295 // Get all possible locations for shortcuts. | 297 // Get all possible locations for shortcuts. |
296 ShellIntegration::ShortcutLocations all_shortcut_locations; | 298 ShellIntegration::ShortcutLocations all_shortcut_locations; |
297 all_shortcut_locations.in_applications_menu = true; | |
298 all_shortcut_locations.in_quick_launch_bar = true; | 299 all_shortcut_locations.in_quick_launch_bar = true; |
299 all_shortcut_locations.on_desktop = true; | 300 all_shortcut_locations.on_desktop = true; |
300 // Delete shortcuts from the Chrome Apps subdirectory. | 301 // Delete shortcuts from the Chrome Apps subdirectory. |
301 // This matches the subdir name set by CreateApplicationShortcutView::Accept | 302 // This matches the subdir name set by CreateApplicationShortcutView::Accept |
302 // for Chrome apps (not URL apps, but this function does not apply for them). | 303 // for Chrome apps (not URL apps, but this function does not apply for them). |
304 all_shortcut_locations.in_applications_menu_chrome_apps_subdir = true; | |
303 string16 start_menu_subdir = GetAppShortcutsSubdirName(); | 305 string16 start_menu_subdir = GetAppShortcutsSubdirName(); |
Matt Giuca
2013/05/15 05:19:45
Move this line below to line 325 (start_menu_subdi
gab
2013/05/15 21:26:38
In fact delete this line (see comment below).
calamity
2013/08/27 07:59:35
Done.
| |
304 all_shortcut_locations.applications_menu_subdir = start_menu_subdir; | 306 std::vector<base::FilePath> shortcut_paths = |
305 std::vector<base::FilePath> shortcut_paths = GetShortcutPaths( | 307 GetShortcutPaths(all_shortcut_locations); |
306 all_shortcut_locations); | |
307 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 308 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
308 shortcut_paths.push_back(web_app_path); | 309 shortcut_paths.push_back(web_app_path); |
309 | 310 |
310 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); | 311 for (std::vector<base::FilePath>::const_iterator i = shortcut_paths.begin(); |
311 i != shortcut_paths.end(); ++i) { | 312 i != shortcut_paths.end(); ++i) { |
312 std::vector<base::FilePath> shortcut_files = | 313 std::vector<base::FilePath> shortcut_files = |
313 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, | 314 MatchingShortcutsForProfileAndExtension(*i, shortcut_info.profile_path, |
314 shortcut_info.title); | 315 shortcut_info.title); |
315 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); | 316 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); |
316 j != shortcut_files.end(); ++j) { | 317 j != shortcut_files.end(); ++j) { |
317 // Any shortcut could have been pinned, either by chrome or the user, so | 318 // Any shortcut could have been pinned, either by chrome or the user, so |
318 // they are all unpinned. | 319 // they are all unpinned. |
319 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 320 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
320 file_util::Delete(*j, false); | 321 file_util::Delete(*j, false); |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. | 325 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. |
325 base::FilePath chrome_apps_dir; | 326 base::FilePath chrome_apps_dir; |
326 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { | 327 if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) { |
327 chrome_apps_dir = chrome_apps_dir.Append(start_menu_subdir); | 328 chrome_apps_dir = chrome_apps_dir.Append(start_menu_subdir); |
Matt Giuca
2013/05/15 05:19:45
.... why are you still using GetAppShortcutsSubdir
gab
2013/05/15 21:26:38
+1
calamity
2013/08/27 07:59:35
Done.
| |
328 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) | 329 if (file_util::IsDirectoryEmpty(chrome_apps_dir)) |
329 file_util::Delete(chrome_apps_dir, false); | 330 file_util::Delete(chrome_apps_dir, false); |
330 } | 331 } |
331 } | 332 } |
332 | 333 |
333 std::vector<base::FilePath> GetShortcutPaths( | 334 std::vector<base::FilePath> GetShortcutPaths( |
334 const ShellIntegration::ShortcutLocations& creation_locations) { | 335 const ShellIntegration::ShortcutLocations& creation_locations) { |
335 // Shortcut paths under which to create shortcuts. | 336 // Shortcut paths under which to create shortcuts. |
336 std::vector<base::FilePath> shortcut_paths; | 337 std::vector<base::FilePath> shortcut_paths; |
337 // Locations to add to shortcut_paths. | 338 // Locations to add to shortcut_paths. |
338 struct { | 339 struct { |
339 bool use_this_location; | 340 bool use_this_location; |
340 int location_id; | 341 ShellUtil::ShortcutLocation location_id; |
341 const wchar_t* subdir; | |
342 } locations[] = { | 342 } locations[] = { |
343 { | 343 { |
344 creation_locations.on_desktop, | 344 creation_locations.on_desktop, |
345 base::DIR_USER_DESKTOP, | 345 ShellUtil::SHORTCUT_LOCATION_DESKTOP |
346 NULL | |
347 }, { | 346 }, { |
348 creation_locations.in_applications_menu, | 347 creation_locations.in_applications_menu, |
349 base::DIR_START_MENU, | 348 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT |
350 creation_locations.applications_menu_subdir.empty() ? NULL : | |
351 creation_locations.applications_menu_subdir.c_str() | |
352 }, { | 349 }, { |
353 creation_locations.in_quick_launch_bar, | 350 creation_locations.in_applications_menu_chrome_subdir, |
354 // For Win7, in_quick_launch_bar means pinning to taskbar. Use | 351 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, |
355 // base::PATH_START as a flag for this case. | 352 }, { |
356 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 353 creation_locations.in_applications_menu_chrome_apps_subdir, |
357 base::PATH_START : base::DIR_APP_DATA, | 354 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
358 (base::win::GetVersion() >= base::win::VERSION_WIN7) ? | 355 }, { |
359 NULL : L"Microsoft\\Internet Explorer\\Quick Launch" | 356 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to |
357 // taskbar. This needs to be handled by callers. | |
358 creation_locations.in_quick_launch_bar && | |
359 base::win::GetVersion() < base::win::VERSION_WIN7, | |
360 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH | |
360 } | 361 } |
361 }; | 362 }; |
363 | |
364 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
362 // Populate shortcut_paths. | 365 // Populate shortcut_paths. |
363 for (int i = 0; i < arraysize(locations); ++i) { | 366 for (int i = 0; i < arraysize(locations); ++i) { |
364 if (locations[i].use_this_location) { | 367 if (locations[i].use_this_location) { |
365 base::FilePath path; | 368 base::FilePath path; |
366 | 369 |
367 // Skip the Win7 case. | 370 if (!ShellUtil::GetShortcutPath(locations[i].location_id, |
368 if (locations[i].location_id == base::PATH_START) | 371 dist, |
369 continue; | 372 ShellUtil::CURRENT_USER, |
370 | 373 &path)) { |
371 if (!PathService::Get(locations[i].location_id, &path)) { | 374 NOTREACHED(); |
372 continue; | 375 continue; |
373 } | 376 } |
374 | 377 |
375 if (locations[i].subdir != NULL) | |
376 path = path.Append(locations[i].subdir); | |
377 shortcut_paths.push_back(path); | 378 shortcut_paths.push_back(path); |
378 } | 379 } |
379 } | 380 } |
380 return shortcut_paths; | 381 return shortcut_paths; |
381 } | 382 } |
382 | 383 |
383 } // namespace internals | 384 } // namespace internals |
384 | 385 |
385 } // namespace web_app | 386 } // namespace web_app |
OLD | NEW |