@@ -34,12 +34,12 @@ class InAppBrowserPlugin : Plugin() {
34
34
fun openInExternalBrowser (call : PluginCall ) {
35
35
val url = call.getString(" url" )
36
36
if (url.isNullOrEmpty()) {
37
- call.reject( " The value of the 'url' input parameter of the 'openInExternalBrowser' action is missing or is empty. " )
37
+ sendErrorResult( call, OSInAppBrowserError . InputArgumentsIssue ( OSInAppBrowserTarget . EXTERNAL_BROWSER ) )
38
38
return
39
39
}
40
40
41
41
if (! isSchemeValid(url)) {
42
- call.reject( " The URL provided must begin with either http:// or https://. " )
42
+ sendErrorResult(call, OSInAppBrowserError . InvalidURL )
43
43
return
44
44
}
45
45
@@ -50,11 +50,11 @@ class InAppBrowserPlugin : Plugin() {
50
50
if (success) {
51
51
call.resolve()
52
52
} else {
53
- call.reject( " External browser couldn't open the following URL: ' $ url' " )
53
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed ( url, OSInAppBrowserTarget . EXTERNAL_BROWSER ) )
54
54
}
55
55
}
56
56
} catch (e: Exception ) {
57
- call.reject( " An error occurred while trying to open the external browser: ${e.message} " )
57
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed (url, OSInAppBrowserTarget . EXTERNAL_BROWSER ) )
58
58
}
59
59
}
60
60
@@ -63,18 +63,13 @@ class InAppBrowserPlugin : Plugin() {
63
63
val url = call.getString(" url" )
64
64
val options = call.getObject(" options" )
65
65
66
- if (url.isNullOrEmpty()) {
67
- call.reject( " The value of the 'url' input parameter of the 'openInSystemBrowser' action is missing or is empty. " )
66
+ if (url.isNullOrEmpty() || options == null ) {
67
+ sendErrorResult( call, OSInAppBrowserError . InputArgumentsIssue ( OSInAppBrowserTarget . SYSTEM_BROWSER ) )
68
68
return
69
69
}
70
70
71
71
if (! isSchemeValid(url)) {
72
- call.reject(" The URL provided must begin with either http:// or https://." )
73
- return
74
- }
75
-
76
- if (options == null ) {
77
- call.reject(" The value of the 'options' input parameter of the 'openInSystemBrowser' action is missing or isn't valid." )
72
+ sendErrorResult(call, OSInAppBrowserError .InvalidURL )
78
73
return
79
74
}
80
75
@@ -101,12 +96,12 @@ class InAppBrowserPlugin : Plugin() {
101
96
activeRouter = customTabsRouter
102
97
call.resolve()
103
98
} else {
104
- call.reject( " Custom Tabs couldn't open the following URL:' $ url' " )
99
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed ( url, OSInAppBrowserTarget . SYSTEM_BROWSER ) )
105
100
}
106
101
}
107
102
}
108
103
} catch (e: Exception ) {
109
- call.reject( " An error occurred while trying to open Custom Tabs: ${e.message} " )
104
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed (url, OSInAppBrowserTarget . SYSTEM_BROWSER ) )
110
105
}
111
106
}
112
107
@@ -115,30 +110,25 @@ class InAppBrowserPlugin : Plugin() {
115
110
val url = call.getString(" url" )
116
111
val options = call.getObject(" options" )
117
112
118
- if (url.isNullOrEmpty()) {
119
- call.reject( " The value of the 'url' input parameter of the 'openInWebView' action is missing or is empty. " )
113
+ if (url.isNullOrEmpty() || options == null ) {
114
+ sendErrorResult( call, OSInAppBrowserError . InputArgumentsIssue ( OSInAppBrowserTarget . WEB_VIEW ) )
120
115
return
121
116
}
122
117
123
118
if (! isSchemeValid(url)) {
124
- call.reject(" The URL provided must begin with either http:// or https://." )
125
- return
126
- }
127
-
128
- if (options == null ) {
129
- call.reject(" The value of the 'options' input parameter of the 'openInWebView' action is missing or isn't valid." )
119
+ sendErrorResult(call, OSInAppBrowserError .InvalidURL )
130
120
return
131
121
}
132
122
133
123
try {
134
124
// Try closing active router before continuing to open
135
125
close {
136
- val options = buildWebViewOptions(call.getObject( " options" ) )
126
+ val webViewOptions = buildWebViewOptions(options)
137
127
138
128
val webViewRouter = OSIABWebViewRouterAdapter (
139
129
context = context,
140
130
lifecycleScope = activity.lifecycleScope,
141
- options = options ,
131
+ options = webViewOptions ,
142
132
flowHelper = OSIABFlowHelper (),
143
133
onBrowserPageLoaded = {
144
134
notifyListeners(OSIABEventType .BROWSER_PAGE_LOADED .value, null )
@@ -153,12 +143,12 @@ class InAppBrowserPlugin : Plugin() {
153
143
activeRouter = webViewRouter
154
144
call.resolve()
155
145
} else {
156
- call.reject( " The WebView couldn't open the following URL: ' $ url' " )
146
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed ( url, OSInAppBrowserTarget . WEB_VIEW ) )
157
147
}
158
148
}
159
149
}
160
150
} catch (e: Exception ) {
161
- call.reject( " An error occurred while trying to open the WebView: ${e.message} " )
151
+ sendErrorResult( call, OSInAppBrowserError . OpenFailed (url, OSInAppBrowserTarget . WEB_VIEW ) )
162
152
}
163
153
164
154
}
@@ -169,7 +159,7 @@ class InAppBrowserPlugin : Plugin() {
169
159
if (success) {
170
160
call.resolve()
171
161
} else {
172
- call.reject( " There's no browser view to close. " )
162
+ sendErrorResult(call, OSInAppBrowserError . CloseFailed )
173
163
}
174
164
}
175
165
}
@@ -274,6 +264,16 @@ class InAppBrowserPlugin : Plugin() {
274
264
return listOf (" http://" , " https://" ).any { url.startsWith(it, true ) }
275
265
}
276
266
267
+ /* *
268
+ * Helper method to send an error result using call.reject
269
+ * @param call The PluginCall object to send the error result
270
+ * @param error The OSInAppBrowserError object to send as the error result
271
+ */
272
+ private fun sendErrorResult (call : PluginCall , error : OSInAppBrowserError ) {
273
+ call.reject(error.message, error.code)
274
+ }
275
+
276
+
277
277
}
278
278
279
279
enum class OSIABEventType (val value : String ) {
0 commit comments