Interface CefriumContentServer

All Known Implementing Classes:
CefriumPathContentServer
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CefriumContentServer
Answers the requests for an https origin the app owns, from Java: the app's assets, files, or bytes it generates. Register one with CefriumProfile.registerContentServer(String, CefriumContentServer). No socket is opened, so no other app can reach the content, and the origin is the same on every launch: localStorage, IndexedDB, cookies and service workers keep their data.

The origin is a secure context, as any https origin, so the APIs that need one work (service workers, crypto.subtle, clipboard). This is the Cefrium counterpart of androidx.webkit.WebViewAssetLoader; see CefriumPathContentServer for its path handlers.

serve(CefriumContentRequest) runs on a background thread, never the main thread, and may block (a database, decryption, the network). Several requests can run at once, so an implementation must be thread-safe.

Range requests (media, large assets) and HEAD are answered for the server: a response with a known length (CefriumContentResponse.setContentLength(long)) gets a 206 Partial Content with the requested bytes, skipped from its stream.

  • Method Details

    • serve

      Answers a request.
      Parameters:
      request - The request, its path relative to the server.
      Returns:
      The response, or null for 404 Not Found.
      Throws:
      IOException - If the content cannot be read; the page gets 500 Internal Server Error.
    • withResponseHeaders

      default CefriumContentServer withResponseHeaders(Map<String,String> headers)
      This server, with headers added to each of its responses, unless the response sets the header itself. For example, to make the pages cross-origin isolated, as WebAssembly threads and SharedArrayBuffer need (Unity and Godot web exports):
      server.withResponseHeaders(Map.of(
              "Cross-Origin-Opener-Policy", "same-origin",
              "Cross-Origin-Embedder-Policy", "require-corp"));
      
      Parameters:
      headers - Header names and values.
      Returns:
      A server that answers as this one, with the headers.