@capacitor/android 4.5.0 → 4.5.1-dev-20221117T024619.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -311,25 +311,24 @@ const nativeBridge = (function (exports) {
|
|
|
311
311
|
},
|
|
312
312
|
set: function (val) {
|
|
313
313
|
const cookiePairs = val.split(';');
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
314
|
+
const domainSection = val.toLowerCase().split('domain=')[1];
|
|
315
|
+
const domain = cookiePairs.length > 1 &&
|
|
316
|
+
domainSection != null &&
|
|
317
|
+
domainSection.length > 0
|
|
318
|
+
? domainSection.split(';')[0].trim()
|
|
319
|
+
: '';
|
|
320
|
+
if (platform === 'ios') {
|
|
321
|
+
// Use prompt to synchronously set cookies.
|
|
322
|
+
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323
|
|
323
|
+
const payload = {
|
|
324
|
+
type: 'CapacitorCookies.set',
|
|
325
|
+
action: val,
|
|
326
|
+
domain,
|
|
327
|
+
};
|
|
328
|
+
prompt(JSON.stringify(payload));
|
|
329
|
+
}
|
|
330
|
+
else if (typeof win.CapacitorCookiesAndroidInterface !== 'undefined') {
|
|
331
|
+
win.CapacitorCookiesAndroidInterface.setCookie(domain, val);
|
|
333
332
|
}
|
|
334
333
|
},
|
|
335
334
|
});
|
|
@@ -426,7 +425,8 @@ const nativeBridge = (function (exports) {
|
|
|
426
425
|
};
|
|
427
426
|
// XHR patch abort
|
|
428
427
|
window.XMLHttpRequest.prototype.abort = function () {
|
|
429
|
-
if (this._url == null ||
|
|
428
|
+
if (this._url == null ||
|
|
429
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
430
430
|
return win.CapacitorWebXMLHttpRequest.abort.call(this);
|
|
431
431
|
}
|
|
432
432
|
this.readyState = 0;
|
|
@@ -480,14 +480,16 @@ const nativeBridge = (function (exports) {
|
|
|
480
480
|
};
|
|
481
481
|
// XHR patch set request header
|
|
482
482
|
window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
|
|
483
|
-
if (this._url == null ||
|
|
483
|
+
if (this._url == null ||
|
|
484
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
484
485
|
return win.CapacitorWebXMLHttpRequest.setRequestHeader.call(this, header, value);
|
|
485
486
|
}
|
|
486
487
|
this._headers[header] = value;
|
|
487
488
|
};
|
|
488
489
|
// XHR patch send
|
|
489
490
|
window.XMLHttpRequest.prototype.send = function (body) {
|
|
490
|
-
if (this._url == null ||
|
|
491
|
+
if (this._url == null ||
|
|
492
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
491
493
|
return win.CapacitorWebXMLHttpRequest.send.call(this, body);
|
|
492
494
|
}
|
|
493
495
|
try {
|
|
@@ -543,7 +545,8 @@ const nativeBridge = (function (exports) {
|
|
|
543
545
|
};
|
|
544
546
|
// XHR patch getAllResponseHeaders
|
|
545
547
|
window.XMLHttpRequest.prototype.getAllResponseHeaders = function () {
|
|
546
|
-
if (this._url == null ||
|
|
548
|
+
if (this._url == null ||
|
|
549
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
547
550
|
return win.CapacitorWebXMLHttpRequest.getAllResponseHeaders.call(this);
|
|
548
551
|
}
|
|
549
552
|
let returnString = '';
|
|
@@ -556,7 +559,8 @@ const nativeBridge = (function (exports) {
|
|
|
556
559
|
};
|
|
557
560
|
// XHR patch getResponseHeader
|
|
558
561
|
window.XMLHttpRequest.prototype.getResponseHeader = function (name) {
|
|
559
|
-
if (this._url == null ||
|
|
562
|
+
if (this._url == null ||
|
|
563
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
560
564
|
return win.CapacitorWebXMLHttpRequest.getResponseHeader.call(this, name);
|
|
561
565
|
}
|
|
562
566
|
return this._headers[name];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.getcapacitor.plugin;
|
|
2
2
|
|
|
3
|
+
import com.getcapacitor.Bridge;
|
|
3
4
|
import java.net.CookieManager;
|
|
4
5
|
import java.net.CookiePolicy;
|
|
5
6
|
import java.net.CookieStore;
|
|
@@ -9,18 +10,20 @@ import java.util.ArrayList;
|
|
|
9
10
|
import java.util.Collections;
|
|
10
11
|
import java.util.HashMap;
|
|
11
12
|
import java.util.List;
|
|
13
|
+
import java.util.Locale;
|
|
12
14
|
import java.util.Map;
|
|
13
15
|
import java.util.Objects;
|
|
14
16
|
|
|
15
17
|
public class CapacitorCookieManager extends CookieManager {
|
|
16
18
|
|
|
17
19
|
private final android.webkit.CookieManager webkitCookieManager;
|
|
20
|
+
private final Bridge bridge;
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Create a new cookie manager with the default cookie store and policy
|
|
21
24
|
*/
|
|
22
|
-
public CapacitorCookieManager() {
|
|
23
|
-
this(null, null);
|
|
25
|
+
public CapacitorCookieManager(Bridge bridge) {
|
|
26
|
+
this(null, null, bridge);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
@@ -30,9 +33,29 @@ public class CapacitorCookieManager extends CookieManager {
|
|
|
30
33
|
* @param policy a {@code CookiePolicy} instance to be used by cookie manager as policy
|
|
31
34
|
* callback. if {@code null}, ACCEPT_ORIGINAL_SERVER will be used.
|
|
32
35
|
*/
|
|
33
|
-
public CapacitorCookieManager(CookieStore store, CookiePolicy policy) {
|
|
36
|
+
public CapacitorCookieManager(CookieStore store, CookiePolicy policy, Bridge bridge) {
|
|
34
37
|
super(store, policy);
|
|
35
38
|
webkitCookieManager = android.webkit.CookieManager.getInstance();
|
|
39
|
+
this.bridge = bridge;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public String getSanitizedDomain(String url) {
|
|
43
|
+
if (url == null || url.isEmpty()) {
|
|
44
|
+
url = this.bridge.getLocalUrl();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
new URI(url);
|
|
49
|
+
} catch (Exception ex) {
|
|
50
|
+
return this.bridge.getServerUrl();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return url;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private String getDomainFromCookieString(String cookie) {
|
|
57
|
+
String[] domain = cookie.toLowerCase(Locale.ROOT).split("domain=");
|
|
58
|
+
return getSanitizedDomain(domain.length <= 1 ? null : domain[1].split(";")[0].trim());
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
/**
|
|
@@ -109,6 +132,11 @@ public class CapacitorCookieManager extends CookieManager {
|
|
|
109
132
|
setCookie(url, cookieValue);
|
|
110
133
|
}
|
|
111
134
|
|
|
135
|
+
public void setCookie(String url, String key, String value, String expires, String path) {
|
|
136
|
+
String cookieValue = key + "=" + value + "; expires=" + expires + "; path=" + path;
|
|
137
|
+
setCookie(url, cookieValue);
|
|
138
|
+
}
|
|
139
|
+
|
|
112
140
|
/**
|
|
113
141
|
* Removes all cookies. This method is asynchronous.
|
|
114
142
|
*/
|
|
@@ -130,9 +158,6 @@ public class CapacitorCookieManager extends CookieManager {
|
|
|
130
158
|
// make sure our args are valid
|
|
131
159
|
if ((uri == null) || (responseHeaders == null)) return;
|
|
132
160
|
|
|
133
|
-
// save our url once
|
|
134
|
-
String url = uri.toString();
|
|
135
|
-
|
|
136
161
|
// go over the headers
|
|
137
162
|
for (String headerKey : responseHeaders.keySet()) {
|
|
138
163
|
// ignore headers which aren't cookie related
|
|
@@ -140,7 +165,11 @@ public class CapacitorCookieManager extends CookieManager {
|
|
|
140
165
|
|
|
141
166
|
// process each of the headers
|
|
142
167
|
for (String headerValue : Objects.requireNonNull(responseHeaders.get(headerKey))) {
|
|
143
|
-
|
|
168
|
+
// Set at server url
|
|
169
|
+
setCookie(uri.toString(), headerValue);
|
|
170
|
+
|
|
171
|
+
// Set at local url or domain
|
|
172
|
+
setCookie(getDomainFromCookieString(headerValue), headerValue);
|
|
144
173
|
}
|
|
145
174
|
}
|
|
146
175
|
}
|
|
@@ -20,7 +20,7 @@ public class CapacitorCookies extends Plugin {
|
|
|
20
20
|
@Override
|
|
21
21
|
public void load() {
|
|
22
22
|
this.bridge.getWebView().addJavascriptInterface(this, "CapacitorCookiesAndroidInterface");
|
|
23
|
-
this.cookieManager = new CapacitorCookieManager(null, java.net.CookiePolicy.ACCEPT_ALL);
|
|
23
|
+
this.cookieManager = new CapacitorCookieManager(null, java.net.CookiePolicy.ACCEPT_ALL, this.bridge);
|
|
24
24
|
CookieHandler.setDefault(cookieManager);
|
|
25
25
|
super.load();
|
|
26
26
|
}
|
|
@@ -74,7 +74,8 @@ public class CapacitorCookies extends Plugin {
|
|
|
74
74
|
try {
|
|
75
75
|
String url = getServerUrl(null);
|
|
76
76
|
if (!url.isEmpty()) {
|
|
77
|
-
|
|
77
|
+
String cookieString = cookieManager.getCookieString(url);
|
|
78
|
+
return (null == cookieString) ? "" : cookieString;
|
|
78
79
|
}
|
|
79
80
|
} catch (Exception e) {
|
|
80
81
|
e.printStackTrace();
|
|
@@ -84,11 +85,11 @@ public class CapacitorCookies extends Plugin {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
@JavascriptInterface
|
|
87
|
-
public void setCookie(String
|
|
88
|
-
String url =
|
|
88
|
+
public void setCookie(String domain, String action) {
|
|
89
|
+
String url = cookieManager.getSanitizedDomain(domain);
|
|
89
90
|
|
|
90
91
|
if (!url.isEmpty()) {
|
|
91
|
-
cookieManager.setCookie(url,
|
|
92
|
+
cookieManager.setCookie(url, action);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -110,9 +111,11 @@ public class CapacitorCookies extends Plugin {
|
|
|
110
111
|
String key = call.getString("key");
|
|
111
112
|
String value = call.getString("value");
|
|
112
113
|
String url = getServerUrl(call);
|
|
114
|
+
String expires = call.getString("expires", "");
|
|
115
|
+
String path = call.getString("path", "/");
|
|
113
116
|
|
|
114
117
|
if (!url.isEmpty()) {
|
|
115
|
-
cookieManager.setCookie(url, key, value);
|
|
118
|
+
cookieManager.setCookie(url, key, value, expires, path);
|
|
116
119
|
call.resolve();
|
|
117
120
|
}
|
|
118
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/android",
|
|
3
|
-
"version": "4.5.0",
|
|
3
|
+
"version": "4.5.1-dev-20221117T024619.0",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"verify": "./gradlew clean lint build test -b capacitor/build.gradle"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@capacitor/core": "^4.
|
|
26
|
+
"@capacitor/core": "^4.5.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "6c509ade89ed4e09169bfd3d3a79fac2b9fe0c4d"
|
|
32
32
|
}
|