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 "webkit/glue/image_decoder.h" | 16 #include "webkit/glue/image_decoder.h" |
16 | 17 |
17 using std::string; | 18 using std::string; |
18 | 19 |
19 void IconLoader::ReadIcon() { | 20 void IconLoader::ReadIcon() { |
20 int size_pixels = 0; | 21 int size_pixels = 0; |
21 switch (icon_size_) { | 22 switch (icon_size_) { |
22 case IconLoader::SMALL: | 23 case IconLoader::SMALL: |
23 size_pixels = 16; | 24 size_pixels = 16; |
24 break; | 25 break; |
(...skipping 15 matching lines...) Expand all Loading... |
40 file_util::ReadFileToString(filename, &icon_data); | 41 file_util::ReadFileToString(filename, &icon_data); |
41 | 42 |
42 webkit_glue::ImageDecoder decoder; | 43 webkit_glue::ImageDecoder decoder; |
43 SkBitmap bitmap; | 44 SkBitmap bitmap; |
44 bitmap = decoder.Decode( | 45 bitmap = decoder.Decode( |
45 reinterpret_cast<const unsigned char*>(icon_data.data()), | 46 reinterpret_cast<const unsigned char*>(icon_data.data()), |
46 icon_data.length()); | 47 icon_data.length()); |
47 if (!bitmap.empty()) { | 48 if (!bitmap.empty()) { |
48 DCHECK_EQ(size_pixels, bitmap.width()); | 49 DCHECK_EQ(size_pixels, bitmap.width()); |
49 DCHECK_EQ(size_pixels, bitmap.height()); | 50 DCHECK_EQ(size_pixels, bitmap.height()); |
50 image_.reset(new gfx::Image(bitmap)); | 51 gfx::ImageSkia image_skia(bitmap); |
| 52 image_skia.MakeThreadSafe(); |
| 53 image_.reset(new gfx::Image(image_skia)); |
51 } else { | 54 } else { |
52 LOG(WARNING) << "Unsupported file type or load error: " | 55 LOG(WARNING) << "Unsupported file type or load error: " |
53 << filename.value(); | 56 << filename.value(); |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
57 target_message_loop_->PostTask( | 60 target_message_loop_->PostTask( |
58 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 61 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); |
59 } | 62 } |
OLD | NEW |