Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: ui/base/resource/resource_bundle.cc

Issue 2149323003: Change the way that gzipped resources are loaded from resources.pak (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: whoops Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle.cc
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 68f9d2574452c5cd2dd55d273b5332d0a34b30e1..153f9ff4e3f89b4547469efb4c5eb9f12a8a37ee 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -23,12 +23,10 @@
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
-#include "base/sys_byteorder.h"
#include "build/build_config.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
-#include "third_party/zlib/zlib.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/data_pack.h"
@@ -113,39 +111,6 @@ SkBitmap CreateEmptyBitmap() {
return bitmap;
}
-// Decodes given gzip input via zlib.
-base::RefCountedBytes* DecodeGzipData(const unsigned char* input_buffer,
- size_t input_size) {
- z_stream inflateStream;
- memset(&inflateStream, 0, sizeof(inflateStream));
- inflateStream.zalloc = Z_NULL;
- inflateStream.zfree = Z_NULL;
- inflateStream.opaque = Z_NULL;
-
- inflateStream.avail_in = input_size;
- inflateStream.next_in = const_cast<Bytef*>(input_buffer);
-
- CHECK(input_size >= 4);
- // Size of output comes from footer of gzip file format, found as the last 4
- // bytes in the compressed file, which are stored little endian.
- inflateStream.avail_out = base::ByteSwapToLE32(
- *reinterpret_cast<const uint32_t*>(&input_buffer[input_size - 4]));
-
- std::vector<unsigned char> output(inflateStream.avail_out);
- inflateStream.next_out = reinterpret_cast<Bytef*>(&output[0]);
-
- CHECK(inflateInit2(&inflateStream, 16) == Z_OK);
- CHECK(inflate(&inflateStream, Z_FINISH) == Z_STREAM_END);
- CHECK(inflateEnd(&inflateStream) == Z_OK);
-
- // Cannot use TakeVector since it puts the RefCounted* into a scoped_refptr,
- // and callers of this function return a raw pointer (not a scoped_refptr), so
- // the memory will be deallocated upon exit of the calling function.
- base::RefCountedBytes* returnVal = new base::RefCountedBytes();
- returnVal->data().swap(output);
- return returnVal;
-}
-
} // namespace
// An ImageSkiaSource that loads bitmaps for the requested scale factor from
@@ -502,17 +467,9 @@ base::RefCountedMemory* ResourceBundle::LoadDataResourceBytesForScale(
if (!bytes) {
base::StringPiece data =
- GetRawDataResourceForScaleImpl(resource_id, scale_factor);
- if (!data.empty()) {
- if (data.starts_with(CUSTOM_GZIP_HEADER)) {
- // Jump past special identification byte prepended to header
- const unsigned char* gzip_start =
- reinterpret_cast<const unsigned char*>(data.data()) + 1;
- bytes = DecodeGzipData(gzip_start, data.length() - 1);
- } else {
- bytes = new base::RefCountedStaticMemory(data.data(), data.length());
- }
- }
+ GetRawDataResourceForScale(resource_id, scale_factor);
+ if (!data.empty())
+ bytes = new base::RefCountedStaticMemory(data.data(), data.length());
}
return bytes;
@@ -525,13 +482,31 @@ base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) const {
base::StringPiece ResourceBundle::GetRawDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) const {
- base::StringPiece data =
- GetRawDataResourceForScaleImpl(resource_id, scale_factor);
+ base::StringPiece data;
+ if (delegate_ &&
+ delegate_->GetRawDataResource(resource_id, scale_factor, &data))
+ return data;
+
+ if (scale_factor != ui::SCALE_FACTOR_100P) {
+ for (size_t i = 0; i < data_packs_.size(); i++) {
+ if (data_packs_[i]->GetScaleFactor() == scale_factor &&
+ data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id),
+ &data))
+ return data;
+ }
+ }
- // Do not allow this function to retrieve gzip compressed resources.
- CHECK(!data.starts_with(CUSTOM_GZIP_HEADER));
+ for (size_t i = 0; i < data_packs_.size(); i++) {
+ if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P ||
+ data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P ||
+ data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_300P ||
+ data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) &&
+ data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id),
+ &data))
+ return data;
+ }
- return data;
+ return base::StringPiece();
}
base::string16 ResourceBundle::GetLocalizedString(int message_id) {
@@ -864,36 +839,6 @@ bool ResourceBundle::LoadBitmap(int resource_id,
return false;
}
-base::StringPiece ResourceBundle::GetRawDataResourceForScaleImpl(
- int resource_id,
- ScaleFactor scale_factor) const {
- base::StringPiece data;
- if (delegate_ &&
- delegate_->GetRawDataResource(resource_id, scale_factor, &data))
- return data;
-
- if (scale_factor != ui::SCALE_FACTOR_100P) {
- for (size_t i = 0; i < data_packs_.size(); i++) {
- if (data_packs_[i]->GetScaleFactor() == scale_factor &&
- data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id),
- &data))
- return data;
- }
- }
-
- for (size_t i = 0; i < data_packs_.size(); i++) {
- if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P ||
- data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P ||
- data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_300P ||
- data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) &&
- data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id),
- &data))
- return data;
- }
-
- return base::StringPiece();
-}
-
gfx::Image& ResourceBundle::GetEmptyImage() {
base::AutoLock lock(*images_and_fonts_lock_);

Powered by Google App Engine
This is Rietveld 408576698