1 of 20

Android WebView

Chrome Graphics Meetup

boliu@ April 2019

2 of 20

android.webkit.WebView

A View in Android SDK to display web contents

Hundreds of APIs

3 of 20

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)?

Yes or no. If no, explain why this feature is not supported on these platforms.

4 of 20

Primary use cases

Embedded into app

Browsers

Cordova

Ads

Screenshot missing intentionally

5 of 20

WebView or not?

Add Google account on Android

Gmail email compose

Clicking on a link in Gmail

Clicking on a link in Facebook app

6 of 20

WebView or not?

Add Google account on Android

Gmail email compose

Clicking on a link in Gmail

Clicking on a link in Facebook app

7 of 20

WebView’s user base is probably on-par with Chrome on Android

8 of 20

Development background

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

  • no multi-profile support

Cannot talk directly to Google services

9 of 20

Source layout

Use OS_ANDROID. No separate compile-time define

Includes src/content and below, but not src/chrome

Rest of diagram fairly out of date ->

android_webview

10 of 20

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

  • On Android N+
  • Population is a lot smaller than Chrome on Android, which is already a lot smaller than desktop

11 of 20

Developer workflow

Historically different (confusing) packaging depending on Android version. Different build targets is confusing

Webview apk only implements webview APIs

  • Also need an embedding app to test.

On Android N+, workflow almost as easy as Chrome on Android

  • Just need an emulator or a userdebug device
  • https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/quick-start.md

Supports UMA metric collection and Finch experiments

12 of 20

WebView is an Android View

A layer in Android’s compositor (hwui)

  • Analogous to a cc::Layer in chromium compositor
  • App or hwui has a control over scheduling, scrolling, etc
  • Lots of synchronous (ie blocking) operations
  • Hwui owns surface webview renders into

WebView connects chromium’s compositing pieces in different ways to satisfy these requirements

13 of 20

Chrome’s architecture (grossly simplified)

Paint

Raster

Draw

Paint

Raster

Draw

Paint

Raster

Draw

Paint

Raster

Draw

GPU Service

Aggregate

DrawAndSwap

Renderer

Compositors

Embedding

Browser

Compositor

CompositorFrame

14 of 20

WebView: No browser compositor

Paint

Raster

Draw

Paint

Raster

Draw

Paint

Raster

Draw

GPU Service

Aggregate

DrawAndSwap

Renderer

Compositors

Embedding

CompositorFrame

15 of 20

WebView: No embedding support, yet

Paint

Raster

Draw

GPU Service

(Aggregate)

DrawAndSwap

Renderer

Compositor

CompositorFrame

16 of 20

WebView: Two GPU services

Paint

Raster

Draw

GPU Service

(Aggregate)

DrawAndSwap

Renderer

Compositor

CompositorFrame

GPU Service

on hwui render thread

Texture sharing

17 of 20

WebView: Separate viz::Display, conceptually

Paint

Raster

Draw

GPU Service

(Aggregate)

DrawAndSwap

Renderer

Compositor

CompositorFrame

GPU Service

on hwui thread

Texture sharing

Paint

Raster

Draw

(Aggregate)

DrawAndSwap

18 of 20

WebView: SynchronousCompositor

Paint

Raster

Draw

GPU Service

(Aggregate)

DrawAndSwap

Renderer

Compositor

CompositorFrame

GPU Service

on hwui thread

Texture sharing

19 of 20

Other rendering differences

  • Hardware overlays are disabled
  • Resourceless software draw
  • Paint whole document (in some mode)
  • Assumptions about viewport size often wrong

20 of 20

Please remember WebView for your features :)