Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Unified Diff: chrome/browser/extensions/image_loading_tracker.cc

Issue 9979001: Attempt to load component extension favicon from the resources first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/image_loading_tracker.cc
===================================================================
--- chrome/browser/extensions/image_loading_tracker.cc (revision 131549)
+++ chrome/browser/extensions/image_loading_tracker.cc (working copy)
@@ -6,11 +6,15 @@
#include "base/bind.h"
#include "base/file_util.h"
+#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_resource.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
+#include "grit/component_extension_resources_map.h"
+#include "grit/theme_resources.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
@@ -114,6 +118,28 @@
ReportBack(decoded.release(), resource, original_size, id);
}
+ // Instructs the loader to load a resource on the File thread.
+ void LoadResource(const ExtensionResource& resource,
+ const gfx::Size& max_size,
+ int id,
+ int resource_id) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&ImageLoader::LoadResourceOnFileThread, this, resource,
+ max_size, id, resource_id));
+ }
+
+ void LoadResourceOnFileThread(const ExtensionResource& resource,
+ const gfx::Size& max_size,
+ int id,
+ int resource_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ SkBitmap* image = ExtensionIconSource::LoadImageByResourceId(
+ resource_id);
+ ReportBack(image, resource, max_size, id);
+ }
+
void ReportBack(SkBitmap* image, const ExtensionResource& resource,
const gfx::Size& original_size, int id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -200,14 +226,50 @@
continue;
}
- // Instruct the ImageLoader to load this on the File thread. LoadImage does
- // not block.
+ // Instruct the ImageLoader to load this on the File thread. LoadImage and
+ // LoadResource do not block.
if (!loader_)
loader_ = new ImageLoader(this);
- loader_->LoadImage(it->resource, it->max_size, id);
+
+ // Load resources for WebStore component extension.
+ if (load_info.extension_id == extension_misc::kWebStoreAppId) {
+ loader_->LoadResource(it->resource, it->max_size, id, IDR_WEBSTORE_ICON);
+ continue;
+ }
+
+ int resource_id;
+ if (IsComponentExtensionResource(extension, it->resource, resource_id)) {
+ loader_->LoadResource(it->resource, it->max_size, id, resource_id);
+ } else {
+ loader_->LoadImage(it->resource, it->max_size, id);
+ }
Finnur 2012/04/11 10:03:09 nit: No braces (single line if&else clauses).
dgozman 2012/04/11 14:48:13 Done.
}
}
+bool ImageLoadingTracker::IsComponentExtensionResource(
+ const Extension* extension,
+ const ExtensionResource& resource,
+ int& resource_id) {
+ if (extension->location() != Extension::COMPONENT)
+ return false;
+
+ FilePath directory_path = extension->path();
+ FilePath relative_path = directory_path.BaseName().Append(
+ resource.relative_path());
+
+ for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
+ FilePath resource_path =
+ FilePath().AppendASCII(kComponentExtensionResources[i].name);
+ resource_path = resource_path.NormalizePathSeparators();
+
+ if (relative_path == resource_path) {
+ resource_id = kComponentExtensionResources[i].value;
+ return true;
+ }
+ }
+ return false;
+}
+
void ImageLoadingTracker::OnImageLoaded(
SkBitmap* image,
const ExtensionResource& resource,

Powered by Google App Engine
This is Rietveld 408576698