migrate mozilla components into project

This commit is contained in:
Fabian Freund
2024-09-07 08:49:38 +02:00
parent 10a49def87
commit 3b047b5d8a
67 changed files with 5840 additions and 0 deletions
@@ -0,0 +1,11 @@
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
class GeckoBrowserService {
final GeckoBrowserApi _api;
GeckoBrowserService({GeckoBrowserApi? api}) : _api = api ?? GeckoBrowserApi();
Future<void> showNativeFragment() {
return _api.showNativeFragment();
}
}
@@ -0,0 +1,128 @@
import 'package:flutter_mozilla_components/src/data/models/load_url_flags.dart';
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
class GeckoSessionService {
final String? tabId;
final GeckoSessionApi _api;
GeckoSessionService.forCurrentTab({GeckoSessionApi? api})
: _api = api ?? GeckoSessionApi(),
tabId = null;
GeckoSessionService({required String this.tabId, GeckoSessionApi? api})
: _api = api ?? GeckoSessionApi();
Future<void> loadUrl({
required Uri url,
LoadUrlFlags flags = LoadUrlFlags.NONE,
Map<String, String>? additionalHeaders,
}) {
return _api.loadUrl(
tabId: tabId,
url: url.toString(),
flags: flags.toValue(),
additionalHeaders: additionalHeaders,
);
}
Future<void> loadData({
required String data,
required String mimeType,
String encoding = "UTF-8",
}) {
return _api.loadData(
tabId: tabId,
data: data,
mimeType: mimeType,
encoding: encoding,
);
}
Future<void> reload({LoadUrlFlags flags = LoadUrlFlags.NONE}) {
return _api.reload(
tabId: tabId,
flags: flags.toValue(),
);
}
Future<void> stopLoading() {
return _api.stopLoading(tabId: tabId);
}
Future<void> goBack({bool userInteraction = true}) {
return _api.goBack(
tabId: tabId,
userInteraction: userInteraction,
);
}
Future<void> goForward({bool userInteraction = true}) {
return _api.goForward(
tabId: tabId,
userInteraction: userInteraction,
);
}
Future<void> goToHistoryIndex({required int index}) {
return _api.goToHistoryIndex(
index: index,
tabId: tabId,
);
}
Future<void> requestDesktopSite({required bool enable}) {
return _api.requestDesktopSite(
enable: enable,
tabId: tabId,
);
}
Future<void> exitFullscreen() {
return _api.exitFullscreen(tabId: tabId);
}
Future<void> saveToPdf() {
return _api.saveToPdf(tabId: tabId);
}
Future<void> printContent() {
return _api.printContent(tabId: tabId);
}
Future<void> translate({
required String fromLanguage,
required String toLanguage,
TranslationOptions? options,
}) {
return _api.translate(
tabId: tabId,
fromLanguage: fromLanguage,
toLanguage: toLanguage,
options: options,
);
}
Future<void> translateRestore() {
return _api.translateRestore(tabId: tabId);
}
Future<void> crashRecovery({
List<String>? tabIds,
}) {
return _api.crashRecovery(tabIds: tabIds);
}
Future<void> purgeHistory() {
return _api.purgeHistory();
}
Future<void> updateLastAccess({
String? tabId, //If null = current tab
DateTime? lastAccess, //If null datetime.now
}) {
return _api.updateLastAccess(
tabId: tabId,
lastAccess: (lastAccess ?? DateTime.now()).millisecondsSinceEpoch,
);
}
}
@@ -0,0 +1,135 @@
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';
class GeckoTabsService {
final GeckoTabsApi _api;
GeckoTabsService({GeckoTabsApi? api}) : _api = api ?? GeckoTabsApi();
Future<void> selectTab({required String tabId}) {
return _api.selectTab(tabId: tabId);
}
Future<void> removeTab({required String tabId}) {
return _api.removeTab(tabId: tabId);
}
Future<String> addTab({
Uri? url,
bool selectTab = true,
bool startLoading = true,
String? parentId,
LoadUrlFlags flags = LoadUrlFlags.NONE,
String? contextId,
Source source = Internal.newTab,
bool private = false,
HistoryMetadataKey? historyMetadata,
Map<String, String>? additionalHeaders,
}) {
return _api.addTab(
url: (url ?? Uri.parse('about:blank')).toString(),
selectTab: selectTab,
startLoading: startLoading,
parentId: parentId,
flags: flags.toValue(),
contextId: contextId,
source: source.toValue(),
private: private,
historyMetadata: historyMetadata,
additionalHeaders: additionalHeaders,
);
}
Future<void> removeAllTabs({required bool recoverable}) {
return _api.removeAllTabs(recoverable: recoverable);
}
Future<void> removeTabs({required List<String> ids}) {
return _api.removeTabs(ids: ids);
}
Future<void> removeNormalTabs() {
return _api.removeNormalTabs();
}
Future<void> removePrivateTabs() {
return _api.removePrivateTabs();
}
Future<void> undo() {
return _api.undo();
}
//restoreTabs invokes splitted
Future<void> restoreTabsByList({
required List<RecoverableTab> tabs,
String? selectTabId,
RestoreLocation restoreLocation = RestoreLocation.end,
}) {
return _api.restoreTabsByList(
tabs: tabs, selectTabId: selectTabId, restoreLocation: restoreLocation);
}
Future<void> restoreTabsByBrowserState({
required RecoverableBrowserState state,
RestoreLocation restoreLocation = RestoreLocation.end,
}) {
return _api.restoreTabsByBrowserState(
state: state, restoreLocation: restoreLocation);
}
//The calls with engin storage for restore are not supported at the moment
//selectOrAddTab invokes splitted
/// Selects an already existing tab with the matching [HistoryMetadataKey] or otherwise
/// creates a new tab with the given [url].
Future<String> selectOrAddTabByHistory({
required Uri url,
required HistoryMetadataKey historyMetadata,
}) {
return _api.selectOrAddTabByHistory(
url: url.toString(), historyMetadata: historyMetadata);
}
/// Selects an already existing tab displaying [url] or otherwise creates a new tab.
Future<String> selectOrAddTabByUrl({
required Uri url,
bool private = false,
Source source = Internal.newTab,
LoadUrlFlags flags = LoadUrlFlags.NONE,
bool ignoreFragment = false,
}) {
return _api.selectOrAddTabByUrl(
url: url.toString(),
private: private,
source: source.toValue(),
flags: flags.toValue(),
ignoreFragment: ignoreFragment,
);
}
Future<String> duplicateTab({
String? selectTabId,
bool selectNewTab = true,
}) {
return _api.duplicateTab(
selectTabId: selectTabId, selectNewTab: selectNewTab);
}
Future<void> moveTabs({
required List<String> tabIds,
required String targetTabId,
required bool placeAfter,
}) {
return _api.moveTabs(
tabIds: tabIds, targetTabId: targetTabId, placeAfter: placeAfter);
}
Future<String> migratePrivateTabUseCase({
required String tabId,
Uri? alternativeUrl,
}) {
return _api.migratePrivateTabUseCase(
tabId: tabId, alternativeUrl: alternativeUrl?.toString());
}
}