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

added support for window.open in onCreateWindow (android) #1679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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