WebView for Android and webview for android

Source: Internet
Author: User
Tags chrome devtools

WebView for Android and webview for android
Please indicate the source of http://blog.csdn.net/typename/ powered by miechal zhao: miechalzhao@gmail.com:

According to the market share of various Android systems (Google Android dashboards) announced by Google, Android 4.0 and above are about 90%, and the development trend is that there will be almost more than 4.0 Android systems in the future. This article focuses on the implementation of WebView for Android 4.0 and later systems. The Framework layer implemented by Android WebView can be divided into three sections: Android 4.0 series, Android 4.1-4.3 series, Android 4.4 series, and more.

WebView differences

WebView is a system control provided by the Android system to display webpages. It is a special View, and it is also a ViewGroup that can have many other sub-views. Below Android 4.4 (excluding 4.4) system WebView underlying implementation is the use of WebKit (http://www.webkit.org/) kernel, and in Android 4.4 and above Google uses chromium (http://www.chromium.org /) as the underlying Kernel support of the system WebView. In this change, the WebView APIs provided by Android have not changed significantly. In Android 4.4, the WebView APIs are compatible with earlier versions and a small number of APIs are introduced. Here, we will briefly introduce the differences between Chromium-based Webview and Webkit-based webview. The Chromium-based Webview provides a wider range of HTML5, CSS3, and Javascript support. Currently, the latest Android version 5.0 is based on chromium 37, webview supports the vast majority of HTML5 features. Webkit JavaScript causes the use of WebCore Javascript on Android 4.4 to be replaced with V8, which can directly improve JavaScript performance. In addition, Chromium supports remote debugging (Chrome DevTools ).

WebKit for WebView VS Chromium for WebView performance comparison (test environment: Xiaomi 2. CM Browser. Android 4.1.1 VS 4.4.3)

  Webkit for Webview Chromium for Webview Remarks
HTML5 278 434 Http://html5test.com/
Remote debugging Not Supported Supported Android 4.4 and above
Memory usage Small Large The difference is about 20-30 m
WebAudio Not Supported Supported Android 5.0 and above
WebGL Not Supported Supported Android 5.0 and above
WebRTC Not Supported Supported Android 5.0 and above

Android 4.0 WebView Structure
The Android WebView API layer mainly provides interfaces for our applications. In order to be compatible with the lower version of Android, the later version also supports this layer of API. Therefore, if the underlying layer changes, these API interfaces do not change much either. The Android platform not only provides application-layer programming interfaces but also native-layer programming. The following describes three parts: 1) Android Framework: Android WebView is a special control to support the code that requires the Framework. in the/frameworks/base/core/java/android/webkit directory, the implementation in Android 4.0 is mainly in WebViewCore. java, BrowserFrame. java files. 2) Android JNI: Native code support is required. Therefore, JNI layer implementation is required. The JNI layer of Android WebView 4.0 implements WebView-related code in. under the/external/webkit/Source/WebKit/android/jni/directory, this layer serves as a bridge connecting the Framework layer and WebKit layer. For example, some related implementations are implemented in WebviewCore. cpp, WebCoreFrameBridge. cpp. 3) WebKit: the Core of the WebKit kernel is to parse W3C standards and render typographical web pages. As a cross-platform kernel engine, it needs to support various platforms and our platform implementation layer, in Android 4.0, this part of related code is mainly used in. /external/webkit/Source/WebKit/android/WebCoreSupport/directory, such as FrameLoaderClientAndroid. cpp, ChromeClientAndroid. cpp, which is responsible for bridging WebCore with the system platform. different platforms have different implementations. Web page parsing and layout and rendering are implemented by WebCore. The code in the Android 4.0 source code is located in. under/external/webkit/Source/WebCore/, the following code supports the functions of each module implemented by WebCore, such as chrome in the page Directory. cpp, for example, FrameLoader In the loader for loading the resources required by the page. cpp and so on. I will not go into further details here. If you are interested, you can download the Android 4.0 source code.
Android 4.1 -- 4.3 WebView Structure

Android 4.1 -- 4.3 WebView kernel implementation is still based on WebKit. However, the Framework layer of WebView changes and the factory mode is introduced to separate the kernel from the upper-layer API interfaces, the significance of separation is not only an abstract interface, but more importantly, it can replace the kernel implementation in the future. In versions 4.1 -- 4.3, the structure of native is basically the same as that of Version 4.0, with new changes:


Android 4.0 -- 4.3 Rendering

Although the previous 4.0 and 4.1 -- 4.3 were in different structural series, the differences between the two were mainly changes on the centralized Framework, this change is more reflected in the changes in the Framework layer structure. The performance mechanism of the WebKit Kernel on Android is not significantly changed, and their rendering mechanism is the same. The following describes the rendering mechanism of Android 4.0 -- 4.3:


Hardware acceleration has been enabled on Android 4.0 by default. Therefore, WebView rendering is based on hardware rendering by default. By analyzing the frames hidden in WebView, we use software rendering, the purpose is to reduce hardware usage and make other UIS respond in a timely manner. In the case of hardware rendering, The WebView transmits the Canvas through the onDraw method and transfers it to HardwareCanvas, generates the native DrawGLFunction pointer, and notifies native to perform rendering. In software mode, WebView notifies the kernel webkitDraw to transmit a picture generated by the kernel to the Canvas by passing the Canvas, and executes the Canvas draw bitmap.

Android 4.4 WebView structure on Android 4.4, Google has replaced the default Webkit kernel of the system with its own open-source project chromium. Based on previous version analysis, we can see that Android adjusts the Framework Structure of WebView to make it more abstract. More importantly, it aims to integrate its own open-source chromium. Next let's take a look at the changes in the WebView structure:

Directory:./frameworks/base/core/java/android/webkit
./Frameworks/webview/chromium/java/com/android/webview/chromium
./External/chromium_org/android_webview
. /External/chromium_org/content in order to integrate the chromium project into Android, the chromium project abstracts the Android webview layer, and the previous interfaces have become obvious at this time, android Webview is based on the chromium content API. Third-Party Browser vendors can also adopt this method. Currently, Opera is the vendor familiar with this method. Currently, the rendering core of Android 4.4WebView has not changed much. The chrome composit structure is drawn to the WebView Canvas Based on the WebView Canvas. Accessing the chromium kernel greatly improves the WebView browsing performance, but it is still somewhat different from chrome for Android, mainly reflected in the following points: 1. chrome is a multi-process architecture, while Chromium for Android Webview is a single-process architecture. 2. chrome browser memory usage is much larger than Android WebView. 3. chrome supports more HTML5 feature. Android WebView Outlook:

The current implementation of the Chromium project compilation "android_webview_apk" is based on Android SurfaceView, which features higher rendering performance than the Canvas of Android WebView, historical issues and WebView functions of Android, with the integration of Chromium and Android, we believe that the rendering performance of Android WebView will be greatly improved in the future.

This blog will continue to update the subsequent versions of Android WebView. Thank you!

References:

Https://source.android.com/Android 4.0 --- 4.4

Http://developer.android.com/reference/android/webkit/WebView.html



How to check the android system version, for example, the system version: the baseband version of the android version ~~ And so on.

You have a problem.
The so-called version is a thing. After adding, modifying, deleting, and so on, the number is marked to be different from the previous version, that is, the version number.
A system is developed with different layers. There are kernels, application layers, images, and so on. Development is relatively independent in different regions. Different versions may have different functions. for developers, the version number is very important.
Here is an example. When developing android software, you must use the android SDK. the SDK version is the android version you mentioned.
A webview method loadUrl has only one parameter loadUrl (String) before 2.1, and after 2.2, it becomes loadUrl (String, Map <String, String> ). If I use the software developed in the following way, and your mobile phone number is 2.1, then you cannot use what I developed. This is probably the meaning. So when downloading the software, you just need to check the required minimum version. The written version you mentioned has no special significance.

Android: how to find content on the page displayed by WebView

It is mainly designed to display html files. Because of this, during application development, we can organize the content to be displayed into a String in html format to easily achieve various typographical effects.
Although the WebView component encapsulates many functions to facilitate application development, but due to its limited open methods, sometimes this convenience may cause great constraints to developers, for example, developers cannot easily control the start line of WebView display and cannot obtain related row information. Therefore, when WebView is convenient to the public, there will inevitably be many shortcomings.
In the process of application development, the widowed person encountered a problem: displaying the specified content in html to the current screen. How can this problem be solved? The WebView open method has never been well studied over and over again. If we can't do it in the white road, we will go to the black road. If we can't do it in the history, we will collect the wild history. What's the so-called Great road to Rome! As a result, few people search for the source code of WebView everywhere, hoping to improve through unconventional methods (calling methods not open in the WebView class library. But it is very difficult. It is also obvious that, even if it is found, it is not a secure call. This is like a reverse building in Shanghai. Maybe it will be flat at any time. This road is not only bumpy, but has a bright future, and may be broken.
Heaven! Even though it is expensive, it is sometimes helpless. What should I do? Once again, I looked at the poor methods WebView opened. Finally, I thought about findAll and findNext. As a result, I thought, if we can ensure the uniqueness of the content to be located and search for the content to be located, will this content not be displayed on the current screen? As a result, we were very unhappy and planned to give it a try. After the success, the whole country celebrated.
However, when I look at the help document, the two methods are empty, so I feel a little uneasy. Sure enough, there is no effect in the program. Few people had to consult Baidu and Google, the two government ministers of China and the West. Finally, we have an answer. Next, let's look at the world. You have listened carefully:
First, let's look at the remarks from the Assistant Minister to Jack:
Find is not a fully supported feature in webview.
However, try calling view. setFindIsUp (true) to get the match to draw; This function is den and subject to change, so your app may break in a future release. webView does not fully support the search function. However, we can try to call
SetFindIsUp
Method to obtain the query result, and display it on the current screen (painted ). This method is hidden and prone to changes, so your application may not be able to use it normally in future versions.
It can be seen that to use findAll and findNext, you must call
SetFindIsUp
Method, but this method is an internal function, so security cannot be guaranteed, and may be harmonious in a future version.
However, this is the only secure solution. If it cannot be used normally in a later version, it may be better to support WebView! Example: Assume that WebView has html content loaded. The following is a program for searching:
WebView webView = (WebView) findViewById (R. id. webView );
WebView. findAll (a); try {Method m = WebView. class. getMethod (setFindIsUp, Boolean. TYPE );
M. invoke (webView, true );
} The same applies to catch (Throwable ignored) {} findNext. Conclusion: findAll & find... of lWebView>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.