LAIS MINCHILLO: Hello.
My name is Lais.
I'm a software engineer in the WebView team in London,
and I'm here to talk about our AndroidX library, AndroidX
WebKit.
So what is it?
AndroidX WebKit is a library in Jetpack.
Jetpack is a [? suite ?] of libraries, tools, and guidance
to help developers write high quality apps easier.
AndroidX libraries are independent from the platform
APIs.
This means that they are updated more frequently.
They also offer backwards compatibility.
In our case, APIs work back all the way to L Plus devices.
That seems great.
But why should you care?
WebView has dozens of APIs introduced after Lollipop.
By using our AndroidX library, you can use all these APIs
and target older devices as well.
Let's say you want to use an API from SDK 28, which
is Android Pie.
If using the framework API, you only target roughly 10%
of devices.
If using the AndroidX WebKit API, you target almost 90%
of devices.
You can check out the full documentation
on how to use AndroidX or how to migrate an existing
project to AndroidX in JetPack's AndroidX Overview, linked here.
For WebKit specifically, you want
to add this line in your apps build.gradle file.
Our current stable release is 1.0.0,
and our current release candidate is 1.1.0-rc.01.
No matter what kind of method you're swapping,
first replace the version check for a feature check.
To swap static methods, simply replace
WebView with WebViewCompat and you're done.
To swap out non-static methods, replace your WebView object
with WebViewCompat, then pass your WebView object
as the first parameter.
That's it.
Let's talk about some of our most recent APIs.
Dark Mode-- we are introducing new API
to control Dark Mode in your WebViews.
There are three modes--
Off, which means your content will never
be dark, On, which means your content will always be dark,
and Auto, which means it's going to follow system settings.
This allows app developers to choose if the content should
be light or dark.
This snippet shows you how to query current Force
Dark settings or change it.
Remember to guard these calls with the feature check.
It's as simple as calling getForceDark, passing
in the WebView settings, or calling setForceDark,
passing the WebView settings and the setting you want.
Improving on the framework APIs, we
are adding new methods for developers
to choose how the content will be darkened.
There are three strategies to choose from.
User agent only-- content will be darkened by a user agent
and the page historic theme will be ignored if it exists.
Web theme only-- content will be darkened by the dark theme
provided by the page.
If the page doesn't have one, content
will be rendered with the default theme.
Prefer web theme over user agent--
content will be darkened by the dark theme provided
by the page, or if the page doesn't have one,
content will be darkened by a user agent.
This snippet shows you how to get or set
the Force Dark strategy with the three options
we discussed before.
Here are some examples of what a WebView looks
like with Dark Mode off or on.
Proxy Controller APIs allow you to override Android proxy
settings for all the WebViews in your app.
You can set multiple proxy and bypass rules
and also specify whether these apply to http, https, or both.
This snippet shows you how to use Proxy Controller.
First get an instance to the ProxyController.
Then create a ProxyConfig object.
You can add as many proxy rules or bypass rules as you need.
Note that the order of the rules matter.
When loading a URL, the first proxy rule
that matches that URL will be used.
If any URLs match a bypass rule, then it
will be loaded directly instead.
In case you want to clear these settings, just
call clearProxyOverride.
It's important to note that both these methods are asynchronous,
so you might want to pass in a listener
to know exactly when the settings were applied.
Asset loader is a helper class to load local assets,
resources, or files.
This doesn't have any Chromium dependency,
which means unlike other APIs discussed here,
you don't have to guard these calls with a feature check.
Asset Loader allows you to securely integrate
local content in your app with web content.
Always use a domain you have full control
over or the default domain reserved for this.
This snippet shows how to load an asset.
First create an assetLoader.
Then override shouldInterceptRequest
in your WebView client and call into assetLoaders
shouldInterceptRequest.
Then load an asset concatenating the domain,
in this example, the default one, and its path.
What else is coming into 1.1.0?
Tracing Controller, that helps collect
tracing information for debugging,
and Render Process, that enables you to control WebView's Render
Process starting in Android 0.
Thank you for listening.
Stay tuned for more stuff coming into AndroidX WebKit.
Check out our documentation on Android Developers,
and if you have any questions, reach out to android webview
dev@chromium.org.
[MUSIC PLAYING]