@capacitor/android 4.4.0 → 4.4.1-dev-20221114T215445.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.
- package/capacitor/build.gradle +13 -0
- package/capacitor/src/main/assets/native-bridge.js +28 -23
- package/capacitor/src/main/java/com/getcapacitor/PluginCall.java +8 -0
- package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java +5 -0
- package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java +41 -3
- package/package.json +3 -3
package/capacitor/build.gradle
CHANGED
|
@@ -16,9 +16,16 @@ buildscript {
|
|
|
16
16
|
repositories {
|
|
17
17
|
google()
|
|
18
18
|
mavenCentral()
|
|
19
|
+
maven {
|
|
20
|
+
url "https://plugins.gradle.org/m2/"
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
dependencies {
|
|
21
24
|
classpath 'com.android.tools.build:gradle:7.2.1'
|
|
25
|
+
|
|
26
|
+
if (System.getenv("CAP_PUBLISH") == "true") {
|
|
27
|
+
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
|
|
28
|
+
}
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -26,6 +33,12 @@ tasks.withType(Javadoc).all { enabled = false }
|
|
|
26
33
|
|
|
27
34
|
apply plugin: 'com.android.library'
|
|
28
35
|
|
|
36
|
+
if (System.getenv("CAP_PUBLISH") == "true") {
|
|
37
|
+
apply plugin: 'io.github.gradle-nexus.publish-plugin'
|
|
38
|
+
apply from: file('../scripts/publish-root.gradle')
|
|
39
|
+
apply from: file('../scripts/publish-module.gradle')
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
android {
|
|
30
43
|
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
|
|
31
44
|
defaultConfig {
|
|
@@ -310,25 +310,25 @@ const nativeBridge = (function (exports) {
|
|
|
310
310
|
}
|
|
311
311
|
},
|
|
312
312
|
set: function (val) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
313
|
+
if (platform === 'ios') {
|
|
314
|
+
// Use prompt to synchronously set cookies.
|
|
315
|
+
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323
|
|
316
|
+
const payload = {
|
|
317
|
+
type: 'CapacitorCookies.set',
|
|
318
|
+
action: val
|
|
319
|
+
};
|
|
320
|
+
prompt(JSON.stringify(payload));
|
|
321
|
+
}
|
|
322
|
+
else if (typeof win.CapacitorCookiesAndroidInterface !== 'undefined') {
|
|
323
|
+
const cookiePairs = val.split(';');
|
|
324
|
+
const domainSection = val.toLowerCase().split('domain=')[1];
|
|
325
|
+
// if key is not domain
|
|
326
|
+
if (cookiePairs.length > 1 && domainSection != null && domainSection.length > 0) {
|
|
327
|
+
const domain = domainSection.split(';')[0].trim();
|
|
328
|
+
win.CapacitorCookiesAndroidInterface.setCookies(domain, val);
|
|
329
329
|
}
|
|
330
|
-
else
|
|
331
|
-
win.CapacitorCookiesAndroidInterface.setCookie(
|
|
330
|
+
else {
|
|
331
|
+
win.CapacitorCookiesAndroidInterface.setCookie(val);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
},
|
|
@@ -426,7 +426,8 @@ const nativeBridge = (function (exports) {
|
|
|
426
426
|
};
|
|
427
427
|
// XHR patch abort
|
|
428
428
|
window.XMLHttpRequest.prototype.abort = function () {
|
|
429
|
-
if (this._url == null ||
|
|
429
|
+
if (this._url == null ||
|
|
430
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
430
431
|
return win.CapacitorWebXMLHttpRequest.abort.call(this);
|
|
431
432
|
}
|
|
432
433
|
this.readyState = 0;
|
|
@@ -480,14 +481,16 @@ const nativeBridge = (function (exports) {
|
|
|
480
481
|
};
|
|
481
482
|
// XHR patch set request header
|
|
482
483
|
window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
|
|
483
|
-
if (this._url == null ||
|
|
484
|
+
if (this._url == null ||
|
|
485
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
484
486
|
return win.CapacitorWebXMLHttpRequest.setRequestHeader.call(this, header, value);
|
|
485
487
|
}
|
|
486
488
|
this._headers[header] = value;
|
|
487
489
|
};
|
|
488
490
|
// XHR patch send
|
|
489
491
|
window.XMLHttpRequest.prototype.send = function (body) {
|
|
490
|
-
if (this._url == null ||
|
|
492
|
+
if (this._url == null ||
|
|
493
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
491
494
|
return win.CapacitorWebXMLHttpRequest.send.call(this, body);
|
|
492
495
|
}
|
|
493
496
|
try {
|
|
@@ -543,7 +546,8 @@ const nativeBridge = (function (exports) {
|
|
|
543
546
|
};
|
|
544
547
|
// XHR patch getAllResponseHeaders
|
|
545
548
|
window.XMLHttpRequest.prototype.getAllResponseHeaders = function () {
|
|
546
|
-
if (this._url == null ||
|
|
549
|
+
if (this._url == null ||
|
|
550
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
547
551
|
return win.CapacitorWebXMLHttpRequest.getAllResponseHeaders.call(this);
|
|
548
552
|
}
|
|
549
553
|
let returnString = '';
|
|
@@ -556,7 +560,8 @@ const nativeBridge = (function (exports) {
|
|
|
556
560
|
};
|
|
557
561
|
// XHR patch getResponseHeader
|
|
558
562
|
window.XMLHttpRequest.prototype.getResponseHeader = function (name) {
|
|
559
|
-
if (this._url == null ||
|
|
563
|
+
if (this._url == null ||
|
|
564
|
+
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) {
|
|
560
565
|
return win.CapacitorWebXMLHttpRequest.getResponseHeader.call(this, name);
|
|
561
566
|
}
|
|
562
567
|
return this._headers[name];
|
|
@@ -318,6 +318,10 @@ public class PluginCall {
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
public JSObject getObject(String name) {
|
|
321
|
+
Logger.warn(
|
|
322
|
+
Logger.tags("Plugin"),
|
|
323
|
+
"getObject calls without a default value will return null in Capacitor 5 instead of an empty object to match iOS behavior"
|
|
324
|
+
);
|
|
321
325
|
return this.getObject(name, new JSObject());
|
|
322
326
|
}
|
|
323
327
|
|
|
@@ -339,6 +343,10 @@ public class PluginCall {
|
|
|
339
343
|
}
|
|
340
344
|
|
|
341
345
|
public JSArray getArray(String name) {
|
|
346
|
+
Logger.warn(
|
|
347
|
+
Logger.tags("Plugin"),
|
|
348
|
+
"getArray calls without a default value will return null in Capacitor 5 instead of an empty array to match iOS behavior"
|
|
349
|
+
);
|
|
342
350
|
return this.getArray(name, new JSArray());
|
|
343
351
|
}
|
|
344
352
|
|
|
@@ -109,6 +109,11 @@ public class CapacitorCookieManager extends CookieManager {
|
|
|
109
109
|
setCookie(url, cookieValue);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
public void setCookie(String url, String key, String value, String expires, String path) {
|
|
113
|
+
String cookieValue = key + "=" + value + "; expires=" + expires + "; path=" + path;
|
|
114
|
+
setCookie(url, cookieValue);
|
|
115
|
+
}
|
|
116
|
+
|
|
112
117
|
/**
|
|
113
118
|
* Removes all cookies. This method is asynchronous.
|
|
114
119
|
*/
|
|
@@ -2,6 +2,7 @@ package com.getcapacitor.plugin;
|
|
|
2
2
|
|
|
3
3
|
import android.webkit.JavascriptInterface;
|
|
4
4
|
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
5
6
|
import com.getcapacitor.Plugin;
|
|
6
7
|
import com.getcapacitor.PluginCall;
|
|
7
8
|
import com.getcapacitor.PluginConfig;
|
|
@@ -55,6 +56,19 @@ public class CapacitorCookies extends Plugin {
|
|
|
55
56
|
return url;
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
private String getSanitizedDomain(String url) {
|
|
60
|
+
if (url == null || url.isEmpty()) {
|
|
61
|
+
url = this.bridge.getLocalUrl();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
URI uri = getUri(url);
|
|
65
|
+
if (uri == null) {
|
|
66
|
+
return getServerUrl(null);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return url;
|
|
70
|
+
}
|
|
71
|
+
|
|
58
72
|
/**
|
|
59
73
|
* Try to parse a url string and if it can't be parsed, return null
|
|
60
74
|
* @param url the url string to try to parse
|
|
@@ -83,11 +97,33 @@ public class CapacitorCookies extends Plugin {
|
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
@JavascriptInterface
|
|
86
|
-
public void setCookie(String
|
|
100
|
+
public void setCookie(String action) {
|
|
87
101
|
String url = getServerUrl(null);
|
|
88
102
|
|
|
89
103
|
if (!url.isEmpty()) {
|
|
90
|
-
cookieManager.setCookie(url,
|
|
104
|
+
cookieManager.setCookie(url, action);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@JavascriptInterface
|
|
109
|
+
public void setCookie(String domain, String action) {
|
|
110
|
+
String url = getSanitizedDomain(domain);
|
|
111
|
+
|
|
112
|
+
if (!url.isEmpty()) {
|
|
113
|
+
cookieManager.setCookie(url, action);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@PluginMethod
|
|
118
|
+
public void getCookies(PluginCall call) {
|
|
119
|
+
String url = getServerUrl(call);
|
|
120
|
+
if (!url.isEmpty()) {
|
|
121
|
+
JSObject cookiesMap = new JSObject();
|
|
122
|
+
HttpCookie[] cookies = cookieManager.getCookies(url);
|
|
123
|
+
for (HttpCookie cookie : cookies) {
|
|
124
|
+
cookiesMap.put(cookie.getName(), cookie.getValue());
|
|
125
|
+
}
|
|
126
|
+
call.resolve(cookiesMap);
|
|
91
127
|
}
|
|
92
128
|
}
|
|
93
129
|
|
|
@@ -96,9 +132,11 @@ public class CapacitorCookies extends Plugin {
|
|
|
96
132
|
String key = call.getString("key");
|
|
97
133
|
String value = call.getString("value");
|
|
98
134
|
String url = getServerUrl(call);
|
|
135
|
+
String expires = call.getString("expires", "");
|
|
136
|
+
String path = call.getString("path", "/");
|
|
99
137
|
|
|
100
138
|
if (!url.isEmpty()) {
|
|
101
|
-
cookieManager.setCookie(url, key, value);
|
|
139
|
+
cookieManager.setCookie(url, key, value, expires, path);
|
|
102
140
|
call.resolve();
|
|
103
141
|
}
|
|
104
142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/android",
|
|
3
|
-
"version": "4.4.0",
|
|
3
|
+
"version": "4.4.1-dev-20221114T215445.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.4.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "ecbf81ebb1b01de0b544c3f171fe3b042253088d"
|
|
32
32
|
}
|