Chromium Code Reviews

Side by Side Diff: android_webview/browser/aw_browser_main_parts.cc

Issue 1193613002: Convert Android WebView to store locale .pak files as res/raw resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-extractor-init
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/aw_browser_main_parts.h" 5 #include "android_webview/browser/aw_browser_main_parts.h"
6 6
7 #include "android_webview/browser/aw_browser_context.h" 7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_dev_tools_discovery_provider.h" 8 #include "android_webview/browser/aw_dev_tools_discovery_provider.h"
9 #include "android_webview/browser/aw_media_client_android.h" 9 #include "android_webview/browser/aw_media_client_android.h"
10 #include "android_webview/browser/aw_result_codes.h" 10 #include "android_webview/browser/aw_result_codes.h"
11 #include "android_webview/common/aw_resource.h" 11 #include "android_webview/common/aw_resource.h"
12 #include "base/android/apk_assets.h" 12 #include "base/android/apk_assets.h"
13 #include "base/android/build_info.h" 13 #include "base/android/build_info.h"
14 #include "base/android/locale_utils.h" 14 #include "base/android/locale_utils.h"
15 #include "base/android/memory_pressure_listener_android.h" 15 #include "base/android/memory_pressure_listener_android.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "content/public/common/result_codes.h" 21 #include "content/public/common/result_codes.h"
22 #include "content/public/common/url_utils.h" 22 #include "content/public/common/url_utils.h"
23 #include "media/base/android/media_client_android.h" 23 #include "media/base/android/media_client_android.h"
24 #include "net/android/network_change_notifier_factory_android.h" 24 #include "net/android/network_change_notifier_factory_android.h"
25 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/layout.h" 27 #include "ui/base/layout.h"
28 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/base/resource/resource_bundle_android.h"
29 #include "ui/base/ui_base_paths.h" 30 #include "ui/base/ui_base_paths.h"
30 31
31 namespace android_webview { 32 namespace android_webview {
32 33
33 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context) 34 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context)
34 : browser_context_(browser_context) { 35 : browser_context_(browser_context) {
35 } 36 }
36 37
37 AwBrowserMainParts::~AwBrowserMainParts() { 38 AwBrowserMainParts::~AwBrowserMainParts() {
38 } 39 }
(...skipping 15 matching lines...)
54 55
55 // TODO(primiano, mkosiba): GetApplicationLocale requires a ResourceBundle 56 // TODO(primiano, mkosiba): GetApplicationLocale requires a ResourceBundle
56 // instance to be present to work correctly so we call this (knowing it will 57 // instance to be present to work correctly so we call this (knowing it will
57 // fail) just to create the ResourceBundle instance. We should refactor 58 // fail) just to create the ResourceBundle instance. We should refactor
58 // ResourceBundle/GetApplicationLocale to not require an instance to be 59 // ResourceBundle/GetApplicationLocale to not require an instance to be
59 // initialized. 60 // initialized.
60 ui::ResourceBundle::InitSharedInstanceWithLocale( 61 ui::ResourceBundle::InitSharedInstanceWithLocale(
61 base::android::GetDefaultLocale(), 62 base::android::GetDefaultLocale(),
62 NULL, 63 NULL,
63 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); 64 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
64 std::string locale = 65 std::string locale = l10n_util::GetApplicationLocale(std::string());
65 "assets/" + l10n_util::GetApplicationLocale(std::string()) + ".pak"; 66 std::string pak_path = ui::GetPathForAndroidLocalePakWithinApk(locale);
66 int pak_fd = base::android::OpenApkAsset(locale, &pak_region); 67 int pak_fd = base::android::OpenApkAsset(pak_path, &pak_region);
67 if (pak_fd != -1) { 68 if (pak_fd != -1) {
68 ui::ResourceBundle::CleanupSharedInstance(); 69 ui::ResourceBundle::CleanupSharedInstance();
69 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( 70 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
70 base::File(pak_fd), pak_region); 71 base::File(pak_fd), pak_region);
71 } else { 72 } else {
72 LOG(WARNING) << "Failed to load " << locale << ".pak from the apk too. " 73 LOG(WARNING) << "Failed to load " << locale << ".pak from the apk. "
73 "Bringing up WebView without any locale"; 74 "Bringing up WebView without any locale";
74 } 75 }
75 76
76 // Try to directly mmap the webviewchromium.pak from the apk. Fall back to 77 // Try to directly mmap the webviewchromium.pak from the apk. Fall back to
77 // load from file, using PATH_SERVICE, otherwise. 78 // load from file, using PATH_SERVICE, otherwise.
78 pak_fd = base::android::OpenApkAsset("assets/webviewchromium.pak", 79 pak_fd = base::android::OpenApkAsset("assets/webviewchromium.pak",
79 &pak_region); 80 &pak_region);
80 if (pak_fd != -1) { 81 if (pak_fd != -1) {
81 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( 82 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
82 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE); 83 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE);
(...skipping 25 matching lines...)
108 content::SetMaxURLChars(20 * 1024 * 1024); 109 content::SetMaxURLChars(20 * 1024 * 1024);
109 } 110 }
110 111
111 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { 112 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) {
112 // Android WebView does not use default MessageLoop. It has its own 113 // Android WebView does not use default MessageLoop. It has its own
113 // Android specific MessageLoop. 114 // Android specific MessageLoop.
114 return true; 115 return true;
115 } 116 }
116 117
117 } // namespace android_webview 118 } // namespace android_webview
OLDNEW

Powered by Google App Engine