| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/extensions/extension_icon_source.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/image_loader.h" | 19 #include "chrome/browser/extensions/image_loader.h" |
| 20 #include "chrome/browser/favicon/favicon_service_factory.h" | 20 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/extension_resource.h" | 25 #include "chrome/common/extensions/extension_resource.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "grit/component_extension_resources_map.h" | 28 #include "grit/component_extension_resources_map.h" |
| 28 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 29 #include "skia/ext/image_operations.h" | 30 #include "skia/ext/image_operations.h" |
| 30 #include "ui/base/layout.h" | 31 #include "ui/base/layout.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 // static | 73 // static |
| 73 GURL ExtensionIconSource::GetIconURL(const extensions::Extension* extension, | 74 GURL ExtensionIconSource::GetIconURL(const extensions::Extension* extension, |
| 74 int icon_size, | 75 int icon_size, |
| 75 ExtensionIconSet::MatchType match, | 76 ExtensionIconSet::MatchType match, |
| 76 bool grayscale, | 77 bool grayscale, |
| 77 bool* exists) { | 78 bool* exists) { |
| 78 if (exists) | 79 if (exists) |
| 79 *exists = true; | 80 *exists = true; |
| 80 if (exists && extension->GetIconURL(icon_size, match) == GURL()) | 81 if (exists && extensions::IconsInfo::GetIconURL( |
| 82 extension, icon_size, match) == GURL()) { |
| 81 *exists = false; | 83 *exists = false; |
| 84 } |
| 82 | 85 |
| 83 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", | 86 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", |
| 84 chrome::kChromeUIExtensionIconURL, | 87 chrome::kChromeUIExtensionIconURL, |
| 85 extension->id().c_str(), | 88 extension->id().c_str(), |
| 86 icon_size, | 89 icon_size, |
| 87 match, | 90 match, |
| 88 grayscale ? "?grayscale=true" : "")); | 91 grayscale ? "?grayscale=true" : "")); |
| 89 CHECK(icon_url.is_valid()); | 92 CHECK(icon_url.is_valid()); |
| 90 return icon_url; | 93 return icon_url; |
| 91 } | 94 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 122 if (!ParseData(path, ++next_id, callback)) { | 125 if (!ParseData(path, ++next_id, callback)) { |
| 123 // If the request data cannot be parsed, request parameters will not be | 126 // If the request data cannot be parsed, request parameters will not be |
| 124 // added to |request_map_|. | 127 // added to |request_map_|. |
| 125 // Send back the default application icon (not resized or desaturated) as | 128 // Send back the default application icon (not resized or desaturated) as |
| 126 // the default response. | 129 // the default response. |
| 127 callback.Run(BitmapToMemory(GetDefaultAppImage())); | 130 callback.Run(BitmapToMemory(GetDefaultAppImage())); |
| 128 return; | 131 return; |
| 129 } | 132 } |
| 130 | 133 |
| 131 ExtensionIconRequest* request = GetData(next_id); | 134 ExtensionIconRequest* request = GetData(next_id); |
| 132 ExtensionResource icon = | 135 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 133 request->extension->GetIconResource(request->size, request->match); | 136 request->extension, request->size, request->match); |
| 134 | 137 |
| 135 if (icon.relative_path().empty()) { | 138 if (icon.relative_path().empty()) { |
| 136 LoadIconFailed(next_id); | 139 LoadIconFailed(next_id); |
| 137 } else { | 140 } else { |
| 138 LoadExtensionImage(icon, next_id); | 141 LoadExtensionImage(icon, next_id); |
| 139 } | 142 } |
| 140 } | 143 } |
| 141 | 144 |
| 142 ExtensionIconSource::~ExtensionIconSource() { | 145 ExtensionIconSource::~ExtensionIconSource() { |
| 143 // Clean up all the temporary data we're holding for requests. | 146 // Clean up all the temporary data we're holding for requests. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 void ExtensionIconSource::OnImageLoaded(int request_id, | 251 void ExtensionIconSource::OnImageLoaded(int request_id, |
| 249 const gfx::Image& image) { | 252 const gfx::Image& image) { |
| 250 if (image.IsEmpty()) | 253 if (image.IsEmpty()) |
| 251 LoadIconFailed(request_id); | 254 LoadIconFailed(request_id); |
| 252 else | 255 else |
| 253 FinalizeImage(image.ToSkBitmap(), request_id); | 256 FinalizeImage(image.ToSkBitmap(), request_id); |
| 254 } | 257 } |
| 255 | 258 |
| 256 void ExtensionIconSource::LoadIconFailed(int request_id) { | 259 void ExtensionIconSource::LoadIconFailed(int request_id) { |
| 257 ExtensionIconRequest* request = GetData(request_id); | 260 ExtensionIconRequest* request = GetData(request_id); |
| 258 ExtensionResource icon = | 261 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 259 request->extension->GetIconResource(request->size, request->match); | 262 request->extension, request->size, request->match); |
| 260 | 263 |
| 261 if (request->size == extension_misc::EXTENSION_ICON_BITTY) | 264 if (request->size == extension_misc::EXTENSION_ICON_BITTY) |
| 262 LoadFaviconImage(request_id); | 265 LoadFaviconImage(request_id); |
| 263 else | 266 else |
| 264 LoadDefaultImage(request_id); | 267 LoadDefaultImage(request_id); |
| 265 } | 268 } |
| 266 | 269 |
| 267 bool ExtensionIconSource::ParseData( | 270 bool ExtensionIconSource::ParseData( |
| 268 const std::string& path, | 271 const std::string& path, |
| 269 int request_id, | 272 int request_id, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 336 |
| 334 void ExtensionIconSource::ClearData(int request_id) { | 337 void ExtensionIconSource::ClearData(int request_id) { |
| 335 std::map<int, ExtensionIconRequest*>::iterator i = | 338 std::map<int, ExtensionIconRequest*>::iterator i = |
| 336 request_map_.find(request_id); | 339 request_map_.find(request_id); |
| 337 if (i == request_map_.end()) | 340 if (i == request_map_.end()) |
| 338 return; | 341 return; |
| 339 | 342 |
| 340 delete i->second; | 343 delete i->second; |
| 341 request_map_.erase(i); | 344 request_map_.erase(i); |
| 342 } | 345 } |
| OLD | NEW |