Skip to content

Commit

Permalink
added support for window.open in onCreateWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
zopagaduanjr committed May 17, 2024
1 parent 4c58653 commit 6762b28
Showing 1 changed file with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -625,7 +626,7 @@ public void onCancel(DialogInterface dialog) {
}

@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
public boolean onCreateWindow(WebView view, final boolean isDialog, final boolean isUserGesture, final Message resultMsg) {
int windowId = 0;
if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowAutoincrementId++;
Expand All @@ -647,6 +648,64 @@ public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGest
}
}
}
if(result.getType() == WebView.HitTestResult.UNKNOWN_TYPE) {
WebView targetWebView = new WebView(getActivity());
targetWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
int windowId = 0;
if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowAutoincrementId++;
windowId = plugin.inAppWebViewManager.windowAutoincrementId;
}
URLRequest request = new URLRequest(url, "GET", null, null);
CreateWindowAction createWindowAction = new CreateWindowAction(
request,
true,
isUserGesture,
false,
windowId,
isDialog
);

if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowWebViewMessages.put(windowId, resultMsg);
}

if (inAppWebView != null && inAppWebView.channelDelegate != null) {
int finalWindowId = windowId;
inAppWebView.channelDelegate.onCreateWindow(createWindowAction, new WebViewChannelDelegate.CreateWindowCallback() {
@Override
public boolean nonNullSuccess(@NonNull Boolean handledByClient) {
return !handledByClient;
}

@Override
public void defaultBehaviour(@Nullable Boolean handledByClient) {
if (plugin != null && plugin.inAppWebViewManager != null) {
plugin.inAppWebViewManager.windowWebViewMessages.remove(finalWindowId);
}
}

@Override
public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
Log.e(LOG_TAG, errorCode + ", " + ((errorMessage != null) ? errorMessage : ""));
defaultBehaviour(null);
}
});

return true;
}

return true;

}
});
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(targetWebView);
resultMsg.sendToTarget();
return true;
}

URLRequest request = new URLRequest(url, "GET", null, null);
CreateWindowAction createWindowAction = new CreateWindowAction(
Expand Down

0 comments on commit 6762b28

Please sign in to comment.