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

Side by Side Diff: mojo/shell/android/bootstrap.cc

Issue 772393003: Android handler: inject the application loading part from the shell .so. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase. Created 6 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/android/jni_android.h" 5 #include "base/android/jni_android.h"
6 #include "base/android/jni_string.h" 6 #include "base/android/jni_string.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/scoped_native_library.h"
10 #include "jni/Bootstrap_jni.h" 9 #include "jni/Bootstrap_jni.h"
11 #include "mojo/shell/dynamic_service_runner.h" 10 #include "mojo/shell/android/run_android_application_function.h"
12 11
13 namespace mojo { 12 namespace mojo {
14 13
15 namespace {
16 // Most applications will need to access the Android ApplicationContext in which
17 // they are run. If the application library exports the InitApplicationContext
18 // function, we will set it there.
19 void SetApplicationContextIfNeeded(
20 JNIEnv* env,
21 const base::ScopedNativeLibrary& app_library,
22 jobject context) {
23 const char* init_application_context_name = "InitApplicationContext";
24 typedef void (*InitApplicationContextFn)(
25 const base::android::JavaRef<jobject>&);
26 InitApplicationContextFn init_application_context =
27 reinterpret_cast<InitApplicationContextFn>(
28 app_library.GetFunctionPointer(init_application_context_name));
29 if (init_application_context) {
30 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
31 init_application_context(scoped_context);
32 }
33 }
34
35 } // namespace
36
37 void Bootstrap(JNIEnv* env, 14 void Bootstrap(JNIEnv* env,
38 jobject, 15 jobject,
39 jobject j_context, 16 jobject j_context,
40 jstring j_native_library_path, 17 jstring j_native_library_path,
41 jint j_handle) { 18 jint j_handle,
19 jlong j_run_application_ptr) {
42 base::FilePath app_path( 20 base::FilePath app_path(
43 base::android::ConvertJavaStringToUTF8(env, j_native_library_path)); 21 base::android::ConvertJavaStringToUTF8(env, j_native_library_path));
44 ScopedMessagePipeHandle handle((mojo::MessagePipeHandle(j_handle))); 22 RunAndroidApplicationFn run_android_application_fn =
45 23 reinterpret_cast<RunAndroidApplicationFn>(j_run_application_ptr);
46 // Load the library, so that we can set the application context there if 24 run_android_application_fn(env, j_context, app_path, j_handle);
47 // needed.
48 base::NativeLibraryLoadError error;
49 base::ScopedNativeLibrary app_library(
50 base::LoadNativeLibrary(app_path, &error));
51 if (!app_library.is_valid()) {
52 LOG(ERROR) << "Failed to load app library (error: " << error.ToString()
53 << ")";
54 return;
55 }
56 SetApplicationContextIfNeeded(env, app_library, j_context);
57
58 // Run the application.
59 base::ScopedNativeLibrary app_library_from_runner(
60 shell::DynamicServiceRunner::LoadAndRunService(app_path, handle.Pass()));
61 } 25 }
62 26
63 bool RegisterBootstrapJni(JNIEnv* env) { 27 bool RegisterBootstrapJni(JNIEnv* env) {
64 return RegisterNativesImpl(env); 28 return RegisterNativesImpl(env);
65 } 29 }
66 30
67 } // namespace mojo 31 } // namespace mojo
68 32
69 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 33 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
70 base::android::InitVM(vm); 34 base::android::InitVM(vm);
71 JNIEnv* env = base::android::AttachCurrentThread(); 35 JNIEnv* env = base::android::AttachCurrentThread();
72 36
73 if (!mojo::RegisterBootstrapJni(env)) 37 if (!mojo::RegisterBootstrapJni(env))
74 return -1; 38 return -1;
75 39
76 return JNI_VERSION_1_4; 40 return JNI_VERSION_1_4;
77 } 41 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698