@capgo/inappbrowser 7.0.0 → 7.1.6
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/CapgoInappbrowser.podspec +1 -1
- package/README.md +448 -54
- package/android/build.gradle +15 -13
- package/android/src/main/AndroidManifest.xml +2 -1
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +530 -35
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java +251 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewCallbacks.java +4 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +904 -20
- package/android/src/main/res/drawable/ic_refresh.xml +9 -0
- package/android/src/main/res/layout/tool_bar.xml +25 -3
- package/android/src/main/res/values/strings.xml +2 -0
- package/dist/docs.json +1365 -67
- package/dist/esm/definitions.d.ts +218 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +10 -2
- package/dist/esm/web.js +26 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +26 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +26 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/InAppBrowserPlugin.m +5 -1
- package/ios/Plugin/InAppBrowserPlugin.swift +247 -12
- package/ios/Plugin/WKWebViewController.swift +303 -55
- package/package.json +26 -27
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package ee.forgr.capacitor_inappbrowser;
|
|
2
2
|
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.app.Activity;
|
|
3
5
|
import android.content.ComponentName;
|
|
4
6
|
import android.content.Intent;
|
|
5
7
|
import android.content.pm.PackageManager;
|
|
@@ -8,31 +10,204 @@ import android.net.Uri;
|
|
|
8
10
|
import android.os.Bundle;
|
|
9
11
|
import android.text.TextUtils;
|
|
10
12
|
import android.util.Log;
|
|
11
|
-
import android.webkit.
|
|
13
|
+
import android.webkit.CookieManager;
|
|
14
|
+
import android.webkit.PermissionRequest;
|
|
15
|
+
import androidx.annotation.NonNull;
|
|
12
16
|
import androidx.browser.customtabs.CustomTabsCallback;
|
|
13
17
|
import androidx.browser.customtabs.CustomTabsClient;
|
|
14
18
|
import androidx.browser.customtabs.CustomTabsIntent;
|
|
15
19
|
import androidx.browser.customtabs.CustomTabsServiceConnection;
|
|
16
20
|
import androidx.browser.customtabs.CustomTabsSession;
|
|
17
21
|
import com.getcapacitor.JSObject;
|
|
22
|
+
import com.getcapacitor.PermissionState;
|
|
18
23
|
import com.getcapacitor.Plugin;
|
|
19
24
|
import com.getcapacitor.PluginCall;
|
|
20
25
|
import com.getcapacitor.PluginMethod;
|
|
21
26
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
27
|
+
import com.getcapacitor.annotation.Permission;
|
|
28
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
29
|
+
import java.util.ArrayList;
|
|
22
30
|
import java.util.Iterator;
|
|
31
|
+
import java.util.regex.Pattern;
|
|
32
|
+
import java.util.regex.PatternSyntaxException;
|
|
33
|
+
import org.json.JSONException;
|
|
34
|
+
import org.json.JSONObject;
|
|
23
35
|
|
|
24
|
-
@CapacitorPlugin(
|
|
25
|
-
|
|
36
|
+
@CapacitorPlugin(
|
|
37
|
+
name = "InAppBrowser",
|
|
38
|
+
permissions = {
|
|
39
|
+
@Permission(alias = "camera", strings = { Manifest.permission.CAMERA }),
|
|
40
|
+
@Permission(
|
|
41
|
+
alias = "microphone",
|
|
42
|
+
strings = { Manifest.permission.RECORD_AUDIO }
|
|
43
|
+
),
|
|
44
|
+
@Permission(
|
|
45
|
+
alias = "storage",
|
|
46
|
+
strings = { Manifest.permission.READ_EXTERNAL_STORAGE }
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
requestCodes = { WebViewDialog.FILE_CHOOSER_REQUEST_CODE }
|
|
50
|
+
)
|
|
51
|
+
public class InAppBrowserPlugin
|
|
52
|
+
extends Plugin
|
|
53
|
+
implements WebViewDialog.PermissionHandler {
|
|
26
54
|
|
|
27
55
|
public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
|
|
28
56
|
private CustomTabsClient customTabsClient;
|
|
29
57
|
private CustomTabsSession currentSession;
|
|
30
58
|
private WebViewDialog webViewDialog = null;
|
|
59
|
+
private String currentUrl = "";
|
|
60
|
+
|
|
61
|
+
private PermissionRequest currentPermissionRequest;
|
|
62
|
+
|
|
63
|
+
public void handleMicrophonePermissionRequest(PermissionRequest request) {
|
|
64
|
+
this.currentPermissionRequest = request;
|
|
65
|
+
if (getPermissionState("microphone") != PermissionState.GRANTED) {
|
|
66
|
+
requestPermissionForAlias(
|
|
67
|
+
"microphone",
|
|
68
|
+
null,
|
|
69
|
+
"microphonePermissionCallback"
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
grantMicrophonePermission();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private void grantMicrophonePermission() {
|
|
77
|
+
if (currentPermissionRequest != null) {
|
|
78
|
+
currentPermissionRequest.grant(
|
|
79
|
+
new String[] { PermissionRequest.RESOURCE_AUDIO_CAPTURE }
|
|
80
|
+
);
|
|
81
|
+
currentPermissionRequest = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@PermissionCallback
|
|
86
|
+
private void microphonePermissionCallback(PluginCall call) {
|
|
87
|
+
if (getPermissionState("microphone") == PermissionState.GRANTED) {
|
|
88
|
+
grantCameraAndMicrophonePermission();
|
|
89
|
+
} else {
|
|
90
|
+
if (currentPermissionRequest != null) {
|
|
91
|
+
currentPermissionRequest.deny();
|
|
92
|
+
currentPermissionRequest = null;
|
|
93
|
+
}
|
|
94
|
+
call.reject("Microphone permission is required");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private void grantCameraAndMicrophonePermission() {
|
|
99
|
+
if (currentPermissionRequest != null) {
|
|
100
|
+
currentPermissionRequest.grant(
|
|
101
|
+
new String[] {
|
|
102
|
+
PermissionRequest.RESOURCE_VIDEO_CAPTURE,
|
|
103
|
+
PermissionRequest.RESOURCE_AUDIO_CAPTURE,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
currentPermissionRequest = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public void handleCameraPermissionRequest(PermissionRequest request) {
|
|
111
|
+
this.currentPermissionRequest = request;
|
|
112
|
+
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
113
|
+
requestPermissionForAlias("camera", null, "cameraPermissionCallback");
|
|
114
|
+
} else if (getPermissionState("microphone") != PermissionState.GRANTED) {
|
|
115
|
+
requestPermissionForAlias(
|
|
116
|
+
"microphone",
|
|
117
|
+
null,
|
|
118
|
+
"microphonePermissionCallback"
|
|
119
|
+
);
|
|
120
|
+
} else {
|
|
121
|
+
grantCameraAndMicrophonePermission();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Override
|
|
126
|
+
protected void handleOnActivityResult(
|
|
127
|
+
int requestCode,
|
|
128
|
+
int resultCode,
|
|
129
|
+
Intent data
|
|
130
|
+
) {
|
|
131
|
+
super.handleOnActivityResult(requestCode, resultCode, data);
|
|
132
|
+
|
|
133
|
+
// Check if the request code matches the file chooser request code
|
|
134
|
+
if (requestCode == WebViewDialog.FILE_CHOOSER_REQUEST_CODE) {
|
|
135
|
+
if (webViewDialog != null && webViewDialog.mFilePathCallback != null) {
|
|
136
|
+
Uri[] results = null;
|
|
137
|
+
|
|
138
|
+
if (resultCode == Activity.RESULT_OK) {
|
|
139
|
+
if (data != null) {
|
|
140
|
+
String dataString = data.getDataString();
|
|
141
|
+
if (data.getClipData() != null) { // If multiple file selected
|
|
142
|
+
int count = data.getClipData().getItemCount();
|
|
143
|
+
results = new Uri[count];
|
|
144
|
+
for (int i = 0; i < count; i++) {
|
|
145
|
+
results[i] = data.getClipData().getItemAt(i).getUri();
|
|
146
|
+
}
|
|
147
|
+
} else if (dataString != null) { //if single file selected
|
|
148
|
+
results = new Uri[] { Uri.parse(dataString) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Pass the results back to the WebView
|
|
154
|
+
try {
|
|
155
|
+
webViewDialog.mFilePathCallback.onReceiveValue(results);
|
|
156
|
+
webViewDialog.mFilePathCallback = null;
|
|
157
|
+
} catch (Exception e) {
|
|
158
|
+
Log.e("ACTIVITYRESULT", e.getMessage());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@PermissionCallback
|
|
165
|
+
private void cameraPermissionCallback() {
|
|
166
|
+
if (getPermissionState("camera") == PermissionState.GRANTED) {
|
|
167
|
+
grantCameraPermission();
|
|
168
|
+
} else {
|
|
169
|
+
if (currentPermissionRequest != null) {
|
|
170
|
+
currentPermissionRequest.deny();
|
|
171
|
+
currentPermissionRequest = null;
|
|
172
|
+
}
|
|
173
|
+
// Handle the case where permission was not granted
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@PermissionCallback
|
|
178
|
+
private void cameraPermissionCallback(PluginCall call) {
|
|
179
|
+
if (getPermissionState("camera") == PermissionState.GRANTED) {
|
|
180
|
+
if (getPermissionState("microphone") != PermissionState.GRANTED) {
|
|
181
|
+
requestPermissionForAlias(
|
|
182
|
+
"microphone",
|
|
183
|
+
null,
|
|
184
|
+
"microphonePermissionCallback"
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
grantCameraAndMicrophonePermission();
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
if (currentPermissionRequest != null) {
|
|
191
|
+
currentPermissionRequest.deny();
|
|
192
|
+
currentPermissionRequest = null;
|
|
193
|
+
}
|
|
194
|
+
call.reject("Camera permission is required");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private void grantCameraPermission() {
|
|
199
|
+
if (currentPermissionRequest != null) {
|
|
200
|
+
currentPermissionRequest.grant(
|
|
201
|
+
new String[] { PermissionRequest.RESOURCE_VIDEO_CAPTURE }
|
|
202
|
+
);
|
|
203
|
+
currentPermissionRequest = null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
31
206
|
|
|
32
207
|
CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
|
|
33
208
|
@Override
|
|
34
209
|
public void onCustomTabsServiceConnected(
|
|
35
|
-
ComponentName name,
|
|
210
|
+
@NonNull ComponentName name,
|
|
36
211
|
CustomTabsClient client
|
|
37
212
|
) {
|
|
38
213
|
customTabsClient = client;
|
|
@@ -43,12 +218,22 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
43
218
|
public void onServiceDisconnected(ComponentName name) {}
|
|
44
219
|
};
|
|
45
220
|
|
|
221
|
+
@PluginMethod
|
|
222
|
+
public void requestCameraPermission(PluginCall call) {
|
|
223
|
+
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
224
|
+
requestPermissionForAlias("camera", call, "cameraPermissionCallback");
|
|
225
|
+
} else {
|
|
226
|
+
call.resolve();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
46
230
|
@PluginMethod
|
|
47
231
|
public void setUrl(PluginCall call) {
|
|
48
232
|
String url = call.getString("url");
|
|
49
233
|
if (url == null || TextUtils.isEmpty(url)) {
|
|
50
234
|
call.reject("Invalid URL");
|
|
51
235
|
}
|
|
236
|
+
currentUrl = url;
|
|
52
237
|
this.getActivity()
|
|
53
238
|
.runOnUiThread(
|
|
54
239
|
new Runnable() {
|
|
@@ -71,6 +256,7 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
71
256
|
if (url == null || TextUtils.isEmpty(url)) {
|
|
72
257
|
call.reject("Invalid URL");
|
|
73
258
|
}
|
|
259
|
+
currentUrl = url;
|
|
74
260
|
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(
|
|
75
261
|
getCustomTabsSession()
|
|
76
262
|
);
|
|
@@ -110,29 +296,198 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
110
296
|
call.resolve();
|
|
111
297
|
}
|
|
112
298
|
|
|
299
|
+
@PluginMethod
|
|
300
|
+
public void clearCache(PluginCall call) {
|
|
301
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
302
|
+
cookieManager.removeAllCookies(null);
|
|
303
|
+
cookieManager.flush();
|
|
304
|
+
call.resolve();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@PluginMethod
|
|
308
|
+
public void clearAllCookies(PluginCall call) {
|
|
309
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
310
|
+
cookieManager.removeAllCookies(null);
|
|
311
|
+
cookieManager.flush();
|
|
312
|
+
call.resolve();
|
|
313
|
+
}
|
|
314
|
+
|
|
113
315
|
@PluginMethod
|
|
114
316
|
public void clearCookies(PluginCall call) {
|
|
115
|
-
|
|
317
|
+
String url = call.getString("url", currentUrl);
|
|
318
|
+
if (url == null || TextUtils.isEmpty(url)) {
|
|
319
|
+
call.reject("Invalid URL");
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
Uri uri = Uri.parse(url);
|
|
324
|
+
String host = uri.getHost();
|
|
325
|
+
if (host == null || TextUtils.isEmpty(host)) {
|
|
326
|
+
call.reject("Invalid URL (Host is null)");
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
331
|
+
String cookieString = cookieManager.getCookie(url);
|
|
332
|
+
ArrayList<String> cookiesToRemove = new ArrayList<>();
|
|
333
|
+
|
|
334
|
+
if (cookieString != null) {
|
|
335
|
+
String[] cookies = cookieString.split("; ");
|
|
336
|
+
|
|
337
|
+
String domain = uri.getHost();
|
|
338
|
+
|
|
339
|
+
for (String cookie : cookies) {
|
|
340
|
+
String[] parts = cookie.split("=");
|
|
341
|
+
if (parts.length > 0) {
|
|
342
|
+
cookiesToRemove.add(parts[0].trim());
|
|
343
|
+
CookieManager.getInstance()
|
|
344
|
+
.setCookie(url, String.format("%s=del;", parts[0].trim()));
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
StringBuilder scriptToRun = new StringBuilder();
|
|
350
|
+
for (String cookieToRemove : cookiesToRemove) {
|
|
351
|
+
scriptToRun.append(
|
|
352
|
+
String.format(
|
|
353
|
+
"window.cookieStore.delete('%s', {name: '%s', domain: '%s'});",
|
|
354
|
+
cookieToRemove,
|
|
355
|
+
cookieToRemove,
|
|
356
|
+
url
|
|
357
|
+
)
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
Log.i("DelCookies", String.format("Script to run:\n%s", scriptToRun));
|
|
362
|
+
|
|
363
|
+
this.getActivity()
|
|
364
|
+
.runOnUiThread(
|
|
365
|
+
new Runnable() {
|
|
366
|
+
@Override
|
|
367
|
+
public void run() {
|
|
368
|
+
webViewDialog.executeScript(scriptToRun.toString());
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
|
|
116
373
|
call.resolve();
|
|
117
374
|
}
|
|
118
375
|
|
|
376
|
+
@PluginMethod
|
|
377
|
+
public void getCookies(PluginCall call) {
|
|
378
|
+
String url = call.getString("url");
|
|
379
|
+
if (url == null || TextUtils.isEmpty(url)) {
|
|
380
|
+
call.reject("Invalid URL");
|
|
381
|
+
} else {
|
|
382
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
383
|
+
String cookieString = cookieManager.getCookie(url);
|
|
384
|
+
if (cookieString != null) {
|
|
385
|
+
String[] cookiePairs = cookieString.split("; ");
|
|
386
|
+
JSObject result = new JSObject();
|
|
387
|
+
for (String cookie : cookiePairs) {
|
|
388
|
+
String[] parts = cookie.split("=", 2);
|
|
389
|
+
if (parts.length == 2) {
|
|
390
|
+
result.put(parts[0], parts[1]);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
call.resolve(result);
|
|
394
|
+
}
|
|
395
|
+
call.resolve(new JSObject());
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
119
399
|
@PluginMethod
|
|
120
400
|
public void openWebView(PluginCall call) {
|
|
121
401
|
String url = call.getString("url");
|
|
122
402
|
if (url == null || TextUtils.isEmpty(url)) {
|
|
123
403
|
call.reject("Invalid URL");
|
|
124
404
|
}
|
|
405
|
+
currentUrl = url;
|
|
125
406
|
final Options options = new Options();
|
|
126
407
|
options.setUrl(url);
|
|
127
408
|
options.setHeaders(call.getObject("headers"));
|
|
128
|
-
options.
|
|
409
|
+
options.setCredentials(call.getObject("credentials"));
|
|
410
|
+
options.setShowReloadButton(
|
|
411
|
+
Boolean.TRUE.equals(call.getBoolean("showReloadButton", false))
|
|
412
|
+
);
|
|
413
|
+
options.setVisibleTitle(
|
|
414
|
+
Boolean.TRUE.equals(call.getBoolean("visibleTitle", true))
|
|
415
|
+
);
|
|
416
|
+
if (Boolean.TRUE.equals(options.getVisibleTitle())) {
|
|
417
|
+
options.setTitle(call.getString("title", "New Window"));
|
|
418
|
+
} else {
|
|
419
|
+
options.setTitle(call.getString("title", ""));
|
|
420
|
+
}
|
|
421
|
+
options.setToolbarColor(call.getString("toolbarColor", "#ffffff"));
|
|
422
|
+
options.setArrow(Boolean.TRUE.equals(call.getBoolean("showArrow", false)));
|
|
423
|
+
options.setIgnoreUntrustedSSLError(
|
|
424
|
+
Boolean.TRUE.equals(call.getBoolean("ignoreUntrustedSSLError", false))
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
String proxyRequestsStr = call.getString("proxyRequests");
|
|
428
|
+
if (proxyRequestsStr != null) {
|
|
429
|
+
try {
|
|
430
|
+
options.setProxyRequestsPattern(Pattern.compile(proxyRequestsStr));
|
|
431
|
+
} catch (PatternSyntaxException e) {
|
|
432
|
+
Log.e(
|
|
433
|
+
"WebViewDialog",
|
|
434
|
+
String.format("Pattern '%s' is not a valid pattern", proxyRequestsStr)
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
try {
|
|
440
|
+
Options.ButtonNearDone buttonNearDone =
|
|
441
|
+
Options.ButtonNearDone.generateFromPluginCall(
|
|
442
|
+
call,
|
|
443
|
+
getActivity().getAssets()
|
|
444
|
+
);
|
|
445
|
+
options.setButtonNearDone(buttonNearDone);
|
|
446
|
+
} catch (IllegalArgumentException illegalArgumentException) {
|
|
447
|
+
call.reject(
|
|
448
|
+
String.format(
|
|
449
|
+
"ButtonNearDone rejected: %s",
|
|
450
|
+
illegalArgumentException.getMessage()
|
|
451
|
+
)
|
|
452
|
+
);
|
|
453
|
+
} catch (RuntimeException e) {
|
|
454
|
+
Log.e(
|
|
455
|
+
"WebViewDialog",
|
|
456
|
+
String.format("ButtonNearDone runtime error: %s", e)
|
|
457
|
+
);
|
|
458
|
+
call.reject(String.format("ButtonNearDone RuntimeException: %s", e));
|
|
459
|
+
}
|
|
460
|
+
|
|
129
461
|
options.setShareDisclaimer(call.getObject("shareDisclaimer", null));
|
|
462
|
+
options.setPreShowScript(call.getString("preShowScript", null));
|
|
130
463
|
options.setShareSubject(call.getString("shareSubject", null));
|
|
131
464
|
options.setToolbarType(call.getString("toolbarType", ""));
|
|
465
|
+
options.setActiveNativeNavigationForWebview(
|
|
466
|
+
Boolean.TRUE.equals(
|
|
467
|
+
call.getBoolean("activeNativeNavigationForWebview", false)
|
|
468
|
+
)
|
|
469
|
+
);
|
|
470
|
+
options.setDisableGoBackOnNativeApplication(
|
|
471
|
+
Boolean.TRUE.equals(
|
|
472
|
+
call.getBoolean("disableGoBackOnNativeApplication", false)
|
|
473
|
+
)
|
|
474
|
+
);
|
|
132
475
|
options.setPresentAfterPageLoad(
|
|
133
|
-
call.getBoolean("isPresentAfterPageLoad", false)
|
|
476
|
+
Boolean.TRUE.equals(call.getBoolean("isPresentAfterPageLoad", false))
|
|
134
477
|
);
|
|
478
|
+
if (Boolean.TRUE.equals(call.getBoolean("closeModal", false))) {
|
|
479
|
+
options.setCloseModal(true);
|
|
480
|
+
options.setCloseModalTitle(call.getString("closeModalTitle", "Close"));
|
|
481
|
+
options.setCloseModalDescription(
|
|
482
|
+
call.getString("closeModalDescription", "Are you sure ?")
|
|
483
|
+
);
|
|
484
|
+
options.setCloseModalOk(call.getString("closeModalOk", "Ok"));
|
|
485
|
+
options.setCloseModalCancel(call.getString("closeModalCancel", "Cancel"));
|
|
486
|
+
} else {
|
|
487
|
+
options.setCloseModal(false);
|
|
488
|
+
}
|
|
135
489
|
options.setPluginCall(call);
|
|
490
|
+
// options.getToolbarItemTypes().add(ToolbarItemType.RELOAD); TODO: fix this
|
|
136
491
|
options.setCallbacks(
|
|
137
492
|
new WebViewCallbacks() {
|
|
138
493
|
@Override
|
|
@@ -154,19 +509,63 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
154
509
|
public void pageLoadError() {
|
|
155
510
|
notifyListeners("pageLoadError", new JSObject());
|
|
156
511
|
}
|
|
512
|
+
|
|
513
|
+
@Override
|
|
514
|
+
public void buttonNearDoneClicked() {
|
|
515
|
+
notifyListeners("buttonNearDoneClick", new JSObject());
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
@Override
|
|
519
|
+
public void javascriptCallback(String message) {
|
|
520
|
+
// Handle the message received from JavaScript
|
|
521
|
+
Log.d(
|
|
522
|
+
"WebViewDialog",
|
|
523
|
+
"Received message from JavaScript: " + message
|
|
524
|
+
);
|
|
525
|
+
// Process the message as needed
|
|
526
|
+
try {
|
|
527
|
+
// Parse the received message as a JSON object
|
|
528
|
+
JSONObject jsonMessage = new JSONObject(message);
|
|
529
|
+
|
|
530
|
+
// Create a new JSObject to send to the Capacitor plugin
|
|
531
|
+
JSObject jsObject = new JSObject();
|
|
532
|
+
|
|
533
|
+
// Iterate through the keys in the JSON object and add them to the JSObject
|
|
534
|
+
Iterator<String> keys = jsonMessage.keys();
|
|
535
|
+
while (keys.hasNext()) {
|
|
536
|
+
String key = keys.next();
|
|
537
|
+
jsObject.put(key, jsonMessage.get(key));
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// Notify listeners with the parsed message
|
|
541
|
+
notifyListeners("messageFromWebview", jsObject);
|
|
542
|
+
} catch (JSONException e) {
|
|
543
|
+
Log.e(
|
|
544
|
+
"WebViewDialog",
|
|
545
|
+
"Error parsing JSON message: " + e.getMessage()
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
// If JSON parsing fails, send the raw message as a string
|
|
549
|
+
JSObject jsObject = new JSObject();
|
|
550
|
+
jsObject.put("rawMessage", message);
|
|
551
|
+
notifyListeners("messageFromWebview", jsObject);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
157
554
|
}
|
|
158
555
|
);
|
|
159
|
-
getActivity()
|
|
556
|
+
this.getActivity()
|
|
160
557
|
.runOnUiThread(
|
|
161
558
|
new Runnable() {
|
|
162
559
|
@Override
|
|
163
560
|
public void run() {
|
|
164
|
-
webViewDialog =
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
)
|
|
561
|
+
webViewDialog = new WebViewDialog(
|
|
562
|
+
getContext(),
|
|
563
|
+
android.R.style.Theme_NoTitleBar,
|
|
564
|
+
options,
|
|
565
|
+
InAppBrowserPlugin.this,
|
|
566
|
+
getBridge().getWebView()
|
|
567
|
+
);
|
|
568
|
+
webViewDialog.activity = InAppBrowserPlugin.this.getActivity();
|
|
170
569
|
webViewDialog.presentWebView();
|
|
171
570
|
}
|
|
172
571
|
}
|
|
@@ -174,21 +573,118 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
174
573
|
}
|
|
175
574
|
|
|
176
575
|
@PluginMethod
|
|
177
|
-
public void
|
|
178
|
-
if (webViewDialog
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
576
|
+
public void postMessage(PluginCall call) {
|
|
577
|
+
if (webViewDialog == null) {
|
|
578
|
+
call.reject("WebView is not initialized");
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
JSObject eventData = call.getObject("detail");
|
|
582
|
+
// Log event data
|
|
583
|
+
if (eventData == null) {
|
|
584
|
+
call.reject("No event data provided");
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
Log.d("InAppBrowserPlugin", "Event data: " + eventData.toString());
|
|
589
|
+
this.getActivity()
|
|
590
|
+
.runOnUiThread(
|
|
591
|
+
new Runnable() {
|
|
592
|
+
@Override
|
|
593
|
+
public void run() {
|
|
594
|
+
webViewDialog.postMessageToJS(eventData);
|
|
595
|
+
call.resolve();
|
|
596
|
+
}
|
|
597
|
+
}
|
|
185
598
|
);
|
|
186
|
-
|
|
187
|
-
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
@PluginMethod
|
|
602
|
+
public void executeScript(PluginCall call) {
|
|
603
|
+
String script = call.getString("code");
|
|
604
|
+
if (script == null || TextUtils.isEmpty(script)) {
|
|
605
|
+
call.reject("No script to run");
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (webViewDialog != null) {
|
|
609
|
+
this.getActivity()
|
|
610
|
+
.runOnUiThread(
|
|
611
|
+
new Runnable() {
|
|
612
|
+
@Override
|
|
613
|
+
public void run() {
|
|
614
|
+
webViewDialog.executeScript(script);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
call.resolve();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
@PluginMethod
|
|
624
|
+
public void reload(PluginCall call) {
|
|
625
|
+
if (webViewDialog != null) {
|
|
626
|
+
this.getActivity()
|
|
627
|
+
.runOnUiThread(
|
|
628
|
+
new Runnable() {
|
|
629
|
+
@Override
|
|
630
|
+
public void run() {
|
|
631
|
+
webViewDialog.reload();
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
);
|
|
188
635
|
}
|
|
189
636
|
call.resolve();
|
|
190
637
|
}
|
|
191
638
|
|
|
639
|
+
@PluginMethod
|
|
640
|
+
public void lsuakdchgbbaHandleProxiedRequest(PluginCall call) {
|
|
641
|
+
if (webViewDialog != null) {
|
|
642
|
+
Boolean ok = call.getBoolean("ok", false);
|
|
643
|
+
String id = call.getString("id");
|
|
644
|
+
if (id == null) {
|
|
645
|
+
Log.e("InAppBrowserProxy", "CRITICAL ERROR, proxy id = null");
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
if (Boolean.FALSE.equals(ok)) {
|
|
649
|
+
String result = call.getString("result", "");
|
|
650
|
+
webViewDialog.handleProxyResultError(result, id);
|
|
651
|
+
} else {
|
|
652
|
+
JSONObject object = call.getObject("result");
|
|
653
|
+
webViewDialog.handleProxyResultOk(object, id);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
call.resolve();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
@PluginMethod
|
|
660
|
+
public void close(PluginCall call) {
|
|
661
|
+
this.getActivity()
|
|
662
|
+
.runOnUiThread(
|
|
663
|
+
new Runnable() {
|
|
664
|
+
@Override
|
|
665
|
+
public void run() {
|
|
666
|
+
if (webViewDialog != null) {
|
|
667
|
+
notifyListeners(
|
|
668
|
+
"closeEvent",
|
|
669
|
+
new JSObject().put("url", webViewDialog.getUrl())
|
|
670
|
+
);
|
|
671
|
+
webViewDialog.dismiss();
|
|
672
|
+
webViewDialog.destroy();
|
|
673
|
+
webViewDialog = null;
|
|
674
|
+
} else {
|
|
675
|
+
Intent intent = new Intent(
|
|
676
|
+
getContext(),
|
|
677
|
+
getBridge().getActivity().getClass()
|
|
678
|
+
);
|
|
679
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
680
|
+
getContext().startActivity(intent);
|
|
681
|
+
}
|
|
682
|
+
call.resolve();
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
192
688
|
private Bundle getHeaders(PluginCall pluginCall) {
|
|
193
689
|
JSObject headersProvided = pluginCall.getObject("headers");
|
|
194
690
|
Bundle headers = new Bundle();
|
|
@@ -223,19 +719,18 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
223
719
|
}
|
|
224
720
|
|
|
225
721
|
if (currentSession == null) {
|
|
226
|
-
currentSession =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
722
|
+
currentSession = customTabsClient.newSession(
|
|
723
|
+
new CustomTabsCallback() {
|
|
724
|
+
@Override
|
|
725
|
+
public void onNavigationEvent(int navigationEvent, Bundle extras) {
|
|
726
|
+
switch (navigationEvent) {
|
|
727
|
+
case NAVIGATION_FINISHED:
|
|
728
|
+
notifyListeners("browserPageLoaded", new JSObject());
|
|
729
|
+
break;
|
|
236
730
|
}
|
|
237
731
|
}
|
|
238
|
-
|
|
732
|
+
}
|
|
733
|
+
);
|
|
239
734
|
}
|
|
240
735
|
return currentSession;
|
|
241
736
|
}
|