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

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: Address comments 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
« no previous file with comments | « chrome/browser/web_applications/web_app_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 extensions::FileHandlersInfo& file_handlers_info, 380 const extensions::FileHandlersInfo& file_handlers_info,
382 const ShellIntegration::ShortcutLocations& creation_locations, 381 const web_app::ShortcutLocations& creation_locations,
383 ShortcutCreationReason creation_reason) { 382 ShortcutCreationReason creation_reason) {
384 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
385 384
386 // Shortcut paths under which to create shortcuts. 385 // Shortcut paths under which to create shortcuts.
387 std::vector<base::FilePath> shortcut_paths = 386 std::vector<base::FilePath> shortcut_paths =
388 GetShortcutPaths(creation_locations); 387 GetShortcutPaths(creation_locations);
389 388
390 bool pin_to_taskbar = creation_locations.in_quick_launch_bar && 389 bool pin_to_taskbar = creation_locations.in_quick_launch_bar &&
391 (base::win::GetVersion() >= base::win::VERSION_WIN7); 390 (base::win::GetVersion() >= base::win::VERSION_WIN7);
392 391
(...skipping 20 matching lines...) Expand all
413 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str())) 412 if (!base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()))
414 return false; 413 return false;
415 } 414 }
416 415
417 return true; 416 return true;
418 } 417 }
419 418
420 void UpdatePlatformShortcuts( 419 void UpdatePlatformShortcuts(
421 const base::FilePath& web_app_path, 420 const base::FilePath& web_app_path,
422 const base::string16& old_app_title, 421 const base::string16& old_app_title,
423 const ShellIntegration::ShortcutInfo& shortcut_info, 422 const web_app::ShortcutInfo& shortcut_info,
424 const extensions::FileHandlersInfo& file_handlers_info) { 423 const extensions::FileHandlersInfo& file_handlers_info) {
425 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 424 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
426 425
427 // Generates file name to use with persisted ico and shortcut file. 426 // Generates file name to use with persisted ico and shortcut file.
428 base::FilePath file_name = 427 base::FilePath file_name =
429 web_app::internals::GetSanitizedFileName(shortcut_info.title); 428 web_app::internals::GetSanitizedFileName(shortcut_info.title);
430 429
431 if (old_app_title != shortcut_info.title) { 430 if (old_app_title != shortcut_info.title) {
432 // The app's title has changed. Delete all existing app shortcuts and 431 // The app's title has changed. Delete all existing app shortcuts and
433 // recreate them in any locations they already existed (but do not add them 432 // recreate them in any locations they already existed (but do not add them
(...skipping 18 matching lines...) Expand all
452 } 451 }
453 } 452 }
454 453
455 // Update the icon if necessary. 454 // Update the icon if necessary.
456 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); 455 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title);
457 CheckAndSaveIcon(icon_file, shortcut_info.favicon); 456 CheckAndSaveIcon(icon_file, shortcut_info.favicon);
458 } 457 }
459 458
460 void DeletePlatformShortcuts( 459 void DeletePlatformShortcuts(
461 const base::FilePath& web_app_path, 460 const base::FilePath& web_app_path,
462 const ShellIntegration::ShortcutInfo& shortcut_info) { 461 const web_app::ShortcutInfo& shortcut_info) {
463 GetShortcutLocationsAndDeleteShortcuts( 462 GetShortcutLocationsAndDeleteShortcuts(
464 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, 463 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL,
465 NULL); 464 NULL);
466 465
467 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. 466 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it.
468 base::FilePath chrome_apps_dir; 467 base::FilePath chrome_apps_dir;
469 if (ShellUtil::GetShortcutPath( 468 if (ShellUtil::GetShortcutPath(
470 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 469 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
471 BrowserDistribution::GetDistribution(), 470 BrowserDistribution::GetDistribution(),
472 ShellUtil::CURRENT_USER, 471 ShellUtil::CURRENT_USER,
(...skipping 13 matching lines...) Expand all
486 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, 485 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
487 BrowserDistribution::GetDistribution(), 486 BrowserDistribution::GetDistribution(),
488 ShellUtil::CURRENT_USER, 487 ShellUtil::CURRENT_USER,
489 &chrome_apps_dir)) { 488 &chrome_apps_dir)) {
490 if (base::IsDirectoryEmpty(chrome_apps_dir)) 489 if (base::IsDirectoryEmpty(chrome_apps_dir))
491 base::DeleteFile(chrome_apps_dir, false); 490 base::DeleteFile(chrome_apps_dir, false);
492 } 491 }
493 } 492 }
494 493
495 std::vector<base::FilePath> GetShortcutPaths( 494 std::vector<base::FilePath> GetShortcutPaths(
496 const ShellIntegration::ShortcutLocations& creation_locations) { 495 const web_app::ShortcutLocations& creation_locations) {
497 // Shortcut paths under which to create shortcuts. 496 // Shortcut paths under which to create shortcuts.
498 std::vector<base::FilePath> shortcut_paths; 497 std::vector<base::FilePath> shortcut_paths;
499 // Locations to add to shortcut_paths. 498 // Locations to add to shortcut_paths.
500 struct { 499 struct {
501 bool use_this_location; 500 bool use_this_location;
502 ShellUtil::ShortcutLocation location_id; 501 ShellUtil::ShortcutLocation location_id;
503 } locations[] = { 502 } locations[] = {
504 { 503 {
505 creation_locations.on_desktop, 504 creation_locations.on_desktop,
506 ShellUtil::SHORTCUT_LOCATION_DESKTOP 505 ShellUtil::SHORTCUT_LOCATION_DESKTOP
507 }, { 506 }, {
508 creation_locations.applications_menu_location == 507 creation_locations.applications_menu_location ==
509 ShellIntegration::APP_MENU_LOCATION_ROOT, 508 web_app::APP_MENU_LOCATION_ROOT,
510 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT 509 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT
511 }, { 510 }, {
512 creation_locations.applications_menu_location == 511 creation_locations.applications_menu_location ==
513 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROME, 512 web_app::APP_MENU_LOCATION_SUBDIR_CHROME,
514 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR 513 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
515 }, { 514 }, {
516 creation_locations.applications_menu_location == 515 creation_locations.applications_menu_location ==
517 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 516 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
518 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR 517 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR
519 }, { 518 }, {
520 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to 519 // For Win7+, |in_quick_launch_bar| indicates that we are pinning to
521 // taskbar. This needs to be handled by callers. 520 // taskbar. This needs to be handled by callers.
522 creation_locations.in_quick_launch_bar && 521 creation_locations.in_quick_launch_bar &&
523 base::win::GetVersion() < base::win::VERSION_WIN7, 522 base::win::GetVersion() < base::win::VERSION_WIN7,
524 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH 523 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH
525 } 524 }
526 }; 525 };
527 526
(...skipping 23 matching lines...) Expand all
551 550
552 } // namespace internals 551 } // namespace internals
553 552
554 void UpdateShortcutForTabContents(content::WebContents* web_contents) { 553 void UpdateShortcutForTabContents(content::WebContents* web_contents) {
555 // UpdateShortcutWorker will delete itself when it's done. 554 // UpdateShortcutWorker will delete itself when it's done.
556 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); 555 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents);
557 worker->Run(); 556 worker->Run();
558 } 557 }
559 558
560 } // namespace web_app 559 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698