webview_entry_point.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "android_webview/lib/webview_jni_onload.h"
  5. #include "base/android/base_jni_onload.h"
  6. #include "base/android/jni_android.h"
  7. #include "base/android/library_loader/library_loader_hooks.h"
  8. #if defined(WEBVIEW_INCLUDES_WEBLAYER)
  9. #include "weblayer/app/jni_onload.h"
  10. #include "weblayer/browser/web_view_compatibility_helper_impl.h"
  11. #endif
  12. namespace {
  13. bool NativeInit(base::android::LibraryProcessType library_process_type) {
  14. switch (library_process_type) {
  15. case base::android::PROCESS_WEBVIEW:
  16. case base::android::PROCESS_WEBVIEW_CHILD:
  17. // TODO(crbug.com/1230005): Remove these once we stop setting these two
  18. // process types from tests.
  19. case base::android::PROCESS_CHILD:
  20. case base::android::PROCESS_BROWSER:
  21. return android_webview::OnJNIOnLoadInit();
  22. case base::android::PROCESS_WEBVIEW_NONEMBEDDED:
  23. return base::android::OnJNIOnLoadInit();
  24. #if defined(WEBVIEW_INCLUDES_WEBLAYER)
  25. case base::android::PROCESS_WEBLAYER:
  26. case base::android::PROCESS_WEBLAYER_CHILD:
  27. return weblayer::OnJNIOnLoadInit();
  28. #endif
  29. default:
  30. NOTREACHED();
  31. return false;
  32. }
  33. }
  34. } // namespace
  35. // This is called by the VM when the shared library is first loaded.
  36. // Most of the initialization is done in LibraryLoadedOnMainThread(), not here.
  37. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
  38. base::android::InitVM(vm);
  39. #if defined(WEBVIEW_INCLUDES_WEBLAYER)
  40. if (!weblayer::MaybeRegisterNatives())
  41. return -1;
  42. #endif
  43. base::android::SetNativeInitializationHook(&NativeInit);
  44. return JNI_VERSION_1_4;
  45. }