diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h index b291f4167725..ebd29f5cacad 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.1.2), do not edit directly. +// Autogenerated from Pigeon (v3.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; @@ -79,12 +79,18 @@ typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { }; @class FWFNSKeyValueObservingOptionsEnumData; +@class FWFNSKeyValueChangeKeyEnumData; @class FWFWKUserScriptInjectionTimeEnumData; @class FWFWKAudiovisualMediaTypeEnumData; @class FWFWKWebsiteDataTypeEnumData; +@class FWFWKNavigationActionPolicyEnumData; @class FWFNSHttpCookiePropertyKeyEnumData; @class FWFNSUrlRequestData; @class FWFWKUserScriptData; +@class FWFWKNavigationActionData; +@class FWFWKFrameInfoData; +@class FWFNSErrorData; +@class FWFWKScriptMessageData; @class FWFNSHttpCookieData; @interface FWFNSKeyValueObservingOptionsEnumData : NSObject @@ -94,6 +100,13 @@ typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { @property(nonatomic, assign) FWFNSKeyValueObservingOptionsEnum value; @end +@interface FWFNSKeyValueChangeKeyEnumData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithValue:(FWFNSKeyValueChangeKeyEnum)value; +@property(nonatomic, assign) FWFNSKeyValueChangeKeyEnum value; +@end + @interface FWFWKUserScriptInjectionTimeEnumData : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; @@ -115,6 +128,13 @@ typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { @property(nonatomic, assign) FWFWKWebsiteDataTypeEnum value; @end +@interface FWFWKNavigationActionPolicyEnumData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithValue:(FWFWKNavigationActionPolicyEnum)value; +@property(nonatomic, assign) FWFWKNavigationActionPolicyEnum value; +@end + @interface FWFNSHttpCookiePropertyKeyEnumData : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; @@ -146,6 +166,41 @@ typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { @property(nonatomic, strong) NSNumber *isMainFrameOnly; @end +@interface FWFWKNavigationActionData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithRequest:(FWFNSUrlRequestData *)request + targetFrame:(FWFWKFrameInfoData *)targetFrame; +@property(nonatomic, strong) FWFNSUrlRequestData *request; +@property(nonatomic, strong) FWFWKFrameInfoData *targetFrame; +@end + +@interface FWFWKFrameInfoData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithIsMainFrame:(NSNumber *)isMainFrame; +@property(nonatomic, strong) NSNumber *isMainFrame; +@end + +@interface FWFNSErrorData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithCode:(NSNumber *)code + domain:(NSString *)domain + localizedDescription:(NSString *)localizedDescription; +@property(nonatomic, strong) NSNumber *code; +@property(nonatomic, copy) NSString *domain; +@property(nonatomic, copy) NSString *localizedDescription; +@end + +@interface FWFWKScriptMessageData : NSObject +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithName:(NSString *)name body:(id)body; +@property(nonatomic, copy) NSString *name; +@property(nonatomic, strong) id body; +@end + @interface FWFNSHttpCookieData : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; @@ -298,6 +353,16 @@ extern void FWFWKScriptMessageHandlerHostApiSetup( id binaryMessenger, NSObject *_Nullable api); +/// The codec used by FWFWKScriptMessageHandlerFlutterApi. +NSObject *FWFWKScriptMessageHandlerFlutterApiGetCodec(void); + +@interface FWFWKScriptMessageHandlerFlutterApi : NSObject +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; +- (void)didReceiveScriptMessageForHandlerWithIdentifier:(NSNumber *)identifier + userContentControllerIdentifier:(NSNumber *)userContentControllerIdentifier + message:(FWFWKScriptMessageData *)message + completion:(void (^)(NSError *_Nullable))completion; +@end /// The codec used by FWFWKNavigationDelegateHostApi. NSObject *FWFWKNavigationDelegateHostApiGetCodec(void); @@ -318,6 +383,33 @@ NSObject *FWFWKNavigationDelegateFlutterApiGetCodec(void); webViewIdentifier:(NSNumber *)webViewIdentifier URL:(nullable NSString *)url completion:(void (^)(NSError *_Nullable))completion; +- (void)didStartProvisionalNavigationForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + URL:(nullable NSString *)url + completion: + (void (^)(NSError *_Nullable))completion; +- (void) + decidePolicyForNavigationActionForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + navigationAction: + (FWFWKNavigationActionData *)navigationAction + completion: + (void (^)(FWFWKNavigationActionPolicyEnumData + *_Nullable, + NSError *_Nullable))completion; +- (void)didFailNavigationForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + error:(FWFNSErrorData *)error + completion:(void (^)(NSError *_Nullable))completion; +- (void)didFailProvisionalNavigationForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + error:(FWFNSErrorData *)error + completion: + (void (^)(NSError *_Nullable))completion; +- (void)webViewWebContentProcessDidTerminateForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + completion:(void (^)(NSError *_Nullable)) + completion; @end /// The codec used by FWFNSObjectHostApi. NSObject *FWFNSObjectHostApiGetCodec(void); @@ -345,6 +437,12 @@ NSObject *FWFNSObjectFlutterApiGetCodec(void); @interface FWFNSObjectFlutterApi : NSObject - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; +- (void)observeValueForObjectWithIdentifier:(NSNumber *)identifier + keyPath:(NSString *)keyPath + objectIdentifier:(NSNumber *)objectIdentifier + changeKeys:(NSArray *)changeKeys + changeValues:(NSArray *)changeValues + completion:(void (^)(NSError *_Nullable))completion; @end /// The codec used by FWFWKWebViewHostApi. NSObject *FWFWKWebViewHostApiGetCodec(void); @@ -420,6 +518,17 @@ NSObject *FWFWKUIDelegateHostApiGetCodec(void); extern void FWFWKUIDelegateHostApiSetup(id binaryMessenger, NSObject *_Nullable api); +/// The codec used by FWFWKUIDelegateFlutterApi. +NSObject *FWFWKUIDelegateFlutterApiGetCodec(void); + +@interface FWFWKUIDelegateFlutterApi : NSObject +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; +- (void)onCreateWebViewForDelegateWithIdentifier:(NSNumber *)identifier + webViewIdentifier:(NSNumber *)webViewIdentifier + configurationIdentifier:(NSNumber *)configurationIdentifier + navigationAction:(FWFWKNavigationActionData *)navigationAction + completion:(void (^)(NSError *_Nullable))completion; +@end /// The codec used by FWFWKHttpCookieStoreHostApi. NSObject *FWFWKHttpCookieStoreHostApiGetCodec(void); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m index f936d151ddd3..592fa87ac9d1 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.1.2), do not edit directly. +// Autogenerated from Pigeon (v3.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "FWFGeneratedWebKitApis.h" #import @@ -37,6 +37,10 @@ @interface FWFNSKeyValueObservingOptionsEnumData () + (FWFNSKeyValueObservingOptionsEnumData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @end +@interface FWFNSKeyValueChangeKeyEnumData () ++ (FWFNSKeyValueChangeKeyEnumData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end @interface FWFWKUserScriptInjectionTimeEnumData () + (FWFWKUserScriptInjectionTimeEnumData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @@ -49,6 +53,10 @@ @interface FWFWKWebsiteDataTypeEnumData () + (FWFWKWebsiteDataTypeEnumData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @end +@interface FWFWKNavigationActionPolicyEnumData () ++ (FWFWKNavigationActionPolicyEnumData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end @interface FWFNSHttpCookiePropertyKeyEnumData () + (FWFNSHttpCookiePropertyKeyEnumData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @@ -61,6 +69,22 @@ @interface FWFWKUserScriptData () + (FWFWKUserScriptData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @end +@interface FWFWKNavigationActionData () ++ (FWFWKNavigationActionData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end +@interface FWFWKFrameInfoData () ++ (FWFWKFrameInfoData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end +@interface FWFNSErrorData () ++ (FWFNSErrorData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end +@interface FWFWKScriptMessageData () ++ (FWFWKScriptMessageData *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end @interface FWFNSHttpCookieData () + (FWFNSHttpCookieData *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @@ -86,6 +110,24 @@ - (NSDictionary *)toMap { } @end +@implementation FWFNSKeyValueChangeKeyEnumData ++ (instancetype)makeWithValue:(FWFNSKeyValueChangeKeyEnum)value { + FWFNSKeyValueChangeKeyEnumData *pigeonResult = [[FWFNSKeyValueChangeKeyEnumData alloc] init]; + pigeonResult.value = value; + return pigeonResult; +} ++ (FWFNSKeyValueChangeKeyEnumData *)fromMap:(NSDictionary *)dict { + FWFNSKeyValueChangeKeyEnumData *pigeonResult = [[FWFNSKeyValueChangeKeyEnumData alloc] init]; + pigeonResult.value = [GetNullableObject(dict, @"value") integerValue]; + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"value" : @(self.value), + }; +} +@end + @implementation FWFWKUserScriptInjectionTimeEnumData + (instancetype)makeWithValue:(FWFWKUserScriptInjectionTimeEnum)value { FWFWKUserScriptInjectionTimeEnumData *pigeonResult = @@ -144,6 +186,26 @@ - (NSDictionary *)toMap { } @end +@implementation FWFWKNavigationActionPolicyEnumData ++ (instancetype)makeWithValue:(FWFWKNavigationActionPolicyEnum)value { + FWFWKNavigationActionPolicyEnumData *pigeonResult = + [[FWFWKNavigationActionPolicyEnumData alloc] init]; + pigeonResult.value = value; + return pigeonResult; +} ++ (FWFWKNavigationActionPolicyEnumData *)fromMap:(NSDictionary *)dict { + FWFWKNavigationActionPolicyEnumData *pigeonResult = + [[FWFWKNavigationActionPolicyEnumData alloc] init]; + pigeonResult.value = [GetNullableObject(dict, @"value") integerValue]; + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"value" : @(self.value), + }; +} +@end + @implementation FWFNSHttpCookiePropertyKeyEnumData + (instancetype)makeWithValue:(FWFNSHttpCookiePropertyKeyEnum)value { FWFNSHttpCookiePropertyKeyEnumData *pigeonResult = @@ -225,6 +287,100 @@ - (NSDictionary *)toMap { } @end +@implementation FWFWKNavigationActionData ++ (instancetype)makeWithRequest:(FWFNSUrlRequestData *)request + targetFrame:(FWFWKFrameInfoData *)targetFrame { + FWFWKNavigationActionData *pigeonResult = [[FWFWKNavigationActionData alloc] init]; + pigeonResult.request = request; + pigeonResult.targetFrame = targetFrame; + return pigeonResult; +} ++ (FWFWKNavigationActionData *)fromMap:(NSDictionary *)dict { + FWFWKNavigationActionData *pigeonResult = [[FWFWKNavigationActionData alloc] init]; + pigeonResult.request = [FWFNSUrlRequestData fromMap:GetNullableObject(dict, @"request")]; + NSAssert(pigeonResult.request != nil, @""); + pigeonResult.targetFrame = [FWFWKFrameInfoData fromMap:GetNullableObject(dict, @"targetFrame")]; + NSAssert(pigeonResult.targetFrame != nil, @""); + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"request" : (self.request ? [self.request toMap] : [NSNull null]), + @"targetFrame" : (self.targetFrame ? [self.targetFrame toMap] : [NSNull null]), + }; +} +@end + +@implementation FWFWKFrameInfoData ++ (instancetype)makeWithIsMainFrame:(NSNumber *)isMainFrame { + FWFWKFrameInfoData *pigeonResult = [[FWFWKFrameInfoData alloc] init]; + pigeonResult.isMainFrame = isMainFrame; + return pigeonResult; +} ++ (FWFWKFrameInfoData *)fromMap:(NSDictionary *)dict { + FWFWKFrameInfoData *pigeonResult = [[FWFWKFrameInfoData alloc] init]; + pigeonResult.isMainFrame = GetNullableObject(dict, @"isMainFrame"); + NSAssert(pigeonResult.isMainFrame != nil, @""); + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"isMainFrame" : (self.isMainFrame ?: [NSNull null]), + }; +} +@end + +@implementation FWFNSErrorData ++ (instancetype)makeWithCode:(NSNumber *)code + domain:(NSString *)domain + localizedDescription:(NSString *)localizedDescription { + FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; + pigeonResult.code = code; + pigeonResult.domain = domain; + pigeonResult.localizedDescription = localizedDescription; + return pigeonResult; +} ++ (FWFNSErrorData *)fromMap:(NSDictionary *)dict { + FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; + pigeonResult.code = GetNullableObject(dict, @"code"); + NSAssert(pigeonResult.code != nil, @""); + pigeonResult.domain = GetNullableObject(dict, @"domain"); + NSAssert(pigeonResult.domain != nil, @""); + pigeonResult.localizedDescription = GetNullableObject(dict, @"localizedDescription"); + NSAssert(pigeonResult.localizedDescription != nil, @""); + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"code" : (self.code ?: [NSNull null]), + @"domain" : (self.domain ?: [NSNull null]), + @"localizedDescription" : (self.localizedDescription ?: [NSNull null]), + }; +} +@end + +@implementation FWFWKScriptMessageData ++ (instancetype)makeWithName:(NSString *)name body:(id)body { + FWFWKScriptMessageData *pigeonResult = [[FWFWKScriptMessageData alloc] init]; + pigeonResult.name = name; + pigeonResult.body = body; + return pigeonResult; +} ++ (FWFWKScriptMessageData *)fromMap:(NSDictionary *)dict { + FWFWKScriptMessageData *pigeonResult = [[FWFWKScriptMessageData alloc] init]; + pigeonResult.name = GetNullableObject(dict, @"name"); + NSAssert(pigeonResult.name != nil, @""); + pigeonResult.body = GetNullableObject(dict, @"body"); + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"name" : (self.name ?: [NSNull null]), + @"body" : (self.body ?: [NSNull null]), + }; +} +@end + @implementation FWFNSHttpCookieData + (instancetype)makeWithPropertyKeys:(NSArray *)propertyKeys propertyValues:(NSArray *)propertyValues { @@ -1095,6 +1251,87 @@ void FWFWKScriptMessageHandlerHostApiSetup(id binaryMess } } } +@interface FWFWKScriptMessageHandlerFlutterApiCodecReader : FlutterStandardReader +@end +@implementation FWFWKScriptMessageHandlerFlutterApiCodecReader +- (nullable id)readValueOfType:(UInt8)type { + switch (type) { + case 128: + return [FWFWKScriptMessageData fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + } +} +@end + +@interface FWFWKScriptMessageHandlerFlutterApiCodecWriter : FlutterStandardWriter +@end +@implementation FWFWKScriptMessageHandlerFlutterApiCodecWriter +- (void)writeValue:(id)value { + if ([value isKindOfClass:[FWFWKScriptMessageData class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else { + [super writeValue:value]; + } +} +@end + +@interface FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter : FlutterStandardReaderWriter +@end +@implementation FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter +- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { + return [[FWFWKScriptMessageHandlerFlutterApiCodecWriter alloc] initWithData:data]; +} +- (FlutterStandardReader *)readerWithData:(NSData *)data { + return [[FWFWKScriptMessageHandlerFlutterApiCodecReader alloc] initWithData:data]; +} +@end + +NSObject *FWFWKScriptMessageHandlerFlutterApiGetCodec() { + static dispatch_once_t sPred = 0; + static FlutterStandardMessageCodec *sSharedObject = nil; + dispatch_once(&sPred, ^{ + FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter *readerWriter = + [[FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter alloc] init]; + sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + }); + return sSharedObject; +} + +@interface FWFWKScriptMessageHandlerFlutterApi () +@property(nonatomic, strong) NSObject *binaryMessenger; +@end + +@implementation FWFWKScriptMessageHandlerFlutterApi + +- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { + self = [super init]; + if (self) { + _binaryMessenger = binaryMessenger; + } + return self; +} +- (void)didReceiveScriptMessageForHandlerWithIdentifier:(NSNumber *)arg_identifier + userContentControllerIdentifier: + (NSNumber *)arg_userContentControllerIdentifier + message:(FWFWKScriptMessageData *)arg_message + completion:(void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage" + binaryMessenger:self.binaryMessenger + codec:FWFWKScriptMessageHandlerFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_userContentControllerIdentifier ?: [NSNull null], + arg_message ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +@end @interface FWFWKNavigationDelegateHostApiCodecReader : FlutterStandardReader @end @implementation FWFWKNavigationDelegateHostApiCodecReader @@ -1154,11 +1391,52 @@ void FWFWKNavigationDelegateHostApiSetup(id binaryMessen @interface FWFWKNavigationDelegateFlutterApiCodecReader : FlutterStandardReader @end @implementation FWFWKNavigationDelegateFlutterApiCodecReader +- (nullable id)readValueOfType:(UInt8)type { + switch (type) { + case 128: + return [FWFNSErrorData fromMap:[self readValue]]; + + case 129: + return [FWFNSUrlRequestData fromMap:[self readValue]]; + + case 130: + return [FWFWKFrameInfoData fromMap:[self readValue]]; + + case 131: + return [FWFWKNavigationActionData fromMap:[self readValue]]; + + case 132: + return [FWFWKNavigationActionPolicyEnumData fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + } +} @end @interface FWFWKNavigationDelegateFlutterApiCodecWriter : FlutterStandardWriter @end @implementation FWFWKNavigationDelegateFlutterApiCodecWriter +- (void)writeValue:(id)value { + if ([value isKindOfClass:[FWFNSErrorData class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { + [self writeByte:129]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { + [self writeByte:130]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { + [self writeByte:131]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionPolicyEnumData class]]) { + [self writeByte:132]; + [self writeValue:[value toMap]]; + } else { + [super writeValue:value]; + } +} @end @interface FWFWKNavigationDelegateFlutterApiCodecReaderWriter : FlutterStandardReaderWriter @@ -1213,6 +1491,96 @@ - (void)didFinishNavigationForDelegateWithIdentifier:(NSNumber *)arg_identifier completion(nil); }]; } +- (void)didStartProvisionalNavigationForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier + URL:(nullable NSString *)arg_url + completion: + (void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation" + binaryMessenger:self.binaryMessenger + codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_url ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +- (void) + decidePolicyForNavigationActionForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier + navigationAction: + (FWFWKNavigationActionData *)arg_navigationAction + completion: + (void (^)(FWFWKNavigationActionPolicyEnumData + *_Nullable, + NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction" + binaryMessenger:self.binaryMessenger + codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_navigationAction ?: [NSNull null] + ] + reply:^(id reply) { + FWFWKNavigationActionPolicyEnumData *output = reply; + completion(output, nil); + }]; +} +- (void)didFailNavigationForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier + error:(FWFNSErrorData *)arg_error + completion:(void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation" + binaryMessenger:self.binaryMessenger + codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_error ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +- (void)didFailProvisionalNavigationForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier + error:(FWFNSErrorData *)arg_error + completion: + (void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation" + binaryMessenger:self.binaryMessenger + codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_error ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +- (void)webViewWebContentProcessDidTerminateForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier: + (NSNumber *)arg_webViewIdentifier + completion:(void (^)(NSError *_Nullable)) + completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName: + @"dev.flutter.pigeon.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate" + binaryMessenger:self.binaryMessenger + codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null] ] + reply:^(id reply) { + completion(nil); + }]; +} @end @interface FWFNSObjectHostApiCodecReader : FlutterStandardReader @end @@ -1350,11 +1718,106 @@ void FWFNSObjectHostApiSetup(id binaryMessenger, @interface FWFNSObjectFlutterApiCodecReader : FlutterStandardReader @end @implementation FWFNSObjectFlutterApiCodecReader +- (nullable id)readValueOfType:(UInt8)type { + switch (type) { + case 128: + return [FWFNSErrorData fromMap:[self readValue]]; + + case 129: + return [FWFNSHttpCookieData fromMap:[self readValue]]; + + case 130: + return [FWFNSHttpCookiePropertyKeyEnumData fromMap:[self readValue]]; + + case 131: + return [FWFNSKeyValueChangeKeyEnumData fromMap:[self readValue]]; + + case 132: + return [FWFNSKeyValueObservingOptionsEnumData fromMap:[self readValue]]; + + case 133: + return [FWFNSUrlRequestData fromMap:[self readValue]]; + + case 134: + return [FWFWKAudiovisualMediaTypeEnumData fromMap:[self readValue]]; + + case 135: + return [FWFWKFrameInfoData fromMap:[self readValue]]; + + case 136: + return [FWFWKNavigationActionData fromMap:[self readValue]]; + + case 137: + return [FWFWKNavigationActionPolicyEnumData fromMap:[self readValue]]; + + case 138: + return [FWFWKScriptMessageData fromMap:[self readValue]]; + + case 139: + return [FWFWKUserScriptData fromMap:[self readValue]]; + + case 140: + return [FWFWKUserScriptInjectionTimeEnumData fromMap:[self readValue]]; + + case 141: + return [FWFWKWebsiteDataTypeEnumData fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + } +} @end @interface FWFNSObjectFlutterApiCodecWriter : FlutterStandardWriter @end @implementation FWFNSObjectFlutterApiCodecWriter +- (void)writeValue:(id)value { + if ([value isKindOfClass:[FWFNSErrorData class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSHttpCookieData class]]) { + [self writeByte:129]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSHttpCookiePropertyKeyEnumData class]]) { + [self writeByte:130]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSKeyValueChangeKeyEnumData class]]) { + [self writeByte:131]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSKeyValueObservingOptionsEnumData class]]) { + [self writeByte:132]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { + [self writeByte:133]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKAudiovisualMediaTypeEnumData class]]) { + [self writeByte:134]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { + [self writeByte:135]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { + [self writeByte:136]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionPolicyEnumData class]]) { + [self writeByte:137]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKScriptMessageData class]]) { + [self writeByte:138]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKUserScriptData class]]) { + [self writeByte:139]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKUserScriptInjectionTimeEnumData class]]) { + [self writeByte:140]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKWebsiteDataTypeEnumData class]]) { + [self writeByte:141]; + [self writeValue:[value toMap]]; + } else { + [super writeValue:value]; + } +} @end @interface FWFNSObjectFlutterApiCodecReaderWriter : FlutterStandardReaderWriter @@ -1392,6 +1855,26 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina } return self; } +- (void)observeValueForObjectWithIdentifier:(NSNumber *)arg_identifier + keyPath:(NSString *)arg_keyPath + objectIdentifier:(NSNumber *)arg_objectIdentifier + changeKeys: + (NSArray *)arg_changeKeys + changeValues:(NSArray *)arg_changeValues + completion:(void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.NSObjectFlutterApi.observeValue" + binaryMessenger:self.binaryMessenger + codec:FWFNSObjectFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_keyPath ?: [NSNull null], + arg_objectIdentifier ?: [NSNull null], arg_changeKeys ?: [NSNull null], + arg_changeValues ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} @end @interface FWFWKWebViewHostApiCodecReader : FlutterStandardReader @end @@ -1399,27 +1882,45 @@ @implementation FWFWKWebViewHostApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [FWFNSHttpCookieData fromMap:[self readValue]]; + return [FWFNSErrorData fromMap:[self readValue]]; case 129: - return [FWFNSHttpCookiePropertyKeyEnumData fromMap:[self readValue]]; + return [FWFNSHttpCookieData fromMap:[self readValue]]; case 130: - return [FWFNSKeyValueObservingOptionsEnumData fromMap:[self readValue]]; + return [FWFNSHttpCookiePropertyKeyEnumData fromMap:[self readValue]]; case 131: - return [FWFNSUrlRequestData fromMap:[self readValue]]; + return [FWFNSKeyValueChangeKeyEnumData fromMap:[self readValue]]; case 132: - return [FWFWKAudiovisualMediaTypeEnumData fromMap:[self readValue]]; + return [FWFNSKeyValueObservingOptionsEnumData fromMap:[self readValue]]; case 133: - return [FWFWKUserScriptData fromMap:[self readValue]]; + return [FWFNSUrlRequestData fromMap:[self readValue]]; case 134: - return [FWFWKUserScriptInjectionTimeEnumData fromMap:[self readValue]]; + return [FWFWKAudiovisualMediaTypeEnumData fromMap:[self readValue]]; case 135: + return [FWFWKFrameInfoData fromMap:[self readValue]]; + + case 136: + return [FWFWKNavigationActionData fromMap:[self readValue]]; + + case 137: + return [FWFWKNavigationActionPolicyEnumData fromMap:[self readValue]]; + + case 138: + return [FWFWKScriptMessageData fromMap:[self readValue]]; + + case 139: + return [FWFWKUserScriptData fromMap:[self readValue]]; + + case 140: + return [FWFWKUserScriptInjectionTimeEnumData fromMap:[self readValue]]; + + case 141: return [FWFWKWebsiteDataTypeEnumData fromMap:[self readValue]]; default: @@ -1432,30 +1933,48 @@ @interface FWFWKWebViewHostApiCodecWriter : FlutterStandardWriter @end @implementation FWFWKWebViewHostApiCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFNSHttpCookieData class]]) { + if ([value isKindOfClass:[FWFNSErrorData class]]) { [self writeByte:128]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFNSHttpCookiePropertyKeyEnumData class]]) { + } else if ([value isKindOfClass:[FWFNSHttpCookieData class]]) { [self writeByte:129]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFNSKeyValueObservingOptionsEnumData class]]) { + } else if ([value isKindOfClass:[FWFNSHttpCookiePropertyKeyEnumData class]]) { [self writeByte:130]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { + } else if ([value isKindOfClass:[FWFNSKeyValueChangeKeyEnumData class]]) { [self writeByte:131]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFWKAudiovisualMediaTypeEnumData class]]) { + } else if ([value isKindOfClass:[FWFNSKeyValueObservingOptionsEnumData class]]) { [self writeByte:132]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFWKUserScriptData class]]) { + } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { [self writeByte:133]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFWKUserScriptInjectionTimeEnumData class]]) { + } else if ([value isKindOfClass:[FWFWKAudiovisualMediaTypeEnumData class]]) { [self writeByte:134]; [self writeValue:[value toMap]]; - } else if ([value isKindOfClass:[FWFWKWebsiteDataTypeEnumData class]]) { + } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { [self writeByte:135]; [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { + [self writeByte:136]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionPolicyEnumData class]]) { + [self writeByte:137]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKScriptMessageData class]]) { + [self writeByte:138]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKUserScriptData class]]) { + [self writeByte:139]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKUserScriptInjectionTimeEnumData class]]) { + [self writeByte:140]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKWebsiteDataTypeEnumData class]]) { + [self writeByte:141]; + [self writeValue:[value toMap]]; } else { [super writeValue:value]; } @@ -1967,6 +2486,98 @@ void FWFWKUIDelegateHostApiSetup(id binaryMessenger, } } } +@interface FWFWKUIDelegateFlutterApiCodecReader : FlutterStandardReader +@end +@implementation FWFWKUIDelegateFlutterApiCodecReader +- (nullable id)readValueOfType:(UInt8)type { + switch (type) { + case 128: + return [FWFNSUrlRequestData fromMap:[self readValue]]; + + case 129: + return [FWFWKFrameInfoData fromMap:[self readValue]]; + + case 130: + return [FWFWKNavigationActionData fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + } +} +@end + +@interface FWFWKUIDelegateFlutterApiCodecWriter : FlutterStandardWriter +@end +@implementation FWFWKUIDelegateFlutterApiCodecWriter +- (void)writeValue:(id)value { + if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { + [self writeByte:129]; + [self writeValue:[value toMap]]; + } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { + [self writeByte:130]; + [self writeValue:[value toMap]]; + } else { + [super writeValue:value]; + } +} +@end + +@interface FWFWKUIDelegateFlutterApiCodecReaderWriter : FlutterStandardReaderWriter +@end +@implementation FWFWKUIDelegateFlutterApiCodecReaderWriter +- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { + return [[FWFWKUIDelegateFlutterApiCodecWriter alloc] initWithData:data]; +} +- (FlutterStandardReader *)readerWithData:(NSData *)data { + return [[FWFWKUIDelegateFlutterApiCodecReader alloc] initWithData:data]; +} +@end + +NSObject *FWFWKUIDelegateFlutterApiGetCodec() { + static dispatch_once_t sPred = 0; + static FlutterStandardMessageCodec *sSharedObject = nil; + dispatch_once(&sPred, ^{ + FWFWKUIDelegateFlutterApiCodecReaderWriter *readerWriter = + [[FWFWKUIDelegateFlutterApiCodecReaderWriter alloc] init]; + sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + }); + return sSharedObject; +} + +@interface FWFWKUIDelegateFlutterApi () +@property(nonatomic, strong) NSObject *binaryMessenger; +@end + +@implementation FWFWKUIDelegateFlutterApi + +- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { + self = [super init]; + if (self) { + _binaryMessenger = binaryMessenger; + } + return self; +} +- (void)onCreateWebViewForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier + configurationIdentifier:(NSNumber *)arg_configurationIdentifier + navigationAction:(FWFWKNavigationActionData *)arg_navigationAction + completion:(void (^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView" + binaryMessenger:self.binaryMessenger + codec:FWFWKUIDelegateFlutterApiGetCodec()]; + [channel sendMessage:@[ + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_configurationIdentifier ?: [NSNull null], arg_navigationAction ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +@end @interface FWFWKHttpCookieStoreHostApiCodecReader : FlutterStandardReader @end @implementation FWFWKHttpCookieStoreHostApiCodecReader diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.pigeon.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.pigeon.dart index 9d928a38a2ef..c1971f09d068 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.pigeon.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.pigeon.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.1.2), do not edit directly. +// Autogenerated from Pigeon (v3.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name // @dart = 2.12 @@ -99,6 +99,27 @@ class NSKeyValueObservingOptionsEnumData { } } +class NSKeyValueChangeKeyEnumData { + NSKeyValueChangeKeyEnumData({ + required this.value, + }); + + NSKeyValueChangeKeyEnum value; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['value'] = value.index; + return pigeonMap; + } + + static NSKeyValueChangeKeyEnumData decode(Object message) { + final Map pigeonMap = message as Map; + return NSKeyValueChangeKeyEnumData( + value: NSKeyValueChangeKeyEnum.values[pigeonMap['value']! as int], + ); + } +} + class WKUserScriptInjectionTimeEnumData { WKUserScriptInjectionTimeEnumData({ required this.value, @@ -162,6 +183,27 @@ class WKWebsiteDataTypeEnumData { } } +class WKNavigationActionPolicyEnumData { + WKNavigationActionPolicyEnumData({ + required this.value, + }); + + WKNavigationActionPolicyEnum value; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['value'] = value.index; + return pigeonMap; + } + + static WKNavigationActionPolicyEnumData decode(Object message) { + final Map pigeonMap = message as Map; + return WKNavigationActionPolicyEnumData( + value: WKNavigationActionPolicyEnum.values[pigeonMap['value']! as int], + ); + } +} + class NSHttpCookiePropertyKeyEnumData { NSHttpCookiePropertyKeyEnumData({ required this.value, @@ -250,6 +292,106 @@ class WKUserScriptData { } } +class WKNavigationActionData { + WKNavigationActionData({ + required this.request, + required this.targetFrame, + }); + + NSUrlRequestData request; + WKFrameInfoData targetFrame; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['request'] = request.encode(); + pigeonMap['targetFrame'] = targetFrame.encode(); + return pigeonMap; + } + + static WKNavigationActionData decode(Object message) { + final Map pigeonMap = message as Map; + return WKNavigationActionData( + request: NSUrlRequestData.decode(pigeonMap['request']!), + targetFrame: WKFrameInfoData.decode(pigeonMap['targetFrame']!), + ); + } +} + +class WKFrameInfoData { + WKFrameInfoData({ + required this.isMainFrame, + }); + + bool isMainFrame; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['isMainFrame'] = isMainFrame; + return pigeonMap; + } + + static WKFrameInfoData decode(Object message) { + final Map pigeonMap = message as Map; + return WKFrameInfoData( + isMainFrame: pigeonMap['isMainFrame']! as bool, + ); + } +} + +class NSErrorData { + NSErrorData({ + required this.code, + required this.domain, + required this.localizedDescription, + }); + + int code; + String domain; + String localizedDescription; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['code'] = code; + pigeonMap['domain'] = domain; + pigeonMap['localizedDescription'] = localizedDescription; + return pigeonMap; + } + + static NSErrorData decode(Object message) { + final Map pigeonMap = message as Map; + return NSErrorData( + code: pigeonMap['code']! as int, + domain: pigeonMap['domain']! as String, + localizedDescription: pigeonMap['localizedDescription']! as String, + ); + } +} + +class WKScriptMessageData { + WKScriptMessageData({ + required this.name, + this.body, + }); + + String name; + Object? body; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['name'] = name; + pigeonMap['body'] = body; + return pigeonMap; + } + + static WKScriptMessageData decode(Object message) { + final Map pigeonMap = message as Map; + return WKScriptMessageData( + name: pigeonMap['name']! as String, + body: pigeonMap['body'] as Object?, + ); + } +} + class NSHttpCookieData { NSHttpCookieData({ required this.propertyKeys, @@ -1035,6 +1177,69 @@ class WKScriptMessageHandlerHostApi { } } +class _WKScriptMessageHandlerFlutterApiCodec extends StandardMessageCodec { + const _WKScriptMessageHandlerFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is WKScriptMessageData) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return WKScriptMessageData.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + } + } +} + +abstract class WKScriptMessageHandlerFlutterApi { + static const MessageCodec codec = + _WKScriptMessageHandlerFlutterApiCodec(); + + void didReceiveScriptMessage(int identifier, + int userContentControllerIdentifier, WKScriptMessageData message); + static void setup(WKScriptMessageHandlerFlutterApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null int.'); + final int? arg_userContentControllerIdentifier = (args[1] as int?); + assert(arg_userContentControllerIdentifier != null, + 'Argument for dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null int.'); + final WKScriptMessageData? arg_message = + (args[2] as WKScriptMessageData?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null WKScriptMessageData.'); + api.didReceiveScriptMessage(arg_identifier!, + arg_userContentControllerIdentifier!, arg_message!); + return; + }); + } + } + } +} + class _WKNavigationDelegateHostApiCodec extends StandardMessageCodec { const _WKNavigationDelegateHostApiCodec(); } @@ -1078,6 +1283,50 @@ class WKNavigationDelegateHostApi { class _WKNavigationDelegateFlutterApiCodec extends StandardMessageCodec { const _WKNavigationDelegateFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is NSErrorData) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is NSUrlRequestData) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is WKFrameInfoData) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionData) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionPolicyEnumData) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return NSErrorData.decode(readValue(buffer)!); + + case 129: + return NSUrlRequestData.decode(readValue(buffer)!); + + case 130: + return WKFrameInfoData.decode(readValue(buffer)!); + + case 131: + return WKNavigationActionData.decode(readValue(buffer)!); + + case 132: + return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + } + } } abstract class WKNavigationDelegateFlutterApi { @@ -1085,6 +1334,18 @@ abstract class WKNavigationDelegateFlutterApi { _WKNavigationDelegateFlutterApiCodec(); void didFinishNavigation(int identifier, int webViewIdentifier, String? url); + void didStartProvisionalNavigation( + int identifier, int webViewIdentifier, String? url); + Future decidePolicyForNavigationAction( + int identifier, + int webViewIdentifier, + WKNavigationActionData navigationAction); + void didFailNavigation( + int identifier, int webViewIdentifier, NSErrorData error); + void didFailProvisionalNavigation( + int identifier, int webViewIdentifier, NSErrorData error); + void webViewWebContentProcessDidTerminate( + int identifier, int webViewIdentifier); static void setup(WKNavigationDelegateFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -1112,6 +1373,138 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null, expected non-null int.'); + final String? arg_url = (args[2] as String?); + api.didStartProvisionalNavigation( + arg_identifier!, arg_webViewIdentifier!, arg_url); + return; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null int.'); + final WKNavigationActionData? arg_navigationAction = + (args[2] as WKNavigationActionData?); + assert(arg_navigationAction != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null WKNavigationActionData.'); + final WKNavigationActionPolicyEnumData output = + await api.decidePolicyForNavigationAction(arg_identifier!, + arg_webViewIdentifier!, arg_navigationAction!); + return output; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null int.'); + final NSErrorData? arg_error = (args[2] as NSErrorData?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null NSErrorData.'); + api.didFailNavigation( + arg_identifier!, arg_webViewIdentifier!, arg_error!); + return; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null int.'); + final NSErrorData? arg_error = (args[2] as NSErrorData?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null NSErrorData.'); + api.didFailProvisionalNavigation( + arg_identifier!, arg_webViewIdentifier!, arg_error!); + return; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null, expected non-null int.'); + api.webViewWebContentProcessDidTerminate( + arg_identifier!, arg_webViewIdentifier!); + return; + }); + } + } } } @@ -1235,43 +1628,200 @@ class NSObjectHostApi { class _NSObjectFlutterApiCodec extends StandardMessageCodec { const _NSObjectFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is NSErrorData) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is NSHttpCookieData) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is NSHttpCookiePropertyKeyEnumData) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is NSKeyValueChangeKeyEnumData) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is NSKeyValueObservingOptionsEnumData) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is NSUrlRequestData) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is WKAudiovisualMediaTypeEnumData) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); + } else if (value is WKFrameInfoData) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionData) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionPolicyEnumData) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else if (value is WKScriptMessageData) { + buffer.putUint8(138); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptData) { + buffer.putUint8(139); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptInjectionTimeEnumData) { + buffer.putUint8(140); + writeValue(buffer, value.encode()); + } else if (value is WKWebsiteDataTypeEnumData) { + buffer.putUint8(141); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return NSErrorData.decode(readValue(buffer)!); + + case 129: + return NSHttpCookieData.decode(readValue(buffer)!); + + case 130: + return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); + + case 131: + return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); + + case 132: + return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); + + case 133: + return NSUrlRequestData.decode(readValue(buffer)!); + + case 134: + return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); + + case 135: + return WKFrameInfoData.decode(readValue(buffer)!); + + case 136: + return WKNavigationActionData.decode(readValue(buffer)!); + + case 137: + return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); + + case 138: + return WKScriptMessageData.decode(readValue(buffer)!); + + case 139: + return WKUserScriptData.decode(readValue(buffer)!); + + case 140: + return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); + + case 141: + return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + } + } } abstract class NSObjectFlutterApi { static const MessageCodec codec = _NSObjectFlutterApiCodec(); + void observeValue( + int identifier, + String keyPath, + int objectIdentifier, + List changeKeys, + List changeValues); static void setup(NSObjectFlutterApi? api, - {BinaryMessenger? binaryMessenger}) {} + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.NSObjectFlutterApi.observeValue', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null, expected non-null int.'); + final String? arg_keyPath = (args[1] as String?); + assert(arg_keyPath != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null, expected non-null String.'); + final int? arg_objectIdentifier = (args[2] as int?); + assert(arg_objectIdentifier != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null, expected non-null int.'); + final List? arg_changeKeys = + (args[3] as List?)?.cast(); + assert(arg_changeKeys != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null, expected non-null List.'); + final List? arg_changeValues = + (args[4] as List?)?.cast(); + assert(arg_changeValues != null, + 'Argument for dev.flutter.pigeon.NSObjectFlutterApi.observeValue was null, expected non-null List.'); + api.observeValue(arg_identifier!, arg_keyPath!, arg_objectIdentifier!, + arg_changeKeys!, arg_changeValues!); + return; + }); + } + } + } } class _WKWebViewHostApiCodec extends StandardMessageCodec { const _WKWebViewHostApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSHttpCookieData) { + if (value is NSErrorData) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { + } else if (value is NSHttpCookieData) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is NSKeyValueObservingOptionsEnumData) { + } else if (value is NSHttpCookiePropertyKeyEnumData) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is NSUrlRequestData) { + } else if (value is NSKeyValueChangeKeyEnumData) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is WKAudiovisualMediaTypeEnumData) { + } else if (value is NSKeyValueObservingOptionsEnumData) { buffer.putUint8(132); writeValue(buffer, value.encode()); - } else if (value is WKUserScriptData) { + } else if (value is NSUrlRequestData) { buffer.putUint8(133); writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { + } else if (value is WKAudiovisualMediaTypeEnumData) { buffer.putUint8(134); writeValue(buffer, value.encode()); - } else if (value is WKWebsiteDataTypeEnumData) { + } else if (value is WKFrameInfoData) { buffer.putUint8(135); writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionData) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionPolicyEnumData) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else if (value is WKScriptMessageData) { + buffer.putUint8(138); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptData) { + buffer.putUint8(139); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptInjectionTimeEnumData) { + buffer.putUint8(140); + writeValue(buffer, value.encode()); + } else if (value is WKWebsiteDataTypeEnumData) { + buffer.putUint8(141); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -1281,27 +1831,45 @@ class _WKWebViewHostApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return NSHttpCookieData.decode(readValue(buffer)!); + return NSErrorData.decode(readValue(buffer)!); case 129: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); + return NSHttpCookieData.decode(readValue(buffer)!); case 130: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); + return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); case 131: - return NSUrlRequestData.decode(readValue(buffer)!); + return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); case 132: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); + return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); case 133: - return WKUserScriptData.decode(readValue(buffer)!); + return NSUrlRequestData.decode(readValue(buffer)!); case 134: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); + return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); case 135: + return WKFrameInfoData.decode(readValue(buffer)!); + + case 136: + return WKNavigationActionData.decode(readValue(buffer)!); + + case 137: + return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); + + case 138: + return WKScriptMessageData.decode(readValue(buffer)!); + + case 139: + return WKUserScriptData.decode(readValue(buffer)!); + + case 140: + return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); + + case 141: return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); default: @@ -1826,6 +2394,82 @@ class WKUIDelegateHostApi { } } +class _WKUIDelegateFlutterApiCodec extends StandardMessageCodec { + const _WKUIDelegateFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is NSUrlRequestData) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is WKFrameInfoData) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionData) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return NSUrlRequestData.decode(readValue(buffer)!); + + case 129: + return WKFrameInfoData.decode(readValue(buffer)!); + + case 130: + return WKNavigationActionData.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + } + } +} + +abstract class WKUIDelegateFlutterApi { + static const MessageCodec codec = _WKUIDelegateFlutterApiCodec(); + + void onCreateWebView(int identifier, int webViewIdentifier, + int configurationIdentifier, WKNavigationActionData navigationAction); + static void setup(WKUIDelegateFlutterApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); + final int? arg_webViewIdentifier = (args[1] as int?); + assert(arg_webViewIdentifier != null, + 'Argument for dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); + final int? arg_configurationIdentifier = (args[2] as int?); + assert(arg_configurationIdentifier != null, + 'Argument for dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); + final WKNavigationActionData? arg_navigationAction = + (args[3] as WKNavigationActionData?); + assert(arg_navigationAction != null, + 'Argument for dev.flutter.pigeon.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null WKNavigationActionData.'); + api.onCreateWebView(arg_identifier!, arg_webViewIdentifier!, + arg_configurationIdentifier!, arg_navigationAction!); + return; + }); + } + } + } +} + class _WKHttpCookieStoreHostApiCodec extends StandardMessageCodec { const _WKHttpCookieStoreHostApiCodec(); @override diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart index 9575cb51c648..f9efe3616ca7 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart @@ -36,17 +36,25 @@ Iterable }); } +extension _NSKeyValueChangeKeyEnumDataConverter on NSKeyValueChangeKeyEnumData { + NSKeyValueChangeKey toNSKeyValueChangeKey() { + return NSKeyValueChangeKey.values.firstWhere( + (NSKeyValueChangeKey element) => element.name == value.name, + ); + } +} + /// Handles initialization of Flutter APIs for the Foundation library. -// TODO(bparrishMines): Add NSObjectFlutterApiImpl once the callback methods -// are added. class FoundationFlutterApis { /// Constructs a [FoundationFlutterApis]. @visibleForTesting FoundationFlutterApis({ BinaryMessenger? binaryMessenger, - // ignore: avoid_unused_constructor_parameters InstanceManager? instanceManager, - }) : _binaryMessenger = binaryMessenger; + }) : _binaryMessenger = binaryMessenger, + object = NSObjectFlutterApiImpl( + instanceManager: instanceManager, + ); static FoundationFlutterApis _instance = FoundationFlutterApis(); @@ -61,13 +69,20 @@ class FoundationFlutterApis { return _instance; } - // ignore: unused_field final BinaryMessenger? _binaryMessenger; bool _hasBeenSetUp = false; + /// Flutter Api for [NSObject]. + @visibleForTesting + final NSObjectFlutterApiImpl object; + /// Ensures all the Flutter APIs have been set up to receive calls from native code. void ensureSetUp() { if (!_hasBeenSetUp) { + NSObjectFlutterApi.setup( + object, + binaryMessenger: _binaryMessenger, + ); _hasBeenSetUp = true; } } @@ -132,3 +147,40 @@ class NSObjectHostApiImpl extends NSObjectHostApi { instanceManager == other.instanceManager; } } + +/// Flutter api implementation for [NSObject]. +class NSObjectFlutterApiImpl extends NSObjectFlutterApi { + /// Constructs a [NSObjectFlutterApiImpl]. + NSObjectFlutterApiImpl({InstanceManager? instanceManager}) + : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + NSObject _getObject(int identifier) { + return instanceManager.getInstanceWithWeakReference(identifier)!; + } + + @override + void observeValue( + int identifier, + String keyPath, + int objectIdentifier, + List changeKeys, + List changeValues, + ) { + final void Function(String, NSObject, Map)? + function = _getObject(identifier).observeValue; + function?.call( + keyPath, + instanceManager.getInstanceWithWeakReference(objectIdentifier)! + as NSObject, + Map.fromIterables( + changeKeys.map( + (NSKeyValueChangeKeyEnumData? data) { + return data!.toNSKeyValueChangeKey(); + }, + ), changeValues), + ); + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index f2efd665298b..b2945293e624 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -400,6 +400,19 @@ class WKUserContentController extends NSObject { ); } + /// Constructs a [WKUserContentController] without creating the associated + /// Objective-C object. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an InstanceManager. + WKUserContentController.detached({ + BinaryMessenger? binaryMessenger, + InstanceManager? instanceManager, + }) : _userContentControllerApi = WKUserContentControllerHostApiImpl( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ); + final WKUserContentControllerHostApiImpl _userContentControllerApi; /// Installs a message handler that you can call from your JavaScript code. @@ -472,7 +485,8 @@ class WKWebViewConfiguration extends NSObject { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) { - final WKWebViewConfiguration configuration = WKWebViewConfiguration._( + final WKWebViewConfiguration configuration = + WKWebViewConfiguration.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); @@ -487,7 +501,8 @@ class WKWebViewConfiguration extends NSObject { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) { - final WKWebViewConfiguration configuration = WKWebViewConfiguration._( + final WKWebViewConfiguration configuration = + WKWebViewConfiguration.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); @@ -498,7 +513,12 @@ class WKWebViewConfiguration extends NSObject { return configuration; } - WKWebViewConfiguration._({ + /// Constructs a [WKWebViewConfiguration] without creating the associated + /// Objective-C object. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an InstanceManager. + WKWebViewConfiguration.detached({ BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _binaryMessenger = binaryMessenger, @@ -584,6 +604,7 @@ class WKUIDelegate extends NSObject { /// Indicates a new [WKWebView] was requested to be created with [configuration]. final void Function( + WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, )? onCreateWebView; @@ -720,6 +741,22 @@ class WKWebView extends UIView { _webViewApi.createForInstances(this, configuration); } + /// Constructs a [WKWebView] without creating the associated + /// Objective-C object. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an InstanceManager. + WKWebView.detached({ + super.observeValue, + super.binaryMessenger, + super.instanceManager, + }) : _binaryMessenger = binaryMessenger, + _instanceManager = instanceManager, + _webViewApi = WKWebViewHostApiImpl( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ); + final BinaryMessenger? _binaryMessenger; final InstanceManager? _instanceManager; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart index 85b9b492eb87..c27fc3e73aee 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart @@ -61,6 +61,16 @@ extension _NSHttpCookieConverter on NSHttpCookie { } } +extension _WKNavigationActionPolicyConverter on WKNavigationActionPolicy { + WKNavigationActionPolicyEnumData toWKNavigationActionPolicyEnumData() { + return WKNavigationActionPolicyEnumData( + value: WKNavigationActionPolicyEnum.values.firstWhere( + (WKNavigationActionPolicyEnum element) => element.name == name, + ), + ); + } +} + extension _NSHttpCookiePropertyKeyConverter on NSHttpCookiePropertyKey { NSHttpCookiePropertyKeyEnumData toNSHttpCookiePropertyKeyEnumData() { late final NSHttpCookiePropertyKeyEnum value; @@ -154,6 +164,48 @@ Iterable _toWKAudiovisualMediaTypeEnumData( }); } +extension _NavigationActionDataConverter on WKNavigationActionData { + WKNavigationAction toNavigationAction() { + return WKNavigationAction( + request: request.toNSUrlRequest(), + targetFrame: targetFrame.toWKFrameInfo(), + ); + } +} + +extension _WKFrameInfoDataConverter on WKFrameInfoData { + WKFrameInfo toWKFrameInfo() { + return WKFrameInfo(isMainFrame: isMainFrame); + } +} + +extension _NSUrlRequestDataConverter on NSUrlRequestData { + NSUrlRequest toNSUrlRequest() { + return NSUrlRequest( + url: url, + httpBody: httpBody, + httpMethod: httpMethod, + allHttpHeaderFields: allHttpHeaderFields.cast(), + ); + } +} + +extension _WKNSErrorDataConverter on NSErrorData { + NSError toNSError() { + return NSError( + domain: domain, + code: code, + localizedDescription: localizedDescription, + ); + } +} + +extension _WKScriptMessageDataConverter on WKScriptMessageData { + WKScriptMessage toWKScriptMessage() { + return WKScriptMessage(name: name, body: body); + } +} + extension _WKUserScriptConverter on WKUserScript { WKUserScriptData toWKUserScriptData() { return WKUserScriptData( @@ -182,11 +234,15 @@ class WebKitFlutterApis { WebKitFlutterApis({ BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - }) : _binaryMessenger = binaryMessenger { - navigationDelegateFlutterApi = WKNavigationDelegateFlutterApiImpl( - instanceManager: instanceManager, - ); - } + }) : _binaryMessenger = binaryMessenger, + navigationDelegate = WKNavigationDelegateFlutterApiImpl( + instanceManager: instanceManager, + ), + scriptMessageHandler = WKScriptMessageHandlerFlutterApiImpl( + instanceManager: instanceManager), + uiDelegate = WKUIDelegateFlutterApiImpl( + instanceManager: instanceManager, + ); static WebKitFlutterApis _instance = WebKitFlutterApis(); @@ -206,13 +262,29 @@ class WebKitFlutterApis { /// Flutter Api for [WKNavigationDelegate]. @visibleForTesting - late final WKNavigationDelegateFlutterApiImpl navigationDelegateFlutterApi; + final WKNavigationDelegateFlutterApiImpl navigationDelegate; + + /// Flutter Api for [WKScriptMessageHandler]. + @visibleForTesting + final WKScriptMessageHandlerFlutterApiImpl scriptMessageHandler; + + /// Flutter Api for [WKUIDelegate]. + @visibleForTesting + final WKUIDelegateFlutterApiImpl uiDelegate; /// Ensures all the Flutter APIs have been set up to receive calls from native code. void ensureSetUp() { if (!_hasBeenSetUp) { WKNavigationDelegateFlutterApi.setup( - navigationDelegateFlutterApi, + navigationDelegate, + binaryMessenger: _binaryMessenger, + ); + WKScriptMessageHandlerFlutterApi.setup( + scriptMessageHandler, + binaryMessenger: _binaryMessenger, + ); + WKUIDelegateFlutterApi.setup( + uiDelegate, binaryMessenger: _binaryMessenger, ); _hasBeenSetUp = true; @@ -282,6 +354,35 @@ class WKScriptMessageHandlerHostApiImpl extends WKScriptMessageHandlerHostApi { } } +/// Flutter api implementation for [WKScriptMessageHandler]. +class WKScriptMessageHandlerFlutterApiImpl + extends WKScriptMessageHandlerFlutterApi { + /// Constructs a [WKScriptMessageHandlerFlutterApiImpl]. + WKScriptMessageHandlerFlutterApiImpl({InstanceManager? instanceManager}) + : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + WKScriptMessageHandler _getHandler(int identifier) { + return instanceManager.getInstanceWithWeakReference(identifier)!; + } + + @override + void didReceiveScriptMessage( + int identifier, + int userContentControllerIdentifier, + WKScriptMessageData message, + ) { + _getHandler(identifier).didReceiveScriptMessage( + instanceManager.getInstanceWithWeakReference( + userContentControllerIdentifier, + )! as WKUserContentController, + message.toWKScriptMessage(), + ); + } +} + /// Host api implementation for [WKPreferences]. class WKPreferencesHostApiImpl extends WKPreferencesHostApi { /// Constructs a [WKPreferencesHostApiImpl]. @@ -492,6 +593,38 @@ class WKUIDelegateHostApiImpl extends WKUIDelegateHostApi { } } +/// Flutter api implementation for [WKUIDelegate]. +class WKUIDelegateFlutterApiImpl extends WKUIDelegateFlutterApi { + /// Constructs a [WKUIDelegateFlutterApiImpl]. + WKUIDelegateFlutterApiImpl({InstanceManager? instanceManager}) + : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + WKUIDelegate _getDelegate(int identifier) { + return instanceManager.getInstanceWithWeakReference(identifier)!; + } + + @override + void onCreateWebView( + int identifier, + int webViewIdentifier, + int configurationIdentifier, + WKNavigationActionData navigationAction, + ) { + final void Function(WKWebView, WKWebViewConfiguration, WKNavigationAction)? + function = _getDelegate(identifier).onCreateWebView; + function?.call( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + instanceManager.getInstanceWithWeakReference(configurationIdentifier)! + as WKWebViewConfiguration, + navigationAction.toNavigationAction(), + ); + } +} + /// Host api implementation for [WKNavigationDelegate]. @immutable class WKNavigationDelegateHostApiImpl extends WKNavigationDelegateHostApi { @@ -533,12 +666,11 @@ class WKNavigationDelegateHostApiImpl extends WKNavigationDelegateHostApi { class WKNavigationDelegateFlutterApiImpl extends WKNavigationDelegateFlutterApi { /// Constructs a [WKNavigationDelegateFlutterApiImpl]. - WKNavigationDelegateFlutterApiImpl({InstanceManager? instanceManager}) { - this.instanceManager = instanceManager ?? NSObject.globalInstanceManager; - } + WKNavigationDelegateFlutterApiImpl({InstanceManager? instanceManager}) + : instanceManager = instanceManager ?? NSObject.globalInstanceManager; /// Maintains instances stored to communicate with native language objects. - late final InstanceManager instanceManager; + final InstanceManager instanceManager; WKNavigationDelegate _getDelegate(int identifier) { return instanceManager.getInstanceWithWeakReference(identifier)!; @@ -558,6 +690,89 @@ class WKNavigationDelegateFlutterApiImpl url, ); } + + @override + Future decidePolicyForNavigationAction( + int identifier, + int webViewIdentifier, + WKNavigationActionData navigationAction, + ) async { + final Future Function( + WKWebView, + WKNavigationAction navigationAction, + )? function = _getDelegate(identifier).decidePolicyForNavigationAction; + + if (function == null) { + return WKNavigationActionPolicyEnumData( + value: WKNavigationActionPolicyEnum.allow, + ); + } + + final WKNavigationActionPolicy policy = await function( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + navigationAction.toNavigationAction(), + ); + return policy.toWKNavigationActionPolicyEnumData(); + } + + @override + void didFailNavigation( + int identifier, + int webViewIdentifier, + NSErrorData error, + ) { + final void Function(WKWebView, NSError)? function = + _getDelegate(identifier).didFailNavigation; + function?.call( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + error.toNSError(), + ); + } + + @override + void didFailProvisionalNavigation( + int identifier, + int webViewIdentifier, + NSErrorData error, + ) { + final void Function(WKWebView, NSError)? function = + _getDelegate(identifier).didFailProvisionalNavigation; + function?.call( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + error.toNSError(), + ); + } + + @override + void didStartProvisionalNavigation( + int identifier, + int webViewIdentifier, + String? url, + ) { + final void Function(WKWebView, String?)? function = + _getDelegate(identifier).didStartProvisionalNavigation; + function?.call( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + url, + ); + } + + @override + void webViewWebContentProcessDidTerminate( + int identifier, + int webViewIdentifier, + ) { + final void Function(WKWebView)? function = + _getDelegate(identifier).webViewWebContentProcessDidTerminate; + function?.call( + instanceManager.getInstanceWithWeakReference(webViewIdentifier)! + as WKWebView, + ); + } } /// Host api implementation for [WKWebView]. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 1cfbc6edb458..05a77f56f851 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -115,6 +115,7 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { @visibleForTesting late final WKUIDelegate uiDelegate = webViewProxy.createUIDelgate(onCreateWebView: ( + WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, ) { @@ -631,6 +632,7 @@ class WebViewWidgetProxy { /// Constructs a [WKUIDelegate]. WKUIDelegate createUIDelgate({ void Function( + WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, )? diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart index 91541e8e741b..e46dafa01a62 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart @@ -206,7 +206,7 @@ class WKFrameInfoData { class NSErrorData { late int code; late String domain; - late String localiziedDescription; + late String localizedDescription; } /// Mirror of WKScriptMessage. @@ -373,6 +373,21 @@ abstract class WKScriptMessageHandlerHostApi { void create(int identifier); } +/// Handles callbacks from an WKScriptMessageHandler instance. +/// +/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. +@FlutterApi() +abstract class WKScriptMessageHandlerFlutterApi { + @ObjCSelector( + 'didReceiveScriptMessageForHandlerWithIdentifier:userContentControllerIdentifier:message:', + ) + void didReceiveScriptMessage( + int identifier, + int userContentControllerIdentifier, + WKScriptMessageData message, + ); +} + /// Mirror of WKNavigationDelegate. /// /// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. @@ -395,6 +410,51 @@ abstract class WKNavigationDelegateFlutterApi { int webViewIdentifier, String? url, ); + + @ObjCSelector( + 'didStartProvisionalNavigationForDelegateWithIdentifier:webViewIdentifier:URL:', + ) + void didStartProvisionalNavigation( + int identifier, + int webViewIdentifier, + String? url, + ); + + @ObjCSelector( + 'decidePolicyForNavigationActionForDelegateWithIdentifier:webViewIdentifier:navigationAction:', + ) + @async + WKNavigationActionPolicyEnumData decidePolicyForNavigationAction( + int identifier, + int webViewIdentifier, + WKNavigationActionData navigationAction, + ); + + @ObjCSelector( + 'didFailNavigationForDelegateWithIdentifier:webViewIdentifier:error:', + ) + void didFailNavigation( + int identifier, + int webViewIdentifier, + NSErrorData error, + ); + + @ObjCSelector( + 'didFailProvisionalNavigationForDelegateWithIdentifier:webViewIdentifier:error:', + ) + void didFailProvisionalNavigation( + int identifier, + int webViewIdentifier, + NSErrorData error, + ); + + @ObjCSelector( + 'webViewWebContentProcessDidTerminateForDelegateWithIdentifier:webViewIdentifier:', + ) + void webViewWebContentProcessDidTerminate( + int identifier, + int webViewIdentifier, + ); } /// Mirror of NSObject. @@ -425,7 +485,23 @@ abstract class NSObjectHostApi { /// /// See https://developer.apple.com/documentation/objectivec/nsobject. @FlutterApi() -abstract class NSObjectFlutterApi {} +abstract class NSObjectFlutterApi { + @ObjCSelector( + 'observeValueForObjectWithIdentifier:keyPath:objectIdentifier:changeKeys:changeValues:', + ) + void observeValue( + int identifier, + String keyPath, + int objectIdentifier, + // TODO(bparrishMines): Change to a map when Objective-C data classes conform + // to `NSCopying`. See https://github.com/flutter/flutter/issues/103383. + // `NSDictionary`s are unable to use data classes as keys because they don't + // conform to `NSCopying`. This splits the map of properties into a list of + // keys and values with the ordered maintained. + List changeKeys, + List changeValues, + ); +} /// Mirror of WKWebView. /// @@ -499,6 +575,22 @@ abstract class WKUIDelegateHostApi { void create(int identifier); } +/// Handles callbacks from an WKUIDelegate instance. +/// +/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. +@FlutterApi() +abstract class WKUIDelegateFlutterApi { + @ObjCSelector( + 'onCreateWebViewForDelegateWithIdentifier:webViewIdentifier:configurationIdentifier:navigationAction:', + ) + void onCreateWebView( + int identifier, + int webViewIdentifier, + int configurationIdentifier, + WKNavigationActionData navigationAction, + ); +} + /// Mirror of WKHttpCookieStore. /// /// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.pigeon.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.pigeon.dart index 00865d66f2bc..5bf50e2b9850 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.pigeon.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.pigeon.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.1.2), do not edit directly. +// Autogenerated from Pigeon (v3.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis // ignore_for_file: avoid_relative_lib_imports @@ -847,30 +847,48 @@ class _TestWKWebViewHostApiCodec extends StandardMessageCodec { const _TestWKWebViewHostApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSHttpCookieData) { + if (value is NSErrorData) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { + } else if (value is NSHttpCookieData) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is NSKeyValueObservingOptionsEnumData) { + } else if (value is NSHttpCookiePropertyKeyEnumData) { buffer.putUint8(130); writeValue(buffer, value.encode()); - } else if (value is NSUrlRequestData) { + } else if (value is NSKeyValueChangeKeyEnumData) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is WKAudiovisualMediaTypeEnumData) { + } else if (value is NSKeyValueObservingOptionsEnumData) { buffer.putUint8(132); writeValue(buffer, value.encode()); - } else if (value is WKUserScriptData) { + } else if (value is NSUrlRequestData) { buffer.putUint8(133); writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { + } else if (value is WKAudiovisualMediaTypeEnumData) { buffer.putUint8(134); writeValue(buffer, value.encode()); - } else if (value is WKWebsiteDataTypeEnumData) { + } else if (value is WKFrameInfoData) { buffer.putUint8(135); writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionData) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is WKNavigationActionPolicyEnumData) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else if (value is WKScriptMessageData) { + buffer.putUint8(138); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptData) { + buffer.putUint8(139); + writeValue(buffer, value.encode()); + } else if (value is WKUserScriptInjectionTimeEnumData) { + buffer.putUint8(140); + writeValue(buffer, value.encode()); + } else if (value is WKWebsiteDataTypeEnumData) { + buffer.putUint8(141); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -880,27 +898,45 @@ class _TestWKWebViewHostApiCodec extends StandardMessageCodec { Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: - return NSHttpCookieData.decode(readValue(buffer)!); + return NSErrorData.decode(readValue(buffer)!); case 129: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); + return NSHttpCookieData.decode(readValue(buffer)!); case 130: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); + return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); case 131: - return NSUrlRequestData.decode(readValue(buffer)!); + return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); case 132: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); + return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); case 133: - return WKUserScriptData.decode(readValue(buffer)!); + return NSUrlRequestData.decode(readValue(buffer)!); case 134: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); + return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); case 135: + return WKFrameInfoData.decode(readValue(buffer)!); + + case 136: + return WKNavigationActionData.decode(readValue(buffer)!); + + case 137: + return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); + + case 138: + return WKScriptMessageData.decode(readValue(buffer)!); + + case 139: + return WKUserScriptData.decode(readValue(buffer)!); + + case 140: + return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); + + case 141: return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); default: diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart index ca84369c9789..8d15d65f3598 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; import 'package:webview_flutter_wkwebview/src/common/web_kit.pigeon.dart'; import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; +import 'package:webview_flutter_wkwebview/src/foundation/foundation_api_impls.dart'; import '../common/test_web_kit.pigeon.dart'; import 'foundation_test.mocks.dart'; @@ -100,6 +103,48 @@ void main() { NSObject.dispose(object); expect(callbackIdentifier, identifier); }); + + test('observeValue', () async { + final Completer> argsCompleter = + Completer>(); + + FoundationFlutterApis.instance = FoundationFlutterApis( + instanceManager: instanceManager, + ); + + object = NSObject( + instanceManager: instanceManager, + observeValue: ( + String keyPath, + NSObject object, + Map change, + ) { + argsCompleter.complete([keyPath, object, change]); + }, + ); + instanceManager.addHostCreatedInstance(object, 1); + + FoundationFlutterApis.instance.object.observeValue( + 1, + 'keyPath', + 1, + [ + NSKeyValueChangeKeyEnumData(value: NSKeyValueChangeKeyEnum.oldValue) + ], + ['value'], + ); + + expect( + argsCompleter.future, + completion([ + 'keyPath', + object, + { + NSKeyValueChangeKey.oldValue: 'value', + }, + ]), + ); + }); }); }); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart index cf417c4e0ca2..d71a6c5e0838 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart @@ -200,6 +200,42 @@ void main() { instanceManager.getIdentifier(scriptMessageHandler), )); }); + + test('didReceiveScriptMessage', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + scriptMessageHandler = WKScriptMessageHandler( + instanceManager: instanceManager, + didReceiveScriptMessage: ( + WKUserContentController userContentController, + WKScriptMessage message, + ) { + argsCompleter.complete([userContentController, message]); + }, + ); + + final WKUserContentController userContentController = + WKUserContentController.detached( + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(userContentController, 2); + + WebKitFlutterApis.instance.scriptMessageHandler.didReceiveScriptMessage( + instanceManager.getIdentifier(scriptMessageHandler)!, + 2, + WKScriptMessageData(name: 'name'), + ); + + expect( + argsCompleter.future, + completion([userContentController, isA()]), + ); + }); }); group('WKPreferences', () { @@ -464,8 +500,7 @@ void main() { }, ); - WebKitFlutterApis.instance.navigationDelegateFlutterApi - .didFinishNavigation( + WebKitFlutterApis.instance.navigationDelegate.didFinishNavigation( instanceManager.getIdentifier(navigationDelegate)!, instanceManager.getIdentifier(webView)!, 'url', @@ -473,6 +508,150 @@ void main() { expect(argsCompleter.future, completion([webView, 'url'])); }); + + test('didStartProvisionalNavigation', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + navigationDelegate = WKNavigationDelegate( + instanceManager: instanceManager, + didStartProvisionalNavigation: (WKWebView webView, String? url) { + argsCompleter.complete([webView, url]); + }, + ); + + WebKitFlutterApis.instance.navigationDelegate + .didStartProvisionalNavigation( + instanceManager.getIdentifier(navigationDelegate)!, + instanceManager.getIdentifier(webView)!, + 'url', + ); + + expect(argsCompleter.future, completion([webView, 'url'])); + }); + + test('decidePolicyForNavigationAction', () async { + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + navigationDelegate = WKNavigationDelegate( + instanceManager: instanceManager, + decidePolicyForNavigationAction: ( + WKWebView webView, + WKNavigationAction navigationAction, + ) async { + return WKNavigationActionPolicy.cancel; + }, + ); + + final WKNavigationActionPolicyEnumData policyData = + await WebKitFlutterApis.instance.navigationDelegate + .decidePolicyForNavigationAction( + instanceManager.getIdentifier(navigationDelegate)!, + instanceManager.getIdentifier(webView)!, + WKNavigationActionData( + request: NSUrlRequestData( + url: 'url', + allHttpHeaderFields: {}, + ), + targetFrame: WKFrameInfoData(isMainFrame: false), + ), + ); + + expect(policyData.value, WKNavigationActionPolicyEnum.cancel); + }); + + test('didFailNavigation', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + navigationDelegate = WKNavigationDelegate( + instanceManager: instanceManager, + didFailNavigation: (WKWebView webView, NSError error) { + argsCompleter.complete([webView, error]); + }, + ); + + WebKitFlutterApis.instance.navigationDelegate.didFailNavigation( + instanceManager.getIdentifier(navigationDelegate)!, + instanceManager.getIdentifier(webView)!, + NSErrorData( + code: 23, + domain: 'Hello', + localizedDescription: 'localiziedDescription', + ), + ); + + expect( + argsCompleter.future, + completion([webView, isA()]), + ); + }); + + test('didFailProvisionalNavigation', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + navigationDelegate = WKNavigationDelegate( + instanceManager: instanceManager, + didFailProvisionalNavigation: (WKWebView webView, NSError error) { + argsCompleter.complete([webView, error]); + }, + ); + + WebKitFlutterApis.instance.navigationDelegate + .didFailProvisionalNavigation( + instanceManager.getIdentifier(navigationDelegate)!, + instanceManager.getIdentifier(webView)!, + NSErrorData( + code: 23, + domain: 'Hello', + localizedDescription: 'localiziedDescription', + ), + ); + + expect( + argsCompleter.future, + completion([webView, isA()]), + ); + }); + + test('webViewWebContentProcessDidTerminate', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + navigationDelegate = WKNavigationDelegate( + instanceManager: instanceManager, + webViewWebContentProcessDidTerminate: (WKWebView webView) { + argsCompleter.complete([webView]); + }, + ); + + WebKitFlutterApis.instance.navigationDelegate + .webViewWebContentProcessDidTerminate( + instanceManager.getIdentifier(navigationDelegate)!, + instanceManager.getIdentifier(webView)!, + ); + + expect(argsCompleter.future, completion([webView])); + }); }); group('WKWebView', () { @@ -659,6 +838,63 @@ void main() { instanceManager.getIdentifier(uiDelegate), )); }); + + test('onCreateWebView', () async { + final Completer> argsCompleter = + Completer>(); + + WebKitFlutterApis.instance = WebKitFlutterApis( + instanceManager: instanceManager, + ); + + uiDelegate = WKUIDelegate( + instanceManager: instanceManager, + onCreateWebView: ( + WKWebView webView, + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + ) { + argsCompleter.complete([ + webView, + configuration, + navigationAction, + ]); + }, + ); + + final WKWebView webView = WKWebView.detached( + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(webView, 2); + + final WKWebViewConfiguration configuration = + WKWebViewConfiguration.detached( + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance(configuration, 3); + + WebKitFlutterApis.instance.uiDelegate.onCreateWebView( + instanceManager.getIdentifier(uiDelegate)!, + 2, + 3, + WKNavigationActionData( + request: NSUrlRequestData( + url: 'url', + allHttpHeaderFields: {}, + ), + targetFrame: WKFrameInfoData(isMainFrame: false), + ), + ); + + expect( + argsCompleter.future, + completion([ + webView, + configuration, + isA(), + ]), + ); + }); }); }); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart index b0c63b663066..8289831fc4e4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.2.0 from annotations -// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.dart. +// in webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.dart. // Do not manually edit this file. import 'dart:async' as _i4; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index c1cdfc503a59..24155d2a05e1 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -136,13 +136,16 @@ void main() { await buildWidget(tester); final dynamic onCreateWebView = verify( - mockWebViewWidgetProxy.createUIDelgate( - onCreateWebView: captureAnyNamed('onCreateWebView'))) - .captured - .single as void Function(WKWebViewConfiguration, WKNavigationAction); + mockWebViewWidgetProxy.createUIDelgate( + onCreateWebView: captureAnyNamed('onCreateWebView'))) + .captured + .single + as void Function( + WKWebView, WKWebViewConfiguration, WKNavigationAction); const NSUrlRequest request = NSUrlRequest(url: 'https://google.com'); onCreateWebView( + mockWebView, mockWebViewConfiguration, const WKNavigationAction( request: request, diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index 728c526ca929..c8ed4c856dcb 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.2.0 from annotations -// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart. +// in webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart. // Do not manually edit this file. import 'dart:async' as _i6; @@ -36,31 +36,31 @@ class _FakePoint_0 extends _i1.Fake implements _i2.Point {} class _FakeCopyable_1 extends _i1.Fake implements _i3.Copyable {} -class _FakeWKNavigationDelegate_2 extends _i1.Fake - implements _i4.WKNavigationDelegate {} - -class _FakeWKWebViewConfiguration_3 extends _i1.Fake +class _FakeWKWebViewConfiguration_2 extends _i1.Fake implements _i4.WKWebViewConfiguration {} -class _FakeUIScrollView_4 extends _i1.Fake implements _i5.UIScrollView {} +class _FakeUIScrollView_3 extends _i1.Fake implements _i5.UIScrollView {} -class _FakeWKUserContentController_5 extends _i1.Fake +class _FakeWKUserContentController_4 extends _i1.Fake implements _i4.WKUserContentController {} -class _FakeWKPreferences_6 extends _i1.Fake implements _i4.WKPreferences {} +class _FakeWKPreferences_5 extends _i1.Fake implements _i4.WKPreferences {} -class _FakeWKWebsiteDataStore_7 extends _i1.Fake +class _FakeWKWebsiteDataStore_6 extends _i1.Fake implements _i4.WKWebsiteDataStore {} -class _FakeWKHttpCookieStore_8 extends _i1.Fake +class _FakeWKHttpCookieStore_7 extends _i1.Fake implements _i4.WKHttpCookieStore {} -class _FakeWKWebView_9 extends _i1.Fake implements _i4.WKWebView {} +class _FakeWKWebView_8 extends _i1.Fake implements _i4.WKWebView {} -class _FakeWKScriptMessageHandler_10 extends _i1.Fake +class _FakeWKScriptMessageHandler_9 extends _i1.Fake implements _i4.WKScriptMessageHandler {} -class _FakeWKUIDelegate_11 extends _i1.Fake implements _i4.WKUIDelegate {} +class _FakeWKUIDelegate_10 extends _i1.Fake implements _i4.WKUIDelegate {} + +class _FakeWKNavigationDelegate_11 extends _i1.Fake + implements _i4.WKNavigationDelegate {} /// A class which mocks [UIScrollView]. /// @@ -125,9 +125,8 @@ class MockWKNavigationDelegate extends _i1.Mock } @override - _i4.WKNavigationDelegate copy() => (super.noSuchMethod( - Invocation.method(#copy, []), - returnValue: _FakeWKNavigationDelegate_2()) as _i4.WKNavigationDelegate); + _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeCopyable_1()) as _i3.Copyable); @override _i6.Future addObserver(_i8.NSObject? observer, {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => @@ -222,12 +221,12 @@ class MockWKWebView extends _i1.Mock implements _i4.WKWebView { @override _i4.WKWebViewConfiguration get configuration => (super.noSuchMethod(Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_3()) + returnValue: _FakeWKWebViewConfiguration_2()) as _i4.WKWebViewConfiguration); @override _i5.UIScrollView get scrollView => (super.noSuchMethod(Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_4()) as _i5.UIScrollView); + returnValue: _FakeUIScrollView_3()) as _i5.UIScrollView); @override _i6.Future setUIDelegate(_i4.WKUIDelegate? delegate) => (super.noSuchMethod(Invocation.method(#setUIDelegate, [delegate]), @@ -352,16 +351,16 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i4.WKUserContentController get userContentController => (super.noSuchMethod(Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_5()) + returnValue: _FakeWKUserContentController_4()) as _i4.WKUserContentController); @override _i4.WKPreferences get preferences => (super.noSuchMethod(Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_6()) as _i4.WKPreferences); + returnValue: _FakeWKPreferences_5()) as _i4.WKPreferences); @override _i4.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod(Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_7()) as _i4.WKWebsiteDataStore); + returnValue: _FakeWKWebsiteDataStore_6()) as _i4.WKWebsiteDataStore); @override _i6.Future setAllowsInlineMediaPlayback(bool? allow) => (super .noSuchMethod(Invocation.method(#setAllowsInlineMediaPlayback, [allow]), @@ -406,7 +405,7 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i4.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod(Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_8()) as _i4.WKHttpCookieStore); + returnValue: _FakeWKHttpCookieStore_7()) as _i4.WKHttpCookieStore); @override _i6.Future removeDataOfTypes( Set<_i4.WKWebsiteDataType>? dataTypes, DateTime? since) => @@ -590,7 +589,7 @@ class MockWebViewWidgetProxy extends _i1.Mock (super.noSuchMethod( Invocation.method( #createWebView, [configuration], {#observeValue: observeValue}), - returnValue: _FakeWKWebView_9()) as _i4.WKWebView); + returnValue: _FakeWKWebView_8()) as _i4.WKWebView); @override _i4.WKScriptMessageHandler createScriptMessageHandler( {void Function(_i4.WKUserContentController, _i4.WKScriptMessage)? @@ -598,16 +597,17 @@ class MockWebViewWidgetProxy extends _i1.Mock (super.noSuchMethod( Invocation.method(#createScriptMessageHandler, [], {#didReceiveScriptMessage: didReceiveScriptMessage}), - returnValue: _FakeWKScriptMessageHandler_10()) + returnValue: _FakeWKScriptMessageHandler_9()) as _i4.WKScriptMessageHandler); @override _i4.WKUIDelegate createUIDelgate( - {void Function(_i4.WKWebViewConfiguration, _i4.WKNavigationAction)? + {void Function(_i4.WKWebView, _i4.WKWebViewConfiguration, + _i4.WKNavigationAction)? onCreateWebView}) => (super.noSuchMethod( Invocation.method( #createUIDelgate, [], {#onCreateWebView: onCreateWebView}), - returnValue: _FakeWKUIDelegate_11()) as _i4.WKUIDelegate); + returnValue: _FakeWKUIDelegate_10()) as _i4.WKUIDelegate); @override _i4.WKNavigationDelegate createNavigationDelegate( {void Function(_i4.WKWebView, String?)? didFinishNavigation, @@ -631,6 +631,6 @@ class MockWebViewWidgetProxy extends _i1.Mock #webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate }), - returnValue: _FakeWKNavigationDelegate_2()) + returnValue: _FakeWKNavigationDelegate_11()) as _i4.WKNavigationDelegate); }