@@ -20,8 +20,6 @@ Licensed to the Apache Software Foundation (ASF) under one
20
20
21
21
import android .annotation .SuppressLint ;
22
22
import android .annotation .TargetApi ;
23
- import android .content .ActivityNotFoundException ;
24
- import android .content .ComponentName ;
25
23
import android .content .Context ;
26
24
import android .content .Intent ;
27
25
import android .content .pm .PackageManager ;
@@ -31,8 +29,6 @@ Licensed to the Apache Software Foundation (ASF) under one
31
29
import android .content .res .Resources ;
32
30
import android .graphics .Bitmap ;
33
31
import android .graphics .drawable .Drawable ;
34
- import android .graphics .PorterDuff ;
35
- import android .graphics .PorterDuffColorFilter ;
36
32
import android .graphics .Color ;
37
33
import android .net .http .SslError ;
38
34
import android .net .Uri ;
@@ -49,7 +45,6 @@ Licensed to the Apache Software Foundation (ASF) under one
49
45
import android .view .inputmethod .EditorInfo ;
50
46
import android .view .inputmethod .InputMethodManager ;
51
47
import android .webkit .CookieManager ;
52
- import android .webkit .CookieSyncManager ;
53
48
import android .webkit .HttpAuthHandler ;
54
49
import android .webkit .JavascriptInterface ;
55
50
import android .webkit .SslErrorHandler ;
@@ -142,10 +137,8 @@ public class InAppBrowser extends CordovaPlugin {
142
137
private boolean mediaPlaybackRequiresUserGesture = false ;
143
138
private boolean shouldPauseInAppBrowser = false ;
144
139
private boolean useWideViewPort = true ;
145
- private ValueCallback <Uri > mUploadCallback ;
146
- private ValueCallback <Uri []> mUploadCallbackLollipop ;
140
+ private ValueCallback <Uri []> mUploadCallback ;
147
141
private final static int FILECHOOSER_REQUESTCODE = 1 ;
148
- private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2 ;
149
142
private String closeButtonCaption = "" ;
150
143
private String closeButtonColor = "" ;
151
144
private boolean leftToRight = false ;
@@ -275,8 +268,12 @@ else if (action.equals("loadAfterBeforeload")) {
275
268
@ SuppressLint ("NewApi" )
276
269
@ Override
277
270
public void run () {
278
- currentClient .waitForBeforeload = false ;
279
- inAppWebView .setWebViewClient (currentClient );
271
+ if (android .os .Build .VERSION .SDK_INT < android .os .Build .VERSION_CODES .O ) {
272
+ currentClient .waitForBeforeload = false ;
273
+ inAppWebView .setWebViewClient (currentClient );
274
+ } else {
275
+ ((InAppBrowserClient )inAppWebView .getWebViewClient ()).waitForBeforeload = false ;
276
+ }
280
277
inAppWebView .loadUrl (url );
281
278
}
282
279
});
@@ -416,12 +413,7 @@ private void injectDeferredObject(String source, String jsWrapper) {
416
413
@ SuppressLint ("NewApi" )
417
414
@ Override
418
415
public void run () {
419
- if (Build .VERSION .SDK_INT < 19 ) {
420
- // This action will have the side-effect of blurring the currently focused element
421
- inAppWebView .loadUrl ("javascript:" + finalScriptToInject );
422
- } else {
423
- inAppWebView .evaluateJavascript (finalScriptToInject , null );
424
- }
416
+ inAppWebView .evaluateJavascript (finalScriptToInject , null );
425
417
}
426
418
});
427
419
} else {
@@ -764,8 +756,7 @@ private View createCloseButton(int id) {
764
756
if (closeButtonColor != "" ) close .setColorFilter (android .graphics .Color .parseColor (closeButtonColor ));
765
757
close .setImageDrawable (closeIcon );
766
758
close .setScaleType (ImageView .ScaleType .FIT_CENTER );
767
- if (Build .VERSION .SDK_INT >= 16 )
768
- close .getAdjustViewBounds ();
759
+ close .getAdjustViewBounds ();
769
760
770
761
_close = close ;
771
762
}
@@ -774,11 +765,7 @@ private View createCloseButton(int id) {
774
765
if (leftToRight ) closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_LEFT );
775
766
else closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
776
767
_close .setLayoutParams (closeLayoutParams );
777
-
778
- if (Build .VERSION .SDK_INT >= 16 )
779
- _close .setBackground (null );
780
- else
781
- _close .setBackgroundDrawable (null );
768
+ _close .setBackground (null );
782
769
783
770
_close .setContentDescription ("Close Button" );
784
771
_close .setId (Integer .valueOf (id ));
@@ -868,15 +855,11 @@ public void run() {
868
855
int backResId = activityRes .getIdentifier ("ic_action_previous_item" , "drawable" , cordova .getActivity ().getPackageName ());
869
856
Drawable backIcon = activityRes .getDrawable (backResId );
870
857
if (navigationButtonColor != "" ) back .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
871
- if (Build .VERSION .SDK_INT >= 16 )
872
- back .setBackground (null );
873
- else
874
- back .setBackgroundDrawable (null );
858
+ back .setBackground (null );
875
859
back .setImageDrawable (backIcon );
876
860
back .setScaleType (ImageView .ScaleType .FIT_CENTER );
877
861
back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
878
- if (Build .VERSION .SDK_INT >= 16 )
879
- back .getAdjustViewBounds ();
862
+ back .getAdjustViewBounds ();
880
863
881
864
back .setOnClickListener (new View .OnClickListener () {
882
865
public void onClick (View v ) {
@@ -894,15 +877,11 @@ public void onClick(View v) {
894
877
int fwdResId = activityRes .getIdentifier ("ic_action_next_item" , "drawable" , cordova .getActivity ().getPackageName ());
895
878
Drawable fwdIcon = activityRes .getDrawable (fwdResId );
896
879
if (navigationButtonColor != "" ) forward .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
897
- if (Build .VERSION .SDK_INT >= 16 )
898
- forward .setBackground (null );
899
- else
900
- forward .setBackgroundDrawable (null );
880
+ forward .setBackground (null );
901
881
forward .setImageDrawable (fwdIcon );
902
882
forward .setScaleType (ImageView .ScaleType .FIT_CENTER );
903
883
forward .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
904
- if (Build .VERSION .SDK_INT >= 16 )
905
- forward .getAdjustViewBounds ();
884
+ forward .getAdjustViewBounds ();
906
885
907
886
forward .setOnClickListener (new View .OnClickListener () {
908
887
public void onClick (View v ) {
@@ -1019,46 +998,24 @@ public void onClick(View v) {
1019
998
inAppWebView .setId (Integer .valueOf (6 ));
1020
999
// File Chooser Implemented ChromeClient
1021
1000
inAppWebView .setWebChromeClient (new InAppChromeClient (thatWebView ) {
1022
- // For Android 5.0+
1023
1001
public boolean onShowFileChooser (WebView webView , ValueCallback <Uri []> filePathCallback , WebChromeClient .FileChooserParams fileChooserParams )
1024
1002
{
1025
1003
LOG .d (LOG_TAG , "File Chooser 5.0+" );
1026
1004
// If callback exists, finish it.
1027
- if (mUploadCallbackLollipop != null ) {
1028
- mUploadCallbackLollipop .onReceiveValue (null );
1005
+ if (mUploadCallback != null ) {
1006
+ mUploadCallback .onReceiveValue (null );
1029
1007
}
1030
- mUploadCallbackLollipop = filePathCallback ;
1008
+ mUploadCallback = filePathCallback ;
1031
1009
1032
1010
// Create File Chooser Intent
1033
1011
Intent content = new Intent (Intent .ACTION_GET_CONTENT );
1034
1012
content .addCategory (Intent .CATEGORY_OPENABLE );
1035
1013
content .setType ("*/*" );
1036
1014
1037
1015
// Run cordova startActivityForResult
1038
- cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE_LOLLIPOP );
1039
- return true ;
1040
- }
1041
-
1042
- // For Android 4.1+
1043
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType , String capture )
1044
- {
1045
- LOG .d (LOG_TAG , "File Chooser 4.1+" );
1046
- // Call file chooser for Android 3.0+
1047
- openFileChooser (uploadMsg , acceptType );
1048
- }
1049
-
1050
- // For Android 3.0+
1051
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType )
1052
- {
1053
- LOG .d (LOG_TAG , "File Chooser 3.0+" );
1054
- mUploadCallback = uploadMsg ;
1055
- Intent content = new Intent (Intent .ACTION_GET_CONTENT );
1056
- content .addCategory (Intent .CATEGORY_OPENABLE );
1057
-
1058
- // run startActivityForResult
1059
1016
cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE );
1017
+ return true ;
1060
1018
}
1061
-
1062
1019
});
1063
1020
currentClient = new InAppBrowserClient (thatWebView , edittext , beforeload );
1064
1021
inAppWebView .setWebViewClient (currentClient );
@@ -1083,10 +1040,8 @@ public void postMessage(String data) {
1083
1040
}
1084
1041
}
1085
1042
1086
- if (android .os .Build .VERSION .SDK_INT >= 17 ) {
1087
- settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
1088
- inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1089
- }
1043
+ settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
1044
+ inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1090
1045
1091
1046
String overrideUserAgent = preferences .getString ("OverrideUserAgent" , null );
1092
1047
String appendUserAgent = preferences .getString ("AppendUserAgent" , null );
@@ -1114,10 +1069,8 @@ public void postMessage(String data) {
1114
1069
CookieManager .getInstance ().removeSessionCookie ();
1115
1070
}
1116
1071
1117
- // Enable Thirdparty Cookies on >=Android 5.0 device
1118
- if (android .os .Build .VERSION .SDK_INT >= 21 ) {
1119
- CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1120
- }
1072
+ // Enable Thirdparty Cookies
1073
+ CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1121
1074
1122
1075
inAppWebView .loadUrl (url );
1123
1076
inAppWebView .setId (Integer .valueOf (6 ));
@@ -1209,32 +1162,14 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu
1209
1162
* @param intent the data from android file chooser
1210
1163
*/
1211
1164
public void onActivityResult (int requestCode , int resultCode , Intent intent ) {
1212
- // For Android >= 5.0
1213
- if (Build .VERSION .SDK_INT >= 21 ) {
1214
- LOG .d (LOG_TAG , "onActivityResult (For Android >= 5.0)" );
1215
- // If RequestCode or Callback is Invalid
1216
- if (requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null ) {
1217
- super .onActivityResult (requestCode , resultCode , intent );
1218
- return ;
1219
- }
1220
- mUploadCallbackLollipop .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1221
- mUploadCallbackLollipop = null ;
1222
- }
1223
- // For Android < 5.0
1224
- else {
1225
- LOG .d (LOG_TAG , "onActivityResult (For Android < 5.0)" );
1226
- // If RequestCode or Callback is Invalid
1227
- if (requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null ) {
1228
- super .onActivityResult (requestCode , resultCode , intent );
1229
- return ;
1230
- }
1231
-
1232
- if (null == mUploadCallback ) return ;
1233
- Uri result = intent == null || resultCode != cordova .getActivity ().RESULT_OK ? null : intent .getData ();
1234
-
1235
- mUploadCallback .onReceiveValue (result );
1236
- mUploadCallback = null ;
1165
+ LOG .d (LOG_TAG , "onActivityResult" );
1166
+ // If RequestCode or Callback is Invalid
1167
+ if (requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null ) {
1168
+ super .onActivityResult (requestCode , resultCode , intent );
1169
+ return ;
1237
1170
}
1171
+ mUploadCallback .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1172
+ mUploadCallback = null ;
1238
1173
}
1239
1174
1240
1175
/**
@@ -1283,7 +1218,7 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) {
1283
1218
* @param webView
1284
1219
* @param request
1285
1220
*/
1286
- @ TargetApi (24 )
1221
+ @ TargetApi (Build . VERSION_CODES . N )
1287
1222
@ Override
1288
1223
public boolean shouldOverrideUrlLoading (WebView webView , WebResourceRequest request ) {
1289
1224
return shouldOverrideUrlLoading (request .getUrl ().toString (), request .getMethod ());
@@ -1467,28 +1402,13 @@ private boolean sendBeforeLoad(String url, String method) {
1467
1402
return false ;
1468
1403
}
1469
1404
1470
-
1471
- /**
1472
- * Legacy (deprecated in API 21)
1473
- * For Android 4.4 and below.
1474
- * @param view
1475
- * @param url
1476
- * @return
1477
- */
1478
- @ SuppressWarnings ("deprecation" )
1479
- @ Override
1480
- public WebResourceResponse shouldInterceptRequest (final WebView view , String url ) {
1481
- return shouldInterceptRequest (url , super .shouldInterceptRequest (view , url ), null );
1482
- }
1483
-
1484
1405
/**
1485
1406
* New (added in API 21)
1486
1407
* For Android 5.0 and above.
1487
1408
*
1488
- * @param webView
1409
+ * @param view
1489
1410
* @param request
1490
1411
*/
1491
- @ TargetApi (21 )
1492
1412
@ Override
1493
1413
public WebResourceResponse shouldInterceptRequest (WebView view , WebResourceRequest request ) {
1494
1414
return shouldInterceptRequest (request .getUrl ().toString (), super .shouldInterceptRequest (view , request ), request .getMethod ());
@@ -1539,16 +1459,10 @@ public void onPageFinished(WebView view, String url) {
1539
1459
super .onPageFinished (view , url );
1540
1460
1541
1461
// Set the namespace for postMessage()
1542
- if (Build .VERSION .SDK_INT >= 17 ) {
1543
- injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1544
- }
1462
+ injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1545
1463
1546
1464
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
1547
- if (android .os .Build .VERSION .SDK_INT >= 21 ) {
1548
- CookieManager .getInstance ().flush ();
1549
- } else {
1550
- CookieSyncManager .getInstance ().sync ();
1551
- }
1465
+ CookieManager .getInstance ().flush ();
1552
1466
1553
1467
// https://issues.apache.org/jira/browse/CB-11248
1554
1468
view .clearFocus ();
0 commit comments