diff options
-rw-r--r-- | android_webview/android_webview.gyp | 8 | ||||
-rw-r--r-- | android_webview/android_webview_tests.gypi | 2 | ||||
-rw-r--r-- | android_webview/browser/DEPS | 1 | ||||
-rw-r--r-- | android_webview/browser/aw_browser_main_parts.cc | 60 | ||||
-rw-r--r-- | android_webview/test/shell/src/org/chromium/android_webview/shell/AwShellApplication.java | 4 | ||||
-rwxr-xr-x | build/android/gyp/package_resources.py | 6 | ||||
-rw-r--r-- | build/java_apk.gypi | 3 | ||||
-rw-r--r-- | chrome/app/chrome_main_delegate.cc | 6 | ||||
-rw-r--r-- | content/shell/app/shell_main_delegate.cc | 4 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.cc | 8 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.h | 12 |
11 files changed, 92 insertions, 22 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index f07f38a..cf93d1c 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -83,6 +83,14 @@ 'pak_output': '<(PRODUCT_DIR)/android_webview_apk/assets/webviewchromium.pak', }, 'includes': [ '../build/repack_action.gypi' ], + }, + { + 'action_name': 'add_en_US_pak_locale', + 'variables': { + 'pak_inputs': ['<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_en-US.pak'], + 'pak_output': '<(PRODUCT_DIR)/android_webview_apk/assets/en-US.pak', + }, + 'includes': [ '../build/repack_action.gypi' ], } ], }, diff --git a/android_webview/android_webview_tests.gypi b/android_webview/android_webview_tests.gypi index 390732a..95731df 100644 --- a/android_webview/android_webview_tests.gypi +++ b/android_webview/android_webview_tests.gypi @@ -16,8 +16,10 @@ 'java_in_dir': 'test/shell', 'native_lib_target': 'libstandalonelibwebviewchromium', 'resource_dir': 'test/shell/res', + 'extensions_to_not_compress': 'pak', 'additional_input_paths': [ '<(PRODUCT_DIR)/android_webview_apk/assets/webviewchromium.pak', + '<(PRODUCT_DIR)/android_webview_apk/assets/en-US.pak', '<(PRODUCT_DIR)/android_webview_apk/assets/asset_file.html', '<(PRODUCT_DIR)/android_webview_apk/assets/cookie_test.html', '<(PRODUCT_DIR)/android_webview_apk/assets/asset_icon.png', 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()); diff --git a/android_webview/test/shell/src/org/chromium/android_webview/shell/AwShellApplication.java b/android_webview/test/shell/src/org/chromium/android_webview/shell/AwShellApplication.java index b019d8a..697bbff 100644 --- a/android_webview/test/shell/src/org/chromium/android_webview/shell/AwShellApplication.java +++ b/android_webview/test/shell/src/org/chromium/android_webview/shell/AwShellApplication.java @@ -21,9 +21,7 @@ public class AwShellApplication extends Application { private static final String TAG = "AwShellApplication"; /** The minimum set of .pak files the test runner needs. */ - private static final String[] MANDATORY_PAKS = { - "webviewchromium.pak", "en-US.pak", "icudtl.dat" - }; + private static final String[] MANDATORY_PAKS = { "icudtl.dat" }; @Override public void onCreate() { diff --git a/build/android/gyp/package_resources.py b/build/android/gyp/package_resources.py index 7a7e16c..77cc276 100755 --- a/build/android/gyp/package_resources.py +++ b/build/android/gyp/package_resources.py @@ -40,6 +40,8 @@ def ParseArgs(): help='zip files containing resources to be packaged') parser.add_option('--asset-dir', help='directories containing assets to be packaged') + parser.add_option('--no-compress', help='disables compression for the ' + 'given comma separated list of extensions') parser.add_option('--apk-path', help='Path to output (partial) apk.') @@ -104,6 +106,10 @@ def main(): '-F', options.apk_path, ] + if options.no_compress: + for ext in options.no_compress.split(','): + package_command += ['-0', ext] + if os.path.exists(options.asset_dir): package_command += ['-A', options.asset_dir] diff --git a/build/java_apk.gypi b/build/java_apk.gypi index d22cfe1..5b54e57 100644 --- a/build/java_apk.gypi +++ b/build/java_apk.gypi @@ -79,6 +79,7 @@ 'additional_res_packages': [], 'additional_bundled_libs%': [], 'is_test_apk%': 0, + 'extensions_to_not_compress%': '', 'resource_input_paths': [], 'intermediate_dir': '<(PRODUCT_DIR)/<(_target_name)', 'asset_location%': '<(intermediate_dir)/assets', @@ -858,6 +859,8 @@ '--asset-dir', '<(asset_location)', '--resource-zips', '>(package_resource_zip_input_paths)', + '--no-compress', '<(extensions_to_not_compress)', + '--apk-path', '<(resource_packaged_apk_path)', ], }, diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index a2be6f1..3f30351 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -723,8 +723,10 @@ void ChromeMainDelegate::PreSandboxStartup() { int locale_pak_fd = base::GlobalDescriptors::GetInstance()->MaybeGet( kAndroidLocalePakDescriptor); CHECK(locale_pak_fd != -1); - ResourceBundle::InitSharedInstanceWithPakFile(base::File(locale_pak_fd), - false); + ResourceBundle::InitSharedInstanceWithPakFileRegion( + base::File(locale_pak_fd), + base::MemoryMappedFile::Region::kWholeFile, + false); int extra_pak_keys[] = { kAndroidChrome100PercentPakDescriptor, diff --git a/content/shell/app/shell_main_delegate.cc b/content/shell/app/shell_main_delegate.cc index 8a6913e..1af3303 100644 --- a/content/shell/app/shell_main_delegate.cc +++ b/content/shell/app/shell_main_delegate.cc @@ -267,8 +267,8 @@ void ShellMainDelegate::InitializeResourceBundle() { base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor); if (pak_fd >= 0) { // This is clearly wrong. See crbug.com/330930 - ui::ResourceBundle::InitSharedInstanceWithPakFile(base::File(pak_fd), - false); + ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( + base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile, false); ResourceBundle::GetSharedInstance().AddDataPackFromFile( base::File(pak_fd), ui::SCALE_FACTOR_100P); return; diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index 95fd2f2..0ae7924 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -174,15 +174,17 @@ std::string ResourceBundle::InitSharedInstanceLocaleOnly( } // static -void ResourceBundle::InitSharedInstanceWithPakFile( - base::File pak_file, bool should_load_common_resources) { +void ResourceBundle::InitSharedInstanceWithPakFileRegion( + base::File pak_file, + const base::MemoryMappedFile::Region& region, + bool should_load_common_resources) { InitSharedInstance(NULL); if (should_load_common_resources) g_shared_instance_->LoadCommonResources(); scoped_ptr<DataPack> data_pack( new DataPack(SCALE_FACTOR_100P)); - if (!data_pack->LoadFromFile(pak_file.Pass())) { + if (!data_pack->LoadFromFileRegion(pak_file.Pass(), region)) { NOTREACHED() << "failed to load pak file"; return; } diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index 1e6ca16d..b0e9cdb 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -132,12 +132,16 @@ class UI_BASE_EXPORT ResourceBundle { static std::string InitSharedInstanceLocaleOnly( const std::string& pref_locale, Delegate* delegate); - // Initialize the ResourceBundle using given file. The second argument - // controls whether or not ResourceBundle::LoadCommonResources is called. + // Initialize the ResourceBundle using the given file region. If |region| is + // MemoryMappedFile::Region::kWholeFile, the entire |pak_file| is used. + // |should_load_common_resources| controls whether or not LoadCommonResources + // is called. // This allows the use of this function in a sandbox without local file // access (as on Android). - static void InitSharedInstanceWithPakFile(base::File file, - bool should_load_common_resources); + static void InitSharedInstanceWithPakFileRegion( + base::File pak_file, + const base::MemoryMappedFile::Region& region, + bool should_load_common_resources); // Initialize the ResourceBundle using given data pack path for testing. static void InitSharedInstanceWithPakPath(const base::FilePath& path); |