Commit 0fdfa429 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Fix crash accessing resources on Monochrome official bundles

For monochrome bundles, we attempt to share chrome resources.
Unfortunately for us, official builds have an additional optimization
which de-duplicates chrome and webview resources, removing webview
resources from the chrome paks. Previously, we were not loading the
webview paks, since during local testing I was not using an official
build. This patch loads both webview and chrome paks, to make sure we
have access to all resources.

This was causing a crash in the safe browsing interstitial page, since
it uses resources shared with webview.

Bug: 1032644
Change-Id: I84d3044917d15bd5c5955c42c1a00082748e2f29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1960719Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723600}
parent 2507e4a0
......@@ -221,8 +221,10 @@ void ContentMainDelegateImpl::InitializeResourceBundle() {
if (is_browser_process) {
// If we're not being loaded from a bundle, locales will be loaded from the
// webview stored-locales directory. Otherwise, we are in Monochrome, and
// can use chrome's locale assets.
if (!base::android::BundleUtils::IsBundle())
// we load both chrome and webview's locale assets.
if (base::android::BundleUtils::IsBundle())
ui::SetLoadSecondaryLocalePaks(true);
else
ui::SetLocalePaksStoredInApk(true);
// Passing an empty |pref_locale| yields the system default locale.
std::string locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
......@@ -247,8 +249,8 @@ void ContentMainDelegateImpl::InitializeResourceBundle() {
base::MemoryMappedFile::Region region;
int fd = base::android::OpenApkAsset(kWebLayerLocalePath, &region);
CHECK_GE(fd, 0) << "Could not find " << kWebLayerLocalePath << " in APK.";
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
base::File(fd), region, ui::SCALE_FACTOR_NONE);
ui::ResourceBundle::GetSharedInstance()
.LoadSecondaryLocaleDataWithPakFileRegion(base::File(fd), region);
base::GlobalDescriptors::GetInstance()->Set(
kWebLayerSecondaryLocalePakDescriptor, fd, region);
}
......@@ -263,13 +265,16 @@ void ContentMainDelegateImpl::InitializeResourceBundle() {
ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd),
pak_region);
pak_fd = global_descriptors->Get(kWebLayerSecondaryLocalePakDescriptor);
pak_region =
global_descriptors->GetRegion(kWebLayerSecondaryLocalePakDescriptor);
ui::ResourceBundle::GetSharedInstance()
.LoadSecondaryLocaleDataWithPakFileRegion(base::File(pak_fd),
pak_region);
std::vector<std::pair<int, ui::ScaleFactor>> extra_paks = {
{kWebLayerMainPakDescriptor, ui::SCALE_FACTOR_NONE},
{kWebLayer100PercentPakDescriptor, ui::SCALE_FACTOR_100P}};
if (!base::android::BundleUtils::IsBundle()) {
extra_paks.push_back(
{kWebLayerSecondaryLocalePakDescriptor, ui::SCALE_FACTOR_NONE});
}
for (const auto& pak_info : extra_paks) {
pak_fd = global_descriptors->Get(pak_info.first);
......
......@@ -375,7 +375,11 @@ void ContentBrowserClientImpl::GetAdditionalMappedFilesForChildProcess(
fd = ui::GetLocalePackFd(&region);
mappings->ShareWithRegion(kWebLayerLocalePakDescriptor, fd, region);
if (!base::android::BundleUtils::IsBundle()) {
if (base::android::BundleUtils::IsBundle()) {
fd = ui::GetSecondaryLocalePackFd(&region);
mappings->ShareWithRegion(kWebLayerSecondaryLocalePakDescriptor, fd,
region);
} else {
mappings->ShareWithRegion(kWebLayerSecondaryLocalePakDescriptor,
base::GlobalDescriptors::GetInstance()->Get(
kWebLayerSecondaryLocalePakDescriptor),
......
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