OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/nix/mime_util_xdg.h" | 13 #include "base/nix/mime_util_xdg.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
16 #include "webkit/glue/image_decoder.h" | 16 #include "webkit/glue/image_decoder.h" |
17 | 17 |
18 using std::string; | 18 using std::string; |
19 | 19 |
20 void IconLoader::ReadIcon() { | 20 void IconLoader::ReadIcon(const IconGroupID& group) { |
21 int size_pixels = 0; | 21 int size_pixels = 0; |
22 switch (icon_size_) { | 22 switch (icon_size_) { |
23 case IconLoader::SMALL: | 23 case IconLoader::SMALL: |
24 size_pixels = 16; | 24 size_pixels = 16; |
25 break; | 25 break; |
26 case IconLoader::NORMAL: | 26 case IconLoader::NORMAL: |
27 size_pixels = 32; | 27 size_pixels = 32; |
28 break; | 28 break; |
29 case IconLoader::LARGE: | 29 case IconLoader::LARGE: |
30 size_pixels = 48; | 30 size_pixels = 48; |
31 break; | 31 break; |
32 default: | 32 default: |
33 NOTREACHED(); | 33 NOTREACHED(); |
34 } | 34 } |
35 | 35 |
36 FilePath filename = base::nix::GetMimeIcon(group_, size_pixels); | 36 FilePath filename = base::nix::GetMimeIcon(group, size_pixels); |
37 // We don't support SVG icons; this just spams the terminal so fail quickly | 37 // We don't support SVG icons; this just spams the terminal so fail quickly |
38 // and don't try to read the file from disk first. | 38 // and don't try to read the file from disk first. |
39 if (filename.Extension() != ".svg") { | 39 if (filename.Extension() != ".svg") { |
40 string icon_data; | 40 string icon_data; |
41 file_util::ReadFileToString(filename, &icon_data); | 41 file_util::ReadFileToString(filename, &icon_data); |
42 | 42 |
43 webkit_glue::ImageDecoder decoder; | 43 webkit_glue::ImageDecoder decoder; |
44 SkBitmap bitmap; | 44 SkBitmap bitmap; |
45 bitmap = decoder.Decode( | 45 bitmap = decoder.Decode( |
46 reinterpret_cast<const unsigned char*>(icon_data.data()), | 46 reinterpret_cast<const unsigned char*>(icon_data.data()), |
47 icon_data.length()); | 47 icon_data.length()); |
48 if (!bitmap.empty()) { | 48 if (!bitmap.empty()) { |
49 DCHECK_EQ(size_pixels, bitmap.width()); | 49 DCHECK_EQ(size_pixels, bitmap.width()); |
50 DCHECK_EQ(size_pixels, bitmap.height()); | 50 DCHECK_EQ(size_pixels, bitmap.height()); |
51 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 51 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
52 image_skia.MakeThreadSafe(); | 52 image_skia.MakeThreadSafe(); |
53 image_.reset(new gfx::Image(image_skia)); | 53 image_.reset(new gfx::Image(image_skia)); |
54 } else { | 54 } else { |
55 LOG(WARNING) << "Unsupported file type or load error: " | 55 LOG(WARNING) << "Unsupported file type or load error: " |
56 << filename.value(); | 56 << filename.value(); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 target_message_loop_->PostTask( | 60 target_message_loop_->PostTask( |
61 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 61 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this, group)); |
62 } | 62 } |
OLD | NEW |