Android WebView 101
Chrome University 2019
ntfschr@ (he/him)
(based on a previous talk by boliu@)
Bring the best of Chromium to the Android platform
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)?
What is it?
android.webkit.WebView
A View in Android SDK to display web contents
Hundreds of APIs
Primary use cases
Embedded into app
Browsers
Cordova
Ads
Screenshot missing intentionally
WebView or not?
Add Google account on Android
Gmail email compose
Clicking on a link in Gmail
Clicking on a link in Facebook app
WebView or not?
Add Google account on Android
Gmail email compose
Clicking on a link in Gmail
Clicking on a link in Facebook app
WebView is used by apps on every Android device worldwide
What can it do?
loadUrl() ~ navigate in omnibox
onPageStarted/onPageFinished() callbacks ~ update omnibox while navigating
onReceivedError()/onReceivedHttpError() callbacks ~ error page
What can it do?
evaluateJavascript()/@JavascriptInterface ~ interact with web content
setCookie()/getCookie() ~ interact directly with cookie database
shouldInterceptRequest() ~ modify or intercept arbitrary network requests
Technical guts
Trust model
Browser process is the app process
Each app is ~equivalent to a different installation of chrome (different data dir)
Each webview is ~equivalent to a tab in chrome
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)
WebView is a Chromium embedder
Embeds content layer, affected by all changes in lower layers
Must support architectural changes (ex. Network Servicification, crashpad)
Chrome's architecture (simplified)
Blink
V8
Renderers
Browser
Blink
V8
Blink
V8
Network Service
GPU Service
Chrome's low-memory architecture
Blink
V8
Renderers
Browser
Blink
V8
Blink
V8
GPU Service (in-process)
Network Service (in-process)
WebView’s architecture (Android O+)
Blink
V8
Single renderer
Browser (app’s process)
GPU Service (in-process)
Network Service (in-process)
WebView’s architecture (Android L-N)
Browser (app’s process)
GPU Service (in-process)
Network Service (in-process)
Renderer (in-process)
Blink
V8
Working with WebView
Developer workflow
Workflow almost as easy as Chrome for Android
WebView APK only implements WebView APIs
Design Challenges
Weird sizes: small, giant
Weird restrictions: no internet, can’t create popups
Release
Identical release as Chrome on Android
Same version pushed to play store at same time. Same version bundled in Android OS system image.
Supports the same canary, dev, beta, stable channels
Experiments & metrics
Supports metrics (platform == Android WebView)
Supports field trials (platform == ANDROID_WEBVIEW)
Knows about base::Features and flags in blink, content, etc.
Please remember WebView for your features :)