| 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_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 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 26 matching lines...) Expand all Loading... |
| 118 const content::URLDataSource::GotDataCallback& callback) { | 121 const content::URLDataSource::GotDataCallback& callback) { |
| 119 // This is where everything gets started. First, parse the request and make | 122 // This is where everything gets started. First, parse the request and make |
| 120 // the request data available for later. | 123 // the request data available for later. |
| 121 static int next_id = 0; | 124 static int next_id = 0; |
| 122 if (!ParseData(path, ++next_id, callback)) { | 125 if (!ParseData(path, ++next_id, callback)) { |
| 123 SendDefaultResponse(next_id); | 126 SendDefaultResponse(next_id); |
| 124 return; | 127 return; |
| 125 } | 128 } |
| 126 | 129 |
| 127 ExtensionIconRequest* request = GetData(next_id); | 130 ExtensionIconRequest* request = GetData(next_id); |
| 128 ExtensionResource icon = | 131 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 129 request->extension->GetIconResource(request->size, request->match); | 132 request->extension, request->size, request->match); |
| 130 | 133 |
| 131 if (icon.relative_path().empty()) { | 134 if (icon.relative_path().empty()) { |
| 132 LoadIconFailed(next_id); | 135 LoadIconFailed(next_id); |
| 133 } else { | 136 } else { |
| 134 LoadExtensionImage(icon, next_id); | 137 LoadExtensionImage(icon, next_id); |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 | 140 |
| 138 ExtensionIconSource::~ExtensionIconSource() { | 141 ExtensionIconSource::~ExtensionIconSource() { |
| 139 // Clean up all the temporary data we're holding for requests. | 142 // Clean up all the temporary data we're holding for requests. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 void ExtensionIconSource::OnImageLoaded(int request_id, | 247 void ExtensionIconSource::OnImageLoaded(int request_id, |
| 245 const gfx::Image& image) { | 248 const gfx::Image& image) { |
| 246 if (image.IsEmpty()) | 249 if (image.IsEmpty()) |
| 247 LoadIconFailed(request_id); | 250 LoadIconFailed(request_id); |
| 248 else | 251 else |
| 249 FinalizeImage(image.ToSkBitmap(), request_id); | 252 FinalizeImage(image.ToSkBitmap(), request_id); |
| 250 } | 253 } |
| 251 | 254 |
| 252 void ExtensionIconSource::LoadIconFailed(int request_id) { | 255 void ExtensionIconSource::LoadIconFailed(int request_id) { |
| 253 ExtensionIconRequest* request = GetData(request_id); | 256 ExtensionIconRequest* request = GetData(request_id); |
| 254 ExtensionResource icon = | 257 ExtensionResource icon = extensions::IconsInfo::GetIconResource( |
| 255 request->extension->GetIconResource(request->size, request->match); | 258 request->extension, request->size, request->match); |
| 256 | 259 |
| 257 if (request->size == extension_misc::EXTENSION_ICON_BITTY) | 260 if (request->size == extension_misc::EXTENSION_ICON_BITTY) |
| 258 LoadFaviconImage(request_id); | 261 LoadFaviconImage(request_id); |
| 259 else | 262 else |
| 260 LoadDefaultImage(request_id); | 263 LoadDefaultImage(request_id); |
| 261 } | 264 } |
| 262 | 265 |
| 263 bool ExtensionIconSource::ParseData( | 266 bool ExtensionIconSource::ParseData( |
| 264 const std::string& path, | 267 const std::string& path, |
| 265 int request_id, | 268 int request_id, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 340 |
| 338 void ExtensionIconSource::ClearData(int request_id) { | 341 void ExtensionIconSource::ClearData(int request_id) { |
| 339 std::map<int, ExtensionIconRequest*>::iterator i = | 342 std::map<int, ExtensionIconRequest*>::iterator i = |
| 340 request_map_.find(request_id); | 343 request_map_.find(request_id); |
| 341 if (i == request_map_.end()) | 344 if (i == request_map_.end()) |
| 342 return; | 345 return; |
| 343 | 346 |
| 344 delete i->second; | 347 delete i->second; |
| 345 request_map_.erase(i); | 348 request_map_.erase(i); |
| 346 } | 349 } |
| OLD | NEW |