Skip to content

Commit

Permalink
fix(android): remove stored references to bridge that holds it in mem…
Browse files Browse the repository at this point in the history
…ory (#6448) (#6455)
  • Loading branch information
carlpoole committed Mar 31, 2023
1 parent f17e582 commit 8fa2d1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
public class CapacitorCookieManager extends CookieManager {

private final android.webkit.CookieManager webkitCookieManager;
private final Bridge bridge;

private final String localUrl;

private final String serverUrl;

/**
* Create a new cookie manager with the default cookie store and policy
Expand All @@ -36,18 +39,19 @@ public CapacitorCookieManager(Bridge bridge) {
public CapacitorCookieManager(CookieStore store, CookiePolicy policy, Bridge bridge) {
super(store, policy);
webkitCookieManager = android.webkit.CookieManager.getInstance();
this.bridge = bridge;
this.localUrl = bridge.getLocalUrl();
this.serverUrl = bridge.getServerUrl();
}

public String getSanitizedDomain(String url) {
if (url == null || url.isEmpty()) {
url = this.bridge.getLocalUrl();
url = this.localUrl;
}

try {
new URI(url);
} catch (Exception ex) {
return this.bridge.getServerUrl();
return this.serverUrl;
}

return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ private void http(final PluginCall call, final String httpMethod) {
@Override
public void run() {
try {
HttpRequestHandler.bridge = bridge;
JSObject response = HttpRequestHandler.request(call, httpMethod);
JSObject response = HttpRequestHandler.request(call, httpMethod, getBridge());
call.resolve(response);
} catch (Exception e) {
call.reject(e.getLocalizedMessage(), e.getClass().getSimpleName(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

public class HttpRequestHandler {

public static Bridge bridge = null;

/**
* An enum specifying conventional HTTP Response Types
* See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
Expand Down Expand Up @@ -367,7 +365,8 @@ public static String readStreamAsString(InputStream in) throws IOException {
* @throws URISyntaxException thrown when the URI is malformed
* @throws JSONException thrown when the incoming JSON is malformed
*/
public static JSObject request(PluginCall call, String httpMethod) throws IOException, URISyntaxException, JSONException {
public static JSObject request(PluginCall call, String httpMethod, Bridge bridge)
throws IOException, URISyntaxException, JSONException {
String urlString = call.getString("url", "");
JSObject headers = call.getObject("headers");
JSObject params = call.getObject("params");
Expand Down

0 comments on commit 8fa2d1c

Please sign in to comment.