Commit 1aba5c34 authored by dpapad's avatar dpapad Committed by Commit Bot

Leverage ResourceBundle::IsGzipped from resource_bundle_source_map.cc

Previously extensions::Dispatcher::GetJsResources() relied on a manually
specified boolean which had to be kept in sync with a grd file's
compress="gzip" attributes (only leveraged by IDR_MOJO_MOJO_BINDINGS_JS).

This is no longer necessary since ResourceBundle::IsGzipped() can be used
to determine if the file is gzipped or not.

Basically this CL undoes a subset of the changes introduced at r516811.

Bug: 961063
Change-Id: I03740235f2c0ee62c9f406be336fa524e89d2d6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602132
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659277}
parent f75accce
......@@ -685,7 +685,7 @@ std::vector<Dispatcher::JsResourceInfo> Dispatcher::GetJsResources() {
{"webViewInternal", IDR_WEB_VIEW_INTERNAL_CUSTOM_BINDINGS_JS},
{"keep_alive", IDR_KEEP_ALIVE_JS},
{"mojo_bindings", IDR_MOJO_MOJO_BINDINGS_JS, true},
{"mojo_bindings", IDR_MOJO_MOJO_BINDINGS_JS},
{"extensions/common/mojo/keep_alive.mojom", IDR_KEEP_ALIVE_MOJOM_JS},
// Custom bindings.
......@@ -1323,7 +1323,7 @@ void Dispatcher::UpdateContentCapabilities(ScriptContext* context) {
void Dispatcher::PopulateSourceMap() {
const std::vector<JsResourceInfo> resources = GetJsResources();
for (const auto& resource : resources)
source_map_.RegisterSource(resource.name, resource.id, resource.gzipped);
source_map_.RegisterSource(resource.name, resource.id);
delegate_->PopulateSourceMap(&source_map_);
}
......
......@@ -159,7 +159,6 @@ class Dispatcher : public content::RenderThreadObserver,
struct JsResourceInfo {
const char* name = nullptr;
int id = 0;
bool gzipped = false;
};
// Returns a list of resources for the JS modules to add to the source map.
static std::vector<JsResourceInfo> GetJsResources();
......
......@@ -27,8 +27,7 @@ v8::Local<v8::String> ConvertString(v8::Isolate* isolate,
} // namespace
ResourceBundleSourceMap::ResourceInfo::ResourceInfo() = default;
ResourceBundleSourceMap::ResourceInfo::ResourceInfo(int in_id, bool in_gzipped)
: id(in_id), gzipped(in_gzipped) {}
ResourceBundleSourceMap::ResourceInfo::ResourceInfo(int in_id) : id(in_id) {}
ResourceBundleSourceMap::ResourceInfo::ResourceInfo(ResourceInfo&& other) =
default;
......@@ -46,9 +45,8 @@ ResourceBundleSourceMap::~ResourceBundleSourceMap() {
}
void ResourceBundleSourceMap::RegisterSource(const char* const name,
int resource_id,
bool gzipped) {
resource_map_[name] = {resource_id, gzipped};
int resource_id) {
resource_map_.emplace(name, resource_id);
}
v8::Local<v8::String> ResourceBundleSourceMap::GetSource(
......@@ -71,7 +69,8 @@ v8::Local<v8::String> ResourceBundleSourceMap::GetSource(
return v8::Local<v8::String>();
}
if (info.gzipped) {
bool is_gzipped = resource_bundle_->IsGzipped(info.id);
if (is_gzipped) {
info.cached = std::make_unique<std::string>();
uint32_t size = compression::GetUncompressedSize(resource);
info.cached->resize(size);
......
......@@ -27,22 +27,19 @@ class ResourceBundleSourceMap : public SourceMap {
const std::string& name) const override;
bool Contains(const std::string& name) const override;
void RegisterSource(const char* const name,
int resource_id,
bool gzipped = false);
void RegisterSource(const char* const name, int resource_id);
private:
struct ResourceInfo {
ResourceInfo();
ResourceInfo(int in_id, bool in_gzipped);
explicit ResourceInfo(int in_id);
ResourceInfo(ResourceInfo&& other);
~ResourceInfo();
ResourceInfo& operator=(ResourceInfo&& other);
int id = 0;
bool gzipped = false;
// Used to cache the uncompressed contents if |gzipped| is true.
// Used to cache the uncompressed contents if the resource is gzipped.
mutable std::unique_ptr<std::string> cached;
};
......
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