diff options
Diffstat (limited to 'content/app')
-rw-r--r-- | content/app/android/OWNERS | 5 | ||||
-rw-r--r-- | content/app/android/content_jni_registrar.cc | 28 | ||||
-rw-r--r-- | content/app/android/content_jni_registrar.h | 19 | ||||
-rw-r--r-- | content/app/android/library_loader_hooks.cc | 104 |
4 files changed, 156 insertions, 0 deletions
diff --git a/content/app/android/OWNERS b/content/app/android/OWNERS new file mode 100644 index 0000000..09e93ca --- /dev/null +++ b/content/app/android/OWNERS @@ -0,0 +1,5 @@ +jrg@chromium.org +michaelbai@chromium.org +sievers@chromium.org +yfriedman@chromium.org + diff --git a/content/app/android/content_jni_registrar.cc b/content/app/android/content_jni_registrar.cc new file mode 100644 index 0000000..e9c8e00 --- /dev/null +++ b/content/app/android/content_jni_registrar.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/app/android/content_jni_registrar.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "content/browser/android/command_line.h" +#include "content/browser/android/download_controller.h" +#include "content/browser/android/trace_event_binding.h" + +namespace content { +namespace android { + +base::android::RegistrationMethod kContentRegisteredMethods[] = { + { "CommandLine", RegisterCommandLine }, + { "DownloadController", DownloadController::RegisterDownloadController }, + { "TraceEvent", RegisterTraceEvent }, +}; + +bool RegisterJni(JNIEnv* env) { + return RegisterNativeMethods(env, kContentRegisteredMethods, + arraysize(kContentRegisteredMethods)); +} + +} // namespace android +} // namespace content diff --git a/content/app/android/content_jni_registrar.h b/content/app/android/content_jni_registrar.h new file mode 100644 index 0000000..df83785 --- /dev/null +++ b/content/app/android/content_jni_registrar.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_APP_ANDROID_CONTENT_JNI_REGISTRAR_H_ +#define CONTENT_APP_ANDROID_CONTENT_JNI_REGISTRAR_H_ + +#include <jni.h> + +namespace content { +namespace android { + +// Register all JNI bindings necessary for content. +bool RegisterJni(JNIEnv* env); + +} // namespace android +} // namespace content + +#endif // CONTENT_APP_ANDROID_CONTENT_JNI_REGISTRAR_H_ diff --git a/content/app/android/library_loader_hooks.cc b/content/app/android/library_loader_hooks.cc new file mode 100644 index 0000000..ef01391 --- /dev/null +++ b/content/app/android/library_loader_hooks.cc @@ -0,0 +1,104 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/app/android_library_loader_hooks.h" + +#include "base/android/base_jni_registrar.h" +#include "base/android/jni_registrar.h" +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/debug/trace_event.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/string_tokenizer.h" +#include "base/string_util.h" +#include "base/tracked_objects.h" +#include "content/app/android/content_jni_registrar.h" +#include "content/browser/android/command_line.h" +#include "content/public/common/content_switches.h" +#include "media/base/android/media_jni_registrar.h" +#include "net/android/net_jni_registrar.h" + +namespace { +base::AtExitManager* g_at_exit_manager = NULL; +} + +jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz, + jobjectArray init_command_line) { + // We need the Chrome AtExitManager to be created before we do any tracing or + // logging. + g_at_exit_manager = new base::AtExitManager(); + InitNativeCommandLineFromJavaArray(env, init_command_line); + + CommandLine* command_line = CommandLine::ForCurrentProcess(); + + if (command_line->HasSwitch(switches::kTraceStartup)) { + base::debug::TraceLog::GetInstance()->SetEnabled( + command_line->GetSwitchValueASCII(switches::kTraceStartup)); + } + + // Can only use event tracing after setting up the command line. + TRACE_EVENT0("jni", "JNI_OnLoad continuation"); + + logging::InitLogging(NULL, + logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, + logging::DONT_LOCK_LOG_FILE, + logging::DELETE_OLD_LOG_FILE, + logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); + // To view log output with IDs and timestamps use "adb logcat -v threadtime". + logging::SetLogItems(false, // Process ID + false, // Thread ID + false, // Timestamp + false); // Tick count + VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() + << ", default verbosity = " << logging::GetVlogVerbosity(); + + if (!base::android::RegisterJni(env)) + return JNI_FALSE; + + if (!net::android::RegisterJni(env)) + return JNI_FALSE; + + if (!content::android::RegisterJni(env)) + return JNI_FALSE; + + if (!media::RegisterJni(env)) + return JNI_FALSE; + + return JNI_TRUE; +} + +namespace content { + +void LibraryLoaderExitHook() { + if (g_at_exit_manager) { + delete g_at_exit_manager; + g_at_exit_manager = NULL; + } +} + +bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { + // TODO(bulach): use the jni generator once we move jni_helper methods here. + const JNINativeMethod kMethods[] = { + { "nativeLibraryLoadedOnMainThread", "([Ljava/lang/String;)Z", + reinterpret_cast<void*>(LibraryLoaderEntryHook) }, + }; + const int kMethodsSize = arraysize(kMethods); + const char kLibraryLoaderPath[] = + "org/chromium/content/browser/LibraryLoader"; + base::android::ScopedJavaLocalRef<jclass> clazz = + base::android::GetClass(env, kLibraryLoaderPath); + + if (env->RegisterNatives(clazz.obj(), + kMethods, + kMethodsSize) < 0) { + return false; + } + return true; +} + +} // namespace content |