implement tracking protection per site
This commit is contained in:
@@ -58,6 +58,7 @@ export 'src/pigeons/gecko.g.dart'
|
||||
GeckoSitePermissionsApi,
|
||||
GeckoSuggestion,
|
||||
GeckoSuggestionType,
|
||||
GeckoTrackingProtectionApi,
|
||||
GeoHitResult,
|
||||
HistoryMetadataKey,
|
||||
HitResult,
|
||||
@@ -75,10 +76,11 @@ export 'src/pigeons/gecko.g.dart'
|
||||
Resource,
|
||||
ResourceSize,
|
||||
SecurityInfoState,
|
||||
SitePermissions,
|
||||
SitePermissionStatus,
|
||||
SitePermissions,
|
||||
TabContent,
|
||||
TabContentState,
|
||||
TrackingProtectionException,
|
||||
TrackingProtectionPolicy,
|
||||
UnknownHitResult,
|
||||
VideoHitResult,
|
||||
|
||||
@@ -3613,6 +3613,51 @@ class SitePermissions {
|
||||
;
|
||||
}
|
||||
|
||||
/// Tracking protection exception for a site
|
||||
///
|
||||
/// This represents a site that has been added to the exceptions list,
|
||||
/// meaning tracking protection is disabled for this specific site.
|
||||
class TrackingProtectionException {
|
||||
TrackingProtectionException({
|
||||
required this.url,
|
||||
});
|
||||
|
||||
String url;
|
||||
|
||||
List<Object?> _toList() {
|
||||
return <Object?>[
|
||||
url,
|
||||
];
|
||||
}
|
||||
|
||||
Object encode() {
|
||||
return _toList(); }
|
||||
|
||||
static TrackingProtectionException decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return TrackingProtectionException(
|
||||
url: result[0]! as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
bool operator ==(Object other) {
|
||||
if (other is! TrackingProtectionException || other.runtimeType != runtimeType) {
|
||||
return false;
|
||||
}
|
||||
if (identical(this, other)) {
|
||||
return true;
|
||||
}
|
||||
return _deepEquals(encode(), other.encode());
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hashAll(_toList())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@@ -3864,6 +3909,9 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
} else if (value is SitePermissions) {
|
||||
buffer.putUint8(209);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is TrackingProtectionException) {
|
||||
buffer.putUint8(210);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
@@ -4062,6 +4110,8 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
return BookmarkInfo.decode(readValue(buffer)!);
|
||||
case 209:
|
||||
return SitePermissions.decode(readValue(buffer)!);
|
||||
case 210:
|
||||
return TrackingProtectionException.decode(readValue(buffer)!);
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
@@ -7866,3 +7916,186 @@ class GeckoPublicSuffixListApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// API for managing per-site tracking protection exceptions
|
||||
///
|
||||
/// This API wraps Mozilla Android Components' TrackingProtectionUseCases
|
||||
/// to allow Flutter code to add/remove/check tracking protection exceptions
|
||||
/// on a per-site basis.
|
||||
class GeckoTrackingProtectionApi {
|
||||
/// Constructor for [GeckoTrackingProtectionApi]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
GeckoTrackingProtectionApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
|
||||
: pigeonVar_binaryMessenger = binaryMessenger,
|
||||
pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
|
||||
final BinaryMessenger? pigeonVar_binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
|
||||
|
||||
final String pigeonVar_messageChannelSuffix;
|
||||
|
||||
/// Check if a tab has a tracking protection exception
|
||||
///
|
||||
/// Uses callback pattern to match Mozilla Android Components API.
|
||||
/// Returns true if the site is in the exceptions list (ETP disabled).
|
||||
Future<bool> containsException(String tabId) async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.containsException$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[tabId]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as bool?)!;
|
||||
}
|
||||
}
|
||||
|
||||
/// Add tracking protection exception for a tab (disable ETP for this site)
|
||||
///
|
||||
/// This adds the current tab's URL to the exceptions list.
|
||||
/// ETP will be disabled for this site until the exception is removed.
|
||||
Future<void> addException(String tabId) async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.addException$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[tabId]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove tracking protection exception for a tab (enable ETP for this site)
|
||||
///
|
||||
/// This removes the current tab's URL from the exceptions list.
|
||||
/// ETP will be re-enabled for this site.
|
||||
Future<void> removeException(String tabId) async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.removeException$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[tabId]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a specific exception by URL
|
||||
///
|
||||
/// Alternative to removeException(tabId) for cases where you
|
||||
/// have a URL rather than a tabId.
|
||||
Future<void> removeExceptionByUrl(String url) async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.removeExceptionByUrl$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[url]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch all tracking protection exceptions
|
||||
///
|
||||
/// Returns list of all sites that have exceptions (ETP disabled).
|
||||
Future<List<TrackingProtectionException>> fetchExceptions() async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.fetchExceptions$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<TrackingProtectionException>();
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove all tracking protection exceptions
|
||||
///
|
||||
/// This re-enables ETP for all exception sites.
|
||||
Future<void> removeAllExceptions() async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoTrackingProtectionApi.removeAllExceptions$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user