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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/extensions/image_utils.h" |
14 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 15 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
19 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
20 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "grit/component_extension_resources_map.h" | |
24 #include "grit/theme_resources.h" | |
25 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
29 #include "ui/gfx/image/image_skia_rep.h" | 28 #include "ui/gfx/image/image_skia_rep.h" |
30 #include "webkit/glue/image_decoder.h" | 29 #include "webkit/glue/image_decoder.h" |
31 | 30 |
32 using content::BrowserThread; | 31 using content::BrowserThread; |
33 using extensions::Extension; | 32 using extensions::Extension; |
34 | 33 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false); | 300 OnBitmapLoaded(&bitmap, *it, it->desired_size, id, false); |
302 continue; | 301 continue; |
303 } | 302 } |
304 | 303 |
305 // Instruct the ImageLoader to load this on the File thread. LoadImage and | 304 // Instruct the ImageLoader to load this on the File thread. LoadImage and |
306 // LoadResource do not block. | 305 // LoadResource do not block. |
307 if (!loader_) | 306 if (!loader_) |
308 loader_ = new ImageLoader(this); | 307 loader_ = new ImageLoader(this); |
309 | 308 |
310 int resource_id = -1; | 309 int resource_id = -1; |
311 if (IsComponentExtensionResource(extension, it->resource.relative_path(), | 310 if (extension_image_utils::IsComponentExtensionResource( |
312 &resource_id)) | 311 extension, it->resource.relative_path(), &resource_id)) |
313 loader_->LoadResource(*it, id, resource_id); | 312 loader_->LoadResource(*it, id, resource_id); |
314 else | 313 else |
315 loader_->LoadImage(*it, id); | 314 loader_->LoadImage(*it, id); |
316 } | 315 } |
317 } | 316 } |
318 | 317 |
319 bool ImageLoadingTracker::IsComponentExtensionResource( | |
320 const Extension* extension, | |
321 const FilePath& resource_path, | |
322 int* resource_id) { | |
323 static const GritResourceMap kExtraComponentExtensionResources[] = { | |
324 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON}, | |
325 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16}, | |
326 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128}, | |
327 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16}, | |
328 }; | |
329 static const size_t kExtraComponentExtensionResourcesSize = | |
330 arraysize(kExtraComponentExtensionResources); | |
331 | |
332 if (extension->location() != Extension::COMPONENT) | |
333 return false; | |
334 | |
335 FilePath directory_path = extension->path(); | |
336 FilePath resources_dir; | |
337 FilePath relative_path; | |
338 if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || | |
339 !resources_dir.AppendRelativePath(directory_path, &relative_path)) { | |
340 return false; | |
341 } | |
342 relative_path = relative_path.Append(resource_path); | |
343 relative_path = relative_path.NormalizePathSeparators(); | |
344 | |
345 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to | |
346 // covert to FilePaths all the time. This will be more useful as we add | |
347 // more resources. | |
348 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { | |
349 FilePath resource_path = | |
350 FilePath().AppendASCII(kComponentExtensionResources[i].name); | |
351 resource_path = resource_path.NormalizePathSeparators(); | |
352 | |
353 if (relative_path == resource_path) { | |
354 *resource_id = kComponentExtensionResources[i].value; | |
355 return true; | |
356 } | |
357 } | |
358 for (size_t i = 0; i < kExtraComponentExtensionResourcesSize; ++i) { | |
359 FilePath resource_path = | |
360 FilePath().AppendASCII(kExtraComponentExtensionResources[i].name); | |
361 resource_path = resource_path.NormalizePathSeparators(); | |
362 | |
363 if (relative_path == resource_path) { | |
364 *resource_id = kExtraComponentExtensionResources[i].value; | |
365 return true; | |
366 } | |
367 } | |
368 return false; | |
369 } | |
370 | |
371 void ImageLoadingTracker::OnBitmapLoaded( | 318 void ImageLoadingTracker::OnBitmapLoaded( |
372 const SkBitmap* bitmap, | 319 const SkBitmap* bitmap, |
373 const ImageRepresentation& image_info, | 320 const ImageRepresentation& image_info, |
374 const gfx::Size& original_size, | 321 const gfx::Size& original_size, |
375 int id, | 322 int id, |
376 bool should_cache) { | 323 bool should_cache) { |
377 LoadMap::iterator load_map_it = load_map_.find(id); | 324 LoadMap::iterator load_map_it = load_map_.find(id); |
378 DCHECK(load_map_it != load_map_.end()); | 325 DCHECK(load_map_it != load_map_.end()); |
379 PendingLoadInfo* info = &load_map_it->second; | 326 PendingLoadInfo* info = &load_map_it->second; |
380 | 327 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // Remove reference to this extension from all pending load entries. This | 371 // Remove reference to this extension from all pending load entries. This |
425 // ensures we don't attempt to cache the bitmap when the load completes. | 372 // ensures we don't attempt to cache the bitmap when the load completes. |
426 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { | 373 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { |
427 PendingLoadInfo* info = &i->second; | 374 PendingLoadInfo* info = &i->second; |
428 if (info->extension == extension) { | 375 if (info->extension == extension) { |
429 info->extension = NULL; | 376 info->extension = NULL; |
430 info->cache = DONT_CACHE; | 377 info->cache = DONT_CACHE; |
431 } | 378 } |
432 } | 379 } |
433 } | 380 } |
OLD | NEW |