1 of 25

Android WebView 101

Chrome University 2019

ntfschr@ (he/him)

(based on a previous talk by boliu@)

2 of 25

Bring the best of Chromium to the Android platform

3 of 25

Sixth platform

Blink’s intent-to-implement / intent-to-ship template:

Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

4 of 25

What is it?

5 of 25

android.webkit.WebView

A View in Android SDK to display web contents

Hundreds of APIs

6 of 25

Primary use cases

Embedded into app

Browsers

Cordova

Ads

Screenshot missing intentionally

7 of 25

WebView or not?

Add Google account on Android

Gmail email compose

Clicking on a link in Gmail

Clicking on a link in Facebook app

8 of 25

WebView or not?

Add Google account on Android

Gmail email compose

Clicking on a link in Gmail

Clicking on a link in Facebook app

9 of 25

WebView is used by apps on every Android device worldwide

10 of 25

What can it do?

loadUrl() ~ navigate in omnibox

onPageStarted/onPageFinished() callbacks ~ update omnibox while navigating

onReceivedError()/onReceivedHttpError() callbacks ~ error page

11 of 25

What can it do?

evaluateJavascript()/@JavascriptInterface ~ interact with web content

setCookie()/getCookie() ~ interact directly with cookie database

shouldInterceptRequest() ~ modify or intercept arbitrary network requests

12 of 25

Technical guts

13 of 25

Trust model

Browser process is the app process

  • Shares code, address space, etc. in the same process
  • App is “trusted” and has total control over web contents

Each app is ~equivalent to a different installation of chrome (different data dir)

  • Does not share cookies or any other profile data with chrome

Each webview is ~equivalent to a tab in chrome

14 of 25

WebView is an Android View

Draws synchronously into View system (lots of blocking graphics operations)

Supports Android platform features (smart text selection, autofill)

APIs to control web platform (ex. ServiceWorkerController)

15 of 25

WebView is a Chromium embedder

Embeds content layer, affected by all changes in lower layers

Must support architectural changes (ex. Network Servicification, crashpad)

16 of 25

Chrome's architecture (simplified)

Blink

V8

Renderers

Browser

Blink

V8

Blink

V8

Network Service

GPU Service

17 of 25

Chrome's low-memory architecture

Blink

V8

Renderers

Browser

Blink

V8

Blink

V8

GPU Service (in-process)

Network Service (in-process)

18 of 25

WebView’s architecture (Android O+)

Blink

V8

Single renderer

Browser (app’s process)

GPU Service (in-process)

Network Service (in-process)

19 of 25

WebView’s architecture (Android L-N)

Browser (app’s process)

GPU Service (in-process)

Network Service (in-process)

Renderer (in-process)

Blink

V8

20 of 25

Working with WebView

21 of 25

Developer workflow

Workflow almost as easy as Chrome for Android

  • Just need an emulator or a userdebug device
  • go/webview-docs/quick-start.md (or, //android_webview/docs/)

WebView APK only implements WebView APIs

  • Also need an embedding app to test
  • go/webview-docs/webview-shell.md

22 of 25

Design Challenges

Weird sizes: small, giant

Weird restrictions: no internet, can’t create popups

23 of 25

Release

Identical release as Chrome on Android

Same version pushed to play store at same time. Same version bundled in Android OS system image.

  • Respins for one requires respinning both

Supports the same canary, dev, beta, stable channels

24 of 25

Experiments & metrics

Supports metrics (platform == Android WebView)

Supports field trials (platform == ANDROID_WEBVIEW)

Knows about base::Features and flags in blink, content, etc.

25 of 25

Please remember WebView for your features :)