Skip to content

Support persistent & binary queries/callbacks#528

Open
VinyarionHyarmendacil wants to merge 3 commits intochromiumembedded:masterfrom
VinyarionHyarmendacil:master
Open

Support persistent & binary queries/callbacks#528
VinyarionHyarmendacil wants to merge 3 commits intochromiumembedded:masterfrom
VinyarionHyarmendacil:master

Conversation

@VinyarionHyarmendacil
Copy link

@VinyarionHyarmendacil VinyarionHyarmendacil commented Mar 19, 2026

Fixes #398
After trying to (ab)use JNA to manually pre-increment the CefQueryCallback native reference count, I found my way here and discovered that #476 existed, but was made to the wrong repo. This is my approach to solving the problem:

  • Add a (j)boolean parameter at the end of CefQueryCallback_N.N_Success to indicate whether the query is persistent
    • Decrement the reference count if and only if this parameter is false
    • CefQueryCallback_N.N_Failure should not have this, as the documentation in cef_message_router.h specifies that the query is canceled (and therefore the callback becomes invalid) when the Callback::Failure function is called
  • Add a new method to CefQueryCallback: boolean isPersistent(), which can be used on the Java side to check if the query is persistent (instead of lugging around a callback + boolean pair)
  • Store whether the query is persistent in the Java runtime type of the callback wrapper instead of a field
    • This subclasses CefQueryCallback_N with CefQueryCallback_N_Persistent which overrides the isPersistent method to return true

Regarding binary queries/successes:

  • Queries:
    • Override MessageRouterHandler::OnQuery(..., CefRefPtr request, ...)
    • Wrap the CefBinaryBuffer in a direct byte buffer (javadocs note that the buffer is only valid in certain scope)
    • Forward to new method CefMessageRouterHandler.onQuery(..., ByteBuffer request, ...)
  • Successes:
    • Add new method CefQueryCallback(_N).success(ByteBuffer response) (javadocs note that the buffer must be direct)
    • Forward this to new native method CefQueryCallback_N.N_SuccessBinary(..., ByteBuffer response, ...)
      • Supports both direct and array-backed buffers
    • Call the native callback binary Success variant

Test cases have been added to the "detailed handler test" in MessageRouterHandlerEx and binding_test2.html

@VinyarionHyarmendacil VinyarionHyarmendacil changed the title Properly support persistent callbacks Support persistent & binary queries/callbacks Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Even for queries with "persistent" set to true, CefQueryCallback->Success clears the reference to the callback

1 participant