Chromium Code Reviews| Index: chrome/browser/icon_loader_chromeos.cc |
| diff --git a/chrome/browser/ui/webui/fileicon_source_chromeos.cc b/chrome/browser/icon_loader_chromeos.cc |
| similarity index 64% |
| rename from chrome/browser/ui/webui/fileicon_source_chromeos.cc |
| rename to chrome/browser/icon_loader_chromeos.cc |
| index d0dc1d5ddd571d22aeefa4ddaf9085021420c969..82b82ac6a785414c2315faeefa3d6bab3249e715 100644 |
| --- a/chrome/browser/ui/webui/fileicon_source_chromeos.cc |
| +++ b/chrome/browser/icon_loader_chromeos.cc |
| @@ -2,30 +2,24 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/webui/fileicon_source_chromeos.h" |
| +#include "chrome/browser/icon_loader.h" |
| +#include <string> |
|
achuithb
2012/01/23 20:59:27
alphabetical order please
asanka
2012/01/26 00:49:35
Done.
|
| #include <map> |
| #include <utility> |
| -#include <vector> |
| -#include "base/file_util.h" |
| -#include "base/memory/singleton.h" |
| -#include "base/string_split.h" |
| -#include "base/string_util.h" |
| -#include "base/threading/thread_restrictions.h" |
| +#include "base/basictypes.h" |
| +#include "base/bind.h" |
| +#include "base/message_loop.h" |
| #include "chrome/browser/icon_loader.h" |
| -#include "chrome/browser/io_thread.h" |
| -#include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| -#include "chrome/common/url_constants.h" |
| -#include "googleurl/src/gurl.h" |
| #include "grit/component_extension_resources.h" |
| -#include "grit/component_extension_resources_map.h" |
| -#include "grit/generated_resources.h" |
| -#include "grit/theme_resources.h" |
| -#include "grit/ui_resources.h" |
| -#include "net/base/escape.h" |
| -#include "net/base/mime_util.h" |
| +#include "skia/ext/image_operations.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/canvas_skia.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "webkit/glue/image_decoder.h" |
| namespace { |
| @@ -35,11 +29,8 @@ struct IdrBySize { |
| int idr_large_; |
| }; |
| -typedef std::map<std::string, IconLoader::IconSize> QueryIconSizeMap; |
| typedef std::map<std::string, IdrBySize> ExtensionIconSizeMap; |
| -const char *kIconSize = "iconsize"; |
| - |
| const IdrBySize kAudioIdrs = { |
| IDR_FILE_MANAGER_IMG_FILETYPE_AUDIO, |
| IDR_FILE_MANAGER_IMG_FILETYPE_LARGE_AUDIO, |
| @@ -106,18 +97,6 @@ const IdrBySize kVideoIdrs = { |
| IDR_FILE_MANAGER_IMG_FILETYPE_LARGE_VIDEO |
| }; |
| -QueryIconSizeMap BuildQueryIconSizeMap() { |
| - QueryIconSizeMap::value_type kQueryIconSizeData[] = { |
| - std::make_pair("small", IconLoader::SMALL), |
| - std::make_pair("normal", IconLoader::NORMAL), |
| - std::make_pair("large", IconLoader::LARGE) |
| - }; |
| - |
| - size_t kQSize = arraysize(kQueryIconSizeData); |
| - return QueryIconSizeMap(&kQueryIconSizeData[0], |
| - &kQueryIconSizeData[kQSize]); |
| -} |
| - |
| // The code below should match translation in |
| // chrome/browser/resources/file_manager/js/file_manager.js |
| // chrome/browser/resources/file_manager/css/file_manager.css |
| @@ -172,45 +151,11 @@ ExtensionIconSizeMap BuildExtensionIdrSizeMap() { |
| &kExtensionIdrBySizeData[kESize]); |
| } |
| -// Split on the very first &. The first part is path, the rest query. |
| -void GetExtensionAndQuery(const std::string& url, |
| - std::string* extension, |
| - std::string* query) { |
| - // We receive the url with chrome://fileicon/ stripped but GURL expects it. |
| - const GURL gurl("chrome://fileicon/" + net::EscapePath(url)); |
| - const std::string path = gurl.path(); |
| - *extension = StringToLowerASCII(FilePath(path).Extension()); |
| - *query = gurl.query(); |
| -} |
| - |
| -// Simple parser for data on the query. |
| -IconLoader::IconSize QueryToIconSize(const std::string& query) { |
| - CR_DEFINE_STATIC_LOCAL( |
| - QueryIconSizeMap, kQueryIconSizeMap, (BuildQueryIconSizeMap())); |
| - typedef std::pair<std::string, std::string> KVPair; |
| - std::vector<KVPair> parameters; |
| - if (base::SplitStringIntoKeyValuePairs(query, '=', '&', ¶meters)) { |
| - for (std::vector<KVPair>::const_iterator itk = parameters.begin(); |
| - itk != parameters.end(); ++itk) { |
| - if (itk->first == kIconSize) { |
| - QueryIconSizeMap::const_iterator itq( |
| - kQueryIconSizeMap.find(itk->second)); |
| - if (itq != kQueryIconSizeMap.end()) |
| - return itq->second; |
| - } |
| - } |
| - } |
| - return IconLoader::NORMAL; |
| -} |
| - |
| // Finds matching resource of proper size. Fallback to generic. |
| -int UrlToIDR(const std::string& url) { |
| +int FileTypeToIDR(const std::string& extension, IconLoader::IconSize size) { |
| CR_DEFINE_STATIC_LOCAL( |
| ExtensionIconSizeMap, kExtensionIdrSizeMap, (BuildExtensionIdrSizeMap())); |
| - std::string extension, query; |
| int idr = -1; |
| - GetExtensionAndQuery(url, &extension, &query); |
| - const IconLoader::IconSize size = QueryToIconSize(query); |
| ExtensionIconSizeMap::const_iterator it = |
| kExtensionIdrSizeMap.find(extension); |
| if (it != kExtensionIdrSizeMap.end()) { |
| @@ -234,26 +179,42 @@ int UrlToIDR(const std::string& url) { |
| } |
| return idr; |
| } |
| -} // namespace |
| -FileIconSourceCros::FileIconSourceCros() |
| - : DataSource("fileicon", NULL) { |
| -} |
| +SkBitmap* GenerateBitmapWithSize(SkBitmap* source, int pixel_size) { |
| + DCHECK(source); |
| + DCHECK(source->width() == source->height()); |
| + |
| + if (pixel_size == -1 || source->width() == pixel_size) |
| + return new SkBitmap(*source); |
| -FileIconSourceCros::~FileIconSourceCros() { |
| + return new SkBitmap(skia::ImageOperations::Resize( |
| + *source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size)); |
| } |
| -void FileIconSourceCros::StartDataRequest(const std::string& url, |
| - bool is_incognito, |
| - int request_id) { |
| - int idr = UrlToIDR(url); |
| - const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| - scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr)); |
| - SendResponse(request_id, bytes); |
| +int IconSizeToPixelSize(IconLoader::IconSize size) { |
| + switch (size) { |
| + case IconLoader::SMALL: return 16; |
| + case IconLoader::NORMAL: return 32; |
| + case IconLoader::LARGE: // fallthrough |
| + case IconLoader::ALL: // fallthrough |
| + default: |
| + return -1; |
| + } |
| } |
| -// The mime type refers to the type of the response/icon served. |
| -std::string FileIconSourceCros::GetMimeType( |
| - const std::string& url) const { |
| - return "image/png"; |
| +} // namespace |
| + |
| +void IconLoader::ReadIcon() { |
| + int idr = FileTypeToIDR(group_, icon_size_); |
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| + scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr)); |
| + DCHECK(bytes.get()); |
| + SkBitmap bitmap; |
| + if (!gfx::PNGCodec::Decode(bytes->front(), bytes->size(), &bitmap)) { |
| + NOTREACHED(); |
| + } |
| + image_.reset(new gfx::Image( |
| + GenerateBitmapWithSize(&bitmap, IconSizeToPixelSize(icon_size_)))); |
| + target_message_loop_->PostTask( |
| + FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); |
| } |