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_result_codes.h" | 8 #include "android_webview/browser/aw_result_codes.h" |
9 #include "android_webview/native/aw_assets.h" | |
9 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
10 #include "base/android/memory_pressure_listener_android.h" | 11 #include "base/android/memory_pressure_listener_android.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/result_codes.h" | 18 #include "content/public/common/result_codes.h" |
18 #include "content/public/common/url_utils.h" | 19 #include "content/public/common/url_utils.h" |
19 #include "gpu/command_buffer/service/mailbox_synchronizer.h" | 20 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
20 #include "net/android/network_change_notifier_factory_android.h" | 21 #include "net/android/network_change_notifier_factory_android.h" |
21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
23 #include "ui/base/l10n/l10n_util.h" | |
22 #include "ui/base/l10n/l10n_util_android.h" | 24 #include "ui/base/l10n/l10n_util_android.h" |
23 #include "ui/base/layout.h" | 25 #include "ui/base/layout.h" |
24 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/base/ui_base_paths.h" | 27 #include "ui/base/ui_base_paths.h" |
26 | 28 |
27 namespace android_webview { | 29 namespace android_webview { |
28 | 30 |
29 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context) | 31 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context) |
30 : browser_context_(browser_context) { | 32 : browser_context_(browser_context) { |
31 } | 33 } |
32 | 34 |
33 AwBrowserMainParts::~AwBrowserMainParts() { | 35 AwBrowserMainParts::~AwBrowserMainParts() { |
34 } | 36 } |
35 | 37 |
36 void AwBrowserMainParts::PreEarlyInitialization() { | 38 void AwBrowserMainParts::PreEarlyInitialization() { |
37 net::NetworkChangeNotifier::SetFactory( | 39 net::NetworkChangeNotifier::SetFactory( |
38 new net::NetworkChangeNotifierFactoryAndroid()); | 40 new net::NetworkChangeNotifierFactoryAndroid()); |
39 | 41 |
40 // Android WebView does not use default MessageLoop. It has its own | 42 // Android WebView does not use default MessageLoop. It has its own |
41 // Android specific MessageLoop. Also see MainMessageLoopRun. | 43 // Android specific MessageLoop. Also see MainMessageLoopRun. |
42 DCHECK(!main_message_loop_.get()); | 44 DCHECK(!main_message_loop_.get()); |
43 main_message_loop_.reset(new base::MessageLoopForUI); | 45 main_message_loop_.reset(new base::MessageLoopForUI); |
44 base::MessageLoopForUI::current()->Start(); | 46 base::MessageLoopForUI::current()->Start(); |
45 } | 47 } |
46 | 48 |
47 int AwBrowserMainParts::PreCreateThreads() { | 49 int AwBrowserMainParts::PreCreateThreads() { |
48 ui::ResourceBundle::InitSharedInstanceLocaleOnly( | 50 int pak_fd = 0; |
49 l10n_util::GetDefaultLocale(), NULL); | 51 int64 pak_off = 0; |
52 int64 pak_len = 0; | |
50 | 53 |
51 base::FilePath pak_path; | 54 // Try to load the locale pak file directly from the apk, falling back to |
52 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); | 55 // the default ResourceBundle behavior, which uses PATH_SERVICE to locate the |
56 // files on the storage, in case of failure. | |
57 std::string locale_pak_file = l10n_util::GetApplicationLocale(l10n_util::GetDe faultLocale()) + ".pak"; | |
58 if (AwAssets::OpenAsset(locale_pak_file, &pak_fd, &pak_off, &pak_len)) { | |
59 VLOG(0) << "Loading " << locale_pak_file << " from FD: " << pak_fd << " OFF: " << pak_off << " LEN: " << pak_len; | |
mkosiba (inactive)
2014/07/21 14:20:58
aren't these lines a bit tooo loooonnnggg?
Primiano Tucci (use gerrit)
2014/07/21 17:20:02
Yeah, that's why the patchset was entitled "WIP" ;
| |
60 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | |
61 base::File(pak_fd), | |
62 base::File::Region(pak_off, pak_len), | |
63 /*should_load_common_resources=*/false); | |
mkosiba (inactive)
2014/07/21 14:20:58
nit: I _think_ it should be like: /*should_load_c
Primiano Tucci (use gerrit)
2014/07/21 17:20:03
A search in code search seems to suggest the contr
| |
64 } else { | |
mkosiba (inactive)
2014/07/21 14:20:58
does this make sense? If it's not there in the apk
benm (inactive)
2014/07/21 14:38:55
Long term, yes we should remove this. But for now
Primiano Tucci (use gerrit)
2014/07/21 17:20:02
Quoting Torne's previous comment in this CL:
"Yeah
| |
65 LOG(WARNING) << "Cannot load " << locale_pak_file << " assets from the apk." | |
66 " Falling back loading it using PATH_SERVICE."; | |
67 ui::ResourceBundle::InitSharedInstanceLocaleOnly( | |
68 l10n_util::GetDefaultLocale(), NULL); | |
69 } | |
53 | 70 |
54 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 71 // Same logic as above for the webviewchromium.pak. |
55 pak_path.AppendASCII("webviewchromium.pak"), | 72 if (AwAssets::OpenAsset("webviewchromium.pak", &pak_fd, &pak_off, &pak_len)) { |
56 ui::SCALE_FACTOR_NONE); | 73 VLOG(0) << "Loading pak from FD: " << pak_fd << " OFF: " << pak_off |
74 << " LEN: " << pak_len; | |
75 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( | |
76 base::File(pak_fd), base::File::Region(pak_off, pak_len), ui::SCALE_FACT OR_NONE); | |
77 } else { | |
78 base::FilePath pak_path; | |
79 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); | |
80 LOG(WARNING) << "Cannot load webviewchromium.pak assets from the apk. " | |
81 "Falling back loading it from " << pak_path.MaybeAsASCII(); | |
82 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
83 pak_path.AppendASCII("webviewchromium.pak"), | |
84 ui::SCALE_FACTOR_NONE); | |
85 } | |
57 | 86 |
58 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback( | 87 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback( |
59 base::android::AttachCurrentThread()); | 88 base::android::AttachCurrentThread()); |
60 | 89 |
61 return content::RESULT_CODE_NORMAL_EXIT; | 90 return content::RESULT_CODE_NORMAL_EXIT; |
62 } | 91 } |
63 | 92 |
64 void AwBrowserMainParts::PreMainMessageLoopRun() { | 93 void AwBrowserMainParts::PreMainMessageLoopRun() { |
65 // TODO(boliu): Can't support accelerated 2d canvas and WebGL with ubercomp | 94 // TODO(boliu): Can't support accelerated 2d canvas and WebGL with ubercomp |
66 // yet: crbug.com/352424. | 95 // yet: crbug.com/352424. |
67 if (!gpu::gles2::MailboxSynchronizer::Initialize()) { | 96 if (!gpu::gles2::MailboxSynchronizer::Initialize()) { |
68 CommandLine* cl = CommandLine::ForCurrentProcess(); | 97 CommandLine* cl = CommandLine::ForCurrentProcess(); |
69 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas); | 98 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas); |
70 cl->AppendSwitch(switches::kDisableExperimentalWebGL); | 99 cl->AppendSwitch(switches::kDisableExperimentalWebGL); |
71 } | 100 } |
72 | 101 |
73 browser_context_->PreMainMessageLoopRun(); | 102 browser_context_->PreMainMessageLoopRun(); |
74 // This is needed for WebView Classic backwards compatibility | 103 // This is needed for WebView Classic backwards compatibility |
75 // See crbug.com/298495 | 104 // See crbug.com/298495 |
76 content::SetMaxURLChars(20 * 1024 * 1024); | 105 content::SetMaxURLChars(20 * 1024 * 1024); |
77 } | 106 } |
78 | 107 |
79 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { | 108 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { |
80 // Android WebView does not use default MessageLoop. It has its own | 109 // Android WebView does not use default MessageLoop. It has its own |
81 // Android specific MessageLoop. | 110 // Android specific MessageLoop. |
82 return true; | 111 return true; |
83 } | 112 } |
84 | 113 |
85 } // namespace android_webview | 114 } // namespace android_webview |
OLD | NEW |