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
3 // found in the LICENSE file.
5 #include "android_webview/browser/aw_browser_main_parts.h"
7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_devtools_delegate.h"
9 #include "android_webview/browser/aw_result_codes.h"
10 #include "base/android/build_info.h"
11 #include "base/android/locale_utils.h"
12 #include "base/files/file_path.h"
13 #include "base/path_service.h"
14 #include "content/public/browser/android/compositor.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/common/content_client.h"
17 #include "content/public/common/result_codes.h"
18 #include "net/android/network_change_notifier_factory_android.h"
19 #include "net/base/network_change_notifier.h"
20 #include "ui/base/layout.h"
21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/ui_base_paths.h"
24 namespace android_webview
{
26 bool UseCompositorDirectDraw() {
27 return base::android::BuildInfo::GetInstance()->sdk_int() >= 16;
30 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext
* browser_context
)
31 : browser_context_(browser_context
) {
34 AwBrowserMainParts::~AwBrowserMainParts() {
37 void AwBrowserMainParts::PreEarlyInitialization() {
38 net::NetworkChangeNotifier::SetFactory(
39 new net::NetworkChangeNotifierFactoryAndroid());
40 content::Compositor::InitializeWithFlags(
41 content::Compositor::DIRECT_CONTEXT_ON_DRAW_THREAD
);
43 // Android WebView does not use default MessageLoop. It has its own
44 // Android specific MessageLoop. Also see MainMessageLoopRun.
45 DCHECK(!main_message_loop_
.get());
46 main_message_loop_
.reset(new MessageLoop(MessageLoop::TYPE_UI
));
47 MessageLoopForUI::current()->Start();
50 int AwBrowserMainParts::PreCreateThreads() {
51 browser_context_
->InitializeBeforeThreadCreation();
53 ui::ResourceBundle::InitSharedInstanceLocaleOnly(
54 base::android::GetDefaultLocale(), NULL
);
56 base::FilePath pak_path
;
57 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID
, &pak_path
);
59 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
60 pak_path
.AppendASCII("webviewchromium.pak"),
61 ui::SCALE_FACTOR_NONE
);
63 return content::RESULT_CODE_NORMAL_EXIT
;
66 void AwBrowserMainParts::PreMainMessageLoopRun() {
67 browser_context_
->PreMainMessageLoopRun();
68 devtools_delegate_
= new AwDevToolsDelegate(browser_context_
);
71 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code
) {
72 // Android WebView does not use default MessageLoop. It has its own
73 // Android specific MessageLoop.
77 void AwBrowserMainParts::PostMainMessageLoopRun() {
78 if (devtools_delegate_
)
79 devtools_delegate_
->Stop();
82 } // namespace android_webview