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

Character encoding in CefResourceHandler #463

Open
wants to merge 4 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
10 changes: 10 additions & 0 deletions java/org/cef/network/CefResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public static final CefResponse create() {
*/
public abstract void setMimeType(String mimeType);

/**
* Get the response charset.
*/
public abstract String getCharset();

/**
* Set the response charset.
*/
public abstract void setCharset(String charset);

/**
* Get the value for the specified response header field. Use getHeaderMap instead if there
* might be multiple values.
Expand Down
21 changes: 21 additions & 0 deletions java/org/cef/network/CefResponse_N.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ public void setMimeType(String mimeType) {
}
}

@Override
public String getCharset() {
try {
return N_GetCharset(N_CefHandle);
} catch (UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
return null;
}

@Override
public void setCharset(String charset) {
try {
N_SetCharset(N_CefHandle, charset);
} catch (UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
}

@Override
public String getHeaderByName(String name) {
try {
Expand Down Expand Up @@ -179,6 +198,8 @@ public void setHeaderMap(Map<String, String> headerMap) {
private final native void N_SetStatusText(long self, String statusText);
private final native String N_GetMimeType(long self);
private final native void N_SetMimeType(long self, String mimeType);
private final native String N_GetCharset(long self);
private final native void N_SetCharset(long self, String charset);
private final native String N_GetHeaderByName(long self, String name);
private final native void N_SetHeaderByName(
long self, String name, String value, boolean overwrite);
Expand Down
21 changes: 21 additions & 0 deletions native/CefResponse_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ Java_org_cef_network_CefResponse_1N_N_1SetMimeType(JNIEnv* env,
response->SetMimeType(GetJNIString(env, jmimeType));
}

JNIEXPORT jstring JNICALL
Java_org_cef_network_CefResponse_1N_N_1GetCharset(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefResponse> response = GetSelf(self);
if (!response)
return nullptr;
return NewJNIString(env, response->GetCharset());
}

JNIEXPORT void JNICALL
Java_org_cef_network_CefResponse_1N_N_1SetCharset(JNIEnv* env,
jobject obj,
jlong self,
jstring jmimeType) {
CefRefPtr<CefResponse> response = GetSelf(self);
if (!response)
return;
response->SetCharset(GetJNIString(env, jmimeType));
}

JNIEXPORT jstring JNICALL
Java_org_cef_network_CefResponse_1N_N_1GetHeaderByName(JNIEnv* env,
jobject obj,
Expand Down
16 changes: 16 additions & 0 deletions native/CefResponse_N.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.