OLD | NEW |
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 #include "ui/gl/gl_surface.h" | 31 #include "ui/gl/gl_surface.h" |
31 | 32 |
32 namespace android_webview { | 33 namespace android_webview { |
33 | 34 |
34 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context) | 35 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context) |
35 : browser_context_(browser_context) { | 36 : browser_context_(browser_context) { |
36 } | 37 } |
37 | 38 |
38 AwBrowserMainParts::~AwBrowserMainParts() { | 39 AwBrowserMainParts::~AwBrowserMainParts() { |
(...skipping 16 matching lines...) Expand all Loading... |
55 | 56 |
56 // TODO(primiano, mkosiba): GetApplicationLocale requires a ResourceBundle | 57 // TODO(primiano, mkosiba): GetApplicationLocale requires a ResourceBundle |
57 // instance to be present to work correctly so we call this (knowing it will | 58 // instance to be present to work correctly so we call this (knowing it will |
58 // fail) just to create the ResourceBundle instance. We should refactor | 59 // fail) just to create the ResourceBundle instance. We should refactor |
59 // ResourceBundle/GetApplicationLocale to not require an instance to be | 60 // ResourceBundle/GetApplicationLocale to not require an instance to be |
60 // initialized. | 61 // initialized. |
61 ui::ResourceBundle::InitSharedInstanceWithLocale( | 62 ui::ResourceBundle::InitSharedInstanceWithLocale( |
62 base::android::GetDefaultLocale(), | 63 base::android::GetDefaultLocale(), |
63 NULL, | 64 NULL, |
64 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); | 65 ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); |
65 std::string locale = | 66 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
66 "assets/" + l10n_util::GetApplicationLocale(std::string()) + ".pak"; | 67 std::string pak_path = ui::GetPathForAndroidLocalePakWithinApk(locale); |
67 int pak_fd = base::android::OpenApkAsset(locale, &pak_region); | 68 int pak_fd = base::android::OpenApkAsset(pak_path, &pak_region); |
68 if (pak_fd != -1) { | 69 if (pak_fd != -1) { |
69 ui::ResourceBundle::CleanupSharedInstance(); | 70 ui::ResourceBundle::CleanupSharedInstance(); |
70 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 71 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
71 base::File(pak_fd), pak_region); | 72 base::File(pak_fd), pak_region); |
72 } else { | 73 } else { |
73 LOG(WARNING) << "Failed to load " << locale << ".pak from the apk too. " | 74 LOG(WARNING) << "Failed to load " << locale << ".pak from the apk. " |
74 "Bringing up WebView without any locale"; | 75 "Bringing up WebView without any locale"; |
75 } | 76 } |
76 | 77 |
77 // Try to directly mmap the webviewchromium.pak from the apk. Fall back to | 78 // Try to directly mmap the webviewchromium.pak from the apk. Fall back to |
78 // load from file, using PATH_SERVICE, otherwise. | 79 // load from file, using PATH_SERVICE, otherwise. |
79 pak_fd = base::android::OpenApkAsset("assets/webviewchromium.pak", | 80 pak_fd = base::android::OpenApkAsset("assets/webviewchromium.pak", |
80 &pak_region); | 81 &pak_region); |
81 if (pak_fd != -1) { | 82 if (pak_fd != -1) { |
82 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( | 83 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( |
83 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE); | 84 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE); |
(...skipping 27 matching lines...) Expand all Loading... |
111 content::SetMaxURLChars(20 * 1024 * 1024); | 112 content::SetMaxURLChars(20 * 1024 * 1024); |
112 } | 113 } |
113 | 114 |
114 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { | 115 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { |
115 // Android WebView does not use default MessageLoop. It has its own | 116 // Android WebView does not use default MessageLoop. It has its own |
116 // Android specific MessageLoop. | 117 // Android specific MessageLoop. |
117 return true; | 118 return true; |
118 } | 119 } |
119 | 120 |
120 } // namespace android_webview | 121 } // namespace android_webview |
OLD | NEW |