Skip to content

Commit 8fa2d1c

Browse files
authored
fix(android): remove stored references to bridge that holds it in memory (#6448) (#6455)
1 parent f17e582 commit 8fa2d1c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
public class CapacitorCookieManager extends CookieManager {
1818

1919
private final android.webkit.CookieManager webkitCookieManager;
20-
private final Bridge bridge;
20+
21+
private final String localUrl;
22+
23+
private final String serverUrl;
2124

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

4246
public String getSanitizedDomain(String url) {
4347
if (url == null || url.isEmpty()) {
44-
url = this.bridge.getLocalUrl();
48+
url = this.localUrl;
4549
}
4650

4751
try {
4852
new URI(url);
4953
} catch (Exception ex) {
50-
return this.bridge.getServerUrl();
54+
return this.serverUrl;
5155
}
5256

5357
return url;

android/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorHttp.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ private void http(final PluginCall call, final String httpMethod) {
3131
@Override
3232
public void run() {
3333
try {
34-
HttpRequestHandler.bridge = bridge;
35-
JSObject response = HttpRequestHandler.request(call, httpMethod);
34+
JSObject response = HttpRequestHandler.request(call, httpMethod, getBridge());
3635
call.resolve(response);
3736
} catch (Exception e) {
3837
call.reject(e.getLocalizedMessage(), e.getClass().getSimpleName(), e);

android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
public class HttpRequestHandler {
2929

30-
public static Bridge bridge = null;
31-
3230
/**
3331
* An enum specifying conventional HTTP Response Types
3432
* See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
@@ -367,7 +365,8 @@ public static String readStreamAsString(InputStream in) throws IOException {
367365
* @throws URISyntaxException thrown when the URI is malformed
368366
* @throws JSONException thrown when the incoming JSON is malformed
369367
*/
370-
public static JSObject request(PluginCall call, String httpMethod) throws IOException, URISyntaxException, JSONException {
368+
public static JSObject request(PluginCall call, String httpMethod, Bridge bridge)
369+
throws IOException, URISyntaxException, JSONException {
371370
String urlString = call.getString("url", "");
372371
JSObject headers = call.getObject("headers");
373372
JSObject params = call.getObject("params");

0 commit comments

Comments
 (0)