Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Android proxy #222

Merged
merged 11 commits into from
Nov 5, 2024
Merged
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [6.9.4](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.9.3...6.9.4) (2024-11-04)

### [6.9.3](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.9.2...6.9.3) (2024-11-04)

### [6.9.2](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.9.1...6.9.2) (2024-11-02)

### [6.9.1](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.9.0...6.9.1) (2024-11-02)


### Bug Fixes

* fix semaphore timeout on proxy error ([ed14ff4](https://github.com/Cap-go/capacitor-inappbrowser/commit/ed14ff4cd81d81001248aa2cdf6c89ac8158a861))

## [6.9.0](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.8.21...6.9.0) (2024-11-02)


### Features

* proxy android ([160d542](https://github.com/Cap-go/capacitor-inappbrowser/commit/160d542d643ecdd3fe546f2df251c762d724562f))

### [6.8.21](https://github.com/Cap-go/capacitor-inappbrowser/compare/6.8.20...6.8.21) (2024-10-31)


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ Reload the current web page.
| **`showArrow`** | <code>boolean</code> | showArrow: if true an arrow would be shown instead of cross for closing the window | <code>false</code> | 1.2.5 |
| **`ignoreUntrustedSSLError`** | <code>boolean</code> | ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website. | <code>false</code> | 6.1.0 |
| **`preShowScript`** | <code><a href="#string">String</a></code> | preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser. This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds) | | 6.6.0 |
| **`proxyRequests`** | <code><a href="#string">String</a></code> | proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only) | | 6.9.0 |
| **`buttonNearDone`** | <code>{ ios: { iconType: 'sf-symbol' \| 'asset'; icon: <a href="#string">String</a>; }; android: { iconType: 'asset'; icon: <a href="#string">String</a>; width?: number; height?: number; }; }</code> | buttonNearDone allows for a creation of a custom button. Please see [buttonNearDone.md](/buttonNearDone.md) for more info. | | 6.7.0 |


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.getcapacitor.annotation.PermissionCallback;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -426,6 +428,18 @@ public void openWebView(PluginCall call) {
Boolean.TRUE.equals(call.getBoolean("ignoreUntrustedSSLError", false))
);

String proxyRequestsStr = call.getString("proxyRequests");
if (proxyRequestsStr != null) {
try {
options.setProxyRequestsPattern(Pattern.compile(proxyRequestsStr));
} catch (PatternSyntaxException e) {
Log.e(
"WebViewDialog",
String.format("Pattern '%s' is not a valid pattern", proxyRequestsStr)
);
}
}

try {
Options.ButtonNearDone buttonNearDone =
Options.ButtonNearDone.generateFromPluginCall(
Expand Down Expand Up @@ -552,10 +566,11 @@ public void run() {
getContext(),
android.R.style.Theme_NoTitleBar,
options,
InAppBrowserPlugin.this
InAppBrowserPlugin.this,
getBridge().getWebView()
);
webViewDialog.presentWebView();
webViewDialog.activity = InAppBrowserPlugin.this.getActivity();
webViewDialog.presentWebView();
}
}
);
Expand All @@ -573,6 +588,7 @@ public void postMessage(PluginCall call) {
call.reject("No event data provided");
return;
}

Log.d("InAppBrowserPlugin", "Event data: " + eventData.toString());
this.getActivity()
.runOnUiThread(
Expand Down Expand Up @@ -624,6 +640,26 @@ public void run() {
call.resolve();
}

@PluginMethod
public void lsuakdchgbbaHandleProxiedRequest(PluginCall call) {
if (webViewDialog != null) {
Boolean ok = call.getBoolean("ok", false);
String id = call.getString("id");
if (id == null) {
Log.e("InAppBrowserProxy", "CRITICAL ERROR, proxy id = null");
return;
}
if (Boolean.FALSE.equals(ok)) {
String result = call.getString("result", "");
webViewDialog.handleProxyResultError(result, id);
} else {
JSONObject object = call.getObject("result");
webViewDialog.handleProxyResultOk(object, id);
}
}
call.resolve();
}

@PluginMethod
public void close(PluginCall call) {
this.getActivity()
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.regex.Pattern;

public class Options {

Expand Down Expand Up @@ -129,6 +130,15 @@ public int getWidth() {
private boolean ShowArrow;
private boolean ignoreUntrustedSSLError;
private String preShowScript;
private Pattern proxyRequestsPattern = null;

public Pattern getProxyRequestsPattern() {
return proxyRequestsPattern;
}

public void setProxyRequestsPattern(Pattern proxyRequestsPattern) {
this.proxyRequestsPattern = proxyRequestsPattern;
}

public PluginCall getPluginCall() {
return pluginCall;
Expand Down
Loading
Loading