| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/fileicon_source.h" | 5 #include "chrome/browser/dom_ui/fileicon_source.h" |
| 6 | 6 |
| 7 #include "app/gfx/codec/png_codec.h" | 7 #include "app/gfx/codec/png_codec.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/common/time_format.h" | 10 #include "chrome/common/time_format.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // this only appears to matter for getting icons from .exe files. | 32 // this only appears to matter for getting icons from .exe files. |
| 33 std::replace(escaped_path.begin(), escaped_path.end(), '/', '\\'); | 33 std::replace(escaped_path.begin(), escaped_path.end(), '/', '\\'); |
| 34 FilePath escaped_filepath(UTF8ToWide(escaped_path)); | 34 FilePath escaped_filepath(UTF8ToWide(escaped_path)); |
| 35 #elif defined(OS_POSIX) | 35 #elif defined(OS_POSIX) |
| 36 // The correct encoding on Linux may not actually be UTF8. | 36 // The correct encoding on Linux may not actually be UTF8. |
| 37 FilePath escaped_filepath(escaped_path); | 37 FilePath escaped_filepath(escaped_path); |
| 38 #endif | 38 #endif |
| 39 SkBitmap* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); | 39 SkBitmap* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); |
| 40 | 40 |
| 41 if (icon) { | 41 if (icon) { |
| 42 std::vector<unsigned char> png_bytes; | 42 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes; |
| 43 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &png_bytes); | 43 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data); |
| 44 | 44 |
| 45 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); | |
| 46 SendResponse(request_id, icon_data); | 45 SendResponse(request_id, icon_data); |
| 47 } else { | 46 } else { |
| 48 // Icon was not in cache, go fetch it slowly. | 47 // Icon was not in cache, go fetch it slowly. |
| 49 IconManager::Handle h = im->LoadIcon(escaped_filepath, | 48 IconManager::Handle h = im->LoadIcon(escaped_filepath, |
| 50 IconLoader::NORMAL, | 49 IconLoader::NORMAL, |
| 51 &cancelable_consumer_, | 50 &cancelable_consumer_, |
| 52 NewCallback(this, &FileIconSource::OnFileIconDataAvailable)); | 51 NewCallback(this, &FileIconSource::OnFileIconDataAvailable)); |
| 53 | 52 |
| 54 // Attach the ChromeURLDataManager request ID to the history request. | 53 // Attach the ChromeURLDataManager request ID to the history request. |
| 55 cancelable_consumer_.SetClientData(im, h, request_id); | 54 cancelable_consumer_.SetClientData(im, h, request_id); |
| 56 } | 55 } |
| 57 } | 56 } |
| 58 | 57 |
| 59 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, | 58 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, |
| 60 SkBitmap* icon) { | 59 SkBitmap* icon) { |
| 61 IconManager* im = g_browser_process->icon_manager(); | 60 IconManager* im = g_browser_process->icon_manager(); |
| 62 int request_id = cancelable_consumer_.GetClientData(im, handle); | 61 int request_id = cancelable_consumer_.GetClientData(im, handle); |
| 63 | 62 |
| 64 if (icon) { | 63 if (icon) { |
| 65 std::vector<unsigned char> png_bytes; | 64 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes; |
| 66 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &png_bytes); | 65 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data); |
| 67 | 66 |
| 68 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); | |
| 69 SendResponse(request_id, icon_data); | 67 SendResponse(request_id, icon_data); |
| 70 } else { | 68 } else { |
| 71 // TODO(glen): send a dummy icon. | 69 // TODO(glen): send a dummy icon. |
| 72 SendResponse(request_id, NULL); | 70 SendResponse(request_id, NULL); |
| 73 } | 71 } |
| 74 } | 72 } |
| OLD | NEW |