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

Unified Diff: chrome/browser/shell_integration_linux.cc

Issue 12218069: CreateShortcutIcon on Linux now creates icons at all available resolutions, not (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Checking return values and correctly initializing vector. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/web_applications/web_app_ui.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/shell_integration_linux.cc
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc
index 932d4cbaa123c62e3e69816eb36ee02734041e17..a42f16e08978b6804f80a29e3e67e81b5f1021d7 100644
--- a/chrome/browser/shell_integration_linux.cc
+++ b/chrome/browser/shell_integration_linux.cc
@@ -36,6 +36,8 @@
#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_skia_rep.h"
using content::BrowserThread;
@@ -83,33 +85,46 @@ std::string CreateShortcutIcon(
base::FilePath temp_file_path = temp_dir.path().Append(
shortcut_filename.ReplaceExtension("png"));
-
- std::vector<unsigned char> png_data;
- const SkBitmap* bitmap = shortcut_info.favicon.ToSkBitmap();
- gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data);
- int bytes_written = file_util::WriteFile(temp_file_path,
- reinterpret_cast<char*>(png_data.data()), png_data.size());
-
- if (bytes_written != static_cast<int>(png_data.size()))
- return std::string();
-
- std::vector<std::string> argv;
- argv.push_back("xdg-icon-resource");
- argv.push_back("install");
-
- // Always install in user mode, even if someone runs the browser as root
- // (people do that).
- argv.push_back("--mode");
- argv.push_back("user");
-
- argv.push_back("--size");
- argv.push_back(base::IntToString(bitmap->width()));
-
- argv.push_back(temp_file_path.value());
std::string icon_name = temp_file_path.BaseName().RemoveExtension().value();
- argv.push_back(icon_name);
- int exit_code;
- LaunchXdgUtility(argv, &exit_code);
+
+ std::vector<gfx::ImageSkiaRep> image_reps =
+ shortcut_info.favicon.ToImageSkia()->image_reps();
+ for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
+ it != image_reps.end(); ++it) {
+ std::vector<unsigned char> png_data;
+ const SkBitmap& bitmap = it->sk_bitmap();
+ if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data)) {
+ // If the bitmap could not be encoded to PNG format, skip it.
+ LOG(WARNING) << "Could not encode icon " << icon_name << ".png at size "
+ << bitmap.width() << ".";
+ continue;
+ }
+ int bytes_written = file_util::WriteFile(temp_file_path,
+ reinterpret_cast<char*>(png_data.data()), png_data.size());
+
+ if (bytes_written != static_cast<int>(png_data.size()))
+ return std::string();
+
+ std::vector<std::string> argv;
+ argv.push_back("xdg-icon-resource");
+ argv.push_back("install");
+
+ // Always install in user mode, even if someone runs the browser as root
+ // (people do that).
+ argv.push_back("--mode");
+ argv.push_back("user");
+
+ argv.push_back("--size");
+ argv.push_back(base::IntToString(bitmap.width()));
+
+ argv.push_back(temp_file_path.value());
+ argv.push_back(icon_name);
+ int exit_code;
+ if (!LaunchXdgUtility(argv, &exit_code) || exit_code) {
+ LOG(WARNING) << "Could not install icon " << icon_name << ".png at size "
+ << bitmap.width() << ".";
+ }
+ }
return icon_name;
}
« no previous file with comments | « no previous file | chrome/browser/ui/web_applications/web_app_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698