| 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_win.h" | 5 #include "chrome/browser/web_applications/web_app_win.h" |
| 6 | 6 |
| 7 #include <shlobj.h> | 7 #include <shlobj.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // they are all unpinned. | 332 // they are all unpinned. |
| 333 base::win::UnpinShortcutFromTaskbar(*j); | 333 base::win::UnpinShortcutFromTaskbar(*j); |
| 334 base::DeleteFile(*j, false); | 334 base::DeleteFile(*j, false); |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 void CreateIconAndSetRelaunchDetails( | 339 void CreateIconAndSetRelaunchDetails( |
| 340 const base::FilePath& web_app_path, | 340 const base::FilePath& web_app_path, |
| 341 const base::FilePath& icon_file, | 341 const base::FilePath& icon_file, |
| 342 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 342 scoped_refptr<web_app::ShortcutInfo> shortcut_info, |
| 343 HWND hwnd) { | 343 HWND hwnd) { |
| 344 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 344 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 345 | 345 |
| 346 base::CommandLine command_line = | 346 base::CommandLine command_line = |
| 347 shell_integration::CommandLineArgsForLauncher( | 347 shell_integration::CommandLineArgsForLauncher( |
| 348 shortcut_info->url, shortcut_info->extension_id, | 348 shortcut_info->url, shortcut_info->extension_id, |
| 349 shortcut_info->profile_path); | 349 shortcut_info->profile_path); |
| 350 | 350 |
| 351 base::FilePath chrome_exe; | 351 base::FilePath chrome_exe; |
| 352 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 352 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 353 NOTREACHED(); | 353 NOTREACHED(); |
| 354 return; | 354 return; |
| 355 } | 355 } |
| 356 command_line.SetProgram(chrome_exe); | 356 command_line.SetProgram(chrome_exe); |
| 357 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), | 357 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), |
| 358 shortcut_info->title, hwnd); | 358 shortcut_info->title, hwnd); |
| 359 | 359 |
| 360 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) | 360 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) |
| 361 return; | 361 return; |
| 362 | 362 |
| 363 ui::win::SetAppIconForWindow(icon_file, 0, hwnd); | 363 ui::win::SetAppIconForWindow(icon_file, 0, hwnd); |
| 364 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info->favicon, true); | 364 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info->favicon, true); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void OnShortcutInfoLoadedForSetRelaunchDetails( | 367 void OnShortcutInfoLoadedForSetRelaunchDetails( |
| 368 HWND hwnd, | 368 HWND hwnd, |
| 369 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | 369 scoped_refptr<web_app::ShortcutInfo> shortcut_info) { |
| 370 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 370 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 371 | 371 |
| 372 // Set window's icon to the one we're about to create/update in the web app | 372 // Set window's icon to the one we're about to create/update in the web app |
| 373 // path. The icon cache will refresh on icon creation. | 373 // path. The icon cache will refresh on icon creation. |
| 374 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( | 374 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( |
| 375 shortcut_info->profile_path, shortcut_info->extension_id, | 375 shortcut_info->profile_path, shortcut_info->extension_id, |
| 376 shortcut_info->url); | 376 shortcut_info->url); |
| 377 base::FilePath icon_file = | 377 base::FilePath icon_file = |
| 378 web_app::internals::GetIconFilePath(web_app_path, shortcut_info->title); | 378 web_app::internals::GetIconFilePath(web_app_path, shortcut_info->title); |
| 379 content::BrowserThread::PostBlockingPoolTask( | 379 content::BrowserThread::PostBlockingPoolTask( |
| 380 FROM_HERE, base::Bind(&CreateIconAndSetRelaunchDetails, web_app_path, | 380 FROM_HERE, base::Bind(&CreateIconAndSetRelaunchDetails, web_app_path, |
| 381 icon_file, base::Passed(&shortcut_info), hwnd)); | 381 icon_file, std::move(shortcut_info), hwnd)); |
| 382 } | 382 } |
| 383 | 383 |
| 384 } // namespace | 384 } // namespace |
| 385 | 385 |
| 386 namespace web_app { | 386 namespace web_app { |
| 387 | 387 |
| 388 base::FilePath CreateShortcutInWebAppDir( | 388 base::FilePath CreateShortcutInWebAppDir( |
| 389 const base::FilePath& web_app_dir, | 389 const base::FilePath& web_app_dir, |
| 390 std::unique_ptr<ShortcutInfo> shortcut_info) { | 390 scoped_refptr<ShortcutInfo> shortcut_info) { |
| 391 std::vector<base::FilePath> paths; | 391 std::vector<base::FilePath> paths; |
| 392 paths.push_back(web_app_dir); | 392 paths.push_back(web_app_dir); |
| 393 std::vector<base::FilePath> out_filenames; | 393 std::vector<base::FilePath> out_filenames; |
| 394 base::FilePath web_app_dir_shortcut = | 394 base::FilePath web_app_dir_shortcut = |
| 395 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info->title)) | 395 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info->title)) |
| 396 .AddExtension(installer::kLnkExt); | 396 .AddExtension(installer::kLnkExt); |
| 397 if (!PathExists(web_app_dir_shortcut)) { | 397 if (!PathExists(web_app_dir_shortcut)) { |
| 398 CreateShortcutsInPaths(web_app_dir, *shortcut_info, paths, | 398 CreateShortcutsInPaths(web_app_dir, *shortcut_info, paths, |
| 399 SHORTCUT_CREATION_BY_USER, &out_filenames); | 399 SHORTCUT_CREATION_BY_USER, &out_filenames); |
| 400 DCHECK_EQ(out_filenames.size(), 1u); | 400 DCHECK_EQ(out_filenames.size(), 1u); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 if (refresh_shell_icon_cache) { | 435 if (refresh_shell_icon_cache) { |
| 436 // Refresh shell's icon cache. This call is quite disruptive as user would | 436 // Refresh shell's icon cache. This call is quite disruptive as user would |
| 437 // see explorer rebuilding the icon cache. It would be great that we find | 437 // see explorer rebuilding the icon cache. It would be great that we find |
| 438 // a better way to achieve this. | 438 // a better way to achieve this. |
| 439 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, | 439 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, |
| 440 NULL); | 440 NULL); |
| 441 } | 441 } |
| 442 return true; | 442 return true; |
| 443 } | 443 } |
| 444 | 444 |
| 445 bool CreatePlatformShortcuts( | 445 bool CreatePlatformShortcuts(const base::FilePath& web_app_path, |
| 446 const base::FilePath& web_app_path, | 446 scoped_refptr<ShortcutInfo> shortcut_info, |
| 447 std::unique_ptr<ShortcutInfo> shortcut_info, | 447 const ShortcutLocations& creation_locations, |
| 448 const ShortcutLocations& creation_locations, | 448 ShortcutCreationReason creation_reason) { |
| 449 ShortcutCreationReason creation_reason) { | |
| 450 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 449 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 451 | 450 |
| 452 // Nothing to do on Windows for hidden apps. | 451 // Nothing to do on Windows for hidden apps. |
| 453 if (creation_locations.applications_menu_location == APP_MENU_LOCATION_HIDDEN) | 452 if (creation_locations.applications_menu_location == APP_MENU_LOCATION_HIDDEN) |
| 454 return true; | 453 return true; |
| 455 | 454 |
| 456 // Shortcut paths under which to create shortcuts. | 455 // Shortcut paths under which to create shortcuts. |
| 457 std::vector<base::FilePath> shortcut_paths = | 456 std::vector<base::FilePath> shortcut_paths = |
| 458 GetShortcutPaths(creation_locations); | 457 GetShortcutPaths(creation_locations); |
| 459 | 458 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 482 AddExtension(installer::kLnkExt); | 481 AddExtension(installer::kLnkExt); |
| 483 if (!base::win::PinShortcutToTaskbar(shortcut_to_pin)) | 482 if (!base::win::PinShortcutToTaskbar(shortcut_to_pin)) |
| 484 return false; | 483 return false; |
| 485 } | 484 } |
| 486 | 485 |
| 487 return true; | 486 return true; |
| 488 } | 487 } |
| 489 | 488 |
| 490 void UpdatePlatformShortcuts(const base::FilePath& web_app_path, | 489 void UpdatePlatformShortcuts(const base::FilePath& web_app_path, |
| 491 const base::string16& old_app_title, | 490 const base::string16& old_app_title, |
| 492 std::unique_ptr<ShortcutInfo> shortcut_info) { | 491 scoped_refptr<ShortcutInfo> shortcut_info) { |
| 493 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 492 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 494 | 493 |
| 495 // Generates file name to use with persisted ico and shortcut file. | 494 // Generates file name to use with persisted ico and shortcut file. |
| 496 base::FilePath file_name = | 495 base::FilePath file_name = |
| 497 web_app::internals::GetSanitizedFileName(shortcut_info->title); | 496 web_app::internals::GetSanitizedFileName(shortcut_info->title); |
| 498 | 497 |
| 499 if (old_app_title != shortcut_info->title) { | 498 if (old_app_title != shortcut_info->title) { |
| 500 // The app's title has changed. Delete all existing app shortcuts and | 499 // The app's title has changed. Delete all existing app shortcuts and |
| 501 // recreate them in any locations they already existed (but do not add them | 500 // recreate them in any locations they already existed (but do not add them |
| 502 // to locations where they do not currently exist). | 501 // to locations where they do not currently exist). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 520 } | 519 } |
| 521 } | 520 } |
| 522 | 521 |
| 523 // Update the icon if necessary. | 522 // Update the icon if necessary. |
| 524 base::FilePath icon_file = | 523 base::FilePath icon_file = |
| 525 GetIconFilePath(web_app_path, shortcut_info->title); | 524 GetIconFilePath(web_app_path, shortcut_info->title); |
| 526 CheckAndSaveIcon(icon_file, shortcut_info->favicon, true); | 525 CheckAndSaveIcon(icon_file, shortcut_info->favicon, true); |
| 527 } | 526 } |
| 528 | 527 |
| 529 void DeletePlatformShortcuts(const base::FilePath& web_app_path, | 528 void DeletePlatformShortcuts(const base::FilePath& web_app_path, |
| 530 std::unique_ptr<ShortcutInfo> shortcut_info) { | 529 scoped_refptr<ShortcutInfo> shortcut_info) { |
| 531 GetShortcutLocationsAndDeleteShortcuts(web_app_path, | 530 GetShortcutLocationsAndDeleteShortcuts(web_app_path, |
| 532 shortcut_info->profile_path, | 531 shortcut_info->profile_path, |
| 533 shortcut_info->title, NULL, NULL); | 532 shortcut_info->title, NULL, NULL); |
| 534 | 533 |
| 535 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. | 534 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. |
| 536 base::FilePath chrome_apps_dir; | 535 base::FilePath chrome_apps_dir; |
| 537 if (ShellUtil::GetShortcutPath( | 536 if (ShellUtil::GetShortcutPath( |
| 538 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, | 537 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
| 539 BrowserDistribution::GetDistribution(), | 538 BrowserDistribution::GetDistribution(), |
| 540 ShellUtil::CURRENT_USER, | 539 ShellUtil::CURRENT_USER, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 617 |
| 619 } // namespace internals | 618 } // namespace internals |
| 620 | 619 |
| 621 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 620 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
| 622 // UpdateShortcutWorker will delete itself when it's done. | 621 // UpdateShortcutWorker will delete itself when it's done. |
| 623 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 622 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
| 624 worker->Run(); | 623 worker->Run(); |
| 625 } | 624 } |
| 626 | 625 |
| 627 } // namespace web_app | 626 } // namespace web_app |
| OLD | NEW |