From b54b9e620a2ec97c338d2eec06426f82494f20df Mon Sep 17 00:00:00 2001 From: Matthew Finkel Date: Thu, 2 Aug 2018 21:49:05 +0000 Subject: [PATCH] Bug 27016 - Create proxy connection during image download Picasso, the image retrieval library used by Fennec, ignores the network proxy configuration. We override the openConnection() method and create the connection using the configured proxy. --- .../org/mozilla/gecko/home/ImageLoader.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mobile/android/base/java/org/mozilla/gecko/home/ImageLoader.java b/mobile/android/base/java/org/mozilla/gecko/home/ImageLoader.java index 2bbd82a8df775..cbbe7babbba4e 100644 --- a/mobile/android/base/java/org/mozilla/gecko/home/ImageLoader.java +++ b/mobile/android/base/java/org/mozilla/gecko/home/ImageLoader.java @@ -15,9 +15,14 @@ import com.squareup.picasso.Picasso; import com.squareup.picasso.Downloader.Response; import com.squareup.picasso.UrlConnectionDownloader; +import org.mozilla.gecko.util.ProxySelector; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import java.util.EnumSet; import java.util.Set; @@ -84,6 +89,23 @@ public class ImageLoader { this.distribution = distribution; } + @Override + protected HttpURLConnection openConnection(Uri path) throws IOException { + try { + // This is annoying, but |path| is an android.net.Uri and + // openConnectionWithProxy() accepts a java.net.URI + return (HttpURLConnection)ProxySelector.openConnectionWithProxy( + new URI( + path.getScheme(), path.getHost(), path.getPath(), + path.getEncodedFragment())); + } catch (URISyntaxException ex) { + // And android.net.Uri is more lenient than java.net.URI. + // Uri does not catch syntax errors which URI may catch. + // We'll re-throw this as an IOException + throw new IOException(ex.getMessage()); + } + } + private Density getDensity(float factor) { final DisplayMetrics dm = context.getResources().getDisplayMetrics(); final float densityDpi = dm.densityDpi * factor; -- GitLab