summaryrefslogtreecommitdiff
path: root/chromium/ui/base/resource
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/base/resource')
-rw-r--r--chromium/ui/base/resource/data_pack.cc2
-rw-r--r--chromium/ui/base/resource/resource_bundle.cc123
-rw-r--r--chromium/ui/base/resource/resource_bundle.h54
-rw-r--r--chromium/ui/base/resource/resource_bundle_android.cc11
-rw-r--r--chromium/ui/base/resource/resource_bundle_unittest.cc3
-rw-r--r--chromium/ui/base/resource/resource_bundle_win.cc6
-rw-r--r--chromium/ui/base/resource/resource_bundle_win.h7
7 files changed, 92 insertions, 114 deletions
diff --git a/chromium/ui/base/resource/data_pack.cc b/chromium/ui/base/resource/data_pack.cc
index 09513e6aed2..a3f14e9a1ea 100644
--- a/chromium/ui/base/resource/data_pack.cc
+++ b/chromium/ui/base/resource/data_pack.cc
@@ -10,6 +10,7 @@
#include <utility>
#include "base/command_line.h"
+#include "base/containers/contains.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
@@ -17,7 +18,6 @@
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
-#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "base/synchronization/lock.h"
#include "base/sys_byteorder.h"
diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc
index 2b24b4ce2e2..910662d25a4 100644
--- a/chromium/ui/base/resource/resource_bundle.cc
+++ b/chromium/ui/base/resource/resource_bundle.cc
@@ -12,6 +12,7 @@
#include "base/big_endian.h"
#include "base/command_line.h"
+#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
@@ -20,13 +21,13 @@
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
-#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "net/filter/gzip_header.h"
#include "skia/ext/image_operations.h"
#include "third_party/brotli/include/brotli/decode.h"
@@ -54,7 +55,7 @@
#include "ui/base/resource/resource_bundle_android.h"
#endif
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
#include "ui/gfx/platform_font_skia.h"
#endif
@@ -223,33 +224,20 @@ class ResourceBundle::ResourceBundleImageSource : public gfx::ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource);
};
-struct ResourceBundle::FontKey {
- FontKey(const std::string& typeface,
- int in_size_delta,
- gfx::Font::FontStyle in_style,
- gfx::Font::Weight in_weight)
- : typeface(typeface),
- size_delta(in_size_delta),
- style(in_style),
- weight(in_weight) {}
-
- ~FontKey() {}
-
- bool operator==(const FontKey& rhs) const {
- return std::tie(typeface, size_delta, style, weight) ==
- std::tie(rhs.typeface, rhs.size_delta, rhs.style, rhs.weight);
- }
+ResourceBundle::FontDetails::FontDetails(std::string typeface,
+ int size_delta,
+ gfx::Font::Weight weight)
+ : typeface(typeface), size_delta(size_delta), weight(weight) {}
- bool operator<(const FontKey& rhs) const {
- return std::tie(typeface, size_delta, style, weight) <
- std::tie(rhs.typeface, rhs.size_delta, rhs.style, rhs.weight);
- }
+bool ResourceBundle::FontDetails::operator==(const FontDetails& rhs) const {
+ return std::tie(typeface, size_delta, weight) ==
+ std::tie(rhs.typeface, rhs.size_delta, rhs.weight);
+}
- std::string typeface;
- int size_delta;
- gfx::Font::FontStyle style;
- gfx::Font::Weight weight;
-};
+bool ResourceBundle::FontDetails::operator<(const FontDetails& rhs) const {
+ return std::tie(typeface, size_delta, weight) <
+ std::tie(rhs.typeface, rhs.size_delta, rhs.weight);
+}
// static
std::string ResourceBundle::InitSharedInstanceWithLocale(
@@ -384,22 +372,8 @@ base::FilePath ResourceBundle::GetLocaleFilePath(
base::FilePath locale_file_path;
if (base::PathService::Get(ui::DIR_LOCALES, &locale_file_path)) {
-#if defined(OS_ANDROID)
- if (locale_file_path.value().find("chromium_tests") == std::string::npos) {
- std::string extracted_file_suffix =
- base::android::BuildInfo::GetInstance()->extracted_file_suffix();
- locale_file_path = locale_file_path.AppendASCII(
- app_locale + kPakFileExtension + extracted_file_suffix);
- } else {
- // TODO(agrieve): Update tests to not side-load pak files and remove
- // this special-case. https://crbug.com/691719
- locale_file_path =
- locale_file_path.AppendASCII(app_locale + kPakFileExtension);
- }
-#else
locale_file_path =
locale_file_path.AppendASCII(app_locale + kPakFileExtension);
-#endif
}
// Note: The delegate GetPathForLocalePack() override is currently only used
@@ -448,6 +422,7 @@ std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale,
}
locale_resources_data_ = std::move(data_pack);
+ loaded_locale_ = pref_locale;
return app_locale;
}
#endif // defined(OS_ANDROID)
@@ -557,7 +532,7 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
if (image.IsEmpty()) {
DCHECK(!data_packs_.empty()) << "Missing call to SetResourcesDataDLL?";
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
#elif defined(OS_WIN)
ui::ScaleFactor scale_factor_to_load =
@@ -750,74 +725,56 @@ base::RefCountedMemory* ResourceBundle::LoadLocalizedResourceBytes(
return LoadDataResourceBytes(resource_id);
}
-const gfx::FontList& ResourceBundle::GetFontListWithDelta(
- int size_delta,
- gfx::Font::FontStyle style,
- gfx::Font::Weight weight) {
- return GetFontListWithTypefaceAndDelta(/*typeface=*/std::string(), size_delta,
- style, weight);
+const gfx::FontList& ResourceBundle::GetFontListWithDelta(int size_delta) {
+ return GetFontListForDetails(FontDetails(std::string(), size_delta));
}
-const gfx::FontList& ResourceBundle::GetFontListWithTypefaceAndDelta(
- const std::string& typeface,
- int size_delta,
- gfx::Font::FontStyle style,
- gfx::Font::Weight weight) {
+const gfx::FontList& ResourceBundle::GetFontListForDetails(
+ const FontDetails& details) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- const FontKey styled_key(typeface, size_delta, style, weight);
-
- auto found = font_cache_.find(styled_key);
+ auto found = font_cache_.find(details);
if (found != font_cache_.end())
return found->second;
- const FontKey base_key(typeface, 0, gfx::Font::NORMAL,
- gfx::Font::Weight::NORMAL);
+ const FontDetails base_details(details.typeface);
gfx::FontList default_font_list = gfx::FontList();
gfx::FontList base_font_list =
- typeface.empty()
+ details.typeface.empty()
? default_font_list
- : gfx::FontList({typeface}, default_font_list.GetFontStyle(),
+ : gfx::FontList({details.typeface}, default_font_list.GetFontStyle(),
default_font_list.GetFontSize(),
default_font_list.GetFontWeight());
- font_cache_.emplace(base_key, base_font_list);
- gfx::FontList& base = font_cache_.find(base_key)->second;
- if (styled_key == base_key)
+ font_cache_.emplace(base_details, base_font_list);
+ gfx::FontList& base = font_cache_.find(base_details)->second;
+ if (details == base_details)
return base;
// Fonts of a given style are derived from the unstyled font of the same size.
// Cache the unstyled font by first inserting a default-constructed font list.
// Then, derive it for the initial insertion, or use the iterator that points
// to the existing entry that the insertion collided with.
- const FontKey sized_key(typeface, size_delta, gfx::Font::NORMAL,
- gfx::Font::Weight::NORMAL);
- auto sized = font_cache_.emplace(sized_key, base_font_list);
+ const FontDetails sized_details(details.typeface, details.size_delta);
+ auto sized = font_cache_.emplace(sized_details, base_font_list);
if (sized.second)
- sized.first->second = base.DeriveWithSizeDelta(size_delta);
- if (styled_key == sized_key) {
+ sized.first->second = base.DeriveWithSizeDelta(details.size_delta);
+ if (details == sized_details) {
return sized.first->second;
}
- auto styled = font_cache_.emplace(styled_key, base_font_list);
+ auto styled = font_cache_.emplace(details, base_font_list);
DCHECK(styled.second); // Otherwise font_cache_.find(..) would have found it.
styled.first->second = sized.first->second.Derive(
- 0, sized.first->second.GetFontStyle() | style, weight);
+ 0, sized.first->second.GetFontStyle(), details.weight);
return styled.first->second;
}
-const gfx::Font& ResourceBundle::GetFontWithDelta(int size_delta,
- gfx::Font::FontStyle style,
- gfx::Font::Weight weight) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return GetFontListWithDelta(size_delta, style, weight).GetPrimaryFont();
-}
-
const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- gfx::Font::Weight font_weight = gfx::Font::Weight::NORMAL;
+ gfx::Font::Weight weight = gfx::Font::Weight::NORMAL;
if (legacy_style == BoldFont || legacy_style == MediumBoldFont)
- font_weight = gfx::Font::Weight::BOLD;
+ weight = gfx::Font::Weight::BOLD;
int size_delta = 0;
switch (legacy_style) {
@@ -836,7 +793,7 @@ const gfx::FontList& ResourceBundle::GetFontList(FontStyle legacy_style) {
break;
}
- return GetFontListWithDelta(size_delta, gfx::Font::NORMAL, font_weight);
+ return GetFontListForDetails(FontDetails(std::string(), size_delta, weight));
}
const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
@@ -969,7 +926,7 @@ void ResourceBundle::AddDataPack(std::unique_ptr<DataPack> data_pack) {
}
void ResourceBundle::InitDefaultFontList() {
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
// InitDefaultFontList() is called earlier than overriding the locale strings.
// So we call the |GetLocalizedStringImpl()| which doesn't set the flag
// |can_override_locale_string_resources_| to false. This is okay, because the
@@ -1097,11 +1054,15 @@ base::string16 ResourceBundle::GetLocalizedStringImpl(int resource_id) const {
// Fall back on the main data pack (shouldn't be any strings here except
// in unittests).
data = GetRawDataResource(resource_id);
+#if defined(OS_FUCHSIA)
+ CHECK(!data.empty());
+#else // !defined(OS_FUCHSIA)
if (data.empty()) {
LOG(WARNING) << "unable to find resource: " << resource_id;
NOTREACHED();
return base::string16();
}
+#endif // !defined(OS_FUCHSIA)
}
}
diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h
index 51dbdfab396..48c329f00c3 100644
--- a/chromium/ui/base/resource/resource_bundle.h
+++ b/chromium/ui/base/resource/resource_bundle.h
@@ -67,6 +67,26 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
LargeFont,
};
+ struct COMPONENT_EXPORT(UI_BASE) FontDetails {
+ explicit FontDetails(std::string typeface = std::string(),
+ int size_delta = 0,
+ gfx::Font::Weight weight = gfx::Font::Weight::NORMAL);
+ FontDetails(const FontDetails&) = default;
+ FontDetails(FontDetails&&) = default;
+ FontDetails& operator=(const FontDetails&) = default;
+ FontDetails& operator=(FontDetails&&) = default;
+ ~FontDetails() = default;
+
+ bool operator==(const FontDetails& rhs) const;
+ bool operator<(const FontDetails& rhs) const;
+
+ // If typeface is empty, we default to the platform-specific "Base" font
+ // list.
+ std::string typeface;
+ int size_delta;
+ gfx::Font::Weight weight;
+ };
+
enum LoadResources {
LOAD_COMMON_RESOURCES,
DO_NOT_LOAD_COMMON_RESOURCES
@@ -293,26 +313,11 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
// Returns a font list derived from the platform-specific "Base" font list.
// The result is always cached and exists for the lifetime of the process.
- const gfx::FontList& GetFontListWithDelta(
- int size_delta,
- gfx::Font::FontStyle style = gfx::Font::NORMAL,
- gfx::Font::Weight weight = gfx::Font::Weight::NORMAL);
-
- // Returns a font list derived from the user-specified typeface. The
- // result is always cached and exists for the lifetime of the process.
- // If typeface is empty, we default to the platform-specific "Base" font
- // list.
- const gfx::FontList& GetFontListWithTypefaceAndDelta(
- const std::string& typeface,
- int size_delta,
- gfx::Font::FontStyle style = gfx::Font::NORMAL,
- gfx::Font::Weight weight = gfx::Font::Weight::NORMAL);
-
- // Returns the primary font from the FontList given by GetFontListWithDelta().
- const gfx::Font& GetFontWithDelta(
- int size_delta,
- gfx::Font::FontStyle style = gfx::Font::NORMAL,
- gfx::Font::Weight weight = gfx::Font::Weight::NORMAL);
+ const gfx::FontList& GetFontListWithDelta(int size_delta);
+
+ // Returns a font list for the given set of |details|. The result is always
+ // cached and exists for the lifetime of the process.
+ const gfx::FontList& GetFontListForDetails(const FontDetails& details);
// Deprecated. Returns fonts using hard-coded size deltas implied by |style|.
const gfx::FontList& GetFontList(FontStyle style);
@@ -360,6 +365,7 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
mangle_localized_strings_ = mangle;
}
+ std::string GetLoadedLocaleForTesting() { return loaded_locale_; }
#if DCHECK_IS_ON()
// Gets whether overriding locale strings is supported.
bool get_can_override_locale_string_resources_for_test() {
@@ -380,8 +386,6 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
class ResourceBundleImageSource;
friend class ResourceBundleImageSource;
- struct FontKey;
-
using IdToStringMap = std::unordered_map<int, base::string16>;
// Ctor/dtor are private, since we're a singleton.
@@ -509,7 +513,7 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
// platform base font size, plus style, to the FontList. Cached to avoid
// repeated GDI creation/destruction and font derivation.
// Must be accessed only from UI thread.
- std::map<FontKey, gfx::FontList> font_cache_;
+ std::map<FontDetails, gfx::FontList> font_cache_;
base::FilePath overridden_pak_path_;
@@ -522,6 +526,10 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
bool is_test_resources_ = false;
bool mangle_localized_strings_ = false;
+ // This is currently just used by the testing infrastructure to make sure
+ // the loaded locale_ is en-US at the start of each unit_test.
+ std::string loaded_locale_;
+
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(ResourceBundle);
diff --git a/chromium/ui/base/resource/resource_bundle_android.cc b/chromium/ui/base/resource/resource_bundle_android.cc
index ddb0e045499..bc5d5289dd6 100644
--- a/chromium/ui/base/resource/resource_bundle_android.cc
+++ b/chromium/ui/base/resource/resource_bundle_android.cc
@@ -106,6 +106,8 @@ bool ResourceBundle::LocaleDataPakExists(const std::string& locale) {
}
if (!GetPathForAndroidLocalePakWithinApk(locale, in_split, log_error).empty())
return true;
+
+ // Fall back to checking on disk, which is necessary only for tests.
const auto path = GetLocaleFilePath(locale);
return !path.empty() && base::PathExists(path);
}
@@ -122,9 +124,7 @@ std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale,
// a) WebView strings, which are always stored uncompressed under
// assets/stored-locales/ inside the APK or App Bundle.
//
- // b) For APKs, the Chrome UI strings are stored under assets/locales/
- // in compressed form. The relevant pak files is extracted on startup
- // and stored on the /data partition, with a version-specific suffix.
+ // b) For APKs, the Chrome UI strings are stored under assets/locales/.
//
// c) For App Bundles, Chrome UI strings are stored uncompressed under
// assets/locales#lang_<lang>/ (where <lang> is an Android language code)
@@ -139,8 +139,7 @@ std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale,
//
// If false, try to load it from the app bundle specific location
// (e.g. locales#lang_<language>/<locale>.pak). If the latter does not
- // exist, try to lookup the extracted APK-specific locale .pak file
- // from /data/app/.../<locale>.pak@<version> instead.
+ // exist, try to lookup the APK-specific locale .pak file.
//
// g_locale_paks_in_apk is set by SetLocalePaksStoredInApk() which
// is called from the WebView startup code.
@@ -172,7 +171,7 @@ std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale,
LoadLocalePakFromApk(app_locale, true, &g_locale_pack_region);
}
if (g_locale_pack_fd < 0) {
- // Otherwise, try to locate the extracted locale .pak file.
+ // Otherwise, try to locate the side-loaded locale .pak file (for tests).
if (locale_file_path.empty()) {
auto path = GetLocaleFilePath(app_locale);
if (base::PathExists(path))
diff --git a/chromium/ui/base/resource/resource_bundle_unittest.cc b/chromium/ui/base/resource/resource_bundle_unittest.cc
index bfa3dab5e80..255adcedf3f 100644
--- a/chromium/ui/base/resource/resource_bundle_unittest.cc
+++ b/chromium/ui/base/resource/resource_bundle_unittest.cc
@@ -18,6 +18,7 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -576,7 +577,7 @@ TEST_F(ResourceBundleImageTest, GetImageNamed) {
gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
-#if defined(OS_CHROMEOS) || defined(OS_WIN)
+#if BUILDFLAG(IS_CHROMEOS_ASH) || defined(OS_WIN)
// ChromeOS/Windows load highest scale factor first.
EXPECT_EQ(ui::SCALE_FACTOR_200P,
GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
diff --git a/chromium/ui/base/resource/resource_bundle_win.cc b/chromium/ui/base/resource/resource_bundle_win.cc
index 1cf3aaffc76..1db7224d9c8 100644
--- a/chromium/ui/base/resource/resource_bundle_win.cc
+++ b/chromium/ui/base/resource/resource_bundle_win.cc
@@ -4,6 +4,8 @@
#include "ui/base/resource/resource_bundle_win.h"
+#include <windows.h>
+
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "skia/ext/image_operations.h"
@@ -50,4 +52,8 @@ HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
}
+HCURSOR LoadCursorFromResourcesDataDLL(const wchar_t* cursor_id) {
+ return ::LoadCursor(GetCurrentResourceDLL(), cursor_id);
+}
+
} // namespace ui;
diff --git a/chromium/ui/base/resource/resource_bundle_win.h b/chromium/ui/base/resource/resource_bundle_win.h
index 167f40c1ce3..44956d2244a 100644
--- a/chromium/ui/base/resource/resource_bundle_win.h
+++ b/chromium/ui/base/resource/resource_bundle_win.h
@@ -7,9 +7,8 @@
#include "build/build_config.h"
-#include <windows.h>
-
#include "base/component_export.h"
+#include "base/win/windows_types.h"
namespace ui {
@@ -20,6 +19,10 @@ COMPONENT_EXPORT(UI_BASE) void SetResourcesDataDLL(HINSTANCE handle);
// Loads and returns an icon from the app module.
COMPONENT_EXPORT(UI_BASE) HICON LoadThemeIconFromResourcesDataDLL(int icon_id);
+// Loads and returns a cursor from the app module.
+COMPONENT_EXPORT(UI_BASE)
+HCURSOR LoadCursorFromResourcesDataDLL(const wchar_t* cursor_id);
+
} // namespace ui
#endif // UI_BASE_RESOURCE_RESOURCE_DATA_DLL_WIN_H_