@@ -24,8 +24,12 @@ Licensed to the Apache Software Foundation (ASF) under one
24
24
import org .json .JSONArray ;
25
25
import org .json .JSONException ;
26
26
27
+ import android .annotation .TargetApi ;
28
+ import android .os .Build ;
29
+ import android .os .Message ;
27
30
import android .webkit .JsPromptResult ;
28
31
import android .webkit .WebChromeClient ;
32
+ import android .webkit .WebResourceRequest ;
29
33
import android .webkit .WebStorage ;
30
34
import android .webkit .WebView ;
31
35
import android .webkit .WebViewClient ;
@@ -135,4 +139,45 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
135
139
return false ;
136
140
}
137
141
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
+ }
138
183
}
0 commit comments