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 | 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/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/installer/util/browser_distribution.h" | 22 #include "chrome/installer/util/browser_distribution.h" |
23 #include "chrome/installer/util/shell_util.h" | 23 #include "chrome/installer/util/shell_util.h" |
24 #include "chrome/installer/util/util_constants.h" | 24 #include "chrome/installer/util/util_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "ui/base/win/shell.h" |
26 #include "ui/gfx/icon_util.h" | 27 #include "ui/gfx/icon_util.h" |
27 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
28 #include "ui/gfx/image/image_family.h" | 29 #include "ui/gfx/image/image_family.h" |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 const base::FilePath::CharType kIconChecksumFileExt[] = | 33 const base::FilePath::CharType kIconChecksumFileExt[] = |
33 FILE_PATH_LITERAL(".ico.md5"); | 34 FILE_PATH_LITERAL(".ico.md5"); |
34 | 35 |
35 // Calculates checksum of an icon family using MD5. | 36 // Calculates checksum of an icon family using MD5. |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); | 317 for (std::vector<base::FilePath>::const_iterator j = shortcut_files.begin(); |
317 j != shortcut_files.end(); ++j) { | 318 j != shortcut_files.end(); ++j) { |
318 // Any shortcut could have been pinned, either by chrome or the user, so | 319 // Any shortcut could have been pinned, either by chrome or the user, so |
319 // they are all unpinned. | 320 // they are all unpinned. |
320 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 321 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
321 base::DeleteFile(*j, false); | 322 base::DeleteFile(*j, false); |
322 } | 323 } |
323 } | 324 } |
324 } | 325 } |
325 | 326 |
| 327 void CreateIconAndSetRelaunchDetails(const base::FilePath& web_app_path, |
| 328 const base::FilePath& icon_file, |
| 329 const web_app::ShortcutInfo& shortcut_info, |
| 330 HWND hwnd) { |
| 331 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 332 |
| 333 CommandLine command_line = |
| 334 ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
| 335 shortcut_info.extension_id, |
| 336 shortcut_info.profile_path); |
| 337 |
| 338 base::FilePath chrome_exe; |
| 339 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 340 NOTREACHED(); |
| 341 return; |
| 342 } |
| 343 command_line.SetProgram(chrome_exe); |
| 344 ui::win::SetRelaunchDetailsForWindow( |
| 345 command_line.GetCommandLineString(), shortcut_info.title, hwnd); |
| 346 |
| 347 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) |
| 348 return; |
| 349 |
| 350 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
| 351 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
| 352 } |
| 353 |
| 354 void OnShortcutInfoLoadedForSetRelaunchDetails( |
| 355 HWND hwnd, |
| 356 const web_app::ShortcutInfo& shortcut_info) { |
| 357 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 358 |
| 359 // Set window's icon to the one we're about to create/update in the web app |
| 360 // path. The icon cache will refresh on icon creation. |
| 361 base::FilePath web_app_path = |
| 362 web_app::GetWebAppDataDirectory(shortcut_info.profile_path, |
| 363 shortcut_info.extension_id, |
| 364 shortcut_info.url); |
| 365 base::FilePath icon_file = |
| 366 web_app_path.Append(web_app::internals::GetSanitizedFileName( |
| 367 shortcut_info.title)) |
| 368 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); |
| 369 |
| 370 content::BrowserThread::PostBlockingPoolTask( |
| 371 FROM_HERE, |
| 372 base::Bind(&CreateIconAndSetRelaunchDetails, |
| 373 web_app_path, |
| 374 icon_file, |
| 375 shortcut_info, |
| 376 hwnd)); |
| 377 } |
| 378 |
326 } // namespace | 379 } // namespace |
327 | 380 |
328 namespace web_app { | 381 namespace web_app { |
329 | 382 |
330 base::FilePath CreateShortcutInWebAppDir(const base::FilePath& web_app_dir, | 383 base::FilePath CreateShortcutInWebAppDir(const base::FilePath& web_app_dir, |
331 const ShortcutInfo& shortcut_info) { | 384 const ShortcutInfo& shortcut_info) { |
332 std::vector<base::FilePath> paths; | 385 std::vector<base::FilePath> paths; |
333 paths.push_back(web_app_dir); | 386 paths.push_back(web_app_dir); |
334 std::vector<base::FilePath> out_filenames; | 387 std::vector<base::FilePath> out_filenames; |
335 base::FilePath web_app_dir_shortcut = | 388 base::FilePath web_app_dir_shortcut = |
336 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) | 389 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) |
337 .AddExtension(installer::kLnkExt); | 390 .AddExtension(installer::kLnkExt); |
338 if (!PathExists(web_app_dir_shortcut)) { | 391 if (!PathExists(web_app_dir_shortcut)) { |
339 CreateShortcutsInPaths(web_app_dir, | 392 CreateShortcutsInPaths(web_app_dir, |
340 shortcut_info, | 393 shortcut_info, |
341 paths, | 394 paths, |
342 SHORTCUT_CREATION_BY_USER, | 395 SHORTCUT_CREATION_BY_USER, |
343 &out_filenames); | 396 &out_filenames); |
344 DCHECK_EQ(out_filenames.size(), 1u); | 397 DCHECK_EQ(out_filenames.size(), 1u); |
345 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); | 398 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); |
346 } else { | 399 } else { |
347 internals::CheckAndSaveIcon( | 400 internals::CheckAndSaveIcon( |
348 internals::GetIconFilePath(web_app_dir, shortcut_info.title), | 401 internals::GetIconFilePath(web_app_dir, shortcut_info.title), |
349 shortcut_info.favicon); | 402 shortcut_info.favicon); |
350 } | 403 } |
351 return web_app_dir_shortcut; | 404 return web_app_dir_shortcut; |
352 } | 405 } |
353 | 406 |
| 407 void UpdateRelaunchDetailsForApp(Profile* profile, |
| 408 const extensions::Extension* extension, |
| 409 HWND hwnd) { |
| 410 web_app::UpdateShortcutInfoAndIconForApp( |
| 411 extension, |
| 412 profile, |
| 413 base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd)); |
| 414 } |
| 415 |
354 namespace internals { | 416 namespace internals { |
355 | 417 |
356 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | 418 // Saves |image| to |icon_file| if the file is outdated and refresh shell's |
357 // icon cache to ensure correct icon is displayed. Returns true if icon_file | 419 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
358 // is up to date or successfully updated. | 420 // is up to date or successfully updated. |
359 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 421 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
360 const gfx::ImageFamily& image) { | 422 const gfx::ImageFamily& image) { |
361 if (ShouldUpdateIcon(icon_file, image)) { | 423 if (ShouldUpdateIcon(icon_file, image)) { |
362 if (SaveIconWithCheckSum(icon_file, image)) { | 424 if (SaveIconWithCheckSum(icon_file, image)) { |
363 // Refresh shell's icon cache. This call is quite disruptive as user would | 425 // Refresh shell's icon cache. This call is quite disruptive as user would |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 610 |
549 } // namespace internals | 611 } // namespace internals |
550 | 612 |
551 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 613 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
552 // UpdateShortcutWorker will delete itself when it's done. | 614 // UpdateShortcutWorker will delete itself when it's done. |
553 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 615 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
554 worker->Run(); | 616 worker->Run(); |
555 } | 617 } |
556 | 618 |
557 } // namespace web_app | 619 } // namespace web_app |
OLD | NEW |