@@ -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 ;
@@ -420,12 +413,7 @@ private void injectDeferredObject(String source, String jsWrapper) {
420
413
@ SuppressLint ("NewApi" )
421
414
@ Override
422
415
public void run () {
423
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .KITKAT ) {
424
- // This action will have the side-effect of blurring the currently focused element
425
- inAppWebView .loadUrl ("javascript:" + finalScriptToInject );
426
- } else {
427
- inAppWebView .evaluateJavascript (finalScriptToInject , null );
428
- }
416
+ inAppWebView .evaluateJavascript (finalScriptToInject , null );
429
417
}
430
418
});
431
419
} else {
@@ -768,8 +756,7 @@ private View createCloseButton(int id) {
768
756
if (closeButtonColor != "" ) close .setColorFilter (android .graphics .Color .parseColor (closeButtonColor ));
769
757
close .setImageDrawable (closeIcon );
770
758
close .setScaleType (ImageView .ScaleType .FIT_CENTER );
771
- if (Build .VERSION .SDK_INT >= 16 )
772
- close .getAdjustViewBounds ();
759
+ close .getAdjustViewBounds ();
773
760
774
761
_close = close ;
775
762
}
@@ -778,11 +765,7 @@ private View createCloseButton(int id) {
778
765
if (leftToRight ) closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_LEFT );
779
766
else closeLayoutParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
780
767
_close .setLayoutParams (closeLayoutParams );
781
-
782
- if (Build .VERSION .SDK_INT >= 16 )
783
- _close .setBackground (null );
784
- else
785
- _close .setBackgroundDrawable (null );
768
+ _close .setBackground (null );
786
769
787
770
_close .setContentDescription ("Close Button" );
788
771
_close .setId (Integer .valueOf (id ));
@@ -872,15 +855,11 @@ public void run() {
872
855
int backResId = activityRes .getIdentifier ("ic_action_previous_item" , "drawable" , cordova .getActivity ().getPackageName ());
873
856
Drawable backIcon = activityRes .getDrawable (backResId );
874
857
if (navigationButtonColor != "" ) back .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
875
- if (Build .VERSION .SDK_INT >= 16 )
876
- back .setBackground (null );
877
- else
878
- back .setBackgroundDrawable (null );
858
+ back .setBackground (null );
879
859
back .setImageDrawable (backIcon );
880
860
back .setScaleType (ImageView .ScaleType .FIT_CENTER );
881
861
back .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
882
- if (Build .VERSION .SDK_INT >= 16 )
883
- back .getAdjustViewBounds ();
862
+ back .getAdjustViewBounds ();
884
863
885
864
back .setOnClickListener (new View .OnClickListener () {
886
865
public void onClick (View v ) {
@@ -898,15 +877,11 @@ public void onClick(View v) {
898
877
int fwdResId = activityRes .getIdentifier ("ic_action_next_item" , "drawable" , cordova .getActivity ().getPackageName ());
899
878
Drawable fwdIcon = activityRes .getDrawable (fwdResId );
900
879
if (navigationButtonColor != "" ) forward .setColorFilter (android .graphics .Color .parseColor (navigationButtonColor ));
901
- if (Build .VERSION .SDK_INT >= 16 )
902
- forward .setBackground (null );
903
- else
904
- forward .setBackgroundDrawable (null );
880
+ forward .setBackground (null );
905
881
forward .setImageDrawable (fwdIcon );
906
882
forward .setScaleType (ImageView .ScaleType .FIT_CENTER );
907
883
forward .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
908
- if (Build .VERSION .SDK_INT >= 16 )
909
- forward .getAdjustViewBounds ();
884
+ forward .getAdjustViewBounds ();
910
885
911
886
forward .setOnClickListener (new View .OnClickListener () {
912
887
public void onClick (View v ) {
@@ -1023,46 +998,24 @@ public void onClick(View v) {
1023
998
inAppWebView .setId (Integer .valueOf (6 ));
1024
999
// File Chooser Implemented ChromeClient
1025
1000
inAppWebView .setWebChromeClient (new InAppChromeClient (thatWebView ) {
1026
- // For Android 5.0+
1027
1001
public boolean onShowFileChooser (WebView webView , ValueCallback <Uri []> filePathCallback , WebChromeClient .FileChooserParams fileChooserParams )
1028
1002
{
1029
1003
LOG .d (LOG_TAG , "File Chooser 5.0+" );
1030
1004
// If callback exists, finish it.
1031
- if (mUploadCallbackLollipop != null ) {
1032
- mUploadCallbackLollipop .onReceiveValue (null );
1005
+ if (mUploadCallback != null ) {
1006
+ mUploadCallback .onReceiveValue (null );
1033
1007
}
1034
- mUploadCallbackLollipop = filePathCallback ;
1008
+ mUploadCallback = filePathCallback ;
1035
1009
1036
1010
// Create File Chooser Intent
1037
1011
Intent content = new Intent (Intent .ACTION_GET_CONTENT );
1038
1012
content .addCategory (Intent .CATEGORY_OPENABLE );
1039
1013
content .setType ("*/*" );
1040
1014
1041
1015
// Run cordova startActivityForResult
1042
- cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE_LOLLIPOP );
1043
- return true ;
1044
- }
1045
-
1046
- // For Android 4.1+
1047
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType , String capture )
1048
- {
1049
- LOG .d (LOG_TAG , "File Chooser 4.1+" );
1050
- // Call file chooser for Android 3.0+
1051
- openFileChooser (uploadMsg , acceptType );
1052
- }
1053
-
1054
- // For Android 3.0+
1055
- public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType )
1056
- {
1057
- LOG .d (LOG_TAG , "File Chooser 3.0+" );
1058
- mUploadCallback = uploadMsg ;
1059
- Intent content = new Intent (Intent .ACTION_GET_CONTENT );
1060
- content .addCategory (Intent .CATEGORY_OPENABLE );
1061
-
1062
- // run startActivityForResult
1063
1016
cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE );
1017
+ return true ;
1064
1018
}
1065
-
1066
1019
});
1067
1020
currentClient = new InAppBrowserClient (thatWebView , edittext , beforeload );
1068
1021
inAppWebView .setWebViewClient (currentClient );
@@ -1087,10 +1040,8 @@ public void postMessage(String data) {
1087
1040
}
1088
1041
}
1089
1042
1090
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
1091
- settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
1092
- inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1093
- }
1043
+ settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
1044
+ inAppWebView .addJavascriptInterface (new JsObject (), "cordova_iab" );
1094
1045
1095
1046
String overrideUserAgent = preferences .getString ("OverrideUserAgent" , null );
1096
1047
String appendUserAgent = preferences .getString ("AppendUserAgent" , null );
@@ -1118,10 +1069,8 @@ public void postMessage(String data) {
1118
1069
CookieManager .getInstance ().removeSessionCookie ();
1119
1070
}
1120
1071
1121
- // Enable Thirdparty Cookies on >=Android 5.0 device
1122
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .LOLLIPOP ) {
1123
- CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1124
- }
1072
+ // Enable Thirdparty Cookies
1073
+ CookieManager .getInstance ().setAcceptThirdPartyCookies (inAppWebView ,true );
1125
1074
1126
1075
inAppWebView .loadUrl (url );
1127
1076
inAppWebView .setId (Integer .valueOf (6 ));
@@ -1213,32 +1162,14 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu
1213
1162
* @param intent the data from android file chooser
1214
1163
*/
1215
1164
public void onActivityResult (int requestCode , int resultCode , Intent intent ) {
1216
- // For Android >= 5.0
1217
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
1218
- LOG .d (LOG_TAG , "onActivityResult (For Android >= 5.0)" );
1219
- // If RequestCode or Callback is Invalid
1220
- if (requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null ) {
1221
- super .onActivityResult (requestCode , resultCode , intent );
1222
- return ;
1223
- }
1224
- mUploadCallbackLollipop .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1225
- mUploadCallbackLollipop = null ;
1226
- }
1227
- // For Android < 5.0
1228
- else {
1229
- LOG .d (LOG_TAG , "onActivityResult (For Android < 5.0)" );
1230
- // If RequestCode or Callback is Invalid
1231
- if (requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null ) {
1232
- super .onActivityResult (requestCode , resultCode , intent );
1233
- return ;
1234
- }
1235
-
1236
- if (null == mUploadCallback ) return ;
1237
- Uri result = intent == null || resultCode != cordova .getActivity ().RESULT_OK ? null : intent .getData ();
1238
-
1239
- mUploadCallback .onReceiveValue (result );
1240
- 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 ;
1241
1170
}
1171
+ mUploadCallback .onReceiveValue (WebChromeClient .FileChooserParams .parseResult (resultCode , intent ));
1172
+ mUploadCallback = null ;
1242
1173
}
1243
1174
1244
1175
/**
@@ -1471,28 +1402,13 @@ private boolean sendBeforeLoad(String url, String method) {
1471
1402
return false ;
1472
1403
}
1473
1404
1474
-
1475
- /**
1476
- * Legacy (deprecated in API 21)
1477
- * For Android 4.4 and below.
1478
- * @param view
1479
- * @param url
1480
- * @return
1481
- */
1482
- @ SuppressWarnings ("deprecation" )
1483
- @ Override
1484
- public WebResourceResponse shouldInterceptRequest (final WebView view , String url ) {
1485
- return shouldInterceptRequest (url , super .shouldInterceptRequest (view , url ), null );
1486
- }
1487
-
1488
1405
/**
1489
1406
* New (added in API 21)
1490
1407
* For Android 5.0 and above.
1491
1408
*
1492
- * @param webView
1409
+ * @param view
1493
1410
* @param request
1494
1411
*/
1495
- @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
1496
1412
@ Override
1497
1413
public WebResourceResponse shouldInterceptRequest (WebView view , WebResourceRequest request ) {
1498
1414
return shouldInterceptRequest (request .getUrl ().toString (), super .shouldInterceptRequest (view , request ), request .getMethod ());
@@ -1543,16 +1459,10 @@ public void onPageFinished(WebView view, String url) {
1543
1459
super .onPageFinished (view , url );
1544
1460
1545
1461
// Set the namespace for postMessage()
1546
- if (Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
1547
- injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1548
- }
1462
+ injectDeferredObject ("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}" , null );
1549
1463
1550
1464
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
1551
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .LOLLIPOP ) {
1552
- CookieManager .getInstance ().flush ();
1553
- } else {
1554
- CookieSyncManager .getInstance ().sync ();
1555
- }
1465
+ CookieManager .getInstance ().flush ();
1556
1466
1557
1467
// https://issues.apache.org/jira/browse/CB-11248
1558
1468
view .clearFocus ();
0 commit comments