Android Chromium for WebView code structure, chromiumwebview

Source: Internet
Author: User

Android Chromium for WebView code structure, chromiumwebview

Reprinted please indicate the source http://blog.csdn.net/typename powered by miechalzhao@gmail.com

Summary I believe everyone who pays attention to Android platform development has observed that the default Implementation of Android 4.4 and above is changed from Webkit to chromium, which is good news for Android WebView, chromium-based WebView provides better and smoother performance, and AOSP has been compatible with earlier versions of APIs. It can run on Android 4.4 without any modifications made by our applications. This article introduces the implementation code structure of Chromium for WebView. The implementation is divided into two parts: the Framework and public API of Android WebView, and the core implementation of WebView. The figure below shows the relationship between the two types and the upper and lower structures.

Android Tree side1. Frameworks/base-- Core/java/android/webkit/(1) define Public API (WebView, WebViewSettings, etc) (2) WebViewFactoryProvider, WebViewProvider (3) defines various "pods (plain old data)" data types that are transferred between applications and WebView implementations. For example, URLUtil class. (4) define the specific implementation code of some webviews. 2. Frameworks/webview-- Chromium/java (1) glue Layer Code, bridging Android WebView Framework and external/chromium_org (2) in java this is the main entry of chromium WebViewFactory. (3) the purpose of implementing the Code in this directory is to rely only on the public API of android_webview (except for some, such as ThreadUtils, LibraryLoader, etc). It does not contain complex logic. Only maintain the status of the glue layer. 3. Frameworks/webview-- Chromium/plat_support this part of Code provides platform support. native support library is bound to a small number of copies of android_webview/public api (GL functor, skia bitmap accesses utilities) chromium Tree side1.android _ webview/java (1) Top-level entry of chromium. (2) provide a wrapper/semi Layer Based on the Chromium code to be backward compatible with the Android system version. (3) background support for most WebView API implementations by Chromium content module (http://dev.chromium.org/developers/content-module) and ancillary components browser (http://dev.chromium.org/developers/design-documents/browser-components) this part of the Code corresponds to the native part of the code android_webview/native directory through JNI. 2. android_webview/native (1) the Code of this directory should be called part of JNI code. This layer of code is only the code of the connection layer between android_webview/java and native code. The class name is basically a copy ing of the java layer class, and the role is the same. (2) This directory can be stored to avoid complicated implementation logic, reduce android_webview/browser pressure or components pressure (3) This Part of code must run in the same thread as the Public API of WebView, the WebView Public API runs in the UI thread, so this part of the code function must also run in the UI thread. Important interaction code like BrowserThread or IPC rendering thread is placed under the browser directory. 3. android_webview/browser (1) this directory Code provides browsing and other important features. (2) code that requires complex interaction with native threads Must be encapsulated here. (3) In order to modularize and test the module, the code in this part does not statically force dependency on the code at the upper-layer (android_webview/native) layer. 4. android_webview/renderer contains all the logic code running in the rendering process. Currently, WebView only supports single-process rendering and browser/renderer separation. This is a very practical architecture. It separates java applications from web platform code to avoid occasional independence and stability between the two. 5. The android_webview/lib directory is mainly the libwebviewchromium. so entry. No other modules depend on the code in this directory. 6. android_webview/common declares that some raw types are provided to android_webview/browser and android_webview/renderer. WebView adopts the single-process mode, allowing you to share the global status. The type declaration for each IPC is also defined here. 7. android_webview/public (1) defines the abstract interface for exporting the native part, to focus on important performance detection (such as rendering) that cannot be implemented in Java (2) use an internal tool of Android Framework to implement high-performance background-compatible M view. 8. android_webview/unittestjava mainly tests some JNI code.
References: https://code.google.com/p/chromium/
Https://source.android.com/
Http://www.chromium.org/developers/design-documents/



In android code, how does webview call JavaScript?

MWebView. setWebChromeClient (new MyWebChromeClient (); mWebView. addJavascriptInterface (new Object () {/*** This is not called on the UI thread. post a runnable to invoke * loadUrl on the UI thread. */public void clickOnAndroid () {mHandler. post (new Runnable () {public void run () {mWebView. loadUrl ("javascript: wave ()") ;}}}, "demo"); similarly, there must be an object named demo in html that calls clickOnAndroid () method. /*** Provides a hook for calling "alert" from javascript. useful for * debugging your javascript. */final class MyWebChromeClient extends WebChromeClient {@ Override public boolean onJsAlert (WebView view, String url, String message, JsResult result) {result. confirm (); return super. onJsAlert (view, url, message, result );}}
 
Android: How to overwrite javascript events in webview in java code

Webview. setWebViewClient (new MyWebViewClient (this, browser); inject javascript code public class MyWebViewClient extends WebViewClient {private Context con; public PTCWebViewClient (Context con, final WebView web) into the onPageFinished method of MyWebViewClient) {this. con = con ;}@ Override public boolean shouldOverrideUrlLoading (WebView view, String url) {view. loadUrl (url); return true ;}@ Override public void onPageS Tarted (WebView view, String url, Bitmap favicon) {super. onPageStarted (view, url, favicon) ;}@ Override public void onPageFinished (WebView view, String url) {super. onPageFinished (view, url); view. loadUrl ("javascript :( function () {document. getElementById ('snapnsendbtn '). onclick = function () {window. ltamtc. toSnapNSend () ;}}) () ") ;}}when this webView loads a page and the page has an element with the ID of" mySourceButton, the click event of this element is modified to the user. Custom toMyPage () events exposed to javascript calls. Once you click, the page will jump to or do anything you want to do.

Related Article

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.