@@ -20,7 +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 .ComponentName ;
24
23
import android .content .Context ;
25
24
import android .content .Intent ;
26
25
import android .content .pm .PackageManager ;
@@ -30,8 +29,6 @@ Licensed to the Apache Software Foundation (ASF) under one
30
29
import android .content .res .Resources ;
31
30
import android .graphics .Bitmap ;
32
31
import android .graphics .drawable .Drawable ;
33
- import android .graphics .PorterDuff ;
34
- import android .graphics .PorterDuffColorFilter ;
35
32
import android .graphics .Color ;
36
33
import android .net .http .SslError ;
37
34
import android .net .Uri ;
@@ -48,7 +45,6 @@ Licensed to the Apache Software Foundation (ASF) under one
48
45
import android .view .inputmethod .EditorInfo ;
49
46
import android .view .inputmethod .InputMethodManager ;
50
47
import android .webkit .CookieManager ;
51
- import android .webkit .CookieSyncManager ;
52
48
import android .webkit .HttpAuthHandler ;
53
49
import android .webkit .JavascriptInterface ;
54
50
import android .webkit .SslErrorHandler ;
@@ -136,10 +132,8 @@ public class InAppBrowser extends CordovaPlugin {
136
132
private boolean mediaPlaybackRequiresUserGesture = false ;
137
133
private boolean shouldPauseInAppBrowser = false ;
138
134
private boolean useWideViewPort = true ;
139
- private ValueCallback <Uri > mUploadCallback ;
140
- private ValueCallback <Uri []> mUploadCallbackLollipop ;
135
+ private ValueCallback <Uri []> mUploadCallback ;
141
136
private final static int FILECHOOSER_REQUESTCODE = 1 ;
142
- private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2 ;
143
137
private String closeButtonCaption = "" ;
144
138
private String closeButtonColor = "" ;
145
139
private boolean leftToRight = false ;
@@ -414,12 +408,7 @@ private void injectDeferredObject(String source, String jsWrapper) {
414
408
@ SuppressLint ("NewApi" )
415
409
@ Override
416
410
public void run () {
417
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .KITKAT ) {
418
- // This action will have the side-effect of blurring the currently focused element
419
- inAppWebView .loadUrl ("javascript:" + finalScriptToInject );
420
- } else {
421
- inAppWebView .evaluateJavascript (finalScriptToInject , null );
422
- }
411
+ inAppWebView .evaluateJavascript (finalScriptToInject , null );
423
412
}
424
413
});
425
414
} else {
@@ -762,8 +751,7 @@ private View createCloseButton(int id) {
762
751
if (closeButtonColor != "" ) close .setColorFilter (android .graphics .Color .parseColor (closeButtonColor ));
763
752
close .setImageDrawable (closeIcon );
764
753
close .setScaleType (ImageView .ScaleType .FIT_CENTER );
765
- if (Build .VERSION .SDK_INT >= 16 )
766
- close .getAdjustViewBounds ();
754
+ close .getAdjustViewBounds ();
767
755
768
756
_close = close ;
769
757
}
@@ -772,11 +760,7 @@ private View createCloseButton(int id) {
772
760
if (leftToRight ) closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_LEFT );
773
761
else closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
774
762
_close .setLayoutParams (closeLayoutParams );
775
-
776
- if (Build .VERSION .SDK_INT >= 16 )
777
- _close .setBackground (null );
778
- else
779
- _close .setBackgroundDrawable (null );
763
+ _close .setBackground (null );
780
764
781
765
_close .setContentDescription ("Close Button" );
782
766
_close .setId (Integer .valueOf (id ));
@@ -845,15 +829,11 @@ public void run() {
845
829
int backResId = activityRes .getIdentifier ("ic_action_previous_item" , "drawable" , cordova .getActivity ().getPackageName ());
846
830
Drawable backIcon = activityRes .getDrawable (backResId );
847
831
if (navigationButtonColor != "" ) back .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
848
- if (Build .VERSION .SDK_INT >= 16 )
849
- back .setBackground (null );
850
- else
851
- back .setBackgroundDrawable (null );
832
+ back .setBackground (null );
852
833
back .setImageDrawable (backIcon );
853
834
back .setScaleType (ImageView .ScaleType .FIT_CENTER );
854
835
back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
855
- if (Build .VERSION .SDK_INT >= 16 )
856
- back .getAdjustViewBounds ();
836
+ back .getAdjustViewBounds ();
857
837
858
838
back .setOnClickListener (new View .OnClickListener () {
859
839
public void onClick (View v ) {
@@ -871,15 +851,11 @@ public void onClick(View v) {
871
851
int fwdResId = activityRes .getIdentifier ("ic_action_next_item" , "drawable" , cordova .getActivity ().getPackageName ());
872
852
Drawable fwdIcon = activityRes .getDrawable (fwdResId );
873
853
if (navigationButtonColor != "" ) forward .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
874
- if (Build .VERSION .SDK_INT >= 16 )
875
- forward .setBackground (null );
876
- else
877
- forward .setBackgroundDrawable (null );
854
+ forward .setBackground (null );
878
855
forward .setImageDrawable (fwdIcon );
879
856
forward .setScaleType (ImageView .ScaleType .FIT_CENTER );
880
857
forward .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
881
- if (Build .VERSION .SDK_INT >= 16 )
882
- forward .getAdjustViewBounds ();
858
+ forward .getAdjustViewBounds ();
883
859
884
860
forward .setOnClickListener (new View .OnClickListener () {
885
861
public void onClick (View v ) {
@@ -942,46 +918,24 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
942
918
inAppWebView .setId (Integer .valueOf (6 ));
943
919
// File Chooser Implemented ChromeClient
944
920
inAppWebView .setWebChromeClient (new InAppChromeClient (thatWebView ) {
945
- // For Android 5.0+
946
921
public boolean onShowFileChooser (WebView webView , ValueCallback <Uri []> filePathCallback , WebChromeClient .FileChooserParams fileChooserParams )
947
922
{
948
923
LOG .d (LOG_TAG , "File Chooser 5.0+" );
949
924
// If callback exists, finish it.
950
- if (mUploadCallbackLollipop != null ) {
951
- mUploadCallbackLollipop .onReceiveValue (null );
925
+ if (mUploadCallback != null ) {
926
+ mUploadCallback .onReceiveValue (null );
952
927
}
953
- mUploadCallbackLollipop = filePathCallback ;
928
+ mUploadCallback = filePathCallback ;
954
929
955
930
// Create File Chooser Intent
956
931
Intent content = new Intent (Intent .ACTION_GET_CONTENT );
957
932
content .addCategory (Intent .CATEGORY_OPENABLE );
958
933
content .setType ("*/*" );
959
934
960
935
// Run cordova startActivityForResult
961
- cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE_LOLLIPOP );
962
- return true ;
963
- }
964
-
965
- // For Android 4.1+
966
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType , String capture )
967
- {
968
- LOG .d (LOG_TAG , "File Chooser 4.1+" );
969
- // Call file chooser for Android 3.0+
970
- openFileChooser (uploadMsg , acceptType );
971
- }
972
-
973
- // For Android 3.0+
974
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType )
975
- {
976
- LOG .d (LOG_TAG , "File Chooser 3.0+" );
977
- mUploadCallback = uploadMsg ;
978
- Intent content = new Intent (Intent .ACTION_GET_CONTENT );
979
- content .addCategory (Intent .CATEGORY_OPENABLE );
980
-
981
- // run startActivityForResult
982
936
cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE );
937
+ return true ;
983
938
}
984
-
985
939
});
986
940
currentClient = new InAppBrowserClient (thatWebView , edittext , beforeload );
987
941
inAppWebView .setWebViewClient (currentClient );
@@ -1006,10 +960,8 @@ public void postMessage(String data) {
1006
960
}
1007
961
}
1008
962
1009
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
1010
- settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
1011
- inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1012
- }
963
+ settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
964
+ inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1013
965
1014
966
String overrideUserAgent = preferences .getString ("OverrideUserAgent" , null );
1015
967
String appendUserAgent = preferences .getString ("AppendUserAgent" , null );
@@ -1037,10 +989,8 @@ public void postMessage(String data) {
1037
989
CookieManager .getInstance ().removeSessionCookie ();
1038
990
}
1039
991
1040
- // Enable Thirdparty Cookies on >=Android 5.0 device
1041
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .LOLLIPOP ) {
1042
- CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1043
- }
992
+ // Enable Thirdparty Cookies
993
+ CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1044
994
1045
995
inAppWebView .loadUrl (url );
1046
996
inAppWebView .setId (Integer .valueOf (6 ));
@@ -1131,32 +1081,14 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu
1131
1081
* @param intent the data from android file chooser
1132
1082
*/
1133
1083
public void onActivityResult (int requestCode , int resultCode , Intent intent ) {
1134
- // For Android >= 5.0
1135
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
1136
- LOG .d (LOG_TAG , "onActivityResult (For Android >= 5.0)" );
1137
- // If RequestCode or Callback is Invalid
1138
- if (requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null ) {
1139
- super .onActivityResult (requestCode , resultCode , intent );
1140
- return ;
1141
- }
1142
- mUploadCallbackLollipop .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1143
- mUploadCallbackLollipop = null ;
1144
- }
1145
- // For Android < 5.0
1146
- else {
1147
- LOG .d (LOG_TAG , "onActivityResult (For Android < 5.0)" );
1148
- // If RequestCode or Callback is Invalid
1149
- if (requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null ) {
1150
- super .onActivityResult (requestCode , resultCode , intent );
1151
- return ;
1152
- }
1153
-
1154
- if (null == mUploadCallback ) return ;
1155
- Uri result = intent == null || resultCode != cordova .getActivity ().RESULT_OK ? null : intent .getData ();
1156
-
1157
- mUploadCallback .onReceiveValue (result );
1158
- mUploadCallback = null ;
1084
+ LOG .d (LOG_TAG , "onActivityResult" );
1085
+ // If RequestCode or Callback is Invalid
1086
+ if (requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null ) {
1087
+ super .onActivityResult (requestCode , resultCode , intent );
1088
+ return ;
1159
1089
}
1090
+ mUploadCallback .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1091
+ mUploadCallback = null ;
1160
1092
}
1161
1093
1162
1094
/**
@@ -1356,28 +1288,13 @@ private boolean sendBeforeLoad(String url, String method) {
1356
1288
return false ;
1357
1289
}
1358
1290
1359
-
1360
- /**
1361
- * Legacy (deprecated in API 21)
1362
- * For Android 4.4 and below.
1363
- * @param view
1364
- * @param url
1365
- * @return
1366
- */
1367
- @ SuppressWarnings ("deprecation" )
1368
- @ Override
1369
- public WebResourceResponse shouldInterceptRequest (final WebView view , String url ) {
1370
- return shouldInterceptRequest (url , super .shouldInterceptRequest (view , url ), null );
1371
- }
1372
-
1373
1291
/**
1374
1292
* New (added in API 21)
1375
1293
* For Android 5.0 and above.
1376
1294
*
1377
- * @param webView
1295
+ * @param view
1378
1296
* @param request
1379
1297
*/
1380
- @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1381
1298
@ Override
1382
1299
public WebResourceResponse shouldInterceptRequest (WebView view , WebResourceRequest request ) {
1383
1300
return shouldInterceptRequest (request .getUrl ().toString (), super .shouldInterceptRequest (view , request ), request .getMethod ());
@@ -1428,16 +1345,10 @@ public void onPageFinished(WebView view, String url) {
1428
1345
super .onPageFinished (view , url );
1429
1346
1430
1347
// Set the namespace for postMessage()
1431
- if (Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
1432
- injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1433
- }
1348
+ injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1434
1349
1435
1350
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
1436
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .LOLLIPOP ) {
1437
- CookieManager .getInstance ().flush ();
1438
- } else {
1439
- CookieSyncManager .getInstance ().sync ();
1440
- }
1351
+ CookieManager .getInstance ().flush ();
1441
1352
1442
1353
// https://issues.apache.org/jira/browse/CB-11248
1443
1354
view .clearFocus ();
0 commit comments