@capgo/inappbrowser 1.2.17 → 1.2.19

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/README.md CHANGED
@@ -16,9 +16,19 @@ npx cap sync
16
16
  ```js
17
17
  import { InAppBrowser } from '@capgo/inappbrowser'
18
18
 
19
- InAppBrowser.open("YOUR_URL");
19
+ InAppBrowser.open({ url: "YOUR_URL" });
20
20
  ```
21
21
 
22
+ ### Camera usage
23
+
24
+ if you need the Camera to work in Android, you need to add the following to your `AndroidManifest.xml` file:
25
+
26
+ ```xml
27
+ <uses-permission android:name="android.permission.CAMERA" />
28
+ ```
29
+
30
+ Then the permission will be asked when the camera is used.
31
+
22
32
  ## API
23
33
 
24
34
  <docgen-index>
@@ -1,30 +1,40 @@
1
1
  package ee.forgr.capacitor_inappbrowser;
2
2
 
3
+ import android.Manifest;
3
4
  import android.content.ComponentName;
4
5
  import android.content.Intent;
5
6
  import android.content.pm.PackageManager;
6
7
  import android.content.pm.ResolveInfo;
7
- import android.graphics.Color;
8
8
  import android.net.Uri;
9
9
  import android.os.Bundle;
10
10
  import android.text.TextUtils;
11
11
  import android.util.Log;
12
12
  import android.webkit.CookieManager;
13
- import android.webkit.WebStorage;
13
+ import android.webkit.PermissionRequest;
14
14
  import androidx.browser.customtabs.CustomTabsCallback;
15
15
  import androidx.browser.customtabs.CustomTabsClient;
16
16
  import androidx.browser.customtabs.CustomTabsIntent;
17
17
  import androidx.browser.customtabs.CustomTabsServiceConnection;
18
18
  import androidx.browser.customtabs.CustomTabsSession;
19
19
  import com.getcapacitor.JSObject;
20
+ import com.getcapacitor.PermissionState;
20
21
  import com.getcapacitor.Plugin;
21
22
  import com.getcapacitor.PluginCall;
22
23
  import com.getcapacitor.PluginMethod;
23
24
  import com.getcapacitor.annotation.CapacitorPlugin;
25
+ import com.getcapacitor.annotation.Permission;
26
+ import com.getcapacitor.annotation.PermissionCallback;
24
27
  import java.util.Iterator;
25
28
 
26
- @CapacitorPlugin(name = "InAppBrowser")
27
- public class InAppBrowserPlugin extends Plugin {
29
+ @CapacitorPlugin(
30
+ name = "InAppBrowser",
31
+ permissions = {
32
+ @Permission(alias = "camera", strings = { Manifest.permission.CAMERA }),
33
+ }
34
+ )
35
+ public class InAppBrowserPlugin
36
+ extends Plugin
37
+ implements WebViewDialog.PermissionHandler {
28
38
 
29
39
  public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
30
40
  private CustomTabsClient customTabsClient;
@@ -32,6 +42,39 @@ public class InAppBrowserPlugin extends Plugin {
32
42
  private WebViewDialog webViewDialog = null;
33
43
  private String currentUrl = "";
34
44
 
45
+ private PermissionRequest currentPermissionRequest;
46
+
47
+ public void handleCameraPermissionRequest(PermissionRequest request) {
48
+ this.currentPermissionRequest = request;
49
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
50
+ requestPermissionForAlias("camera", null, "cameraPermissionCallback");
51
+ } else {
52
+ grantCameraPermission();
53
+ }
54
+ }
55
+
56
+ @PermissionCallback
57
+ private void cameraPermissionCallback() {
58
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
59
+ grantCameraPermission();
60
+ } else {
61
+ if (currentPermissionRequest != null) {
62
+ currentPermissionRequest.deny();
63
+ currentPermissionRequest = null;
64
+ }
65
+ // Handle the case where permission was not granted
66
+ }
67
+ }
68
+
69
+ private void grantCameraPermission() {
70
+ if (currentPermissionRequest != null) {
71
+ currentPermissionRequest.grant(
72
+ new String[] { PermissionRequest.RESOURCE_VIDEO_CAPTURE }
73
+ );
74
+ currentPermissionRequest = null;
75
+ }
76
+ }
77
+
35
78
  CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
36
79
  @Override
37
80
  public void onCustomTabsServiceConnected(
@@ -46,6 +89,33 @@ public class InAppBrowserPlugin extends Plugin {
46
89
  public void onServiceDisconnected(ComponentName name) {}
47
90
  };
48
91
 
92
+ @PluginMethod
93
+ public void requestCameraPermission(PluginCall call) {
94
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
95
+ requestPermissionForAlias("camera", call, "cameraPermissionCallback");
96
+ } else {
97
+ call.resolve();
98
+ }
99
+ }
100
+
101
+ @PermissionCallback
102
+ private void cameraPermissionCallback(PluginCall call) {
103
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
104
+ // Permission granted, notify the WebView to proceed
105
+ if (
106
+ webViewDialog != null && webViewDialog.currentPermissionRequest != null
107
+ ) {
108
+ webViewDialog.currentPermissionRequest.grant(
109
+ new String[] { PermissionRequest.RESOURCE_VIDEO_CAPTURE }
110
+ );
111
+ webViewDialog.currentPermissionRequest = null;
112
+ }
113
+ call.resolve();
114
+ } else {
115
+ call.reject("Camera permission is required");
116
+ }
117
+ }
118
+
49
119
  @PluginMethod
50
120
  public void setUrl(PluginCall call) {
51
121
  String url = call.getString("url");
@@ -211,9 +281,11 @@ public class InAppBrowserPlugin extends Plugin {
211
281
  new WebViewDialog(
212
282
  getContext(),
213
283
  android.R.style.Theme_NoTitleBar,
214
- options
284
+ options,
285
+ InAppBrowserPlugin.this
215
286
  );
216
287
  webViewDialog.presentWebView();
288
+ webViewDialog.activity = InAppBrowserPlugin.this.getActivity();
217
289
  }
218
290
  }
219
291
  );
@@ -1,5 +1,6 @@
1
1
  package ee.forgr.capacitor_inappbrowser;
2
2
 
3
+ import android.app.Activity;
3
4
  import android.app.AlertDialog;
4
5
  import android.app.Dialog;
5
6
  import android.content.Context;
@@ -7,15 +8,19 @@ import android.content.DialogInterface;
7
8
  import android.graphics.Bitmap;
8
9
  import android.graphics.Color;
9
10
  import android.text.TextUtils;
11
+ import android.util.Log;
10
12
  import android.view.View;
11
13
  import android.view.Window;
12
14
  import android.view.WindowManager;
15
+ import android.webkit.PermissionRequest;
16
+ import android.webkit.WebChromeClient;
13
17
  import android.webkit.WebResourceError;
14
18
  import android.webkit.WebResourceRequest;
15
19
  import android.webkit.WebView;
16
20
  import android.webkit.WebViewClient;
17
21
  import android.widget.ImageButton;
18
22
  import android.widget.TextView;
23
+ import android.widget.Toast;
19
24
  import android.widget.Toolbar;
20
25
  import java.net.URI;
21
26
  import java.net.URISyntaxException;
@@ -29,12 +34,27 @@ public class WebViewDialog extends Dialog {
29
34
  private Toolbar _toolbar;
30
35
  private Options _options;
31
36
  private Context _context;
37
+ public Activity activity;
32
38
  private boolean isInitialized = false;
33
39
 
34
- public WebViewDialog(Context context, int theme, Options options) {
40
+ public PermissionRequest currentPermissionRequest;
41
+
42
+ public interface PermissionHandler {
43
+ void handleCameraPermissionRequest(PermissionRequest request);
44
+ }
45
+
46
+ private PermissionHandler permissionHandler;
47
+
48
+ public WebViewDialog(
49
+ Context context,
50
+ int theme,
51
+ Options options,
52
+ PermissionHandler permissionHandler
53
+ ) {
35
54
  super(context, theme);
36
55
  this._options = options;
37
56
  this._context = context;
57
+ this.permissionHandler = permissionHandler;
38
58
  this.isInitialized = false;
39
59
  }
40
60
 
@@ -65,6 +85,55 @@ public class WebViewDialog extends Dialog {
65
85
  .setPluginState(android.webkit.WebSettings.PluginState.ON);
66
86
  _webView.getSettings().setLoadWithOverviewMode(true);
67
87
  _webView.getSettings().setUseWideViewPort(true);
88
+ _webView.getSettings().setAllowFileAccessFromFileURLs(true);
89
+ _webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
90
+
91
+ _webView.setWebViewClient(new WebViewClient());
92
+
93
+ _webView.setWebChromeClient(
94
+ new WebChromeClient() {
95
+ // Grant permissions for cam
96
+
97
+ @Override
98
+ public void onPermissionRequest(final PermissionRequest request) {
99
+ Log.i(
100
+ "INAPPBROWSER",
101
+ "onPermissionRequest " + request.getResources().toString()
102
+ );
103
+ final String[] requestedResources = request.getResources();
104
+ for (String r : requestedResources) {
105
+ Log.i("INAPPBROWSER", "requestedResources " + r);
106
+ if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
107
+ Log.i("INAPPBROWSER", "RESOURCE_VIDEO_CAPTURE req");
108
+ // Store the permission request
109
+ currentPermissionRequest = request;
110
+ // Initiate the permission request through the plugin
111
+ if (permissionHandler != null) {
112
+ permissionHandler.handleCameraPermissionRequest(request);
113
+ }
114
+ break;
115
+ }
116
+ }
117
+ }
118
+
119
+ @Override
120
+ public void onPermissionRequestCanceled(PermissionRequest request) {
121
+ super.onPermissionRequestCanceled(request);
122
+ Toast
123
+ .makeText(
124
+ WebViewDialog.this.activity,
125
+ "Permission Denied",
126
+ Toast.LENGTH_SHORT
127
+ )
128
+ .show();
129
+ // Handle the denied permission
130
+ if (currentPermissionRequest != null) {
131
+ currentPermissionRequest.deny();
132
+ currentPermissionRequest = null;
133
+ }
134
+ }
135
+ }
136
+ );
68
137
 
69
138
  Map<String, String> requestHeaders = new HashMap<>();
70
139
  if (_options.getHeaders() != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",