Interface CefriumResourceInterceptor

All Known Subinterfaces:
CefriumBrowser.RequestInterceptor

@CefriumExperimental public interface CefriumResourceInterceptor
Sees every request a CefriumBrowser makes, and may cancel it or answer it instead of the network. Set it with CefriumBrowser.setResourceInterceptor(CefriumResourceInterceptor). Unlike the navigation client, it is NOT called on the UI thread: each method says which thread, and an implementation must be thread-safe.
  • Method Details

    • shouldBlockRequest

      default boolean shouldBlockRequest(CefriumBrowser.ResourceRequest request)
      Network thread, synchronous: return true to cancel the request. Called for every request, so it must be fast; do not block here.
    • shouldInterceptRequest

      default CefriumContentResponse shouldInterceptRequest(CefriumContentRequest request)
      Background thread, may block (read a file, a database): return a response to answer the request yourself, or null to let it go to the network. Like WebView's shouldInterceptRequest, for any URL, with the request's method, headers and body. Range requests and HEAD are handled for you, as for a CefriumContentServer. Called after shouldBlockRequest(CefriumBrowser.ResourceRequest) let the request through; the request waits for the answer.
    • onRequestFiltered

      default void onRequestFiltered(String url, String method, boolean blocked)
      Every request, after the block decision: blocked is true when the built-in ad filter or shouldBlockRequest(CefriumBrowser.ResourceRequest) refused it. Network thread.
    • onResourceRedirect

      default void onResourceRedirect(String oldUrl, String newUrl)
      A request was redirected to newUrl. Network thread.
    • onResourceResponse

      default void onResourceResponse(String url, int statusCode)
      A response's headers arrived, with this status code. Network thread.
    • onResourceLoadComplete

      default void onResourceLoadComplete(String url, int statusCode, long receivedBytes)
      A request finished: its status code and the bytes it received. Network thread.
    • onResponseData

      default void onResponseData(String url, ByteBuffer chunk)
      A chunk of a response body, as it arrives (read only; the page gets it unchanged). Network thread. Overriding it copies every body across, so only override it when needed.
    • onCanSendCookie

      default boolean onCanSendCookie(String url, String name, String value)
      Whether a cookie may be sent with a request. Network thread.
    • onCanSaveCookie

      default boolean onCanSaveCookie(String url, String name, String value)
      Whether a cookie a response sets may be stored. Network thread.