diff options
-rw-r--r-- | base/mime_util.h | 7 | ||||
-rw-r--r-- | base/mime_util_linux.cc | 32 | ||||
-rw-r--r-- | chrome/browser/icon_loader.cc | 6 |
3 files changed, 39 insertions, 6 deletions
diff --git a/base/mime_util.h b/base/mime_util.h index 4b67e46..7e1593b 100644 --- a/base/mime_util.h +++ b/base/mime_util.h @@ -20,6 +20,13 @@ std::string GetFileMimeType(const FilePath& filepath); // Get the mime type for a byte vector. std::string GetDataMimeType(const std::string& data); +#if defined(OS_LINUX) +// This detects the current GTK theme by calling gtk_settings_get_default(). +// It should only be executed on the UI thread and must be called before +// GetMimeIcon(). +void DetectGtkTheme(); +#endif + // Gets the file name for an icon given the mime type and icon pixel size. // Where an icon is a square image of |size| x |size|. // This will try to find the closest matching icon. If that's not available, diff --git a/base/mime_util_linux.cc b/base/mime_util_linux.cc index c5fe60c..b42122f 100644 --- a/base/mime_util_linux.cc +++ b/base/mime_util_linux.cc @@ -15,6 +15,7 @@ #include "base/file_util.h" #include "base/logging.h" +#include "base/message_loop.h" #include "base/scoped_ptr.h" #include "base/singleton.h" #include "base/string_util.h" @@ -46,6 +47,11 @@ class MimeUtilConstants { time_t last_check_time_; + // This is set by DetectGtkTheme(). We cache it so that we can access the + // theme name from threads that aren't allowed to call + // gtk_settings_get_default(). + std::string gtk_theme_name_; + private: MimeUtilConstants() : kUpdateInterval(5), @@ -489,13 +495,9 @@ void InitDefaultThemes() { default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); } else { // Assume it's Gnome and use GTK to figure out the theme. - gchar* gtk_theme_name; - g_object_get(gtk_settings_get_default(), - "gtk-icon-theme-name", - >k_theme_name, NULL); - default_themes[1] = IconTheme::LoadTheme(gtk_theme_name); + default_themes[1] = IconTheme::LoadTheme( + Singleton<MimeUtilConstants>::get()->gtk_theme_name_); default_themes[2] = IconTheme::LoadTheme("gnome"); - g_free(gtk_theme_name); } // hicolor needs to be last per icon theme spec. default_themes[3] = IconTheme::LoadTheme("hicolor"); @@ -550,6 +552,24 @@ std::string GetDataMimeType(const std::string& data) { return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); } +void DetectGtkTheme() { + // If the theme name is already loaded, do nothing. Chrome doesn't respond + // to changes in the system theme, so we never need to set this more than + // once. + if (!Singleton<MimeUtilConstants>::get()->gtk_theme_name_.empty()) + return; + + // We should only be called on the UI thread. + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); + + gchar* gtk_theme_name; + g_object_get(gtk_settings_get_default(), + "gtk-icon-theme-name", + >k_theme_name, NULL); + Singleton<MimeUtilConstants>::get()->gtk_theme_name_.assign(gtk_theme_name); + g_free(gtk_theme_name); +} + FilePath GetMimeIcon(const std::string& mime_type, size_t size) { std::vector<std::string> icon_names; std::string icon_name; diff --git a/chrome/browser/icon_loader.cc b/chrome/browser/icon_loader.cc index 1978ca5..a8f496c 100644 --- a/chrome/browser/icon_loader.cc +++ b/chrome/browser/icon_loader.cc @@ -5,6 +5,7 @@ #include "chrome/browser/icon_loader.h" #include "base/message_loop.h" +#include "base/mime_util.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -24,6 +25,11 @@ IconLoader::~IconLoader() { void IconLoader::Start() { target_message_loop_ = MessageLoop::current(); +#if defined(OS_LINUX) + // This call must happen on the UI thread before we can start loading icons. + mime_util::DetectGtkTheme(); +#endif + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &IconLoader::ReadIcon)); } |