Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/web_applications/web_app_win.cc

Issue 12881003: ShortcutInfo::favicon is now a gfx::ImageFamily instead of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added test suite for icon_family. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_family.h"
22 #include "ui/gfx/icon_util.h" 23 #include "ui/gfx/icon_util.h"
24 #include "ui/gfx/image/image_skia.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
29 // Calculates image checksum using MD5. 31 // Calculates image checksum using MD5.
30 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) { 32 void GetImageCheckSum(const SkBitmap& image, base::MD5Digest* digest) {
31 DCHECK(digest); 33 DCHECK(digest);
32 34
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 168
167 } // namespace 169 } // namespace
168 170
169 namespace web_app { 171 namespace web_app {
170 172
171 namespace internals { 173 namespace internals {
172 174
173 // Saves |image| to |icon_file| if the file is outdated and refresh shell's 175 // 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 176 // icon cache to ensure correct icon is displayed. Returns true if icon_file
175 // is up to date or successfully updated. 177 // is up to date or successfully updated.
176 bool CheckAndSaveIcon(const base::FilePath& icon_file, const SkBitmap& image) { 178 bool CheckAndSaveIcon(const base::FilePath& icon_file,
177 if (ShouldUpdateIcon(icon_file, image)) { 179 const gfx::IconFamily& image) {
178 if (SaveIconWithCheckSum(icon_file, image)) { 180 // TODO(mgiuca): Save an icon with all icon sizes, not just a hard-coded
181 // 32x32 icon. http://crbug.com/180766.
182 const gfx::ImageSkia* icon_32 = image.Get(32, 32);
183 SkBitmap bitmap = icon_32 ? *icon_32->bitmap() : SkBitmap();
184 if (ShouldUpdateIcon(icon_file, bitmap)) {
185 if (SaveIconWithCheckSum(icon_file, bitmap)) {
179 // Refresh shell's icon cache. This call is quite disruptive as user would 186 // 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 187 // see explorer rebuilding the icon cache. It would be great that we find
181 // a better way to achieve this. 188 // a better way to achieve this.
182 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, 189 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT,
183 NULL, NULL); 190 NULL, NULL);
184 } else { 191 } else {
185 return false; 192 return false;
186 } 193 }
187 } 194 }
188 195
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return false; 237 return false;
231 } 238 }
232 239
233 // Generates file name to use with persisted ico and shortcut file. 240 // Generates file name to use with persisted ico and shortcut file.
234 base::FilePath file_name = 241 base::FilePath file_name =
235 web_app::internals::GetSanitizedFileName(shortcut_info.title); 242 web_app::internals::GetSanitizedFileName(shortcut_info.title);
236 243
237 // Creates an ico file to use with shortcut. 244 // Creates an ico file to use with shortcut.
238 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( 245 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension(
239 FILE_PATH_LITERAL(".ico")); 246 FILE_PATH_LITERAL(".ico"));
240 if (!web_app::internals::CheckAndSaveIcon(icon_file, 247 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) {
241 *shortcut_info.favicon.ToSkBitmap())) {
242 return false; 248 return false;
243 } 249 }
244 250
245 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info); 251 base::FilePath target_exe = GetShortcutExecutablePath(shortcut_info);
246 DCHECK(!target_exe.empty()); 252 DCHECK(!target_exe.empty());
247 253
248 // Working directory. 254 // Working directory.
249 base::FilePath working_dir(target_exe.DirName()); 255 base::FilePath working_dir(target_exe.DirName());
250 256
251 CommandLine cmd_line(CommandLine::NO_PROGRAM); 257 CommandLine cmd_line(CommandLine::NO_PROGRAM);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 const ShellIntegration::ShortcutInfo& shortcut_info) { 324 const ShellIntegration::ShortcutInfo& shortcut_info) {
319 // Generates file name to use with persisted ico and shortcut file. 325 // Generates file name to use with persisted ico and shortcut file.
320 base::FilePath file_name = 326 base::FilePath file_name =
321 web_app::internals::GetSanitizedFileName(shortcut_info.title); 327 web_app::internals::GetSanitizedFileName(shortcut_info.title);
322 328
323 // 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
324 // and let the shell know the icon has been modified. 330 // and let the shell know the icon has been modified.
325 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension( 331 base::FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension(
326 FILE_PATH_LITERAL(".ico")); 332 FILE_PATH_LITERAL(".ico"));
327 if (file_util::PathExists(icon_file)) { 333 if (file_util::PathExists(icon_file)) {
328 web_app::internals::CheckAndSaveIcon(icon_file, 334 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
329 *shortcut_info.favicon.ToSkBitmap());
330 } 335 }
331 } 336 }
332 337
333 void DeletePlatformShortcuts( 338 void DeletePlatformShortcuts(
334 const base::FilePath& web_app_path, 339 const base::FilePath& web_app_path,
335 const ShellIntegration::ShortcutInfo& shortcut_info) { 340 const ShellIntegration::ShortcutInfo& shortcut_info) {
336 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 341 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
337 342
338 // Get all possible locations for shortcuts. 343 // Get all possible locations for shortcuts.
339 ShellIntegration::ShortcutLocations all_shortcut_locations; 344 ShellIntegration::ShortcutLocations all_shortcut_locations;
(...skipping 16 matching lines...) Expand all
356 // they are all unpinned. 361 // they are all unpinned.
357 base::win::TaskbarUnpinShortcutLink(j->value().c_str()); 362 base::win::TaskbarUnpinShortcutLink(j->value().c_str());
358 file_util::Delete(*j, false); 363 file_util::Delete(*j, false);
359 } 364 }
360 } 365 }
361 } 366 }
362 367
363 } // namespace internals 368 } // namespace internals
364 369
365 } // namespace web_app 370 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698