@@ -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 ;
@@ -122,6 +125,8 @@ public class InAppBrowser extends CordovaPlugin {
122
125
private static final String FOOTER_COLOR = "footercolor" ;
123
126
private static final String BEFORELOAD = "beforeload" ;
124
127
private static final String FULLSCREEN = "fullscreen" ;
128
+ private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101 ;
129
+ private static final int MY_PERMISSIONS_REQUEST_CAMERA = 102 ;
125
130
126
131
private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR , FOOTER_COLOR );
127
132
@@ -153,6 +158,7 @@ public class InAppBrowser extends CordovaPlugin {
153
158
private boolean fullscreen = true ;
154
159
private String [] allowedSchemes ;
155
160
private InAppBrowserClient currentClient ;
161
+ private PermissionRequest myRequest ;
156
162
157
163
/**
158
164
* Executes the request and returns PluginResult.
@@ -977,19 +983,19 @@ public void onClick(View v) {
977
983
String shareBody = inAppWebView .getUrl ();
978
984
sharingIntent .putExtra (android .content .Intent .EXTRA_SUBJECT , inAppWebView .getUrl ());
979
985
sharingIntent .putExtra (android .content .Intent .EXTRA_TEXT , shareBody );
980
-
986
+
981
987
cordova .getActivity ().startActivity (Intent .createChooser (sharingIntent , "URL 공유" ));
982
988
}
983
989
});
984
-
990
+
985
991
RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
986
992
closeLayoutParams .addRule (RelativeLayout .RIGHT_OF , shareButtonId );
987
993
closeButton .setLayoutParams (closeLayoutParams );
988
994
989
995
RelativeLayout .LayoutParams shareLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
990
996
shareLayoutParams .addRule (RelativeLayout .ALIGN_LEFT );
991
997
shareButton .setLayoutParams (shareLayoutParams );
992
-
998
+
993
999
customButtonContainer .addView ((View )closeButton );
994
1000
customButtonContainer .addView ((View )shareButton );
995
1001
@@ -1017,6 +1023,18 @@ public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePath
1017
1023
cordova .startActivityForResult (InAppBrowser .this , Intent .createChooser (content , "Select File" ), FILECHOOSER_REQUESTCODE );
1018
1024
return true ;
1019
1025
}
1026
+
1027
+ @ Override
1028
+ public void onPermissionRequest (PermissionRequest request ) {
1029
+ myRequest = request ;
1030
+ for (String permission : request .getResources ()) {
1031
+ if (permission .equals ("android.webkit.resource.AUDIO_CAPTURE" )) {
1032
+ askForPermission (Manifest .permission .RECORD_AUDIO , MY_PERMISSIONS_REQUEST_RECORD_AUDIO );
1033
+ } else if (permission .equals ("android.webkit.resource.VIDEO_CAPTURE" )) {
1034
+ askForPermission (Manifest .permission .CAMERA , MY_PERMISSIONS_REQUEST_CAMERA );
1035
+ }
1036
+ }
1037
+ }
1020
1038
});
1021
1039
currentClient = new InAppBrowserClient (thatWebView , edittext , beforeload );
1022
1040
inAppWebView .setWebViewClient (currentClient );
@@ -1129,6 +1147,40 @@ public void postMessage(String data) {
1129
1147
return "" ;
1130
1148
}
1131
1149
1150
+ /**
1151
+ * WebView에서 권한이 필요할 시에 확인하는 로직
1152
+ *
1153
+ * @param permission 요청하는 권한
1154
+ * @param requestCode 내부적으로 정의한 코드
1155
+ */
1156
+ public void askForPermission (String permission , int requestCode ) {
1157
+ if (!PermissionHelper .hasPermission (this , permission )) {
1158
+ PermissionHelper .requestPermission (this , requestCode , permission );
1159
+ } else {
1160
+ myRequest .grant (myRequest .getResources ());
1161
+ }
1162
+ }
1163
+
1164
+ /**
1165
+ * 권한 요청 결과가 반환되는 콜백
1166
+ *
1167
+ * @param requestCode 요청시 넣어줬던 코드
1168
+ * @param permissions 요청했던 권한
1169
+ * @param grantResults 권환 획득 여부
1170
+ */
1171
+ public void onRequestPermissionResult (int requestCode , String [] permissions , int [] grantResults ) throws JSONException {
1172
+ for (int r : grantResults ) {
1173
+ if (r == PackageManager .PERMISSION_DENIED ) {
1174
+ myRequest .deny ();
1175
+ return ;
1176
+ }
1177
+ }
1178
+
1179
+ if (requestCode == MY_PERMISSIONS_REQUEST_RECORD_AUDIO || requestCode == MY_PERMISSIONS_REQUEST_CAMERA ) {
1180
+ myRequest .grant (myRequest .getResources ());
1181
+ }
1182
+ }
1183
+
1132
1184
/**
1133
1185
* Create a new plugin success result and send it back to JavaScript
1134
1186
*
@@ -1339,12 +1391,12 @@ else if (url.startsWith(HOGANGNONO_SCHEME)) {
1339
1391
else if (url .startsWith (INTENT_PROTOCOL_START )) {
1340
1392
final int customUrlStartIndex = INTENT_PROTOCOL_START .length ();
1341
1393
final int customUrlEndIndex = url .indexOf (INTENT_PROTOCOL_INTENT );
1342
-
1394
+
1343
1395
if (customUrlEndIndex < 0 ) {
1344
1396
return false ;
1345
1397
} else {
1346
1398
final String customUrl = url .substring (customUrlStartIndex , customUrlEndIndex );
1347
-
1399
+
1348
1400
try {
1349
1401
cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1350
1402
} catch (ActivityNotFoundException e ) {
0 commit comments