summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/resource_bundle.h6
-rw-r--r--chrome/common/resource_bundle_linux.cc26
2 files changed, 31 insertions, 1 deletions
diff --git a/chrome/common/resource_bundle.h b/chrome/common/resource_bundle.h
index 4b6e0fc..983f34b 100644
--- a/chrome/common/resource_bundle.h
+++ b/chrome/common/resource_bundle.h
@@ -23,6 +23,7 @@
namespace base {
class DataPack;
};
+typedef struct _GdkPixbuf GdkPixbuf;
#endif
class ChromeFont;
class SkBitmap;
@@ -108,7 +109,10 @@ class ResourceBundle {
// Loads and returns a cursor from the app module.
HCURSOR LoadCursor(int cursor_id);
-#endif // OS_WIN
+#elif defined(OS_LINUX)
+ // Load a theme image as a GdkPixbuf.
+ GdkPixbuf* LoadPixbuf(int resource_id);
+#endif
private:
// We define a DataHandle typedef to abstract across how data is stored
diff --git a/chrome/common/resource_bundle_linux.cc b/chrome/common/resource_bundle_linux.cc
index 12b0858..08bbeee 100644
--- a/chrome/common/resource_bundle_linux.cc
+++ b/chrome/common/resource_bundle_linux.cc
@@ -4,6 +4,8 @@
#include "chrome/common/resource_bundle.h"
+#include <gtk/gtk.h>
+
#include "base/base_paths.h"
#include "base/data_pack.h"
#include "base/file_path.h"
@@ -114,3 +116,27 @@ std::wstring ResourceBundle::GetLocalizedString(int message_id) {
data.length() / 2);
return UTF16ToWide(msg);
}
+
+GdkPixbuf* ResourceBundle::LoadPixbuf(int resource_id) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ std::vector<unsigned char> data;
+ rb.LoadImageResourceBytes(resource_id, &data);
+
+ GdkPixbufLoader* loader = gdk_pixbuf_loader_new();
+ bool ok = gdk_pixbuf_loader_write(loader, static_cast<guint8*>(data.data()),
+ data.size(), NULL);
+ DCHECK(ok) << "failed to write " << resource_id;
+ // Calling gdk_pixbuf_loader_close forces the data to be parsed by the
+ // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf.
+ ok = gdk_pixbuf_loader_close(loader, NULL);
+ DCHECK(ok) << "close failed " << resource_id;
+ GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ DCHECK(pixbuf) << "failed to load " << resource_id << " " << data.size();
+
+ // The pixbuf is owned by the loader, so add a ref so when we delete the
+ // loader, the pixbuf still exists.
+ g_object_ref(pixbuf);
+ g_object_unref(loader);
+
+ return pixbuf;
+}