isUriAllowed method
Tells whether the URI is allowed.
Implementation
bool isUriAllowed(Uri uri) {
final host = uri.host;
if (host.isEmpty) {
return false;
}
final patterns = allowedDomains;
for (var pattern in patterns) {
{
final i = pattern.indexOf('://');
if (i < 0) {
if (uri.scheme != 'https') {
continue;
}
} else {
final patternScheme = pattern.substring(0, i);
if (patternScheme != '*' && uri.scheme != patternScheme) {
continue;
}
pattern = pattern.substring(i + 3);
}
}
if (pattern.startsWith('**.')) {
if (host.endsWith(pattern.substring(3))) {
return true;
}
}
if (pattern.startsWith('*.')) {
if (host.endsWith(pattern.substring(2)) &&
host.indexOf('.') == host.length - pattern.length + 1) {
return true;
}
}
// Allow all domains
if (pattern == '**') {
return true;
}
if (host == pattern) {
return true;
}
}
return false;
}