| Index: chrome/browser/extensions/image_loading_tracker.cc
|
| diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc
|
| index f7cd334af31ab0fd49f74685dfb89c07e4f344ba..b522758e4da9edd283f67a33a0740279a3acb372 100644
|
| --- a/chrome/browser/extensions/image_loading_tracker.cc
|
| +++ b/chrome/browser/extensions/image_loading_tracker.cc
|
| @@ -14,6 +14,7 @@
|
| #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_file_util.h"
|
| #include "chrome/common/extensions/extension_resource.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/notification_service.h"
|
| @@ -31,30 +32,6 @@ using extensions::Extension;
|
|
|
| namespace {
|
|
|
| -struct ComponentExtensionResource {
|
| - const char* extension_id;
|
| - const int resource_id;
|
| -};
|
| -
|
| -const ComponentExtensionResource kSpecialComponentExtensionResources[] = {
|
| - { extension_misc::kWebStoreAppId, IDR_WEBSTORE_ICON },
|
| - { extension_misc::kChromeAppId, IDR_PRODUCT_LOGO_128 },
|
| -};
|
| -
|
| -// Finds special component extension resource id for given extension id.
|
| -bool FindSpecialExtensionResourceId(const std::string& extension_id,
|
| - int* out_resource_id) {
|
| - for (size_t i = 0; i < arraysize(kSpecialComponentExtensionResources); ++i) {
|
| - if (extension_id == kSpecialComponentExtensionResources[i].extension_id) {
|
| - if (out_resource_id)
|
| - *out_resource_id = kSpecialComponentExtensionResources[i].resource_id;
|
| - return true;
|
| - }
|
| - }
|
| -
|
| - return false;
|
| -}
|
| -
|
| bool ShouldResizeImageRepresentation(
|
| ImageLoadingTracker::ImageRepresentation::ResizeCondition resize_method,
|
| const gfx::Size& decoded_size,
|
| @@ -247,13 +224,6 @@ class ImageLoadingTracker::ImageLoader
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ImageLoadingTracker
|
|
|
| -// static
|
| -bool ImageLoadingTracker::IsSpecialBundledExtensionId(
|
| - const std::string& extension_id) {
|
| - int resource_id = -1;
|
| - return FindSpecialExtensionResourceId(extension_id, &resource_id);
|
| -}
|
| -
|
| ImageLoadingTracker::ImageLoadingTracker(Observer* observer)
|
| : observer_(observer),
|
| next_id_(0) {
|
| @@ -295,16 +265,6 @@ void ImageLoadingTracker::LoadImages(
|
|
|
| for (std::vector<ImageRepresentation>::const_iterator it = info_list.begin();
|
| it != info_list.end(); ++it) {
|
| - int resource_id = -1;
|
| -
|
| - // Load resources for special component extensions.
|
| - if (FindSpecialExtensionResourceId(load_info.extension_id, &resource_id)) {
|
| - if (!loader_)
|
| - loader_ = new ImageLoader(this);
|
| - loader_->LoadResource(*it, id, resource_id);
|
| - continue;
|
| - }
|
| -
|
| // If we don't have a path we don't need to do any further work, just
|
| // respond back.
|
| if (it->resource.relative_path().empty()) {
|
| @@ -327,7 +287,9 @@ void ImageLoadingTracker::LoadImages(
|
| if (!loader_)
|
| loader_ = new ImageLoader(this);
|
|
|
| - if (IsComponentExtensionResource(extension, it->resource, resource_id))
|
| + int resource_id = -1;
|
| + if (IsComponentExtensionResource(extension, it->resource.relative_path(),
|
| + &resource_id))
|
| loader_->LoadResource(*it, id, resource_id);
|
| else
|
| loader_->LoadImage(*it, id);
|
| @@ -336,22 +298,44 @@ void ImageLoadingTracker::LoadImages(
|
|
|
| bool ImageLoadingTracker::IsComponentExtensionResource(
|
| const Extension* extension,
|
| - const ExtensionResource& resource,
|
| - int& resource_id) const {
|
| + const FilePath& resource_path,
|
| + int* resource_id) {
|
| + static const GritResourceMap kExtraComponentExtensionResources[] = {
|
| + {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON},
|
| + {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16},
|
| + {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128},
|
| + {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16},
|
| + };
|
| + static const size_t kExtraComponentExtensionResourcesSize =
|
| + arraysize(kExtraComponentExtensionResources);
|
| +
|
| if (extension->location() != Extension::COMPONENT)
|
| return false;
|
|
|
| FilePath directory_path = extension->path();
|
| - FilePath relative_path = directory_path.BaseName().Append(
|
| - resource.relative_path());
|
| + FilePath relative_path = directory_path.BaseName().Append(resource_path);
|
| + relative_path = relative_path.NormalizePathSeparators();
|
|
|
| + // TODO(tc): Make a map of FilePath -> resource ids so we don't have to
|
| + // covert to FilePaths all the time. This will be more useful as we add
|
| + // more resources.
|
| 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;
|
| + *resource_id = kComponentExtensionResources[i].value;
|
| + return true;
|
| + }
|
| + }
|
| + for (size_t i = 0; i < kExtraComponentExtensionResourcesSize; ++i) {
|
| + FilePath resource_path =
|
| + FilePath().AppendASCII(kExtraComponentExtensionResources[i].name);
|
| + resource_path = resource_path.NormalizePathSeparators();
|
| +
|
| + if (relative_path == resource_path) {
|
| + *resource_id = kExtraComponentExtensionResources[i].value;
|
| return true;
|
| }
|
| }
|
|
|