| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/gfx/png_encoder.h" | 7 #include "base/gfx/png_encoder.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" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
| 13 | 13 |
| 14 // The path used in internal URLs to file icon data. | 14 // The path used in internal URLs to file icon data. |
| 15 static const char kFileIconPath[] = "fileicon"; | 15 static const char kFileIconPath[] = "fileicon"; |
| 16 | 16 |
| 17 FileIconSource::FileIconSource() | 17 FileIconSource::FileIconSource() |
| 18 : DataSource(kFileIconPath, MessageLoop::current()) {} | 18 : DataSource(kFileIconPath, MessageLoop::current()) {} |
| 19 | 19 |
| 20 FileIconSource::~FileIconSource() { | 20 FileIconSource::~FileIconSource() { |
| 21 cancelable_consumer_.CancelAllRequests(); | 21 cancelable_consumer_.CancelAllRequests(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void FileIconSource::StartDataRequest(const std::string& path, | 24 void FileIconSource::StartDataRequest(const std::string& path, |
| 25 int request_id) { | 25 int request_id) { |
| 26 IconManager* im = g_browser_process->icon_manager(); | 26 IconManager* im = g_browser_process->icon_manager(); |
| 27 | 27 |
| 28 std::string escaped_path = UnescapeURLComponent(path, UnescapeRule::SPACES); |
| 29 |
| 30 #if defined(OS_WIN) |
| 28 // The path we receive has the wrong slashes and escaping for what we need; | 31 // The path we receive has the wrong slashes and escaping for what we need; |
| 29 // this only appears to matter for getting icons from .exe files. | 32 // this only appears to matter for getting icons from .exe files. |
| 30 std::string escaped_path = UnescapeURLComponent(path, UnescapeRule::SPACES); | |
| 31 std::replace(escaped_path.begin(), escaped_path.end(), '/', '\\'); | 33 std::replace(escaped_path.begin(), escaped_path.end(), '/', '\\'); |
| 32 | |
| 33 // Fast look up. | |
| 34 #if defined(OS_WIN) | |
| 35 FilePath escaped_filepath(UTF8ToWide(escaped_path)); | 34 FilePath escaped_filepath(UTF8ToWide(escaped_path)); |
| 36 #elif defined(OS_POSIX) | 35 #elif defined(OS_POSIX) |
| 37 // The correct encoding on Linux may not actually be UTF8. | 36 // The correct encoding on Linux may not actually be UTF8. |
| 38 FilePath escaped_filepath(escaped_path); | 37 FilePath escaped_filepath(escaped_path); |
| 39 #endif | 38 #endif |
| 40 SkBitmap* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); | 39 SkBitmap* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); |
| 41 | 40 |
| 42 if (icon) { | 41 if (icon) { |
| 43 std::vector<unsigned char> png_bytes; | 42 std::vector<unsigned char> png_bytes; |
| 44 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); | 43 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 std::vector<unsigned char> png_bytes; | 65 std::vector<unsigned char> png_bytes; |
| 67 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); | 66 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes); |
| 68 | 67 |
| 69 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); | 68 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes); |
| 70 SendResponse(request_id, icon_data); | 69 SendResponse(request_id, icon_data); |
| 71 } else { | 70 } else { |
| 72 // TODO(glen): send a dummy icon. | 71 // TODO(glen): send a dummy icon. |
| 73 SendResponse(request_id, NULL); | 72 SendResponse(request_id, NULL); |
| 74 } | 73 } |
| 75 } | 74 } |
| OLD | NEW |