| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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. | 
|  | 4 | 
|  | 5 #include "chrome/browser/icon_loader.h" | 
|  | 6 | 
|  | 7 #include <string> | 
|  | 8 | 
|  | 9 #include "base/file_util.h" | 
|  | 10 #include "base/logging.h" | 
|  | 11 #include "base/message_loop.h" | 
|  | 12 #include "base/mime_util.h" | 
|  | 13 #include "third_party/skia/include/core/SkBitmap.h" | 
|  | 14 #include "webkit/glue/image_decoder.h" | 
|  | 15 | 
|  | 16 using std::string; | 
|  | 17 | 
|  | 18 void IconLoader::ReadIcon() { | 
|  | 19   int size_pixels = 0; | 
|  | 20   switch (icon_size_) { | 
|  | 21     case IconLoader::SMALL: | 
|  | 22       size_pixels = 16; | 
|  | 23       break; | 
|  | 24     case IconLoader::NORMAL: | 
|  | 25       size_pixels = 32; | 
|  | 26       break; | 
|  | 27     case IconLoader::LARGE: | 
|  | 28       size_pixels = 48; | 
|  | 29       break; | 
|  | 30     default: | 
|  | 31       NOTREACHED(); | 
|  | 32   } | 
|  | 33 | 
|  | 34   FilePath filename = mime_util::GetMimeIcon(group_, size_pixels); | 
|  | 35   string icon_data; | 
|  | 36   file_util::ReadFileToString(filename, &icon_data); | 
|  | 37 | 
|  | 38   webkit_glue::ImageDecoder decoder; | 
|  | 39   scoped_ptr<SkBitmap> bitmap(new SkBitmap()); | 
|  | 40   *bitmap = decoder.Decode( | 
|  | 41       reinterpret_cast<const unsigned char*>(icon_data.data()), | 
|  | 42       icon_data.length()); | 
|  | 43   if (!bitmap->empty()) { | 
|  | 44     DCHECK_EQ(size_pixels, bitmap->width()); | 
|  | 45     DCHECK_EQ(size_pixels, bitmap->height()); | 
|  | 46     image_.reset(new gfx::Image(bitmap.release())); | 
|  | 47   } else { | 
|  | 48     LOG(WARNING) << "Unsupported file type or load error: " << filename.value(); | 
|  | 49   } | 
|  | 50 | 
|  | 51   target_message_loop_->PostTask( | 
|  | 52       FROM_HERE, NewRunnableMethod(this, &IconLoader::NotifyDelegate)); | 
|  | 53 } | 
| OLD | NEW | 
|---|