From 296e4676e6286ba1f2296f6e778f78e8b4d27bea Mon Sep 17 00:00:00 2001 From: Gustav Sennton Date: Tue, 20 Jun 2017 17:13:46 +0100 Subject: Move native methods from WebViewFactory to WebViewLibraryLoader. To clean up WebViewFactory we are moving some of its functionality into a new class, WebViewLibraryLoader. Some of this functionality is native, and thus we need to update JNI registration code. Bug: 28736099 Test: start WebView-using app, ensure libwebviewchromium64.relro is loaded into the app process. Change-Id: I0dbf5d15fe33e75605e100850d06f48cb49b949c --- chromium/loader/loader.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/chromium/loader/loader.cpp b/chromium/loader/loader.cpp index 91c0a21..565c6b0 100644 --- a/chromium/loader/loader.cpp +++ b/chromium/loader/loader.cpp @@ -191,7 +191,9 @@ jint LoadWithRelroFile(JNIEnv* env, jclass, jstring lib32, jstring lib64, return ret; } -const char kClassName[] = "android/webkit/WebViewFactory"; +const char kWebViewFactoryClassName[] = "android/webkit/WebViewFactory"; +const char kWebViewLibraryLoaderClassName[] = + "android/webkit/WebViewLibraryLoader"; const JNINativeMethod kJniMethods[] = { { "nativeReserveAddressSpace", "(J)Z", reinterpret_cast(ReserveAddressSpace) }, @@ -208,10 +210,8 @@ const JNINativeMethod kJniMethods[] = { void RegisterWebViewFactory(JNIEnv* env) { // If either of these fail, it will set an exception that will be thrown on // return, so no need to handle errors here. - jclass clazz = env->FindClass(kClassName); + jclass clazz = env->FindClass(kWebViewFactoryClassName); if (clazz) { - env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods)); - LIBLOAD_SUCCESS = env->GetStaticIntField( clazz, env->GetStaticFieldID(clazz, "LIBLOAD_SUCCESS", "I")); @@ -234,6 +234,15 @@ void RegisterWebViewFactory(JNIEnv* env) { } } +void RegisterWebViewLibraryLoader(JNIEnv* env) { + // If either of these fail, it will set an exception that will be thrown on + // return, so no need to handle errors here. + jclass clazz = env->FindClass(kWebViewLibraryLoaderClassName); + if (clazz) { + env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods)); + } +} + } // namespace android JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) { @@ -243,5 +252,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) { return JNI_ERR; } android::RegisterWebViewFactory(env); + // Ensure there isn't a pending Java exception before registering methods from + // WebViewLibraryLoader + if (!env->ExceptionCheck()) { + android::RegisterWebViewLibraryLoader(env); + } return JNI_VERSION_1_6; } -- cgit v1.2.3