@@ -24,8 +24,12 @@ Licensed to the Apache Software Foundation (ASF) under one
2424import org .json .JSONArray ;
2525import org .json .JSONException ;
2626
27+ import android .annotation .TargetApi ;
28+ import android .os .Build ;
29+ import android .os .Message ;
2730import android .webkit .JsPromptResult ;
2831import android .webkit .WebChromeClient ;
32+ import android .webkit .WebResourceRequest ;
2933import android .webkit .WebStorage ;
3034import android .webkit .WebView ;
3135import android .webkit .WebViewClient ;
@@ -135,4 +139,45 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
135139 return false ;
136140 }
137141
142+ /**
143+ * The InAppWebBrowser WebView is configured to MultipleWindow mode to mitigate a security
144+ * bug found in Chromium prior to version 83.0.4103.106.
145+ * See https://bugs.chromium.org/p/chromium/issues/detail?id=1083819
146+ *
147+ * Valid Urls set to open in new window will be routed back to load in the original WebView.
148+ *
149+ * @param view
150+ * @param isDialog
151+ * @param isUserGesture
152+ * @param resultMsg
153+ * @return
154+ */
155+ @ Override
156+ public boolean onCreateWindow (WebView view , boolean isDialog , boolean isUserGesture , Message resultMsg ) {
157+ WebView inAppWebView = view ;
158+ final WebViewClient webViewClient =
159+ new WebViewClient () {
160+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
161+ @ Override
162+ public boolean shouldOverrideUrlLoading (WebView view , WebResourceRequest request ) {
163+ inAppWebView .loadUrl (request .getUrl ().toString ());
164+ return true ;
165+ }
166+
167+ @ Override
168+ public boolean shouldOverrideUrlLoading (WebView view , String url ) {
169+ inAppWebView .loadUrl (url );
170+ return true ;
171+ }
172+ };
173+
174+ final WebView newWebView = new WebView (view .getContext ());
175+ newWebView .setWebViewClient (webViewClient );
176+
177+ final WebView .WebViewTransport transport = (WebView .WebViewTransport ) resultMsg .obj ;
178+ transport .setWebView (newWebView );
179+ resultMsg .sendToTarget ();
180+
181+ return true ;
182+ }
138183}
0 commit comments