chromium_linker_test_android.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file.
48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/android/jni_android.h"
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/android/jni_registrar.h"
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/android/library_loader/library_loader_hooks.h"
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/basictypes.h"
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/debug/debugger.h"
108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/logging.h"
118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/public/app/android_library_loader_hooks.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/public/app/content_main.h"
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/public/browser/android/compositor.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h"
158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/shell/android/shell_jni_registrar.h"
168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "content/shell/app/shell_main_delegate.h"
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// This is called by the VM when the shared library is first loaded.
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::android::SetLibraryLoadedHook(&content::LibraryLoaded);
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  base::android::InitVM(vm);
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  JNIEnv* env = base::android::AttachCurrentThread();
258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!base::android::RegisterLibraryLoaderEntryHook(env))
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return -1;
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // To be called only from the UI thread.  If loading the library is done on
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // a separate thread, this should be moved elsewhere.
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!content::android::RegisterShellJni(env))
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return -1;
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!content::RegisterLinkerTestsJni(env))
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return -1;
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  content::Compositor::Initialize();
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  content::SetContentMainDelegate(new content::ShellMainDelegate());
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return JNI_VERSION_1_4;
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
41