Reprint Please specify the source http://blog.csdn.net/typename/powered by Miechal Zhao: [email protected]Objective:
According to Google's release of the Android system version of the market share (Google Android dashboards), Android 4.0 and more than 90% of the system, the trend is bound to be almost Android 4.0 or more on the market in the future. This article focuses on Android 4.0 and above system WebView implementation, from Android WebView implementation of the framework layer can be divided roughly into three segments Android 4.0 series, Android 4.1---4.3 series, Android 4.4 and above series.
WebView differences
WebView is an Android system that provides a system control that can display a Web page, it is a special view, and it is also a viewgroup can have many other sub-view. Under Android 4.4 (not including 4.4) system WebView The underlying implementation is using the WebKit (http://www.webkit.org/) core, while Android 4.4 and above Google uses chromium (http:/ /www.chromium.org/) as the underlying kernel support for system webview. The WebView-related APIs that Android has provided in this change have not changed greatly, and in 4.4 It is also compatible with the low-version API and has introduced a small portion of the API. Here is a brief introduction to the WebView based on the chromium and the WebKit WebView based differences, based on chromium webview to provide a broader html5,css3,javascript support, in the current latest Android The majority of HTML5 feature support is provided on system version 5.0 based on chromium 37,webview. Webkit JavaScript causes the use of WebCore JavaScript on Android 4.4 to replace V8 to directly improve JavaScript performance. In addition chromium supports remote debugging (Chrome DevTools).
WebKit for WebView VS Chromium for WebView performance (test environment Xiaomi 2. CM Browser. Android 4.1.1 VS 4.4.3)
|
Webkit for Webview |
Chromium for Webview |
Note |
HTML5
| 278 |
434 |
http://html5test.com/ |
remote debugging
|
support |
android 4.4 and above support |
memory consumption
| small |
big |
20-30m around |
webaudio
|
support |
android 5.0 and above support |
WEBGL
|
support |
android 5.0 and above support |
| WebRTC |
Not supported |
Support |
Android 5.0 and above support |
Android 4.0 WebView Structure
The Android WebView API layer is primarily provided to our application interface, in order to be compatible with the next version of Android in the high version is also to support this layer of API, so if the underlying changes, these API interface layer will not change too much. The Android platform not only provides the application layer programming interface but also provides native layer programming. Here are the three sections:1) Android framework:android WebView is a special control implementation that supports the need for Framework code primarily in the ./frameworks/base/core/java/android/ WebKit directory, the Android 4.0 implementation is mainly in Webviewcore.java,browserframe.java and other files. 2) Android JNI: Need to have native code support, so need to have JNI layer implementation, Android WebView 4.0 JNI layer Implementation WebView related code in./external/webkit/source/webkit /android/jni/directory, this layer plays a connecting role, linking the framework layer and the WebKit layer of the bridge, such as related to some implementations in the Webviewcore.cpp,webcoreframebridge.cpp and so on. 3) Webkit:webkit kernel, its core is the analysis of the standard and rendering typesetting Web page, he is a cross-platform kernel engine, then need to support each platform, need our platform implementation layer, in the Android 4.0 system this part of the relevant code mainly in. external/webkit/source/webkit/android/webcoresupport/directory, such as FrameLoaderClientAndroid.cpp, ChromeClientAndroid.cpp, this layer is responsible for WebCore and the system platform bridge, the specific platform will have different implementations. The implementation of the page's analytic layout and rendering by the WebCore to achieve in the Android 4.0 source code is located in the./external/webkit/source/webcore/, below the WebCore implementation of the various modules to support the relevant code, For example, the Page view section in the pages directory of the chrome.cpp, such as loading the page needs resources Loader FrameLoader.cpp, etc., here do not continue in-depth explanation, interested friends can download Android 4.0 source reading.
Android 4.1--4.3 webview structure
Android 4.1--4.3 version WebView kernel implementation is still based on WebKit, but the framework layer in WebView has changed, introduced the Factory mode, the purpose is to separate the kernel and the upper API interface, the meaning of separation is not only the abstract interface, It is more important to replace the implementation of the kernel section in the future. In 4.1--4.3 this series of versions of the native structure is basically the same as the 4.0 release, presenting new changes:
Android 4.0--4.3 Rendering
Although the previous 4.0, with 4.1--4.3 is in a series of different structures, the difference between the two is mainly focused on the framework of changes, this change is more reflected in the framework layer structure changes, webkit kernel extremely on the Android performance mechanism does not change greatly, their rendering machine System is the same. The following describes the rendering mechanism for Android 4.0--4.3:
Hardware acceleration has been turned on by default on Android 4.0, so WebView rendering is based on hardware rendering by default, and by analyzing its hidden frame in webview, software rendering is used to reduce the hardware footprint and allow the other UI to respond in a timely manner. In the case of hardware rendering, WebView passes the canvas through the OnDraw method and Hardwarecanvas it to the behavior, and generates a drawglfunction pointer of native, notifying native to render. In software mode, WebView transmits a frame of the kernel to the canvas by notifying the kernel Webkitdraw by passing the canvas, performing a canvas draw bitmap.
Android 4.4 WebView structure on Android 4.4 system Google has replaced the system's default WebKit kernel with its own open source project chromium, with previous versions of the analysis, we can see the Android WebView's framework structure is tuned to make it more abstract, and more importantly, to integrate its own open source chromium. Let's take a look at the changes in the structure of WebView:
Directory:./frameworks/base/core/java/android/webkit
./frameworks/webview/chromium/java/com/android/webview/chromium
./external/chromium_org/android_webview
./external/chromium_org/contentIn order to integrate the Chromium project into Android, the Chromium project abstracts the Android WebView layer, and the previous interface has become apparent, and Android WebView is based on chromium content API this layer, third-party browser vendors can also use this way, the current understanding of the manufacturers have opera use this way. The Android 4.4WebView rendering core has not changed much at this time, or based on the WebView canvas, drawing the chromium composit structure onto the WebView canvas. Access to the chromium kernel, WebView browsing performance significantly increased, but with Chrome for Android is still a little different, mainly reflected in the following: 1. The Chrome browser is a multi-process architecture, and Chromium for Android Webview is a single-process architecture. 2. Chrome browser has much larger memory footprint than Android WebView. 3. Chrome supports more HTML5 feature. Android webview Outlook:
Chromium Project Compilation "android_webview_apk" is currently implemented based on Android Surfaceview, which has a higher rendering performance than Android WebView canvas, legacy issues and Android The function of the system WebView, this piece with chromium and Android project integration, I believe it is worth looking forward to the future Android WebView rendering performance will be greatly improved.
This blog will continue to update the changes of Android WebView later version, please pay attention to thank you!
Resources:
Https://source.android.com/Android 4.0---4.4
Http://developer.android.com/reference/android/webkit/WebView.html
Android each version WebView