Commit 1e462f3f authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Compress IDR_DIR_HEADER_HTML within the .pak file.

Bug: 982762
Change-Id: Ia381787192d654d21e7928afb58d461f94b6539c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851084Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704692}
parent 3ef9b281
......@@ -8,7 +8,6 @@
#include "base/i18n/rtl.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
......@@ -23,8 +22,6 @@ namespace {
// The net module doesn't have access to this HTML or the strings that need to
// be localized. The Chrome locale will never change while we're running, so
// it's safe to have a static string that we always return a pointer into.
// This allows us to have the ResourceProvider return a pointer into the actual
// resource (via a StringPiece), instead of always copying resources.
struct LazyDirectoryListerCacher {
LazyDirectoryListerCacher() {
base::DictionaryValue value;
......@@ -44,22 +41,24 @@ struct LazyDirectoryListerCacher {
l10n_util::GetStringFUTF16(IDS_DIRECTORY_LISTING_PARSING_ERROR_BOX_TEXT,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
html_data = webui::GetI18nTemplateHtml(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
std::string str = webui::GetI18nTemplateHtml(
ui::ResourceBundle::GetSharedInstance().DecompressDataResource(
IDR_DIR_HEADER_HTML),
&value);
html_data = base::RefCountedString::TakeString(&str);
}
std::string html_data;
scoped_refptr<base::RefCountedMemory> html_data;
};
} // namespace
base::StringPiece ChromeNetResourceProvider(int key) {
scoped_refptr<base::RefCountedMemory> ChromeNetResourceProvider(int key) {
static base::NoDestructor<LazyDirectoryListerCacher> lazy_dir_lister;
if (IDR_DIR_HEADER_HTML == key)
return base::StringPiece(lazy_dir_lister->html_data);
return lazy_dir_lister->html_data;
return ui::ResourceBundle::GetSharedInstance().GetRawDataResource(key);
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(key);
}
......@@ -5,9 +5,9 @@
#ifndef CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
#define CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
#include "base/strings/string_piece.h"
#include "base/memory/ref_counted_memory.h"
// This is called indirectly by the network layer to access resources.
base::StringPiece ChromeNetResourceProvider(int key);
scoped_refptr<base::RefCountedMemory> ChromeNetResourceProvider(int key);
#endif // CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
......@@ -83,14 +83,12 @@ GURL GetStartupURL() {
base::MakeAbsoluteFilePath(base::FilePath(args[0])));
}
base::StringPiece PlatformResourceProvider(int key) {
scoped_refptr<base::RefCountedMemory> PlatformResourceProvider(int key) {
if (key == IDR_DIR_HEADER_HTML) {
base::StringPiece html_data =
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_DIR_HEADER_HTML);
return html_data;
}
return base::StringPiece();
return nullptr;
}
} // namespace
......
......@@ -7,7 +7,7 @@
#include "base/i18n/time_formatting.h"
#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/strings/string_piece.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
......@@ -18,15 +18,14 @@
namespace net {
std::string GetDirectoryListingHeader(const base::string16& title) {
static const base::StringPiece header(
scoped_refptr<base::RefCountedMemory> header(
NetModule::GetResource(IDR_DIR_HEADER_HTML));
// This can be null in unit tests.
DLOG_IF(WARNING, header.empty())
<< "Missing resource: directory listing header";
DLOG_IF(WARNING, !header) << "Missing resource: directory listing header";
std::string result;
if (!header.empty())
result.assign(header.data(), header.size());
if (header)
result.assign(header->front_as<char>(), header->size());
result.append("<script>start(");
base::EscapeJSONString(title, true, &result);
......
......@@ -14,8 +14,8 @@ void NetModule::SetResourceProvider(ResourceProvider func) {
}
// static
base::StringPiece NetModule::GetResource(int key) {
return resource_provider ? resource_provider(key) : base::StringPiece();
scoped_refptr<base::RefCountedMemory> NetModule::GetResource(int key) {
return resource_provider ? resource_provider(key) : nullptr;
}
} // namespace net
......@@ -6,7 +6,7 @@
#define NET_BASE_NET_MODULE_H__
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "base/memory/ref_counted_memory.h"
#include "net/base/net_export.h"
namespace net {
......@@ -20,15 +20,15 @@ namespace net {
//
class NET_EXPORT NetModule {
public:
typedef base::StringPiece (*ResourceProvider)(int key);
typedef scoped_refptr<base::RefCountedMemory> (*ResourceProvider)(int key);
// Set the function to call when the net module needs resources
static void SetResourceProvider(ResourceProvider func);
// Call the resource provider (if one exists) to get the specified resource.
// Returns an empty string if the resource does not exist or if there is no
// resource provider.
static base::StringPiece GetResource(int key);
// Returns nullptr if the resource does not exist or if there is no resource
// provider.
static scoped_refptr<base::RefCountedMemory> GetResource(int key);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(NetModule);
......
......@@ -9,7 +9,7 @@
<translations />
<release seq="1">
<includes>
<include name="IDR_DIR_HEADER_HTML" file="dir_header.html" type="BINDATA" />
<include name="IDR_DIR_HEADER_HTML" file="dir_header.html" type="BINDATA" compress="gzip" />
</includes>
</release>
</grit>
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