blob: 769fcf4f1809914af4c08429e6271ae365f3e8a7 [file] [log] [blame]
[email protected]f81fa202012-10-25 23:32:281// 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
3// found in the LICENSE file.
4
5#include "android_webview/browser/aw_browser_main_parts.h"
6
7#include "android_webview/browser/aw_browser_context.h"
ben5be0b9132016-08-03 00:17:188#include "android_webview/browser/aw_content_browser_client.h"
dgozman0115d2a262015-04-22 18:39:139#include "android_webview/browser/aw_dev_tools_discovery_provider.h"
[email protected]f81fa202012-10-25 23:32:2810#include "android_webview/browser/aw_result_codes.h"
boliuc5befe72015-07-21 19:08:5611#include "android_webview/browser/deferred_gpu_command_service.h"
timvolodinebbaeb5b2016-03-02 19:58:4712#include "android_webview/browser/net/aw_network_change_notifier_factory.h"
gunsch2288c532015-04-30 03:58:4513#include "android_webview/common/aw_resource.h"
boliu1463e1e2015-07-23 00:18:0414#include "android_webview/common/aw_switches.h"
agrieve3b864c92015-05-27 18:08:3815#include "base/android/apk_assets.h"
[email protected]197284842012-11-20 03:39:0116#include "base/android/build_info.h"
yfriedman38b461382014-10-20 19:40:1617#include "base/android/locale_utils.h"
[email protected]e1632c92013-09-30 00:47:5918#include "base/android/memory_pressure_listener_android.h"
boliu1463e1e2015-07-23 00:18:0419#include "base/command_line.h"
[email protected]57999812013-02-24 05:40:5220#include "base/files/file_path.h"
boliu40123db2016-01-16 01:38:2021#include "base/i18n/rtl.h"
[email protected]17237f12012-12-06 17:37:3522#include "base/path_service.h"
mnaganovf322c8f2016-01-08 02:49:3123#include "components/crash/content/browser/crash_micro_dump_manager_android.h"
boliu1463e1e2015-07-23 00:18:0424#include "content/public/browser/android/synchronous_compositor.h"
Jochen Eisinger14ea9772015-07-24 12:04:3725#include "content/public/browser/render_frame_host.h"
[email protected]f81fa202012-10-25 23:32:2826#include "content/public/browser/render_process_host.h"
27#include "content/public/common/content_client.h"
[email protected]2df8d412014-03-15 05:28:4128#include "content/public/common/content_switches.h"
[email protected]f81fa202012-10-25 23:32:2829#include "content/public/common/result_codes.h"
mcasas4e216e72016-07-28 21:28:3830#include "device/geolocation/access_token_store.h"
31#include "device/geolocation/geolocation_delegate.h"
32#include "device/geolocation/geolocation_provider.h"
[email protected]f81fa202012-10-25 23:32:2833#include "net/android/network_change_notifier_factory_android.h"
34#include "net/base/network_change_notifier.h"
[email protected]dd1c2a72014-07-29 18:11:3335#include "ui/base/l10n/l10n_util.h"
[email protected]17237f12012-12-06 17:37:3536#include "ui/base/layout.h"
[email protected]f81fa202012-10-25 23:32:2837#include "ui/base/resource/resource_bundle.h"
agrievebffa19f32015-06-25 19:55:3438#include "ui/base/resource/resource_bundle_android.h"
[email protected]17237f12012-12-06 17:37:3539#include "ui/base/ui_base_paths.h"
tobiasjsca238b3b2015-06-24 22:53:5440#include "ui/gl/gl_surface.h"
[email protected]f81fa202012-10-25 23:32:2841
42namespace android_webview {
mcasas80ef5232016-07-22 23:00:4743namespace {
44
mcasas4e216e72016-07-28 21:28:3845class AwAccessTokenStore : public device::AccessTokenStore {
mcasas80ef5232016-07-22 23:00:4746 public:
47 AwAccessTokenStore() { }
48
mcasas4e216e72016-07-28 21:28:3849 // device::AccessTokenStore implementation
mcasas80ef5232016-07-22 23:00:4750 void LoadAccessTokens(const LoadAccessTokensCallback& request) override {
51 AccessTokenStore::AccessTokenMap access_token_map;
52 // AccessTokenMap and net::URLRequestContextGetter not used on Android,
53 // but Run needs to be called to finish the geolocation setup.
54 request.Run(access_token_map, NULL);
55 }
56 void SaveAccessToken(const GURL& server_url,
57 const base::string16& access_token) override {}
58
59 private:
60 ~AwAccessTokenStore() override {}
61
62 DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore);
63};
64
65// A provider of Geolocation services to override AccessTokenStore.
mcasas4e216e72016-07-28 21:28:3866class AwGeolocationDelegate : public device::GeolocationDelegate {
mcasas80ef5232016-07-22 23:00:4767 public:
68 AwGeolocationDelegate() = default;
69
mcasas4e216e72016-07-28 21:28:3870 scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() final {
mcasas80ef5232016-07-22 23:00:4771 return new AwAccessTokenStore();
72 }
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(AwGeolocationDelegate);
76};
77
78} // anonymous namespace
[email protected]f81fa202012-10-25 23:32:2879
ben5be0b9132016-08-03 00:17:1880AwBrowserMainParts::AwBrowserMainParts(AwContentBrowserClient* browser_client)
81 : browser_client_(browser_client) {
[email protected]f81fa202012-10-25 23:32:2882}
83
84AwBrowserMainParts::~AwBrowserMainParts() {
85}
86
87void AwBrowserMainParts::PreEarlyInitialization() {
timvolodinebbaeb5b2016-03-02 19:58:4788 net::NetworkChangeNotifier::SetFactory(new AwNetworkChangeNotifierFactory());
[email protected]f81fa202012-10-25 23:32:2889
90 // Android WebView does not use default MessageLoop. It has its own
[email protected]f4d884432013-01-08 03:08:5091 // Android specific MessageLoop. Also see MainMessageLoopRun.
[email protected]f81fa202012-10-25 23:32:2892 DCHECK(!main_message_loop_.get());
[email protected]166f2ed2013-12-19 19:34:0093 main_message_loop_.reset(new base::MessageLoopForUI);
[email protected]9e1d6b12013-04-27 04:48:4494 base::MessageLoopForUI::current()->Start();
[email protected]f81fa202012-10-25 23:32:2895}
96
97int AwBrowserMainParts::PreCreateThreads() {
agrieve96cd9182015-06-25 20:50:2698 ui::SetLocalePaksStoredInApk(true);
mnaganov2f73f792015-08-21 16:24:4899 std::string locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
yfriedman38b461382014-10-20 19:40:16100 base::android::GetDefaultLocale(),
[email protected]4ce2aa62014-08-14 01:05:49101 NULL,
aberent3bcea372016-08-16 12:12:53102 ui::ResourceBundle::LOAD_COMMON_RESOURCES);
mnaganov2f73f792015-08-21 16:24:48103 if (locale.empty()) {
104 LOG(WARNING) << "Failed to load locale .pak from the apk. "
105 "Bringing up WebView without any locale";
[email protected]dd1c2a72014-07-29 18:11:33106 }
boliu40123db2016-01-16 01:38:20107 base::i18n::SetICUDefaultLocale(locale);
[email protected]c11f4fe2013-02-19 19:50:46108
aberent3bcea372016-08-16 12:12:53109 // Try to directly mmap the resources.pak from the apk. Fall back to load
110 // from file, using PATH_SERVICE, otherwise.
111 base::FilePath pak_file_path;
112 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_file_path);
113 pak_file_path = pak_file_path.AppendASCII("resources.pak");
114 ui::LoadMainAndroidPackFile("assets/resources.pak", pak_file_path);
[email protected]17237f12012-12-06 17:37:35115
[email protected]e1632c92013-09-30 00:47:59116 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(
117 base::android::AttachCurrentThread());
boliuc5befe72015-07-21 19:08:56118 DeferredGpuCommandService::SetInstance();
mnaganovf322c8f2016-01-08 02:49:31119 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kSingleProcess)) {
121 // Create the renderers crash manager on the UI thread.
122 breakpad::CrashMicroDumpManager::GetInstance();
123 }
[email protected]e1632c92013-09-30 00:47:59124
[email protected]f81fa202012-10-25 23:32:28125 return content::RESULT_CODE_NORMAL_EXIT;
126}
127
[email protected]f2ab1b152013-01-25 04:38:41128void AwBrowserMainParts::PreMainMessageLoopRun() {
ben5be0b9132016-08-03 00:17:18129 browser_client_->InitBrowserContext()->PreMainMessageLoopRun();
dgozman0115d2a262015-04-22 18:39:13130
mcasas4e216e72016-07-28 21:28:38131 device::GeolocationProvider::SetGeolocationDelegate(
mcasas80ef5232016-07-22 23:00:47132 new AwGeolocationDelegate());
133
dgozmanec2b982a2015-04-28 10:36:39134 AwDevToolsDiscoveryProvider::Install();
dgozman0115d2a262015-04-22 18:39:13135
Jochen Eisinger14ea9772015-07-24 12:04:37136 content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView();
[email protected]f2ab1b152013-01-25 04:38:41137}
138
[email protected]f81fa202012-10-25 23:32:28139bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) {
140 // Android WebView does not use default MessageLoop. It has its own
141 // Android specific MessageLoop.
142 return true;
143}
144
[email protected]f81fa202012-10-25 23:32:28145} // namespace android_webview