Skip to content

Commit 030bac9

Browse files
committed
2 parents 7174025 + 149c937 commit 030bac9

File tree

6 files changed

+225
-135
lines changed

6 files changed

+225
-135
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-inappbrowser",
3-
"version": "5.0.4-hogangnono",
3+
"version": "5.0.9-hogangnono",
44
"description": "Cordova InAppBrowser Plugin",
55
"types": "./types/index.d.ts",
66
"cordova": {

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2222
id="cordova-plugin-inappbrowser"
23-
version="5.0.4-hogangnono">
23+
version="5.0.9-hogangnono">
2424

2525
<name>InAppBrowser</name>
2626
<description>Cordova InAppBrowser Plugin</description>

src/android/InAppBrowser.java

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
1818
*/
1919
package org.apache.cordova.inappbrowser;
2020

21+
import android.Manifest;
2122
import android.annotation.SuppressLint;
2223
import android.annotation.TargetApi;
2324
import android.content.ActivityNotFoundException;
@@ -48,6 +49,7 @@ Licensed to the Apache Software Foundation (ASF) under one
4849
import android.webkit.CookieManager;
4950
import android.webkit.HttpAuthHandler;
5051
import android.webkit.JavascriptInterface;
52+
import android.webkit.PermissionRequest;
5153
import android.webkit.SslErrorHandler;
5254
import android.webkit.ValueCallback;
5355
import android.webkit.WebChromeClient;
@@ -70,6 +72,7 @@ Licensed to the Apache Software Foundation (ASF) under one
7072
import org.apache.cordova.CordovaPlugin;
7173
import org.apache.cordova.CordovaWebView;
7274
import org.apache.cordova.LOG;
75+
import org.apache.cordova.PermissionHelper;
7376
import org.apache.cordova.PluginManager;
7477
import org.apache.cordova.PluginResult;
7578
import org.json.JSONException;
@@ -102,6 +105,7 @@ public class InAppBrowser extends CordovaPlugin {
102105
private static final String CLEAR_ALL_CACHE = "clearcache";
103106
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
104107
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
108+
private static final String TRIGGER_BACK_BUTTON = "triggerback";
105109
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction";
106110
private static final String INTENT_PROTOCOL_START = "intent:";
107111
private static final String INTENT_PROTOCOL_INTENT = "#Intent;";
@@ -110,6 +114,7 @@ public class InAppBrowser extends CordovaPlugin {
110114
private static final String HOGANGNONO_SCHEME = "hogangnono://";
111115
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
112116
private static final Boolean DEFAULT_HARDWARE_BACK = true;
117+
private static final Boolean DEFAULT_TRIGGER_BACK = false;
113118
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
114119
private static final String TOOLBAR_COLOR = "toolbarcolor";
115120
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
@@ -122,6 +127,8 @@ public class InAppBrowser extends CordovaPlugin {
122127
private static final String FOOTER_COLOR = "footercolor";
123128
private static final String BEFORELOAD = "beforeload";
124129
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;
125132

126133
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
127134

@@ -135,6 +142,7 @@ public class InAppBrowser extends CordovaPlugin {
135142
private boolean clearAllCache = false;
136143
private boolean clearSessionCache = false;
137144
private boolean hadwareBackButton = true;
145+
private boolean triggerBackButton = false;
138146
private boolean mediaPlaybackRequiresUserGesture = false;
139147
private boolean shouldPauseInAppBrowser = false;
140148
private boolean useWideViewPort = true;
@@ -153,6 +161,7 @@ public class InAppBrowser extends CordovaPlugin {
153161
private boolean fullscreen = true;
154162
private String[] allowedSchemes;
155163
private InAppBrowserClient currentClient;
164+
private PermissionRequest myRequest;
156165

157166
/**
158167
* Executes the request and returns PluginResult.
@@ -583,6 +592,21 @@ public boolean hardwareBack() {
583592
return hadwareBackButton;
584593
}
585594

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+
586610
/**
587611
* Checks to see if it is possible to go forward one page in history, then does so.
588612
*/
@@ -661,6 +685,12 @@ public String showWebPage(final String url, HashMap<String, String> features) {
661685
} else {
662686
hadwareBackButton = DEFAULT_HARDWARE_BACK;
663687
}
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+
}
664694
String mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
665695
if (mediaPlayback != null) {
666696
mediaPlaybackRequiresUserGesture = mediaPlayback.equals("yes") ? true : false;
@@ -977,19 +1007,19 @@ public void onClick(View v) {
9771007
String shareBody = inAppWebView.getUrl();
9781008
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, inAppWebView.getUrl());
9791009
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
980-
1010+
9811011
cordova.getActivity().startActivity(Intent.createChooser(sharingIntent, "URL 공유"));
9821012
}
9831013
});
984-
1014+
9851015
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
9861016
closeLayoutParams.addRule(RelativeLayout.RIGHT_OF, shareButtonId);
9871017
closeButton.setLayoutParams(closeLayoutParams);
9881018

9891019
RelativeLayout.LayoutParams shareLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
9901020
shareLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
9911021
shareButton.setLayoutParams(shareLayoutParams);
992-
1022+
9931023
customButtonContainer.addView((View)closeButton);
9941024
customButtonContainer.addView((View)shareButton);
9951025

@@ -1017,6 +1047,18 @@ public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePath
10171047
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE);
10181048
return true;
10191049
}
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+
}
10201062
});
10211063
currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload);
10221064
inAppWebView.setWebViewClient(currentClient);
@@ -1129,6 +1171,40 @@ public void postMessage(String data) {
11291171
return "";
11301172
}
11311173

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+
11321208
/**
11331209
* Create a new plugin success result and send it back to JavaScript
11341210
*
@@ -1339,12 +1415,12 @@ else if (url.startsWith(HOGANGNONO_SCHEME)) {
13391415
else if (url.startsWith(INTENT_PROTOCOL_START)) {
13401416
final int customUrlStartIndex = INTENT_PROTOCOL_START.length();
13411417
final int customUrlEndIndex = url.indexOf(INTENT_PROTOCOL_INTENT);
1342-
1418+
13431419
if (customUrlEndIndex < 0) {
13441420
return false;
13451421
} else {
13461422
final String customUrl = url.substring(customUrlStartIndex, customUrlEndIndex);
1347-
1423+
13481424
try {
13491425
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(customUrl)));
13501426
} catch (ActivityNotFoundException e) {

src/android/InAppBrowserDialog.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ public void onBackPressed () {
5050
if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
5151
this.inAppBrowser.goBack();
5252
} else {
53-
this.inAppBrowser.closeDialog();
53+
// Hogangnono - triggerback 옵션이 설정되어 있으면, 웹뷰를 닫지 않고 웹으로 backbutton 함수를 실행시킨다
54+
if (this.inAppBrowser.isTriggerBack()) {
55+
this.inAppBrowser.triggerBackButton();
56+
} else {
57+
this.inAppBrowser.closeDialog();
58+
}
5459
}
5560
}
5661
}

0 commit comments

Comments
 (0)