Skip to content

Commit

Permalink
Add resource whitelisting to android_webview pak files.
Browse files Browse the repository at this point in the history
This saves only 5kb off of webview's .apk.

BUG=641032

Review-Url: https://codereview.chromium.org/2343083003
Cr-Commit-Position: refs/heads/master@{#419622}
  • Loading branch information
agrieve authored and Commit bot committed Sep 20, 2016
1 parent f4c80bd commit 425d550
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 26 deletions.
36 changes: 35 additions & 1 deletion android_webview/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
import("//tools/grit/repack.gni")
import("//tools/resources/generate_resource_whitelist.gni")
import("system_webview_apk_tmpl.gni")
import("webview_repack_locales.gni")

Expand All @@ -18,6 +19,11 @@ if (!defined(use_webview_internal_framework)) {
use_webview_internal_framework = false
}

if (enable_resource_whitelist_generation) {
system_webview_pak_whitelist =
"$target_gen_dir/system_webview_pak_whitelist.txt"
}

system_webview_android_manifest =
"$target_gen_dir/system_webview_apk/AndroidManifest.xml"

Expand All @@ -38,6 +44,13 @@ jinja_template("system_webview_manifest") {
webview_repack_locales("repack_locales") {
input_locales = locales
output_locales = locales

if (enable_resource_whitelist_generation) {
repack_whitelist = system_webview_pak_whitelist
deps = [
":system_webview_pak_whitelist",
]
}
}

locale_pak_resources("locale_paks") {
Expand Down Expand Up @@ -115,6 +128,11 @@ repack("repack_pack") {
"//third_party/WebKit/public:resources",
]
output = "$target_gen_dir/resources.pak"

if (enable_resource_whitelist_generation) {
repack_whitelist = system_webview_pak_whitelist
deps += [ ":system_webview_pak_whitelist" ]
}
}

repack("repack_100_percent") {
Expand All @@ -129,6 +147,11 @@ repack("repack_100_percent") {
"//ui/resources",
]
output = "$target_gen_dir/chrome_100_percent.pak"

if (enable_resource_whitelist_generation) {
repack_whitelist = system_webview_pak_whitelist
deps += [ ":system_webview_pak_whitelist" ]
}
}

webview_license_path = "$target_gen_dir/webview_licenses.notice"
Expand Down Expand Up @@ -267,7 +290,8 @@ grit("generate_components_strings") {

# components_strings contains strings from all components. WebView
# will never display most of them, so we try to limit the included
# strings
# strings. This whitelist trims about 50% more than the compile-based
# whitelist generated by :system_webview_pak_whitelist.
whitelist = rebase_path("ui/grit_components_whitelist.txt")
inputs = [
whitelist,
Expand Down Expand Up @@ -404,6 +428,16 @@ if (android_64bit_target_cpu) {
}
}

if (enable_resource_whitelist_generation) {
generate_resource_whitelist("system_webview_pak_whitelist") {
deps = [
":libwebviewchromium",
]
input = "$root_out_dir/libwebviewchromium$shlib_extension.whitelist"
output = system_webview_pak_whitelist
}
}

source_set("common") {
sources = [
"browser/aw_browser_context.cc",
Expand Down
5 changes: 4 additions & 1 deletion android_webview/webview_repack_locales.gni
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import("webview_repack_locales_list.gni")
template("webview_repack_locales") {
repack_locales(target_name) {
forward_variables_from(invoker, "*")
if (!defined(deps)) {
deps = []
}

# Adding webview specific pak file? You should add it to
# webview_repack_locales_source_patterns, so it is also included in
Expand All @@ -20,7 +23,7 @@ template("webview_repack_locales") {
"${root_gen_dir}/content/app/strings/content_strings_",
"${root_gen_dir}/ui/strings/app_locale_settings_",
]
deps = [
deps += [
"//android_webview:generate_components_strings",
"//content/app/strings",
"//ui/strings:app_locale_settings",
Expand Down
28 changes: 4 additions & 24 deletions chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import("//chrome/chrome_paks.gni")
import("//chrome/common/features.gni")
import("//chrome/process_version_rc_template.gni")
import("//third_party/widevine/cdm/widevine.gni")
import("//tools/resources/generate_resource_whitelist.gni")
import("//ui/base/ui_features.gni")
import("//v8/gni/v8.gni")

Expand Down Expand Up @@ -1461,33 +1462,12 @@ if (is_android) {
}

if (enable_resource_whitelist_generation) {
action("resource_whitelist") {
assert(is_android,
"Resource whitelist currently implemented only on Android")

generate_resource_whitelist("resource_whitelist") {
deps = [
"//chrome/android:chrome",
]
script = "//tools/resources/generate_resource_whitelist.py"

_infile = "$root_out_dir/libchrome$shlib_extension.whitelist"
inputs = [
_infile,
]

_outfile = chrome_resource_whitelist
outputs = [
_outfile,
]

args = [
"-i",
rebase_path(_infile, root_build_dir),
"-o",
rebase_path(_outfile, root_build_dir),
"--out-dir=.",
"--use-existing-resource-ids",
]
input = "$root_out_dir/libchrome$shlib_extension.whitelist"
output = chrome_resource_whitelist
}
}

Expand Down
2 changes: 2 additions & 0 deletions tools/resources/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
per-file generate_resource_whitelist.*=agrieve@chromium.org
per-file generate_resource_whitelist.*=estevenson@chromium.org
48 changes: 48 additions & 0 deletions tools/resources/generate_resource_whitelist.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Generates the final .pak file whitelist that can be used by repack()'s
# repack_whitelist parameter. Used resources are tracked by the toolchain when
# enable_resource_whitelist_generation = true, and per-.o and per-.so .whitelist
# files are generated. However, there are a couple of IDs (IDS_VERSION_UI_32BIT
# and IDS_VERSION_UI_64BIT) that should always be included, and which are not
# referenced in code. This action adds in these two ids to an existing
# .so.whitelist.
#
# Variables
# input: Path to the .whitelist created by the toolchain.
# output: Path to write the output whitelist to.
#
# Example
# generate_resource_whitelist("pak_whitelist") {
# deps = [ ":my_shared_library" ]
# input = "$root_out_dir/libmy_shared_library$shlib_extension.whitelist"
# output = "$target_gen_dir/pak_whitelist.txt"
# }
template("generate_resource_whitelist") {
action(target_name) {
forward_variables_from(invoker, [ "deps" ])
assert(is_android,
"Resource whitelist currently implemented only on Android")

script = "//tools/resources/generate_resource_whitelist.py"

inputs = [
invoker.input,
]

outputs = [
invoker.output,
]

args = [
"-i",
rebase_path(invoker.input, root_build_dir),
"-o",
rebase_path(invoker.output, root_build_dir),
"--out-dir=.",
"--use-existing-resource-ids",
]
}
}

0 comments on commit 425d550

Please sign in to comment.