以android 4.2爲例java
1, android 4.2中 WebViewClassic.java 爲 WebView.java的代理類.android
2,程序運行後,瀏覽器首先加載webkit so.c++
WebViewCore.java ,apk 運行後只加載一次.web
static {瀏覽器
// Load libwebcore and libchromium_net during static initialization.app
// This happens in the zygote process so they will be shared read-onlyide
// across all app processes.spa
try {代理
System.loadLibrary("chromium_net");blog
System.loadLibrary("webcore");
} catch (UnsatisfiedLinkError e) {
Log.e(LOGTAG, "Unable to load native support libraries.");
}
3,loadLibary 後則會初始化對應的JNI.將framwork 層webkit與c++ 層關聯對應起來.
主要處理在 WebCoreJniOnLoad.cpp
static RegistrationMethod gWebCoreRegMethods[] = {
{ "JavaBridge", android::registerJavaBridge },
{ "WebFrame", android::registerWebFrame },
{ "WebViewCore", android::registerWebViewCore },
{ "WebHistory", android::registerWebHistory },
{ "WebIconDatabase", android::registerWebIconDatabase },
{ "WebSettingsClassic", android::registerWebSettings },
#if ENABLE(DATABASE)
{ "WebStorage", android::registerWebStorage },
#endif
{ "WebView", android::registerWebView },
{ "ViewStateSerializer", android::registerViewStateSerializer },
{ "GeolocationPermissions", android::registerGeolocationPermissions },
{ "MockGeolocation", android::registerMockGeolocation },
#if ENABLE(VIDEO)
{ "HTML5Audio", android::registerMediaPlayerAudio },
{ "HTML5VideoViewProxy", android::registerMediaPlayerVideo },
#endif
{ "DeviceMotionAndOrientationManager", android::registerDeviceMotionAndOrientationManager },
{ "CookieManager", android::registerCookieManager },
{ "CacheManager", android::registerCacheManager },
};
4.建立WebView:
webview1 = (WebView) findViewById(R.id.WebView1);
該行調用後,則會初始webkit ,java 及c++ 層的關鍵類.
下圖是各重要的類,建立流程.
5,android 瀏覽器上實現式.
android 手機瀏覽器,經過建立WebView.組織WebView 來實現的. 每打開一個窗口(一個Tab) 則建立一個webview.
即,android 瀏覽器存在多個webview.