| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 // static | 74 // static |
| 74 GURL ExtensionIconSource::GetIconURL(const extensions::Extension* extension, | 75 GURL ExtensionIconSource::GetIconURL(const extensions::Extension* extension, |
| 75 int icon_size, | 76 int icon_size, |
| 76 ExtensionIconSet::MatchType match, | 77 ExtensionIconSet::MatchType match, |
| 77 bool grayscale, | 78 bool grayscale, |
| 78 bool* exists) { | 79 bool* exists) { |
| 79 if (exists) | 80 if (exists) |
| 80 *exists = true; | 81 *exists = true; |
| 81 if (exists && extension->GetIconURL(icon_size, match) == GURL()) | 82 if (exists && extensions::IconsInfo::GetIconURL( |
| 83 extension, icon_size, match) == GURL()) { |
| 82 *exists = false; | 84 *exists = false; |
| 85 } |
| 83 | 86 |
| 84 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", | 87 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", |
| 85 chrome::kChromeUIExtensionIconURL, | 88 chrome::kChromeUIExtensionIconURL, |
| 86 extension->id().c_str(), | 89 extension->id().c_str(), |
| 87 icon_size, | 90 icon_size, |
| 88 match, | 91 match, |
| 89 grayscale ? "?grayscale=true" : "")); | 92 grayscale ? "?grayscale=true" : "")); |
| 90 CHECK(icon_url.is_valid()); | 93 CHECK(icon_url.is_valid()); |
| 91 return icon_url; | 94 return icon_url; |
| 92 } | 95 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 bool is_incognito, | 116 bool is_incognito, |
| 114 int request_id) { | 117 int request_id) { |
| 115 // This is where everything gets started. First, parse the request and make | 118 // This is where everything gets started. First, parse the request and make |
| 116 // the request data available for later. | 119 // the request data available for later. |
| 117 if (!ParseData(path, request_id)) { | 120 if (!ParseData(path, request_id)) { |
| 118 SendDefaultResponse(request_id); | 121 SendDefaultResponse(request_id); |
| 119 return; | 122 return; |
| 120 } | 123 } |
| 121 | 124 |
| 122 ExtensionIconRequest* request = GetData(request_id); | 125 ExtensionIconRequest* request = GetData(request_id); |
| 123 ExtensionResource icon = | 126 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 124 request->extension->GetIconResource(request->size, request->match); | 127 request->extension, request->size, request->match); |
| 125 | 128 |
| 126 if (icon.relative_path().empty()) { | 129 if (icon.relative_path().empty()) { |
| 127 LoadIconFailed(request_id); | 130 LoadIconFailed(request_id); |
| 128 } else { | 131 } else { |
| 129 LoadExtensionImage(icon, request_id); | 132 LoadExtensionImage(icon, request_id); |
| 130 } | 133 } |
| 131 } | 134 } |
| 132 | 135 |
| 133 ExtensionIconSource::~ExtensionIconSource() { | 136 ExtensionIconSource::~ExtensionIconSource() { |
| 134 // Clean up all the temporary data we're holding for requests. | 137 // Clean up all the temporary data we're holding for requests. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void ExtensionIconSource::OnImageLoaded(int request_id, | 241 void ExtensionIconSource::OnImageLoaded(int request_id, |
| 239 const gfx::Image& image) { | 242 const gfx::Image& image) { |
| 240 if (image.IsEmpty()) | 243 if (image.IsEmpty()) |
| 241 LoadIconFailed(request_id); | 244 LoadIconFailed(request_id); |
| 242 else | 245 else |
| 243 FinalizeImage(image.ToSkBitmap(), request_id); | 246 FinalizeImage(image.ToSkBitmap(), request_id); |
| 244 } | 247 } |
| 245 | 248 |
| 246 void ExtensionIconSource::LoadIconFailed(int request_id) { | 249 void ExtensionIconSource::LoadIconFailed(int request_id) { |
| 247 ExtensionIconRequest* request = GetData(request_id); | 250 ExtensionIconRequest* request = GetData(request_id); |
| 248 ExtensionResource icon = | 251 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 249 request->extension->GetIconResource(request->size, request->match); | 252 request->extension, request->size, request->match); |
| 250 | 253 |
| 251 if (request->size == extension_misc::EXTENSION_ICON_BITTY) | 254 if (request->size == extension_misc::EXTENSION_ICON_BITTY) |
| 252 LoadFaviconImage(request_id); | 255 LoadFaviconImage(request_id); |
| 253 else | 256 else |
| 254 LoadDefaultImage(request_id); | 257 LoadDefaultImage(request_id); |
| 255 } | 258 } |
| 256 | 259 |
| 257 bool ExtensionIconSource::ParseData(const std::string& path, | 260 bool ExtensionIconSource::ParseData(const std::string& path, |
| 258 int request_id) { | 261 int request_id) { |
| 259 // Extract the parameters from the path by lower casing and splitting. | 262 // Extract the parameters from the path by lower casing and splitting. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 329 |
| 327 void ExtensionIconSource::ClearData(int request_id) { | 330 void ExtensionIconSource::ClearData(int request_id) { |
| 328 std::map<int, ExtensionIconRequest*>::iterator i = | 331 std::map<int, ExtensionIconRequest*>::iterator i = |
| 329 request_map_.find(request_id); | 332 request_map_.find(request_id); |
| 330 if (i == request_map_.end()) | 333 if (i == request_map_.end()) |
| 331 return; | 334 return; |
| 332 | 335 |
| 333 delete i->second; | 336 delete i->second; |
| 334 request_map_.erase(i); | 337 request_map_.erase(i); |
| 335 } | 338 } |
| OLD | NEW |