[tbb-commits] [tor-browser/tor-browser-60.1.0esr-8.0-1] Bug 27016 - Create proxy connection during image download

gk at torproject.org gk at torproject.org
Wed Aug 15 12:52:31 UTC 2018


commit dda3c7d44a12cc2d9ff5e071605c8f36670ac956
Author: Matthew Finkel <Matthew.Finkel at gmail.com>
Date:   Thu Aug 2 21:49:05 2018 +0000

    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.
---
 .../java/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 2bbd82a8df77..cbbe7babbba4 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;



More information about the tbb-commits mailing list