Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / resource_provider / android / android_hooks.cc
blobc84730fabc01111c2bf258763f77f3728fd83caa
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.
5 #include <vector>
7 #include "base/android/base_jni_onload.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/library_loader/library_loader_hooks.h"
10 #include "base/bind.h"
11 #include "components/resource_provider/jni/Main_jni.h"
13 namespace {
14 bool RegisterJNI(JNIEnv* env) {
15 return true;
18 bool Init() {
19 return true;
21 } // namespace
23 // This is called by the VM when the shared library is first loaded.
24 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
25 std::vector<base::android::RegisterCallback> register_callbacks;
26 register_callbacks.push_back(base::Bind(&RegisterJNI));
27 register_callbacks.push_back(
28 base::Bind(&resource_provider::RegisterNativesImpl));
30 std::vector<base::android::InitCallback> init_callbacks;
31 init_callbacks.push_back(base::Bind(&Init));
33 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
34 !base::android::OnJNIOnLoadInit(init_callbacks)) {
35 return -1;
38 // There cannot be two AtExitManagers at the same time. Remove the one from
39 // LibraryLoader as ApplicationRunner also uses one.
40 base::android::LibraryLoaderExitHook();
42 return JNI_VERSION_1_4;
45 extern "C" JNI_EXPORT void InitApplicationContext(
46 const base::android::JavaRef<jobject>& context) {
47 JNIEnv* env = base::android::AttachCurrentThread();
48 base::android::InitApplicationContext(env, context);
49 resource_provider::Java_Main_init(
50 env, base::android::GetApplicationContext());