summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/dom_ui/downloads_dom_handler.cc12
-rw-r--r--chrome/browser/dom_ui/downloads_ui.cc8
-rw-r--r--chrome/browser/dom_ui/fileicon_source.h6
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc29
-rw-r--r--chrome/browser/gtk/download_item_gtk.h15
-rw-r--r--chrome/browser/icon_loader_linux.cc29
-rw-r--r--chrome/browser/icon_manager_linux.cc5
8 files changed, 89 insertions, 17 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 759934b..18e3a83 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/download/save_file_manager.h"
#include "chrome/browser/google_url_tracker.h"
+#include "chrome/browser/icon_manager.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
@@ -33,7 +34,6 @@
#if defined(OS_WIN)
#include "chrome/browser/automation/automation_provider_list.h"
-#include "chrome/browser/icon_manager.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "views/focus/view_storage.h"
#include "views/widget/accelerator_handler.h"
diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc
index ea56c07..f38a664 100644
--- a/chrome/browser/dom_ui/downloads_dom_handler.cc
+++ b/chrome/browser/dom_ui/downloads_dom_handler.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/dom_ui/downloads_dom_handler.h"
#include "app/l10n_util.h"
+#include "base/basictypes.h"
#include "base/gfx/png_encoder.h"
#include "base/string_piece.h"
#include "base/thread.h"
@@ -12,10 +13,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/fileicon_source.h"
-#if defined(OS_WIN)
-// TODO(port): re-enable when download_util is ported
-#include "chrome/browser/download/download_util.h"
-#endif
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/common/jstemplate_builder.h"
@@ -24,6 +21,13 @@
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
+#if defined(OS_WIN)
+// TODO(port): re-enable when download_util is ported
+#include "chrome/browser/download/download_util.h"
+#else
+#include "chrome/common/temp_scaffolding_stubs.h"
+#endif
+
namespace {
// Maximum number of downloads to show. TODO(glen): Remove this and instead
diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc
index 76eb9074..9039200 100644
--- a/chrome/browser/dom_ui/downloads_ui.cc
+++ b/chrome/browser/dom_ui/downloads_ui.cc
@@ -19,6 +19,14 @@
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
+#if defined(OS_WIN)
+// TODO(port): re-enable when download_util is ported
+#include "chrome/browser/download/download_util.h"
+#else
+#include "chrome/common/temp_scaffolding_stubs.h"
+#endif
+
+
namespace {
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/dom_ui/fileicon_source.h b/chrome/browser/dom_ui/fileicon_source.h
index 423efcb..0f2924d 100644
--- a/chrome/browser/dom_ui/fileicon_source.h
+++ b/chrome/browser/dom_ui/fileicon_source.h
@@ -7,13 +7,7 @@
#include "app/resource_bundle.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-
-#if defined(OS_WIN)
#include "chrome/browser/icon_manager.h"
-#else
-// TODO(port): Remove when IconManager has been ported.
-#include "chrome/common/temp_scaffolding_stubs.h"
-#endif
class GURL;
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index 02f2f3f..80996f3 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_shelf.h"
@@ -21,6 +22,7 @@
#include "chrome/common/gtk_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
namespace {
@@ -148,8 +150,10 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
: parent_shelf_(parent_shelf),
progress_angle_(download_util::kStartAngleDegrees),
download_model_(download_model),
- bounding_widget_(parent_shelf->GetRightBoundingWidget()) {
+ bounding_widget_(parent_shelf->GetRightBoundingWidget()),
+ icon_(NULL) {
InitNineBoxes();
+ LoadIcon();
body_ = gtk_button_new();
gtk_widget_set_app_paintable(body_, TRUE);
@@ -326,6 +330,21 @@ void DownloadItemGtk::StopDownloadProgress() {
progress_timer_.Stop();
}
+// Icon loading functions.
+
+void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle,
+ SkBitmap* icon_bitmap) {
+ icon_ = icon_bitmap;
+ gtk_widget_queue_draw(progress_area_);
+}
+
+void DownloadItemGtk::LoadIcon() {
+ IconManager* im = g_browser_process->icon_manager();
+ im->LoadIcon(download_model_->download()->full_path(),
+ IconLoader::SMALL, &icon_consumer_,
+ NewCallback(this, &DownloadItemGtk::OnLoadIconComplete));
+}
+
// static
void DownloadItemGtk::InitNineBoxes() {
if (body_nine_box_normal_)
@@ -422,7 +441,13 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget,
download_util::SMALL);
}
- // TODO(estade): paint download icon.
+ // TODO(estade): draw a default icon if |icon_| is null.
+ if (download_item->icon_) {
+ canvas.DrawBitmapInt(*download_item->icon_,
+ widget->allocation.x + download_util::kSmallProgressIconOffset,
+ widget->allocation.y + download_util::kSmallProgressIconOffset);
+ }
+
return TRUE;
}
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index 00f1795..fd21680 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -10,11 +10,13 @@
#include "app/animation.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/icon_manager.h"
class BaseDownloadItemModel;
class DownloadShelfContextMenuGtk;
class DownloadShelfGtk;
class NineBox;
+class SkBitmap;
class SlideAnimation;
class DownloadItemGtk : public DownloadItem::Observer,
@@ -35,6 +37,10 @@ class DownloadItemGtk : public DownloadItem::Observer,
// AnimationDelegate implementation.
virtual void AnimationProgressed(const Animation* animation);
+ // Called when the icon manager has finished loading the icon. We take
+ // ownership of |icon_bitmap|.
+ void OnLoadIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap);
+
private:
// Functions for controlling the progress animation.
// Repaint the download progress.
@@ -46,6 +52,9 @@ class DownloadItemGtk : public DownloadItem::Observer,
// Stops the repeating timer.
void StopDownloadProgress();
+ // Ask the icon manager to asynchronously start loading the icon for the file.
+ void LoadIcon();
+
static void InitNineBoxes();
// Used for the download item's body and menu button.
@@ -124,6 +133,12 @@ class DownloadItemGtk : public DownloadItem::Observer,
// Animation for download complete.
scoped_ptr<SlideAnimation> complete_animation_;
+
+ // The file icon for the download. May be null.
+ SkBitmap* icon_;
+
+ // For canceling an in progress icon request.
+ CancelableRequestConsumerT<int, 0> icon_consumer_;
};
#endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_
diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc
index 83a8305..26788d8 100644
--- a/chrome/browser/icon_loader_linux.cc
+++ b/chrome/browser/icon_loader_linux.cc
@@ -4,11 +4,38 @@
#include "chrome/browser/icon_loader.h"
+#include "base/file_util.h"
+#include "base/gfx/png_decoder.h"
+#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/mime_util.h"
#include "base/thread.h"
+#include "base/string_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
void IconLoader::ReadIcon() {
- NOTIMPLEMENTED();
+ size_t size = 48;
+ if (icon_size_ == NORMAL)
+ size = 32;
+ else if (icon_size_ == SMALL)
+ size = 16;
+
+ FilePath filename = mime_util::GetMimeIcon(group_, size);
+ if (LowerCaseEqualsASCII(mime_util::GetFileMimeType(filename), "image/png")) {
+ std::string file_contents;
+ file_util::ReadFileToString(filename, &file_contents);
+
+ std::vector<unsigned char> pixels;
+ int width, height;
+ if (PNGDecoder::Decode(
+ reinterpret_cast<const unsigned char*>(file_contents.c_str()),
+ file_contents.length(), PNGDecoder::FORMAT_BGRA,
+ &pixels, &width, &height)) {
+ bitmap_ = PNGDecoder::CreateSkBitmapFromBGRAFormat(pixels, width, height);
+ }
+ } else {
+ // TODO(estade): support other file types.
+ }
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 3e5d8be..c653d2f 100644
--- a/chrome/browser/icon_manager_linux.cc
+++ b/chrome/browser/icon_manager_linux.cc
@@ -4,9 +4,8 @@
#include "chrome/browser/icon_manager.h"
-#include "base/file_path.h"
+#include "base/mime_util.h"
IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) {
- NOTIMPLEMENTED();
- return std::string();
+ return mime_util::GetFileMimeType(filepath);
}