Skip to content

Commit 834fb57

Browse files
authored
Merge pull request #9 from hogangnono/feature/HGNN-7715
[HGNN-7715] [호갱노노/Android] in-app 브라우저 customscheme 대응
2 parents ae99b8e + bebc3ed commit 834fb57

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-inappbrowser",
3-
"version": "5.0.17-hogangnono",
3+
"version": "5.0.20-hogangnono",
44
"description": "Cordova InAppBrowser Plugin",
55
"types": "./types/index.d.ts",
66
"cordova": {
@@ -56,4 +56,4 @@
5656
"devDependencies": {
5757
"@cordova/eslint-config": "^3.0.0"
5858
}
59-
}
59+
}

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.17-hogangnono">
23+
version="5.0.20-hogangnono">
2424

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

src/android/InAppBrowser.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ public class InAppBrowser extends CordovaPlugin {
127127
private static final String FOOTER_COLOR = "footercolor";
128128
private static final String BEFORELOAD = "beforeload";
129129
private static final String FULLSCREEN = "fullscreen";
130+
private static final String ALLOWEDSCHEMES = "allowedschemes";
130131
private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101;
131132
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 102;
132133

133-
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
134+
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR, ALLOWEDSCHEMES);
134135

135136
private InAppBrowserDialog dialog;
136137
private WebView inAppWebView;
@@ -181,6 +182,11 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
181182
}
182183
final String target = t;
183184
final HashMap<String, String> features = parseFeature(args.optString(2));
185+
final String customscheme = features.get(ALLOWEDSCHEMES);
186+
if (customscheme != null) {
187+
LOG.d(LOG_TAG, "customscheme = " + customscheme);
188+
allowedSchemes = customscheme.split("/");
189+
}
184190

185191
LOG.d(LOG_TAG, "target = " + target);
186192

@@ -1029,6 +1035,7 @@ public void onClick(View v) {
10291035

10301036
// WebView
10311037
inAppWebView = new WebView(cordova.getActivity());
1038+
inAppWebView.setBackgroundColor(Color.WHITE);
10321039
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
10331040
inAppWebView.setId(Integer.valueOf(6));
10341041
// File Chooser Implemented ChromeClient
@@ -1443,29 +1450,37 @@ else if (url.startsWith(INTENT_PROTOCOL_START)) {
14431450
}
14441451
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
14451452
else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[A-Za-z0-9+.-]*://.*?$")) {
1446-
if (allowedSchemes == null) {
1447-
String allowed = preferences.getString("AllowedSchemes", null);
1448-
if(allowed != null) {
1449-
allowedSchemes = allowed.split(",");
1450-
}
1451-
}
14521453
if (allowedSchemes != null) {
1453-
for (String scheme : allowedSchemes) {
1454-
if (url.startsWith(scheme)) {
1455-
try {
1456-
JSONObject obj = new JSONObject();
1457-
obj.put("type", "customscheme");
1458-
obj.put("url", url);
1459-
sendUpdate(obj, true);
1454+
try {
1455+
for (String scheme : allowedSchemes) {
1456+
if (scheme != null && (scheme.equals("all") || url.startsWith(scheme))) {
1457+
LOG.d(LOG_TAG, "execute deeplink [" + url + "]");
1458+
try {
1459+
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
1460+
JSONObject obj = new JSONObject();
1461+
obj.put("type", "customscheme");
1462+
obj.put("url", url);
1463+
sendUpdate(obj, true);
1464+
} catch (ActivityNotFoundException e) {
1465+
LOG.e(LOG_TAG, "not installed deeplink app [" + url + "] : " + e.toString());
1466+
} catch (JSONException ex) {
1467+
LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error.");
1468+
}
14601469
override = true;
1461-
} catch (JSONException ex) {
1462-
LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error.");
1470+
break;
14631471
}
14641472
}
1473+
if (!override) {
1474+
LOG.e(LOG_TAG, "not allowed this scheme [" + url + "]");
1475+
}
1476+
} catch (NullPointerException e) {
1477+
LOG.e(LOG_TAG, "scheme is null?! : " + e.toString());
14651478
}
1479+
} else {
1480+
LOG.e(LOG_TAG, "no allowedSchemes");
14661481
}
1482+
return true;
14671483
}
1468-
14691484
if (useBeforeload) {
14701485
this.waitForBeforeload = true;
14711486
}

0 commit comments

Comments
 (0)