Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy handling #2

Open
wants to merge 2 commits into
base: orfox-tb_GECKO380esr_2015050513_RELBRANCH
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mobile/android/base/CrashReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.Proxy;
import java.net.InetSocketAddress;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.util.zip.GZIPOutputStream;

import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.util.ProxySettings;

import android.app.Activity;
import android.app.AlertDialog;
Expand Down Expand Up @@ -354,8 +353,7 @@ private void sendReport(File minidumpFile, Map<String, String> extras, File extr
Log.i(LOGTAG, "server url: " + spec);
try {
URL url = new URL(spec);
Proxy torProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8118));
HttpURLConnection conn = (HttpURLConnection)url.openConnection(torProxy);
HttpURLConnection conn = (HttpURLConnection)url.openConnection(ProxySettings.getProxy());
conn.setRequestMethod("POST");
String boundary = generateBoundary();
conn.setDoOutput(true);
Expand Down
6 changes: 2 additions & 4 deletions mobile/android/base/SuggestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.InetSocketAddress;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;

import org.json.JSONArray;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.util.ProxySettings;
import org.mozilla.gecko.util.HardwareUtils;

import android.content.Context;
Expand Down Expand Up @@ -86,8 +85,7 @@ public ArrayList<String> query(String query) {
HttpURLConnection urlConnection = null;
InputStream in = null;
try {
Proxy torProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8118));
urlConnection = (HttpURLConnection) url.openConnection(torProxy);
urlConnection = (HttpURLConnection) url.openConnection(ProxySettings.getProxy());
urlConnection.setConnectTimeout(mTimeout);
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
in = new BufferedInputStream(urlConnection.getInputStream());
Expand Down
12 changes: 8 additions & 4 deletions mobile/android/base/background/bagheera/BagheeraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.mozilla.gecko.background.bagheera;

import android.content.Context;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -32,6 +34,7 @@
*/
public class BagheeraClient {

protected final Context mCtx;
protected final String serverURI;
protected final Executor executor;
protected static final Pattern URI_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+$");
Expand All @@ -51,13 +54,14 @@ public class BagheeraClient {
* @param executor
* the executor which will be used to invoke delegate callbacks.
*/
public BagheeraClient(final String serverURI, final Executor executor) {
public BagheeraClient(final Context ctx, final String serverURI, final Executor executor) {
if (serverURI == null) {
throw new IllegalArgumentException("Must provide a server URI.");
}
if (executor == null) {
throw new IllegalArgumentException("Must provide a non-null executor.");
}
this.mCtx = ctx;
this.serverURI = serverURI.endsWith("/") ? serverURI : serverURI + "/";
this.executor = executor;
}
Expand All @@ -71,8 +75,8 @@ public BagheeraClient(final String serverURI, final Executor executor) {
* @param serverURI
* the destination server URI.
*/
public BagheeraClient(final String serverURI) {
this(serverURI, Executors.newSingleThreadExecutor());
public BagheeraClient(final Context ctx, final String serverURI) {
this(ctx, serverURI, Executors.newSingleThreadExecutor());
}

/**
Expand Down Expand Up @@ -147,7 +151,7 @@ protected BaseResource makeResource(final String namespace, final String id) thr

final String uri = this.serverURI + PROTOCOL_VERSION + SUBMIT_PATH +
namespace + "/" + id;
return new BaseResource(uri);
return new BaseResource(mCtx, uri);
}

public class BagheeraResourceDelegate extends BaseResourceDelegate {
Expand Down
9 changes: 7 additions & 2 deletions mobile/android/base/background/fxa/FxAccountClient10.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import javax.crypto.Mac;

import android.content.Context;

import org.json.simple.JSONObject;
import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientMalformedResponseException;
import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
Expand Down Expand Up @@ -77,6 +79,8 @@ public class FxAccountClient10 {
protected static final String[] requiredErrorStringFields = { JSON_KEY_ERROR, JSON_KEY_MESSAGE, JSON_KEY_INFO };
protected static final String[] requiredErrorLongFields = { JSON_KEY_CODE, JSON_KEY_ERRNO };

protected final Context mCtx;

/**
* The server's URI.
* <p>
Expand All @@ -87,13 +91,14 @@ public class FxAccountClient10 {

protected final Executor executor;

public FxAccountClient10(String serverURI, Executor executor) {
public FxAccountClient10(Context ctx, String serverURI, Executor executor) {
if (serverURI == null) {
throw new IllegalArgumentException("Must provide a server URI.");
}
if (executor == null) {
throw new IllegalArgumentException("Must provide a non-null executor.");
}
this.mCtx = ctx;
this.serverURI = serverURI.endsWith("/") ? serverURI : serverURI + "/";
if (!this.serverURI.endsWith("/")) {
throw new IllegalArgumentException("Constructed serverURI must end with a trailing slash: " + this.serverURI);
Expand Down Expand Up @@ -140,7 +145,7 @@ protected BaseResource getBaseResource(String path, String... queryParameters) t
sb.append(URLEncoder.encode(val, "UTF-8"));
}
}
return new BaseResource(new URI(sb.toString()));
return new BaseResource(mCtx, new URI(sb.toString()));
}

/**
Expand Down
6 changes: 4 additions & 2 deletions mobile/android/base/background/fxa/FxAccountClient20.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Map;
import java.util.concurrent.Executor;

import android.content.Context;

import org.json.simple.JSONObject;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
Expand All @@ -22,8 +24,8 @@ public class FxAccountClient20 extends FxAccountClient10 implements FxAccountCli
protected static final String[] LOGIN_RESPONSE_REQUIRED_STRING_FIELDS_KEYS = new String[] { JSON_KEY_UID, JSON_KEY_SESSIONTOKEN, JSON_KEY_KEYFETCHTOKEN, };
protected static final String[] LOGIN_RESPONSE_REQUIRED_BOOLEAN_FIELDS = new String[] { JSON_KEY_VERIFIED };

public FxAccountClient20(String serverURI, Executor executor) {
super(serverURI, executor);
public FxAccountClient20(Context ctx, String serverURI, Executor executor) {
super(ctx, serverURI, executor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.net.URISyntaxException;
import java.util.concurrent.Executor;

import android.content.Context;

import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.net.BaseResource;

Expand Down Expand Up @@ -59,10 +61,10 @@ public AuthorizationResponse(String access_token, String token_type, String scop
}

public void authorization(String client_id, String assertion, String state, String scope,
RequestDelegate<AuthorizationResponse> delegate) {
RequestDelegate<AuthorizationResponse> delegate, Context context) {
final BaseResource resource;
try {
resource = new BaseResource(new URI(serverURI + "authorization"));
resource = new BaseResource(context, new URI(serverURI + "authorization"));
} catch (URISyntaxException e) {
invokeHandleError(delegate, e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.net.URISyntaxException;
import java.util.concurrent.Executor;

import android.content.Context;

import org.mozilla.gecko.background.fxa.oauth.FxAccountAbstractClient;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
Expand All @@ -27,10 +29,10 @@ public FxAccountProfileClient10(String serverURI, Executor executor) {
super(serverURI, executor);
}

public void profile(final String token, RequestDelegate<ExtendedJSONObject> delegate) {
public void profile(final String token, RequestDelegate<ExtendedJSONObject> delegate, Context context) {
BaseResource resource;
try {
resource = new BaseResource(new URI(serverURI + "profile"));
resource = new BaseResource(context, new URI(serverURI + "profile"));
} catch (URISyntaxException e) {
invokeHandleError(delegate, e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected JSONObject generateDocument(final long localTime, final long last,
}

protected void uploadPayload(String id, String payload, Collection<String> oldIds, BagheeraRequestDelegate uploadDelegate) {
final BagheeraClient client = new BagheeraClient(getDocumentServerURI());
final BagheeraClient client = new BagheeraClient(context, getDocumentServerURI());

Logger.pii(LOG_TAG, "New health report has id " + id +
"and obsoletes " + (oldIds != null ? Integer.toString(oldIds.size()) : "no") + " old ids.");
Expand Down Expand Up @@ -186,7 +186,7 @@ protected SubmissionsTracker getSubmissionsTracker(final HealthReportStorage sto

@Override
public void delete(final long localTime, final String id, Delegate delegate) {
final BagheeraClient client = new BagheeraClient(getDocumentServerURI());
final BagheeraClient client = new BagheeraClient(context, getDocumentServerURI());

Logger.pii(LOG_TAG, "Deleting health report with id " + id + ".");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.mozilla.gecko.browserid.verifier;

import android.content.Context;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -25,12 +27,16 @@ public class BrowserIDRemoteVerifierClient10 extends AbstractBrowserIDRemoteVeri

public static final String DEFAULT_VERIFIER_URL = "https://verifier.login.persona.org/verify";

public BrowserIDRemoteVerifierClient10() throws URISyntaxException {
private final Context mCtx;

public BrowserIDRemoteVerifierClient10(Context ctx) throws URISyntaxException {
super(new URI(DEFAULT_VERIFIER_URL));
mCtx = ctx;
}

public BrowserIDRemoteVerifierClient10(URI verifierUri) {
public BrowserIDRemoteVerifierClient10(Context ctx, URI verifierUri) {
super(verifierUri);
mCtx = ctx;
}

@Override
Expand All @@ -45,7 +51,7 @@ public void verify(String audience, String assertion, final BrowserIDVerifierDel
throw new IllegalArgumentException("delegate cannot be null.");
}

BaseResource r = new BaseResource(verifierUri);
BaseResource r = new BaseResource(mCtx, verifierUri);

r.delegate = new RemoteVerifierResourceDelegate(r, delegate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import android.content.Context;

import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.net.BaseResource;
Expand All @@ -22,12 +23,16 @@ public class BrowserIDRemoteVerifierClient20 extends AbstractBrowserIDRemoteVeri
protected static final String JSON_KEY_ASSERTION = "assertion";
protected static final String JSON_KEY_AUDIENCE = "audience";

public BrowserIDRemoteVerifierClient20() throws URISyntaxException {
private final Context mCtx;

public BrowserIDRemoteVerifierClient20(Context ctx) throws URISyntaxException {
super(new URI(DEFAULT_VERIFIER_URL));
mCtx = ctx;
}

public BrowserIDRemoteVerifierClient20(URI verifierUri) {
public BrowserIDRemoteVerifierClient20(Context ctx, URI verifierUri) {
super(verifierUri);
mCtx = ctx;
}

@Override
Expand All @@ -42,7 +47,7 @@ public void verify(String audience, String assertion, final BrowserIDVerifierDel
throw new IllegalArgumentException("delegate cannot be null.");
}

BaseResource r = new BaseResource(verifierUri);
BaseResource r = new BaseResource(mCtx, verifierUri);
r.delegate = new RemoteVerifierResourceDelegate(r, delegate);

final ExtendedJSONObject requestBody = new ExtendedJSONObject();
Expand Down
6 changes: 2 additions & 4 deletions mobile/android/base/distribution/Distribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.net.Proxy;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
Expand All @@ -44,6 +42,7 @@
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.util.ProxySettings;
import org.mozilla.gecko.util.FileUtils;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils;
Expand Down Expand Up @@ -469,8 +468,7 @@ private boolean checkIntentDistribution(final ReferrerDescriptor referrer) {
Log.v(LOGTAG, "Downloading referred distribution: " + uri);

try {
Proxy torProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8118));
final HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(torProxy);
final HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(ProxySettings.getProxy());

// If the Search Activity starts, and we handle the referrer intent, this'll return
// null. Recover gracefully in this case.
Expand Down
24 changes: 13 additions & 11 deletions mobile/android/base/favicons/LoadFaviconTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
import android.text.TextUtils;
import android.util.Log;
import ch.boye.httpclientandroidlib.Header;
import ch.boye.httpclientandroidlib.HttpEntity;
import ch.boye.httpclientandroidlib.HttpResponse;
import ch.boye.httpclientandroidlib.client.methods.HttpGet;
import ch.boye.httpclientandroidlib.HttpHost;
import ch.boye.httpclientandroidlib.conn.params.ConnRoutePNames;
import ch.boye.httpclientandroidlib.impl.client.CloseableHttpClient;
import ch.boye.httpclientandroidlib.impl.client.HttpClients;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.decoders.FaviconDecoder;
import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
import org.mozilla.gecko.util.ProxyRoutePlanner;
import org.mozilla.gecko.util.GeckoJarReader;
import org.mozilla.gecko.util.IOUtils;
import org.mozilla.gecko.util.ThreadUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
Expand Down Expand Up @@ -74,7 +73,10 @@ public class LoadFaviconTask {
private LinkedList<LoadFaviconTask> chainees;
private boolean isChaining;

static DefaultHttpClient httpClient = new DefaultHttpClient();
static CloseableHttpClient httpClient = HttpClients.custom()
.setUserAgent(GeckoAppShell.getGeckoInterface().getDefaultUAString())
.setRoutePlanner(new ProxyRoutePlanner())
.build();

public LoadFaviconTask(Context context, String pageURL, String faviconURL, int flags, OnFaviconLoadedListener listener) {
this(context, pageURL, faviconURL, flags, listener, -1, false);
Expand Down Expand Up @@ -128,12 +130,9 @@ private HttpResponse tryDownloadRecurse(URI faviconURI, HashSet<String> visited)
if (visited.size() == MAX_REDIRECTS_TO_FOLLOW) {
return null;
}

HttpHost torProxy = new HttpHost("127.0.0.1", 8118);

HttpGet request = new HttpGet(faviconURI);
request.setHeader("User-Agent", GeckoAppShell.getGeckoInterface().getDefaultUAString());
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, torProxy);


HttpResponse response = httpClient.execute(request);
if (response == null) {
return null;
Expand Down Expand Up @@ -610,7 +609,10 @@ static void closeHTTPClient() {
// which counts as network activity.
if (ThreadUtils.isOnBackgroundThread()) {
if (httpClient != null) {
httpClient.close();
try {
httpClient.close();
} catch (IOException e) {
}
}
return;
}
Expand Down
Loading