This document describes the current Android API split after the WPEPlatform backend, JNI/CAPI bridge, and high-level convenience API changes.
Older documentation and examples may still refer to the pre-refactor API path
(org.wpewebkit.wpeview.WPEView, WPEContext, the org.wpewebkit.wpe.WK*
proxies, or Browser/Page/gfx.View internals). Those classes have been removed;
new and existing code should use the APIs described below.
This layer initializes native libraries, bridges Android and GLib event delivery, and manages the Android services used for auxiliary processes on behalf of the WPEPlatform process manager.
Java code lives in:
wpeview/src/main/java/org/wpewebkit/WPEApplication.javawpeview/src/main/java/org/wpewebkit/wpe/WPERuntime.javawpeview/src/main/java/org/wpewebkit/wpe/WPEActivityObserver.javawpeview/src/main/java/org/wpewebkit/wpe/AuxiliaryProcessesContainer.javawpeview/src/main/java/org/wpewebkit/wpe/services/
Native code lives in:
wpeview/src/main/cpp/Runtime/EntryPoint.cppwpeview/src/main/cpp/Runtime/WPERuntime.cppwpeview/src/main/cpp/Runtime/MessagePump.cppwpeview/src/main/cpp/Common/
Runtime/EntryPoint.cpp is the JNI entry point. It initializes the common JNI
environment, registers the WPERuntime infrastructure JNI mappings, then
registers the capi/ mappings through WebKit::configureJNIMappings().
This is the Android widget API intended for application developers. It owns the
Android UI behavior: SurfaceView lifecycle, physical-to-logical coordinate
translation, adaptation of touch and key events, and delivery to WebView-style
clients.
Java code lives in:
wpeview/src/main/java/org/wpewebkit/wpeview/WebView.javawpeview/src/main/java/org/wpewebkit/wpeview/WebContext.javawpeview/src/main/java/org/wpewebkit/wpeview/WebSettings.javawpeview/src/main/java/org/wpewebkit/wpeview/CookieManager.javawpeview/src/main/java/org/wpewebkit/wpeview/WebViewClient.javawpeview/src/main/java/org/wpewebkit/wpeview/WebChromeClient.java
Use this layer when embedding WPE in a normal Android view hierarchy:
<org.wpewebkit.wpeview.WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />WebView webView = findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("https://www.wpewebkit.org/");WebView creates a WebContext by default. Applications that want to share
engine state, settings, cookie policy, cache directories, or automation mode
between multiple views should create one WebContext and pass it to each
WebView.
WebContext context = new WebContext(applicationContext);
WebView first = new WebView(context);
WebView second = new WebView(context);This layer exposes Java proxy objects for WebKit and WPEPlatform native objects.
It is intended for advanced embedders who want to manage the WPE objects
directly instead of using the Android WebView convenience widget.
Java code lives in wpeview/src/main/java/org/wpewebkit/wpe/:
WebKitWebViewwraps a nativeWebKitWebView.WebKitWebContextwraps a nativeWebKitWebContext.WebKitNetworkSessionwraps a nativeWebKitNetworkSession.WebKitWebsiteDataManagerwraps a nativeWebKitWebsiteDataManager.WebKitCookieManagerwraps a nativeWebKitCookieManager.WebKitSettingswraps a nativeWebKitSettings.WPEDisplaywraps a nativeWPEDisplay.WPEInputMethodContextwraps a nativeWPEInputMethodContextborrowed from aWPEView.WPEScreenwraps a nativeWPEScreen.WPEToplevelwraps a nativeWPEToplevel.WPEViewwraps a nativeWPEView.MainLooperDispatcheradapts callbacks to the Android main looper.
Native bridge code lives in wpeview/src/main/cpp/capi/. File names mirror the
Java proxy names and the native types they expose:
WebKitWebView.cppWebKitWebContext.cppWebKitNetworkSession.cppWebKitWebsiteDataManager.cppWebKitCookieManager.cppWebKitSettings.cppWPEDisplay.cppWPEInputMethodContext.cppWPEScreen.cppWPEToplevel.cppWPEView.cppJNIMappings.cpp
This layer is deliberately small, but it is not a raw pointer dump. It is responsible for JNI marshalling, native reference ownership, signal hookup, callback lifetime, and Java-side thread adaptation. Android widget policy still belongs in Layer 1.
Callbacks exposed from this layer are delivered to Java on the Android main
looper. For asynchronous JavaScript evaluation, WebKitWebView posts the result
through MainLooperDispatcher. For automation view creation,
WebKitWebContext may synchronously post to the main looper and block until the
UI-bound Java object has been created.
This layer implements the WPEPlatform backend for Android. It is the native Android platform logic used by WebKit through the WPEPlatform abstraction.
Native code lives in wpeview/src/main/cpp/Platform/:
WPEDisplayAndroid.cppWPEToplevelAndroid.cppWPEViewAndroid.cppWPEInputMethodContextAndroid.cppWPEKeymapAndroid.cppWPEProcessManagerAndroid.cppWPEScreenAndroid.cppWPEScreenSyncObserverAndroid.cpp
This is where Android-specific rendering and platform integration belongs:
EGL, ASurfaceControl, ASurfaceTransaction, Android native windows,
buffer presentation, screen state, key mapping, and IME integration.
Platform classes use the Android suffix because they are concrete
implementations of WPEPlatform types. For example, WPEDisplayAndroid
implements the WPE display vfuncs and registers the "android" display
extension; WPEViewAndroid owns rendering/buffer integration for a WPEView;
WPEToplevelAndroid owns the Android native-window connection for a
WPEToplevel.
This project links against imported WebKit and WPE headers and libraries. The engine is not Android UI code. It talks to the Android port through the WPEPlatform implementation from Layer 3 and through the WebKit C API wrapped by Layer 2.
Relevant imported native API locations include:
wpeview/src/main/cpp/imported/include/wpe-webkit/wpe/wpeview/src/main/cpp/imported/include/wpe-webkit/wpe-platform/wpeview/src/main/cpp/imported/lib/<abi>/libWPEWebKit-2.0.so
The Java proxies use explicit destroy() methods. Call them from the owner that
created the object, normally from the Android component lifecycle. Do not rely on
finalizers for the new API path.
Owning proxies:
| Java class | Native ownership |
|---|---|
WPEDisplay |
Owns a WPEDisplay; destroy() unreferences it and invalidates its borrowed WPEScreen. |
WPEToplevel |
Owns a WPEToplevel; destroy() unreferences it. |
WebKitWebContext |
Owns a bridge object holding a WebKitWebContext; destroy() disconnects automation signals and unreferences it. |
WebKitNetworkSession |
Owns a WebKitNetworkSession; destroy() unreferences it and invalidates the borrowed website data manager wrapper. |
WebKitSettings |
Owns a WebKitSettings; destroy() unreferences it. |
WebKitCookieManager |
Owns or holds the cookie manager wrapper for a network session; destroy it before destroying the session. |
WebKitWebView |
Owns a bridge object holding a WebKitWebView; destroy() disconnects signals, unreferences the native view, and invalidates its borrowed WPEView. |
Borrowed proxies:
| Java class | Native owner |
|---|---|
WPEView |
Borrowed from WebKitWebView. It must not outlive the parent WebKitWebView. |
WPEInputMethodContext |
Borrowed from WebKitWebView (attached to the borrowed WPEView); destroy() clears the focus listener and drops its JNI global ref. Must not outlive the parent WebKitWebView. |
WPEScreen |
Borrowed from WPEDisplay. It must not outlive the parent WPEDisplay. |
WebKitWebsiteDataManager |
Borrowed from WebKitNetworkSession. It must not outlive the parent WebKitNetworkSession. |
The high-level WebView owns the objects it creates in this order:
WebContext, unless the caller provided a shared context.WebKitWebView.- Borrowed
WPEViewfromWebKitWebView. WPEToplevel.SurfaceViewand Android surface callbacks.
WebView.destroy() detaches the WPEView from the toplevel, destroys the
WPEToplevel, destroys the WebKitWebView, and finally destroys the owned
WebContext if the WebView created it. When a WebContext is shared, the
application owns it and must destroy it after all WebView instances using it
have been destroyed.
WebContext.destroy() destroys settings, cookie manager, network session, web
context, and display. This order matters because several wrappers borrow objects
from earlier owners.
Surface lifetime is separate from object lifetime. WebView may create a
WPEToplevel before an Android Surface exists, then attach the native window
from surfaceCreated() or surfaceChanged(). surfaceDestroyed() clears the
native window and unmaps the WPEView, but it does not destroy the WebKit page.
Add Android application-facing APIs to Layer 1:
- Put new
android.webkit.WebView-style methods onwpeview/.../wpeview/WebView.java. - Put shared state and defaults on
WebContext.java. - Put app-visible settings on
WebSettings.java, backed byWebKitSettings. - Put app-visible callbacks on
WebViewClient.javaorWebChromeClient.java. - Keep Android
View,SurfaceView, gesture, focus, and key event policy in this layer.
Add low-level WebKit or WPE object coverage to Layer 2:
- Add or extend Java proxy classes in
org.wpewebkit.wpe. - Add matching JNI glue in
wpeview/src/main/cpp/capi/. - Register the mapping from
capi/JNIMappings.cpp. - Keep the Java class name aligned with the C type:
WebKit*for WebKit C API objects andWPE*for WPEPlatform objects. - Limit this layer to marshalling, ownership, signal hookup, and callback thread adaptation.
Add Android platform behavior to Layer 3:
- Add rendering, buffer, native-window, EGL, input method, screen, or keymap
behavior under
wpeview/src/main/cpp/Platform/. - Use the
Androidsuffix for concrete WPEPlatform implementations. - Wire new platform source files into
wpeview/src/main/cpp/CMakeLists.txt.
Add runtime or process behavior to Layer 0:
- Put JNI startup and mapping registration in
Runtime/EntryPoint.cpp. - Put process-provider changes in
Runtime/WPERuntime.cpp. - Put looper and GLib main-loop integration in
Runtime/MessagePump.cpp. - Put service-side code under
org.wpewebkit.wpe.servicesandwpeview/src/main/cpp/Service/.
The current naming convention is:
| Responsibility | Java/API name | Native/API name |
|---|---|---|
| Public Android widget | org.wpewebkit.wpeview.WebView |
Uses the low-level proxies internally |
| Shared public Android state | org.wpewebkit.wpeview.WebContext |
Owns display, WebKit context, session, cookies, and settings |
| Public Android settings | org.wpewebkit.wpeview.WebSettings |
Backed by WebKitSettings |
| Public Android cookies | org.wpewebkit.wpeview.CookieManager |
Backed by WebKitCookieManager and WebKitWebsiteDataManager |
| WebKit page proxy | org.wpewebkit.wpe.WebKitWebView |
WebKitWebView* |
| WebKit context proxy | org.wpewebkit.wpe.WebKitWebContext |
WebKitWebContext* |
| WebKit session proxy | org.wpewebkit.wpe.WebKitNetworkSession |
WebKitNetworkSession* |
| WebKit settings proxy | org.wpewebkit.wpe.WebKitSettings |
WebKitSettings* |
| WPE display proxy | org.wpewebkit.wpe.WPEDisplay |
WPEDisplay* |
| WPE toplevel proxy | org.wpewebkit.wpe.WPEToplevel |
WPEToplevel* |
| WPE view proxy | org.wpewebkit.wpe.WPEView |
WPEView* |
| Android platform display | no Java class | WPEDisplayAndroid |
| Android platform toplevel | no Java class | WPEToplevelAndroid |
| Android platform view | no Java class | WPEViewAndroid |
Avoid adding new APIs with the generic WK prefix. Use WebKit when mirroring a
WebKit C API type, WPE when mirroring a WPEPlatform type, and the Android
framework-style names in org.wpewebkit.wpeview for the convenience API.
The legacy convenience and proxy classes (org.wpewebkit.wpeview.WPEView,
WPEContext, WPESettings, WPECookieManager, WPEViewClient,
WPEChromeClient, and the org.wpewebkit.wpe.WK* proxies such as WKWebView,
WKWebContext, WKSettings, WKNetworkSession, WKCookieManager,
WKWebsiteDataManager) have been removed. Use the convenience API
(WebView, WebContext, WebSettings, …) and the WebKit/WPE CAPI proxies
instead.
The infrastructure layer classes formerly using the WK prefix have been
renamed: WPERuntime, WPEActivityObserver, WPEProcessType, and
WPEVersions. Note these are Android infrastructure names, not proxies of
WPEPlatform C types.
