1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/icon_loader.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/message_loop.h"
13 #include "base/nix/mime_util_xdg.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "webkit/glue/image_decoder.h"
19 void IconLoader::ReadIcon() {
22 case IconLoader::SMALL
:
25 case IconLoader::NORMAL
:
28 case IconLoader::LARGE
:
35 FilePath filename
= base::nix::GetMimeIcon(group_
, size_pixels
);
37 file_util::ReadFileToString(filename
, &icon_data
);
39 webkit_glue::ImageDecoder decoder
;
40 scoped_ptr
<SkBitmap
> bitmap(new SkBitmap());
41 *bitmap
= decoder
.Decode(
42 reinterpret_cast<const unsigned char*>(icon_data
.data()),
44 if (!bitmap
->empty()) {
45 DCHECK_EQ(size_pixels
, bitmap
->width());
46 DCHECK_EQ(size_pixels
, bitmap
->height());
47 image_
.reset(new gfx::Image(bitmap
.release()));
49 LOG(WARNING
) << "Unsupported file type or load error: " << filename
.value();
52 target_message_loop_
->PostTask(
53 FROM_HERE
, base::Bind(&IconLoader::NotifyDelegate
, this));