blob: 8f608087429436f42ec9a0941300fa6e710c39b6 [file] [log] [blame] [view]
Nate Fischer397cd552020-06-24 01:35:021# WebView Architecture
2
3## Layering
4
5Android WebView is a [content embedder](/content/README.md), meaning it depends
6on code in `//content/` and lower layers (ex. `//net/`, `//base/`), but does not
Scott Violet447e4fe2023-09-19 16:47:037depend on sibling layers such as `//chrome/`. Android WebView can also depend on
8[components](/components/README.md).
Nate Fischer397cd552020-06-24 01:35:029
10## Java and C++
11
12Android WebView exposes Java APIs in the
13[framework](https://developer.android.com/reference/android/webkit/package-summary)
14and
15[AndroidX](https://developer.android.com/reference/androidx/webkit/package-summary),
16which are responsible for loading chromium code from the WebView provider
17package. These APIs call into glue code
18([`//android_webview/glue/`](/android_webview/glue/README.md) and
19[`//android_webview/support_library/`](/android_webview/support_library/README.md)
20respectively).
21
22The glue layers convert to chromium-defined types in [the "AW"
23layer](/android_webview/java/README.md). The AW Java types typically call into
24[browser C++ code][browser] via Java Native Interface (JNI) or call into Java
25methods in other layers which eventually use JNI (ex. `//content/public/`).
26These AW types are the layer we write [automated instrumentation
27tests](contributing-tests.md) against.
28
29In addition to browser C++ code, WebView also has a small amount of code in
30[`//android_webview/renderer/`][renderer] (renderer process code) and
31[`//android_webview/common/`][common] (shared between multiple processes), which
32are patterned off `//content/browser/`, `//content/renderer/`, and
33`//content/common/`. The bulk of WebView's code is defined in `//content/` layer
34and below.
35
36## Processes
37
38When an Android app embeds WebView, WebView's browser code runs in the app's
39process (we call this the "browser process"). This means WebView code shares the
40same address space, and we generally consider the app to be trusted just like
41any other browser process code. WebView's browser process code runs in the same
42**context** as the embedding application, which means it has all the same
43permissions and limitations of the embedding app (ex. WebView only has network
44access if the app requeested it). One consequence of this is WebView uses the
45app's data directory, so each app has a separate cookie jar, network cache, etc.
46
47WebView follows Chrome's architecture by separating browser and renderer code.
Nate Fischer7adda0ef2025-07-25 18:53:0948See [this document][renderer] for details. WebView's renderer process also runs
49in the app's context, although this process is sandboxed so it actually has even
50fewer permissions.
Nate Fischer397cd552020-06-24 01:35:0251
52WebView runs other services (ex. GPU service, Network Service) in-process on all
53OS versions. This saves memory (which is why Chrome for Android does the same
54thing on low-memory devices), although WebView is technically blocked because
55there's [no Android API to run a non-sandboxed process under another app's
56context](https://bugs.chromium.org/p/chromium/issues/detail?id=882650#c7).
57
58Although WebView is typically embedded in other apps, it runs some code as its
59own context. This includes a limited amount of UI code as well as a service. See
60[`//android_webview/nonembedded/`](/android_webview/nonembedded/README.md) for
61details.
62
63## Packaging variants
64
65Since Android Lollipop, WebView has been implemented by an updatable package. We
Nate Fischer7adda0ef2025-07-25 18:53:0966ship WebView to users as either standalone WebView or Trichrome. See [Packaging
Nate Fischer397cd552020-06-24 01:35:0267Variants](webview-packaging-variants.md) for details.
68
69## See also
70
71* Check out [Android WebView 101 (2019)](https://youtu.be/qMvbtcbEkDU) ([public
72 slide
73 deck](https://docs.google.com/presentation/d/1Nv0fsiU0xtPQPyAWb0FRsjzr9h2nh339-pq7ssWoNQg/edit?usp=sharing))
74 for more architecture details, and an overview of use cases
75* [Reach out to the
76 team](https://groups.google.com/a/chromium.org/forum/#!forum/android-webview-dev)
77 if you have more questions
78
79[browser]: /android_webview/browser/README.md
80[renderer]: /android_webview/renderer/README.md
81[common]: /android_webview/common/README.md