Skip to content

Fix issue #13: CefQueryCallback.success() ignores persistent=true - #38

Merged
Thrameos merged 1 commit into
masterfrom
backport/query-callback-persistent
Sep 6, 2026
Merged

Thrameos merged 1 commit into
masterfrom
backport/query-callback-persistent

Conversation

@Thrameos

@Thrameos Thrameos commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #13 (matches upstream chromiumembedded#398)

Summary

  • The CEF message router's "subscription" style query workflow (JS sets persistent: true) is documented to allow CefQueryCallback.success() to be called repeatedly, with each call invoking the JS onSuccess handler again.
  • native/CefQueryCallback_N.cpp's N_Success unconditionally cleared the native reference after the first call regardless of persistent, so a second success() call on the same callback silently no-op'd.
  • Fixed by threading the persistent flag (already known to MessageRouterHandler::OnQuery()) through to CefQueryCallback_N via a new setPersistent() call made right after the callback object is constructed, and only clearing the native ref in N_Success when the query is not persistent. N_Failure is unchanged -- a failure always ends the query.

Test plan

  • Added UpstreamIssue398Test (matches upstream chromiumembedded/java-cef#398) as a regression test.
  • Rebuilt libjcef.so cleanly (ninja jcef), zero compile errors.
  • Full local suite run: 124/124 tests passing, including the new regression test.

Small, focused backport of a single self-contained fix (no other changes bundled in), following the same shape as PR #1, #36, and #37.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HBFmQs6JDypYP5qdC99yDq

@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.99%. Comparing base (be68fe1) to head (409fa1c).

Files with missing lines Patch % Lines
java/tests/junittests/UpstreamIssue398Test.java 91.42% 1 Missing and 2 partials ⚠️
native/CefQueryCallback_N.cpp 33.33% 1 Missing and 1 partial ⚠️
native/message_router_handler.cpp 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #38      +/-   ##
============================================
+ Coverage     38.01%   38.99%   +0.98%     
- Complexity      735      746      +11     
============================================
  Files           243      244       +1     
  Lines         14863    14904      +41     
  Branches       2449     2454       +5     
============================================
+ Hits           5650     5812     +162     
+ Misses         8011     7870     -141     
- Partials       1202     1222      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Thrameos added a commit that referenced this pull request Sep 5, 2026
preliminary update racing ahead of onBeforeDownload

CefDownloadItemTest.cancelDuringDownloadInvokesNCancel() flaked
intermittently in CI across multiple unrelated backport PRs (#38, #39, #41,
#42), always failing the same assertion: "onBeforeDownload was never
invoked". Root-caused by reproducing it locally (100% deterministic once a
low-risk, narrowly-scoped repro was possible -- see PR #44's run_tests.sh
fix, needed first to run just this one test without also running the whole
suite + leak-sweep) and adding temporary native fprintf instrumentation
(not included in this commit) at DownloadHandler::OnBeforeDownload/
OnDownloadUpdated and ClientHandler::GetDownloadHandler.

That instrumentation showed CEF can deliver a preliminary
OnDownloadUpdated() notification -- for a valid, real CefDownloadItem --
*before* OnBeforeDownload() has been dispatched to the handler at all. This
test's onDownloadUpdated() used to treat "not complete" on the very first
update it saw as "must actively cancel it", immediately calling
callback.cancel() and terminateTest() -- racing ahead of onBeforeDownload
and ending the test before it ever got a chance to run, which is exactly
what "onBeforeDownload was never invoked" captures.

Fix: ignore any onDownloadUpdated() notification that arrives before this
handler's own onBeforeDownload() has recorded its decision
(gotBeforeDownload[0]). Verified via direct reproduction: failed 3/3 in
isolation before the fix (including against a heavily-used local CEF
profile where it failed 100% of the time), passed cleanly every time after
(5+ consecutive solo runs, plus the full class together) with no change to
downloadCompletesAndWritesRealFile's behavior.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HBFmQs6JDypYP5qdC99yDq
N_Success unconditionally cleared the native reference after the first
call, regardless of whether the originating query was persistent, so a
second success() call on the same callback silently no-op'd. Thread
the persistent flag (already known to MessageRouterHandler::OnQuery())
through to CefQueryCallback_N via a new setPersistent() call made right
after the callback object is constructed, and only clear the native ref
in N_Success when the query is not persistent. N_Failure is unchanged --
a failure always ends the query.

Adds UpstreamIssue398Test (matches upstream chromiumembedded#398)
as a regression test, ported from the future branch's own repro. Verified
against a full local suite run: 124/124 passing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HBFmQs6JDypYP5qdC99yDq
@Thrameos
Thrameos force-pushed the backport/query-callback-persistent branch from 72d9263 to 409fa1c Compare September 5, 2026 21:23
@Thrameos Thrameos added the bug Something isn't working label Sep 6, 2026
@Thrameos
Thrameos merged commit 8ee7f65 into master Sep 6, 2026
12 of 13 checks passed
@Thrameos
Thrameos deleted the backport/query-callback-persistent branch September 6, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CefQueryCallback.success() ignores persistent=true, clears native ref after first call (matches upstream #398)

1 participant