15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "android_webview/lib/main/aw_main_delegate.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "android_webview/native/android_webview_jni_registrar.h" 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/jni_android.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/android/jni_registrar.h" 903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/android/jni_utils.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/android/library_loader/library_loader_hooks.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "components/navigation_interception/component_jni_registrar.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "components/web_contents_delegate_android/component_jni_registrar.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/app/android_library_loader_hooks.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/app/content_main.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "url/url_util.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static base::android::RegistrationMethod 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kWebViewDependencyRegisteredMethods[] = { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { "NavigationInterception", 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) navigation_interception::RegisterNavigationInterceptionJni }, 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { "WebContentsDelegateAndroid", 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) web_contents_delegate_android::RegisterWebContentsDelegateAndroidJni }, 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is called by the VM when the shared library is first loaded. 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Most of the initialization is done in LibraryLoadedOnMainThread(), not here. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::android::SetLibraryLoadedHook(&content::LibraryLoaded); 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::android::InitVM(vm); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!base::android::RegisterLibraryLoaderEntryHook(env)) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return -1; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Register content JNI functions now, rather than waiting until 370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // LibraryLoadedOnMainThread, so that we can call into native code early. 380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (!content::EnsureJniRegistered(env)) 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return -1; 400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Register JNI for components we depend on. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!RegisterNativeMethods( 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env, 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kWebViewDependencyRegisteredMethods, 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) arraysize(kWebViewDependencyRegisteredMethods))) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return -1; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!android_webview::RegisterJni(env)) 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return -1; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::android::InitReplacementClassLoader(env, 5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::android::GetClassLoader(env)); 5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::SetContentMainDelegate(new android_webview::AwMainDelegate()); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Initialize url lib here while we are still single-threaded, in case we use 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // CookieManager before initializing Chromium (which would normally have done 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // this). It's safe to call this multiple times. 59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) url::Initialize(); 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return JNI_VERSION_1_4; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 63