Commit 9e7f34f7 authored by Kelvin Jiang's avatar Kelvin Jiang Committed by Commit Bot

[Extensions] Fix bug where placeholder extension icon is an unknown symbol (RTL)

The placeholder icon for an extension is the first letter of the extension's
name on a grey background. extension->name() (which we currently use) is padded
with formatting characters if RTL mode is enabled, and grabbing the first
character in that case does not get us the extension's actual name.

Fix is implemented by reversing the RTL adjustment of the extension's name
before getting the first letter.

Bug: 869358
Change-Id: I986c2aade64e981ce634f5d14befd21df759d9cd

TEST: This behavior is difficult to automatically test. To test manually:
1) Load an extension without an icon set in the manifest and note the
   appearance of the placeholder icon.

2) Navigate to chrome://flags and toggle "force ui direction" to RTL
   (search for rtl to find this flag), then click to relaunch when prompted.

3) The extension placeholder icon's appearance should not change and should show
   the first letter of the extension's name as defined in the manifest.

Change-Id: I986c2aade64e981ce634f5d14befd21df759d9cd
Reviewed-on: https://chromium-review.googlesource.com/c/1302633Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Kelvin Jiang <kelvinjiang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604653}
parent 0bc461bf
......@@ -4,6 +4,7 @@
#include "extensions/browser/extension_icon_placeholder.h"
#include "base/i18n/rtl.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "extensions/grit/extensions_browser_resources.h"
......@@ -68,11 +69,16 @@ gfx::Image GetBackgroundImageForIconSize(extension_misc::ExtensionIcons size) {
ExtensionIconPlaceholder::ExtensionIconPlaceholder(
extension_misc::ExtensionIcons size,
const std::string& letter)
const std::string& name)
: gfx::CanvasImageSource(gfx::Size(size, size), false),
icon_size_(size),
letter_(base::UTF8ToUTF16(letter.substr(0, 1))),
base_image_(GetBackgroundImageForIconSize(size)) {
// Remove RTL formatting characters, if any, that may pad the extension name.
// See https://crbug.com/869358
base::string16 sanitized_name = base::UTF8ToUTF16(std::string(name));
base::i18n::UnadjustStringForLocaleDirection(&sanitized_name);
letter_ = sanitized_name.substr(0, 1);
}
ExtensionIconPlaceholder::~ExtensionIconPlaceholder() {
......
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