diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 23:01:19 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 23:01:19 +0000 |
commit | 3ce52b7367e007940d7ab34ae8eae1df236c59df (patch) | |
tree | 47f5613516962fab4f194fe71301f893bfc0b30f /chrome/browser | |
parent | f5f2b838a077645b6ff97a995c98906e314304d5 (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/icon_loader.cc | 4 | ||||
-rw-r--r-- | chrome/browser/icon_loader.h | 9 | ||||
-rw-r--r-- | chrome/browser/icon_loader_aura.cc | 11 | ||||
-rw-r--r-- | chrome/browser/icon_loader_gtk.cc | 71 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 53 | ||||
-rw-r--r-- | chrome/browser/icon_manager_linux.cc | 5 |
6 files changed, 55 insertions, 98 deletions
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 } |