OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/jni_android.h" | 5 #include "chrome/app/android/chrome_jni_onload.h" |
| 6 |
| 7 #include "base/android/library_loader/library_loader_hooks.h" |
6 #include "base/bind.h" | 8 #include "base/bind.h" |
7 #include "chrome/app/android/chrome_android_initializer.h" | 9 #include "chrome/app/android/chrome_android_initializer.h" |
| 10 #include "chrome/browser/android/chrome_jni_registrar.h" |
8 #include "content/public/app/content_jni_onload.h" | 11 #include "content/public/app/content_jni_onload.h" |
9 | 12 |
| 13 namespace chrome { |
| 14 namespace android { |
| 15 |
10 namespace { | 16 namespace { |
11 | 17 |
12 bool RegisterJNI(JNIEnv* env) { | 18 bool RegisterJNI(JNIEnv* env) { |
| 19 if (base::android::GetLibraryProcessType(env) == |
| 20 base::android::PROCESS_BROWSER) { |
| 21 return RegisterBrowserJNI(env); |
| 22 } |
13 return true; | 23 return true; |
14 } | 24 } |
15 | 25 |
16 bool Init() { | 26 bool Init() { |
17 // TODO(michaelbai): Move the JNI registration from RunChrome() to | |
18 // RegisterJNI(). | |
19 return RunChrome(); | 27 return RunChrome(); |
20 } | 28 } |
21 | 29 |
22 } // namespace | 30 } // namespace |
23 | 31 |
| 32 bool OnJNIOnLoadRegisterJNI( |
| 33 JavaVM* vm, |
| 34 base::android::RegisterCallback callback) { |
| 35 std::vector<base::android::RegisterCallback> register_callbacks; |
| 36 register_callbacks.push_back(callback); |
| 37 register_callbacks.push_back(base::Bind(&RegisterJNI)); |
| 38 return content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks); |
| 39 } |
24 | 40 |
25 // This is called by the VM when the shared library is first loaded. | 41 bool OnJNIOnLoadInit(base::android::InitCallback callback) { |
26 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | |
27 std::vector<base::android::RegisterCallback> register_callbacks; | |
28 register_callbacks.push_back(base::Bind(&RegisterJNI)); | |
29 std::vector<base::android::InitCallback> init_callbacks; | 42 std::vector<base::android::InitCallback> init_callbacks; |
| 43 init_callbacks.push_back(callback); |
30 init_callbacks.push_back(base::Bind(&Init)); | 44 init_callbacks.push_back(base::Bind(&Init)); |
31 if (!content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || | 45 return content::android::OnJNIOnLoadInit(init_callbacks); |
32 !content::android::OnJNIOnLoadInit(init_callbacks)) { | |
33 return -1; | |
34 } | |
35 return JNI_VERSION_1_4; | |
36 } | 46 } |
| 47 |
| 48 } // namespace android |
| 49 } // namespace chrome |
OLD | NEW |