Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 15, 2024
1 parent de8401c commit 2bd3493
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void didFailLoad(boolean isInPrimaryMainFrame, int errorCode, GURL failin
if (navigationDelegate != null) {
Log.e("ChromiumErrorPage", "navigationDelegate != null => onLoadError() is called");

WResult<String> errorUriResult = navigationDelegate.onLoadError(mSession, failingUrl.getSpec(), new WWebRequestError() {
byte[] errorData = navigationDelegate.onLoadErrorData(mSession, failingUrl.getSpec(), new WWebRequestError() {
@Override
public int code() {
return errorCode;
Expand All @@ -145,10 +145,7 @@ public X509Certificate certificate() {
}
});

Log.e("ChromiumErrorPage", "errorUriResult: " + errorUriResult.toString());
//mSession.loadUri(errorUriResult.toString());
Log.e("ChromiumErrorPage", "InternalPages.htmlBytes: " + InternalPages.htmlBytes);
mSession.loadData(InternalPages.htmlBytes, "text/html");
mSession.loadData(errorData, "text/html");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,15 @@ WResult<String> onLoadError(
Log.e("ChromiumErrorPage", "onLoadError() returns null");
return null;
}

@UiThread
default @Nullable
byte[] onLoadErrorData(
@NonNull final WSession session,
@Nullable final String uri,
@NonNull final WWebRequestError error) {
return null;
}
}

@Retention(RetentionPolicy.SOURCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,11 @@ public WResult<String> onLoadError(@NonNull WSession session, @Nullable String u
return WResult.fromValue(InternalPages.createErrorPageDataURI(mContext, uri, error.code()));
}

@Override
public byte[] onLoadErrorData(@NonNull WSession session, @Nullable String uri, @NonNull WWebRequestError error) {
return InternalPages.createErrorPageData(mContext, uri, error.code());
}

// Progress Listener

@Override
Expand Down
11 changes: 8 additions & 3 deletions app/src/common/shared/com/igalia/wolvic/utils/InternalPages.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public static PageResources create(int html, int css) {
public static String createErrorPageDataURI(Context context,
@Nullable String uri,
int sessionError) {

return "data:text/html;base64," + Base64.encodeToString(createErrorPageData(context, uri, sessionError), Base64.NO_WRAP);
}

public static byte[] createErrorPageData(Context context,
@Nullable String uri,
int sessionError) {
String html = readRawResourceString(context, R.raw.error_pages);
String css = readRawResourceString(context, R.raw.error_style);

Expand Down Expand Up @@ -153,9 +160,7 @@ public static String createErrorPageDataURI(Context context,

Log.e("ChromiumErrorPage", "createErrorPageDataURI() returns " + html);

htmlBytes = html.getBytes();

return "data:text/html;base64," + Base64.encodeToString(html.getBytes(), Base64.NO_WRAP);
return html.getBytes();
}

public static byte[] htmlBytes;
Expand Down

0 comments on commit 2bd3493

Please sign in to comment.