Commit 18c60acc authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Reland "[WebLayer] Load pak files correctly on Android"

This is a reland of cf1e154f

Added in the fixes from http://crrev.com/c/1867289 to fix browsertests.

Original change's description:
> [WebLayer] Load pak files correctly on Android
>
> Loading pak files was not quite working right in weblayer, since we were
> not loading locale paks. This caused text on e.g. submit buttons to not
> show up in some configurations like loading from monochrome.
>
> This change makes weblayer load pak assets similar to webview, and
> uses the webview pak deps for the weblayer support APK, since those
> should be sufficient for weblayer.
>
> As an added bonus this also allows l10n to work, so switching the
> default language of the device will show buttons and labels in that
> language.
>
> Change-Id: I1a2b47009e7bb74f1ea3c16dc6f52451e2b78066
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865015
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Reviewed-by: Richard Coles <torne@chromium.org>
> Commit-Queue: Clark DuVall <cduvall@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#706978}

TBR=jam@chromium.org,torne@chromium.org

Change-Id: I58961564500bcc92d05bf84e7372c2aca8a17c57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866925Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707167}
parent 6b6798f6
...@@ -13,7 +13,7 @@ bool NativeInit(base::android::LibraryProcessType library_process_type) { ...@@ -13,7 +13,7 @@ bool NativeInit(base::android::LibraryProcessType library_process_type) {
switch (library_process_type) { switch (library_process_type) {
case base::android::PROCESS_WEBLAYER: case base::android::PROCESS_WEBLAYER:
case base::android::PROCESS_WEBLAYER_CHILD: case base::android::PROCESS_WEBLAYER_CHILD:
return weblayer::OnJNIOnLoadInit("resources.pak"); return weblayer::OnJNIOnLoadInit();
break; break;
default: default:
return android_webview::OnJNIOnLoadInit(); return android_webview::OnJNIOnLoadInit();
......
...@@ -10,6 +10,7 @@ import("//build/config/locales.gni") ...@@ -10,6 +10,7 @@ import("//build/config/locales.gni")
import("//build/util/version.gni") import("//build/util/version.gni")
import("//chrome/android/trichrome.gni") import("//chrome/android/trichrome.gni")
import("//tools/v8_context_snapshot/v8_context_snapshot.gni") import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
import("//weblayer/variables.gni")
declare_args() { declare_args() {
# Android package name to use when compiling the system_webview_apk and # Android package name to use when compiling the system_webview_apk and
...@@ -34,7 +35,10 @@ template("system_webview_apk_tmpl") { ...@@ -34,7 +35,10 @@ template("system_webview_apk_tmpl") {
] ]
target_sdk_version = android_sdk_version target_sdk_version = android_sdk_version
locale_config_java_packages = [ webview_locale_config_java_package ] locale_config_java_packages = [
webview_locale_config_java_package,
weblayer_locale_config_java_package,
]
if (!defined(alternative_android_sdk_dep)) { if (!defined(alternative_android_sdk_dep)) {
alternative_android_sdk_dep = webview_framework_dep alternative_android_sdk_dep = webview_framework_dep
......
...@@ -14,6 +14,7 @@ import("//chrome/android/chrome_common_shared_library.gni") ...@@ -14,6 +14,7 @@ import("//chrome/android/chrome_common_shared_library.gni")
import("//chrome/android/features/dev_ui/dev_ui_module.gni") import("//chrome/android/features/dev_ui/dev_ui_module.gni")
import("//chrome/common/features.gni") import("//chrome/common/features.gni")
import("//device/vr/buildflags/buildflags.gni") import("//device/vr/buildflags/buildflags.gni")
import("//weblayer/variables.gni")
import("channel.gni") import("channel.gni")
declare_args() { declare_args() {
...@@ -344,6 +345,7 @@ template("monochrome_public_common_apk_or_module_tmpl") { ...@@ -344,6 +345,7 @@ template("monochrome_public_common_apk_or_module_tmpl") {
locale_config_java_packages = [ locale_config_java_packages = [
"org.chromium.chrome.browser", "org.chromium.chrome.browser",
webview_locale_config_java_package, webview_locale_config_java_package,
weblayer_locale_config_java_package,
] ]
if (android_64bit_target_cpu) { if (android_64bit_target_cpu) {
# Build //android_webview:monochrome with the opposite bitness that # Build //android_webview:monochrome with the opposite bitness that
......
...@@ -23,7 +23,7 @@ bool NativeInit(base::android::LibraryProcessType library_process_type) { ...@@ -23,7 +23,7 @@ bool NativeInit(base::android::LibraryProcessType library_process_type) {
break; break;
case base::android::PROCESS_WEBLAYER: case base::android::PROCESS_WEBLAYER:
case base::android::PROCESS_WEBLAYER_CHILD: case base::android::PROCESS_WEBLAYER_CHILD:
return weblayer::OnJNIOnLoadInit("resources.pak"); return weblayer::OnJNIOnLoadInit();
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
...@@ -96,6 +96,7 @@ template("test") { ...@@ -96,6 +96,7 @@ template("test") {
"android_manifest", "android_manifest",
"android_manifest_dep", "android_manifest_dep",
"enable_multidex", "enable_multidex",
"locale_config_java_packages",
"min_sdk_version", "min_sdk_version",
"proguard_configs", "proguard_configs",
"proguard_enabled", "proguard_enabled",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <iostream> #include <iostream>
#include "base/base_switches.h" #include "base/base_switches.h"
#include "base/command_line.h"
#include "base/cpu.h" #include "base/cpu.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -22,8 +23,12 @@ ...@@ -22,8 +23,12 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/android/apk_assets.h" #include "base/android/apk_assets.h"
#include "base/android/locale_utils.h"
#include "base/i18n/rtl.h"
#include "base/posix/global_descriptors.h" #include "base/posix/global_descriptors.h"
#include "content/public/browser/android/compositor.h" #include "content/public/browser/android/compositor.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "ui/base/ui_base_switches.h"
#include "weblayer/browser/android_descriptors.h" #include "weblayer/browser/android_descriptors.h"
#endif #endif
...@@ -118,34 +123,49 @@ int ContentMainDelegateImpl::RunProcess( ...@@ -118,34 +123,49 @@ int ContentMainDelegateImpl::RunProcess(
void ContentMainDelegateImpl::InitializeResourceBundle() { void ContentMainDelegateImpl::InitializeResourceBundle() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// On Android, the renderer runs with a different UID and can never access const base::CommandLine& command_line =
// the file system. Use the file descriptor passed in at launch time. *base::CommandLine::ForCurrentProcess();
auto* global_descriptors = base::GlobalDescriptors::GetInstance();
int pak_fd = global_descriptors->MaybeGet(kPakDescriptor); bool is_browser_process =
base::MemoryMappedFile::Region pak_region; command_line.GetSwitchValueASCII(switches::kProcessType).empty();
if (pak_fd >= 0) { if (is_browser_process) {
pak_region = global_descriptors->GetRegion(kPakDescriptor); ui::SetLocalePaksStoredInApk(true);
} else { std::string locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
pak_fd = base::android::OpenApkAsset( base::android::GetDefaultLocaleString(), nullptr,
std::string("assets/") + params_.pak_name, &pak_region); ui::ResourceBundle::LOAD_COMMON_RESOURCES);
if (pak_fd < 0) { if (locale.empty()) {
base::FilePath pak_file; LOG(WARNING) << "Failed to load locale .pak from apk.";
bool r = base::PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_file);
DCHECK(r);
pak_file = pak_file.Append(FILE_PATH_LITERAL("paks"));
pak_file = pak_file.AppendASCII(params_.pak_name);
int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
pak_fd = base::File(pak_file, flags).TakePlatformFile();
pak_region = base::MemoryMappedFile::Region::kWholeFile;
}
global_descriptors->Set(kPakDescriptor, pak_fd, pak_region);
} }
DCHECK_GE(pak_fd, 0); base::i18n::SetICUDefaultLocale(locale);
// This is clearly wrong. See crbug.com/330930
// Try to directly mmap the resources.pak from the apk. Fall back to load
// from file, using PATH_SERVICE, otherwise.
base::FilePath pak_file_path;
base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_file_path);
pak_file_path = pak_file_path.AppendASCII("resources.pak");
ui::LoadMainAndroidPackFile("assets/resources.pak", pak_file_path);
} else {
base::i18n::SetICUDefaultLocale(
command_line.GetSwitchValueASCII(switches::kLang));
auto* global_descriptors = base::GlobalDescriptors::GetInstance();
int pak_fd = global_descriptors->Get(kWebLayerLocalePakDescriptor);
base::MemoryMappedFile::Region pak_region =
global_descriptors->GetRegion(kWebLayerLocalePakDescriptor);
ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd), ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd),
pak_region); pak_region);
std::pair<int, ui::ScaleFactor> extra_paks[] = {
{kWebLayerMainPakDescriptor, ui::SCALE_FACTOR_NONE},
{kWebLayer100PercentPakDescriptor, ui::SCALE_FACTOR_100P}};
for (const auto& pak_info : extra_paks) {
pak_fd = global_descriptors->Get(pak_info.first);
pak_region = global_descriptors->GetRegion(pak_info.first);
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
base::File(pak_fd), pak_region, ui::SCALE_FACTOR_100P); base::File(pak_fd), pak_region, pak_info.second);
}
}
#else #else
base::FilePath pak_file; base::FilePath pak_file;
bool r = base::PathService::Get(base::DIR_ASSETS, &pak_file); bool r = base::PathService::Get(base::DIR_ASSETS, &pak_file);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace { namespace {
bool NativeInit(base::android::LibraryProcessType) { bool NativeInit(base::android::LibraryProcessType) {
return weblayer::OnJNIOnLoadInit("weblayer_support.pak"); return weblayer::OnJNIOnLoadInit();
} }
} // namespace } // namespace
......
...@@ -18,12 +18,11 @@ class MainDelegateImpl : public MainDelegate { ...@@ -18,12 +18,11 @@ class MainDelegateImpl : public MainDelegate {
}; };
// This is called by the VM when the shared library is first loaded. // This is called by the VM when the shared library is first loaded.
bool OnJNIOnLoadInit(const std::string& pak_name) { bool OnJNIOnLoadInit() {
if (!content::android::OnJNIOnLoadInit()) if (!content::android::OnJNIOnLoadInit())
return false; return false;
weblayer::MainParams params; weblayer::MainParams params;
params.delegate = new weblayer::MainDelegateImpl; params.delegate = new weblayer::MainDelegateImpl;
params.pak_name = pak_name;
params.brand = "WebLayer"; params.brand = "WebLayer";
base::android::SetVersionNumber(PRODUCT_VERSION); base::android::SetVersionNumber(PRODUCT_VERSION);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace weblayer { namespace weblayer {
bool OnJNIOnLoadInit(const std::string& pak_name); bool OnJNIOnLoadInit();
} // namespace weblayer } // namespace weblayer
......
...@@ -12,7 +12,9 @@ namespace weblayer { ...@@ -12,7 +12,9 @@ namespace weblayer {
// This is a list of global descriptor keys to be used with the // This is a list of global descriptor keys to be used with the
// base::GlobalDescriptors object (see base/posix/global_descriptors.h) // base::GlobalDescriptors object (see base/posix/global_descriptors.h)
enum { enum {
kPakDescriptor = kContentIPCDescriptorMax + 1, kWebLayerLocalePakDescriptor = kContentIPCDescriptorMax + 1,
kWebLayerMainPakDescriptor,
kWebLayer100PercentPakDescriptor,
}; };
} // namespace weblayer } // namespace weblayer
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include "weblayer/public/main.h" #include "weblayer/public/main.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "base/android/apk_assets.h"
#include "base/android/path_utils.h" #include "base/android/path_utils.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "weblayer/browser/android_descriptors.h" #include "weblayer/browser/android_descriptors.h"
#endif #endif
...@@ -149,10 +149,15 @@ void ContentBrowserClientImpl::GetAdditionalMappedFilesForChildProcess( ...@@ -149,10 +149,15 @@ void ContentBrowserClientImpl::GetAdditionalMappedFilesForChildProcess(
int child_process_id, int child_process_id,
content::PosixFileDescriptorInfo* mappings) { content::PosixFileDescriptorInfo* mappings) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
mappings->ShareWithRegion( base::MemoryMappedFile::Region region;
kPakDescriptor, int fd = ui::GetMainAndroidPackFd(&region);
base::GlobalDescriptors::GetInstance()->Get(kPakDescriptor), mappings->ShareWithRegion(kWebLayerMainPakDescriptor, fd, region);
base::GlobalDescriptors::GetInstance()->GetRegion(kPakDescriptor));
fd = ui::GetCommonResourcesPackFd(&region);
mappings->ShareWithRegion(kWebLayer100PercentPakDescriptor, fd, region);
fd = ui::GetLocalePackFd(&region);
mappings->ShareWithRegion(kWebLayerLocalePakDescriptor, fd, region);
#endif #endif
} }
#endif // defined(OS_LINUX) || defined(OS_ANDROID) #endif // defined(OS_LINUX) || defined(OS_ANDROID)
......
...@@ -4,12 +4,17 @@ ...@@ -4,12 +4,17 @@
import("//build/config/android/config.gni") import("//build/config/android/config.gni")
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
import("//weblayer/variables.gni")
android_resources("weblayer_resources") { android_resources("weblayer_resources") {
resource_dirs = [] resource_dirs = []
custom_package = "org.chromium.weblayer_private" custom_package = "org.chromium.weblayer_private"
} }
generate_locale_config_srcjar("weblayer_locale_config") {
java_package = weblayer_locale_config_java_package
}
android_library("java") { android_library("java") {
java_files = [ java_files = [
"org/chromium/weblayer_private/BrowserControllerImpl.java", "org/chromium/weblayer_private/BrowserControllerImpl.java",
...@@ -37,6 +42,8 @@ android_library("java") { ...@@ -37,6 +42,8 @@ android_library("java") {
"//content/public/android:content_java", "//content/public/android:content_java",
"//ui/android:ui_java", "//ui/android:ui_java",
] ]
srcjar_deps = [ ":weblayer_locale_config" ]
jar_excluded_patterns = [ "*/LocaleConfig.class" ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
......
...@@ -60,7 +60,7 @@ public final class WebLayerImpl extends IWebLayer.Stub { ...@@ -60,7 +60,7 @@ public final class WebLayerImpl extends IWebLayer.Stub {
Context context = ObjectWrapper.unwrap(webLayerContextWrapper, Context.class); Context context = ObjectWrapper.unwrap(webLayerContextWrapper, Context.class);
ContextUtils.initApplicationContext(context); ContextUtils.initApplicationContext(context);
ResourceBundle.setNoAvailableLocalePaks(); ResourceBundle.setAvailablePakLocales(new String[] {}, LocaleConfig.UNCOMPRESSED_LOCALES);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ChildProcessCreationParams.set(context.getPackageName(), false /* isExternalService */, ChildProcessCreationParams.set(context.getPackageName(), false /* isExternalService */,
......
...@@ -7,6 +7,7 @@ import("//build/config/android/config.gni") ...@@ -7,6 +7,7 @@ import("//build/config/android/config.gni")
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
import("//third_party/icu/config.gni") import("//third_party/icu/config.gni")
import("//tools/v8_context_snapshot/v8_context_snapshot.gni") import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
import("//weblayer/variables.gni")
android_assets("weblayer_shell_assets") { android_assets("weblayer_shell_assets") {
testonly = true testonly = true
...@@ -206,30 +207,14 @@ jinja_template("weblayer_support_manifest") { ...@@ -206,30 +207,14 @@ jinja_template("weblayer_support_manifest") {
output = weblayer_support_manifest output = weblayer_support_manifest
} }
android_assets("weblayer_support_assets") {
testonly = true
sources = [
"$root_out_dir/weblayer_support.pak",
]
disable_compression = true
deps = [
"//third_party/icu:icu_assets",
"//weblayer/shell:support_pak",
]
if (use_v8_context_snapshot) {
deps += [ "//tools/v8_context_snapshot:v8_context_snapshot_assets" ]
} else {
deps += [ "//v8:v8_external_startup_data_assets" ]
}
}
android_apk("weblayer_support_apk") { android_apk("weblayer_support_apk") {
testonly = true testonly = true
deps = [ deps = [
":weblayer_support_assets",
":weblayer_support_manifest", ":weblayer_support_manifest",
"//android_webview:locale_pak_assets",
"//android_webview:monochrome_webview_assets",
"//android_webview:pak_file_assets",
"//base:base_java", "//base:base_java",
"//weblayer/browser/java", "//weblayer/browser/java",
] ]
...@@ -249,6 +234,8 @@ android_apk("weblayer_support_apk") { ...@@ -249,6 +234,8 @@ android_apk("weblayer_support_apk") {
android_manifest_dep = ":weblayer_support_manifest" android_manifest_dep = ":weblayer_support_manifest"
shared_resources = true shared_resources = true
locale_config_java_packages = [ weblayer_locale_config_java_package ]
native_lib_version_rule = "//build/util:chrome_version_json" native_lib_version_rule = "//build/util:chrome_version_json"
_native_lib_file = _native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir) rebase_path("$root_gen_dir/CHROME_VERSION.json", root_build_dir)
......
...@@ -7,6 +7,7 @@ import("//build/config/ui.gni") ...@@ -7,6 +7,7 @@ import("//build/config/ui.gni")
import("//testing/test.gni") import("//testing/test.gni")
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
import("//tools/v8_context_snapshot/v8_context_snapshot.gni") import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
import("//weblayer/variables.gni")
if (is_android) { if (is_android) {
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
...@@ -41,18 +42,12 @@ if (is_android) { ...@@ -41,18 +42,12 @@ if (is_android) {
android_manifest_for_lint = weblayer_browsertests_manifest android_manifest_for_lint = weblayer_browsertests_manifest
} }
}
if (is_android) {
android_assets("weblayer_test_assets") { android_assets("weblayer_test_assets") {
testonly = true testonly = true
sources = [
"$root_out_dir/weblayer.pak",
]
disable_compression = true disable_compression = true
deps = [ deps = [
"//third_party/icu:icu_assets", "//third_party/icu:icu_assets",
"//weblayer/shell:pak",
] ]
if (use_v8_context_snapshot) { if (use_v8_context_snapshot) {
deps += [ "//tools/v8_context_snapshot:v8_context_snapshot_assets" ] deps += [ "//tools/v8_context_snapshot:v8_context_snapshot_assets" ]
...@@ -106,6 +101,8 @@ test("weblayer_browsertests") { ...@@ -106,6 +101,8 @@ test("weblayer_browsertests") {
deps += [ deps += [
":weblayer_browsertests_java", ":weblayer_browsertests_java",
":weblayer_test_assets", ":weblayer_test_assets",
"//android_webview:locale_pak_assets",
"//android_webview:pak_file_assets",
"//content/public/test/android:android_test_message_pump_support_java", "//content/public/test/android:android_test_message_pump_support_java",
"//content/test:android_test_message_pump_support", "//content/test:android_test_message_pump_support",
"//content/test:android_test_message_pump_support", "//content/test:android_test_message_pump_support",
...@@ -122,5 +119,6 @@ test("weblayer_browsertests") { ...@@ -122,5 +119,6 @@ test("weblayer_browsertests") {
android_manifest_dep = ":weblayer_browsertests_manifest" android_manifest_dep = ":weblayer_browsertests_manifest"
use_default_launcher = false use_default_launcher = false
shared_resources = true shared_resources = true
locale_config_java_packages = [ weblayer_locale_config_java_package ]
} }
} }
# Copyright 2019 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.
weblayer_locale_config_java_package = "org.chromium.weblayer_private"
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