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" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 struct ExtensionIconSource::ExtensionIconRequest { | 61 struct ExtensionIconSource::ExtensionIconRequest { |
62 int request_id; | 62 int request_id; |
63 const Extension* extension; | 63 const Extension* extension; |
64 bool grayscale; | 64 bool grayscale; |
65 int size; | 65 int size; |
66 ExtensionIconSet::MatchType match; | 66 ExtensionIconSet::MatchType match; |
67 }; | 67 }; |
68 | 68 |
69 ExtensionIconSource::~ExtensionIconSource() { | |
70 // Clean up all the temporary data we're holding for requests. | |
71 STLDeleteValues(&request_map_); | |
72 } | |
73 | |
74 // static | 69 // static |
75 GURL ExtensionIconSource::GetIconURL(const Extension* extension, | 70 GURL ExtensionIconSource::GetIconURL(const Extension* extension, |
76 int icon_size, | 71 int icon_size, |
77 ExtensionIconSet::MatchType match, | 72 ExtensionIconSet::MatchType match, |
78 bool grayscale, | 73 bool grayscale, |
79 bool* exists) { | 74 bool* exists) { |
80 if (exists) | 75 if (exists) |
81 *exists = true; | 76 *exists = true; |
82 if (exists && extension->GetIconURL(icon_size, match) == GURL()) | 77 if (exists && extension->GetIconURL(icon_size, match) == GURL()) |
83 *exists = false; | 78 *exists = false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ExtensionResource icon = | 118 ExtensionResource icon = |
124 request->extension->GetIconResource(request->size, request->match); | 119 request->extension->GetIconResource(request->size, request->match); |
125 | 120 |
126 if (icon.relative_path().empty()) { | 121 if (icon.relative_path().empty()) { |
127 LoadIconFailed(request_id); | 122 LoadIconFailed(request_id); |
128 } else { | 123 } else { |
129 LoadExtensionImage(icon, request_id); | 124 LoadExtensionImage(icon, request_id); |
130 } | 125 } |
131 } | 126 } |
132 | 127 |
133 void ExtensionIconSource::LoadIconFailed(int request_id) { | 128 ExtensionIconSource::~ExtensionIconSource() { |
134 ExtensionIconRequest* request = GetData(request_id); | 129 // Clean up all the temporary data we're holding for requests. |
135 ExtensionResource icon = | 130 STLDeleteValues(&request_map_); |
136 request->extension->GetIconResource(request->size, request->match); | |
137 | |
138 if (request->size == ExtensionIconSet::EXTENSION_ICON_BITTY) | |
139 LoadFaviconImage(request_id); | |
140 else | |
141 LoadDefaultImage(request_id); | |
142 } | 131 } |
143 | 132 |
144 const SkBitmap* ExtensionIconSource::GetWebStoreImage() { | 133 const SkBitmap* ExtensionIconSource::GetWebStoreImage() { |
145 if (!web_store_icon_data_.get()) | 134 if (!web_store_icon_data_.get()) |
146 web_store_icon_data_.reset(LoadImageByResourceId(IDR_WEBSTORE_ICON)); | 135 web_store_icon_data_.reset(LoadImageByResourceId(IDR_WEBSTORE_ICON)); |
147 | 136 |
148 return web_store_icon_data_.get(); | 137 return web_store_icon_data_.get(); |
149 } | 138 } |
150 | 139 |
151 const SkBitmap* ExtensionIconSource::GetDefaultAppImage() { | 140 const SkBitmap* ExtensionIconSource::GetDefaultAppImage() { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 int index) { | 247 int index) { |
259 int request_id = tracker_map_[index]; | 248 int request_id = tracker_map_[index]; |
260 tracker_map_.erase(tracker_map_.find(index)); | 249 tracker_map_.erase(tracker_map_.find(index)); |
261 | 250 |
262 if (image.IsEmpty()) | 251 if (image.IsEmpty()) |
263 LoadIconFailed(request_id); | 252 LoadIconFailed(request_id); |
264 else | 253 else |
265 FinalizeImage(image.ToSkBitmap(), request_id); | 254 FinalizeImage(image.ToSkBitmap(), request_id); |
266 } | 255 } |
267 | 256 |
| 257 void ExtensionIconSource::LoadIconFailed(int request_id) { |
| 258 ExtensionIconRequest* request = GetData(request_id); |
| 259 ExtensionResource icon = |
| 260 request->extension->GetIconResource(request->size, request->match); |
| 261 |
| 262 if (request->size == ExtensionIconSet::EXTENSION_ICON_BITTY) |
| 263 LoadFaviconImage(request_id); |
| 264 else |
| 265 LoadDefaultImage(request_id); |
| 266 } |
| 267 |
268 bool ExtensionIconSource::ParseData(const std::string& path, | 268 bool ExtensionIconSource::ParseData(const std::string& path, |
269 int request_id) { | 269 int request_id) { |
270 // Extract the parameters from the path by lower casing and splitting. | 270 // Extract the parameters from the path by lower casing and splitting. |
271 std::string path_lower = StringToLowerASCII(path); | 271 std::string path_lower = StringToLowerASCII(path); |
272 std::vector<std::string> path_parts; | 272 std::vector<std::string> path_parts; |
273 | 273 |
274 base::SplitString(path_lower, '/', &path_parts); | 274 base::SplitString(path_lower, '/', &path_parts); |
275 if (path_lower.empty() || path_parts.size() < 3) | 275 if (path_lower.empty() || path_parts.size() < 3) |
276 return false; | 276 return false; |
277 | 277 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 336 |
337 void ExtensionIconSource::ClearData(int request_id) { | 337 void ExtensionIconSource::ClearData(int request_id) { |
338 std::map<int, ExtensionIconRequest*>::iterator i = | 338 std::map<int, ExtensionIconRequest*>::iterator i = |
339 request_map_.find(request_id); | 339 request_map_.find(request_id); |
340 if (i == request_map_.end()) | 340 if (i == request_map_.end()) |
341 return; | 341 return; |
342 | 342 |
343 delete i->second; | 343 delete i->second; |
344 request_map_.erase(i); | 344 request_map_.erase(i); |
345 } | 345 } |
OLD | NEW |