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.h" | 5 #include "chrome/browser/web_applications/web_app.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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/md5.h" | 12 #include "base/md5.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/win/shortcut.h" | 16 #include "base/win/shortcut.h" |
17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 19 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
20 #include "chrome/installer/util/browser_distribution.h" | 20 #include "chrome/installer/util/browser_distribution.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "ui/gfx/icon_util.h" | 22 #include "ui/gfx/icon_util.h" |
| 23 #include "ui/gfx/image/image.h" |
| 24 #include "ui/gfx/image/image_family.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 const base::FilePath::CharType kIconChecksumFileExt[] = | 28 const base::FilePath::CharType kIconChecksumFileExt[] = |
27 FILE_PATH_LITERAL(".ico.md5"); | 29 FILE_PATH_LITERAL(".ico.md5"); |
28 | 30 |
| 31 // Width and height of icons exported to .ico files. |
| 32 // TODO(mgiuca): Remove when icon_util has the capability to save all icon |
| 33 // sizes, not just a single particular size. |
| 34 const int kIconExportSize = 32; |
| 35 |
29 // Calculates image checksum using MD5. | 36 // Calculates image checksum using MD5. |
30 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { | 37 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { |
31 DCHECK(digest); | 38 DCHECK(digest); |
32 | 39 |
33 SkAutoLockPixels image_lock(image); | 40 SkAutoLockPixels image_lock(image); |
34 MD5Sum(image.getPixels(), image.getSize(), digest); | 41 MD5Sum(image.getPixels(), image.getSize(), digest); |
35 } | 42 } |
36 | 43 |
37 // Saves |image| as an |icon_file| with the checksum. | 44 // Saves |image| as an |icon_file| with the checksum. |
38 bool SaveIconWithCheckSum(const base::FilePath& icon_file, | 45 bool SaveIconWithCheckSum(const base::FilePath& icon_file, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 173 |
167 } // namespace | 174 } // namespace |
168 | 175 |
169 namespace web_app { | 176 namespace web_app { |
170 | 177 |
171 namespace internals { | 178 namespace internals { |
172 | 179 |
173 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | 180 // Saves |image| to |icon_file| if the file is outdated and refresh shell's |
174 // icon cache to ensure correct icon is displayed. Returns true if icon_file | 181 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
175 // is up to date or successfully updated. | 182 // is up to date or successfully updated. |
176 bool CheckAndSaveIcon(const base::FilePath& icon_file, const SkBitmap& image) { | 183 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
177 if (ShouldUpdateIcon(icon_file, image)) { | 184 const gfx::ImageFamily& image) { |
178 if (SaveIconWithCheckSum(icon_file, image)) { | 185 // TODO(mgiuca): Save an icon with all icon sizes, not just an icon at a |
| 186 // hard-coded fixed size. http://crbug.com/163864. |
| 187 const gfx::Image* icon = image.GetBest(kIconExportSize, kIconExportSize); |
| 188 SkBitmap bitmap = icon ? icon->AsBitmap() : SkBitmap(); |
| 189 if (ShouldUpdateIcon(icon_file, bitmap)) { |
| 190 if (SaveIconWithCheckSum(icon_file, bitmap)) { |
179 // Refresh shell's icon cache. This call is quite disruptive as user would | 191 // Refresh shell's icon cache. This call is quite disruptive as user would |
180 // see explorer rebuilding the icon cache. It would be great that we find | 192 // see explorer rebuilding the icon cache. It would be great that we find |
181 // a better way to achieve this. | 193 // a better way to achieve this. |
182 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, | 194 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, |
183 NULL, NULL); | 195 NULL, NULL); |
184 } else { | 196 } else { |
185 return false; | 197 return false; |
186 } | 198 } |
187 } | 199 } |
188 | 200 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return false; | 241 return false; |
230 } | 242 } |
231 | 243 |
232 // Generates file name to use with persisted ico and shortcut file. | 244 // Generates file name to use with persisted ico and shortcut file. |
233 base::FilePath file_name = | 245 base::FilePath file_name = |
234 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 246 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
235 | 247 |
236 // Creates an ico file to use with shortcut. | 248 // Creates an ico file to use with shortcut. |
237 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( | 249 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( |
238 FILE_PATH_LITERAL(".ico")); | 250 FILE_PATH_LITERAL(".ico")); |
239 if (!web_app::internals::CheckAndSaveIcon(icon_file, | 251 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { |
240 *shortcut_info.favicon.ToSkBitmap())) { | |
241 return false; | 252 return false; |
242 } | 253 } |
243 | 254 |
244 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); | 255 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); |
245 DCHECK(!target_exe.empty()); | 256 DCHECK(!target_exe.empty()); |
246 | 257 |
247 // Working directory. | 258 // Working directory. |
248 base::FilePath working_dir(target_exe.DirName()); | 259 base::FilePath working_dir(target_exe.DirName()); |
249 | 260 |
250 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 261 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 const ShellIntegration::ShortcutInfo& shortcut_info) { | 323 const ShellIntegration::ShortcutInfo& shortcut_info) { |
313 // Generates file name to use with persisted ico and shortcut file. | 324 // Generates file name to use with persisted ico and shortcut file. |
314 base::FilePath file_name = | 325 base::FilePath file_name = |
315 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 326 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
316 | 327 |
317 // If an icon file exists, and is out of date, replace it with the new icon | 328 // If an icon file exists, and is out of date, replace it with the new icon |
318 // and let the shell know the icon has been modified. | 329 // and let the shell know the icon has been modified. |
319 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( | 330 base::FilePath icon_file = web_app_path.Append(file_name).AddExtension( |
320 FILE_PATH_LITERAL(".ico")); | 331 FILE_PATH_LITERAL(".ico")); |
321 if (file_util::PathExists(icon_file)) { | 332 if (file_util::PathExists(icon_file)) { |
322 web_app::internals::CheckAndSaveIcon(icon_file, | 333 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
323 *shortcut_info.favicon.ToSkBitmap()); | |
324 } | 334 } |
325 } | 335 } |
326 | 336 |
327 void DeletePlatformShortcuts( | 337 void DeletePlatformShortcuts( |
328 const base::FilePath& web_app_path, | 338 const base::FilePath& web_app_path, |
329 const ShellIntegration::ShortcutInfo& shortcut_info) { | 339 const ShellIntegration::ShortcutInfo& shortcut_info) { |
330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 340 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
331 | 341 |
332 // Get all possible locations for shortcuts. | 342 // Get all possible locations for shortcuts. |
333 ShellIntegration::ShortcutLocations all_shortcut_locations; | 343 ShellIntegration::ShortcutLocations all_shortcut_locations; |
(...skipping 16 matching lines...) Expand all Loading... |
350 // they are all unpinned. | 360 // they are all unpinned. |
351 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 361 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
352 file_util::Delete(*j, false); | 362 file_util::Delete(*j, false); |
353 } | 363 } |
354 } | 364 } |
355 } | 365 } |
356 | 366 |
357 } // namespace internals | 367 } // namespace internals |
358 | 368 |
359 } // namespace web_app | 369 } // namespace web_app |
OLD | NEW |