11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Copyright 2014 The Chromium Authors. All rights reserved.
21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Use of this source code is governed by a BSD-style license that can be
31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// found in the LICENSE file.
41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/android/jni_android.h"
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/android/jni_registrar.h"
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/android/library_loader/library_loader_hooks.h"
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/basictypes.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/debug/debugger.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/logging.h"
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chromecast/android/cast_jni_registrar.h"
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chromecast/android/platform_jni_loader.h"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chromecast/shell/app/cast_main_delegate.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/app/android_library_loader_hooks.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/app/content_main.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/android/compositor.h"
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This is called by the VM when the shared library is first loaded.
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciJNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::android::SetLibraryLoadedHook(&content::LibraryLoaded);
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::android::InitVM(vm);
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  JNIEnv* env = base::android::AttachCurrentThread();
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1;
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // To be called only from the UI thread.  If loading the library is done on
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // a separate thread, this should be moved elsewhere.
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!chromecast::android::RegisterJni(env)) return -1;
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Allow platform-specific implementations to perform more JNI registration.
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!chromecast::android::PlatformRegisterJni(env)) return -1;
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  content::Compositor::Initialize();
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return JNI_VERSION_1_4;
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
37