add setting to block http protocol
This commit is contained in:
@@ -7,7 +7,7 @@ part of 'generic_website.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$genericWebsiteServiceHash() =>
|
String _$genericWebsiteServiceHash() =>
|
||||||
r'06ec407f4ed37b1b6370d48ad418b54131a08007';
|
r'517304ca95e1ef8377d4c1a3bd06fef9c68c92cd';
|
||||||
|
|
||||||
/// See also [GenericWebsiteService].
|
/// See also [GenericWebsiteService].
|
||||||
@ProviderFor(GenericWebsiteService)
|
@ProviderFor(GenericWebsiteService)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class Settings with FastEquatable {
|
|||||||
final bool enableJavascript;
|
final bool enableJavascript;
|
||||||
final bool launchUrlExternal;
|
final bool launchUrlExternal;
|
||||||
final bool enableContentBlocking;
|
final bool enableContentBlocking;
|
||||||
|
final bool blockHttpProtocol;
|
||||||
final Set<HostSource> enableHostList;
|
final Set<HostSource> enableHostList;
|
||||||
final ThemeMode themeMode;
|
final ThemeMode themeMode;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ class Settings with FastEquatable {
|
|||||||
required this.enableJavascript,
|
required this.enableJavascript,
|
||||||
required this.launchUrlExternal,
|
required this.launchUrlExternal,
|
||||||
required this.enableContentBlocking,
|
required this.enableContentBlocking,
|
||||||
|
required this.blockHttpProtocol,
|
||||||
required this.enableHostList,
|
required this.enableHostList,
|
||||||
required this.themeMode,
|
required this.themeMode,
|
||||||
});
|
});
|
||||||
@@ -34,6 +36,7 @@ class Settings with FastEquatable {
|
|||||||
bool? enableJavascript,
|
bool? enableJavascript,
|
||||||
bool? launchUrlExternal,
|
bool? launchUrlExternal,
|
||||||
bool? enableContentBlocking,
|
bool? enableContentBlocking,
|
||||||
|
bool? blockHttpProtocol,
|
||||||
Set<HostSource>? enableHostList,
|
Set<HostSource>? enableHostList,
|
||||||
ThemeMode? themeMode,
|
ThemeMode? themeMode,
|
||||||
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
|
}) : showEarlyAccessFeatures = showEarlyAccessFeatures ?? true,
|
||||||
@@ -41,6 +44,7 @@ class Settings with FastEquatable {
|
|||||||
enableJavascript = enableJavascript ?? true,
|
enableJavascript = enableJavascript ?? true,
|
||||||
launchUrlExternal = launchUrlExternal ?? false,
|
launchUrlExternal = launchUrlExternal ?? false,
|
||||||
enableContentBlocking = enableContentBlocking ?? true,
|
enableContentBlocking = enableContentBlocking ?? true,
|
||||||
|
blockHttpProtocol = blockHttpProtocol ?? false,
|
||||||
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
enableHostList = enableHostList ?? {HostSource.stevenBlackUnified},
|
||||||
themeMode = themeMode ?? ThemeMode.dark;
|
themeMode = themeMode ?? ThemeMode.dark;
|
||||||
|
|
||||||
@@ -55,6 +59,7 @@ class Settings with FastEquatable {
|
|||||||
enableJavascript,
|
enableJavascript,
|
||||||
launchUrlExternal,
|
launchUrlExternal,
|
||||||
enableContentBlocking,
|
enableContentBlocking,
|
||||||
|
blockHttpProtocol,
|
||||||
enableHostList,
|
enableHostList,
|
||||||
themeMode,
|
themeMode,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ abstract class _$SettingsCWProxy {
|
|||||||
|
|
||||||
Settings enableContentBlocking(bool enableContentBlocking);
|
Settings enableContentBlocking(bool enableContentBlocking);
|
||||||
|
|
||||||
|
Settings blockHttpProtocol(bool blockHttpProtocol);
|
||||||
|
|
||||||
Settings enableHostList(Set<HostSource> enableHostList);
|
Settings enableHostList(Set<HostSource> enableHostList);
|
||||||
|
|
||||||
Settings themeMode(ThemeMode themeMode);
|
Settings themeMode(ThemeMode themeMode);
|
||||||
@@ -36,6 +38,7 @@ abstract class _$SettingsCWProxy {
|
|||||||
bool? enableJavascript,
|
bool? enableJavascript,
|
||||||
bool? launchUrlExternal,
|
bool? launchUrlExternal,
|
||||||
bool? enableContentBlocking,
|
bool? enableContentBlocking,
|
||||||
|
bool? blockHttpProtocol,
|
||||||
Set<HostSource>? enableHostList,
|
Set<HostSource>? enableHostList,
|
||||||
ThemeMode? themeMode,
|
ThemeMode? themeMode,
|
||||||
});
|
});
|
||||||
@@ -70,6 +73,10 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
Settings enableContentBlocking(bool enableContentBlocking) =>
|
Settings enableContentBlocking(bool enableContentBlocking) =>
|
||||||
this(enableContentBlocking: enableContentBlocking);
|
this(enableContentBlocking: enableContentBlocking);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Settings blockHttpProtocol(bool blockHttpProtocol) =>
|
||||||
|
this(blockHttpProtocol: blockHttpProtocol);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Settings enableHostList(Set<HostSource> enableHostList) =>
|
Settings enableHostList(Set<HostSource> enableHostList) =>
|
||||||
this(enableHostList: enableHostList);
|
this(enableHostList: enableHostList);
|
||||||
@@ -92,6 +99,7 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
Object? enableJavascript = const $CopyWithPlaceholder(),
|
Object? enableJavascript = const $CopyWithPlaceholder(),
|
||||||
Object? launchUrlExternal = const $CopyWithPlaceholder(),
|
Object? launchUrlExternal = const $CopyWithPlaceholder(),
|
||||||
Object? enableContentBlocking = const $CopyWithPlaceholder(),
|
Object? enableContentBlocking = const $CopyWithPlaceholder(),
|
||||||
|
Object? blockHttpProtocol = const $CopyWithPlaceholder(),
|
||||||
Object? enableHostList = const $CopyWithPlaceholder(),
|
Object? enableHostList = const $CopyWithPlaceholder(),
|
||||||
Object? themeMode = const $CopyWithPlaceholder(),
|
Object? themeMode = const $CopyWithPlaceholder(),
|
||||||
}) {
|
}) {
|
||||||
@@ -127,6 +135,11 @@ class _$SettingsCWProxyImpl implements _$SettingsCWProxy {
|
|||||||
? _value.enableContentBlocking
|
? _value.enableContentBlocking
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: enableContentBlocking as bool,
|
: enableContentBlocking as bool,
|
||||||
|
blockHttpProtocol: blockHttpProtocol == const $CopyWithPlaceholder() ||
|
||||||
|
blockHttpProtocol == null
|
||||||
|
? _value.blockHttpProtocol
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: blockHttpProtocol as bool,
|
||||||
enableHostList: enableHostList == const $CopyWithPlaceholder() ||
|
enableHostList: enableHostList == const $CopyWithPlaceholder() ||
|
||||||
enableHostList == null
|
enableHostList == null
|
||||||
? _value.enableHostList
|
? _value.enableHostList
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
static const _javascriptStorageKey = 'b4ng_settings_js';
|
static const _javascriptStorageKey = 'b4ng_settings_js';
|
||||||
static const _launchExternalStorageKey = 'b4ng_settings_launch_external';
|
static const _launchExternalStorageKey = 'b4ng_settings_launch_external';
|
||||||
static const _contentBlockingStorageKey = 'b4ng_settings_content_blocking';
|
static const _contentBlockingStorageKey = 'b4ng_settings_content_blocking';
|
||||||
|
static const _blockHttpProtocolStorageKey = 'b4ng_settings_block_http';
|
||||||
static const _enableHostListStorageKey = 'b4ng_settings_host_lists';
|
static const _enableHostListStorageKey = 'b4ng_settings_host_lists';
|
||||||
static const _themeModeStorageKey = 'b4ng_settings_theme_mode';
|
static const _themeModeStorageKey = 'b4ng_settings_theme_mode';
|
||||||
|
|
||||||
@@ -96,6 +97,13 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSettings.blockHttpProtocol != oldSettings.blockHttpProtocol) {
|
||||||
|
await sharedPreferences.setBool(
|
||||||
|
_blockHttpProtocolStorageKey,
|
||||||
|
newSettings.blockHttpProtocol,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!const DeepCollectionEquality.unordered().equals(
|
if (!const DeepCollectionEquality.unordered().equals(
|
||||||
newSettings.enableHostList,
|
newSettings.enableHostList,
|
||||||
oldSettings.enableHostList,
|
oldSettings.enableHostList,
|
||||||
@@ -130,6 +138,8 @@ class SettingsRepository extends _$SettingsRepository {
|
|||||||
launchUrlExternal: sharedPreferences.getBool(_launchExternalStorageKey),
|
launchUrlExternal: sharedPreferences.getBool(_launchExternalStorageKey),
|
||||||
enableContentBlocking:
|
enableContentBlocking:
|
||||||
sharedPreferences.getBool(_contentBlockingStorageKey),
|
sharedPreferences.getBool(_contentBlockingStorageKey),
|
||||||
|
blockHttpProtocol:
|
||||||
|
sharedPreferences.getBool(_blockHttpProtocolStorageKey),
|
||||||
enableHostList: _parseHostSources(
|
enableHostList: _parseHostSources(
|
||||||
sharedPreferences.getStringList(_enableHostListStorageKey),
|
sharedPreferences.getStringList(_enableHostListStorageKey),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ part of 'settings_repository.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
String _$settingsRepositoryHash() =>
|
String _$settingsRepositoryHash() =>
|
||||||
r'2fed76bdc3132729f1018f8e4c9d493ee11831a0';
|
r'ac2b1ecddd82e45e901425e9e5fcb9b4b61855fa';
|
||||||
|
|
||||||
/// See also [SettingsRepository].
|
/// See also [SettingsRepository].
|
||||||
@ProviderFor(SettingsRepository)
|
@ProviderFor(SettingsRepository)
|
||||||
|
|||||||
@@ -214,6 +214,19 @@ class SettingsScreen extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
SwitchListTile.adaptive(
|
||||||
|
title: const Text('Block HTTP Protocol'),
|
||||||
|
subtitle: const Text(
|
||||||
|
'Prevents loading of HTTP (unsecure) content entirely. When enabled, only HTTPS (secure) is allowed.',
|
||||||
|
),
|
||||||
|
value: settings.blockHttpProtocol,
|
||||||
|
onChanged: (value) async {
|
||||||
|
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||||
|
(currentSettings) =>
|
||||||
|
currentSettings.copyWith.blockHttpProtocol(value),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
SwitchListTile.adaptive(
|
SwitchListTile.adaptive(
|
||||||
title: const Text('Launch Links Externally'),
|
title: const Text('Launch Links Externally'),
|
||||||
subtitle: const Text(
|
subtitle: const Text(
|
||||||
|
|||||||
@@ -312,6 +312,19 @@ class _WebViewState extends ConsumerState<WebView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.url.isScheme('http')) {
|
||||||
|
if ((ref.read(settingsRepositoryProvider).valueOrNull ??
|
||||||
|
Settings.withDefaults())
|
||||||
|
.blockHttpProtocol) {
|
||||||
|
return WebResourceResponse(
|
||||||
|
contentType: "text/plain",
|
||||||
|
data: utf8.encode("HTTP protocol is blocked"),
|
||||||
|
statusCode: 403,
|
||||||
|
reasonPhrase: "Forbidden",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onProgressChanged: (controller, progress) {
|
onProgressChanged: (controller, progress) {
|
||||||
|
|||||||
Reference in New Issue
Block a user