webview_entry_point.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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.
4
5#include "android_webview/lib/main/aw_main_delegate.h"
6#include "android_webview/native/android_webview_jni_registrar.h"
7#include "base/android/jni_android.h"
8#include "base/command_line.h"
9#include "content/public/app/android_library_loader_hooks.h"
10#include "content/public/app/content_main.h"
11#include "content/public/browser/android/compositor.h"
12#include "content/public/common/content_switches.h"
13
14// This is called by the VM when the shared library is first loaded.
15// Most of the initialization is done in LibraryLoadedOnMainThread(), not here.
16JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
17  base::android::InitVM(vm);
18  JNIEnv* env = base::android::AttachCurrentThread();
19  if (!content::RegisterLibraryLoaderEntryHook(env))
20    return -1;
21
22  if (!android_webview::RegisterJni(env))
23    return -1;
24
25  // Set the command line to enable synchronous API compatibility.
26  CommandLine::Init(0, NULL);
27  CommandLine::ForCurrentProcess()->AppendSwitch(
28      switches::kEnableWebViewSynchronousAPIs);
29
30  // TODO: The next two lines are temporarily required for the renderer
31  // initialization to not crash. Note that single process is already set in
32  // AwBrowserMainParts::PreEarlyInitialization, but Compositor requires this
33  // flag set.
34  // See BUG 152904.
35  CommandLine::ForCurrentProcess()->AppendSwitch(
36      switches::kSingleProcess);
37  content::Compositor::Initialize();
38
39  content::SetContentMainDelegate(new android_webview::AwMainDelegate());
40
41  return JNI_VERSION_1_4;
42}
43