summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/libgtk2ui
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-13 02:13:34 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-13 02:13:34 +0000
commit6fafc2c7294d80e2f74cb37908cdaaa3580cb3d5 (patch)
tree154cf253585e46843bc5e68ee9cb5efc0317ba77 /chrome/browser/ui/libgtk2ui
parent25b75114dbb1ae08b331996b224907c8b454330e (diff)
downloadchromium_src-6fafc2c7294d80e2f74cb37908cdaaa3580cb3d5.zip
chromium_src-6fafc2c7294d80e2f74cb37908cdaaa3580cb3d5.tar.gz
chromium_src-6fafc2c7294d80e2f74cb37908cdaaa3580cb3d5.tar.bz2
Get download icons from GTK in linux_aura.
Add a GetIconForContentType hook in LinuxUI and implement in libgtk2ui using the native library interfaces. This saves us from having to implement icon theme lookup ourselves. BUG=102211 TEST=downloading a file in linux_aura on stock Ubuntu shows icons. Review URL: https://codereview.chromium.org/70533002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234709 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/libgtk2ui')
-rw-r--r--chrome/browser/ui/libgtk2ui/gtk2_ui.cc39
-rw-r--r--chrome/browser/ui/libgtk2ui/gtk2_ui.h2
2 files changed, 41 insertions, 0 deletions
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
index d28f115..2555bad 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -54,6 +54,20 @@
namespace {
+struct GObjectDeleter {
+ void operator()(void* ptr) {
+ g_object_unref(ptr);
+ }
+};
+struct GtkIconInfoDeleter {
+ void operator()(GtkIconInfo* ptr) {
+ gtk_icon_info_free(ptr);
+ }
+};
+typedef scoped_ptr<GIcon, GObjectDeleter> ScopedGIcon;
+typedef scoped_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo;
+typedef scoped_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf;
+
// Prefix for app indicator ids
const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_";
@@ -467,6 +481,31 @@ scoped_ptr<views::StatusIconLinux> Gtk2UI::CreateLinuxStatusIcon(
}
}
+gfx::Image Gtk2UI::GetIconForContentType(
+ const std::string& content_type,
+ int size) const {
+ // This call doesn't take a reference.
+ GtkIconTheme* theme = gtk_icon_theme_get_default();
+
+ ScopedGIcon icon(g_content_type_get_icon(content_type.c_str()));
+ ScopedGtkIconInfo icon_info(
+ gtk_icon_theme_lookup_by_gicon(
+ theme, icon.get(), size,
+ static_cast<GtkIconLookupFlags>(GTK_ICON_LOOKUP_FORCE_SIZE)));
+ if (!icon_info)
+ return gfx::Image();
+ ScopedGdkPixbuf pixbuf(gtk_icon_info_load_icon(icon_info.get(), NULL));
+ if (!pixbuf)
+ return gfx::Image();
+
+ SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get());
+ DCHECK_EQ(size, bitmap.width());
+ DCHECK_EQ(size, bitmap.height());
+ gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+ image_skia.MakeThreadSafe();
+ return gfx::Image(image_skia);
+}
+
void Gtk2UI::AddWindowButtonOrderObserver(
views::WindowButtonOrderObserver* observer) {
if (!leading_buttons_.empty() || !trailing_buttons_.empty()) {
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.h b/chrome/browser/ui/libgtk2ui/gtk2_ui.h
index cb7e08c..0d300ee 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.h
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.h
@@ -73,6 +73,8 @@ class Gtk2UI : public views::LinuxUI {
virtual scoped_ptr<views::StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image,
const string16& tool_tip) const OVERRIDE;
+ virtual gfx::Image GetIconForContentType(
+ const std::string& content_type, int size) const OVERRIDE;
virtual void AddWindowButtonOrderObserver(
views::WindowButtonOrderObserver* observer) OVERRIDE;
virtual void RemoveWindowButtonOrderObserver(