I need to be able to get the cookie manager for a specific context so I can read and set cookies for that context.
I have noticed there is a GetCookieManager function in CEF:
- Code: Select all
public virtual CefRefPtr< CefCookieManager > GetCookieManager( CefRefPtr< CefCompletionCallback > callback )= 0;
https://magpcss.org/ceforum/apidocs3/projects/(default)/CefRequestContext.html#GetCookieManager(CefRefPtr%3CCefCompletionCallback%3E)
So I tried implementing it copying bits of code from here and there:
CefRequestContext_N.java:
- Code: Select all
...
import org.cef.network.CefCookieManager;
...
@Override
public CefCookieManager getCookieManager() {
try {
return N_GetCookieManager();
} catch (UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
return null;
}
...
private final native CefCookieManager N_GetCookieManager();
...
CefRequestContext.java:
- Code: Select all
...
import org.cef.network.CefCookieManager;
...
public abstract CefCookieManager getCookieManager();
...
after this I generated headers with make_jni_header.bat win64 org.cef.browser.CefRequestContext_N
CefRequestContext_N.cpp:
- Code: Select all
...
#include "include/cef_cookie.h"
...
JNIEXPORT jobject JNICALL Java_org_cef_browser_CefRequestContext_1N_N_1GetCookieManager
(JNIEnv* env, jobject obj) {
CefRefPtr<CefRequestContext> context =
GetCefFromJNIObject<CefRequestContext>(env, obj, "CefRequestContext");
CefRefPtr<CefCookieManager> manager =
context -> GetCookieManager(NULL);
if (!manager)
return NULL;
//Which to use?
//ScopedJNIObjectLocal jManager(env, NewJNIObject(env, "CefCookieManager"));
jobject jManager = NewJNIObject(env, "CefCookieManager");
if (!jManager)
return NULL;
SetCefForJNIObject(env, jManager, manager.get(), "CefCookieManager");
return jManager;
}
...
After this I built it using vs2017, then compile.bat win64 and make_distrib.bat
The error:
When I call this in my java app:
- Code: Select all
CefCookieManager cm = requestContext.getCookieManager();
I get the following error:
- Code: Select all
java.lang.ClassNotFoundException: CefCookieManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at org.cef.browser.CefRequestContext_N.N_GetCookieManager(Native Method)
at org.cef.browser.CefRequestContext_N.getCookieManager(CefRequestContext_N.java:30)
Where have I missed an import?