mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-13 20:03:46 +00:00
Isolate extension WebView profiles and follow host proxy settings
This commit is contained in:
1 parent
cee5f3336e
commit
a0e84a75b1
556 files changed
+71097
-31
No files matched your search
+3
@@ -0,0 +1,3 @@
|
||||
library flutter_inappwebview_macos;
|
||||
|
||||
export 'src/main.dart';
|
||||
+433
@@ -0,0 +1,433 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
import 'in_app_webview/headless_in_app_webview.dart';
|
||||
import 'platform_util.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSCookieManager].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformCookieManagerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSCookieManagerCreationParams
|
||||
extends PlatformCookieManagerCreationParams {
|
||||
/// Creates a new [MacOSCookieManagerCreationParams] instance.
|
||||
const MacOSCookieManagerCreationParams(
|
||||
// This parameter prevents breaking changes later.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformCookieManagerCreationParams params,
|
||||
) : super();
|
||||
|
||||
/// Creates a [MacOSCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams].
|
||||
factory MacOSCookieManagerCreationParams.fromPlatformCookieManagerCreationParams(
|
||||
PlatformCookieManagerCreationParams params) {
|
||||
return MacOSCookieManagerCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager}
|
||||
class MacOSCookieManager extends PlatformCookieManager with ChannelController {
|
||||
/// Creates a new [MacOSCookieManager].
|
||||
MacOSCookieManager(PlatformCookieManagerCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSCookieManagerCreationParams
|
||||
? params
|
||||
: MacOSCookieManagerCreationParams
|
||||
.fromPlatformCookieManagerCreationParams(params),
|
||||
) {
|
||||
channel = const MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_cookiemanager');
|
||||
handler = handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
static MacOSCookieManager? _instance;
|
||||
|
||||
///Gets the [MacOSCookieManager] shared instance.
|
||||
static MacOSCookieManager instance() {
|
||||
return (_instance != null) ? _instance! : _init();
|
||||
}
|
||||
|
||||
static MacOSCookieManager _init() {
|
||||
_instance = MacOSCookieManager(MacOSCookieManagerCreationParams(
|
||||
const PlatformCookieManagerCreationParams()));
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {}
|
||||
|
||||
@override
|
||||
Future<bool> setCookie(
|
||||
{required WebUri url,
|
||||
required String name,
|
||||
required String value,
|
||||
String path = "/",
|
||||
String? domain,
|
||||
int? expiresDate,
|
||||
int? maxAge,
|
||||
bool? isSecure,
|
||||
bool? isHttpOnly,
|
||||
HTTPCookieSameSitePolicy? sameSite,
|
||||
@Deprecated("Use webViewController instead")
|
||||
PlatformInAppWebViewController? iosBelow11WebViewController,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
webViewController = webViewController ?? iosBelow11WebViewController;
|
||||
|
||||
assert(url.toString().isNotEmpty);
|
||||
assert(name.isNotEmpty);
|
||||
assert(value.isNotEmpty);
|
||||
assert(path.isNotEmpty);
|
||||
|
||||
if (await _shouldUseJavascript()) {
|
||||
await _setCookieWithJavaScript(
|
||||
url: url,
|
||||
name: name,
|
||||
value: value,
|
||||
domain: domain,
|
||||
path: path,
|
||||
expiresDate: expiresDate,
|
||||
maxAge: maxAge,
|
||||
isSecure: isSecure,
|
||||
sameSite: sameSite,
|
||||
webViewController: webViewController);
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
args.putIfAbsent('name', () => name);
|
||||
args.putIfAbsent('value', () => value);
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
args.putIfAbsent('expiresDate', () => expiresDate?.toString());
|
||||
args.putIfAbsent('maxAge', () => maxAge);
|
||||
args.putIfAbsent('isSecure', () => isSecure);
|
||||
args.putIfAbsent('isHttpOnly', () => isHttpOnly);
|
||||
args.putIfAbsent('sameSite', () => sameSite?.toNativeValue());
|
||||
|
||||
return await channel?.invokeMethod<bool>('setCookie', args) ?? false;
|
||||
}
|
||||
|
||||
Future<void> _setCookieWithJavaScript(
|
||||
{required WebUri url,
|
||||
required String name,
|
||||
required String value,
|
||||
String path = "/",
|
||||
String? domain,
|
||||
int? expiresDate,
|
||||
int? maxAge,
|
||||
bool? isSecure,
|
||||
HTTPCookieSameSitePolicy? sameSite,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
var cookieValue = name + "=" + value + "; Path=" + path;
|
||||
|
||||
if (domain != null) cookieValue += "; Domain=" + domain;
|
||||
|
||||
if (expiresDate != null)
|
||||
cookieValue += "; Expires=" + await _getCookieExpirationDate(expiresDate);
|
||||
|
||||
if (maxAge != null) cookieValue += "; Max-Age=" + maxAge.toString();
|
||||
|
||||
if (isSecure != null && isSecure) cookieValue += "; Secure";
|
||||
|
||||
if (sameSite != null)
|
||||
cookieValue += "; SameSite=" + sameSite.toNativeValue();
|
||||
|
||||
cookieValue += ";";
|
||||
|
||||
if (webViewController != null) {
|
||||
final javaScriptEnabled =
|
||||
(await webViewController.getSettings())?.javaScriptEnabled ?? false;
|
||||
if (javaScriptEnabled) {
|
||||
await webViewController.evaluateJavascript(
|
||||
source: 'document.cookie="$cookieValue"');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final setCookieCompleter = Completer<void>();
|
||||
final headlessWebView =
|
||||
MacOSHeadlessInAppWebView(MacOSHeadlessInAppWebViewCreationParams(
|
||||
initialUrlRequest: URLRequest(url: url),
|
||||
onLoadStop: (controller, url) async {
|
||||
await controller.evaluateJavascript(
|
||||
source: 'document.cookie="$cookieValue"');
|
||||
setCookieCompleter.complete();
|
||||
}));
|
||||
await headlessWebView.run();
|
||||
await setCookieCompleter.future;
|
||||
await headlessWebView.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Cookie>> getCookies(
|
||||
{required WebUri url,
|
||||
@Deprecated("Use webViewController instead")
|
||||
PlatformInAppWebViewController? iosBelow11WebViewController,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
|
||||
webViewController = webViewController ?? iosBelow11WebViewController;
|
||||
|
||||
if (await _shouldUseJavascript()) {
|
||||
return await _getCookiesWithJavaScript(
|
||||
url: url, webViewController: webViewController);
|
||||
}
|
||||
|
||||
List<Cookie> cookies = [];
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
List<dynamic> cookieListMap =
|
||||
await channel?.invokeMethod<List>('getCookies', args) ?? [];
|
||||
cookieListMap = cookieListMap.cast<Map<dynamic, dynamic>>();
|
||||
|
||||
cookieListMap.forEach((cookieMap) {
|
||||
cookies.add(Cookie(
|
||||
name: cookieMap["name"],
|
||||
value: cookieMap["value"],
|
||||
expiresDate: cookieMap["expiresDate"],
|
||||
isSessionOnly: cookieMap["isSessionOnly"],
|
||||
domain: cookieMap["domain"],
|
||||
sameSite:
|
||||
HTTPCookieSameSitePolicy.fromNativeValue(cookieMap["sameSite"]),
|
||||
isSecure: cookieMap["isSecure"],
|
||||
isHttpOnly: cookieMap["isHttpOnly"],
|
||||
path: cookieMap["path"]));
|
||||
});
|
||||
return cookies;
|
||||
}
|
||||
|
||||
Future<List<Cookie>> _getCookiesWithJavaScript(
|
||||
{required WebUri url,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
|
||||
List<Cookie> cookies = [];
|
||||
|
||||
if (webViewController != null) {
|
||||
final javaScriptEnabled =
|
||||
(await webViewController.getSettings())?.javaScriptEnabled ?? false;
|
||||
if (javaScriptEnabled) {
|
||||
List<String> documentCookies = (await webViewController
|
||||
.evaluateJavascript(source: 'document.cookie') as String)
|
||||
.split(';')
|
||||
.map((documentCookie) => documentCookie.trim())
|
||||
.toList();
|
||||
documentCookies.forEach((documentCookie) {
|
||||
List<String> cookie = documentCookie.split('=');
|
||||
if (cookie.length > 1) {
|
||||
cookies.add(Cookie(
|
||||
name: cookie[0],
|
||||
value: cookie[1],
|
||||
));
|
||||
}
|
||||
});
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
|
||||
final pageLoaded = Completer<void>();
|
||||
final headlessWebView =
|
||||
MacOSHeadlessInAppWebView(MacOSHeadlessInAppWebViewCreationParams(
|
||||
initialUrlRequest: URLRequest(url: url),
|
||||
onLoadStop: (controller, url) async {
|
||||
pageLoaded.complete();
|
||||
},
|
||||
));
|
||||
await headlessWebView.run();
|
||||
await pageLoaded.future;
|
||||
|
||||
List<String> documentCookies = (await headlessWebView.webViewController!
|
||||
.evaluateJavascript(source: 'document.cookie') as String)
|
||||
.split(';')
|
||||
.map((documentCookie) => documentCookie.trim())
|
||||
.toList();
|
||||
documentCookies.forEach((documentCookie) {
|
||||
List<String> cookie = documentCookie.split('=');
|
||||
if (cookie.length > 1) {
|
||||
cookies.add(Cookie(
|
||||
name: cookie[0],
|
||||
value: cookie[1],
|
||||
));
|
||||
}
|
||||
});
|
||||
await headlessWebView.dispose();
|
||||
return cookies;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Cookie?> getCookie(
|
||||
{required WebUri url,
|
||||
required String name,
|
||||
@Deprecated("Use webViewController instead")
|
||||
PlatformInAppWebViewController? iosBelow11WebViewController,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
assert(name.isNotEmpty);
|
||||
|
||||
webViewController = webViewController ?? iosBelow11WebViewController;
|
||||
|
||||
if (await _shouldUseJavascript()) {
|
||||
List<Cookie> cookies = await _getCookiesWithJavaScript(
|
||||
url: url, webViewController: webViewController);
|
||||
return cookies
|
||||
.cast<Cookie?>()
|
||||
.firstWhere((cookie) => cookie!.name == name, orElse: () => null);
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
List<dynamic> cookies =
|
||||
await channel?.invokeMethod<List>('getCookies', args) ?? [];
|
||||
cookies = cookies.cast<Map<dynamic, dynamic>>();
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
cookies[i] = cookies[i].cast<String, dynamic>();
|
||||
if (cookies[i]["name"] == name)
|
||||
return Cookie(
|
||||
name: cookies[i]["name"],
|
||||
value: cookies[i]["value"],
|
||||
expiresDate: cookies[i]["expiresDate"],
|
||||
isSessionOnly: cookies[i]["isSessionOnly"],
|
||||
domain: cookies[i]["domain"],
|
||||
sameSite: HTTPCookieSameSitePolicy.fromNativeValue(
|
||||
cookies[i]["sameSite"]),
|
||||
isSecure: cookies[i]["isSecure"],
|
||||
isHttpOnly: cookies[i]["isHttpOnly"],
|
||||
path: cookies[i]["path"]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteCookie(
|
||||
{required WebUri url,
|
||||
required String name,
|
||||
String path = "/",
|
||||
String? domain,
|
||||
@Deprecated("Use webViewController instead")
|
||||
PlatformInAppWebViewController? iosBelow11WebViewController,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
assert(name.isNotEmpty);
|
||||
|
||||
webViewController = webViewController ?? iosBelow11WebViewController;
|
||||
|
||||
if (await _shouldUseJavascript()) {
|
||||
await _setCookieWithJavaScript(
|
||||
url: url,
|
||||
name: name,
|
||||
value: "",
|
||||
path: path,
|
||||
domain: domain,
|
||||
maxAge: -1,
|
||||
webViewController: webViewController);
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
args.putIfAbsent('name', () => name);
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
return await channel?.invokeMethod<bool>('deleteCookie', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteCookies(
|
||||
{required WebUri url,
|
||||
String path = "/",
|
||||
String? domain,
|
||||
@Deprecated("Use webViewController instead")
|
||||
PlatformInAppWebViewController? iosBelow11WebViewController,
|
||||
PlatformInAppWebViewController? webViewController}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
|
||||
webViewController = webViewController ?? iosBelow11WebViewController;
|
||||
|
||||
if (await _shouldUseJavascript()) {
|
||||
List<Cookie> cookies = await _getCookiesWithJavaScript(
|
||||
url: url, webViewController: webViewController);
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
await _setCookieWithJavaScript(
|
||||
url: url,
|
||||
name: cookies[i].name,
|
||||
value: "",
|
||||
path: path,
|
||||
domain: domain,
|
||||
maxAge: -1,
|
||||
webViewController: webViewController);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
return await channel?.invokeMethod<bool>('deleteCookies', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteAllCookies() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await channel?.invokeMethod<bool>('deleteAllCookies', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Cookie>> getAllCookies() async {
|
||||
List<Cookie> cookies = [];
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
List<dynamic> cookieListMap =
|
||||
await channel?.invokeMethod<List>('getAllCookies', args) ?? [];
|
||||
cookieListMap = cookieListMap.cast<Map<dynamic, dynamic>>();
|
||||
|
||||
cookieListMap.forEach((cookieMap) {
|
||||
cookies.add(Cookie(
|
||||
name: cookieMap["name"],
|
||||
value: cookieMap["value"],
|
||||
expiresDate: cookieMap["expiresDate"],
|
||||
isSessionOnly: cookieMap["isSessionOnly"],
|
||||
domain: cookieMap["domain"],
|
||||
sameSite:
|
||||
HTTPCookieSameSitePolicy.fromNativeValue(cookieMap["sameSite"]),
|
||||
isSecure: cookieMap["isSecure"],
|
||||
isHttpOnly: cookieMap["isHttpOnly"],
|
||||
path: cookieMap["path"]));
|
||||
});
|
||||
return cookies;
|
||||
}
|
||||
|
||||
Future<String> _getCookieExpirationDate(int expiresDate) async {
|
||||
var platformUtil = PlatformUtil.instance();
|
||||
var dateTime = DateTime.fromMillisecondsSinceEpoch(expiresDate).toUtc();
|
||||
return !kIsWeb
|
||||
? await platformUtil.formatDate(
|
||||
date: dateTime,
|
||||
format: 'EEE, dd MMM yyyy hh:mm:ss z',
|
||||
locale: 'en_US',
|
||||
timezone: 'GMT')
|
||||
: await platformUtil.getWebCookieExpirationDate(date: dateTime);
|
||||
}
|
||||
|
||||
Future<bool> _shouldUseJavascript() async {
|
||||
final platformUtil = PlatformUtil.instance();
|
||||
final systemVersion = await platformUtil.getSystemVersion();
|
||||
return systemVersion.compareTo("11") == -1;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalCookieManager on MacOSCookieManager {
|
||||
get handleMethod => _handleMethod;
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSFindInteractionController].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformFindInteractionControllerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSFindInteractionControllerCreationParams
|
||||
extends PlatformFindInteractionControllerCreationParams {
|
||||
/// Creates a new [MacOSFindInteractionControllerCreationParams] instance.
|
||||
const MacOSFindInteractionControllerCreationParams(
|
||||
{super.onFindResultReceived});
|
||||
|
||||
/// Creates a [MacOSFindInteractionControllerCreationParams] instance based on [PlatformFindInteractionControllerCreationParams].
|
||||
factory MacOSFindInteractionControllerCreationParams.fromPlatformFindInteractionControllerCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformFindInteractionControllerCreationParams params) {
|
||||
return MacOSFindInteractionControllerCreationParams(
|
||||
onFindResultReceived: params.onFindResultReceived);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController}
|
||||
class MacOSFindInteractionController extends PlatformFindInteractionController
|
||||
with ChannelController {
|
||||
/// Constructs a [MacOSFindInteractionController].
|
||||
MacOSFindInteractionController(
|
||||
PlatformFindInteractionControllerCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSFindInteractionControllerCreationParams
|
||||
? params
|
||||
: MacOSFindInteractionControllerCreationParams
|
||||
.fromPlatformFindInteractionControllerCreationParams(params),
|
||||
);
|
||||
|
||||
_debugLog(String method, dynamic args) {
|
||||
debugLog(
|
||||
className: this.runtimeType.toString(),
|
||||
debugLoggingSettings:
|
||||
PlatformFindInteractionController.debugLoggingSettings,
|
||||
method: method,
|
||||
args: args);
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
_debugLog(call.method, call.arguments);
|
||||
|
||||
switch (call.method) {
|
||||
case "onFindResultReceived":
|
||||
if (onFindResultReceived != null) {
|
||||
int activeMatchOrdinal = call.arguments["activeMatchOrdinal"];
|
||||
int numberOfMatches = call.arguments["numberOfMatches"];
|
||||
bool isDoneCounting = call.arguments["isDoneCounting"];
|
||||
onFindResultReceived!(
|
||||
this, activeMatchOrdinal, numberOfMatches, isDoneCounting);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.findAll}
|
||||
Future<void> findAll({String? find}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('find', () => find);
|
||||
await channel?.invokeMethod('findAll', args);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.findNext}
|
||||
Future<void> findNext({bool forward = true}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('forward', () => forward);
|
||||
await channel?.invokeMethod('findNext', args);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.clearMatches}
|
||||
Future<void> clearMatches() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('clearMatches', args);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.setSearchText}
|
||||
Future<void> setSearchText(String? searchText) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('searchText', () => searchText);
|
||||
await channel?.invokeMethod('setSearchText', args);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.getSearchText}
|
||||
Future<String?> getSearchText() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await channel?.invokeMethod<String?>('getSearchText', args);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.getActiveFindSession}
|
||||
Future<FindSession?> getActiveFindSession() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
Map<String, dynamic>? result =
|
||||
(await channel?.invokeMethod('getActiveFindSession', args))
|
||||
?.cast<String, dynamic>();
|
||||
return FindSession.fromMap(result);
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.dispose}
|
||||
@override
|
||||
void dispose({bool isKeepAlive = false}) {
|
||||
disposeChannel(removeMethodCallHandler: !isKeepAlive);
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalFindInteractionController on MacOSFindInteractionController {
|
||||
void init(dynamic id) {
|
||||
channel = MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_find_interaction_$id');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export 'find_interaction_controller.dart'
|
||||
hide InternalFindInteractionController;
|
||||
Vendored
Executable
+155
@@ -0,0 +1,155 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSHttpAuthCredentialDatabase].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformHttpAuthCredentialDatabaseCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSHttpAuthCredentialDatabaseCreationParams
|
||||
extends PlatformHttpAuthCredentialDatabaseCreationParams {
|
||||
/// Creates a new [MacOSHttpAuthCredentialDatabaseCreationParams] instance.
|
||||
const MacOSHttpAuthCredentialDatabaseCreationParams(
|
||||
// This parameter prevents breaking changes later.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformHttpAuthCredentialDatabaseCreationParams params,
|
||||
) : super();
|
||||
|
||||
/// Creates a [MacOSHttpAuthCredentialDatabaseCreationParams] instance based on [PlatformHttpAuthCredentialDatabaseCreationParams].
|
||||
factory MacOSHttpAuthCredentialDatabaseCreationParams.fromPlatformHttpAuthCredentialDatabaseCreationParams(
|
||||
PlatformHttpAuthCredentialDatabaseCreationParams params) {
|
||||
return MacOSHttpAuthCredentialDatabaseCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformHttpAuthCredentialDatabase}
|
||||
class MacOSHttpAuthCredentialDatabase extends PlatformHttpAuthCredentialDatabase
|
||||
with ChannelController {
|
||||
/// Creates a new [MacOSHttpAuthCredentialDatabase].
|
||||
MacOSHttpAuthCredentialDatabase(
|
||||
PlatformHttpAuthCredentialDatabaseCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSHttpAuthCredentialDatabaseCreationParams
|
||||
? params
|
||||
: MacOSHttpAuthCredentialDatabaseCreationParams
|
||||
.fromPlatformHttpAuthCredentialDatabaseCreationParams(params),
|
||||
) {
|
||||
channel = const MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_credential_database');
|
||||
handler = handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
static MacOSHttpAuthCredentialDatabase? _instance;
|
||||
|
||||
///Gets the database shared instance.
|
||||
static MacOSHttpAuthCredentialDatabase instance() {
|
||||
return (_instance != null) ? _instance! : _init();
|
||||
}
|
||||
|
||||
static MacOSHttpAuthCredentialDatabase _init() {
|
||||
_instance = MacOSHttpAuthCredentialDatabase(
|
||||
MacOSHttpAuthCredentialDatabaseCreationParams(
|
||||
const PlatformHttpAuthCredentialDatabaseCreationParams()));
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {}
|
||||
|
||||
@override
|
||||
Future<List<URLProtectionSpaceHttpAuthCredentials>>
|
||||
getAllAuthCredentials() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
List<dynamic> allCredentials =
|
||||
await channel?.invokeMethod<List>('getAllAuthCredentials', args) ?? [];
|
||||
|
||||
List<URLProtectionSpaceHttpAuthCredentials> result = [];
|
||||
|
||||
for (Map<dynamic, dynamic> map in allCredentials) {
|
||||
var element = URLProtectionSpaceHttpAuthCredentials.fromMap(
|
||||
map.cast<String, dynamic>());
|
||||
if (element != null) {
|
||||
result.add(element);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<URLCredential>> getHttpAuthCredentials(
|
||||
{required URLProtectionSpace protectionSpace}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("host", () => protectionSpace.host);
|
||||
args.putIfAbsent("protocol", () => protectionSpace.protocol);
|
||||
args.putIfAbsent("realm", () => protectionSpace.realm);
|
||||
args.putIfAbsent("port", () => protectionSpace.port);
|
||||
List<dynamic> credentialList =
|
||||
await channel?.invokeMethod<List>('getHttpAuthCredentials', args) ?? [];
|
||||
List<URLCredential> credentials = [];
|
||||
for (Map<dynamic, dynamic> map in credentialList) {
|
||||
var credential = URLCredential.fromMap(map.cast<String, dynamic>());
|
||||
if (credential != null) {
|
||||
credentials.add(credential);
|
||||
}
|
||||
}
|
||||
return credentials;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setHttpAuthCredential(
|
||||
{required URLProtectionSpace protectionSpace,
|
||||
required URLCredential credential}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("host", () => protectionSpace.host);
|
||||
args.putIfAbsent("protocol", () => protectionSpace.protocol);
|
||||
args.putIfAbsent("realm", () => protectionSpace.realm);
|
||||
args.putIfAbsent("port", () => protectionSpace.port);
|
||||
args.putIfAbsent("username", () => credential.username);
|
||||
args.putIfAbsent("password", () => credential.password);
|
||||
await channel?.invokeMethod('setHttpAuthCredential', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeHttpAuthCredential(
|
||||
{required URLProtectionSpace protectionSpace,
|
||||
required URLCredential credential}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("host", () => protectionSpace.host);
|
||||
args.putIfAbsent("protocol", () => protectionSpace.protocol);
|
||||
args.putIfAbsent("realm", () => protectionSpace.realm);
|
||||
args.putIfAbsent("port", () => protectionSpace.port);
|
||||
args.putIfAbsent("username", () => credential.username);
|
||||
args.putIfAbsent("password", () => credential.password);
|
||||
await channel?.invokeMethod('removeHttpAuthCredential', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeHttpAuthCredentials(
|
||||
{required URLProtectionSpace protectionSpace}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("host", () => protectionSpace.host);
|
||||
args.putIfAbsent("protocol", () => protectionSpace.protocol);
|
||||
args.putIfAbsent("realm", () => protectionSpace.realm);
|
||||
args.putIfAbsent("port", () => protectionSpace.port);
|
||||
await channel?.invokeMethod('removeHttpAuthCredentials', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearAllAuthCredentials() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('clearAllAuthCredentials', args);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalHttpAuthCredentialDatabase
|
||||
on MacOSHttpAuthCredentialDatabase {
|
||||
get handleMethod => _handleMethod;
|
||||
}
|
||||
Vendored
Executable
+373
@@ -0,0 +1,373 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
import '../find_interaction/find_interaction_controller.dart';
|
||||
import '../in_app_webview/in_app_webview_controller.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSInAppBrowser].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformInAppBrowserCreationParams] for
|
||||
/// more information.
|
||||
class MacOSInAppBrowserCreationParams
|
||||
extends PlatformInAppBrowserCreationParams {
|
||||
/// Creates a new [MacOSInAppBrowserCreationParams] instance.
|
||||
MacOSInAppBrowserCreationParams(
|
||||
{super.contextMenu,
|
||||
super.pullToRefreshController,
|
||||
this.findInteractionController,
|
||||
super.initialUserScripts,
|
||||
super.windowId});
|
||||
|
||||
/// Creates a [MacOSInAppBrowserCreationParams] instance based on [PlatformInAppBrowserCreationParams].
|
||||
factory MacOSInAppBrowserCreationParams.fromPlatformInAppBrowserCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformInAppBrowserCreationParams params) {
|
||||
return MacOSInAppBrowserCreationParams(
|
||||
contextMenu: params.contextMenu,
|
||||
pullToRefreshController: params.pullToRefreshController,
|
||||
findInteractionController:
|
||||
params.findInteractionController as MacOSFindInteractionController?,
|
||||
initialUserScripts: params.initialUserScripts,
|
||||
windowId: params.windowId);
|
||||
}
|
||||
|
||||
@override
|
||||
final MacOSFindInteractionController? findInteractionController;
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser}
|
||||
class MacOSInAppBrowser extends PlatformInAppBrowser with ChannelController {
|
||||
@override
|
||||
final String id = IdGenerator.generate();
|
||||
|
||||
/// Constructs a [MacOSInAppBrowser].
|
||||
MacOSInAppBrowser(PlatformInAppBrowserCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSInAppBrowserCreationParams
|
||||
? params
|
||||
: MacOSInAppBrowserCreationParams
|
||||
.fromPlatformInAppBrowserCreationParams(params),
|
||||
) {
|
||||
_contextMenu = params.contextMenu;
|
||||
}
|
||||
|
||||
static final MacOSInAppBrowser _staticValue =
|
||||
MacOSInAppBrowser(MacOSInAppBrowserCreationParams());
|
||||
|
||||
/// Provide static access.
|
||||
factory MacOSInAppBrowser.static() {
|
||||
return _staticValue;
|
||||
}
|
||||
|
||||
MacOSInAppBrowserCreationParams get _macosParams =>
|
||||
params as MacOSInAppBrowserCreationParams;
|
||||
|
||||
static const MethodChannel _staticChannel =
|
||||
const MethodChannel('com.pichillilorenzo/flutter_inappbrowser');
|
||||
|
||||
ContextMenu? _contextMenu;
|
||||
|
||||
@override
|
||||
ContextMenu? get contextMenu => _contextMenu;
|
||||
|
||||
Map<int, InAppBrowserMenuItem> _menuItems = HashMap();
|
||||
bool _isOpened = false;
|
||||
MacOSInAppWebViewController? _webViewController;
|
||||
|
||||
@override
|
||||
MacOSInAppWebViewController? get webViewController {
|
||||
return _isOpened ? _webViewController : null;
|
||||
}
|
||||
|
||||
_init() {
|
||||
channel = MethodChannel('com.pichillilorenzo/flutter_inappbrowser_$id');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
|
||||
_webViewController = MacOSInAppWebViewController.fromInAppBrowser(
|
||||
MacOSInAppWebViewControllerCreationParams(id: id),
|
||||
channel!,
|
||||
this,
|
||||
this.initialUserScripts);
|
||||
_macosParams.findInteractionController?.init(id);
|
||||
}
|
||||
|
||||
_debugLog(String method, dynamic args) {
|
||||
debugLog(
|
||||
className: this.runtimeType.toString(),
|
||||
id: id,
|
||||
debugLoggingSettings: PlatformInAppBrowser.debugLoggingSettings,
|
||||
method: method,
|
||||
args: args);
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case "onBrowserCreated":
|
||||
_debugLog(call.method, call.arguments);
|
||||
eventHandler?.onBrowserCreated();
|
||||
break;
|
||||
case "onMenuItemClicked":
|
||||
_debugLog(call.method, call.arguments);
|
||||
int id = call.arguments["id"].toInt();
|
||||
if (this._menuItems[id] != null) {
|
||||
if (this._menuItems[id]?.onClick != null) {
|
||||
this._menuItems[id]?.onClick!();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "onMainWindowWillClose":
|
||||
_debugLog(call.method, call.arguments);
|
||||
eventHandler?.onMainWindowWillClose();
|
||||
break;
|
||||
case "onExit":
|
||||
_debugLog(call.method, call.arguments);
|
||||
_isOpened = false;
|
||||
final onExit = eventHandler?.onExit;
|
||||
dispose();
|
||||
onExit?.call();
|
||||
break;
|
||||
default:
|
||||
return _webViewController?.handleMethod(call);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> _prepareOpenRequest(
|
||||
{@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
|
||||
InAppBrowserClassSettings? settings}) {
|
||||
assert(!_isOpened, 'The browser is already opened.');
|
||||
_isOpened = true;
|
||||
_init();
|
||||
|
||||
var initialSettings = settings?.toMap() ??
|
||||
options?.toMap() ??
|
||||
InAppBrowserClassSettings().toMap();
|
||||
|
||||
Map<String, dynamic> pullToRefreshSettings =
|
||||
pullToRefreshController?.settings.toMap() ??
|
||||
pullToRefreshController?.options.toMap() ??
|
||||
PullToRefreshSettings(enabled: false).toMap();
|
||||
|
||||
List<Map<String, dynamic>> menuItemList = [];
|
||||
_menuItems.forEach((key, value) {
|
||||
menuItemList.add(value.toMap());
|
||||
});
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('id', () => id);
|
||||
args.putIfAbsent('settings', () => initialSettings);
|
||||
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
|
||||
args.putIfAbsent('windowId', () => windowId);
|
||||
args.putIfAbsent('initialUserScripts',
|
||||
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
|
||||
args.putIfAbsent('pullToRefreshSettings', () => pullToRefreshSettings);
|
||||
args.putIfAbsent('menuItems', () => menuItemList);
|
||||
return args;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openUrlRequest(
|
||||
{required URLRequest urlRequest,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
|
||||
InAppBrowserClassSettings? settings}) async {
|
||||
assert(urlRequest.url != null && urlRequest.url.toString().isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args =
|
||||
_prepareOpenRequest(options: options, settings: settings);
|
||||
args.putIfAbsent('urlRequest', () => urlRequest.toMap());
|
||||
await _staticChannel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openFile(
|
||||
{required String assetFilePath,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
|
||||
InAppBrowserClassSettings? settings}) async {
|
||||
assert(assetFilePath.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args =
|
||||
_prepareOpenRequest(options: options, settings: settings);
|
||||
args.putIfAbsent('assetFilePath', () => assetFilePath);
|
||||
await _staticChannel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openData(
|
||||
{required String data,
|
||||
String mimeType = "text/html",
|
||||
String encoding = "utf8",
|
||||
WebUri? baseUrl,
|
||||
@Deprecated("Use historyUrl instead") Uri? androidHistoryUrl,
|
||||
WebUri? historyUrl,
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
|
||||
InAppBrowserClassSettings? settings}) async {
|
||||
Map<String, dynamic> args =
|
||||
_prepareOpenRequest(options: options, settings: settings);
|
||||
args.putIfAbsent('data', () => data);
|
||||
args.putIfAbsent('mimeType', () => mimeType);
|
||||
args.putIfAbsent('encoding', () => encoding);
|
||||
args.putIfAbsent('baseUrl', () => baseUrl?.toString() ?? "about:blank");
|
||||
args.putIfAbsent('historyUrl',
|
||||
() => (historyUrl ?? androidHistoryUrl)?.toString() ?? "about:blank");
|
||||
await _staticChannel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> openWithSystemBrowser({required WebUri url}) async {
|
||||
assert(url.toString().isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url.toString());
|
||||
return await _staticChannel.invokeMethod('openWithSystemBrowser', args);
|
||||
}
|
||||
|
||||
@override
|
||||
void addMenuItem(InAppBrowserMenuItem menuItem) {
|
||||
_menuItems[menuItem.id] = menuItem;
|
||||
}
|
||||
|
||||
@override
|
||||
void addMenuItems(List<InAppBrowserMenuItem> menuItems) {
|
||||
menuItems.forEach((menuItem) {
|
||||
_menuItems[menuItem.id] = menuItem;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
bool removeMenuItem(InAppBrowserMenuItem menuItem) {
|
||||
return _menuItems.remove(menuItem.id) != null;
|
||||
}
|
||||
|
||||
@override
|
||||
void removeMenuItems(List<InAppBrowserMenuItem> menuItems) {
|
||||
for (final menuItem in menuItems) {
|
||||
removeMenuItem(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void removeAllMenuItem() {
|
||||
_menuItems.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
bool hasMenuItem(InAppBrowserMenuItem menuItem) {
|
||||
return _menuItems.containsKey(menuItem.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> show() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('show', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> hide() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('hide', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('close', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isHidden() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await channel?.invokeMethod<bool>('isHidden', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
@Deprecated('Use setSettings instead')
|
||||
Future<void> setOptions({required InAppBrowserClassOptions options}) async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('settings', () => options.toMap());
|
||||
await channel?.invokeMethod('setSettings', args);
|
||||
}
|
||||
|
||||
@override
|
||||
@Deprecated('Use getSettings instead')
|
||||
Future<InAppBrowserClassOptions?> getOptions() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
|
||||
Map<dynamic, dynamic>? options =
|
||||
await channel?.invokeMethod('getSettings', args);
|
||||
if (options != null) {
|
||||
options = options.cast<String, dynamic>();
|
||||
return InAppBrowserClassOptions.fromMap(options as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setSettings(
|
||||
{required InAppBrowserClassSettings settings}) async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('settings', () => settings.toMap());
|
||||
await channel?.invokeMethod('setSettings', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<InAppBrowserClassSettings?> getSettings() async {
|
||||
assert(_isOpened, 'The browser is not opened.');
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
|
||||
Map<dynamic, dynamic>? settings =
|
||||
await channel?.invokeMethod('getSettings', args);
|
||||
if (settings != null) {
|
||||
settings = settings.cast<String, dynamic>();
|
||||
return InAppBrowserClassSettings.fromMap(
|
||||
settings as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isOpened() {
|
||||
return this._isOpened;
|
||||
}
|
||||
|
||||
@override
|
||||
@mustCallSuper
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
disposeChannel();
|
||||
_webViewController?.dispose();
|
||||
_webViewController = null;
|
||||
pullToRefreshController?.dispose();
|
||||
findInteractionController?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalInAppBrowser on MacOSInAppBrowser {
|
||||
void setContextMenu(ContextMenu? contextMenu) {
|
||||
_contextMenu = contextMenu;
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export 'in_app_browser.dart' hide InternalInAppBrowser;
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
const IN_APP_WEBVIEW_STATIC_CHANNEL =
|
||||
MethodChannel('com.pichillilorenzo/flutter_inappwebview_manager');
|
||||
+433
@@ -0,0 +1,433 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
import '../find_interaction/find_interaction_controller.dart';
|
||||
import 'in_app_webview_controller.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSHeadlessInAppWebView].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformHeadlessInAppWebViewCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSHeadlessInAppWebViewCreationParams
|
||||
extends PlatformHeadlessInAppWebViewCreationParams {
|
||||
/// Creates a new [MacOSHeadlessInAppWebViewCreationParams] instance.
|
||||
MacOSHeadlessInAppWebViewCreationParams(
|
||||
{super.controllerFromPlatform,
|
||||
super.initialSize,
|
||||
super.windowId,
|
||||
super.onWebViewCreated,
|
||||
super.onLoadStart,
|
||||
super.onLoadStop,
|
||||
@Deprecated('Use onReceivedError instead') super.onLoadError,
|
||||
super.onReceivedError,
|
||||
@Deprecated("Use onReceivedHttpError instead") super.onLoadHttpError,
|
||||
super.onReceivedHttpError,
|
||||
super.onProgressChanged,
|
||||
super.onConsoleMessage,
|
||||
super.shouldOverrideUrlLoading,
|
||||
super.onLoadResource,
|
||||
super.onScrollChanged,
|
||||
@Deprecated('Use onDownloadStartRequest instead') super.onDownloadStart,
|
||||
super.onDownloadStartRequest,
|
||||
@Deprecated('Use onLoadResourceWithCustomScheme instead')
|
||||
super.onLoadResourceCustomScheme,
|
||||
super.onLoadResourceWithCustomScheme,
|
||||
super.onCreateWindow,
|
||||
super.onCloseWindow,
|
||||
super.onJsAlert,
|
||||
super.onJsConfirm,
|
||||
super.onJsPrompt,
|
||||
super.onReceivedHttpAuthRequest,
|
||||
super.onReceivedServerTrustAuthRequest,
|
||||
super.onReceivedClientCertRequest,
|
||||
@Deprecated('Use FindInteractionController.onFindResultReceived instead')
|
||||
super.onFindResultReceived,
|
||||
super.shouldInterceptAjaxRequest,
|
||||
super.onAjaxReadyStateChange,
|
||||
super.onAjaxProgress,
|
||||
super.shouldInterceptFetchRequest,
|
||||
super.onUpdateVisitedHistory,
|
||||
@Deprecated("Use onPrintRequest instead") super.onPrint,
|
||||
super.onPrintRequest,
|
||||
super.onLongPressHitTestResult,
|
||||
super.onEnterFullscreen,
|
||||
super.onExitFullscreen,
|
||||
super.onPageCommitVisible,
|
||||
super.onTitleChanged,
|
||||
super.onWindowFocus,
|
||||
super.onWindowBlur,
|
||||
super.onOverScrolled,
|
||||
super.onZoomScaleChanged,
|
||||
@Deprecated('Use onSafeBrowsingHit instead')
|
||||
super.androidOnSafeBrowsingHit,
|
||||
super.onSafeBrowsingHit,
|
||||
@Deprecated('Use onPermissionRequest instead')
|
||||
super.androidOnPermissionRequest,
|
||||
super.onPermissionRequest,
|
||||
@Deprecated('Use onGeolocationPermissionsShowPrompt instead')
|
||||
super.androidOnGeolocationPermissionsShowPrompt,
|
||||
super.onGeolocationPermissionsShowPrompt,
|
||||
@Deprecated('Use onGeolocationPermissionsHidePrompt instead')
|
||||
super.androidOnGeolocationPermissionsHidePrompt,
|
||||
super.onGeolocationPermissionsHidePrompt,
|
||||
@Deprecated('Use shouldInterceptRequest instead')
|
||||
super.androidShouldInterceptRequest,
|
||||
super.shouldInterceptRequest,
|
||||
@Deprecated('Use onRenderProcessGone instead')
|
||||
super.androidOnRenderProcessGone,
|
||||
super.onRenderProcessGone,
|
||||
@Deprecated('Use onRenderProcessResponsive instead')
|
||||
super.androidOnRenderProcessResponsive,
|
||||
super.onRenderProcessResponsive,
|
||||
@Deprecated('Use onRenderProcessUnresponsive instead')
|
||||
super.androidOnRenderProcessUnresponsive,
|
||||
super.onRenderProcessUnresponsive,
|
||||
@Deprecated('Use onFormResubmission instead')
|
||||
super.androidOnFormResubmission,
|
||||
super.onFormResubmission,
|
||||
@Deprecated('Use onZoomScaleChanged instead') super.androidOnScaleChanged,
|
||||
@Deprecated('Use onReceivedIcon instead') super.androidOnReceivedIcon,
|
||||
super.onReceivedIcon,
|
||||
@Deprecated('Use onReceivedTouchIconUrl instead')
|
||||
super.androidOnReceivedTouchIconUrl,
|
||||
super.onReceivedTouchIconUrl,
|
||||
@Deprecated('Use onJsBeforeUnload instead') super.androidOnJsBeforeUnload,
|
||||
super.onJsBeforeUnload,
|
||||
@Deprecated('Use onReceivedLoginRequest instead')
|
||||
super.androidOnReceivedLoginRequest,
|
||||
super.onReceivedLoginRequest,
|
||||
super.onPermissionRequestCanceled,
|
||||
super.onRequestFocus,
|
||||
@Deprecated('Use onWebContentProcessDidTerminate instead')
|
||||
super.iosOnWebContentProcessDidTerminate,
|
||||
super.onWebContentProcessDidTerminate,
|
||||
@Deprecated(
|
||||
'Use onDidReceiveServerRedirectForProvisionalNavigation instead')
|
||||
super.iosOnDidReceiveServerRedirectForProvisionalNavigation,
|
||||
super.onDidReceiveServerRedirectForProvisionalNavigation,
|
||||
@Deprecated('Use onNavigationResponse instead')
|
||||
super.iosOnNavigationResponse,
|
||||
super.onNavigationResponse,
|
||||
@Deprecated('Use shouldAllowDeprecatedTLS instead')
|
||||
super.iosShouldAllowDeprecatedTLS,
|
||||
super.shouldAllowDeprecatedTLS,
|
||||
super.onCameraCaptureStateChanged,
|
||||
super.onMicrophoneCaptureStateChanged,
|
||||
super.onContentSizeChanged,
|
||||
super.initialUrlRequest,
|
||||
super.initialFile,
|
||||
super.initialData,
|
||||
@Deprecated('Use initialSettings instead') super.initialOptions,
|
||||
super.initialSettings,
|
||||
super.contextMenu,
|
||||
super.initialUserScripts,
|
||||
super.pullToRefreshController,
|
||||
this.findInteractionController});
|
||||
|
||||
/// Creates a [MacOSHeadlessInAppWebViewCreationParams] instance based on [PlatformHeadlessInAppWebViewCreationParams].
|
||||
MacOSHeadlessInAppWebViewCreationParams.fromPlatformHeadlessInAppWebViewCreationParams(
|
||||
PlatformHeadlessInAppWebViewCreationParams params)
|
||||
: this(
|
||||
controllerFromPlatform: params.controllerFromPlatform,
|
||||
initialSize: params.initialSize,
|
||||
windowId: params.windowId,
|
||||
onWebViewCreated: params.onWebViewCreated,
|
||||
onLoadStart: params.onLoadStart,
|
||||
onLoadStop: params.onLoadStop,
|
||||
onLoadError: params.onLoadError,
|
||||
onReceivedError: params.onReceivedError,
|
||||
onLoadHttpError: params.onLoadHttpError,
|
||||
onReceivedHttpError: params.onReceivedHttpError,
|
||||
onProgressChanged: params.onProgressChanged,
|
||||
onConsoleMessage: params.onConsoleMessage,
|
||||
shouldOverrideUrlLoading: params.shouldOverrideUrlLoading,
|
||||
onLoadResource: params.onLoadResource,
|
||||
onScrollChanged: params.onScrollChanged,
|
||||
onDownloadStart: params.onDownloadStart,
|
||||
onDownloadStartRequest: params.onDownloadStartRequest,
|
||||
onLoadResourceCustomScheme: params.onLoadResourceCustomScheme,
|
||||
onLoadResourceWithCustomScheme:
|
||||
params.onLoadResourceWithCustomScheme,
|
||||
onCreateWindow: params.onCreateWindow,
|
||||
onCloseWindow: params.onCloseWindow,
|
||||
onJsAlert: params.onJsAlert,
|
||||
onJsConfirm: params.onJsConfirm,
|
||||
onJsPrompt: params.onJsPrompt,
|
||||
onReceivedHttpAuthRequest: params.onReceivedHttpAuthRequest,
|
||||
onReceivedServerTrustAuthRequest:
|
||||
params.onReceivedServerTrustAuthRequest,
|
||||
onReceivedClientCertRequest: params.onReceivedClientCertRequest,
|
||||
onFindResultReceived: params.onFindResultReceived,
|
||||
shouldInterceptAjaxRequest: params.shouldInterceptAjaxRequest,
|
||||
onAjaxReadyStateChange: params.onAjaxReadyStateChange,
|
||||
onAjaxProgress: params.onAjaxProgress,
|
||||
shouldInterceptFetchRequest: params.shouldInterceptFetchRequest,
|
||||
onUpdateVisitedHistory: params.onUpdateVisitedHistory,
|
||||
onPrint: params.onPrint,
|
||||
onPrintRequest: params.onPrintRequest,
|
||||
onLongPressHitTestResult: params.onLongPressHitTestResult,
|
||||
onEnterFullscreen: params.onEnterFullscreen,
|
||||
onExitFullscreen: params.onExitFullscreen,
|
||||
onPageCommitVisible: params.onPageCommitVisible,
|
||||
onTitleChanged: params.onTitleChanged,
|
||||
onWindowFocus: params.onWindowFocus,
|
||||
onWindowBlur: params.onWindowBlur,
|
||||
onOverScrolled: params.onOverScrolled,
|
||||
onZoomScaleChanged: params.onZoomScaleChanged,
|
||||
androidOnSafeBrowsingHit: params.androidOnSafeBrowsingHit,
|
||||
onSafeBrowsingHit: params.onSafeBrowsingHit,
|
||||
androidOnPermissionRequest: params.androidOnPermissionRequest,
|
||||
onPermissionRequest: params.onPermissionRequest,
|
||||
androidOnGeolocationPermissionsShowPrompt:
|
||||
params.androidOnGeolocationPermissionsShowPrompt,
|
||||
onGeolocationPermissionsShowPrompt:
|
||||
params.onGeolocationPermissionsShowPrompt,
|
||||
androidOnGeolocationPermissionsHidePrompt:
|
||||
params.androidOnGeolocationPermissionsHidePrompt,
|
||||
onGeolocationPermissionsHidePrompt:
|
||||
params.onGeolocationPermissionsHidePrompt,
|
||||
androidShouldInterceptRequest: params.androidShouldInterceptRequest,
|
||||
shouldInterceptRequest: params.shouldInterceptRequest,
|
||||
androidOnRenderProcessGone: params.androidOnRenderProcessGone,
|
||||
onRenderProcessGone: params.onRenderProcessGone,
|
||||
androidOnRenderProcessResponsive:
|
||||
params.androidOnRenderProcessResponsive,
|
||||
onRenderProcessResponsive: params.onRenderProcessResponsive,
|
||||
androidOnRenderProcessUnresponsive:
|
||||
params.androidOnRenderProcessUnresponsive,
|
||||
onRenderProcessUnresponsive: params.onRenderProcessUnresponsive,
|
||||
androidOnFormResubmission: params.androidOnFormResubmission,
|
||||
onFormResubmission: params.onFormResubmission,
|
||||
androidOnScaleChanged: params.androidOnScaleChanged,
|
||||
androidOnReceivedIcon: params.androidOnReceivedIcon,
|
||||
onReceivedIcon: params.onReceivedIcon,
|
||||
androidOnReceivedTouchIconUrl: params.androidOnReceivedTouchIconUrl,
|
||||
onReceivedTouchIconUrl: params.onReceivedTouchIconUrl,
|
||||
androidOnJsBeforeUnload: params.androidOnJsBeforeUnload,
|
||||
onJsBeforeUnload: params.onJsBeforeUnload,
|
||||
androidOnReceivedLoginRequest: params.androidOnReceivedLoginRequest,
|
||||
onReceivedLoginRequest: params.onReceivedLoginRequest,
|
||||
onPermissionRequestCanceled: params.onPermissionRequestCanceled,
|
||||
onRequestFocus: params.onRequestFocus,
|
||||
iosOnWebContentProcessDidTerminate:
|
||||
params.iosOnWebContentProcessDidTerminate,
|
||||
onWebContentProcessDidTerminate:
|
||||
params.onWebContentProcessDidTerminate,
|
||||
iosOnDidReceiveServerRedirectForProvisionalNavigation:
|
||||
params.iosOnDidReceiveServerRedirectForProvisionalNavigation,
|
||||
onDidReceiveServerRedirectForProvisionalNavigation:
|
||||
params.onDidReceiveServerRedirectForProvisionalNavigation,
|
||||
iosOnNavigationResponse: params.iosOnNavigationResponse,
|
||||
onNavigationResponse: params.onNavigationResponse,
|
||||
iosShouldAllowDeprecatedTLS: params.iosShouldAllowDeprecatedTLS,
|
||||
shouldAllowDeprecatedTLS: params.shouldAllowDeprecatedTLS,
|
||||
onCameraCaptureStateChanged: params.onCameraCaptureStateChanged,
|
||||
onMicrophoneCaptureStateChanged:
|
||||
params.onMicrophoneCaptureStateChanged,
|
||||
onContentSizeChanged: params.onContentSizeChanged,
|
||||
initialUrlRequest: params.initialUrlRequest,
|
||||
initialFile: params.initialFile,
|
||||
initialData: params.initialData,
|
||||
initialOptions: params.initialOptions,
|
||||
initialSettings: params.initialSettings,
|
||||
contextMenu: params.contextMenu,
|
||||
initialUserScripts: params.initialUserScripts,
|
||||
pullToRefreshController: params.pullToRefreshController,
|
||||
findInteractionController: params.findInteractionController
|
||||
as MacOSFindInteractionController?);
|
||||
|
||||
@override
|
||||
final MacOSFindInteractionController? findInteractionController;
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformHeadlessInAppWebView}
|
||||
class MacOSHeadlessInAppWebView extends PlatformHeadlessInAppWebView
|
||||
with ChannelController {
|
||||
@override
|
||||
late final String id;
|
||||
|
||||
bool _started = false;
|
||||
bool _running = false;
|
||||
|
||||
static const MethodChannel _sharedChannel =
|
||||
const MethodChannel('com.pichillilorenzo/flutter_headless_inappwebview');
|
||||
|
||||
MacOSInAppWebViewController? _webViewController;
|
||||
|
||||
/// Constructs a [MacOSHeadlessInAppWebView].
|
||||
MacOSHeadlessInAppWebView(PlatformHeadlessInAppWebViewCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSHeadlessInAppWebViewCreationParams
|
||||
? params
|
||||
: MacOSHeadlessInAppWebViewCreationParams
|
||||
.fromPlatformHeadlessInAppWebViewCreationParams(params),
|
||||
) {
|
||||
id = IdGenerator.generate();
|
||||
}
|
||||
|
||||
@override
|
||||
MacOSInAppWebViewController? get webViewController => _webViewController;
|
||||
|
||||
dynamic _controllerFromPlatform;
|
||||
|
||||
MacOSHeadlessInAppWebViewCreationParams get _macosParams =>
|
||||
params as MacOSHeadlessInAppWebViewCreationParams;
|
||||
|
||||
_init() {
|
||||
_webViewController = MacOSInAppWebViewController(
|
||||
MacOSInAppWebViewControllerCreationParams(id: id, webviewParams: params),
|
||||
);
|
||||
_controllerFromPlatform =
|
||||
params.controllerFromPlatform?.call(_webViewController!) ??
|
||||
_webViewController!;
|
||||
_macosParams.findInteractionController?.init(id);
|
||||
channel =
|
||||
MethodChannel('com.pichillilorenzo/flutter_headless_inappwebview_$id');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case "onWebViewCreated":
|
||||
if (params.onWebViewCreated != null && _webViewController != null) {
|
||||
params.onWebViewCreated!(_controllerFromPlatform);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> run() async {
|
||||
if (_started) {
|
||||
return;
|
||||
}
|
||||
_started = true;
|
||||
_init();
|
||||
|
||||
final initialSettings = params.initialSettings ?? InAppWebViewSettings();
|
||||
_inferInitialSettings(initialSettings);
|
||||
|
||||
Map<String, dynamic> settingsMap =
|
||||
(params.initialSettings != null ? initialSettings.toMap() : null) ??
|
||||
params.initialOptions?.toMap() ??
|
||||
initialSettings.toMap();
|
||||
|
||||
Map<String, dynamic> pullToRefreshSettings =
|
||||
_macosParams.pullToRefreshController?.params.settings.toMap() ??
|
||||
_macosParams.pullToRefreshController?.params.options.toMap() ??
|
||||
PullToRefreshSettings(enabled: false).toMap();
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('id', () => id);
|
||||
args.putIfAbsent(
|
||||
'params',
|
||||
() => <String, dynamic>{
|
||||
'initialUrlRequest': params.initialUrlRequest?.toMap(),
|
||||
'initialFile': params.initialFile,
|
||||
'initialData': params.initialData?.toMap(),
|
||||
'initialSettings': settingsMap,
|
||||
'contextMenu': params.contextMenu?.toMap() ?? {},
|
||||
'windowId': params.windowId,
|
||||
'initialUserScripts':
|
||||
params.initialUserScripts?.map((e) => e.toMap()).toList() ??
|
||||
[],
|
||||
'pullToRefreshSettings': pullToRefreshSettings,
|
||||
'initialSize': params.initialSize.toMap()
|
||||
});
|
||||
await _sharedChannel.invokeMethod('run', args);
|
||||
_running = true;
|
||||
}
|
||||
|
||||
void _inferInitialSettings(InAppWebViewSettings settings) {
|
||||
if (params.shouldOverrideUrlLoading != null &&
|
||||
settings.useShouldOverrideUrlLoading == null) {
|
||||
settings.useShouldOverrideUrlLoading = true;
|
||||
}
|
||||
if (params.onLoadResource != null && settings.useOnLoadResource == null) {
|
||||
settings.useOnLoadResource = true;
|
||||
}
|
||||
if (params.onDownloadStartRequest != null &&
|
||||
settings.useOnDownloadStart == null) {
|
||||
settings.useOnDownloadStart = true;
|
||||
}
|
||||
if (params.shouldInterceptAjaxRequest != null &&
|
||||
settings.useShouldInterceptAjaxRequest == null) {
|
||||
settings.useShouldInterceptAjaxRequest = true;
|
||||
}
|
||||
if (params.shouldInterceptFetchRequest != null &&
|
||||
settings.useShouldInterceptFetchRequest == null) {
|
||||
settings.useShouldInterceptFetchRequest = true;
|
||||
}
|
||||
if (params.shouldInterceptRequest != null &&
|
||||
settings.useShouldInterceptRequest == null) {
|
||||
settings.useShouldInterceptRequest = true;
|
||||
}
|
||||
if (params.onRenderProcessGone != null &&
|
||||
settings.useOnRenderProcessGone == null) {
|
||||
settings.useOnRenderProcessGone = true;
|
||||
}
|
||||
if (params.onNavigationResponse != null &&
|
||||
settings.useOnNavigationResponse == null) {
|
||||
settings.useOnNavigationResponse = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool isRunning() {
|
||||
return _running;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setSize(Size size) async {
|
||||
if (!_running) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('size', () => size.toMap());
|
||||
await channel?.invokeMethod('setSize', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Size?> getSize() async {
|
||||
if (!_running) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
Map<String, dynamic> sizeMap =
|
||||
(await channel?.invokeMethod('getSize', args))?.cast<String, dynamic>();
|
||||
return MapSize.fromMap(sizeMap);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
if (!_running) {
|
||||
return;
|
||||
}
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('dispose', args);
|
||||
disposeChannel();
|
||||
_started = false;
|
||||
_running = false;
|
||||
_webViewController?.dispose();
|
||||
_webViewController = null;
|
||||
_controllerFromPlatform = null;
|
||||
_macosParams.pullToRefreshController?.dispose();
|
||||
_macosParams.findInteractionController?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalHeadlessInAppWebView on MacOSHeadlessInAppWebView {
|
||||
Future<void> internalDispose() async {
|
||||
_started = false;
|
||||
_running = false;
|
||||
}
|
||||
}
|
||||
Vendored
Executable
+408
@@ -0,0 +1,408 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
import 'headless_in_app_webview.dart';
|
||||
|
||||
import '../find_interaction/find_interaction_controller.dart';
|
||||
import 'in_app_webview_controller.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [PlatformInAppWebViewWidget].
|
||||
///
|
||||
/// Platform specific implementations can add additional fields by extending
|
||||
/// this class.
|
||||
class MacOSInAppWebViewWidgetCreationParams
|
||||
extends PlatformInAppWebViewWidgetCreationParams {
|
||||
MacOSInAppWebViewWidgetCreationParams(
|
||||
{super.controllerFromPlatform,
|
||||
super.key,
|
||||
super.layoutDirection,
|
||||
super.gestureRecognizers,
|
||||
super.headlessWebView,
|
||||
super.keepAlive,
|
||||
super.preventGestureDelay,
|
||||
super.windowId,
|
||||
super.onWebViewCreated,
|
||||
super.onLoadStart,
|
||||
super.onLoadStop,
|
||||
@Deprecated('Use onReceivedError instead') super.onLoadError,
|
||||
super.onReceivedError,
|
||||
@Deprecated("Use onReceivedHttpError instead") super.onLoadHttpError,
|
||||
super.onReceivedHttpError,
|
||||
super.onProgressChanged,
|
||||
super.onConsoleMessage,
|
||||
super.shouldOverrideUrlLoading,
|
||||
super.onLoadResource,
|
||||
super.onScrollChanged,
|
||||
@Deprecated('Use onDownloadStartRequest instead') super.onDownloadStart,
|
||||
super.onDownloadStartRequest,
|
||||
@Deprecated('Use onLoadResourceWithCustomScheme instead')
|
||||
super.onLoadResourceCustomScheme,
|
||||
super.onLoadResourceWithCustomScheme,
|
||||
super.onCreateWindow,
|
||||
super.onCloseWindow,
|
||||
super.onJsAlert,
|
||||
super.onJsConfirm,
|
||||
super.onJsPrompt,
|
||||
super.onReceivedHttpAuthRequest,
|
||||
super.onReceivedServerTrustAuthRequest,
|
||||
super.onReceivedClientCertRequest,
|
||||
@Deprecated('Use FindInteractionController.onFindResultReceived instead')
|
||||
super.onFindResultReceived,
|
||||
super.shouldInterceptAjaxRequest,
|
||||
super.onAjaxReadyStateChange,
|
||||
super.onAjaxProgress,
|
||||
super.shouldInterceptFetchRequest,
|
||||
super.onUpdateVisitedHistory,
|
||||
@Deprecated("Use onPrintRequest instead") super.onPrint,
|
||||
super.onPrintRequest,
|
||||
super.onLongPressHitTestResult,
|
||||
super.onEnterFullscreen,
|
||||
super.onExitFullscreen,
|
||||
super.onPageCommitVisible,
|
||||
super.onTitleChanged,
|
||||
super.onWindowFocus,
|
||||
super.onWindowBlur,
|
||||
super.onOverScrolled,
|
||||
super.onZoomScaleChanged,
|
||||
@Deprecated('Use onSafeBrowsingHit instead')
|
||||
super.androidOnSafeBrowsingHit,
|
||||
super.onSafeBrowsingHit,
|
||||
@Deprecated('Use onPermissionRequest instead')
|
||||
super.androidOnPermissionRequest,
|
||||
super.onPermissionRequest,
|
||||
@Deprecated('Use onGeolocationPermissionsShowPrompt instead')
|
||||
super.androidOnGeolocationPermissionsShowPrompt,
|
||||
super.onGeolocationPermissionsShowPrompt,
|
||||
@Deprecated('Use onGeolocationPermissionsHidePrompt instead')
|
||||
super.androidOnGeolocationPermissionsHidePrompt,
|
||||
super.onGeolocationPermissionsHidePrompt,
|
||||
@Deprecated('Use shouldInterceptRequest instead')
|
||||
super.androidShouldInterceptRequest,
|
||||
super.shouldInterceptRequest,
|
||||
@Deprecated('Use onRenderProcessGone instead')
|
||||
super.androidOnRenderProcessGone,
|
||||
super.onRenderProcessGone,
|
||||
@Deprecated('Use onRenderProcessResponsive instead')
|
||||
super.androidOnRenderProcessResponsive,
|
||||
super.onRenderProcessResponsive,
|
||||
@Deprecated('Use onRenderProcessUnresponsive instead')
|
||||
super.androidOnRenderProcessUnresponsive,
|
||||
super.onRenderProcessUnresponsive,
|
||||
@Deprecated('Use onFormResubmission instead')
|
||||
super.androidOnFormResubmission,
|
||||
super.onFormResubmission,
|
||||
@Deprecated('Use onZoomScaleChanged instead') super.androidOnScaleChanged,
|
||||
@Deprecated('Use onReceivedIcon instead') super.androidOnReceivedIcon,
|
||||
super.onReceivedIcon,
|
||||
@Deprecated('Use onReceivedTouchIconUrl instead')
|
||||
super.androidOnReceivedTouchIconUrl,
|
||||
super.onReceivedTouchIconUrl,
|
||||
@Deprecated('Use onJsBeforeUnload instead') super.androidOnJsBeforeUnload,
|
||||
super.onJsBeforeUnload,
|
||||
@Deprecated('Use onReceivedLoginRequest instead')
|
||||
super.androidOnReceivedLoginRequest,
|
||||
super.onReceivedLoginRequest,
|
||||
super.onPermissionRequestCanceled,
|
||||
super.onRequestFocus,
|
||||
@Deprecated('Use onWebContentProcessDidTerminate instead')
|
||||
super.iosOnWebContentProcessDidTerminate,
|
||||
super.onWebContentProcessDidTerminate,
|
||||
@Deprecated(
|
||||
'Use onDidReceiveServerRedirectForProvisionalNavigation instead')
|
||||
super.iosOnDidReceiveServerRedirectForProvisionalNavigation,
|
||||
super.onDidReceiveServerRedirectForProvisionalNavigation,
|
||||
@Deprecated('Use onNavigationResponse instead')
|
||||
super.iosOnNavigationResponse,
|
||||
super.onNavigationResponse,
|
||||
@Deprecated('Use shouldAllowDeprecatedTLS instead')
|
||||
super.iosShouldAllowDeprecatedTLS,
|
||||
super.shouldAllowDeprecatedTLS,
|
||||
super.onCameraCaptureStateChanged,
|
||||
super.onMicrophoneCaptureStateChanged,
|
||||
super.onContentSizeChanged,
|
||||
super.initialUrlRequest,
|
||||
super.initialFile,
|
||||
super.initialData,
|
||||
@Deprecated('Use initialSettings instead') super.initialOptions,
|
||||
super.initialSettings,
|
||||
super.contextMenu,
|
||||
super.initialUserScripts,
|
||||
super.pullToRefreshController,
|
||||
this.findInteractionController});
|
||||
|
||||
/// Constructs a [MacOSInAppWebViewWidgetCreationParams] using a
|
||||
/// [PlatformInAppWebViewWidgetCreationParams].
|
||||
MacOSInAppWebViewWidgetCreationParams.fromPlatformInAppWebViewWidgetCreationParams(
|
||||
PlatformInAppWebViewWidgetCreationParams params)
|
||||
: this(
|
||||
controllerFromPlatform: params.controllerFromPlatform,
|
||||
key: params.key,
|
||||
layoutDirection: params.layoutDirection,
|
||||
gestureRecognizers: params.gestureRecognizers,
|
||||
headlessWebView: params.headlessWebView,
|
||||
keepAlive: params.keepAlive,
|
||||
preventGestureDelay: params.preventGestureDelay,
|
||||
windowId: params.windowId,
|
||||
onWebViewCreated: params.onWebViewCreated,
|
||||
onLoadStart: params.onLoadStart,
|
||||
onLoadStop: params.onLoadStop,
|
||||
onLoadError: params.onLoadError,
|
||||
onReceivedError: params.onReceivedError,
|
||||
onLoadHttpError: params.onLoadHttpError,
|
||||
onReceivedHttpError: params.onReceivedHttpError,
|
||||
onProgressChanged: params.onProgressChanged,
|
||||
onConsoleMessage: params.onConsoleMessage,
|
||||
shouldOverrideUrlLoading: params.shouldOverrideUrlLoading,
|
||||
onLoadResource: params.onLoadResource,
|
||||
onScrollChanged: params.onScrollChanged,
|
||||
onDownloadStart: params.onDownloadStart,
|
||||
onDownloadStartRequest: params.onDownloadStartRequest,
|
||||
onLoadResourceCustomScheme: params.onLoadResourceCustomScheme,
|
||||
onLoadResourceWithCustomScheme:
|
||||
params.onLoadResourceWithCustomScheme,
|
||||
onCreateWindow: params.onCreateWindow,
|
||||
onCloseWindow: params.onCloseWindow,
|
||||
onJsAlert: params.onJsAlert,
|
||||
onJsConfirm: params.onJsConfirm,
|
||||
onJsPrompt: params.onJsPrompt,
|
||||
onReceivedHttpAuthRequest: params.onReceivedHttpAuthRequest,
|
||||
onReceivedServerTrustAuthRequest:
|
||||
params.onReceivedServerTrustAuthRequest,
|
||||
onReceivedClientCertRequest: params.onReceivedClientCertRequest,
|
||||
onFindResultReceived: params.onFindResultReceived,
|
||||
shouldInterceptAjaxRequest: params.shouldInterceptAjaxRequest,
|
||||
onAjaxReadyStateChange: params.onAjaxReadyStateChange,
|
||||
onAjaxProgress: params.onAjaxProgress,
|
||||
shouldInterceptFetchRequest: params.shouldInterceptFetchRequest,
|
||||
onUpdateVisitedHistory: params.onUpdateVisitedHistory,
|
||||
onPrint: params.onPrint,
|
||||
onPrintRequest: params.onPrintRequest,
|
||||
onLongPressHitTestResult: params.onLongPressHitTestResult,
|
||||
onEnterFullscreen: params.onEnterFullscreen,
|
||||
onExitFullscreen: params.onExitFullscreen,
|
||||
onPageCommitVisible: params.onPageCommitVisible,
|
||||
onTitleChanged: params.onTitleChanged,
|
||||
onWindowFocus: params.onWindowFocus,
|
||||
onWindowBlur: params.onWindowBlur,
|
||||
onOverScrolled: params.onOverScrolled,
|
||||
onZoomScaleChanged: params.onZoomScaleChanged,
|
||||
androidOnSafeBrowsingHit: params.androidOnSafeBrowsingHit,
|
||||
onSafeBrowsingHit: params.onSafeBrowsingHit,
|
||||
androidOnPermissionRequest: params.androidOnPermissionRequest,
|
||||
onPermissionRequest: params.onPermissionRequest,
|
||||
androidOnGeolocationPermissionsShowPrompt:
|
||||
params.androidOnGeolocationPermissionsShowPrompt,
|
||||
onGeolocationPermissionsShowPrompt:
|
||||
params.onGeolocationPermissionsShowPrompt,
|
||||
androidOnGeolocationPermissionsHidePrompt:
|
||||
params.androidOnGeolocationPermissionsHidePrompt,
|
||||
onGeolocationPermissionsHidePrompt:
|
||||
params.onGeolocationPermissionsHidePrompt,
|
||||
androidShouldInterceptRequest: params.androidShouldInterceptRequest,
|
||||
shouldInterceptRequest: params.shouldInterceptRequest,
|
||||
androidOnRenderProcessGone: params.androidOnRenderProcessGone,
|
||||
onRenderProcessGone: params.onRenderProcessGone,
|
||||
androidOnRenderProcessResponsive:
|
||||
params.androidOnRenderProcessResponsive,
|
||||
onRenderProcessResponsive: params.onRenderProcessResponsive,
|
||||
androidOnRenderProcessUnresponsive:
|
||||
params.androidOnRenderProcessUnresponsive,
|
||||
onRenderProcessUnresponsive: params.onRenderProcessUnresponsive,
|
||||
androidOnFormResubmission: params.androidOnFormResubmission,
|
||||
onFormResubmission: params.onFormResubmission,
|
||||
androidOnScaleChanged: params.androidOnScaleChanged,
|
||||
androidOnReceivedIcon: params.androidOnReceivedIcon,
|
||||
onReceivedIcon: params.onReceivedIcon,
|
||||
androidOnReceivedTouchIconUrl: params.androidOnReceivedTouchIconUrl,
|
||||
onReceivedTouchIconUrl: params.onReceivedTouchIconUrl,
|
||||
androidOnJsBeforeUnload: params.androidOnJsBeforeUnload,
|
||||
onJsBeforeUnload: params.onJsBeforeUnload,
|
||||
androidOnReceivedLoginRequest: params.androidOnReceivedLoginRequest,
|
||||
onReceivedLoginRequest: params.onReceivedLoginRequest,
|
||||
onPermissionRequestCanceled: params.onPermissionRequestCanceled,
|
||||
onRequestFocus: params.onRequestFocus,
|
||||
iosOnWebContentProcessDidTerminate:
|
||||
params.iosOnWebContentProcessDidTerminate,
|
||||
onWebContentProcessDidTerminate:
|
||||
params.onWebContentProcessDidTerminate,
|
||||
iosOnDidReceiveServerRedirectForProvisionalNavigation:
|
||||
params.iosOnDidReceiveServerRedirectForProvisionalNavigation,
|
||||
onDidReceiveServerRedirectForProvisionalNavigation:
|
||||
params.onDidReceiveServerRedirectForProvisionalNavigation,
|
||||
iosOnNavigationResponse: params.iosOnNavigationResponse,
|
||||
onNavigationResponse: params.onNavigationResponse,
|
||||
iosShouldAllowDeprecatedTLS: params.iosShouldAllowDeprecatedTLS,
|
||||
shouldAllowDeprecatedTLS: params.shouldAllowDeprecatedTLS,
|
||||
onCameraCaptureStateChanged: params.onCameraCaptureStateChanged,
|
||||
onMicrophoneCaptureStateChanged:
|
||||
params.onMicrophoneCaptureStateChanged,
|
||||
onContentSizeChanged: params.onContentSizeChanged,
|
||||
initialUrlRequest: params.initialUrlRequest,
|
||||
initialFile: params.initialFile,
|
||||
initialData: params.initialData,
|
||||
initialOptions: params.initialOptions,
|
||||
initialSettings: params.initialSettings,
|
||||
contextMenu: params.contextMenu,
|
||||
initialUserScripts: params.initialUserScripts,
|
||||
pullToRefreshController: params.pullToRefreshController,
|
||||
findInteractionController: params.findInteractionController
|
||||
as MacOSFindInteractionController?);
|
||||
|
||||
@override
|
||||
final MacOSFindInteractionController? findInteractionController;
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget}
|
||||
class MacOSInAppWebViewWidget extends PlatformInAppWebViewWidget {
|
||||
/// Constructs a [MacOSInAppWebViewWidget].
|
||||
///
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewWidget}
|
||||
MacOSInAppWebViewWidget(PlatformInAppWebViewWidgetCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSInAppWebViewWidgetCreationParams
|
||||
? params
|
||||
: MacOSInAppWebViewWidgetCreationParams
|
||||
.fromPlatformInAppWebViewWidgetCreationParams(params),
|
||||
);
|
||||
|
||||
MacOSInAppWebViewWidgetCreationParams get _macosParams =>
|
||||
params as MacOSInAppWebViewWidgetCreationParams;
|
||||
|
||||
MacOSInAppWebViewController? _controller;
|
||||
|
||||
MacOSHeadlessInAppWebView? get _macosHeadlessInAppWebView =>
|
||||
params.headlessWebView as MacOSHeadlessInAppWebView?;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final initialSettings = params.initialSettings ?? InAppWebViewSettings();
|
||||
_inferInitialSettings(initialSettings);
|
||||
|
||||
Map<String, dynamic> settingsMap =
|
||||
(params.initialSettings != null ? initialSettings.toMap() : null) ??
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
params.initialOptions?.toMap() ??
|
||||
initialSettings.toMap();
|
||||
|
||||
Map<String, dynamic> pullToRefreshSettings =
|
||||
params.pullToRefreshController?.params.settings.toMap() ??
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
params.pullToRefreshController?.params.options.toMap() ??
|
||||
PullToRefreshSettings(enabled: false).toMap();
|
||||
|
||||
if ((params.headlessWebView?.isRunning() ?? false) &&
|
||||
params.keepAlive != null) {
|
||||
final headlessId = params.headlessWebView?.id;
|
||||
if (headlessId != null) {
|
||||
// force keep alive id to match headless webview id
|
||||
params.keepAlive?.id = headlessId;
|
||||
}
|
||||
}
|
||||
|
||||
return AppKitView(
|
||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||
onPlatformViewCreated: _onPlatformViewCreated,
|
||||
gestureRecognizers: params.gestureRecognizers,
|
||||
creationParams: <String, dynamic>{
|
||||
'initialUrlRequest': params.initialUrlRequest?.toMap(),
|
||||
'initialFile': params.initialFile,
|
||||
'initialData': params.initialData?.toMap(),
|
||||
'initialSettings': settingsMap,
|
||||
'contextMenu': params.contextMenu?.toMap() ?? {},
|
||||
'windowId': params.windowId,
|
||||
'headlessWebViewId': params.headlessWebView?.isRunning() ?? false
|
||||
? params.headlessWebView?.id
|
||||
: null,
|
||||
'initialUserScripts':
|
||||
params.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
|
||||
'pullToRefreshSettings': pullToRefreshSettings,
|
||||
'keepAliveId': params.keepAlive?.id,
|
||||
'preventGestureDelay': params.preventGestureDelay
|
||||
},
|
||||
creationParamsCodec: const StandardMessageCodec(),
|
||||
);
|
||||
}
|
||||
|
||||
void _onPlatformViewCreated(int id) {
|
||||
dynamic viewId = id;
|
||||
if (params.headlessWebView?.isRunning() ?? false) {
|
||||
viewId = params.headlessWebView?.id;
|
||||
}
|
||||
viewId = params.keepAlive?.id ?? viewId ?? id;
|
||||
_macosHeadlessInAppWebView?.internalDispose();
|
||||
_controller = MacOSInAppWebViewController(
|
||||
PlatformInAppWebViewControllerCreationParams(
|
||||
id: viewId, webviewParams: params));
|
||||
_macosParams.findInteractionController?.init(viewId);
|
||||
debugLog(
|
||||
className: runtimeType.toString(),
|
||||
id: viewId?.toString(),
|
||||
debugLoggingSettings:
|
||||
PlatformInAppWebViewController.debugLoggingSettings,
|
||||
method: "onWebViewCreated",
|
||||
args: []);
|
||||
if (params.onWebViewCreated != null) {
|
||||
params.onWebViewCreated!(
|
||||
params.controllerFromPlatform?.call(_controller!) ?? _controller!);
|
||||
}
|
||||
}
|
||||
|
||||
void _inferInitialSettings(InAppWebViewSettings settings) {
|
||||
if (params.shouldOverrideUrlLoading != null &&
|
||||
settings.useShouldOverrideUrlLoading == null) {
|
||||
settings.useShouldOverrideUrlLoading = true;
|
||||
}
|
||||
if (params.onLoadResource != null && settings.useOnLoadResource == null) {
|
||||
settings.useOnLoadResource = true;
|
||||
}
|
||||
if (params.onDownloadStartRequest != null &&
|
||||
settings.useOnDownloadStart == null) {
|
||||
settings.useOnDownloadStart = true;
|
||||
}
|
||||
if ((params.shouldInterceptAjaxRequest != null ||
|
||||
params.onAjaxProgress != null ||
|
||||
params.onAjaxReadyStateChange != null) &&
|
||||
settings.useShouldInterceptAjaxRequest == null) {
|
||||
settings.useShouldInterceptAjaxRequest = true;
|
||||
}
|
||||
if (params.shouldInterceptFetchRequest != null &&
|
||||
settings.useShouldInterceptFetchRequest == null) {
|
||||
settings.useShouldInterceptFetchRequest = true;
|
||||
}
|
||||
if (params.shouldInterceptRequest != null &&
|
||||
settings.useShouldInterceptRequest == null) {
|
||||
settings.useShouldInterceptRequest = true;
|
||||
}
|
||||
if (params.onRenderProcessGone != null &&
|
||||
settings.useOnRenderProcessGone == null) {
|
||||
settings.useOnRenderProcessGone = true;
|
||||
}
|
||||
if (params.onNavigationResponse != null &&
|
||||
settings.useOnNavigationResponse == null) {
|
||||
settings.useOnNavigationResponse = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
dynamic viewId = _controller?.getViewId();
|
||||
debugLog(
|
||||
className: runtimeType.toString(),
|
||||
id: viewId?.toString(),
|
||||
debugLoggingSettings:
|
||||
PlatformInAppWebViewController.debugLoggingSettings,
|
||||
method: "dispose",
|
||||
args: []);
|
||||
final isKeepAlive = params.keepAlive != null;
|
||||
_controller?.dispose(isKeepAlive: isKeepAlive);
|
||||
_controller = null;
|
||||
params.findInteractionController?.dispose(isKeepAlive: isKeepAlive);
|
||||
}
|
||||
|
||||
@override
|
||||
T controllerFromPlatform<T>(PlatformInAppWebViewController controller) {
|
||||
// unused
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
+2689
File diff suppressed because it is too large.
Load diff
+3
@@ -0,0 +1,3 @@
|
||||
export 'in_app_webview_controller.dart' hide InternalInAppWebViewController;
|
||||
export 'in_app_webview.dart';
|
||||
export 'headless_in_app_webview.dart' hide InternalHeadlessInAppWebView;
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
import 'cookie_manager.dart';
|
||||
import 'http_auth_credentials_database.dart';
|
||||
import 'find_interaction/main.dart';
|
||||
import 'in_app_browser/in_app_browser.dart';
|
||||
import 'in_app_webview/main.dart';
|
||||
import 'print_job/main.dart';
|
||||
import 'web_message/main.dart';
|
||||
import 'web_storage/main.dart';
|
||||
import 'web_authentication_session/main.dart';
|
||||
|
||||
/// Implementation of [InAppWebViewPlatform] using the WebKit API.
|
||||
class MacOSInAppWebViewPlatform extends InAppWebViewPlatform {
|
||||
/// Registers this class as the default instance of [InAppWebViewPlatform].
|
||||
static void registerWith() {
|
||||
InAppWebViewPlatform.instance = MacOSInAppWebViewPlatform();
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSCookieManager].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [CookieManager] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSCookieManager createPlatformCookieManager(
|
||||
PlatformCookieManagerCreationParams params,
|
||||
) {
|
||||
return MacOSCookieManager(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSInAppWebViewController].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [InAppWebViewController] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSInAppWebViewController createPlatformInAppWebViewController(
|
||||
PlatformInAppWebViewControllerCreationParams params,
|
||||
) {
|
||||
return MacOSInAppWebViewController(params);
|
||||
}
|
||||
|
||||
/// Creates a new empty [MacOSInAppWebViewController] to access static methods.
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [InAppWebViewController] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSInAppWebViewController createPlatformInAppWebViewControllerStatic() {
|
||||
return MacOSInAppWebViewController.static();
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSInAppWebViewWidget].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [InAppWebView] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSInAppWebViewWidget createPlatformInAppWebViewWidget(
|
||||
PlatformInAppWebViewWidgetCreationParams params,
|
||||
) {
|
||||
return MacOSInAppWebViewWidget(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSFindInteractionController].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [FindInteractionController] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSFindInteractionController createPlatformFindInteractionController(
|
||||
PlatformFindInteractionControllerCreationParams params,
|
||||
) {
|
||||
return MacOSFindInteractionController(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSPrintJobController].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [PrintJobController] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSPrintJobController createPlatformPrintJobController(
|
||||
PlatformPrintJobControllerCreationParams params,
|
||||
) {
|
||||
return MacOSPrintJobController(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSWebMessageChannel].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebMessageChannel] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebMessageChannel createPlatformWebMessageChannel(
|
||||
PlatformWebMessageChannelCreationParams params,
|
||||
) {
|
||||
return MacOSWebMessageChannel(params);
|
||||
}
|
||||
|
||||
/// Creates a new empty [MacOSWebMessageChannel] to access static methods.
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebMessageChannel] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebMessageChannel createPlatformWebMessageChannelStatic() {
|
||||
return MacOSWebMessageChannel.static();
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSWebMessageListener].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebMessageListener] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebMessageListener createPlatformWebMessageListener(
|
||||
PlatformWebMessageListenerCreationParams params,
|
||||
) {
|
||||
return MacOSWebMessageListener(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSJavaScriptReplyProxy].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [JavaScriptReplyProxy] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSJavaScriptReplyProxy createPlatformJavaScriptReplyProxy(
|
||||
PlatformJavaScriptReplyProxyCreationParams params,
|
||||
) {
|
||||
return MacOSJavaScriptReplyProxy(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSWebMessagePort].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebMessagePort] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebMessagePort createPlatformWebMessagePort(
|
||||
PlatformWebMessagePortCreationParams params,
|
||||
) {
|
||||
return MacOSWebMessagePort(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSWebStorage].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebStorage] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebStorage createPlatformWebStorage(
|
||||
PlatformWebStorageCreationParams params,
|
||||
) {
|
||||
return MacOSWebStorage(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSLocalStorage].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [LocalStorage] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSLocalStorage createPlatformLocalStorage(
|
||||
PlatformLocalStorageCreationParams params,
|
||||
) {
|
||||
return MacOSLocalStorage(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSSessionStorage].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [SessionStorage] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSSessionStorage createPlatformSessionStorage(
|
||||
PlatformSessionStorageCreationParams params,
|
||||
) {
|
||||
return MacOSSessionStorage(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSHeadlessInAppWebView].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [HeadlessInAppWebView] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSHeadlessInAppWebView createPlatformHeadlessInAppWebView(
|
||||
PlatformHeadlessInAppWebViewCreationParams params,
|
||||
) {
|
||||
return MacOSHeadlessInAppWebView(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSHttpAuthCredentialDatabase].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [HttpAuthCredentialDatabase] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSHttpAuthCredentialDatabase createPlatformHttpAuthCredentialDatabase(
|
||||
PlatformHttpAuthCredentialDatabaseCreationParams params,
|
||||
) {
|
||||
return MacOSHttpAuthCredentialDatabase(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSInAppBrowser].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [InAppBrowser] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSInAppBrowser createPlatformInAppBrowser(
|
||||
PlatformInAppBrowserCreationParams params,
|
||||
) {
|
||||
return MacOSInAppBrowser(params);
|
||||
}
|
||||
|
||||
/// Creates a new empty [MacOSInAppBrowser] to access static methods.
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [InAppBrowser] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSInAppBrowser createPlatformInAppBrowserStatic() {
|
||||
return MacOSInAppBrowser.static();
|
||||
}
|
||||
|
||||
/// Creates a new empty [MacOSWebStorageManager] to access static methods.
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebStorageManager] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebStorageManager createPlatformWebStorageManager(
|
||||
PlatformWebStorageManagerCreationParams params) {
|
||||
return MacOSWebStorageManager(params);
|
||||
}
|
||||
|
||||
/// Creates a new [MacOSWebAuthenticationSession].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebAuthenticationSession] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebAuthenticationSession createPlatformWebAuthenticationSession(
|
||||
PlatformWebAuthenticationSessionCreationParams params) {
|
||||
return MacOSWebAuthenticationSession(params);
|
||||
}
|
||||
|
||||
/// Creates a new empty [MacOSWebAuthenticationSession] to access static methods.
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [WebAuthenticationSession] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
MacOSWebAuthenticationSession createPlatformWebAuthenticationSessionStatic() {
|
||||
return MacOSWebAuthenticationSession.static();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export 'inappwebview_platform.dart';
|
||||
export 'in_app_webview/main.dart';
|
||||
export 'in_app_browser/main.dart';
|
||||
export 'web_storage/main.dart';
|
||||
export 'cookie_manager.dart' hide InternalCookieManager;
|
||||
export 'http_auth_credentials_database.dart'
|
||||
hide InternalHttpAuthCredentialDatabase;
|
||||
export 'web_message/main.dart';
|
||||
export 'print_job/main.dart';
|
||||
export 'find_interaction/main.dart';
|
||||
export 'web_authentication_session/main.dart';
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
///Platform native utilities
|
||||
class PlatformUtil {
|
||||
static PlatformUtil? _instance;
|
||||
static const MethodChannel _channel =
|
||||
MethodChannel('com.pichillilorenzo/flutter_inappwebview_platformutil');
|
||||
|
||||
PlatformUtil._();
|
||||
|
||||
///Get [PlatformUtil] instance.
|
||||
static PlatformUtil instance() {
|
||||
return (_instance != null) ? _instance! : _init();
|
||||
}
|
||||
|
||||
static PlatformUtil _init() {
|
||||
_channel.setMethodCallHandler((call) async {
|
||||
try {
|
||||
return await _handleMethod(call);
|
||||
} on Error catch (e) {
|
||||
print(e);
|
||||
print(e.stackTrace);
|
||||
}
|
||||
});
|
||||
_instance = PlatformUtil._();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
static Future<dynamic> _handleMethod(MethodCall call) async {}
|
||||
|
||||
String? _cachedSystemVersion;
|
||||
|
||||
///Get current platform system version.
|
||||
Future<String> getSystemVersion() async {
|
||||
if (_cachedSystemVersion != null) {
|
||||
return _cachedSystemVersion!;
|
||||
}
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
_cachedSystemVersion =
|
||||
await _channel.invokeMethod('getSystemVersion', args);
|
||||
return _cachedSystemVersion!;
|
||||
}
|
||||
|
||||
///Format date.
|
||||
Future<String> formatDate(
|
||||
{required DateTime date,
|
||||
required String format,
|
||||
String locale = "en_US",
|
||||
String timezone = "UTC"}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('date', () => date.millisecondsSinceEpoch);
|
||||
args.putIfAbsent('format', () => format);
|
||||
args.putIfAbsent('locale', () => locale);
|
||||
args.putIfAbsent('timezone', () => timezone);
|
||||
return await _channel.invokeMethod('formatDate', args);
|
||||
}
|
||||
|
||||
///Get cookie expiration date used by Web platform.
|
||||
Future<String> getWebCookieExpirationDate({required DateTime date}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('date', () => date.millisecondsSinceEpoch);
|
||||
return await _channel.invokeMethod('getWebCookieExpirationDate', args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export 'print_job_controller.dart';
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSPrintJobController].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformPrintJobControllerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSPrintJobControllerCreationParams
|
||||
extends PlatformPrintJobControllerCreationParams {
|
||||
/// Creates a new [MacOSPrintJobControllerCreationParams] instance.
|
||||
const MacOSPrintJobControllerCreationParams(
|
||||
{required super.id, super.onComplete});
|
||||
|
||||
/// Creates a [MacOSPrintJobControllerCreationParams] instance based on [PlatformPrintJobControllerCreationParams].
|
||||
factory MacOSPrintJobControllerCreationParams.fromPlatformPrintJobControllerCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformPrintJobControllerCreationParams params) {
|
||||
return MacOSPrintJobControllerCreationParams(
|
||||
id: params.id, onComplete: params.onComplete);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformPrintJobController}
|
||||
class MacOSPrintJobController extends PlatformPrintJobController
|
||||
with ChannelController {
|
||||
/// Constructs a [MacOSPrintJobController].
|
||||
MacOSPrintJobController(PlatformPrintJobControllerCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSPrintJobControllerCreationParams
|
||||
? params
|
||||
: MacOSPrintJobControllerCreationParams
|
||||
.fromPlatformPrintJobControllerCreationParams(params),
|
||||
) {
|
||||
onComplete = params.onComplete;
|
||||
channel = MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_printjobcontroller_${params.id}');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case "onComplete":
|
||||
bool completed = call.arguments["completed"];
|
||||
String? error = call.arguments["error"];
|
||||
if (onComplete != null) {
|
||||
onComplete!(completed, error);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PrintJobInfo?> getInfo() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
Map<String, dynamic>? infoMap =
|
||||
(await channel?.invokeMethod('getInfo', args))?.cast<String, dynamic>();
|
||||
return PrintJobInfo.fromMap(infoMap);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod('dispose', args);
|
||||
disposeChannel();
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export 'web_authenticate_session.dart';
|
||||
Vendored
Executable
+164
@@ -0,0 +1,164 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebAuthenticationSession].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebAuthenticationSessionCreationParams] for
|
||||
/// more information.
|
||||
class MacOSWebAuthenticationSessionCreationParams
|
||||
extends PlatformWebAuthenticationSessionCreationParams {
|
||||
/// Creates a new [MacOSWebAuthenticationSessionCreationParams] instance.
|
||||
const MacOSWebAuthenticationSessionCreationParams();
|
||||
|
||||
/// Creates a [MacOSWebAuthenticationSessionCreationParams] instance based on [PlatformWebAuthenticationSessionCreationParams].
|
||||
factory MacOSWebAuthenticationSessionCreationParams.fromPlatformWebAuthenticationSessionCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebAuthenticationSessionCreationParams params) {
|
||||
return MacOSWebAuthenticationSessionCreationParams();
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebAuthenticationSession}
|
||||
class MacOSWebAuthenticationSession extends PlatformWebAuthenticationSession
|
||||
with ChannelController {
|
||||
/// Constructs a [MacOSWebAuthenticationSession].
|
||||
MacOSWebAuthenticationSession(
|
||||
PlatformWebAuthenticationSessionCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebAuthenticationSessionCreationParams
|
||||
? params
|
||||
: MacOSWebAuthenticationSessionCreationParams
|
||||
.fromPlatformWebAuthenticationSessionCreationParams(params),
|
||||
);
|
||||
|
||||
static final MacOSWebAuthenticationSession _staticValue =
|
||||
MacOSWebAuthenticationSession(
|
||||
MacOSWebAuthenticationSessionCreationParams());
|
||||
|
||||
/// Provide static access.
|
||||
factory MacOSWebAuthenticationSession.static() {
|
||||
return _staticValue;
|
||||
}
|
||||
|
||||
@override
|
||||
final String id = IdGenerator.generate();
|
||||
|
||||
@override
|
||||
late final WebUri url;
|
||||
|
||||
@override
|
||||
late final String? callbackURLScheme;
|
||||
|
||||
@override
|
||||
late final WebAuthenticationSessionSettings? initialSettings;
|
||||
|
||||
@override
|
||||
late final WebAuthenticationSessionCompletionHandler onComplete;
|
||||
|
||||
static const MethodChannel _staticChannel = const MethodChannel(
|
||||
'com.pichillilorenzo/flutter_webauthenticationsession');
|
||||
|
||||
@override
|
||||
Future<MacOSWebAuthenticationSession> create(
|
||||
{required WebUri url,
|
||||
String? callbackURLScheme,
|
||||
WebAuthenticationSessionCompletionHandler onComplete,
|
||||
WebAuthenticationSessionSettings? initialSettings}) async {
|
||||
var session = MacOSWebAuthenticationSession._create(
|
||||
url: url,
|
||||
callbackURLScheme: callbackURLScheme,
|
||||
onComplete: onComplete,
|
||||
initialSettings: initialSettings);
|
||||
initialSettings =
|
||||
session.initialSettings ?? WebAuthenticationSessionSettings();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("id", () => session.id);
|
||||
args.putIfAbsent("url", () => session.url.toString());
|
||||
args.putIfAbsent("callbackURLScheme", () => session.callbackURLScheme);
|
||||
args.putIfAbsent("initialSettings", () => initialSettings?.toMap());
|
||||
await _staticChannel.invokeMethod('create', args);
|
||||
return session;
|
||||
}
|
||||
|
||||
MacOSWebAuthenticationSession._create(
|
||||
{required this.url,
|
||||
this.callbackURLScheme,
|
||||
this.onComplete,
|
||||
WebAuthenticationSessionSettings? initialSettings})
|
||||
: super.implementation(MacOSWebAuthenticationSessionCreationParams()) {
|
||||
assert(url.toString().isNotEmpty);
|
||||
assert(['http', 'https'].contains(url.scheme),
|
||||
'The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported on iOS.');
|
||||
|
||||
this.initialSettings =
|
||||
initialSettings ?? WebAuthenticationSessionSettings();
|
||||
channel = MethodChannel(
|
||||
'com.pichillilorenzo/flutter_webauthenticationsession_$id');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
_debugLog(String method, dynamic args) {
|
||||
debugLog(
|
||||
className: this.runtimeType.toString(),
|
||||
debugLoggingSettings:
|
||||
PlatformWebAuthenticationSession.debugLoggingSettings,
|
||||
id: id,
|
||||
method: method,
|
||||
args: args);
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
_debugLog(call.method, call.arguments);
|
||||
|
||||
switch (call.method) {
|
||||
case "onComplete":
|
||||
String? url = call.arguments["url"];
|
||||
WebUri? uri = url != null ? WebUri(url) : null;
|
||||
var error = WebAuthenticationSessionError.fromNativeValue(
|
||||
call.arguments["errorCode"]);
|
||||
if (onComplete != null) {
|
||||
onComplete!(uri, error);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> canStart() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await channel?.invokeMethod<bool>('canStart', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> start() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await channel?.invokeMethod<bool>('start', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> cancel() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod("cancel", args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await channel?.invokeMethod("dispose", args);
|
||||
disposeChannel();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isAvailable() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
return await _staticChannel.invokeMethod<bool>("isAvailable", args) ??
|
||||
false;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export 'web_message_port.dart' hide InternalWebMessagePort;
|
||||
export 'web_message_channel.dart' hide InternalWebMessageChannel;
|
||||
export 'web_message_listener.dart';
|
||||
Vendored
+120
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
import 'web_message_port.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebMessageChannel].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebMessageChannelCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSWebMessageChannelCreationParams
|
||||
extends PlatformWebMessageChannelCreationParams {
|
||||
/// Creates a new [MacOSWebMessageChannelCreationParams] instance.
|
||||
const MacOSWebMessageChannelCreationParams(
|
||||
{required super.id, required super.port1, required super.port2});
|
||||
|
||||
/// Creates a [MacOSWebMessageChannelCreationParams] instance based on [PlatformWebMessageChannelCreationParams].
|
||||
factory MacOSWebMessageChannelCreationParams.fromPlatformWebMessageChannelCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebMessageChannelCreationParams params) {
|
||||
return MacOSWebMessageChannelCreationParams(
|
||||
id: params.id, port1: params.port1, port2: params.port2);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessageChannelCreationParams{id: $id, port1: $port1, port2: $port2}';
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebMessageChannel}
|
||||
class MacOSWebMessageChannel extends PlatformWebMessageChannel
|
||||
with ChannelController {
|
||||
/// Constructs a [MacOSWebMessageChannel].
|
||||
MacOSWebMessageChannel(PlatformWebMessageChannelCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebMessageChannelCreationParams
|
||||
? params
|
||||
: MacOSWebMessageChannelCreationParams
|
||||
.fromPlatformWebMessageChannelCreationParams(params),
|
||||
) {
|
||||
channel = MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_web_message_channel_${params.id}');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
static final MacOSWebMessageChannel _staticValue = MacOSWebMessageChannel(
|
||||
MacOSWebMessageChannelCreationParams(
|
||||
id: '',
|
||||
port1:
|
||||
MacOSWebMessagePort(MacOSWebMessagePortCreationParams(index: 0)),
|
||||
port2: MacOSWebMessagePort(
|
||||
MacOSWebMessagePortCreationParams(index: 1))));
|
||||
|
||||
/// Provide static access.
|
||||
factory MacOSWebMessageChannel.static() {
|
||||
return _staticValue;
|
||||
}
|
||||
|
||||
MacOSWebMessagePort get _macosPort1 => port1 as MacOSWebMessagePort;
|
||||
|
||||
MacOSWebMessagePort get _macosPort2 => port2 as MacOSWebMessagePort;
|
||||
|
||||
static MacOSWebMessageChannel? _fromMap(Map<String, dynamic>? map) {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
var webMessageChannel = MacOSWebMessageChannel(
|
||||
MacOSWebMessageChannelCreationParams(
|
||||
id: map["id"],
|
||||
port1: MacOSWebMessagePort(
|
||||
MacOSWebMessagePortCreationParams(index: 0)),
|
||||
port2: MacOSWebMessagePort(
|
||||
MacOSWebMessagePortCreationParams(index: 1))));
|
||||
webMessageChannel._macosPort1.webMessageChannel = webMessageChannel;
|
||||
webMessageChannel._macosPort2.webMessageChannel = webMessageChannel;
|
||||
return webMessageChannel;
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case "onMessage":
|
||||
int index = call.arguments["index"];
|
||||
var port = index == 0 ? _macosPort1 : _macosPort2;
|
||||
if (port.onMessage != null) {
|
||||
WebMessage? message = call.arguments["message"] != null
|
||||
? WebMessage.fromMap(
|
||||
call.arguments["message"].cast<String, dynamic>())
|
||||
: null;
|
||||
port.onMessage!(message);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
MacOSWebMessageChannel? fromMap(Map<String, dynamic>? map) {
|
||||
return _fromMap(map);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
disposeChannel();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessageChannel{id: $id, port1: $port1, port2: $port2}';
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalWebMessageChannel on MacOSWebMessageChannel {
|
||||
MethodChannel? get internalChannel => channel;
|
||||
}
|
||||
Vendored
+164
@@ -0,0 +1,164 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebMessageListener].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebMessageListenerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSWebMessageListenerCreationParams
|
||||
extends PlatformWebMessageListenerCreationParams {
|
||||
/// Creates a new [MacOSWebMessageListenerCreationParams] instance.
|
||||
const MacOSWebMessageListenerCreationParams(
|
||||
{required this.allowedOriginRules,
|
||||
required super.jsObjectName,
|
||||
super.onPostMessage});
|
||||
|
||||
/// Creates a [MacOSWebMessageListenerCreationParams] instance based on [PlatformWebMessageListenerCreationParams].
|
||||
factory MacOSWebMessageListenerCreationParams.fromPlatformWebMessageListenerCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebMessageListenerCreationParams params) {
|
||||
return MacOSWebMessageListenerCreationParams(
|
||||
allowedOriginRules: params.allowedOriginRules ?? Set.from(["*"]),
|
||||
jsObjectName: params.jsObjectName,
|
||||
onPostMessage: params.onPostMessage);
|
||||
}
|
||||
|
||||
@override
|
||||
final Set<String> allowedOriginRules;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessageListenerCreationParams{jsObjectName: $jsObjectName, allowedOriginRules: $allowedOriginRules, onPostMessage: $onPostMessage}';
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebMessageListener}
|
||||
class MacOSWebMessageListener extends PlatformWebMessageListener
|
||||
with ChannelController {
|
||||
/// Constructs a [MacOSWebMessageListener].
|
||||
MacOSWebMessageListener(PlatformWebMessageListenerCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebMessageListenerCreationParams
|
||||
? params
|
||||
: MacOSWebMessageListenerCreationParams
|
||||
.fromPlatformWebMessageListenerCreationParams(params),
|
||||
) {
|
||||
assert(!this._macosParams.allowedOriginRules.contains(""),
|
||||
"allowedOriginRules cannot contain empty strings");
|
||||
channel = MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_web_message_listener_${_id}_${params.jsObjectName}');
|
||||
handler = _handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
///Message Listener ID used internally.
|
||||
final String _id = IdGenerator.generate();
|
||||
|
||||
MacOSJavaScriptReplyProxy? _replyProxy;
|
||||
|
||||
MacOSWebMessageListenerCreationParams get _macosParams =>
|
||||
params as MacOSWebMessageListenerCreationParams;
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case "onPostMessage":
|
||||
if (_replyProxy == null) {
|
||||
_replyProxy = MacOSJavaScriptReplyProxy(
|
||||
PlatformJavaScriptReplyProxyCreationParams(
|
||||
webMessageListener: this));
|
||||
}
|
||||
if (onPostMessage != null) {
|
||||
WebMessage? message = call.arguments["message"] != null
|
||||
? WebMessage.fromMap(
|
||||
call.arguments["message"].cast<String, dynamic>())
|
||||
: null;
|
||||
WebUri? sourceOrigin = call.arguments["sourceOrigin"] != null
|
||||
? WebUri(call.arguments["sourceOrigin"])
|
||||
: null;
|
||||
bool isMainFrame = call.arguments["isMainFrame"];
|
||||
onPostMessage!(message, sourceOrigin, isMainFrame, _replyProxy!);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
disposeChannel();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"id": _id,
|
||||
"jsObjectName": params.jsObjectName,
|
||||
"allowedOriginRules": _macosParams.allowedOriginRules.toList(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return this.toMap();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessageListener{id: ${_id}, jsObjectName: ${params.jsObjectName}, allowedOriginRules: ${params.allowedOriginRules}, replyProxy: $_replyProxy}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSJavaScriptReplyProxy].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformJavaScriptReplyProxyCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSJavaScriptReplyProxyCreationParams
|
||||
extends PlatformJavaScriptReplyProxyCreationParams {
|
||||
/// Creates a new [MacOSJavaScriptReplyProxyCreationParams] instance.
|
||||
const MacOSJavaScriptReplyProxyCreationParams(
|
||||
{required super.webMessageListener});
|
||||
|
||||
/// Creates a [MacOSJavaScriptReplyProxyCreationParams] instance based on [PlatformJavaScriptReplyProxyCreationParams].
|
||||
factory MacOSJavaScriptReplyProxyCreationParams.fromPlatformJavaScriptReplyProxyCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformJavaScriptReplyProxyCreationParams params) {
|
||||
return MacOSJavaScriptReplyProxyCreationParams(
|
||||
webMessageListener: params.webMessageListener);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.JavaScriptReplyProxy}
|
||||
class MacOSJavaScriptReplyProxy extends PlatformJavaScriptReplyProxy {
|
||||
/// Constructs a [MacOSWebMessageListener].
|
||||
MacOSJavaScriptReplyProxy(PlatformJavaScriptReplyProxyCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSJavaScriptReplyProxyCreationParams
|
||||
? params
|
||||
: MacOSJavaScriptReplyProxyCreationParams
|
||||
.fromPlatformJavaScriptReplyProxyCreationParams(params),
|
||||
);
|
||||
|
||||
MacOSWebMessageListener get _macosWebMessageListener =>
|
||||
params.webMessageListener as MacOSWebMessageListener;
|
||||
|
||||
@override
|
||||
Future<void> postMessage(WebMessage message) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('message', () => message.toMap());
|
||||
await _macosWebMessageListener.channel?.invokeMethod('postMessage', args);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSJavaScriptReplyProxy{}';
|
||||
}
|
||||
}
|
||||
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
import 'web_message_channel.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebMessagePort].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebMessagePortCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSWebMessagePortCreationParams
|
||||
extends PlatformWebMessagePortCreationParams {
|
||||
/// Creates a new [MacOSWebMessagePortCreationParams] instance.
|
||||
const MacOSWebMessagePortCreationParams({required super.index});
|
||||
|
||||
/// Creates a [MacOSWebMessagePortCreationParams] instance based on [PlatformWebMessagePortCreationParams].
|
||||
factory MacOSWebMessagePortCreationParams.fromPlatformWebMessagePortCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebMessagePortCreationParams params) {
|
||||
return MacOSWebMessagePortCreationParams(index: params.index);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessagePortCreationParams{index: $index}';
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebMessagePort}
|
||||
class MacOSWebMessagePort extends PlatformWebMessagePort {
|
||||
WebMessageCallback? _onMessage;
|
||||
late MacOSWebMessageChannel _webMessageChannel;
|
||||
|
||||
/// Constructs a [MacOSWebMessagePort].
|
||||
MacOSWebMessagePort(PlatformWebMessagePortCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebMessagePortCreationParams
|
||||
? params
|
||||
: MacOSWebMessagePortCreationParams
|
||||
.fromPlatformWebMessagePortCreationParams(params),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> setWebMessageCallback(WebMessageCallback? onMessage) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('index', () => params.index);
|
||||
await _webMessageChannel.internalChannel
|
||||
?.invokeMethod('setWebMessageCallback', args);
|
||||
this._onMessage = onMessage;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> postMessage(WebMessage message) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('index', () => params.index);
|
||||
args.putIfAbsent('message', () => message.toMap());
|
||||
await _webMessageChannel.internalChannel?.invokeMethod('postMessage', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('index', () => params.index);
|
||||
await _webMessageChannel.internalChannel?.invokeMethod('close', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"index": params.index,
|
||||
"webMessageChannelId": this._webMessageChannel.params.id
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return toMap();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'MacOSWebMessagePort{index: ${params.index}}';
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalWebMessagePort on MacOSWebMessagePort {
|
||||
WebMessageCallback? get onMessage => _onMessage;
|
||||
void set onMessage(WebMessageCallback? value) => _onMessage = value;
|
||||
|
||||
MacOSWebMessageChannel get webMessageChannel => _webMessageChannel;
|
||||
void set webMessageChannel(MacOSWebMessageChannel value) =>
|
||||
_webMessageChannel = value;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export 'web_storage.dart';
|
||||
export 'web_storage_manager.dart' hide InternalWebStorageManager;
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
import '../in_app_webview/in_app_webview_controller.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebStorage].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebStorageCreationParams] for
|
||||
/// more information.
|
||||
class MacOSWebStorageCreationParams extends PlatformWebStorageCreationParams {
|
||||
/// Creates a new [MacOSWebStorageCreationParams] instance.
|
||||
MacOSWebStorageCreationParams(
|
||||
{required super.localStorage, required super.sessionStorage});
|
||||
|
||||
/// Creates a [MacOSWebStorageCreationParams] instance based on [PlatformWebStorageCreationParams].
|
||||
factory MacOSWebStorageCreationParams.fromPlatformWebStorageCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebStorageCreationParams params) {
|
||||
return MacOSWebStorageCreationParams(
|
||||
localStorage: params.localStorage,
|
||||
sessionStorage: params.sessionStorage);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebStorage}
|
||||
class MacOSWebStorage extends PlatformWebStorage {
|
||||
/// Constructs a [MacOSWebStorage].
|
||||
MacOSWebStorage(PlatformWebStorageCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebStorageCreationParams
|
||||
? params
|
||||
: MacOSWebStorageCreationParams
|
||||
.fromPlatformWebStorageCreationParams(params),
|
||||
);
|
||||
|
||||
@override
|
||||
PlatformLocalStorage get localStorage => params.localStorage;
|
||||
|
||||
@override
|
||||
PlatformSessionStorage get sessionStorage => params.sessionStorage;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
localStorage.dispose();
|
||||
sessionStorage.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSStorage].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformStorageCreationParams] for
|
||||
/// more information.
|
||||
class MacOSStorageCreationParams extends PlatformStorageCreationParams {
|
||||
/// Creates a new [MacOSStorageCreationParams] instance.
|
||||
MacOSStorageCreationParams(
|
||||
{required super.controller, required super.webStorageType});
|
||||
|
||||
/// Creates a [MacOSStorageCreationParams] instance based on [PlatformStorageCreationParams].
|
||||
factory MacOSStorageCreationParams.fromPlatformStorageCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformStorageCreationParams params) {
|
||||
return MacOSStorageCreationParams(
|
||||
controller: params.controller, webStorageType: params.webStorageType);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformStorage}
|
||||
abstract mixin class MacOSStorage implements PlatformStorage {
|
||||
@override
|
||||
MacOSInAppWebViewController? controller;
|
||||
|
||||
@override
|
||||
Future<int?> length() async {
|
||||
var result = await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.length;
|
||||
""");
|
||||
return result != null ? int.parse(json.decode(result)) : null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setItem({required String key, required dynamic value}) async {
|
||||
var encodedValue = json.encode(value);
|
||||
await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.setItem("$key", ${value is String ? encodedValue : "JSON.stringify($encodedValue)"});
|
||||
""");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<dynamic> getItem({required String key}) async {
|
||||
var itemValue = await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.getItem("$key");
|
||||
""");
|
||||
|
||||
if (itemValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return json.decode(itemValue);
|
||||
} catch (e) {}
|
||||
|
||||
return itemValue;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeItem({required String key}) async {
|
||||
await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.removeItem("$key");
|
||||
""");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<WebStorageItem>> getItems() async {
|
||||
var webStorageItems = <WebStorageItem>[];
|
||||
|
||||
List<Map<dynamic, dynamic>>? items =
|
||||
(await controller?.evaluateJavascript(source: """
|
||||
(function() {
|
||||
var webStorageItems = [];
|
||||
for(var i = 0; i < window.$webStorageType.length; i++){
|
||||
var key = window.$webStorageType.key(i);
|
||||
webStorageItems.push(
|
||||
{
|
||||
key: key,
|
||||
value: window.$webStorageType.getItem(key)
|
||||
}
|
||||
);
|
||||
}
|
||||
return webStorageItems;
|
||||
})();
|
||||
"""))?.cast<Map<dynamic, dynamic>>();
|
||||
|
||||
if (items == null) {
|
||||
return webStorageItems;
|
||||
}
|
||||
|
||||
for (var item in items) {
|
||||
webStorageItems
|
||||
.add(WebStorageItem(key: item["key"], value: item["value"]));
|
||||
}
|
||||
|
||||
return webStorageItems;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear() async {
|
||||
await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.clear();
|
||||
""");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> key({required int index}) async {
|
||||
var result = await controller?.evaluateJavascript(source: """
|
||||
window.$webStorageType.key($index);
|
||||
""");
|
||||
return result != null ? json.decode(result) : null;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSLocalStorage].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformLocalStorageCreationParams] for
|
||||
/// more information.
|
||||
class MacOSLocalStorageCreationParams
|
||||
extends PlatformLocalStorageCreationParams {
|
||||
/// Creates a new [MacOSLocalStorageCreationParams] instance.
|
||||
MacOSLocalStorageCreationParams(super.params);
|
||||
|
||||
/// Creates a [MacOSLocalStorageCreationParams] instance based on [PlatformLocalStorageCreationParams].
|
||||
factory MacOSLocalStorageCreationParams.fromPlatformLocalStorageCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformLocalStorageCreationParams params) {
|
||||
return MacOSLocalStorageCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformLocalStorage}
|
||||
class MacOSLocalStorage extends PlatformLocalStorage with MacOSStorage {
|
||||
/// Constructs a [MacOSLocalStorage].
|
||||
MacOSLocalStorage(PlatformLocalStorageCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSLocalStorageCreationParams
|
||||
? params
|
||||
: MacOSLocalStorageCreationParams
|
||||
.fromPlatformLocalStorageCreationParams(params),
|
||||
);
|
||||
|
||||
/// Default storage
|
||||
factory MacOSLocalStorage.defaultStorage(
|
||||
{required PlatformInAppWebViewController? controller}) {
|
||||
return MacOSLocalStorage(MacOSLocalStorageCreationParams(
|
||||
PlatformLocalStorageCreationParams(PlatformStorageCreationParams(
|
||||
controller: controller,
|
||||
webStorageType: WebStorageType.LOCAL_STORAGE))));
|
||||
}
|
||||
|
||||
@override
|
||||
MacOSInAppWebViewController? get controller =>
|
||||
params.controller as MacOSInAppWebViewController?;
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSSessionStorage].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformSessionStorageCreationParams] for
|
||||
/// more information.
|
||||
class MacOSSessionStorageCreationParams
|
||||
extends PlatformSessionStorageCreationParams {
|
||||
/// Creates a new [MacOSSessionStorageCreationParams] instance.
|
||||
MacOSSessionStorageCreationParams(super.params);
|
||||
|
||||
/// Creates a [MacOSSessionStorageCreationParams] instance based on [PlatformSessionStorageCreationParams].
|
||||
factory MacOSSessionStorageCreationParams.fromPlatformSessionStorageCreationParams(
|
||||
// Recommended placeholder to prevent being broken by platform interface.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformSessionStorageCreationParams params) {
|
||||
return MacOSSessionStorageCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformSessionStorage}
|
||||
class MacOSSessionStorage extends PlatformSessionStorage with MacOSStorage {
|
||||
/// Constructs a [MacOSSessionStorage].
|
||||
MacOSSessionStorage(PlatformSessionStorageCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSSessionStorageCreationParams
|
||||
? params
|
||||
: MacOSSessionStorageCreationParams
|
||||
.fromPlatformSessionStorageCreationParams(params),
|
||||
);
|
||||
|
||||
/// Default storage
|
||||
factory MacOSSessionStorage.defaultStorage(
|
||||
{required PlatformInAppWebViewController? controller}) {
|
||||
return MacOSSessionStorage(MacOSSessionStorageCreationParams(
|
||||
PlatformSessionStorageCreationParams(PlatformStorageCreationParams(
|
||||
controller: controller,
|
||||
webStorageType: WebStorageType.SESSION_STORAGE))));
|
||||
}
|
||||
|
||||
@override
|
||||
MacOSInAppWebViewController? get controller =>
|
||||
params.controller as MacOSInAppWebViewController?;
|
||||
}
|
||||
Vendored
Executable
+134
@@ -0,0 +1,134 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
|
||||
/// Object specifying creation parameters for creating a [MacOSWebStorageManager].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformWebStorageManagerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class MacOSWebStorageManagerCreationParams
|
||||
extends PlatformWebStorageManagerCreationParams {
|
||||
/// Creates a new [MacOSWebStorageManagerCreationParams] instance.
|
||||
const MacOSWebStorageManagerCreationParams(
|
||||
// This parameter prevents breaking changes later.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformWebStorageManagerCreationParams params,
|
||||
) : super();
|
||||
|
||||
/// Creates a [MacOSWebStorageManagerCreationParams] instance based on [PlatformWebStorageManagerCreationParams].
|
||||
factory MacOSWebStorageManagerCreationParams.fromPlatformWebStorageManagerCreationParams(
|
||||
PlatformWebStorageManagerCreationParams params) {
|
||||
return MacOSWebStorageManagerCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebStorageManager}
|
||||
class MacOSWebStorageManager extends PlatformWebStorageManager
|
||||
with ChannelController {
|
||||
/// Creates a new [MacOSWebStorageManager].
|
||||
MacOSWebStorageManager(PlatformWebStorageManagerCreationParams params)
|
||||
: super.implementation(
|
||||
params is MacOSWebStorageManagerCreationParams
|
||||
? params
|
||||
: MacOSWebStorageManagerCreationParams
|
||||
.fromPlatformWebStorageManagerCreationParams(params),
|
||||
) {
|
||||
channel = const MethodChannel(
|
||||
'com.pichillilorenzo/flutter_inappwebview_webstoragemanager');
|
||||
handler = handleMethod;
|
||||
initMethodCallHandler();
|
||||
}
|
||||
|
||||
static MacOSWebStorageManager? _instance;
|
||||
|
||||
///Gets the WebStorage manager shared instance.
|
||||
static MacOSWebStorageManager instance() {
|
||||
return (_instance != null) ? _instance! : _init();
|
||||
}
|
||||
|
||||
static MacOSWebStorageManager _init() {
|
||||
_instance = MacOSWebStorageManager(MacOSWebStorageManagerCreationParams(
|
||||
const PlatformWebStorageManagerCreationParams()));
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {}
|
||||
|
||||
@override
|
||||
Future<List<WebsiteDataRecord>> fetchDataRecords(
|
||||
{required Set<WebsiteDataType> dataTypes}) async {
|
||||
List<WebsiteDataRecord> recordList = [];
|
||||
List<String> dataTypesList = [];
|
||||
for (var dataType in dataTypes) {
|
||||
dataTypesList.add(dataType.toNativeValue());
|
||||
}
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("dataTypes", () => dataTypesList);
|
||||
List<Map<dynamic, dynamic>> records =
|
||||
(await channel?.invokeMethod<List>('fetchDataRecords', args))
|
||||
?.cast<Map<dynamic, dynamic>>() ??
|
||||
[];
|
||||
for (var record in records) {
|
||||
List<String> dataTypesString = record["dataTypes"].cast<String>();
|
||||
Set<WebsiteDataType> dataTypes = Set();
|
||||
for (var dataTypeValue in dataTypesString) {
|
||||
var dataType = WebsiteDataType.fromNativeValue(dataTypeValue);
|
||||
if (dataType != null) {
|
||||
dataTypes.add(dataType);
|
||||
}
|
||||
}
|
||||
recordList.add(WebsiteDataRecord(
|
||||
displayName: record["displayName"], dataTypes: dataTypes));
|
||||
}
|
||||
return recordList;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeDataFor(
|
||||
{required Set<WebsiteDataType> dataTypes,
|
||||
required List<WebsiteDataRecord> dataRecords}) async {
|
||||
List<String> dataTypesList = [];
|
||||
for (var dataType in dataTypes) {
|
||||
dataTypesList.add(dataType.toNativeValue());
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> recordList = [];
|
||||
for (var record in dataRecords) {
|
||||
recordList.add(record.toMap());
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("dataTypes", () => dataTypesList);
|
||||
args.putIfAbsent("recordList", () => recordList);
|
||||
await channel?.invokeMethod('removeDataFor', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeDataModifiedSince(
|
||||
{required Set<WebsiteDataType> dataTypes, required DateTime date}) async {
|
||||
List<String> dataTypesList = [];
|
||||
for (var dataType in dataTypes) {
|
||||
dataTypesList.add(dataType.toNativeValue());
|
||||
}
|
||||
|
||||
var timestamp = date.millisecondsSinceEpoch;
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("dataTypes", () => dataTypesList);
|
||||
args.putIfAbsent("timestamp", () => timestamp);
|
||||
await channel?.invokeMethod('removeDataModifiedSince', args);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
extension InternalWebStorageManager on MacOSWebStorageManager {
|
||||
get handleMethod => _handleMethod;
|
||||
}
|
||||
Reference in new issue
Block a user