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" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "ui/gfx/icon_util.h" | 26 #include "ui/gfx/icon_util.h" |
27 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
28 #include "ui/gfx/image/image_family.h" | 28 #include "ui/gfx/image/image_family.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const base::FilePath::CharType kIconChecksumFileExt[] = | 32 const base::FilePath::CharType kIconChecksumFileExt[] = |
33 FILE_PATH_LITERAL(".ico.md5"); | 33 FILE_PATH_LITERAL(".ico.md5"); |
34 | 34 |
35 // Width and height of icons exported to .ico files. | |
36 | |
37 // Calculates checksum of an icon family using MD5. | 35 // Calculates checksum of an icon family using MD5. |
38 // The checksum is derived from all of the icons in the family. | 36 // The checksum is derived from all of the icons in the family. |
39 void GetImageCheckSum(const gfx::ImageFamily& image, base::MD5Digest* digest) { | 37 void GetImageCheckSum(const gfx::ImageFamily& image, base::MD5Digest* digest) { |
40 DCHECK(digest); | 38 DCHECK(digest); |
41 base::MD5Context md5_context; | 39 base::MD5Context md5_context; |
42 base::MD5Init(&md5_context); | 40 base::MD5Init(&md5_context); |
43 | 41 |
44 for (gfx::ImageFamily::const_iterator it = image.begin(); it != image.end(); | 42 for (gfx::ImageFamily::const_iterator it = image.begin(); it != image.end(); |
45 ++it) { | 43 ++it) { |
46 SkBitmap bitmap = it->AsBitmap(); | 44 SkBitmap bitmap = it->AsBitmap(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 const std::vector<base::FilePath>& shortcut_paths, | 164 const std::vector<base::FilePath>& shortcut_paths, |
167 web_app::ShortcutCreationReason creation_reason, | 165 web_app::ShortcutCreationReason creation_reason, |
168 std::vector<base::FilePath>* out_filenames) { | 166 std::vector<base::FilePath>* out_filenames) { |
169 // Ensure web_app_path exists. | 167 // Ensure web_app_path exists. |
170 if (!base::PathExists(web_app_path) && | 168 if (!base::PathExists(web_app_path) && |
171 !base::CreateDirectory(web_app_path)) { | 169 !base::CreateDirectory(web_app_path)) { |
172 return false; | 170 return false; |
173 } | 171 } |
174 | 172 |
175 // Generates file name to use with persisted ico and shortcut file. | 173 // Generates file name to use with persisted ico and shortcut file. |
176 base::FilePath file_name = | 174 base::FilePath icon_file = |
177 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 175 web_app::internals::GetIconFilePath(web_app_path, shortcut_info.title); |
178 | |
179 // Creates an ico file to use with shortcut. | |
180 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( | |
181 FILE_PATH_LITERAL(".ico")); | |
182 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { | 176 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { |
183 return false; | 177 return false; |
184 } | 178 } |
185 | 179 |
186 base::FilePath chrome_exe; | 180 base::FilePath chrome_exe; |
187 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 181 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
188 NOTREACHED(); | 182 NOTREACHED(); |
189 return false; | 183 return false; |
190 } | 184 } |
191 | 185 |
(...skipping 15 matching lines...) Expand all Loading... | |
207 if (description.length() >= MAX_PATH) | 201 if (description.length() >= MAX_PATH) |
208 description.resize(MAX_PATH - 1); | 202 description.resize(MAX_PATH - 1); |
209 | 203 |
210 // Generates app id from web app url and profile path. | 204 // Generates app id from web app url and profile path. |
211 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); | 205 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); |
212 base::string16 app_id(ShellIntegration::GetAppModelIdForProfile( | 206 base::string16 app_id(ShellIntegration::GetAppModelIdForProfile( |
213 base::UTF8ToUTF16(app_name), shortcut_info.profile_path)); | 207 base::UTF8ToUTF16(app_name), shortcut_info.profile_path)); |
214 | 208 |
215 bool success = true; | 209 bool success = true; |
216 for (size_t i = 0; i < shortcut_paths.size(); ++i) { | 210 for (size_t i = 0; i < shortcut_paths.size(); ++i) { |
217 base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). | 211 base::FilePath shortcut_file = |
218 AddExtension(installer::kLnkExt); | 212 shortcut_paths[i] |
213 .Append( | |
214 web_app::internals::GetSanitizedFileName(shortcut_info.title)) | |
215 .AddExtension(installer::kLnkExt); | |
219 if (creation_reason == web_app::SHORTCUT_CREATION_AUTOMATED) { | 216 if (creation_reason == web_app::SHORTCUT_CREATION_AUTOMATED) { |
220 // Check whether there is an existing shortcut to this app. | 217 // Check whether there is an existing shortcut to this app. |
221 std::vector<base::FilePath> shortcut_files = | 218 std::vector<base::FilePath> shortcut_files = |
222 FindAppShortcutsByProfileAndTitle(shortcut_paths[i], | 219 FindAppShortcutsByProfileAndTitle(shortcut_paths[i], |
223 shortcut_info.profile_path, | 220 shortcut_info.profile_path, |
224 shortcut_info.title); | 221 shortcut_info.title); |
225 if (!shortcut_files.empty()) | 222 if (!shortcut_files.empty()) |
226 continue; | 223 continue; |
227 } | 224 } |
228 if (shortcut_paths[i] != web_app_path) { | 225 if (shortcut_paths[i] != web_app_path) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 } // namespace | 325 } // namespace |
329 | 326 |
330 namespace web_app { | 327 namespace web_app { |
331 | 328 |
332 base::FilePath CreateShortcutInWebAppDir( | 329 base::FilePath CreateShortcutInWebAppDir( |
333 const base::FilePath& web_app_dir, | 330 const base::FilePath& web_app_dir, |
334 const ShellIntegration::ShortcutInfo& shortcut_info) { | 331 const ShellIntegration::ShortcutInfo& shortcut_info) { |
335 std::vector<base::FilePath> paths; | 332 std::vector<base::FilePath> paths; |
336 paths.push_back(web_app_dir); | 333 paths.push_back(web_app_dir); |
337 std::vector<base::FilePath> out_filenames; | 334 std::vector<base::FilePath> out_filenames; |
338 CreateShortcutsInPaths(web_app_dir, shortcut_info, paths, | 335 base::FilePath web_app_dir_shortcut = |
339 SHORTCUT_CREATION_BY_USER, &out_filenames); | 336 web_app_dir.Append(web_app::internals::GetSanitizedFileName( |
340 DCHECK_EQ(out_filenames.size(), 1u); | 337 shortcut_info.title)) |
341 return out_filenames[0]; | 338 .AddExtension(installer::kLnkExt); |
339 if (!PathExists(web_app_dir_shortcut)) { | |
340 CreateShortcutsInPaths(web_app_dir, | |
341 shortcut_info, | |
342 paths, | |
343 SHORTCUT_CREATION_BY_USER, | |
344 &out_filenames); | |
345 DCHECK_EQ(out_filenames.size(), 1u); | |
346 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); | |
347 } else { | |
348 web_app::internals::CheckAndSaveIcon( | |
benwells
2014/03/27 01:53:22
Nit: you don't need web_app:: here.
| |
349 web_app::internals::GetIconFilePath(web_app_dir, shortcut_info.title), | |
350 shortcut_info.favicon); | |
351 } | |
352 return web_app_dir_shortcut; | |
342 } | 353 } |
343 | 354 |
344 namespace internals { | 355 namespace internals { |
345 | 356 |
346 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | 357 // Saves |image| to |icon_file| if the file is outdated and refresh shell's |
347 // icon cache to ensure correct icon is displayed. Returns true if icon_file | 358 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
348 // is up to date or successfully updated. | 359 // is up to date or successfully updated. |
349 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 360 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
350 const gfx::ImageFamily& image) { | 361 const gfx::ImageFamily& image) { |
351 if (ShouldUpdateIcon(icon_file, image)) { | 362 if (ShouldUpdateIcon(icon_file, image)) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 // Use the web app path shortcut for pinning to avoid having unique | 446 // Use the web app path shortcut for pinning to avoid having unique |
436 // numbers in the application name. | 447 // numbers in the application name. |
437 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 448 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
438 AddExtension(installer::kLnkExt); | 449 AddExtension(installer::kLnkExt); |
439 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); | 450 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); |
440 } | 451 } |
441 } | 452 } |
442 | 453 |
443 // If an icon file exists, and is out of date, replace it with the new icon | 454 // If an icon file exists, and is out of date, replace it with the new icon |
444 // and let the shell know the icon has been modified. | 455 // and let the shell know the icon has been modified. |
445 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( | 456 base::FilePath icon_file = |
446 FILE_PATH_LITERAL(".ico")); | 457 web_app::internals::GetIconFilePath(web_app_path, shortcut_info.title); |
benwells
2014/03/27 01:53:22
Nit: you don't need the namespace here as you're i
| |
447 if (base::PathExists(icon_file)) { | 458 if (base::PathExists(icon_file)) { |
448 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 459 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
449 } | 460 } |
450 } | 461 } |
451 | 462 |
452 void DeletePlatformShortcuts( | 463 void DeletePlatformShortcuts( |
453 const base::FilePath& web_app_path, | 464 const base::FilePath& web_app_path, |
454 const ShellIntegration::ShortcutInfo& shortcut_info) { | 465 const ShellIntegration::ShortcutInfo& shortcut_info) { |
455 GetShortcutLocationsAndDeleteShortcuts( | 466 GetShortcutLocationsAndDeleteShortcuts( |
456 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, | 467 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 &path)) { | 539 &path)) { |
529 NOTREACHED(); | 540 NOTREACHED(); |
530 continue; | 541 continue; |
531 } | 542 } |
532 shortcut_paths.push_back(path); | 543 shortcut_paths.push_back(path); |
533 } | 544 } |
534 } | 545 } |
535 return shortcut_paths; | 546 return shortcut_paths; |
536 } | 547 } |
537 | 548 |
549 base::FilePath GetIconFilePath(const base::FilePath& web_app_path, | |
550 const base::string16& title) { | |
551 return web_app_path.Append(web_app::internals::GetSanitizedFileName(title)) | |
552 .AddExtension(FILE_PATH_LITERAL(".ico")); | |
553 } | |
554 | |
538 } // namespace internals | 555 } // namespace internals |
539 | 556 |
540 } // namespace web_app | 557 } // namespace web_app |
OLD | NEW |