Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: content/browser/android/library_loader_hooks.cc

Issue 10035034: Implement the skeleton of an android content shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary bits. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/library_loader_hooks.cc
diff --git a/content/browser/android/library_loader_hooks.cc b/content/browser/android/library_loader_hooks.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6b9c0f8cbcce81fc7eff3a93b8187c3e4a6c3d30
--- /dev/null
+++ b/content/browser/android/library_loader_hooks.cc
@@ -0,0 +1,117 @@
+// Copyright (c) 2010 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/browser/android/library_loader_hooks.h"
+
+#include "base/android/build_info.h"
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/path_utils.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/browser/android/jni_helper.h"
+#include "content/public/common/content_switches.h"
+#include "media/base/android/media_player_bridge.h"
+
+namespace base {
+bool RegisterSystemMessageHandler(JNIEnv* env);
+}
+
+// The following arrays list the registration methods for all native methods
+// required by either ChromeView or tests. They are registered in all
+// processes. Native methods required only by the browser application in the
+// browser process should be registered in InitBrowserProcess().
+
+static RegistrationMethod kContentRegisteredMethods[] = {
+ { "MediaPlayerListener",
+ media::MediaPlayerBridge::RegisterMediaPlayerListener },
+};
+
+static RegistrationMethod kBaseRegisteredMethods[] = {
+ { "BuildInfo", base::android::RegisterBuildInfo },
+ { "PathUtils", base::android::RegisterPathUtils },
+ { "SystemMessageHandler", base::RegisterSystemMessageHandler },
+};
+
+// Return true if the registration of the given methods succeed.
+bool RegisterNativeMethods(JNIEnv* env,
+ const RegistrationMethod* method,
+ size_t count) {
+ const RegistrationMethod* end = method + count;
+ while (method != end) {
+ if (!method->func(env) < 0) {
+ DLOG(ERROR) << method->name << " failed registration!";
+ return false;
+ }
+ method++;
+ }
+ return true;
+}
+
+jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz,
+ jobjectArray init_command_line) {
+
+ // TODO(tedchoc): Initialize the native command line from the java array
+ // passed in.
+
+ 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 (!RegisterNativeMethods(env, kBaseRegisteredMethods,
+ arraysize(kBaseRegisteredMethods)))
+ return JNI_FALSE;
+
Yaron 2012/04/19 00:35:34 TODO(yfriedman): Add net registration
Ted C 2012/04/19 01:17:07 Done.
+ if (!RegisterNativeMethods(env, kContentRegisteredMethods,
+ arraysize(kContentRegisteredMethods)))
+ return JNI_FALSE;
+
+ return JNI_TRUE;
+}
+
+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);
+ // TODO(tedchoc): Upstream LibraryLoader.java to make this work.
+ 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
+ "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;
+}

Powered by Google App Engine
This is Rietveld 408576698