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

Side by Side Diff: chrome/browser/web_applications/web_app_win.cc

Issue 231673005: Move ShortcutInfo, ShortcutLocations from ShellIntegration to web_app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windws Created 6 years, 8 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 #include "chrome/browser/web_applications/web_app_win.h" 5 #include "chrome/browser/web_applications/web_app_win.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/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/shortcut.h" 18 #include "base/win/shortcut.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "chrome/browser/web_applications/update_shortcut_worker_win.h" 20 #include "chrome/browser/web_applications/update_shortcut_worker_win.h"
21 #include "chrome/browser/web_applications/web_app.h"
22 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
23 #include "chrome/installer/util/browser_distribution.h" 22 #include "chrome/installer/util/browser_distribution.h"
24 #include "chrome/installer/util/shell_util.h" 23 #include "chrome/installer/util/shell_util.h"
25 #include "chrome/installer/util/util_constants.h" 24 #include "chrome/installer/util/util_constants.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 #include "ui/gfx/icon_util.h" 26 #include "ui/gfx/icon_util.h"
28 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_family.h" 28 #include "ui/gfx/image/image_family.h"
30 29
31 namespace { 30 namespace {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 153 }
155 154
156 // Creates application shortcuts in a given set of paths. 155 // Creates application shortcuts in a given set of paths.
157 // |shortcut_paths| is a list of directories in which shortcuts should be 156 // |shortcut_paths| is a list of directories in which shortcuts should be
158 // created. If |creation_reason| is SHORTCUT_CREATION_AUTOMATED and there is an 157 // created. If |creation_reason| is SHORTCUT_CREATION_AUTOMATED and there is an
159 // existing shortcut to this app for this profile, does nothing (succeeding). 158 // existing shortcut to this app for this profile, does nothing (succeeding).
160 // Returns true on success, false on failure. 159 // Returns true on success, false on failure.
161 // Must be called on the FILE thread. 160 // Must be called on the FILE thread.
162 bool CreateShortcutsInPaths( 161 bool CreateShortcutsInPaths(
163 const base::FilePath& web_app_path, 162 const base::FilePath& web_app_path,
164 const ShellIntegration::ShortcutInfo& shortcut_info, 163 const web_app::ShortcutInfo& shortcut_info,
165 const std::vector<base::FilePath>& shortcut_paths, 164 const std::vector<base::FilePath>& shortcut_paths,
166 web_app::ShortcutCreationReason creation_reason, 165 web_app::ShortcutCreationReason creation_reason,
167 std::vector<base::FilePath>* out_filenames) { 166 std::vector<base::FilePath>* out_filenames) {
168 // Ensure web_app_path exists. 167 // Ensure web_app_path exists.
169 if (!base::PathExists(web_app_path) && 168 if (!base::PathExists(web_app_path) &&
170 !base::CreateDirectory(web_app_path)) { 169 !base::CreateDirectory(web_app_path)) {
171 return false; 170 return false;
172 } 171 }
173 172
174 // Generates file name to use with persisted ico and shortcut file. 173 // Generates file name to use with persisted ico and shortcut file.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // shortcuts. Both of these may be NULL. 271 // shortcuts. Both of these may be NULL.
273 void GetShortcutLocationsAndDeleteShortcuts( 272 void GetShortcutLocationsAndDeleteShortcuts(
274 const base::FilePath& web_app_path, 273 const base::FilePath& web_app_path,
275 const base::FilePath& profile_path, 274 const base::FilePath& profile_path,
276 const base::string16& title, 275 const base::string16& title,
277 bool* was_pinned_to_taskbar, 276 bool* was_pinned_to_taskbar,
278 std::vector<base::FilePath>* shortcut_paths) { 277 std::vector<base::FilePath>* shortcut_paths) {
279 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 278 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
280 279
281 // Get all possible locations for shortcuts. 280 // Get all possible locations for shortcuts.
282 ShellIntegration::ShortcutLocations all_shortcut_locations; 281 web_app::ShortcutLocations all_shortcut_locations;
283 all_shortcut_locations.in_quick_launch_bar = true; 282 all_shortcut_locations.in_quick_launch_bar = true;
284 all_shortcut_locations.on_desktop = true; 283 all_shortcut_locations.on_desktop = true;
285 // Delete shortcuts from the Chrome Apps subdirectory. 284 // Delete shortcuts from the Chrome Apps subdirectory.
286 // This matches the subdir name set by CreateApplicationShortcutView::Accept 285 // This matches the subdir name set by CreateApplicationShortcutView::Accept
287 // for Chrome apps (not URL apps, but this function does not apply for them). 286 // for Chrome apps (not URL apps, but this function does not apply for them).
288 all_shortcut_locations.applications_menu_location = 287 all_shortcut_locations.applications_menu_location =
289 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; 288 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
290 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths( 289 std::vector<base::FilePath> all_paths = web_app::internals::GetShortcutPaths(
291 all_shortcut_locations); 290 all_shortcut_locations);
292 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 291 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
293 !web_app_path.empty()) { 292 !web_app_path.empty()) {
294 all_paths.push_back(web_app_path); 293 all_paths.push_back(web_app_path);
295 } 294 }
296 295
297 if (was_pinned_to_taskbar) { 296 if (was_pinned_to_taskbar) {
298 // Determine if there is a link to this app in the TaskBar pin directory. 297 // Determine if there is a link to this app in the TaskBar pin directory.
299 base::FilePath taskbar_pin_path; 298 base::FilePath taskbar_pin_path;
(...skipping 23 matching lines...) Expand all
323 } 322 }
324 } 323 }
325 } 324 }
326 325
327 } // namespace 326 } // namespace
328 327
329 namespace web_app { 328 namespace web_app {
330 329
331 base::FilePath CreateShortcutInWebAppDir( 330 base::FilePath CreateShortcutInWebAppDir(
332 const base::FilePath& web_app_dir, 331 const base::FilePath& web_app_dir,
333 const ShellIntegration::ShortcutInfo& shortcut_info) { 332 const web_app::ShortcutInfo& shortcut_info) {
334 std::vector<base::FilePath> paths; 333 std::vector<base::FilePath> paths;
335 paths.push_back(web_app_dir); 334 paths.push_back(web_app_dir);
336 std::vector<base::FilePath> out_filenames; 335 std::vector<base::FilePath> out_filenames;
337 base::FilePath web_app_dir_shortcut = 336 base::FilePath web_app_dir_shortcut =
338 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) 337 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title))
339 .AddExtension(installer::kLnkExt); 338 .AddExtension(installer::kLnkExt);
340 if (!PathExists(web_app_dir_shortcut)) { 339 if (!PathExists(web_app_dir_shortcut)) {
341 CreateShortcutsInPaths(web_app_dir, 340 CreateShortcutsInPaths(web_app_dir,
342 shortcut_info, 341 shortcut_info,
343 paths, 342 paths,
(...skipping 26 matching lines...) Expand all
370 } else { 369 } else {
371 return false; 370 return false;
372 } 371 }
373 } 372 }
374 373
375 return true; 374 return true;
376 } 375 }
377 376
378 bool CreatePlatformShortcuts( 377 bool CreatePlatformShortcuts(
379 const base::FilePath& web_app_path, 378 const base::FilePath& web_app_path,
380 const ShellIntegration::ShortcutInfo& shortcut_info, 379 const web_app::ShortcutInfo& shortcut_info,
381 const ShellIntegration::ShortcutLocations& creation_locations, 380 const web_app::ShortcutLocations& creation_locations,
382 ShortcutCreationReason creation_reason) { 381 ShortcutCreationReason creation_reason) {
383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 382 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
384 383
385 // Shortcut paths under which to create shortcuts. 384 // Shortcut paths under which to create shortcuts.
386 std::vector<base::FilePath> shortcut_paths = 385 std::vector<base::FilePath> shortcut_paths =
387 GetShortcutPaths(creation_locations); 386 GetShortcutPaths(creation_locations);
388 387
389 bool pin_to_taskbar = creation_locations.in_quick_launch_bar && 388 bool pin_to_taskbar = creation_locations.in_quick_launch_bar &&
390 (base::win::GetVersion() >= base::win::VERSION_WIN7); 389 (base::win::GetVersion() >= base::win::VERSION_WIN7);
391 390
(...skipping 20 matching lines...) Expand all
412 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str())) 411 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()))
413 return false; 412 return false;
414 } 413 }
415 414
416 return true; 415 return true;
417 } 416 }
418 417
419 void UpdatePlatformShortcuts( 418 void UpdatePlatformShortcuts(
420 const base::FilePath& web_app_path, 419 const base::FilePath& web_app_path,
421 const base::string16& old_app_title, 420 const base::string16& old_app_title,
422 const ShellIntegration::ShortcutInfo& shortcut_info) { 421 const web_app::ShortcutInfo& shortcut_info) {
423 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 422 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
424 423
425 // Generates file name to use with persisted ico and shortcut file. 424 // Generates file name to use with persisted ico and shortcut file.
426 base::FilePath file_name = 425 base::FilePath file_name =
427 web_app::internals::GetSanitizedFileName(shortcut_info.title); 426 web_app::internals::GetSanitizedFileName(shortcut_info.title);
428 427
429 if (old_app_title != shortcut_info.title) { 428 if (old_app_title != shortcut_info.title) {
430 // The app's title has changed. Delete all existing app shortcuts and 429 // The app's title has changed. Delete all existing app shortcuts and
431 // recreate them in any locations they already existed (but do not add them 430 // recreate them in any locations they already existed (but do not add them
432 // to locations where they do not currently exist). 431 // to locations where they do not currently exist).
(...skipping 17 matching lines...) Expand all
450 } 449 }
451 } 450 }
452 451
453 // Update the icon if necessary. 452 // Update the icon if necessary.
454 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); 453 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title);
455 CheckAndSaveIcon(icon_file, shortcut_info.favicon); 454 CheckAndSaveIcon(icon_file, shortcut_info.favicon);
456 } 455 }
457 456
458 void DeletePlatformShortcuts( 457 void DeletePlatformShortcuts(
459 const base::FilePath& web_app_path, 458 const base::FilePath& web_app_path,
460 const ShellIntegration::ShortcutInfo& shortcut_info) { 459 const web_app::ShortcutInfo& shortcut_info) {
461 GetShortcutLocationsAndDeleteShortcuts( 460 GetShortcutLocationsAndDeleteShortcuts(
462 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 461 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL,
463 NULL); 462 NULL);
464 463
465 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 464 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
466 base::FilePath chrome_apps_dir; 465 base::FilePath chrome_apps_dir;
467 if (ShellUtil::GetShortcutPath( 466 if (ShellUtil::GetShortcutPath(
468 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 467 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
469 BrowserDistribution::GetDistribution(), 468 BrowserDistribution::GetDistribution(),
470 ShellUtil::CURRENT_USER, 469 ShellUtil::CURRENT_USER,
(...skipping 13 matching lines...) Expand all
484 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 483 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
485 BrowserDistribution::GetDistribution(), 484 BrowserDistribution::GetDistribution(),
486 ShellUtil::CURRENT_USER, 485 ShellUtil::CURRENT_USER,
487 &chrome_apps_dir)) { 486 &chrome_apps_dir)) {
488 if (base::IsDirectoryEmpty(chrome_apps_dir)) 487 if (base::IsDirectoryEmpty(chrome_apps_dir))
489 base::DeleteFile(chrome_apps_dir, false); 488 base::DeleteFile(chrome_apps_dir, false);
490 } 489 }
491 } 490 }
492 491
493 std::vector<base::FilePath> GetShortcutPaths( 492 std::vector<base::FilePath> GetShortcutPaths(
494 const ShellIntegration::ShortcutLocations& creation_locations) { 493 const web_app::ShortcutLocations& creation_locations) {
495 // Shortcut paths under which to create shortcuts. 494 // Shortcut paths under which to create shortcuts.
496 std::vector<base::FilePath> shortcut_paths; 495 std::vector<base::FilePath> shortcut_paths;
497 // Locations to add to shortcut_paths. 496 // Locations to add to shortcut_paths.
498 struct { 497 struct {
499 bool use_this_location; 498 bool use_this_location;
500 ShellUtil::ShortcutLocation location_id; 499 ShellUtil::ShortcutLocation location_id;
501 } locations[] = { 500 } locations[] = {
502 { 501 {
503 creation_locations.on_desktop, 502 creation_locations.on_desktop,
504 ShellUtil::SHORTCUT_LOCATION_DESKTOP 503 ShellUtil::SHORTCUT_LOCATION_DESKTOP
505 }, { 504 }, {
506 creation_locations.applications_menu_location == 505 creation_locations.applications_menu_location ==
507 ShellIntegration::APP_MENU_LOCATION_ROOT, 506 web_app::APP_MENU_LOCATION_ROOT,
508 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT 507 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT
509 }, { 508 }, {
510 creation_locations.applications_menu_location == 509 creation_locations.applications_menu_location ==
511 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROME, 510 web_app::APP_MENU_LOCATION_SUBDIR_CHROME,
512 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR 511 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
513 }, { 512 }, {
514 creation_locations.applications_menu_location == 513 creation_locations.applications_menu_location ==
515 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 514 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
516 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR 515 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
517 }, { 516 }, {
518 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to 517 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to
519 // taskbar. This needs to be handled by callers. 518 // taskbar. This needs to be handled by callers.
520 creation_locations.in_quick_launch_bar && 519 creation_locations.in_quick_launch_bar &&
521 base::win::GetVersion() < base::win::VERSION_WIN7, 520 base::win::GetVersion() < base::win::VERSION_WIN7,
522 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH 521 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
523 } 522 }
524 }; 523 };
525 524
(...skipping 23 matching lines...) Expand all
549 548
550 } // namespace internals 549 } // namespace internals
551 550
552 void UpdateShortcutForTabContents(content::WebContents* web_contents) { 551 void UpdateShortcutForTabContents(content::WebContents* web_contents) {
553 // UpdateShortcutWorker will delete itself when it's done. 552 // UpdateShortcutWorker will delete itself when it's done.
554 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); 553 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents);
555 worker->Run(); 554 worker->Run();
556 } 555 }
557 556
558 } // namespace web_app 557 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698