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.Get(kIconExportSize, kIconExportSize); | |
188 SkBitmap bitmap = (icon && !icon->IsEmpty()) ? *icon->ToSkBitmap() : | |
189 SkBitmap(); | |
Robert Sesek
2013/04/04 18:39:02
AsSkBitmap()
Matt Giuca
2013/04/05 06:30:13
Done.
| |
190 if (ShouldUpdateIcon(icon_file, bitmap)) { | |
191 if (SaveIconWithCheckSum(icon_file, bitmap)) { | |
179 // Refresh shell's icon cache. This call is quite disruptive as user would | 192 // 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 | 193 // see explorer rebuilding the icon cache. It would be great that we find |
181 // a better way to achieve this. | 194 // a better way to achieve this. |
182 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, | 195 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, |
183 NULL, NULL); | 196 NULL, NULL); |
184 } else { | 197 } else { |
185 return false; | 198 return false; |
186 } | 199 } |
187 } | 200 } |
188 | 201 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 return false; | 242 return false; |
230 } | 243 } |
231 | 244 |
232 // Generates file name to use with persisted ico and shortcut file. | 245 // Generates file name to use with persisted ico and shortcut file. |
233 base::FilePath file_name = | 246 base::FilePath file_name = |
234 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 247 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
235 | 248 |
236 // Creates an ico file to use with shortcut. | 249 // Creates an ico file to use with shortcut. |
237 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( | 250 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( |
238 FILE_PATH_LITERAL(".ico")); | 251 FILE_PATH_LITERAL(".ico")); |
239 if (!web_app::internals::CheckAndSaveIcon(icon_file, | 252 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { |
240 *shortcut_info.favicon.ToSkBitmap())) { | |
241 return false; | 253 return false; |
242 } | 254 } |
243 | 255 |
244 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); | 256 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); |
245 DCHECK(!target_exe.empty()); | 257 DCHECK(!target_exe.empty()); |
246 | 258 |
247 // Working directory. | 259 // Working directory. |
248 base::FilePath working_dir(target_exe.DirName()); | 260 base::FilePath working_dir(target_exe.DirName()); |
249 | 261 |
250 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 262 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) { | 324 const ShellIntegration::ShortcutInfo& shortcut_info) { |
313 // Generates file name to use with persisted ico and shortcut file. | 325 // Generates file name to use with persisted ico and shortcut file. |
314 base::FilePath file_name = | 326 base::FilePath file_name = |
315 web_app::internals::GetSanitizedFileName(shortcut_info.title); | 327 web_app::internals::GetSanitizedFileName(shortcut_info.title); |
316 | 328 |
317 // If an icon file exists, and is out of date, replace it with the new icon | 329 // 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. | 330 // and let the shell know the icon has been modified. |
319 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( | 331 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( |
320 FILE_PATH_LITERAL(".ico")); | 332 FILE_PATH_LITERAL(".ico")); |
321 if (file_util::PathExists(icon_file)) { | 333 if (file_util::PathExists(icon_file)) { |
322 web_app::internals::CheckAndSaveIcon(icon_file, | 334 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
323 *shortcut_info.favicon.ToSkBitmap()); | |
324 } | 335 } |
325 } | 336 } |
326 | 337 |
327 void DeletePlatformShortcuts( | 338 void DeletePlatformShortcuts( |
328 const base::FilePath& web_app_path, | 339 const base::FilePath& web_app_path, |
329 const ShellIntegration::ShortcutInfo& shortcut_info) { | 340 const ShellIntegration::ShortcutInfo& shortcut_info) { |
330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 341 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
331 | 342 |
332 // Get all possible locations for shortcuts. | 343 // Get all possible locations for shortcuts. |
333 ShellIntegration::ShortcutLocations all_shortcut_locations; | 344 ShellIntegration::ShortcutLocations all_shortcut_locations; |
(...skipping 16 matching lines...) Expand all Loading... | |
350 // they are all unpinned. | 361 // they are all unpinned. |
351 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); | 362 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); |
352 file_util::Delete(*j, false); | 363 file_util::Delete(*j, false); |
353 } | 364 } |
354 } | 365 } |
355 } | 366 } |
356 | 367 |
357 } // namespace internals | 368 } // namespace internals |
358 | 369 |
359 } // namespace web_app | 370 } // namespace web_app |
OLD | NEW |