Skip to content

Commit

Permalink
Merge pull request #139 from thestr4ng3r/fix-nanohttpd-errors
Browse files Browse the repository at this point in the history
Prevent WebView's automatic favicon loading
  • Loading branch information
Mahavir Jain committed Nov 16, 2017
2 parents eb7e585 + 952804b commit 93a1fc2
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.folioreader.ui.folio.fragment;

import android.app.Activity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
Expand All @@ -21,6 +22,8 @@
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
Expand Down Expand Up @@ -458,6 +461,34 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}
return true;
}


// prevent favicon.ico to be loaded automatically
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if(url.toLowerCase().contains("/favicon.ico")) {
try {
return new WebResourceResponse("image/png", null, null);
} catch (Exception e) {
Log.e(TAG, "shouldInterceptRequest failed", e);
}
}
return null;
}

// prevent favicon.ico to be loaded automatically
@Override
@SuppressLint("NewApi")
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if(!request.isForMainFrame() && request.getUrl().getPath().endsWith("/favicon.ico")) {
try {
return new WebResourceResponse("image/png", null, null);
} catch (Exception e) {
Log.e(TAG, "shouldInterceptRequest failed", e);
}
}
return null;
}
});

mWebview.setWebChromeClient(new WebChromeClient() {
Expand Down

0 comments on commit 93a1fc2

Please sign in to comment.