@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
18
18
*/
19
19
package org .apache .cordova .inappbrowser ;
20
20
21
+ import android .Manifest ;
21
22
import android .annotation .SuppressLint ;
22
23
import android .annotation .TargetApi ;
23
24
import android .content .ActivityNotFoundException ;
@@ -48,6 +49,7 @@ Licensed to the Apache Software Foundation (ASF) under one
48
49
import android .webkit .CookieManager ;
49
50
import android .webkit .HttpAuthHandler ;
50
51
import android .webkit .JavascriptInterface ;
52
+ import android .webkit .PermissionRequest ;
51
53
import android .webkit .SslErrorHandler ;
52
54
import android .webkit .ValueCallback ;
53
55
import android .webkit .WebChromeClient ;
@@ -70,6 +72,7 @@ Licensed to the Apache Software Foundation (ASF) under one
70
72
import org .apache .cordova .CordovaPlugin ;
71
73
import org .apache .cordova .CordovaWebView ;
72
74
import org .apache .cordova .LOG ;
75
+ import org .apache .cordova .PermissionHelper ;
73
76
import org .apache .cordova .PluginManager ;
74
77
import org .apache .cordova .PluginResult ;
75
78
import org .json .JSONException ;
@@ -102,6 +105,7 @@ public class InAppBrowser extends CordovaPlugin {
102
105
private static final String CLEAR_ALL_CACHE = "clearcache" ;
103
106
private static final String CLEAR_SESSION_CACHE = "clearsessioncache" ;
104
107
private static final String HARDWARE_BACK_BUTTON = "hardwareback" ;
108
+ private static final String TRIGGER_BACK_BUTTON = "triggerback" ;
105
109
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction" ;
106
110
private static final String INTENT_PROTOCOL_START = "intent:" ;
107
111
private static final String INTENT_PROTOCOL_INTENT = "#Intent;" ;
@@ -110,6 +114,7 @@ public class InAppBrowser extends CordovaPlugin {
110
114
private static final String HOGANGNONO_SCHEME = "hogangnono://" ;
111
115
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend" ;
112
116
private static final Boolean DEFAULT_HARDWARE_BACK = true ;
117
+ private static final Boolean DEFAULT_TRIGGER_BACK = false ;
113
118
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort" ;
114
119
private static final String TOOLBAR_COLOR = "toolbarcolor" ;
115
120
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption" ;
@@ -122,6 +127,8 @@ public class InAppBrowser extends CordovaPlugin {
122
127
private static final String FOOTER_COLOR = "footercolor" ;
123
128
private static final String BEFORELOAD = "beforeload" ;
124
129
private static final String FULLSCREEN = "fullscreen" ;
130
+ private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101 ;
131
+ private static final int MY_PERMISSIONS_REQUEST_CAMERA = 102 ;
125
132
126
133
private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR , FOOTER_COLOR );
127
134
@@ -135,6 +142,7 @@ public class InAppBrowser extends CordovaPlugin {
135
142
private boolean clearAllCache = false ;
136
143
private boolean clearSessionCache = false ;
137
144
private boolean hadwareBackButton = true ;
145
+ private boolean triggerBackButton = false ;
138
146
private boolean mediaPlaybackRequiresUserGesture = false ;
139
147
private boolean shouldPauseInAppBrowser = false ;
140
148
private boolean useWideViewPort = true ;
@@ -153,6 +161,7 @@ public class InAppBrowser extends CordovaPlugin {
153
161
private boolean fullscreen = true ;
154
162
private String [] allowedSchemes ;
155
163
private InAppBrowserClient currentClient ;
164
+ private PermissionRequest myRequest ;
156
165
157
166
/**
158
167
* Executes the request and returns PluginResult.
@@ -583,6 +592,21 @@ public boolean hardwareBack() {
583
592
return hadwareBackButton ;
584
593
}
585
594
595
+ /**
596
+ * Hogangnono - Has the user set the trigger back button to go back
597
+ * @return boolean
598
+ */
599
+ public boolean isTriggerBack () {
600
+ return triggerBackButton ;
601
+ }
602
+
603
+ /**
604
+ * Hogangnono - Execute javaScript for triggering back button
605
+ */
606
+ public void triggerBackButton () {
607
+ this .inAppWebView .loadUrl ("javascript:window.backbutton && window.backbutton()" );
608
+ }
609
+
586
610
/**
587
611
* Checks to see if it is possible to go forward one page in history, then does so.
588
612
*/
@@ -661,6 +685,12 @@ public String showWebPage(final String url, HashMap<String, String> features) {
661
685
} else {
662
686
hadwareBackButton = DEFAULT_HARDWARE_BACK ;
663
687
}
688
+ String triggerBack = features .get (TRIGGER_BACK_BUTTON );
689
+ if (triggerBack != null ) {
690
+ triggerBackButton = triggerBack .equals ("yes" ) ? true : false ;
691
+ } else {
692
+ triggerBackButton = DEFAULT_TRIGGER_BACK ;
693
+ }
664
694
String mediaPlayback = features .get (MEDIA_PLAYBACK_REQUIRES_USER_ACTION );
665
695
if (mediaPlayback != null ) {
666
696
mediaPlaybackRequiresUserGesture = mediaPlayback .equals ("yes" ) ? true : false ;
@@ -977,19 +1007,19 @@ public void onClick(View v) {
977
1007
String shareBody = inAppWebView .getUrl ();
978
1008
sharingIntent .putExtra (android .content .Intent .EXTRA_SUBJECT , inAppWebView .getUrl ());
979
1009
sharingIntent .putExtra (android .content .Intent .EXTRA_TEXT , shareBody );
980
-
1010
+
981
1011
cordova .getActivity ().startActivity (Intent .createChooser (sharingIntent , "URL 공유" ));
982
1012
}
983
1013
});
984
-
1014
+
985
1015
RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
986
1016
closeLayoutParams .addRule (RelativeLayout .RIGHT_OF , shareButtonId );
987
1017
closeButton .setLayoutParams (closeLayoutParams );
988
1018
989
1019
RelativeLayout .LayoutParams shareLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
990
1020
shareLayoutParams .addRule (RelativeLayout .ALIGN_LEFT );
991
1021
shareButton .setLayoutParams (shareLayoutParams );
992
-
1022
+
993
1023
customButtonContainer .addView ((View )closeButton );
994
1024
customButtonContainer .addView ((View )shareButton );
995
1025
@@ -1017,6 +1047,18 @@ public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePath
1017
1047
cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE );
1018
1048
return true ;
1019
1049
}
1050
+
1051
+ @ Override
1052
+ public void onPermissionRequest (PermissionRequest request ) {
1053
+ myRequest = request ;
1054
+ for (String permission : request .getResources ()) {
1055
+ if (permission .equals ("android.webkit.resource.AUDIO_CAPTURE" )) {
1056
+ askForPermission (Manifest .permission .RECORD_AUDIO , MY_PERMISSIONS_REQUEST_RECORD_AUDIO );
1057
+ } else if (permission .equals ("android.webkit.resource.VIDEO_CAPTURE" )) {
1058
+ askForPermission (Manifest .permission .CAMERA , MY_PERMISSIONS_REQUEST_CAMERA );
1059
+ }
1060
+ }
1061
+ }
1020
1062
});
1021
1063
currentClient = new InAppBrowserClient (thatWebView , edittext , beforeload );
1022
1064
inAppWebView .setWebViewClient (currentClient );
@@ -1129,6 +1171,40 @@ public void postMessage(String data) {
1129
1171
return "" ;
1130
1172
}
1131
1173
1174
+ /**
1175
+ * WebView에서 권한이 필요할 시에 확인하는 로직
1176
+ *
1177
+ * @param permission 요청하는 권한
1178
+ * @param requestCode 내부적으로 정의한 코드
1179
+ */
1180
+ public void askForPermission (String permission , int requestCode ) {
1181
+ if (!PermissionHelper .hasPermission (this , permission )) {
1182
+ PermissionHelper .requestPermission (this , requestCode , permission );
1183
+ } else {
1184
+ myRequest .grant (myRequest .getResources ());
1185
+ }
1186
+ }
1187
+
1188
+ /**
1189
+ * 권한 요청 결과가 반환되는 콜백
1190
+ *
1191
+ * @param requestCode 요청시 넣어줬던 코드
1192
+ * @param permissions 요청했던 권한
1193
+ * @param grantResults 권환 획득 여부
1194
+ */
1195
+ public void onRequestPermissionResult (int requestCode , String [] permissions , int [] grantResults ) throws JSONException {
1196
+ for (int r : grantResults ) {
1197
+ if (r == PackageManager .PERMISSION_DENIED ) {
1198
+ myRequest .deny ();
1199
+ return ;
1200
+ }
1201
+ }
1202
+
1203
+ if (requestCode == MY_PERMISSIONS_REQUEST_RECORD_AUDIO || requestCode == MY_PERMISSIONS_REQUEST_CAMERA ) {
1204
+ myRequest .grant (myRequest .getResources ());
1205
+ }
1206
+ }
1207
+
1132
1208
/**
1133
1209
* Create a new plugin success result and send it back to JavaScript
1134
1210
*
@@ -1339,12 +1415,12 @@ else if (url.startsWith(HOGANGNONO_SCHEME)) {
1339
1415
else if (url .startsWith (INTENT_PROTOCOL_START )) {
1340
1416
final int customUrlStartIndex = INTENT_PROTOCOL_START .length ();
1341
1417
final int customUrlEndIndex = url .indexOf (INTENT_PROTOCOL_INTENT );
1342
-
1418
+
1343
1419
if (customUrlEndIndex < 0 ) {
1344
1420
return false ;
1345
1421
} else {
1346
1422
final String customUrl = url .substring (customUrlStartIndex , customUrlEndIndex );
1347
-
1423
+
1348
1424
try {
1349
1425
cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1350
1426
} catch (ActivityNotFoundException e ) {
0 commit comments