Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #include "content/browser/android/library_loader_hooks.h" | |
| 6 | |
| 7 #include "base/android/build_info.h" | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "base/android/path_utils.h" | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/debug/trace_event.h" | |
| 13 #include "base/file_path.h" | |
| 14 #include "base/file_util.h" | |
| 15 #include "base/logging.h" | |
| 16 #include "base/string_tokenizer.h" | |
| 17 #include "base/string_util.h" | |
| 18 #include "base/tracked_objects.h" | |
| 19 #include "content/browser/android/jni_helper.h" | |
| 20 #include "content/public/common/content_switches.h" | |
| 21 #include "media/base/android/media_player_bridge.h" | |
| 22 | |
| 23 namespace base { | |
| 24 bool RegisterSystemMessageHandler(JNIEnv* env); | |
| 25 } | |
| 26 | |
| 27 // The following arrays list the registration methods for all native methods | |
| 28 // required by either ChromeView or tests. They are registered in all | |
| 29 // processes. Native methods required only by the browser application in the | |
| 30 // browser process should be registered in InitBrowserProcess(). | |
| 31 | |
| 32 static RegistrationMethod kContentRegisteredMethods[] = { | |
| 33 { "MediaPlayerListener", | |
| 34 media::MediaPlayerBridge::RegisterMediaPlayerListener }, | |
| 35 }; | |
| 36 | |
| 37 static RegistrationMethod kBaseRegisteredMethods[] = { | |
| 38 { "BuildInfo", base::android::RegisterBuildInfo }, | |
| 39 { "PathUtils", base::android::RegisterPathUtils }, | |
| 40 { "SystemMessageHandler", base::RegisterSystemMessageHandler }, | |
| 41 }; | |
| 42 | |
| 43 // Return true if the registration of the given methods succeed. | |
| 44 bool RegisterNativeMethods(JNIEnv* env, | |
| 45 const RegistrationMethod* method, | |
| 46 size_t count) { | |
| 47 const RegistrationMethod* end = method + count; | |
| 48 while (method != end) { | |
| 49 if (!method->func(env) < 0) { | |
| 50 DLOG(ERROR) << method->name << " failed registration!"; | |
| 51 return false; | |
| 52 } | |
| 53 method++; | |
| 54 } | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz, | |
| 59 jobjectArray init_command_line) { | |
| 60 | |
| 61 // TODO(tedchoc): Initialize the native command line from the java array | |
| 62 // passed in. | |
| 63 | |
| 64 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 65 | |
| 66 if (command_line->HasSwitch(switches::kTraceStartup)) { | |
| 67 base::debug::TraceLog::GetInstance()->SetEnabled( | |
| 68 command_line->GetSwitchValueASCII(switches::kTraceStartup)); | |
| 69 } | |
| 70 | |
| 71 // Can only use event tracing after setting up the command line. | |
| 72 TRACE_EVENT0("jni", "JNI_OnLoad continuation"); | |
| 73 | |
| 74 logging::InitLogging(NULL, | |
| 75 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | |
| 76 logging::DONT_LOCK_LOG_FILE, | |
| 77 logging::DELETE_OLD_LOG_FILE, | |
| 78 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | |
| 79 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | |
| 80 logging::SetLogItems(false, // Process ID | |
| 81 false, // Thread ID | |
| 82 false, // Timestamp | |
| 83 false); // Tick count | |
| 84 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() | |
| 85 << ", default verbosity = " << logging::GetVlogVerbosity(); | |
| 86 | |
| 87 if (!RegisterNativeMethods(env, kBaseRegisteredMethods, | |
| 88 arraysize(kBaseRegisteredMethods))) | |
| 89 return JNI_FALSE; | |
| 90 | |
|
Yaron
2012/04/19 00:35:34
TODO(yfriedman): Add net registration
Ted C
2012/04/19 01:17:07
Done.
| |
| 91 if (!RegisterNativeMethods(env, kContentRegisteredMethods, | |
| 92 arraysize(kContentRegisteredMethods))) | |
| 93 return JNI_FALSE; | |
| 94 | |
| 95 return JNI_TRUE; | |
| 96 } | |
| 97 | |
| 98 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { | |
| 99 // TODO(bulach): use the jni generator once we move jni_helper methods here. | |
| 100 const JNINativeMethod kMethods[] = { | |
| 101 { "nativeLibraryLoadedOnMainThread", "([Ljava/lang/String;)Z", | |
| 102 reinterpret_cast<void*>(LibraryLoaderEntryHook) }, | |
| 103 }; | |
| 104 const int kMethodsSize = arraysize(kMethods); | |
| 105 // TODO(tedchoc): Upstream LibraryLoader.java to make this work. | |
| 106 const char kLibraryLoaderPath[] = | |
|
Yaron
2012/04/19 00:35:34
I'd just omit the libraryLaoder reference for now.
Ted C
2012/04/19 01:17:07
Removed the path but kept the rest to keep the unu
| |
| 107 "org/chromium/content/browser/LibraryLoader"; | |
| 108 base::android::ScopedJavaLocalRef<jclass> clazz = | |
| 109 base::android::GetClass(env, kLibraryLoaderPath); | |
| 110 | |
| 111 if (env->RegisterNatives(clazz.obj(), | |
| 112 kMethods, | |
| 113 kMethodsSize) < 0) { | |
| 114 return false; | |
| 115 } | |
| 116 return true; | |
| 117 } | |
| OLD | NEW |