in facebook-common/src/main/java/com/facebook/internal/WebDialog.kt [489:544]
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
logd(LOG_TAG, "Redirect URL: $url")
val parsedURL = Uri.parse(url)
val isPlatformDialogURL =
(parsedURL.path != null && Pattern.matches(PLATFORM_DIALOG_PATH_REGEX, parsedURL.path))
if (url.startsWith(expectedRedirectUrl)) {
val values = parseResponseUri(url)
var error = values.getString("error")
if (error == null) {
error = values.getString("error_type")
}
var errorMessage = values.getString("error_msg")
if (errorMessage == null) {
errorMessage = values.getString("error_message")
}
if (errorMessage == null) {
errorMessage = values.getString("error_description")
}
val errorCodeString = values.getString("error_code")
var errorCode = FacebookRequestError.INVALID_ERROR_CODE
if (errorCodeString !== null && !isNullOrEmpty(errorCodeString)) {
errorCode =
try {
errorCodeString.toInt()
} catch (ex: NumberFormatException) {
FacebookRequestError.INVALID_ERROR_CODE
}
}
if (isNullOrEmpty(error) &&
isNullOrEmpty(errorMessage) &&
errorCode == FacebookRequestError.INVALID_ERROR_CODE) {
sendSuccessToListener(values)
} else if (error != null &&
(error == "access_denied" || error == "OAuthAccessDeniedException")) {
cancel()
} else if (errorCode == API_EC_DIALOG_CANCEL) {
cancel()
} else {
val requestError = FacebookRequestError(errorCode, error, errorMessage)
sendErrorToListener(FacebookServiceException(requestError, errorMessage))
}
return true
} else if (url.startsWith(ServerProtocol.DIALOG_CANCEL_URI)) {
cancel()
return true
} else if (isPlatformDialogURL || url.contains(DISPLAY_TOUCH)) {
return false
}
// launch non-dialog URLs in a full browser
return try {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
true
} catch (e: ActivityNotFoundException) {
false
}
}