summaryrefslogtreecommitdiff
path: root/chromium/ui/base/resource
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-31 15:50:41 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-08-30 12:35:23 +0000
commit7b2ffa587235a47d4094787d72f38102089f402a (patch)
tree30e82af9cbab08a7fa028bb18f4f2987a3f74dfa /chromium/ui/base/resource
parentd94af01c90575348c4e81a418257f254b6f8d225 (diff)
downloadqtwebengine-chromium-7b2ffa587235a47d4094787d72f38102089f402a.tar.gz
BASELINE: Update Chromium to 76.0.3809.94
Change-Id: I321c3f5f929c105aec0f98c5091ef6108822e647 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/base/resource')
-rw-r--r--chromium/ui/base/resource/data_pack.cc20
-rw-r--r--chromium/ui/base/resource/data_pack.h1
-rw-r--r--chromium/ui/base/resource/data_pack_literal.cc11
-rw-r--r--chromium/ui/base/resource/data_pack_unittest.cc11
-rw-r--r--chromium/ui/base/resource/resource_bundle.cc11
-rw-r--r--chromium/ui/base/resource/resource_bundle.h4
-rw-r--r--chromium/ui/base/resource/resource_bundle_android.cc21
-rw-r--r--chromium/ui/base/resource/resource_bundle_unittest.cc20
-rw-r--r--chromium/ui/base/resource/resource_data_dll_win.cc4
-rw-r--r--chromium/ui/base/resource/resource_data_dll_win.h1
-rw-r--r--chromium/ui/base/resource/resource_handle.h4
11 files changed, 84 insertions, 24 deletions
diff --git a/chromium/ui/base/resource/data_pack.cc b/chromium/ui/base/resource/data_pack.cc
index f6cbde5fcc5..da3771f0193 100644
--- a/chromium/ui/base/resource/data_pack.cc
+++ b/chromium/ui/base/resource/data_pack.cc
@@ -21,6 +21,7 @@
#include "base/synchronization/lock.h"
#include "base/sys_byteorder.h"
#include "build/build_config.h"
+#include "net/filter/gzip_header.h"
// For details of the file layout, see
// http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalizedstrings
@@ -84,6 +85,14 @@ void MaybePrintResourceId(uint16_t resource_id) {
}
}
+bool HasGzipHeader(base::StringPiece* data) {
+ net::GZipHeader header;
+ const char* header_end = nullptr;
+ net::GZipHeader::Status header_status =
+ header.ReadMore(data->data(), data->length(), &header_end);
+ return header_status == net::GZipHeader::COMPLETE_HEADER;
+}
+
// Convenience class to write data to a file. Usage is the following:
// 1) Create a new instance, passing a base::FilePath.
// 2) Call Write() repeatedly to write all desired data to the file.
@@ -380,6 +389,17 @@ bool DataPack::HasResource(uint16_t resource_id) const {
return !!LookupEntryById(resource_id);
}
+bool DataPack::IsGzipped(uint16_t resource_id, bool* is_gzipped) const {
+ DCHECK(is_gzipped);
+ if (!HasResource(resource_id))
+ return false;
+
+ base::StringPiece data;
+ CHECK(GetStringPiece(resource_id, &data));
+ *is_gzipped = HasGzipHeader(&data);
+ return true;
+}
+
bool DataPack::GetStringPiece(uint16_t resource_id,
base::StringPiece* data) const {
// It won't be hard to make this endian-agnostic, but it's not worth
diff --git a/chromium/ui/base/resource/data_pack.h b/chromium/ui/base/resource/data_pack.h
index 6d252b07ccf..3a8f66c7219 100644
--- a/chromium/ui/base/resource/data_pack.h
+++ b/chromium/ui/base/resource/data_pack.h
@@ -60,6 +60,7 @@ class UI_DATA_PACK_EXPORT DataPack : public ResourceHandle {
// ResourceHandle implementation:
bool HasResource(uint16_t resource_id) const override;
+ bool IsGzipped(uint16_t resource_id, bool* is_gzipped) const override;
bool GetStringPiece(uint16_t resource_id,
base::StringPiece* data) const override;
base::RefCountedStaticMemory* GetStaticMemory(
diff --git a/chromium/ui/base/resource/data_pack_literal.cc b/chromium/ui/base/resource/data_pack_literal.cc
index 3218f848e94..7d35c6a2ccd 100644
--- a/chromium/ui/base/resource/data_pack_literal.cc
+++ b/chromium/ui/base/resource/data_pack_literal.cc
@@ -29,10 +29,15 @@ const char kSamplePakContentsV5[] = {
0x01, 0x00, 0x28, 0x00, 0x00, 0x00, // index entry 1
0x04, 0x00, 0x28, 0x00, 0x00, 0x00, // index entry 4
0x06, 0x00, 0x34, 0x00, 0x00, 0x00, // index entry 6
- 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // extra entry for the size of last
+ 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, // extra entry for the size of last
0x0a, 0x00, 0x01, 0x00, // alias table
- 't', 'h', 'i', 's', ' ', 'i', 's', ' ', 'i', 'd', ' ', '4',
- 't', 'h', 'i', 's', ' ', 'i', 's', ' ', 'i', 'd', ' ', '6'};
+
+ 't', 'h', 'i', 's', ' ', 'i', 's', ' ', 'i', 'd', ' ', '4',
+ // "this is id 6" gzipped with
+ // echo "this is id 6" | gzip -f -c | hexdump -C
+ 0x1f, 0x8b, 0x08, 0x00, 0x2e, 0x15, 0xc1, 0x5c, 0x00, 0x03, 0x2b, 0xc9,
+ 0xc8, 0x2c, 0x56, 0x00, 0xa1, 0x14, 0x05, 0x33, 0x2e, 0x00, 0x10, 0x61,
+ 0x1b, 0x8b, 0x0d, 0x00, 0x00, 0x00};
const size_t kSamplePakSizeV5 = sizeof(kSamplePakContentsV5);
diff --git a/chromium/ui/base/resource/data_pack_unittest.cc b/chromium/ui/base/resource/data_pack_unittest.cc
index 9ddeee9a84a..17bd93d5fb3 100644
--- a/chromium/ui/base/resource/data_pack_unittest.cc
+++ b/chromium/ui/base/resource/data_pack_unittest.cc
@@ -175,7 +175,6 @@ TEST(DataPackTest, LoadFromBufferV5) {
EXPECT_EQ("this is id 4", data);
ASSERT_TRUE(pack.HasResource(6));
ASSERT_TRUE(pack.GetStringPiece(6, &data));
- EXPECT_EQ("this is id 6", data);
// Try reading zero-length data blobs, just in case.
ASSERT_TRUE(pack.GetStringPiece(1, &data));
@@ -186,6 +185,16 @@ TEST(DataPackTest, LoadFromBufferV5) {
// Try looking up an invalid key.
ASSERT_FALSE(pack.HasResource(140));
ASSERT_FALSE(pack.GetStringPiece(140, &data));
+
+ bool is_gzipped;
+ ASSERT_TRUE(pack.IsGzipped(1, &is_gzipped));
+ ASSERT_FALSE(is_gzipped);
+ ASSERT_TRUE(pack.IsGzipped(4, &is_gzipped));
+ ASSERT_FALSE(is_gzipped);
+ ASSERT_TRUE(pack.IsGzipped(6, &is_gzipped));
+ ASSERT_TRUE(is_gzipped);
+ ASSERT_TRUE(pack.IsGzipped(10, &is_gzipped));
+ ASSERT_FALSE(is_gzipped);
}
INSTANTIATE_TEST_SUITE_P(WriteBINARY,
diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc
index 340291d8c8f..ab883f7cb8b 100644
--- a/chromium/ui/base/resource/resource_bundle.cc
+++ b/chromium/ui/base/resource/resource_bundle.cc
@@ -415,7 +415,7 @@ base::string16 ResourceBundle::MaybeMangleLocalizedString(
if (!mangle_localized_strings_)
return str;
- // IDS_DEFAULT_FONT_SIZE and friends are localization "strings" that are
+ // IDS_MINIMUM_FONT_SIZE and friends are localization "strings" that are
// actually integral constants. These should not be mangled or they become
// impossible to parse.
int ignored;
@@ -555,6 +555,15 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale(
return base::StringPiece();
}
+bool ResourceBundle::IsGzipped(int resource_id) const {
+ bool is_gzipped;
+ for (const auto& pack : data_packs_) {
+ if (pack->IsGzipped(resource_id, &is_gzipped))
+ return is_gzipped;
+ }
+ return false;
+}
+
base::string16 ResourceBundle::GetLocalizedString(int resource_id) {
#if DCHECK_IS_ON()
{
diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h
index 1f0f0b575e4..23005f6da22 100644
--- a/chromium/ui/base/resource/resource_bundle.h
+++ b/chromium/ui/base/resource/resource_bundle.h
@@ -217,6 +217,10 @@ class UI_BASE_EXPORT ResourceBundle {
// Loads the raw bytes of a scale independent data resource.
base::RefCountedMemory* LoadDataResourceBytes(int resource_id) const;
+ // Whether the |resource_id| is gzipped in this bundle. False is also returned
+ // if the resource is not found.
+ bool IsGzipped(int resource_id) const;
+
// Loads the raw bytes of a data resource nearest the scale factor
// |scale_factor| into |bytes|, without doing any processing or
// interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE
diff --git a/chromium/ui/base/resource/resource_bundle_android.cc b/chromium/ui/base/resource/resource_bundle_android.cc
index 899bb583517..6686f17a223 100644
--- a/chromium/ui/base/resource/resource_bundle_android.cc
+++ b/chromium/ui/base/resource/resource_bundle_android.cc
@@ -8,7 +8,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/logging.h"
-#include "base/metrics/histogram_macros.h"
#include "base/path_service.h"
#include "jni/ResourceBundle_jni.h"
#include "ui/base/l10n/l10n_util.h"
@@ -78,17 +77,6 @@ std::unique_ptr<DataPack> LoadDataPackFromLocalePak(
return data_pack;
}
-enum class LoadFailureReason {
- kLocalePakNotFound,
- kPackLoadFailedPrimary,
- kPackLoadFailedSecondary,
- kMaxValue = kPackLoadFailedSecondary,
-};
-
-void LogLoadLocaleFailureReason(LoadFailureReason reason) {
- UMA_HISTOGRAM_ENUMERATION("Android.ResourceBundle.LoadLocaleFailure", reason);
-}
-
} // namespace
void ResourceBundle::LoadCommonResources() {
@@ -134,7 +122,6 @@ std::string ResourceBundle::LoadLocaleResources(
if (locale_file_path.empty()) {
// It's possible that there is no locale.pak.
LOG(WARNING) << "locale_file_path.empty() for locale " << app_locale;
- LogLoadLocaleFailureReason(LoadFailureReason::kLocalePakNotFound);
return std::string();
}
int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
@@ -145,10 +132,8 @@ std::string ResourceBundle::LoadLocaleResources(
locale_resources_data_ = LoadDataPackFromLocalePak(
g_locale_pack_fd, g_locale_pack_region);
- if (!locale_resources_data_.get()) {
- LogLoadLocaleFailureReason(LoadFailureReason::kPackLoadFailedPrimary);
+ if (!locale_resources_data_.get())
return std::string();
- }
// Load secondary locale .pak file if it exists. For debug build monochrome,
// a secondary locale pak will always be loaded; however, it should be
@@ -161,10 +146,8 @@ std::string ResourceBundle::LoadLocaleResources(
secondary_locale_resources_data_ = LoadDataPackFromLocalePak(
g_secondary_locale_pack_fd, g_secondary_locale_pack_region);
- if (!secondary_locale_resources_data_.get()) {
- LogLoadLocaleFailureReason(LoadFailureReason::kPackLoadFailedSecondary);
+ if (!secondary_locale_resources_data_.get())
return std::string();
- }
}
return app_locale;
diff --git a/chromium/ui/base/resource/resource_bundle_unittest.cc b/chromium/ui/base/resource/resource_bundle_unittest.cc
index be36b9ad616..4b3f0f50d28 100644
--- a/chromium/ui/base/resource/resource_bundle_unittest.cc
+++ b/chromium/ui/base/resource/resource_bundle_unittest.cc
@@ -35,6 +35,7 @@
using ::testing::_;
using ::testing::Between;
+using ::testing::DoAll;
using ::testing::Property;
using ::testing::Return;
using ::testing::ReturnArg;
@@ -246,6 +247,25 @@ TEST_F(ResourceBundleTest, DelegateGetRawDataResource) {
EXPECT_EQ(string_piece.data(), result.data());
}
+TEST_F(ResourceBundleTest, IsGzipped) {
+ base::ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+ base::FilePath data_path =
+ dir.GetPath().Append(FILE_PATH_LITERAL("sample.pak"));
+ // Dump contents into a pak file and load it.
+ ASSERT_EQ(base::WriteFile(data_path, kSamplePakContentsV5, kSamplePakSizeV5),
+ static_cast<int>(kSamplePakSizeV5));
+ ResourceBundle* resource_bundle = CreateResourceBundle(nullptr);
+ resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P);
+
+ ASSERT_FALSE(resource_bundle->IsGzipped(1));
+ ASSERT_FALSE(resource_bundle->IsGzipped(4));
+ ASSERT_TRUE(resource_bundle->IsGzipped(6));
+ ASSERT_FALSE(resource_bundle->IsGzipped(10));
+ // Ask for a non-existent resource ID.
+ ASSERT_FALSE(resource_bundle->IsGzipped(200));
+}
+
TEST_F(ResourceBundleTest, DelegateGetLocalizedString) {
MockResourceBundleDelegate delegate;
ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
diff --git a/chromium/ui/base/resource/resource_data_dll_win.cc b/chromium/ui/base/resource/resource_data_dll_win.cc
index 12c54c99eb3..153971554c3 100644
--- a/chromium/ui/base/resource/resource_data_dll_win.cc
+++ b/chromium/ui/base/resource/resource_data_dll_win.cc
@@ -28,6 +28,10 @@ bool ResourceDataDLL::HasResource(uint16_t resource_id) const {
&data_size);
}
+bool ResourceDataDLL::IsGzipped(uint16_t resource_id, bool* is_gzipped) const {
+ return false;
+}
+
bool ResourceDataDLL::GetStringPiece(uint16_t resource_id,
base::StringPiece* data) const {
DCHECK(data);
diff --git a/chromium/ui/base/resource/resource_data_dll_win.h b/chromium/ui/base/resource/resource_data_dll_win.h
index c5f0e60ac38..1e21a828e29 100644
--- a/chromium/ui/base/resource/resource_data_dll_win.h
+++ b/chromium/ui/base/resource/resource_data_dll_win.h
@@ -21,6 +21,7 @@ class ResourceDataDLL : public ResourceHandle {
// ResourceHandle implementation:
bool HasResource(uint16_t resource_id) const override;
+ bool IsGzipped(uint16_t resource_id, bool* is_gzipped) const override;
bool GetStringPiece(uint16_t resource_id,
base::StringPiece* data) const override;
base::RefCountedStaticMemory* GetStaticMemory(
diff --git a/chromium/ui/base/resource/resource_handle.h b/chromium/ui/base/resource/resource_handle.h
index 055b0370868..1ebd50032fc 100644
--- a/chromium/ui/base/resource/resource_handle.h
+++ b/chromium/ui/base/resource/resource_handle.h
@@ -31,6 +31,10 @@ class UI_DATA_PACK_EXPORT ResourceHandle {
// Returns true if the DataPack contains a resource with id |resource_id|.
virtual bool HasResource(uint16_t resource_id) const = 0;
+ // Whether a specific |resource_id| is gzipped. Returns false if
+ // !HasResource(resource_id). |is_gzipped| cannot be nullptr.
+ virtual bool IsGzipped(uint16_t resource_id, bool* is_gzipped) const = 0;
+
// Get resource by id |resource_id|, filling in |data|.
// The data is owned by the DataPack object and should not be modified.
// Returns false if the resource id isn't found.