| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 "blimp/client/app/android/blimp_library_loader.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/android/base_jni_onload.h" | |
| 10 #include "base/android/base_jni_registrar.h" | |
| 11 #include "base/android/jni_android.h" | |
| 12 #include "base/android/library_loader/library_loader_hooks.h" | |
| 13 #include "base/bind.h" | |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "blimp/client/app/android/blimp_app_jni_registrar.h" | |
| 16 #include "blimp/client/app/blimp_startup.h" | |
| 17 #include "blimp/client/public/android/blimp_jni_registrar.h" | |
| 18 #include "jni/BlimpLibraryLoader_jni.h" | |
| 19 #include "net/android/net_jni_registrar.h" | |
| 20 #include "ui/android/ui_android_jni_registrar.h" | |
| 21 #include "ui/gl/gl_surface.h" | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 bool OnLibrariesLoaded(JNIEnv* env, jclass clazz) { | |
| 26 blimp::client::InitializeLogging(); | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 bool OnJniInitializationComplete() { | |
| 31 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 bool RegisterJni(JNIEnv* env) { | |
| 36 if (!base::android::RegisterJni(env)) | |
| 37 return false; | |
| 38 | |
| 39 if (!net::android::RegisterJni(env)) | |
| 40 return false; | |
| 41 | |
| 42 if (!blimp::client::RegisterBlimpJni(env)) | |
| 43 return false; | |
| 44 | |
| 45 if (!blimp::client::RegisterBlimpAppJni(env)) | |
| 46 return false; | |
| 47 | |
| 48 if (!ui::RegisterUIAndroidJni(env)) | |
| 49 return false; | |
| 50 | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 namespace blimp { | |
| 57 namespace client { | |
| 58 | |
| 59 static jboolean StartBlimp(JNIEnv* env, | |
| 60 const base::android::JavaParamRef<jclass>& clazz) { | |
| 61 if (!InitializeMainMessageLoop()) | |
| 62 return false; | |
| 63 | |
| 64 base::MessageLoopForUI::current()->Start(); | |
| 65 | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { | |
| 70 return RegisterNativesImpl(env); | |
| 71 } | |
| 72 | |
| 73 } // namespace client | |
| 74 } // namespace blimp | |
| 75 | |
| 76 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | |
| 77 std::vector<base::android::RegisterCallback> register_callbacks; | |
| 78 register_callbacks.push_back(base::Bind(&RegisterJni)); | |
| 79 | |
| 80 std::vector<base::android::InitCallback> init_callbacks; | |
| 81 init_callbacks.push_back(base::Bind(&OnJniInitializationComplete)); | |
| 82 | |
| 83 // Although we only need to register JNI for base/ and blimp/, this follows | |
| 84 // the general Chrome for Android pattern, to be future-proof against future | |
| 85 // changes to JNI. | |
| 86 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || | |
| 87 !base::android::OnJNIOnLoadInit(init_callbacks)) { | |
| 88 return -1; | |
| 89 } | |
| 90 | |
| 91 return JNI_VERSION_1_4; | |
| 92 } | |
| OLD | NEW |