summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-10 23:01:19 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-10 23:01:19 +0000
commit3ce52b7367e007940d7ab34ae8eae1df236c59df (patch)
tree47f5613516962fab4f194fe71301f893bfc0b30f
parentf5f2b838a077645b6ff97a995c98906e314304d5 (diff)
downloadchromium_src-3ce52b7367e007940d7ab34ae8eae1df236c59df.zip
chromium_src-3ce52b7367e007940d7ab34ae8eae1df236c59df.tar.gz
chromium_src-3ce52b7367e007940d7ab34ae8eae1df236c59df.tar.bz2
aura: Make the Linux version of IconLoader not require GTK+.
This change makes it use webkit_glue::ImageDecoder instead of gdk-pixbuf and hides various GTK+ theme-related code behind TOOLKIT_USES_GTK ifdefs. Chrome OS is currently loading its own icons from resources (see r86936 and http://crosbug.com/129) instead of using IconLoader and IconManager, so this only removes NOTIMPLEMENTED()s on non-Chrome-OS Linux Aura builds (along with simplifying the GTK+ version of the code). BUG=99494 TEST=manual: download icons are still visible on a gtk+ build Review URL: http://codereview.chromium.org/8501030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109527 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mime_util.h2
-rw-r--r--base/mime_util_xdg.cc11
-rw-r--r--build/common.gypi7
-rw-r--r--chrome/browser/icon_loader.cc4
-rw-r--r--chrome/browser/icon_loader.h9
-rw-r--r--chrome/browser/icon_loader_aura.cc11
-rw-r--r--chrome/browser/icon_loader_gtk.cc71
-rw-r--r--chrome/browser/icon_loader_linux.cc53
-rw-r--r--chrome/browser/icon_manager_linux.cc5
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--net/base/platform_mime_util_linux.cc6
11 files changed, 73 insertions, 109 deletions
diff --git a/base/mime_util.h b/base/mime_util.h
index fd862ed..7af0472 100644
--- a/base/mime_util.h
+++ b/base/mime_util.h
@@ -24,7 +24,7 @@ BASE_EXPORT std::string GetFileMimeType(const FilePath& filepath);
// Get the mime type for a byte vector.
BASE_EXPORT std::string GetDataMimeType(const std::string& data);
-#if defined(TOOLKIT_GTK)
+#if defined(TOOLKIT_USES_GTK)
// 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().
diff --git a/base/mime_util_xdg.cc b/base/mime_util_xdg.cc
index fcd8d97..efe64b3 100644
--- a/base/mime_util_xdg.cc
+++ b/base/mime_util_xdg.cc
@@ -4,7 +4,6 @@
#include "base/mime_util.h"
-#include <gtk/gtk.h>
#include <sys/time.h>
#include <time.h>
@@ -27,6 +26,10 @@
#include "base/third_party/xdg_mime/xdgmime.h"
#include "base/threading/thread_restrictions.h"
+#if defined(TOOLKIT_USES_GTK)
+#include <gtk/gtk.h>
+#endif
+
namespace {
// None of the XDG stuff is thread-safe, so serialize all access under
@@ -66,10 +69,12 @@ class MimeUtilConstants {
time_t last_check_time_;
+#if defined(TOOLKIT_USES_GTK)
// 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_;
+#endif
private:
MimeUtilConstants()
@@ -507,10 +512,12 @@ void InitDefaultThemes() {
default_themes[1] = IconTheme::LoadTheme(kde_default_theme);
default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme);
} else {
+#if defined(TOOLKIT_USES_GTK)
// Assume it's Gnome and use GTK to figure out the theme.
default_themes[1] = IconTheme::LoadTheme(
MimeUtilConstants::GetInstance()->gtk_theme_name_);
default_themes[2] = IconTheme::LoadTheme("gnome");
+#endif
}
// hicolor needs to be last per icon theme spec.
default_themes[3] = IconTheme::LoadTheme("hicolor");
@@ -567,6 +574,7 @@ std::string GetDataMimeType(const std::string& data) {
return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL);
}
+#if defined(TOOLKIT_USES_GTK)
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
@@ -584,6 +592,7 @@ void DetectGtkTheme() {
MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name);
g_free(gtk_theme_name);
}
+#endif
FilePath GetMimeIcon(const std::string& mime_type, size_t size) {
base::ThreadRestrictions::AssertIOAllowed();
diff --git a/build/common.gypi b/build/common.gypi
index 6f2d9d7..4c9487b 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -1278,11 +1278,16 @@
}],
['toolkit_uses_gtk!=1', {
'sources/': [
- ['exclude', '_(gtk|xdg)(_unittest)?\\.(h|cc)$'],
+ ['exclude', '_gtk(_unittest)?\\.(h|cc)$'],
['exclude', '(^|/)gtk/'],
['exclude', '(^|/)gtk_[^/]*\\.(h|cc)$'],
],
}],
+ ['OS!="linux"', {
+ 'sources/': [
+ ['exclude', '_xdg(_unittest)?\\.(h|cc)$'],
+ ],
+ }],
['use_wayland!=1', {
'sources/': [
['exclude', '_(wayland)(_unittest)?\\.(h|cc)$'],
diff --git a/chrome/browser/icon_loader.cc b/chrome/browser/icon_loader.cc
index 9670551..20904b5 100644
--- a/chrome/browser/icon_loader.cc
+++ b/chrome/browser/icon_loader.cc
@@ -8,7 +8,7 @@
#include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
-#if defined(TOOLKIT_GTK)
+#if defined(TOOLKIT_USES_GTK)
#include "base/mime_util.h"
#endif
@@ -29,7 +29,7 @@ IconLoader::~IconLoader() {
void IconLoader::Start() {
target_message_loop_ = base::MessageLoopProxy::current();
-#if defined(TOOLKIT_GTK)
+#if defined(TOOLKIT_USES_GTK)
// This call must happen on the UI thread before we can start loading icons.
mime_util::DetectGtkTheme();
#endif
diff --git a/chrome/browser/icon_loader.h b/chrome/browser/icon_loader.h
index 139c243..5053858 100644
--- a/chrome/browser/icon_loader.h
+++ b/chrome/browser/icon_loader.h
@@ -80,15 +80,6 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
Delegate* delegate_;
-#if defined(TOOLKIT_USES_GTK)
- // On X11 we use gdk's pixbuf loader, which has to execute on the UI
- // thread, so we only read the file on the background thread and parse it
- // on the main thread.
- void ParseIcon();
- FilePath filename_;
- std::string icon_data_;
-#endif
-
DISALLOW_COPY_AND_ASSIGN(IconLoader);
};
diff --git a/chrome/browser/icon_loader_aura.cc b/chrome/browser/icon_loader_aura.cc
deleted file mode 100644
index 1ac3619..0000000
--- a/chrome/browser/icon_loader_aura.cc
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/icon_loader.h"
-
-void IconLoader::ReadIcon() {
- // TODO(saintlou): stubs for now.
- NOTIMPLEMENTED();
-}
-
diff --git a/chrome/browser/icon_loader_gtk.cc b/chrome/browser/icon_loader_gtk.cc
deleted file mode 100644
index c5b0423..0000000
--- a/chrome/browser/icon_loader_gtk.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/icon_loader.h"
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <gio/gio.h>
-#include <gtk/gtk.h>
-
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/mime_util.h"
-#include "base/threading/thread.h"
-#include "base/string_util.h"
-
-static int SizeToInt(IconLoader::IconSize size) {
- int pixels = 0;
- switch (size) {
- case IconLoader::SMALL:
- pixels = 16;
- break;
- case IconLoader::NORMAL:
- pixels = 32;
- break;
- case IconLoader::LARGE:
- pixels = 48;
- break;
- default:
- NOTREACHED();
- }
- return pixels;
-}
-
-void IconLoader::ReadIcon() {
- filename_ = mime_util::GetMimeIcon(group_, SizeToInt(icon_size_));
- file_util::ReadFileToString(filename_, &icon_data_);
- target_message_loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &IconLoader::ParseIcon));
-}
-
-void IconLoader::ParseIcon() {
- int size = SizeToInt(icon_size_);
-
- // It would be more convenient to use gdk_pixbuf_new_from_stream_at_scale
- // but that is only available after 2.14.
- GdkPixbufLoader* loader = gdk_pixbuf_loader_new();
- gdk_pixbuf_loader_set_size(loader, size, size);
- gdk_pixbuf_loader_write(loader,
- reinterpret_cast<const guchar*>(icon_data_.data()),
- icon_data_.length(), NULL);
- gdk_pixbuf_loader_close(loader, NULL);
- // At this point, the pixbuf is owned by the loader.
- GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
-
- if (pixbuf) {
- DCHECK_EQ(size, gdk_pixbuf_get_width(pixbuf));
- DCHECK_EQ(size, gdk_pixbuf_get_height(pixbuf));
- // Takes ownership of |pixbuf|.
- g_object_ref(pixbuf);
- image_.reset(new gfx::Image(pixbuf));
- } else {
- LOG(WARNING) << "Unsupported file type or load error: " <<
- filename_.value();
- }
-
- g_object_unref(loader);
-
- NotifyDelegate();
-}
diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc
new file mode 100644
index 0000000..0bb6879
--- /dev/null
+++ b/chrome/browser/icon_loader_linux.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/icon_loader.h"
+
+#include <string>
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/mime_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "webkit/glue/image_decoder.h"
+
+using std::string;
+
+void IconLoader::ReadIcon() {
+ int size_pixels = 0;
+ switch (icon_size_) {
+ case IconLoader::SMALL:
+ size_pixels = 16;
+ break;
+ case IconLoader::NORMAL:
+ size_pixels = 32;
+ break;
+ case IconLoader::LARGE:
+ size_pixels = 48;
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ FilePath filename = mime_util::GetMimeIcon(group_, size_pixels);
+ string icon_data;
+ file_util::ReadFileToString(filename, &icon_data);
+
+ webkit_glue::ImageDecoder decoder;
+ scoped_ptr<SkBitmap> bitmap(new SkBitmap());
+ *bitmap = decoder.Decode(
+ reinterpret_cast<const unsigned char*>(icon_data.data()),
+ icon_data.length());
+ if (!bitmap->empty()) {
+ DCHECK_EQ(size_pixels, bitmap->width());
+ DCHECK_EQ(size_pixels, bitmap->height());
+ image_.reset(new gfx::Image(bitmap.release()));
+ } else {
+ LOG(WARNING) << "Unsupported file type or load error: " << filename.value();
+ }
+
+ target_message_loop_->PostTask(
+ FROM_HERE, NewRunnableMethod(this, &IconLoader::NotifyDelegate));
+}
diff --git a/chrome/browser/icon_manager_linux.cc b/chrome/browser/icon_manager_linux.cc
index 930320e..fc3cfa8 100644
--- a/chrome/browser/icon_manager_linux.cc
+++ b/chrome/browser/icon_manager_linux.cc
@@ -8,10 +8,6 @@
#include "base/threading/thread_restrictions.h"
IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) {
-#if defined(USE_AURA)
- // TODO(davemoore) Implement this for aura.
- return std::string();
-#else
// It turns out the call to mime_util::GetFileMimeType below does IO, but
// callers of GetGroupIDFromFilepath assume it does not do IO (the Windows
// and Mac implementations do not). We should fix this by either not doing IO
@@ -20,5 +16,4 @@ IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) {
base::ThreadRestrictions::ScopedAllowIO allow_io;
return mime_util::GetFileMimeType(filepath);
-#endif
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index cb8989e..68bf3dd 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1373,8 +1373,7 @@
'browser/history/visitsegment_database.h',
'browser/icon_loader.cc',
'browser/icon_loader.h',
- 'browser/icon_loader_aura.cc',
- 'browser/icon_loader_gtk.cc',
+ 'browser/icon_loader_linux.cc',
'browser/icon_loader_mac.mm',
'browser/icon_loader_win.cc',
'browser/icon_manager.cc',
diff --git a/net/base/platform_mime_util_linux.cc b/net/base/platform_mime_util_linux.cc
index c841914..1d4acc0 100644
--- a/net/base/platform_mime_util_linux.cc
+++ b/net/base/platform_mime_util_linux.cc
@@ -22,12 +22,6 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
const FilePath::StringType& ext, std::string* result) const {
return android::GetMimeTypeFromExtension(ext, result);
}
-#elif defined(USE_AURA)
-bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
- const FilePath::StringType& ext, std::string* result) const {
- NOTIMPLEMENTED();
- return false;
-}
#else
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
const FilePath::StringType& ext, std::string* result) const {