| 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 "content/public/child/image_decoder_utils.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 16 #include "webkit/glue/image_decoder.h" | 17 #include "ui/gfx/size.h" |
| 17 | 18 |
| 18 using std::string; | 19 using std::string; |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 IconGroupID IconLoader::ReadGroupIDFromFilepath( | 22 IconGroupID IconLoader::ReadGroupIDFromFilepath( |
| 22 const base::FilePath& filepath) { | 23 const base::FilePath& filepath) { |
| 23 return base::nix::GetFileMimeType(filepath); | 24 return base::nix::GetFileMimeType(filepath); |
| 24 } | 25 } |
| 25 | 26 |
| 26 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) { | 27 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 NOTREACHED(); | 44 NOTREACHED(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 base::FilePath filename = base::nix::GetMimeIcon(group_, size_pixels); | 47 base::FilePath filename = base::nix::GetMimeIcon(group_, size_pixels); |
| 47 // We don't support SVG icons; this just spams the terminal so fail quickly | 48 // We don't support SVG icons; this just spams the terminal so fail quickly |
| 48 // and don't try to read the file from disk first. | 49 // and don't try to read the file from disk first. |
| 49 if (filename.Extension() != ".svg") { | 50 if (filename.Extension() != ".svg") { |
| 50 string icon_data; | 51 string icon_data; |
| 51 file_util::ReadFileToString(filename, &icon_data); | 52 file_util::ReadFileToString(filename, &icon_data); |
| 52 | 53 |
| 53 webkit_glue::ImageDecoder decoder; | |
| 54 SkBitmap bitmap; | 54 SkBitmap bitmap; |
| 55 bitmap = decoder.Decode( | 55 bitmap = content::DecodeImage( |
| 56 reinterpret_cast<const unsigned char*>(icon_data.data()), | 56 reinterpret_cast<const unsigned char*>(icon_data.data()), |
| 57 gfx::Size(), |
| 57 icon_data.length()); | 58 icon_data.length()); |
| 58 if (!bitmap.empty()) { | 59 if (!bitmap.empty()) { |
| 59 DCHECK_EQ(size_pixels, bitmap.width()); | 60 DCHECK_EQ(size_pixels, bitmap.width()); |
| 60 DCHECK_EQ(size_pixels, bitmap.height()); | 61 DCHECK_EQ(size_pixels, bitmap.height()); |
| 61 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 62 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 62 image_skia.MakeThreadSafe(); | 63 image_skia.MakeThreadSafe(); |
| 63 image_.reset(new gfx::Image(image_skia)); | 64 image_.reset(new gfx::Image(image_skia)); |
| 64 } else { | 65 } else { |
| 65 LOG(WARNING) << "Unsupported file type or load error: " | 66 LOG(WARNING) << "Unsupported file type or load error: " |
| 66 << filename.value(); | 67 << filename.value(); |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 target_message_loop_->PostTask( | 71 target_message_loop_->PostTask( |
| 71 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 72 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); |
| 72 } | 73 } |
| OLD | NEW |