Commit 764a6e3d authored by ananta's avatar ananta Committed by Commit bot

Ensure that the extension icons show up in the omnibox at fractional scales.

Proposed fix is to discard all unsupported representations (Read fractional scales) in the Extension icon image when
the icon is loaded. This ensures that stale caches are invalidated and the correct icons are loaded when the cache is regenerated.

BUG=461958

Review URL: https://codereview.chromium.org/1025513004

Cr-Commit-Position: refs/heads/master@{#322225}
parent a836d402
......@@ -11,6 +11,7 @@
#include "extensions/browser/image_loader.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"
#include "ui/base/layout.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
......@@ -223,7 +224,21 @@ void IconImage::OnImageLoaded(float scale, const gfx::Image& image_in) {
DCHECK(!rep.is_null());
DCHECK_EQ(scale, rep.scale());
// Remove old representation if there is one.
// Remove fractional scale image representations as they may have become
// stale here. These images are generated by ImageSkia on request from
// supported scales like 1x, 2x, etc.
// TODO(oshima)
// A better approach might be to set the |image_| member using the ImageSkia
// copy from the image passed in and set the |image_skia_| member using
// image_.ToImageSkia(). However that does not work correctly as the
// ImageSkia from the image does not contain a source which breaks requests
// for scaled images.
std::vector<gfx::ImageSkiaRep> reps = image_skia_.image_reps();
for (const auto rep : reps) {
if (!ui::IsSupportedScale(rep.scale()))
image_skia_.RemoveRepresentation(rep.scale());
}
image_skia_.RemoveRepresentation(scale);
image_skia_.AddRepresentation(rep);
......
......@@ -92,6 +92,14 @@ float GetScaleForScaleFactor(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor];
}
bool IsSupportedScale(float scale) {
for (auto scale_factor_idx : *g_supported_scale_factors) {
if (kScaleFactorScales[scale_factor_idx] == scale)
return true;
}
return false;
}
namespace test {
ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors(
......
......@@ -54,6 +54,10 @@ UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view);
// Returns the image scale for the scale factor passed in.
UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor);
// Returns true if the scale passed in is the list of supported scales for
// the platform.
UI_BASE_EXPORT bool IsSupportedScale(float scale);
namespace test {
// Class which changes the value of GetSupportedScaleFactors() to
// |new_scale_factors| for the duration of its lifetime.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment