Skip to content

Commit 1211a64

Browse files
committed
fix(android): Validate url from Android platform
1 parent 48bc53c commit 1211a64

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ in case of vulnerabilities.
2222

2323
## [Unreleased]
2424

25+
## [3.6.1] - 2021-06-27
26+
27+
- Add try catch block to `CustomTabs` logic to validate the url.
28+
2529
## [3.6.0] - 2021-06-25
2630

2731
### Added
@@ -187,7 +191,8 @@ Missing tags for previous versions 🤷‍♂
187191
- Fix `EventBusException` on **Android** by [@Almouro](https://github.com/Almouro) ([9cf4cbb](https://github.com/proyecto26/react-native-inappbrowser/commit/9cf4cbb58d55c8b534dabac6791e6a2a5428253f)).
188192

189193

190-
[Unreleased]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.6.0...HEAD
194+
[Unreleased]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.6.1...HEAD
195+
[3.6.1]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.6.0...v3.6.1
191196
[3.6.0]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.5.1...v3.6.0
192197
[3.5.1]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.5.0...v3.5.1
193198
[3.5.0]: https://github.com/proyecto26/react-native-inappbrowser/compare/v3.4.0...v3.5.0

android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsDismissedEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
public class ChromeTabsDismissedEvent {
44
public final String message;
55
public final String resultType;
6+
public final Boolean isError;
67

7-
public ChromeTabsDismissedEvent(String message, String resultType) {
8+
public ChromeTabsDismissedEvent(String message, String resultType, Boolean isError) {
89
this.message = message;
910
this.resultType = resultType;
11+
this.isError = isError;
1012
}
1113
}

android/src/main/java/com/proyecto26/inappbrowser/ChromeTabsManagerActivity.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,26 @@ private static Intent createBaseIntent(Context context) {
3939

4040
@Override
4141
protected void onCreate(Bundle savedInstanceState) {
42-
super.onCreate(savedInstanceState);
42+
try {
43+
super.onCreate(savedInstanceState);
4344

44-
// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
45-
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
46-
// in order to close the intent that was started previously so we just close this.
47-
if (getIntent().hasExtra(KEY_BROWSER_INTENT)
48-
&& (savedInstanceState == null || savedInstanceState.getString(BROWSER_RESULT_TYPE) == null)
49-
) {
50-
Intent browserIntent = getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
51-
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
52-
startActivity(browserIntent);
53-
resultType = DEFAULT_RESULT_TYPE;
54-
} else {
45+
// This activity gets opened in 2 different ways. If the extra KEY_BROWSER_INTENT is present we
46+
// start that intent and if it is not it means this activity was started with FLAG_ACTIVITY_CLEAR_TOP
47+
// in order to close the intent that was started previously so we just close this.
48+
if (getIntent().hasExtra(KEY_BROWSER_INTENT)
49+
&& (savedInstanceState == null || savedInstanceState.getString(BROWSER_RESULT_TYPE) == null)
50+
) {
51+
Intent browserIntent = getIntent().getParcelableExtra(KEY_BROWSER_INTENT);
52+
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
53+
startActivity(browserIntent);
54+
resultType = DEFAULT_RESULT_TYPE;
55+
} else {
56+
finish();
57+
}
58+
} catch (Exception e) {
59+
EventBus.getDefault().post(new ChromeTabsDismissedEvent("Unable to open url.", "cancel", true));
5560
finish();
61+
e.printStackTrace();
5662
}
5763
}
5864

@@ -76,10 +82,10 @@ protected void onDestroy() {
7682
if (resultType != null) {
7783
switch (resultType) {
7884
case "cancel":
79-
EventBus.getDefault().post(new ChromeTabsDismissedEvent("chrome tabs activity closed", resultType));
85+
EventBus.getDefault().post(new ChromeTabsDismissedEvent("chrome tabs activity closed", resultType, false));
8086
break;
8187
default:
82-
EventBus.getDefault().post(new ChromeTabsDismissedEvent("chrome tabs activity destroyed", DEFAULT_RESULT_TYPE));
88+
EventBus.getDefault().post(new ChromeTabsDismissedEvent("chrome tabs activity destroyed", DEFAULT_RESULT_TYPE, false));
8389
break;
8490
}
8591
resultType = null;

android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,13 @@ public void onEvent(ChromeTabsDismissedEvent event) {
238238
throw new AssertionError();
239239
}
240240

241-
WritableMap result = Arguments.createMap();
242-
result.putString("type", event.resultType);
243-
mOpenBrowserPromise.resolve(result);
241+
if (event.isError) {
242+
mOpenBrowserPromise.reject(ERROR_CODE, event.message);
243+
} else {
244+
WritableMap result = Arguments.createMap();
245+
result.putString("type", event.resultType);
246+
mOpenBrowserPromise.resolve(result);
247+
}
244248
mOpenBrowserPromise = null;
245249
}
246250

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ buck-out/
5757

5858
# CocoaPods
5959
/ios/Pods/
60+
61+
yarn.lock

example/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class App extends Component<ComponentState> {
3737
super(props);
3838

3939
this.state = {
40-
url: 'https://www.proyecto26.com',
40+
url: 'https://reactnative.dev',
4141
statusBarStyle: 'dark-content',
4242
};
4343
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-inappbrowser-reborn",
3-
"version": "3.6.0",
3+
"version": "3.6.1",
44
"description": "InAppBrowser for React Native",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)