OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/debug/debugger.h" |
| 7 #include "base/logging.h" |
6 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
7 #include "base/android/jni_registrar.h" | 9 #include "base/android/jni_registrar.h" |
| 10 #include "content/public/app/content_main_runner.h" |
8 #include "content/public/browser/android_library_loader_hooks.h" | 11 #include "content/public/browser/android_library_loader_hooks.h" |
9 #include "content/shell/shell_main_delegate.h" | 12 #include "content/shell/shell_main_delegate.h" |
10 #include "content/shell/android/shell_manager.h" | 13 #include "content/shell/android/shell_manager.h" |
11 #include "content/shell/android/shell_view.h" | 14 #include "content/shell/android/shell_view.h" |
12 | 15 |
13 static base::android::RegistrationMethod kRegistrationMethods[] = { | 16 static base::android::RegistrationMethod kRegistrationMethods[] = { |
14 { "ShellManager", content::RegisterShellManager }, | 17 { "ShellManager", content::RegisterShellManager }, |
15 { "ShellView", content::ShellView::Register }, | 18 { "ShellView", content::ShellView::Register }, |
16 }; | 19 }; |
17 | 20 |
| 21 namespace { |
| 22 content::ContentMainRunner* g_content_main_runner = NULL; |
| 23 } |
| 24 |
18 // This is called by the VM when the shared library is first loaded. | 25 // This is called by the VM when the shared library is first loaded. |
19 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 26 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 27 |
| 28 // Don't call anything in base without initializing it. |
| 29 // ContentMainRunner will do what we need. |
| 30 g_content_main_runner = content::ContentMainRunner::Create(); |
| 31 |
| 32 // TODO(tedchoc): Set this to the main delegate once the Android specific |
| 33 // browser process initialization gets checked in. |
| 34 ShellMainDelegate* delegate = new ShellMainDelegate(); |
| 35 |
| 36 // We use a ShellContentClient, created as a member of |
| 37 // ShellMainDelegate and set with a call to |
| 38 // content::SetContentClient() in PreSandboxStartup(). |
| 39 // That must be done before ContentMainRunner::Initialize(). |
| 40 // TODO(jrg): resolve the upstream/downstream discrepancy; we |
| 41 // shouldn't need to do this. |
| 42 delegate->PreSandboxStartup(); |
| 43 |
| 44 // TODO(jrg): find command line info from java; pass down in here. |
| 45 g_content_main_runner->Initialize(0, NULL, NULL); |
| 46 |
20 base::android::InitVM(vm); | 47 base::android::InitVM(vm); |
21 JNIEnv* env = base::android::AttachCurrentThread(); | 48 JNIEnv* env = base::android::AttachCurrentThread(); |
22 if (!RegisterLibraryLoaderEntryHook(env)) { | 49 if (!RegisterLibraryLoaderEntryHook(env)) { |
23 return -1; | 50 return -1; |
24 } | 51 } |
25 | 52 |
26 // To be called only from the UI thread. If loading the library is done on | 53 // To be called only from the UI thread. If loading the library is done on |
27 // a separate thread, this should be moved elsewhere. | 54 // a separate thread, this should be moved elsewhere. |
28 if (!base::android::RegisterNativeMethods(env, kRegistrationMethods, | 55 if (!base::android::RegisterNativeMethods(env, kRegistrationMethods, |
29 arraysize(kRegistrationMethods))) | 56 arraysize(kRegistrationMethods))) |
30 return -1; | 57 return -1; |
31 | 58 |
32 // TODO(tedchoc): Set this to the main delegate once the Android specific | |
33 // browser process initialization gets checked in. | |
34 new ShellMainDelegate(); | |
35 | |
36 return JNI_VERSION_1_4; | 59 return JNI_VERSION_1_4; |
37 } | 60 } |
| 61 |
| 62 |
| 63 JNI_EXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) { |
| 64 delete g_content_main_runner; |
| 65 g_content_main_runner = NULL; |
| 66 } |
| 67 |
OLD | NEW |