diff options
author | primiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-29 18:11:33 +0000 |
---|---|---|
committer | primiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-29 18:11:33 +0000 |
commit | dd1c2a75d2dacd95526ec21ab765098fd931def8 (patch) | |
tree | 0ac7959e93bb4e1e299df3f43b24a832c3f3c8c7 /android_webview/browser | |
parent | ee9eef6a6f5656da2305fc103282ae613ac8e309 (diff) | |
download | chromium_src-dd1c2a75d2dacd95526ec21ab765098fd931def8.zip chromium_src-dd1c2a75d2dacd95526ec21ab765098fd931def8.tar.gz chromium_src-dd1c2a75d2dacd95526ec21ab765098fd931def8.tar.bz2 |
[android_webview] Do not extract webviewchromium.pak
- Change the android_webview_apk gyp files to include the en-US.pak
file in the apk, which was erroneously missing.
- Add the do_not_compress gyp plumbing to store and zipalign paks in
the apk (only for the android_webview_apk target).
- Stop decompressing pak files in the android webview shell apk.
- Change aw_browser_main_parts.cc to take advantage of the new AwAssets
and DataPack/ResourceBundle *FromRegion methods (mmap from the apk).
- Add temporary workaround which loads always the en-US.pak locale, in
lack of a proper refactoring of i10n_utils and ResourceBundle.
BUG=394502
Review URL: https://codereview.chromium.org/402603006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/browser')
-rw-r--r-- | android_webview/browser/DEPS | 1 | ||||
-rw-r--r-- | android_webview/browser/aw_browser_main_parts.cc | 60 |
2 files changed, 53 insertions, 8 deletions
diff --git a/android_webview/browser/DEPS b/android_webview/browser/DEPS index 417b2c9..eb70713 100644 --- a/android_webview/browser/DEPS +++ b/android_webview/browser/DEPS @@ -2,6 +2,7 @@ include_rules = [ "-android_webview", "+android_webview/browser", "+android_webview/common", + "+android_webview/native", "+android_webview/public/browser", "+cc", diff --git a/android_webview/browser/aw_browser_main_parts.cc b/android_webview/browser/aw_browser_main_parts.cc index 29e9003..2abc6c2c 100644 --- a/android_webview/browser/aw_browser_main_parts.cc +++ b/android_webview/browser/aw_browser_main_parts.cc @@ -6,6 +6,7 @@ #include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_result_codes.h" +#include "android_webview/native/aw_assets.h" #include "base/android/build_info.h" #include "base/android/memory_pressure_listener_android.h" #include "base/command_line.h" @@ -19,6 +20,7 @@ #include "gpu/command_buffer/service/mailbox_synchronizer.h" #include "net/android/network_change_notifier_factory_android.h" #include "net/base/network_change_notifier.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_android.h" #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" @@ -45,15 +47,57 @@ void AwBrowserMainParts::PreEarlyInitialization() { } int AwBrowserMainParts::PreCreateThreads() { - ui::ResourceBundle::InitSharedInstanceLocaleOnly( - l10n_util::GetDefaultLocale(), NULL); - - base::FilePath pak_path; - PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); + int pak_fd = 0; + int64 pak_off = 0; + int64 pak_len = 0; + + // TODO(primiano): at present state there is a cyclic logic dependency + // between l10n_util::GetApplicationLocale and our code here. l10n_util + // decides which locale to ultimately use by scanning the pak files in the + // data folder. What we ultimately want to achieve is knowing the pak file to + // load from the apk beforehand, without looking at the data folder at all. + // Fixing this cyclic dependency involves some refactoring in ResourceBundle + // and l10n_util. + // In the meanwhile we use the mmap path only as a fallback (i.e. we check + // first for the existence of the pak files in the data dir). In the immediate + // future this order should be reversed, and we should look in the data + // directory only if we failed to mmap the pak file from the apk. + bool did_init_from_file = !ui::ResourceBundle::InitSharedInstanceLocaleOnly( + l10n_util::GetDefaultLocale(), NULL).empty(); + if (!did_init_from_file) { + LOG(WARNING) << "Failed to load the locale pak from PATH_SERVICE. " + " Trying to mmap en-US.pak from the apk"; + if (AwAssets::OpenAsset("en-US.pak", &pak_fd, &pak_off, &pak_len)) { + VLOG(0) << "Load from apk succesful, fd=" << pak_fd << " off=" << pak_off + << " len=" << pak_len; + ui::ResourceBundle::CleanupSharedInstance(); + ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( + base::File(pak_fd), + base::MemoryMappedFile::Region(pak_off, pak_len), + /*should_load_common_resources=*/false); + } else { + LOG(WARNING) << "Failed to load en-US.pak from the apk too. " + "Bringing up WebView without any locale"; + } + } - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( - pak_path.AppendASCII("webviewchromium.pak"), - ui::SCALE_FACTOR_NONE); + // Try to directly mmap the webviewchromium.pak from the apk. Fall back to + // load from file, using PATH_SERVICE, otherwise. + if (AwAssets::OpenAsset("webviewchromium.pak", &pak_fd, &pak_off, &pak_len)) { + VLOG(0) << "Loading webviewchromium.pak from, fd:" << pak_fd + << " off:" << pak_off << " len:" << pak_len; + ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( + base::File(pak_fd), + base::MemoryMappedFile::Region(pak_off, pak_len), + ui::SCALE_FACTOR_NONE); + } else { + base::FilePath pak_path; + PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); + LOG(WARNING) << "Cannot load webviewchromium.pak assets from the apk. " + "Falling back loading it from " << pak_path.MaybeAsASCII(); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( + pak_path.AppendASCII("webviewchromium.pak"), ui::SCALE_FACTOR_NONE); + } base::android::MemoryPressureListenerAndroid::RegisterSystemCallback( base::android::AttachCurrentThread()); |