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/extensions/image_loading_tracker.h" | 5 #include "chrome/browser/extensions/image_loading_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
9 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_resource.h" | 12 #include "chrome/common/extensions/extension_resource.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "grit/component_extension_resources_map.h" |
14 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
17 #include "webkit/glue/image_decoder.h" | 19 #include "webkit/glue/image_decoder.h" |
18 | 20 |
19 using content::BrowserThread; | 21 using content::BrowserThread; |
20 | 22 |
21 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
22 // ImageLoadingTracker::Observer | 24 // ImageLoadingTracker::Observer |
23 | 25 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 186 |
185 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); | 187 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); |
186 it != info_list.end(); ++it) { | 188 it != info_list.end(); ++it) { |
187 // If we don't have a path we don't need to do any further work, just | 189 // If we don't have a path we don't need to do any further work, just |
188 // respond back. | 190 // respond back. |
189 if (it->resource.relative_path().empty()) { | 191 if (it->resource.relative_path().empty()) { |
190 OnImageLoaded(NULL, it->resource, it->max_size, id, false); | 192 OnImageLoaded(NULL, it->resource, it->max_size, id, false); |
191 continue; | 193 continue; |
192 } | 194 } |
193 | 195 |
| 196 SkBitmap* from_resources = TryLoadingComponentExtensionImage(extension, |
| 197 it->resource); |
| 198 if (from_resources) { |
| 199 OnImageLoaded(from_resources, it->resource, it->max_size, id, false); |
| 200 continue; |
| 201 } |
| 202 |
194 DCHECK(extension->path() == it->resource.extension_root()); | 203 DCHECK(extension->path() == it->resource.extension_root()); |
195 | 204 |
196 // See if the extension has the image already. | 205 // See if the extension has the image already. |
197 if (extension->HasCachedImage(it->resource, it->max_size)) { | 206 if (extension->HasCachedImage(it->resource, it->max_size)) { |
198 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); | 207 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); |
199 OnImageLoaded(&image, it->resource, it->max_size, id, false); | 208 OnImageLoaded(&image, it->resource, it->max_size, id, false); |
200 continue; | 209 continue; |
201 } | 210 } |
202 | 211 |
203 // Instruct the ImageLoader to load this on the File thread. LoadImage does | 212 // Instruct the ImageLoader to load this on the File thread. LoadImage does |
204 // not block. | 213 // not block. |
205 if (!loader_) | 214 if (!loader_) |
206 loader_ = new ImageLoader(this); | 215 loader_ = new ImageLoader(this); |
207 loader_->LoadImage(it->resource, it->max_size, id); | 216 loader_->LoadImage(it->resource, it->max_size, id); |
208 } | 217 } |
209 } | 218 } |
210 | 219 |
| 220 SkBitmap* ImageLoadingTracker::TryLoadingComponentExtensionImage( |
| 221 const Extension* extension, |
| 222 const ExtensionResource& resource) { |
| 223 if (extension->location() != Extension::COMPONENT) |
| 224 return NULL; |
| 225 |
| 226 FilePath directory_path = extension->path(); |
| 227 FilePath relative_path = directory_path.BaseName().Append( |
| 228 resource.relative_path()); |
| 229 |
| 230 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { |
| 231 FilePath bm_resource_path = |
| 232 FilePath().AppendASCII(kComponentExtensionResources[i].name); |
| 233 bm_resource_path = bm_resource_path.NormalizePathSeparators(); |
| 234 |
| 235 if (relative_path == bm_resource_path) { |
| 236 return ExtensionIconSource::LoadImageByResourceId( |
| 237 kComponentExtensionResources[i].value); |
| 238 } |
| 239 } |
| 240 return NULL; |
| 241 } |
| 242 |
211 void ImageLoadingTracker::OnImageLoaded( | 243 void ImageLoadingTracker::OnImageLoaded( |
212 SkBitmap* image, | 244 SkBitmap* image, |
213 const ExtensionResource& resource, | 245 const ExtensionResource& resource, |
214 const gfx::Size& original_size, | 246 const gfx::Size& original_size, |
215 int id, | 247 int id, |
216 bool should_cache) { | 248 bool should_cache) { |
217 LoadMap::iterator load_map_it = load_map_.find(id); | 249 LoadMap::iterator load_map_it = load_map_.find(id); |
218 DCHECK(load_map_it != load_map_.end()); | 250 DCHECK(load_map_it != load_map_.end()); |
219 PendingLoadInfo* info = &load_map_it->second; | 251 PendingLoadInfo* info = &load_map_it->second; |
220 | 252 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // Remove reference to this extension from all pending load entries. This | 298 // Remove reference to this extension from all pending load entries. This |
267 // ensures we don't attempt to cache the image when the load completes. | 299 // ensures we don't attempt to cache the image when the load completes. |
268 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { | 300 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { |
269 PendingLoadInfo* info = &i->second; | 301 PendingLoadInfo* info = &i->second; |
270 if (info->extension == extension) { | 302 if (info->extension == extension) { |
271 info->extension = NULL; | 303 info->extension = NULL; |
272 info->cache = DONT_CACHE; | 304 info->cache = DONT_CACHE; |
273 } | 305 } |
274 } | 306 } |
275 } | 307 } |
OLD | NEW |