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

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

Powered by Google App Engine
This is Rietveld 408576698