blob: 26788d857433d5679e93694236ba99b5f99e7375 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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() {
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));
}
|