Commit 25a7bd32 authored by smaier's avatar smaier Committed by Commit bot

Brotli compression used on about credits html file.

resources.pak shrunk by 1285356B.

To make use of brotli's compression, more of brotli's repo was added. The presubmit script had to be edited to allow the "#include ../" that was used in brotli's "tools" folder.

BUG=332521

Review-Url: https://codereview.chromium.org/1951363002
Cr-Commit-Position: refs/heads/master@{#395920}
parent f1f9ada3
...@@ -169,6 +169,7 @@ source_set("ui") { ...@@ -169,6 +169,7 @@ source_set("ui") {
"//storage/common", "//storage/common",
"//third_party/WebKit/public:resources", "//third_party/WebKit/public:resources",
"//third_party/adobe/flash:flapper_version_h", "//third_party/adobe/flash:flapper_version_h",
"//third_party/brotli",
"//third_party/leveldatabase", "//third_party/leveldatabase",
"//third_party/libjingle", "//third_party/libjingle",
"//third_party/re2", "//third_party/re2",
......
...@@ -14,6 +14,7 @@ include_rules = [ ...@@ -14,6 +14,7 @@ include_rules = [
# Other libraries. # Other libraries.
"+third_party/angle", # For ANGLE version. "+third_party/angle", # For ANGLE version.
"+third_party/brotli", # For compressed resources.
"+third_party/zlib/zlib.h", # For compression level constants. "+third_party/zlib/zlib.h", # For compression level constants.
"+third_party/libaddressinput", # For i18n address input. "+third_party/libaddressinput", # For i18n address input.
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
#include "third_party/brotli/dec/decode.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/jstemplate_builder.h" #include "ui/base/webui/jstemplate_builder.h"
...@@ -760,8 +761,25 @@ void AboutUIHTMLSource::StartDataRequest( ...@@ -760,8 +761,25 @@ void AboutUIHTMLSource::StartDataRequest(
idr = IDR_KEYBOARD_UTILS_JS; idr = IDR_KEYBOARD_UTILS_JS;
#endif #endif
response = ResourceBundle::GetSharedInstance().GetRawDataResource( base::StringPiece raw_response =
idr).as_string(); ResourceBundle::GetSharedInstance().GetRawDataResource(idr);
if (idr == IDR_ABOUT_UI_CREDITS_HTML) {
size_t decoded_size;
const uint8_t* encoded_response_buffer =
reinterpret_cast<const uint8_t*>(raw_response.data());
CHECK(BrotliDecompressedSize(raw_response.size(), encoded_response_buffer,
&decoded_size));
// Resizing the response and using it as the buffer Brotli decompresses
// into.
response.resize(decoded_size);
CHECK(BrotliDecompressBuffer(raw_response.size(), encoded_response_buffer,
&decoded_size,
reinterpret_cast<uint8_t*>(&response[0])) ==
BROTLI_RESULT_SUCCESS);
} else {
response = raw_response.as_string();
}
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
} else if (source_name_ == chrome::kChromeUIDiscardsHost) { } else if (source_name_ == chrome::kChromeUIDiscardsHost) {
response = AboutDiscards(path); response = AboutDiscards(path);
......
...@@ -2919,6 +2919,7 @@ ...@@ -2919,6 +2919,7 @@
'../net/net.gyp:stale_while_revalidate_experiment_domains', '../net/net.gyp:stale_while_revalidate_experiment_domains',
'../storage/storage_browser.gyp:storage', '../storage/storage_browser.gyp:storage',
'../storage/storage_common.gyp:storage_common', '../storage/storage_common.gyp:storage_common',
'../third_party/brotli/brotli.gyp:brotli',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'../third_party/re2/re2.gyp:re2', '../third_party/re2/re2.gyp:re2',
'../ui/base/ime/ui_base_ime.gyp:ui_base_ime', '../ui/base/ime/ui_base_ime.gyp:ui_base_ime',
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
{ {
'variables': { 'variables': {
'about_credits_file': '<(SHARED_INTERMEDIATE_DIR)/about_credits.html', 'about_credits_file': '<(SHARED_INTERMEDIATE_DIR)/about_credits.html',
'about_credits_file_bro': '<(SHARED_INTERMEDIATE_DIR)/about_credits.bro',
}, },
'targets': [ 'targets': [
{ {
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
'target_name': 'components_resources', 'target_name': 'components_resources',
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
'about_credits', 'compressed_about_credits',
], ],
'hard_dependency': 1, 'hard_dependency': 1,
'variables': { 'variables': {
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
'variables': { 'variables': {
'grit_grd_file': 'resources/components_resources.grd', 'grit_grd_file': 'resources/components_resources.grd',
'grit_additional_defines': [ 'grit_additional_defines': [
'-E', 'about_credits_file=<(about_credits_file)', '-E', 'about_credits_file=<(about_credits_file_bro)',
], ],
}, },
'includes': [ '../build/grit_action.gypi' ], 'includes': [ '../build/grit_action.gypi' ],
...@@ -41,6 +42,22 @@ ...@@ -41,6 +42,22 @@
], ],
'includes': [ '../build/grit_target.gypi' ], 'includes': [ '../build/grit_target.gypi' ],
}, },
{
'target_name': 'compressed_about_credits',
'type': 'none',
'actions': [
{
'variables': {
'input_file': '<(about_credits_file)',
'output_file': '<(about_credits_file_bro)',
},
'includes': ['../third_party/brotli/bro.gypi'],
}
],
'dependencies': [
'about_credits'
],
},
{ {
# GN version: //components/resources:about_credits # GN version: //components/resources:about_credits
'target_name': 'about_credits', 'target_name': 'about_credits',
......
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
import("//third_party/brotli/brotli.gni")
about_credits_file = "$target_gen_dir/about_credits.html" about_credits_file = "$target_gen_dir/about_credits.html"
about_credits_file_bro = "$target_gen_dir/about_credits.bro"
# GYP version: components/components_resources.gyp:components_resources # GYP version: components/components_resources.gyp:components_resources
group("resources") { group("resources") {
...@@ -29,11 +31,11 @@ grit("components_resources") { ...@@ -29,11 +31,11 @@ grit("components_resources") {
grit_flags = [ grit_flags = [
"-E", "-E",
"about_credits_file=" + rebase_path(about_credits_file, root_build_dir), "about_credits_file=" + rebase_path(about_credits_file_bro, root_build_dir),
] ]
deps = [ deps = [
":about_credits", ":compressed_about_credits",
] ]
} }
...@@ -55,6 +57,14 @@ grit("components_scaled_resources") { ...@@ -55,6 +57,14 @@ grit("components_scaled_resources") {
output_dir = "$root_gen_dir/components" output_dir = "$root_gen_dir/components"
} }
compress_file_brotli("compressed_about_credits") {
input_file = about_credits_file
output_file = about_credits_file_bro
deps = [
":about_credits",
]
}
# GYP version: components/components_resources.gyp:about_credits # GYP version: components/components_resources.gyp:about_credits
action("about_credits") { action("about_credits") {
script = "//tools/licenses.py" script = "//tools/licenses.py"
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
if (is_win) {
import("//build/config/win/visual_studio_version.gni")
}
source_set("brotli") { source_set("brotli") {
sources = [ sources = [
"dec/bit_reader.c", "dec/bit_reader.c",
...@@ -85,15 +89,16 @@ if (current_toolchain == host_toolchain) { ...@@ -85,15 +89,16 @@ if (current_toolchain == host_toolchain) {
":brotli", ":brotli",
] ]
if (is_win && visual_studio_version == "2015") {
# Disabling "result of 32-bit shift implicitly converted to 64 bits",
# caused by code like: foo |= (1 << i); // warning 4334
cflags = [ "/wd4334" ]
}
# Always build release since this is a build tool. # Always build release since this is a build tool.
if (is_debug) { if (is_debug) {
configs -= [ "//build/config:debug" ] configs -= [ "//build/config:debug" ]
configs += [ "//build/config:release" ] configs += [ "//build/config:release" ]
} }
if (is_posix) {
configs -= [ "//build/config/gcc:no_exceptions" ]
} else if (is_win) {
cflags_cc = [ "/EHsc" ]
}
} }
} }
...@@ -16,6 +16,8 @@ Local Modifications: ...@@ -16,6 +16,8 @@ Local Modifications:
tools. tools.
- Lines 659 of enc/hash.h and 66 of enc/cluster.h were modified to eliminate - Lines 659 of enc/hash.h and 66 of enc/cluster.h were modified to eliminate
build errors that appeared on Windows. build errors that appeared on Windows.
- Lines 290 - 304 from tools/bro.cc were adjusted to remove a try/catch block,
which are disabled by default in Chromium.
- BUILD.gn: Added. - BUILD.gn: Added.
- brotli.gyp: Added. - brotli.gyp: Added.
- brotli.gni: Added. - brotli.gni: Added.
......
...@@ -41,6 +41,6 @@ ...@@ -41,6 +41,6 @@
'<(output_file)', '<(output_file)',
], ],
'dependencies': [ 'dependencies': [
'<(DEPTH)/third_party/brotli/brotli.gyp:bro', '<(DEPTH)/third_party/brotli/brotli.gyp:bro#host',
], ],
} }
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
'cflags': ['-O2'], 'cflags': ['-O2'],
}], }],
], ],
'toolsets': ['host', 'target'],
}, },
{ {
'target_name': 'bro', 'target_name': 'bro',
...@@ -88,16 +89,12 @@ ...@@ -88,16 +89,12 @@
'enc/write_bits.h', 'enc/write_bits.h',
'tools/bro.cc', 'tools/bro.cc',
], ],
'toolsets': ['host'],
'conditions': [ 'conditions': [
['OS=="win"', { ['OS=="win" and MSVS_VERSION == "2015"', {
'msvs_settings': { # Disabling "result of 32-bit shift implicitly converted to 64 bits",
'VCCLCompilerTool': { # caused by code like: foo |= (1 << i); // warning 4334
'AdditionalOptions': [ '/EHsc', ], 'msvs_disabled_warnings': [ 4334, ],
},
},
}],
['os_posix==1', {
'cflags_cc!': [ '-fno-exceptions', ],
}], }],
], ],
} }
......
...@@ -287,16 +287,10 @@ int main(int argc, char** argv) { ...@@ -287,16 +287,10 @@ int main(int argc, char** argv) {
brotli::BrotliParams params; brotli::BrotliParams params;
params.lgwin = lgwin; params.lgwin = lgwin;
params.quality = quality; params.quality = quality;
try { brotli::BrotliFileIn in(fin, 1 << 16);
brotli::BrotliFileIn in(fin, 1 << 16); brotli::BrotliFileOut out(fout);
brotli::BrotliFileOut out(fout); if (!BrotliCompress(params, &in, &out)) {
if (!BrotliCompress(params, &in, &out)) { fprintf(stderr, "compression failed\n");
fprintf(stderr, "compression failed\n");
unlink(output_path);
exit(1);
}
} catch (std::bad_alloc&) {
fprintf(stderr, "not enough memory\n");
unlink(output_path); unlink(output_path);
exit(1); exit(1);
} }
......
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