Skip to content

Commit

Permalink
Fix crash if onLoadError uri parameter is null (#3000)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 20, 2020
1 parent 1915c2d commit a6ae172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @N
}

@Override
public GeckoResult<String> onLoadError(@NonNull GeckoSession session, String uri, @NonNull WebRequestError error) {
public GeckoResult<String> onLoadError(@NonNull GeckoSession session, @Nullable String uri, @NonNull WebRequestError error) {
Log.d(LOGTAG, "Session onLoadError: " + uri);

return GeckoResult.fromValue(InternalPages.createErrorPageDataURI(mContext, uri, error.code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.util.Base64;

import androidx.annotation.Nullable;

import org.mozilla.vrbrowser.R;

import org.mozilla.geckoview.WebRequestError;
Expand Down Expand Up @@ -115,7 +117,7 @@ public static PageResources create(int html, int css) {
}

public static String createErrorPageDataURI(Context context,
String uri,
@Nullable String uri,
int errorType) {
String html = ErrorPages.INSTANCE.createErrorPage(
context,
Expand All @@ -134,9 +136,10 @@ public static String createErrorPageDataURI(Context context,
showSSLAdvanced = false;
}

html = html
.replace("%url%", uri)
.replace("%advancedSSLStyle%", showSSLAdvanced ? "block" : "none");
if (uri != null) {
html = html.replace("%url%", uri);
}
html = html.replace("%advancedSSLStyle%", showSSLAdvanced ? "block" : "none");

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

0 comments on commit a6ae172

Please sign in to comment.