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)) { | |
sky
2014/05/23 13:27:27
nit: no {}
calamity
2014/05/26 01:54:48
Done.
| |
348 return; | |
349 } | |
350 | |
351 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | |
352 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | |
353 } | |
354 | |
355 void OnShortcutInfoLoadedForSetRelaunchDetails( | |
356 HWND hwnd, | |
357 const web_app::ShortcutInfo& shortcut_info) { | |
358 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
359 | |
360 // Set window's icon to the one we're about to create/update in the web app | |
361 // path. The icon cache will refresh on icon creation. | |
362 base::FilePath web_app_path = | |
363 web_app::GetWebAppDataDirectory(shortcut_info.profile_path, | |
364 shortcut_info.extension_id, | |
365 shortcut_info.url); | |
366 base::FilePath icon_file = | |
367 web_app_path.Append(web_app::internals::GetSanitizedFileName( | |
368 shortcut_info.title)) | |
369 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); | |
370 | |
371 content::BrowserThread::PostBlockingPoolTask( | |
372 FROM_HERE, | |
373 base::Bind(&CreateIconAndSetRelaunchDetails, | |
374 web_app_path, | |
375 icon_file, | |
376 shortcut_info, | |
377 hwnd)); | |
378 } | |
379 | |
326 } // namespace | 380 } // namespace |
327 | 381 |
328 namespace web_app { | 382 namespace web_app { |
329 | 383 |
330 base::FilePath CreateShortcutInWebAppDir( | 384 base::FilePath CreateShortcutInWebAppDir( |
331 const base::FilePath& web_app_dir, | 385 const base::FilePath& web_app_dir, |
332 const web_app::ShortcutInfo& shortcut_info) { | 386 const web_app::ShortcutInfo& shortcut_info) { |
333 std::vector<base::FilePath> paths; | 387 std::vector<base::FilePath> paths; |
334 paths.push_back(web_app_dir); | 388 paths.push_back(web_app_dir); |
335 std::vector<base::FilePath> out_filenames; | 389 std::vector<base::FilePath> out_filenames; |
336 base::FilePath web_app_dir_shortcut = | 390 base::FilePath web_app_dir_shortcut = |
337 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) | 391 web_app_dir.Append(internals::GetSanitizedFileName(shortcut_info.title)) |
338 .AddExtension(installer::kLnkExt); | 392 .AddExtension(installer::kLnkExt); |
339 if (!PathExists(web_app_dir_shortcut)) { | 393 if (!PathExists(web_app_dir_shortcut)) { |
340 CreateShortcutsInPaths(web_app_dir, | 394 CreateShortcutsInPaths(web_app_dir, |
341 shortcut_info, | 395 shortcut_info, |
342 paths, | 396 paths, |
343 SHORTCUT_CREATION_BY_USER, | 397 SHORTCUT_CREATION_BY_USER, |
344 &out_filenames); | 398 &out_filenames); |
345 DCHECK_EQ(out_filenames.size(), 1u); | 399 DCHECK_EQ(out_filenames.size(), 1u); |
346 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); | 400 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); |
347 } else { | 401 } else { |
348 internals::CheckAndSaveIcon( | 402 internals::CheckAndSaveIcon( |
349 internals::GetIconFilePath(web_app_dir, shortcut_info.title), | 403 internals::GetIconFilePath(web_app_dir, shortcut_info.title), |
350 shortcut_info.favicon); | 404 shortcut_info.favicon); |
351 } | 405 } |
352 return web_app_dir_shortcut; | 406 return web_app_dir_shortcut; |
353 } | 407 } |
354 | 408 |
409 void UpdateRelaunchDetailsForApp(Profile* profile, | |
410 const extensions::Extension* extension, | |
411 HWND hwnd) { | |
412 web_app::UpdateShortcutInfoAndIconForApp( | |
413 extension, | |
414 profile, | |
415 base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd)); | |
416 } | |
417 | |
355 namespace internals { | 418 namespace internals { |
356 | 419 |
357 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | 420 // Saves |image| to |icon_file| if the file is outdated and refresh shell's |
358 // icon cache to ensure correct icon is displayed. Returns true if icon_file | 421 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
359 // is up to date or successfully updated. | 422 // is up to date or successfully updated. |
360 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 423 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
361 const gfx::ImageFamily& image) { | 424 const gfx::ImageFamily& image) { |
362 if (ShouldUpdateIcon(icon_file, image)) { | 425 if (ShouldUpdateIcon(icon_file, image)) { |
363 if (SaveIconWithCheckSum(icon_file, image)) { | 426 if (SaveIconWithCheckSum(icon_file, image)) { |
364 // Refresh shell's icon cache. This call is quite disruptive as user would | 427 // Refresh shell's icon cache. This call is quite disruptive as user would |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 | 613 |
551 } // namespace internals | 614 } // namespace internals |
552 | 615 |
553 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 616 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
554 // UpdateShortcutWorker will delete itself when it's done. | 617 // UpdateShortcutWorker will delete itself when it's done. |
555 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 618 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
556 worker->Run(); | 619 worker->Run(); |
557 } | 620 } |
558 | 621 |
559 } // namespace web_app | 622 } // namespace web_app |
OLD | NEW |