From 137edb1874d741e6ed7c36b05e4ed5a02c3b53c5 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 12 Aug 2022 17:48:20 +0200 Subject: [PATCH] Improved favicon scanner --- .../java/eu/faircode/email/ContactInfo.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index d2a7829f29..1f7c6ceaad 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -117,6 +117,13 @@ public class ContactInfo { private static final long CACHE_FAVICON_DURATION = 2 * 7 * 24 * 60 * 60 * 1000L; // milliseconds private static final float MIN_FAVICON_LUMINANCE = 0.2f; + // https://realfavicongenerator.net/faq + private static final String[] FIXED_FAVICONS = new String[]{ + "apple-touch-icon.png", // 57x57 + "apple-touch-icon-precomposed.png", // 57x57 + "favicon.ico" + }; + // https://css-tricks.com/prefetching-preloading-prebrowsing/ // https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch private static final List REL_EXCLUDE = Collections.unmodifiableList(Arrays.asList( @@ -390,9 +397,10 @@ public class ContactInfo { if (favicons) { String host = domain; + if (!host.startsWith("www.")) + host = "www." + host; while (host.indexOf('.') > 0) { final URL base = new URL("https://" + host); - final URL www = new URL("https://www." + host); futures.add(executorFavicon.submit(new Callable() { @Override @@ -401,35 +409,23 @@ public class ContactInfo { } })); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Favicon call() throws Exception { - return parseFavicon(www, scaleToPixels, context); - } - })); - int dot = host.indexOf('.'); host = host.substring(dot + 1); } host = domain; + if (!host.startsWith("www.")) + host = "www." + host; while (host.indexOf('.') > 0) { final URL base = new URL("https://" + host); - final URL www = new URL("https://www." + host); - futures.add(executorFavicon.submit(new Callable() { - @Override - public Favicon call() throws Exception { - return getFavicon(new URL(base, "favicon.ico"), null, scaleToPixels, context); - } - })); - - futures.add(executorFavicon.submit(new Callable() { - @Override - public Favicon call() throws Exception { - return getFavicon(new URL(www, "favicon.ico"), null, scaleToPixels, context); - } - })); + for (String name : FIXED_FAVICONS) + futures.add(executorFavicon.submit(new Callable() { + @Override + public Favicon call() throws Exception { + return getFavicon(new URL(base, name), null, scaleToPixels, context); + } + })); int dot = host.indexOf('.'); host = host.substring(dot + 1);