Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for persistent callbacks #476

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion java/org/cef/callback/CefQueryCallback_N.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
package org.cef.callback;

class CefQueryCallback_N extends CefNativeAdapter implements CefQueryCallback {
CefQueryCallback_N() {}
private boolean persistent_;

CefQueryCallback_N() {
}

@Override
protected void finalize() throws Throwable {
Expand All @@ -31,6 +34,15 @@ public void failure(int error_code, String error_message) {
}
}

private void makePersistent() {
this.persistent_ = true;
}

private boolean getIsPersistent() {
return this.persistent_;
}

private final native void N_Success(long self, String response);

private final native void N_Failure(long self, int error_code, String error_message);
}
7 changes: 6 additions & 1 deletion native/CefQueryCallback_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ Java_org_cef_callback_CefQueryCallback_1N_N_1Success(JNIEnv* env,
if (!callback)
return;
callback->Success(GetJNIString(env, response));
ClearSelf(env, obj);

bool persistent = false;
JNI_CALL_BOOLEAN_METHOD(persistent, env, obj, "getIsPersistent", "()Z");

if (!persistent)
ClearSelf(env, obj);
}

JNIEXPORT void JNICALL
Expand Down
3 changes: 3 additions & 0 deletions native/message_router_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ bool MessageRouterHandler::OnQuery(

jboolean jresult = JNI_FALSE;

if (persistent)
JNI_CALL_VOID_METHOD(env, jcallback.get(), "makePersistent", "()V");

JNI_CALL_METHOD(env, handle_, "onQuery",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/browser/"
"CefFrame;JLjava/lang/String;ZLorg/cef/"
Expand Down