intermediate

This commit is contained in:
Fabian Freund
2024-09-13 09:11:06 +02:00
parent 3b047b5d8a
commit 37d2c84d7f
155 changed files with 5666 additions and 1816 deletions
@@ -1,4 +1,3 @@
import 'package:flutter_mozilla_components/src/helper/helper.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
/// Describes a category of an external package.
@@ -16,6 +15,13 @@ enum PackageCategory {
final int id;
const PackageCategory(this.id);
factory PackageCategory.fromInt(int? id) {
return PackageCategory.values.firstWhere(
(category) => category.id == id,
orElse: () => PackageCategory.unknown,
);
}
PackageCategoryValue toValue() {
return PackageCategoryValue(value: id);
}
@@ -36,7 +42,7 @@ abstract class Source {
final caller = packageId != null
? ExternalPackage(
packageId: packageId,
category: packageCategoryfromInt(packageCategory).toValue())
category: PackageCategory.fromInt(packageCategory).toValue())
: null;
switch (sourceId) {
@@ -1,9 +1,11 @@
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
final _apiInstance = GeckoBrowserApi();
class GeckoBrowserService {
final GeckoBrowserApi _api;
GeckoBrowserService({GeckoBrowserApi? api}) : _api = api ?? GeckoBrowserApi();
GeckoBrowserService({GeckoBrowserApi? api}) : _api = api ?? _apiInstance;
Future<void> showNativeFragment() {
return _api.showNativeFragment();
@@ -0,0 +1,99 @@
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
final _apiInstance = GeckoCookieApi();
class GeckoCookieService {
final GeckoCookieApi _api;
GeckoCookieService({GeckoCookieApi? api}) : _api = api ?? _apiInstance;
Future<Cookie> getCookie({
Uri? firstPartyDomain,
required String name,
String? partitionKey,
String? storeId,
required Uri url,
}) {
return _api.getCookie(
firstPartyDomain?.host,
name,
(partitionKey != null)
? CookiePartitionKey(topLevelSite: partitionKey)
: null,
storeId,
url.toString(),
);
}
Future<List<Cookie>> getAllCookies({
Uri? domain,
Uri? firstPartyDomain,
String? name,
String? partitionKey,
String? storeId,
required Uri url,
}) {
return _api
.getAllCookies(
domain?.host,
firstPartyDomain?.host,
name,
(partitionKey != null)
? CookiePartitionKey(topLevelSite: partitionKey)
: null,
storeId,
url.toString(),
)
.then((value) => value.nonNulls.toList());
}
Future<void> setCookie({
Uri? domain,
int? expirationDate,
Uri? firstPartyDomain,
bool? httpOnly,
String? name,
String? partitionKey,
String? path,
CookieSameSiteStatus? sameSite,
bool? secure,
String? storeId,
required Uri url,
String? value,
}) {
return _api.setCookie(
domain?.host,
expirationDate,
firstPartyDomain?.host,
httpOnly,
name,
(partitionKey != null)
? CookiePartitionKey(topLevelSite: partitionKey)
: null,
path,
sameSite,
secure,
storeId,
url.toString(),
value,
);
}
Future<void> removeCookie({
Uri? firstPartyDomain,
required String name,
String? partitionKey,
String? storeId,
required Uri url,
}) {
return _api.removeCookie(
firstPartyDomain?.host,
name,
(partitionKey != null)
? CookiePartitionKey(topLevelSite: partitionKey)
: null,
storeId,
url.toString(),
);
}
}
@@ -0,0 +1,93 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
// Typedefs for record types
typedef HistoryEvent = ({String tabId, HistoryState history});
typedef ReaderableEvent = ({String tabId, ReaderableState readerable});
typedef SecurityInfoEvent = ({String tabId, SecurityInfoState securityInfo});
typedef IconEvent = ({String tabId, Uint8List? bytes});
typedef ThumbnailEvent = ({String tabId, Uint8List? bytes});
class GeckoEventService extends GeckoStateEvents {
// Stream controllers
final _tabListController = StreamController<List<String>>.broadcast();
final _selectedTabController = StreamController<String?>.broadcast();
final _tabContentController = StreamController<TabContentState>.broadcast();
final _historyController = StreamController<HistoryEvent>.broadcast();
final _readerableController = StreamController<ReaderableEvent>.broadcast();
final _securityInfoController =
StreamController<SecurityInfoEvent>.broadcast();
final _iconController = StreamController<IconEvent>.broadcast();
final _thumbnailController = StreamController<ThumbnailEvent>.broadcast();
// Event streams
Stream<List<String>> get tabListEvents => _tabListController.stream;
Stream<String?> get selectedTabEvents => _selectedTabController.stream;
Stream<TabContentState> get tabContentEvents => _tabContentController.stream;
Stream<HistoryEvent> get historyEvents => _historyController.stream;
Stream<ReaderableEvent> get readerableEvents => _readerableController.stream;
Stream<SecurityInfoEvent> get securityInfoEvents =>
_securityInfoController.stream;
Stream<IconEvent> get iconEvents => _iconController.stream;
Stream<ThumbnailEvent> get thumbnailEvents => _thumbnailController.stream;
// Overridden methods
@override
void onTabListChange(List<String?> tabIds) {
_tabListController.add(tabIds.nonNulls.toList());
}
@override
void onSelectedTabChange(String? id) {
_selectedTabController.add(id);
}
@override
void onTabContentStateChange(TabContentState state) {
_tabContentController.add(state);
}
@override
void onHistoryStateChange(String id, HistoryState state) {
_historyController.add((tabId: id, history: state));
}
@override
void onReaderableStateChange(String id, ReaderableState state) {
_readerableController.add((tabId: id, readerable: state));
}
@override
void onSecurityInfoStateChange(String id, SecurityInfoState state) {
_securityInfoController.add((tabId: id, securityInfo: state));
}
@override
void onIconChange(String id, Uint8List? bytes) {
_iconController.add((tabId: id, bytes: bytes));
}
@override
void onThumbnailChange(String id, Uint8List? bytes) {
_thumbnailController.add((tabId: id, bytes: bytes));
}
GeckoEventService.setUp({
BinaryMessenger? binaryMessenger,
String messageChannelSuffix = '',
}) {
GeckoStateEvents.setUp(this);
}
void dispose() {
_tabListController.close();
_selectedTabController.close();
_tabContentController.close();
_historyController.close();
_readerableController.close();
_securityInfoController.close();
_iconController.close();
_thumbnailController.close();
}
}
@@ -0,0 +1,20 @@
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
final _apiInstance = GeckoIconsApi();
class GeckoIconService {
final GeckoIconsApi _api;
GeckoIconService({GeckoIconsApi? api}) : _api = api ?? _apiInstance;
Future<IconResult> loadIcon(
{required Uri url, List<Resource> resources = const []}) async {
return _api.loadIcon(IconRequest(
url: url.toString(),
size: IconSize.defaultSize,
resources: resources,
isPrivate: false,
waitOnNetworkLoad: true,
));
}
}
@@ -1,16 +1,18 @@
import 'package:flutter_mozilla_components/src/data/models/load_url_flags.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
final _apiInstance = GeckoSessionApi();
class GeckoSessionService {
final String? tabId;
final GeckoSessionApi _api;
GeckoSessionService.forCurrentTab({GeckoSessionApi? api})
: _api = api ?? GeckoSessionApi(),
GeckoSessionService.forActiveTab({GeckoSessionApi? api})
: _api = api ?? _apiInstance,
tabId = null;
GeckoSessionService({required String this.tabId, GeckoSessionApi? api})
: _api = api ?? GeckoSessionApi();
: _api = api ?? _apiInstance;
Future<void> loadUrl({
required Uri url,
@@ -1,11 +1,14 @@
import 'package:flutter_mozilla_components/src/data/models/load_url_flags.dart';
import 'package:flutter_mozilla_components/src/data/models/source.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart'
hide IconSource;
class GeckoTabsService {
final _apiInstance = GeckoTabsApi();
class GeckoTabService {
final GeckoTabsApi _api;
GeckoTabsService({GeckoTabsApi? api}) : _api = api ?? GeckoTabsApi();
GeckoTabService({GeckoTabsApi? api}) : _api = api ?? _apiInstance;
Future<void> selectTab({required String tabId}) {
return _api.selectTab(tabId: tabId);
@@ -1,9 +0,0 @@
import 'package:flutter_mozilla_components/src/data/models/source.dart';
/// Maps an int category (as it can be obtained from a package manager) to our internal representation.
PackageCategory packageCategoryfromInt(int? id) {
return PackageCategory.values.firstWhere(
(category) => category.id == id,
orElse: () => PackageCategory.unknown,
);
}
File diff suppressed because it is too large Load Diff