From 752df24fcdea5e631b08b752d9c706bbcf2469de Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:52:31 -0700 Subject: [PATCH 01/16] include generated objc code --- .../ios/Classes/FWFGeneratedWebKitApis.h | 110 ++- .../ios/Classes/FWFGeneratedWebKitApis.m | 642 +++++++++++++++++- 2 files changed, 735 insertions(+), 17 deletions(-) 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..b2abedb00276 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 + localiziedDescription:(NSString *)localiziedDescription; +@property(nonatomic, strong) NSNumber *code; +@property(nonatomic, copy) NSString *domain; +@property(nonatomic, copy) NSString *localiziedDescription; +@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,16 @@ 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 + 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..19b44761e982 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 + localiziedDescription:(NSString *)localiziedDescription { + FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; + pigeonResult.code = code; + pigeonResult.domain = domain; + pigeonResult.localiziedDescription = localiziedDescription; + 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.localiziedDescription = GetNullableObject(dict, @"localiziedDescription"); + NSAssert(pigeonResult.localiziedDescription != nil, @""); + return pigeonResult; +} +- (NSDictionary *)toMap { + return @{ + @"code" : (self.code ?: [NSNull null]), + @"domain" : (self.domain ?: [NSNull null]), + @"localiziedDescription" : (self.localiziedDescription ?: [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,97 @@ 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 + 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_configurationIdentifier ?: [NSNull null], + arg_navigationAction ?: [NSNull null] + ] + reply:^(id reply) { + completion(nil); + }]; +} +@end @interface FWFWKHttpCookieStoreHostApiCodecReader : FlutterStandardReader @end @implementation FWFWKHttpCookieStoreHostApiCodecReader From 3a8fb6f0f9981646cbd9f3317e6181fe9c902995 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 16:36:48 -0700 Subject: [PATCH 02/16] navigation delegate code --- .../ios/Classes/FWFDataConverters.h | 45 ++++++++++ .../ios/Classes/FWFDataConverters.m | 28 ++++++ .../Classes/FWFNavigationDelegateHostApi.m | 90 +++++++++++++++++-- 3 files changed, 158 insertions(+), 5 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h index 4cf24c67ac95..33fee9ebcf94 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h @@ -85,4 +85,49 @@ extern WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData( */ extern NSString *_Nullable FWFWKWebsiteDataTypeFromEnumData(FWFWKWebsiteDataTypeEnumData *data); +/** + * Converts a WKNavigationAction to an FWFWKNavigationActionData. + * + * @param action The object containing information to create a WKNavigationActionData. + * + * @return A FWFWKNavigationActionData. + */ +extern FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction(WKNavigationAction *action); + +/** + * Converts a NSURLRequest to an FWFNSUrlRequestData. + * + * @param request The object containing information to create a WKNavigationActionData. + * + * @return A FWFNSUrlRequestData. + */ +extern FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request); + +/** + * Converts a WKFrameInfo to an FWFWKFrameInfoData. + * + * @param info The object containing information to create a FWFWKFrameInfoData. + * + * @return A FWFWKFrameInfoData. + */ +extern FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info); + +/** + * Converts an FWFWKNavigationActionPolicyEnumData to a WKNavigationActionPolicy. + * + * @param data The data object containing information to create a WKNavigationActionPolicy. + * + * @return A WKNavigationActionPolicy or -1 if data could not be converted. + */ +extern WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigationActionPolicyEnumData *data); + +/** + * Converts a NSError to an FWFNSErrorData. + * + * @param error The object containing information to create a FWFNSErrorData. + * + * @return A FWFNSErrorData. + */ +extern FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error); + NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index a06b3d79b38c..76246b64509c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -153,3 +153,31 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData( return nil; } + +FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction(WKNavigationAction *action) { + return [FWFWKNavigationActionData makeWithRequest:FWFNSUrlRequestDataFromNSURLRequest(action.request) targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)]; +} + + +FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request) { + return [FWFNSUrlRequestData makeWithUrl:request.URL.absoluteString httpMethod:request.HTTPMethod httpBody:[FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] allHttpHeaderFields:request.allHTTPHeaderFields]; +} + +FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info) { + return [FWFWKFrameInfoData makeWithIsMainFrame:@(info.isMainFrame)]; +} + +WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigationActionPolicyEnumData *data) { + switch(data.value) { + case FWFWKNavigationActionPolicyEnumAllow: + return WKNavigationActionPolicyAllow; + case FWFWKNavigationActionPolicyEnumCancel: + return WKNavigationActionPolicyCancel; + } + + return -1; +} + +FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error) { + return [FWFNSErrorData makeWithCode:@(error.code) domain:error.domain localiziedDescription:error.localizedDescription]; +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m index be651c942c0e..f1c80ce30e65 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m @@ -4,6 +4,7 @@ #import "FWFNavigationDelegateHostApi.h" #import "FWFWebViewConfigurationHostApi.h" +#import "FWFDataConverters.h" @interface FWFNavigationDelegateFlutterApiImpl () // This reference must be weak to prevent a circular reference with the objects it stores. @@ -26,15 +27,59 @@ - (long)identifierForDelegate:(FWFNavigationDelegate *)instance { - (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView - URL:(NSString *)URL { + URL:(NSString *)URL + completion: + (void (^)(NSError *_Nullable))completion { [self didFinishNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier: @([self.instanceManager identifierWithStrongReferenceForInstance:webView]) URL:URL - completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; + completion:completion]; +} + +-(void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + URL:(NSString *)URL + completion: + (void (^)(NSError *_Nullable))completion { + [self didStartProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]) + URL:URL + completion:completion]; +} + +- (void)decidePolicyForNavigationActionForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + navigationAction:(WKNavigationAction *)navigationAction + completion:(void (^)(FWFWKNavigationActionPolicyEnumData + *_Nullable, + NSError *_Nullable))completion { + [self decidePolicyForNavigationActionForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier:@([self.instanceManager + identifierWithStrongReferenceForInstance:webView]) + navigationAction:FWFWKNavigationActionDataFromNavigationAction(navigationAction) + completion:completion]; +} + +- (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError * _Nullable))completion { + [self didFailNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) + error:FWFNSErrorDataFromNSError(error) + completion:completion]; +} + +- (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError * _Nullable))completion { + [self didFailProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) + error:FWFNSErrorDataFromNSError(error) + completion:completion]; +} + +- (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView completion:(void (^)(NSError * _Nullable))completion { + [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) completion:completion]; } @end @@ -53,7 +98,42 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [self.navigationDelegateAPI didFinishNavigationForDelegate:self webView:webView - URL:webView.URL.absoluteString]; + URL:webView.URL.absoluteString + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { + [self.navigationDelegateAPI didStartProvisionalNavigationForDelegate:self webView:webView URL:webView.URL.absoluteString + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { + [self.navigationDelegateAPI decidePolicyForNavigationActionForDelegate:self webView:webView navigationAction:navigationAction completion:^(FWFWKNavigationActionPolicyEnumData *policy, NSError *error) { + NSAssert(!error, @"%@", error); + decisionHandler(FWFWKNavigationActionPolicyFromEnumData(policy)); + }]; +} + +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { + [self.navigationDelegateAPI didFailNavigationForDelegate:self webView:webView error:error completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { + [self.navigationDelegateAPI didFailProvisionalNavigationForDelegate:self webView:webView error:error completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { + [self.navigationDelegateAPI webViewWebContentProcessDidTerminateForDelegate:self webView:webView completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } @end From b83c2cc90320b758e9807fd9762488a3df3f0632 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:06:07 -0700 Subject: [PATCH 03/16] finish nsobject --- .../ios/Classes/FWFDataConverters.h | 9 ++++++ .../ios/Classes/FWFDataConverters.m | 20 ++++++++++++ .../ios/Classes/FWFObjectHostApi.m | 31 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h index 33fee9ebcf94..a75269fb2b5b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h @@ -130,4 +130,13 @@ extern WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNav */ extern FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error); +/** + * Converts an NSKeyValueChangeKey to a FWFNSKeyValueChangeKeyEnumData. + * + * @param key The data object containing information to create a FWFNSKeyValueChangeKeyEnumData. + * + * @return A FWFNSKeyValueChangeKeyEnumData or nil if data could not be converted. + */ +extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key); + NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 76246b64509c..1e4babab3d73 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -181,3 +181,23 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigation FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error) { return [FWFNSErrorData makeWithCode:@(error.code) domain:error.domain localiziedDescription:error.localizedDescription]; } + +FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key) { + if ([key isEqualToString:NSKeyValueChangeIndexesKey]) { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumIndexes]; + } else + if ([key isEqualToString:NSKeyValueChangeKindKey]) { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumKind]; + }else + if ([key isEqualToString:NSKeyValueChangeNewKey]) { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNewValue]; + }else + if ([key isEqualToString:NSKeyValueChangeNotificationIsPriorKey]) { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior]; + }else + if ([key isEqualToString:NSKeyValueChangeOldKey]) { + return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue]; + } + + return nil; +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index 0cc4c5693342..de5a653f917a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -19,6 +19,31 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen } return self; } + +- (long)identifierForObject:(NSObject *)instance { + return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; +} + +- (void)observeValueForObject:(NSObject *)instance + keyPath:(NSString *)keyPath + object:(NSObject *)object + change:(NSDictionary *)change + completion:(void (^)(NSError * _Nullable))completion { + NSMutableArray *changeKeys = [NSMutableArray array]; + NSMutableArray *changeValues = [NSMutableArray array]; + + [change enumerateKeysAndObjectsUsingBlock:^(NSKeyValueChangeKey key, id value, BOOL* stop) { + [changeKeys addObject:FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(key)]; + [changeValues addObject:value]; + }]; + + [self observeValueForObjectWithIdentifier:@([self identifierForObject:instance]) + keyPath:keyPath + objectIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:object]) + changeKeys:changeKeys + changeValues:changeValues + completion:completion]; +} @end @implementation FWFObject @@ -31,6 +56,12 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen } return self; } + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + [self.objectApi observeValueForObject:self keyPath:keyPath object:object change:change completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} @end @interface FWFObjectHostApiImpl () From fbeb901ea6be324780a10b491fa4b0bd28954a55 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:36:01 -0700 Subject: [PATCH 04/16] finish script handler and uidelegate --- .../ios/Classes/FWFDataConverters.h | 9 ++++ .../ios/Classes/FWFDataConverters.m | 4 ++ .../Classes/FWFNavigationDelegateHostApi.h | 2 + .../Classes/FWFScriptMessageHandlerHostApi.h | 16 +++++- .../Classes/FWFScriptMessageHandlerHostApi.m | 45 ++++++++++++++++- .../ios/Classes/FWFUIDelegateHostApi.h | 16 +++++- .../ios/Classes/FWFUIDelegateHostApi.m | 50 ++++++++++++++++++- 7 files changed, 138 insertions(+), 4 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h index a75269fb2b5b..42a10fd50500 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h @@ -139,4 +139,13 @@ extern FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error); */ extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key); +/** + * Converts a WKScriptMessage to an FWFWKScriptMessageData. + * + * @param message The object containing information to create a FWFWKScriptMessageData. + * + * @return A FWFWKScriptMessageData. + */ +extern FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message); + NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 1e4babab3d73..5136258041fa 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -201,3 +201,7 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigation return nil; } + +FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message) { + return [FWFWKScriptMessageData makeWithName:message.name body:message.body]; +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h index 2ac599603152..c06ebfb372a3 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h @@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FWFNavigationDelegate : FWFObject @property(readonly, nonnull) FWFNavigationDelegateFlutterApiImpl *navigationDelegateAPI; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end /** diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h index 7440862ce4e4..9d5db94bd18e 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h @@ -7,13 +7,27 @@ #import "FWFGeneratedWebKitApis.h" #import "FWFInstanceManager.h" +#import "FWFObjectHostApi.h" NS_ASSUME_NONNULL_BEGIN +/** + * Flutter api implementation for WKScriptMessageHandler. + * + * Handles making callbacks to Dart for a WKScriptMessageHandler. + */ +@interface FWFScriptMessageHandlerFlutterApiImpl : FWFWKScriptMessageHandlerFlutterApi +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; +@end + /** * Implementation of WKScriptMessageHandler for FWFScriptMessageHandlerHostApiImpl. */ -@interface FWFScriptMessageHandler : NSObject +@interface FWFScriptMessageHandler : FWFObject +@property(readonly, nonnull) FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end /** diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m index 9e4b5f003abc..7f39fd14c18a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m @@ -5,14 +5,57 @@ #import "FWFScriptMessageHandlerHostApi.h" #import "FWFDataConverters.h" +@interface FWFScriptMessageHandlerFlutterApiImpl () +// This reference must be weak to prevent a circular reference with the objects it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; +@end + +@implementation FWFScriptMessageHandlerFlutterApiImpl +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { + self = [self initWithBinaryMessenger:binaryMessenger]; + if (self) { + _instanceManager = instanceManager; + } + return self; +} + +- (long)identifierForHandler:(FWFScriptMessageHandler *)instance { + return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; +} + +- (void)didReceiveScriptMessageForHandler:(FWFScriptMessageHandler *)instance + userContentController:(WKUserContentController *)userContentController + message:(WKScriptMessage *)message + completion:(void (^)(NSError * _Nullable))completion { + [self didReceiveScriptMessageForHandlerWithIdentifier:@([self identifierForHandler:instance]) + userContentControllerIdentifier:@([self.instanceManager + identifierWithStrongReferenceForInstance:userContentController]) message:FWFWKScriptMessageDataFromWKScriptMessage(message) completion:completion]; +} +@end + @implementation FWFScriptMessageHandler +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { + self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; + if (self) { + _scriptMessageHandlerAPI = + [[FWFScriptMessageHandlerFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger + instanceManager:instanceManager]; + } + return self; +} + - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { + [self.scriptMessageHandlerAPI didReceiveScriptMessageForHandler:self userContentController:userContentController message:message completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } @end @interface FWFScriptMessageHandlerHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFScriptMessageHandlerHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h index 8795b00e9001..969366f33a16 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h @@ -7,13 +7,27 @@ #import "FWFGeneratedWebKitApis.h" #import "FWFInstanceManager.h" +#import "FWFObjectHostApi.h" NS_ASSUME_NONNULL_BEGIN +/** + * Flutter api implementation for WKUIDelegate. + * + * Handles making callbacks to Dart for a WKUIDelegate. + */ +@interface FWFUIDelegateFlutterApiImpl : FWFWKUIDelegateFlutterApi +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; +@end + /** * Implementation of WKUIDelegate for FWFUIDelegateHostApiImpl. */ -@interface FWFUIDelegate : NSObject +@interface FWFUIDelegate : FWFObject +@property(readonly, nonnull) FWFUIDelegateFlutterApiImpl *UIDelegateAPI; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end /** diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 28d0ab53aaad..4b4caaa0ecfb 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -4,12 +4,60 @@ #import "FWFUIDelegateHostApi.h" #import "FWFWebViewConfigurationHostApi.h" +#import "FWFDataConverters.h" + +@interface FWFUIDelegateFlutterApiImpl () +// This reference must be weak to prevent a circular reference with the objects it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; +@end + +@implementation FWFUIDelegateFlutterApiImpl +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { + self = [self initWithBinaryMessenger:binaryMessenger]; + if (self) { + _instanceManager = instanceManager; + } + return self; +} + +- (long)identifierForDelegate:(FWFUIDelegate *)instance { + return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; +} + +- (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance + configuration:(WKWebViewConfiguration *)configuration + navigationAction:(WKNavigationAction *)navigationAction + completion:(void (^)(NSError * _Nullable))completion { + [self onCreateWebViewForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + configurationIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:configuration]) + navigationAction:FWFWKNavigationActionDataFromNavigationAction(navigationAction) + completion:completion]; +} +@end @implementation FWFUIDelegate +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { + self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; + if (self) { + _UIDelegateAPI = + [[FWFUIDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger + instanceManager:instanceManager]; + } + return self; +} + +- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { + [self.UIDelegateAPI onCreateWebViewForDelegate:self configuration:configuration navigationAction:navigationAction completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; + return nil; +} @end @interface FWFUIDelegateHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFUIDelegateHostApiImpl From b6873302b4930fb8764b22463907e674808484bf Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 19:47:34 -0700 Subject: [PATCH 05/16] test progress --- .../FWFNavigationDelegateHostApiTests.m | 85 +++++++++++++++++-- .../FWFScriptMessageHandlerHostApiTests.m | 1 + .../ios/Classes/FWFDataConverters.m | 5 +- 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 206137e301f5..296fd017e21d 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -12,6 +12,20 @@ @interface FWFNavigationDelegateHostApiTests : XCTestCase @end @implementation FWFNavigationDelegateHostApiTests +- (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { + FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; + + return OCMPartialMock(navigationDelegate); +} + +- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { + FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + return OCMPartialMock(flutterAPI); +} + - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; FWFNavigationDelegateHostApiImpl *hostAPI = [[FWFNavigationDelegateHostApiImpl alloc] @@ -29,15 +43,35 @@ - (void)testCreateWithIdentifier { - (void)testDidFinishNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegateHostApiImpl *hostAPI = [[FWFNavigationDelegateHostApiImpl alloc] + + FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + id mockDelegate = OCMPartialMock(navigationDelegate); + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; + + FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; + id mockFlutterApi = OCMPartialMock(flutterAPI); - FlutterError *error; - [hostAPI createWithIdentifier:@0 error:&error]; - FWFNavigationDelegate *navigationDelegate = - (FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0]; + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterApi); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + [mockDelegate webView:mockWebView didFinishNavigation:OCMClassMock([WKNavigation class])]; + OCMVerify([mockFlutterApi didFinishNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + URL:@"https://flutter.dev/" + completion:OCMOCK_ANY]); +} + +- (void)testDidStartProvisionalNavigation { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; id mockDelegate = OCMPartialMock(navigationDelegate); + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) @@ -50,10 +84,47 @@ - (void)testDidFinishNavigation { OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - [mockDelegate webView:mockWebView didFinishNavigation:OCMClassMock([WKNavigation class])]; - OCMVerify([mockFlutterApi didFinishNavigationForDelegateWithIdentifier:@0 + [mockDelegate webView:mockWebView didStartProvisionalNavigation:OCMClassMock([WKNavigation class])]; + OCMVerify([mockFlutterApi didStartProvisionalNavigationForDelegateWithIdentifier:@0 webViewIdentifier:@1 URL:@"https://flutter.dev/" completion:OCMOCK_ANY]); } + +- (void)testDecidePolicyForNavigationAction { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + id mockDelegate = OCMPartialMock(navigationDelegate); + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; + + FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + id mockFlutterApi = OCMPartialMock(flutterAPI); + + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterApi); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); + OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); + + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); + OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); + OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); + + OCMStub([mockFlutterApi decidePolicyForNavigationActionForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + navigationAction:[OCMArg isKindOfClass:[FWFWKNavigationActionData class]] + completion:([OCMArg invokeBlockWithArgs:[FWFWKNavigationActionPolicyEnumData makeWithValue:FWFWKNavigationActionPolicyEnumCancel], [NSNull null], nil])]); + + WKNavigationActionPolicy __block callbackPolicy = -1; + [mockDelegate webView:mockWebView decidePolicyForNavigationAction:mockNavigationAction decisionHandler:^(WKNavigationActionPolicy policy) { + callbackPolicy = policy; + }]; + XCTAssertEqual(callbackPolicy, WKNavigationActionPolicyCancel); +} @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index b74d21114cc4..fae8ce7c6bb0 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -26,4 +26,5 @@ - (void)testCreateWithIdentifier { XCTAssertTrue([scriptMessageHandler conformsToProtocol:@protocol(WKScriptMessageHandler)]); XCTAssertNil(error); } + @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 5136258041fa..70c19ea3b295 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -160,7 +160,10 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData( FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request) { - return [FWFNSUrlRequestData makeWithUrl:request.URL.absoluteString httpMethod:request.HTTPMethod httpBody:[FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] allHttpHeaderFields:request.allHTTPHeaderFields]; + return [FWFNSUrlRequestData makeWithUrl:request.URL.absoluteString + httpMethod:request.HTTPMethod + httpBody:request.HTTPBody ? [FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] : nil + allHttpHeaderFields:request.allHTTPHeaderFields ? request.allHTTPHeaderFields : @{}]; } FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info) { From b0eb2cc45e1925005aa2d1ffaf69479d832078bb Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 20:29:46 -0700 Subject: [PATCH 06/16] object tests --- .../FWFNavigationDelegateHostApiTests.m | 97 +++++++++++++------ .../ios/RunnerTests/FWFObjectHostApiTests.m | 33 +++++++ .../ios/Classes/FWFObjectHostApi.h | 4 +- .../ios/Classes/FWFObjectHostApi.m | 6 +- 4 files changed, 103 insertions(+), 37 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 296fd017e21d..113a0c800738 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -15,7 +15,6 @@ @implementation FWFNavigationDelegateHostApiTests - (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; - return OCMPartialMock(navigationDelegate); } @@ -44,23 +43,17 @@ - (void)testCreateWithIdentifier { - (void)testDidFinishNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; - id mockDelegate = OCMPartialMock(navigationDelegate); - [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; - - FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - id mockFlutterApi = OCMPartialMock(flutterAPI); + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; - OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterApi); + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; [mockDelegate webView:mockWebView didFinishNavigation:OCMClassMock([WKNavigation class])]; - OCMVerify([mockFlutterApi didFinishNavigationForDelegateWithIdentifier:@0 + OCMVerify([mockFlutterAPI didFinishNavigationForDelegateWithIdentifier:@0 webViewIdentifier:@1 URL:@"https://flutter.dev/" completion:OCMOCK_ANY]); @@ -69,23 +62,17 @@ - (void)testDidFinishNavigation { - (void)testDidStartProvisionalNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; - id mockDelegate = OCMPartialMock(navigationDelegate); - [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; - FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - id mockFlutterApi = OCMPartialMock(flutterAPI); - - OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterApi); + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; [mockDelegate webView:mockWebView didStartProvisionalNavigation:OCMClassMock([WKNavigation class])]; - OCMVerify([mockFlutterApi didStartProvisionalNavigationForDelegateWithIdentifier:@0 + OCMVerify([mockFlutterAPI didStartProvisionalNavigationForDelegateWithIdentifier:@0 webViewIdentifier:@1 URL:@"https://flutter.dev/" completion:OCMOCK_ANY]); @@ -94,19 +81,12 @@ - (void)testDidStartProvisionalNavigation { - (void)testDecidePolicyForNavigationAction { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; - id mockDelegate = OCMPartialMock(navigationDelegate); - [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; - FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - id mockFlutterApi = OCMPartialMock(flutterAPI); - - OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterApi); + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); - OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); @@ -116,7 +96,7 @@ - (void)testDecidePolicyForNavigationAction { OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); - OCMStub([mockFlutterApi decidePolicyForNavigationActionForDelegateWithIdentifier:@0 + OCMStub([mockFlutterAPI decidePolicyForNavigationActionForDelegateWithIdentifier:@0 webViewIdentifier:@1 navigationAction:[OCMArg isKindOfClass:[FWFWKNavigationActionData class]] completion:([OCMArg invokeBlockWithArgs:[FWFWKNavigationActionPolicyEnumData makeWithValue:FWFWKNavigationActionPolicyEnumCancel], [NSNull null], nil])]); @@ -127,4 +107,57 @@ - (void)testDecidePolicyForNavigationAction { }]; XCTAssertEqual(callbackPolicy, WKNavigationActionPolicyCancel); } + +- (void)testDidFailNavigation { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + [mockDelegate webView:mockWebView didFailNavigation:OCMClassMock([WKNavigation class]) withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; + OCMVerify([mockFlutterAPI didFailNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + error:[OCMArg isKindOfClass:[FWFNSErrorData class]] + completion:OCMOCK_ANY]); +} + +- (void)testDidFailProvisionalNavigation { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + [mockDelegate webView:mockWebView didFailProvisionalNavigation:OCMClassMock([WKNavigation class]) withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; + OCMVerify([mockFlutterAPI didFailProvisionalNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + error:[OCMArg isKindOfClass:[FWFNSErrorData class]] + completion:OCMOCK_ANY]); +} + +- (void)testWebViewWebContentProcessDidTerminate { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + [mockDelegate webViewWebContentProcessDidTerminate:mockWebView]; + OCMVerify([mockFlutterAPI webViewWebContentProcessDidTerminateForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + completion:OCMOCK_ANY]); +} @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m index bdaeae4c09dc..3073601374d1 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m @@ -12,6 +12,19 @@ @interface FWFObjectHostApiTests : XCTestCase @end @implementation FWFObjectHostApiTests +- (id)mockObjectWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { + FWFObject *object = [[FWFObject alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + [instanceManager addDartCreatedInstance:object withIdentifier:0]; + return OCMPartialMock(object); +} + +- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { + FWFObjectFlutterApiImpl *flutterAPI = [[FWFObjectFlutterApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + return OCMPartialMock(flutterAPI); +} + - (void)testAddObserver { NSObject *mockObject = OCMClassMock([NSObject class]); @@ -82,4 +95,24 @@ - (void)testDispose { XCTAssertFalse([instanceManager containsInstance:object]); XCTAssertNil(error); } + +- (void)testObserveValueForKeyPath { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFObject *mockObject = [self mockObjectWithManager:instanceManager identifier:0]; + FWFObjectFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockObject objectApi]).andReturn(mockFlutterAPI); + + NSObject *object = [[NSObject alloc] init]; + [instanceManager addDartCreatedInstance:object withIdentifier:1]; + + [mockObject observeValueForKeyPath:@"keyPath" ofObject:object change:@{NSKeyValueChangeOldKey: @"key"} context:nil]; + OCMVerify([mockFlutterAPI observeValueForObjectWithIdentifier:@0 + keyPath:@"keyPath" + objectIdentifier:@1 + changeKeys:[OCMArg checkWithBlock:^BOOL(NSArray * value) { return value[0].value == FWFNSKeyValueChangeKeyEnumOldValue; }] + changeValues:[OCMArg checkWithBlock:^BOOL(id value) { return [@"key" isEqual:value[0]]; }] + completion:OCMOCK_ANY]); +} @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h index f1dbdbb20776..84165c4b8f3d 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN * * Handles making callbacks to Dart for an NSObject. */ -@interface FWFObjectFlutterApi : FWFNSObjectFlutterApi +@interface FWFObjectFlutterApiImpl : FWFNSObjectFlutterApi - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of NSObject for FWFObjectHostApiImpl. */ @interface FWFObject : NSObject -@property(readonly, nonnull) FWFObjectFlutterApi *objectApi; +@property(readonly, nonnull) FWFObjectFlutterApiImpl *objectApi; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index de5a653f917a..fbe698aaace2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -5,12 +5,12 @@ #import "FWFObjectHostApi.h" #import "FWFDataConverters.h" -@interface FWFObjectFlutterApi () +@interface FWFObjectFlutterApiImpl () // This reference must be weak to prevent a circular reference with the objects it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end -@implementation FWFObjectFlutterApi +@implementation FWFObjectFlutterApiImpl - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager { self = [self initWithBinaryMessenger:binaryMessenger]; @@ -51,7 +51,7 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen instanceManager:(FWFInstanceManager *)instanceManager { self = [self init]; if (self) { - _objectApi = [[FWFObjectFlutterApi alloc] initWithBinaryMessenger:binaryMessenger + _objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; } return self; From 776931a1caf5a4d2ebf92c83617d4715975ddd79 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 20:48:03 -0700 Subject: [PATCH 07/16] almost done still need uidelegate --- .../FWFScriptMessageHandlerHostApiTests.m | 34 +++++++++++++++ .../RunnerTests/FWFUIDelegateHostApiTests.m | 41 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index fae8ce7c6bb0..58cf6d256ec4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -12,6 +12,19 @@ @interface FWFScriptMessageHandlerHostApiTests : XCTestCase @end @implementation FWFScriptMessageHandlerHostApiTests +- (id)mockHandlerWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { + FWFScriptMessageHandler *handler = [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + [instanceManager addDartCreatedInstance:handler withIdentifier:0]; + return OCMPartialMock(handler); +} + +- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { + FWFScriptMessageHandlerFlutterApiImpl *flutterAPI = [[FWFScriptMessageHandlerFlutterApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + return OCMPartialMock(flutterAPI); +} + - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; FWFScriptMessageHandlerHostApiImpl *hostAPI = @@ -27,4 +40,25 @@ - (void)testCreateWithIdentifier { XCTAssertNil(error); } +- (void)testWebViewWebContentProcessDidTerminate { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFScriptMessageHandler *mockHandler = [self mockHandlerWithManager:instanceManager identifier:0]; + FWFScriptMessageHandlerFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockHandler scriptMessageHandlerAPI]).andReturn(mockFlutterAPI); + + WKUserContentController *userContentController = [[WKUserContentController alloc] init]; + [instanceManager addDartCreatedInstance:userContentController withIdentifier:1]; + + WKScriptMessage *mockScriptMessage = OCMClassMock([WKScriptMessage class]); + OCMStub([mockScriptMessage name]).andReturn(@"name"); + OCMStub([mockScriptMessage body]).andReturn(@"message"); + + [mockHandler userContentController:userContentController didReceiveScriptMessage:mockScriptMessage]; + OCMVerify([mockFlutterAPI didReceiveScriptMessageForHandlerWithIdentifier:@0 + userContentControllerIdentifier:@1 + message:[OCMArg isKindOfClass:[FWFWKScriptMessageData class]] + completion:OCMOCK_ANY]); +} @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index 4ee36ae7c492..fe0ef2f64fc5 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -12,6 +12,19 @@ @interface FWFUIDelegateHostApiTests : XCTestCase @end @implementation FWFUIDelegateHostApiTests +- (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { + FWFUIDelegate *delegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + [instanceManager addDartCreatedInstance:delegate withIdentifier:0]; + return OCMPartialMock(delegate); +} + +- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { + FWFUIDelegateFlutterApiImpl *flutterAPI = [[FWFUIDelegateFlutterApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + return OCMPartialMock(flutterAPI); +} + - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; FWFUIDelegateHostApiImpl *hostAPI = @@ -24,4 +37,32 @@ - (void)testCreateWithIdentifier { XCTAssertTrue([delegate conformsToProtocol:@protocol(WKUIDelegate)]); XCTAssertNil(error); } + +- (void)testWebViewWebContentProcessDidTerminate { + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + + FWFUIDelegate *mockDelegate = [self mockDelegateWithManager:instanceManager identifier:0]; + FWFUIDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + OCMStub([mockDelegate UIDelegateAPI]).andReturn(mockFlutterAPI); + + WKWebView *mockWebView = OCMClassMock([WKWebView class]); + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; + [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + + WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); + OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); + + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); + OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); + OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); + + [mockDelegate webView:mockWebView +createWebViewWithConfiguration:configuration + forNavigationAction:mockNavigationAction + windowFeatures:OCMClassMock([WKWindowFeatures class])]; + OCMVerify([mockFlutterAPI onCreateWebViewForDelegateWithIdentifier:@0 configurationIdentifier:@1 navigationAction:nil completion:OCMOCK_ANY]); +} @end From 3c8b396ee8ae9db60f410a863e8ffc9fc2d43155 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 21:00:14 -0700 Subject: [PATCH 08/16] update generated files --- .../ios/Classes/FWFGeneratedWebKitApis.h | 1 + .../ios/Classes/FWFGeneratedWebKitApis.m | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 b2abedb00276..da21f4e3b473 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h @@ -524,6 +524,7 @@ 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; 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 19b44761e982..b292b50a4ee4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m @@ -2561,6 +2561,7 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina return self; } - (void)onCreateWebViewForDelegateWithIdentifier:(NSNumber *)arg_identifier + webViewIdentifier:(NSNumber *)arg_webViewIdentifier configurationIdentifier:(NSNumber *)arg_configurationIdentifier navigationAction:(FWFWKNavigationActionData *)arg_navigationAction completion:(void (^)(NSError *_Nullable))completion { @@ -2569,8 +2570,8 @@ - (void)onCreateWebViewForDelegateWithIdentifier:(NSNumber *)arg_identifier binaryMessenger:self.binaryMessenger codec:FWFWKUIDelegateFlutterApiGetCodec()]; [channel sendMessage:@[ - arg_identifier ?: [NSNull null], arg_configurationIdentifier ?: [NSNull null], - arg_navigationAction ?: [NSNull null] + arg_identifier ?: [NSNull null], arg_webViewIdentifier ?: [NSNull null], + arg_configurationIdentifier ?: [NSNull null], arg_navigationAction ?: [NSNull null] ] reply:^(id reply) { completion(nil); From 9f73d4b73959ce91287ccbed21912df84f408cc1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 7 Jun 2022 21:04:54 -0700 Subject: [PATCH 09/16] finish most tests --- .../RunnerTests/FWFScriptMessageHandlerHostApiTests.m | 2 +- .../ios/RunnerTests/FWFUIDelegateHostApiTests.m | 10 +++++++--- .../ios/Classes/FWFUIDelegateHostApi.m | 8 +++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index 58cf6d256ec4..0976ea2d9510 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -40,7 +40,7 @@ - (void)testCreateWithIdentifier { XCTAssertNil(error); } -- (void)testWebViewWebContentProcessDidTerminate { +- (void)testDidReceiveScriptMessageForHandler { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; FWFScriptMessageHandler *mockHandler = [self mockHandlerWithManager:instanceManager identifier:0]; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index fe0ef2f64fc5..c3e418e61d0b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -38,7 +38,7 @@ - (void)testCreateWithIdentifier { XCTAssertNil(error); } -- (void)testWebViewWebContentProcessDidTerminate { +- (void)testOnCreateWebViewForDelegateWithIdentifier{ FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; FWFUIDelegate *mockDelegate = [self mockDelegateWithManager:instanceManager identifier:0]; @@ -50,7 +50,7 @@ - (void)testWebViewWebContentProcessDidTerminate { [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; + [instanceManager addDartCreatedInstance:configuration withIdentifier:2]; WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); @@ -63,6 +63,10 @@ - (void)testWebViewWebContentProcessDidTerminate { createWebViewWithConfiguration:configuration forNavigationAction:mockNavigationAction windowFeatures:OCMClassMock([WKWindowFeatures class])]; - OCMVerify([mockFlutterAPI onCreateWebViewForDelegateWithIdentifier:@0 configurationIdentifier:@1 navigationAction:nil completion:OCMOCK_ANY]); + OCMVerify([mockFlutterAPI onCreateWebViewForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + configurationIdentifier:@2 + navigationAction:[OCMArg isKindOfClass:[FWFWKNavigationActionData class]] + completion:OCMOCK_ANY]); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 4b4caaa0ecfb..8ba3884c6ee3 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -26,10 +26,12 @@ - (long)identifierForDelegate:(FWFUIDelegate *)instance { } - (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance + webView:(WKWebView *)webView configuration:(WKWebViewConfiguration *)configuration navigationAction:(WKNavigationAction *)navigationAction completion:(void (^)(NSError * _Nullable))completion { [self onCreateWebViewForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) configurationIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:configuration]) navigationAction:FWFWKNavigationActionDataFromNavigationAction(navigationAction) completion:completion]; @@ -49,7 +51,11 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen } - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { - [self.UIDelegateAPI onCreateWebViewForDelegate:self configuration:configuration navigationAction:navigationAction completion:^(NSError *error) { + [self.UIDelegateAPI onCreateWebViewForDelegate:self + webView:webView + configuration:configuration + navigationAction:navigationAction + completion:^(NSError *error) { NSAssert(!error, @"%@", error); }]; return nil; From 061156a71d9eab7767f06be7506d265f5ec792b5 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 01:00:56 -0700 Subject: [PATCH 10/16] data converter tests --- .../ios/RunnerTests/FWFDataConvertersTests.m | 61 ++++++ .../FWFNavigationDelegateHostApiTests.m | 136 ++++++++----- .../ios/RunnerTests/FWFObjectHostApiTests.m | 33 +++- .../FWFScriptMessageHandlerHostApiTests.m | 27 ++- .../RunnerTests/FWFUIDelegateHostApiTests.m | 36 ++-- .../ios/Classes/FWFDataConverters.h | 9 +- .../ios/Classes/FWFDataConverters.m | 50 ++--- .../Classes/FWFNavigationDelegateHostApi.m | 179 +++++++++++------- .../ios/Classes/FWFObjectHostApi.m | 28 ++- .../Classes/FWFScriptMessageHandlerHostApi.m | 25 ++- .../ios/Classes/FWFUIDelegateHostApi.m | 33 ++-- 11 files changed, 411 insertions(+), 206 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m index 57d90f6c6814..36128e1c946d 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m @@ -6,6 +6,8 @@ @import XCTest; @import webview_flutter_wkwebview; +#import + @interface FWFDataConvertersTests : XCTestCase @end @@ -43,4 +45,63 @@ - (void)testFWFWKUserScriptFromScriptData { XCTAssertEqual(userScript.injectionTime, WKUserScriptInjectionTimeAtDocumentStart); XCTAssertEqual(userScript.isForMainFrameOnly, NO); } + +- (void)testFWFWKNavigationActionDataFromNavigationAction { + WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); + + NSURLRequest *request = + [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev/"]]; + OCMStub([mockNavigationAction request]).andReturn(request); + + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); + OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); + OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); + + FWFWKNavigationActionData *data = + FWFWKNavigationActionDataFromNavigationAction(mockNavigationAction); + XCTAssertNotNil(data); +} + +- (void)testFWFNSUrlRequestDataFromNSURLRequest { + NSMutableURLRequest *request = + [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev/"]]; + request.HTTPMethod = @"POST"; + request.HTTPBody = [@"aString" dataUsingEncoding:NSUTF8StringEncoding]; + request.allHTTPHeaderFields = @{@"a" : @"field"}; + + FWFNSUrlRequestData *data = FWFNSUrlRequestDataFromNSURLRequest(request); + XCTAssertEqualObjects(data.url, @"https://www.flutter.dev/"); + XCTAssertEqualObjects(data.httpMethod, @"POST"); + XCTAssertEqualObjects(data.httpBody.data, [@"aString" dataUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqualObjects(data.allHttpHeaderFields, @{@"a" : @"field"}); +} + +- (void)testFWFWKFrameInfoDataFromWKFrameInfo { + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); + OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); + + FWFWKFrameInfoData *targetFrameData = FWFWKFrameInfoDataFromWKFrameInfo(mockFrameInfo); + XCTAssertEqualObjects(targetFrameData.isMainFrame, @YES); +} + +- (void)testFWFNSErrorDataFromNSError { + NSError *error = [NSError errorWithDomain:@"domain" + code:23 + userInfo:@{NSLocalizedDescriptionKey : @"description"}]; + + FWFNSErrorData *data = FWFNSErrorDataFromNSError(error); + XCTAssertEqualObjects(data.code, @23); + XCTAssertEqualObjects(data.domain, @"domain"); + XCTAssertEqualObjects(data.localiziedDescription, @"description"); +} + +- (void)testFWFWKScriptMessageDataFromWKScriptMessage { + WKScriptMessage *mockScriptMessage = OCMClassMock([WKScriptMessage class]); + OCMStub([mockScriptMessage name]).andReturn(@"name"); + OCMStub([mockScriptMessage body]).andReturn(@"message"); + + FWFWKScriptMessageData *data = FWFWKScriptMessageDataFromWKScriptMessage(mockScriptMessage); + XCTAssertEqualObjects(data.name, @"name"); + XCTAssertEqualObjects(data.body, @"message"); +} @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 113a0c800738..5947f0bfe31f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -12,8 +12,12 @@ @interface FWFNavigationDelegateHostApiTests : XCTestCase @end @implementation FWFNavigationDelegateHostApiTests -- (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { - FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; +- (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager + identifier:(long)identifier { + FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + ; [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; return OCMPartialMock(navigationDelegate); } @@ -42,9 +46,11 @@ - (void)testCreateWithIdentifier { - (void)testDidFinishNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); @@ -61,9 +67,11 @@ - (void)testDidFinishNavigation { - (void)testDidStartProvisionalNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); @@ -71,84 +79,113 @@ - (void)testDidStartProvisionalNavigation { OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://flutter.dev/"]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - [mockDelegate webView:mockWebView didStartProvisionalNavigation:OCMClassMock([WKNavigation class])]; - OCMVerify([mockFlutterAPI didStartProvisionalNavigationForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - URL:@"https://flutter.dev/" - completion:OCMOCK_ANY]); + [mockDelegate webView:mockWebView + didStartProvisionalNavigation:OCMClassMock([WKNavigation class])]; + OCMVerify([mockFlutterAPI + didStartProvisionalNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + URL:@"https://flutter.dev/" + completion:OCMOCK_ANY]); } - (void)testDecidePolicyForNavigationAction { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - + WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); - OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); - + OCMStub([mockNavigationAction request]) + .andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); - - OCMStub([mockFlutterAPI decidePolicyForNavigationActionForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - navigationAction:[OCMArg isKindOfClass:[FWFWKNavigationActionData class]] - completion:([OCMArg invokeBlockWithArgs:[FWFWKNavigationActionPolicyEnumData makeWithValue:FWFWKNavigationActionPolicyEnumCancel], [NSNull null], nil])]); - + + OCMStub([mockFlutterAPI + decidePolicyForNavigationActionForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + navigationAction: + [OCMArg isKindOfClass:[FWFWKNavigationActionData + class]] + completion: + ([OCMArg + invokeBlockWithArgs: + [FWFWKNavigationActionPolicyEnumData + makeWithValue: + FWFWKNavigationActionPolicyEnumCancel], + [NSNull null], nil])]); + WKNavigationActionPolicy __block callbackPolicy = -1; - [mockDelegate webView:mockWebView decidePolicyForNavigationAction:mockNavigationAction decisionHandler:^(WKNavigationActionPolicy policy) { - callbackPolicy = policy; - }]; + [mockDelegate webView:mockWebView + decidePolicyForNavigationAction:mockNavigationAction + decisionHandler:^(WKNavigationActionPolicy policy) { + callbackPolicy = policy; + }]; XCTAssertEqual(callbackPolicy, WKNavigationActionPolicyCancel); } - (void)testDidFailNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - [mockDelegate webView:mockWebView didFailNavigation:OCMClassMock([WKNavigation class]) withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; - OCMVerify([mockFlutterAPI didFailNavigationForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - error:[OCMArg isKindOfClass:[FWFNSErrorData class]] - completion:OCMOCK_ANY]); + [mockDelegate webView:mockWebView + didFailNavigation:OCMClassMock([WKNavigation class]) + withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; + OCMVerify([mockFlutterAPI + didFailNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + error:[OCMArg isKindOfClass:[FWFNSErrorData class]] + completion:OCMOCK_ANY]); } - (void)testDidFailProvisionalNavigation { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); WKWebView *mockWebView = OCMClassMock([WKWebView class]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - [mockDelegate webView:mockWebView didFailProvisionalNavigation:OCMClassMock([WKNavigation class]) withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; - OCMVerify([mockFlutterAPI didFailProvisionalNavigationForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - error:[OCMArg isKindOfClass:[FWFNSErrorData class]] - completion:OCMOCK_ANY]); + [mockDelegate webView:mockWebView + didFailProvisionalNavigation:OCMClassMock([WKNavigation class]) + withError:[NSError errorWithDomain:@"domain" code:0 userInfo:nil]]; + OCMVerify([mockFlutterAPI + didFailProvisionalNavigationForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + error:[OCMArg isKindOfClass:[FWFNSErrorData + class]] + completion:OCMOCK_ANY]); } - (void)testWebViewWebContentProcessDidTerminate { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + + FWFNavigationDelegate *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager + identifier:0]; + FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); @@ -156,8 +193,9 @@ - (void)testWebViewWebContentProcessDidTerminate { [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; [mockDelegate webViewWebContentProcessDidTerminate:mockWebView]; - OCMVerify([mockFlutterAPI webViewWebContentProcessDidTerminateForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - completion:OCMOCK_ANY]); + OCMVerify([mockFlutterAPI + webViewWebContentProcessDidTerminateForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + completion:OCMOCK_ANY]); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m index 3073601374d1..d555d14acb3f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m @@ -13,7 +13,10 @@ @interface FWFObjectHostApiTests : XCTestCase @implementation FWFObjectHostApiTests - (id)mockObjectWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { - FWFObject *object = [[FWFObject alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + FWFObject *object = + [[FWFObject alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + ; [instanceManager addDartCreatedInstance:object withIdentifier:0]; return OCMPartialMock(object); } @@ -98,21 +101,31 @@ - (void)testDispose { - (void)testObserveValueForKeyPath { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - + FWFObject *mockObject = [self mockObjectWithManager:instanceManager identifier:0]; FWFObjectFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockObject objectApi]).andReturn(mockFlutterAPI); - + NSObject *object = [[NSObject alloc] init]; [instanceManager addDartCreatedInstance:object withIdentifier:1]; - [mockObject observeValueForKeyPath:@"keyPath" ofObject:object change:@{NSKeyValueChangeOldKey: @"key"} context:nil]; - OCMVerify([mockFlutterAPI observeValueForObjectWithIdentifier:@0 - keyPath:@"keyPath" - objectIdentifier:@1 - changeKeys:[OCMArg checkWithBlock:^BOOL(NSArray * value) { return value[0].value == FWFNSKeyValueChangeKeyEnumOldValue; }] - changeValues:[OCMArg checkWithBlock:^BOOL(id value) { return [@"key" isEqual:value[0]]; }] - completion:OCMOCK_ANY]); + [mockObject observeValueForKeyPath:@"keyPath" + ofObject:object + change:@{NSKeyValueChangeOldKey : @"key"} + context:nil]; + OCMVerify([mockFlutterAPI + observeValueForObjectWithIdentifier:@0 + keyPath:@"keyPath" + objectIdentifier:@1 + changeKeys:[OCMArg checkWithBlock:^BOOL( + NSArray + *value) { + return value[0].value == FWFNSKeyValueChangeKeyEnumOldValue; + }] + changeValues:[OCMArg checkWithBlock:^BOOL(id value) { + return [@"key" isEqual:value[0]]; + }] + completion:OCMOCK_ANY]); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index 0976ea2d9510..0b1ee8b043b2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -13,7 +13,10 @@ @interface FWFScriptMessageHandlerHostApiTests : XCTestCase @implementation FWFScriptMessageHandlerHostApiTests - (id)mockHandlerWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { - FWFScriptMessageHandler *handler = [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + FWFScriptMessageHandler *handler = [[FWFScriptMessageHandler alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + ; [instanceManager addDartCreatedInstance:handler withIdentifier:0]; return OCMPartialMock(handler); } @@ -42,23 +45,27 @@ - (void)testCreateWithIdentifier { - (void)testDidReceiveScriptMessageForHandler { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - + FWFScriptMessageHandler *mockHandler = [self mockHandlerWithManager:instanceManager identifier:0]; - FWFScriptMessageHandlerFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; + FWFScriptMessageHandlerFlutterApiImpl *mockFlutterAPI = + [self mockFlutterApiWithManager:instanceManager]; OCMStub([mockHandler scriptMessageHandlerAPI]).andReturn(mockFlutterAPI); - + WKUserContentController *userContentController = [[WKUserContentController alloc] init]; [instanceManager addDartCreatedInstance:userContentController withIdentifier:1]; - + WKScriptMessage *mockScriptMessage = OCMClassMock([WKScriptMessage class]); OCMStub([mockScriptMessage name]).andReturn(@"name"); OCMStub([mockScriptMessage body]).andReturn(@"message"); - [mockHandler userContentController:userContentController didReceiveScriptMessage:mockScriptMessage]; - OCMVerify([mockFlutterAPI didReceiveScriptMessageForHandlerWithIdentifier:@0 - userContentControllerIdentifier:@1 - message:[OCMArg isKindOfClass:[FWFWKScriptMessageData class]] - completion:OCMOCK_ANY]); + [mockHandler userContentController:userContentController + didReceiveScriptMessage:mockScriptMessage]; + OCMVerify([mockFlutterAPI + didReceiveScriptMessageForHandlerWithIdentifier:@0 + userContentControllerIdentifier:@1 + message:[OCMArg isKindOfClass:[FWFWKScriptMessageData + class]] + completion:OCMOCK_ANY]); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index c3e418e61d0b..c4eed0167973 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -13,7 +13,10 @@ @interface FWFUIDelegateHostApiTests : XCTestCase @implementation FWFUIDelegateHostApiTests - (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { - FWFUIDelegate *delegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager];; + FWFUIDelegate *delegate = [[FWFUIDelegate alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; + ; [instanceManager addDartCreatedInstance:delegate withIdentifier:0]; return OCMPartialMock(delegate); } @@ -38,9 +41,9 @@ - (void)testCreateWithIdentifier { XCTAssertNil(error); } -- (void)testOnCreateWebViewForDelegateWithIdentifier{ +- (void)testOnCreateWebViewForDelegateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - + FWFUIDelegate *mockDelegate = [self mockDelegateWithManager:instanceManager identifier:0]; FWFUIDelegateFlutterApiImpl *mockFlutterAPI = [self mockFlutterApiWithManager:instanceManager]; @@ -48,25 +51,28 @@ - (void)testOnCreateWebViewForDelegateWithIdentifier{ WKWebView *mockWebView = OCMClassMock([WKWebView class]); [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - + WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; [instanceManager addDartCreatedInstance:configuration withIdentifier:2]; - + WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); - OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); - + OCMStub([mockNavigationAction request]) + .andReturn([NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev"]]); + WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); [mockDelegate webView:mockWebView -createWebViewWithConfiguration:configuration - forNavigationAction:mockNavigationAction - windowFeatures:OCMClassMock([WKWindowFeatures class])]; - OCMVerify([mockFlutterAPI onCreateWebViewForDelegateWithIdentifier:@0 - webViewIdentifier:@1 - configurationIdentifier:@2 - navigationAction:[OCMArg isKindOfClass:[FWFWKNavigationActionData class]] - completion:OCMOCK_ANY]); + createWebViewWithConfiguration:configuration + forNavigationAction:mockNavigationAction + windowFeatures:OCMClassMock([WKWindowFeatures class])]; + OCMVerify([mockFlutterAPI + onCreateWebViewForDelegateWithIdentifier:@0 + webViewIdentifier:@1 + configurationIdentifier:@2 + navigationAction:[OCMArg + isKindOfClass:[FWFWKNavigationActionData class]] + completion:OCMOCK_ANY]); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h index 42a10fd50500..2863048726a9 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h @@ -92,7 +92,8 @@ extern NSString *_Nullable FWFWKWebsiteDataTypeFromEnumData(FWFWKWebsiteDataType * * @return A FWFWKNavigationActionData. */ -extern FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction(WKNavigationAction *action); +extern FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction( + WKNavigationAction *action); /** * Converts a NSURLRequest to an FWFNSUrlRequestData. @@ -119,7 +120,8 @@ extern FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info); * * @return A WKNavigationActionPolicy or -1 if data could not be converted. */ -extern WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigationActionPolicyEnumData *data); +extern WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData( + FWFWKNavigationActionPolicyEnumData *data); /** * Converts a NSError to an FWFNSErrorData. @@ -137,7 +139,8 @@ extern FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error); * * @return A FWFNSKeyValueChangeKeyEnumData or nil if data could not be converted. */ -extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key); +extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey( + NSKeyValueChangeKey key); /** * Converts a WKScriptMessage to an FWFWKScriptMessageData. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 70c19ea3b295..140e88dde434 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -154,54 +154,60 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData( return nil; } -FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction(WKNavigationAction *action) { - return [FWFWKNavigationActionData makeWithRequest:FWFNSUrlRequestDataFromNSURLRequest(action.request) targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)]; +FWFWKNavigationActionData *FWFWKNavigationActionDataFromNavigationAction( + WKNavigationAction *action) { + return [FWFWKNavigationActionData + makeWithRequest:FWFNSUrlRequestDataFromNSURLRequest(action.request) + targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)]; } - FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request) { - return [FWFNSUrlRequestData makeWithUrl:request.URL.absoluteString - httpMethod:request.HTTPMethod - httpBody:request.HTTPBody ? [FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] : nil - allHttpHeaderFields:request.allHTTPHeaderFields ? request.allHTTPHeaderFields : @{}]; + return [FWFNSUrlRequestData + makeWithUrl:request.URL.absoluteString + httpMethod:request.HTTPMethod + httpBody:request.HTTPBody + ? [FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] + : nil + allHttpHeaderFields:request.allHTTPHeaderFields ? request.allHTTPHeaderFields : @{}]; } FWFWKFrameInfoData *FWFWKFrameInfoDataFromWKFrameInfo(WKFrameInfo *info) { return [FWFWKFrameInfoData makeWithIsMainFrame:@(info.isMainFrame)]; } -WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(FWFWKNavigationActionPolicyEnumData *data) { - switch(data.value) { +WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData( + FWFWKNavigationActionPolicyEnumData *data) { + switch (data.value) { case FWFWKNavigationActionPolicyEnumAllow: return WKNavigationActionPolicyAllow; case FWFWKNavigationActionPolicyEnumCancel: return WKNavigationActionPolicyCancel; } - + return -1; } FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error) { - return [FWFNSErrorData makeWithCode:@(error.code) domain:error.domain localiziedDescription:error.localizedDescription]; + return [FWFNSErrorData makeWithCode:@(error.code) + domain:error.domain + localiziedDescription:error.localizedDescription]; } -FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(NSKeyValueChangeKey key) { +FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey( + NSKeyValueChangeKey key) { if ([key isEqualToString:NSKeyValueChangeIndexesKey]) { return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumIndexes]; - } else - if ([key isEqualToString:NSKeyValueChangeKindKey]) { + } else if ([key isEqualToString:NSKeyValueChangeKindKey]) { return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumKind]; - }else - if ([key isEqualToString:NSKeyValueChangeNewKey]) { + } else if ([key isEqualToString:NSKeyValueChangeNewKey]) { return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNewValue]; - }else - if ([key isEqualToString:NSKeyValueChangeNotificationIsPriorKey]) { - return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior]; - }else - if ([key isEqualToString:NSKeyValueChangeOldKey]) { + } else if ([key isEqualToString:NSKeyValueChangeNotificationIsPriorKey]) { + return [FWFNSKeyValueChangeKeyEnumData + makeWithValue:FWFNSKeyValueChangeKeyEnumNotificationIsPrior]; + } else if ([key isEqualToString:NSKeyValueChangeOldKey]) { return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumOldValue]; } - + return nil; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m index f1c80ce30e65..c362b9a6debc 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m @@ -3,8 +3,8 @@ // found in the LICENSE file. #import "FWFNavigationDelegateHostApi.h" -#import "FWFWebViewConfigurationHostApi.h" #import "FWFDataConverters.h" +#import "FWFWebViewConfigurationHostApi.h" @interface FWFNavigationDelegateFlutterApiImpl () // This reference must be weak to prevent a circular reference with the objects it stores. @@ -28,8 +28,7 @@ - (long)identifierForDelegate:(FWFNavigationDelegate *)instance { - (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView URL:(NSString *)URL - completion: - (void (^)(NSError *_Nullable))completion { + completion:(void (^)(NSError *_Nullable))completion { [self didFinishNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier: @([self.instanceManager @@ -38,48 +37,76 @@ - (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance completion:completion]; } --(void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance +- (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + URL:(NSString *)URL + completion:(void (^)(NSError *_Nullable))completion { + [self didStartProvisionalNavigationForDelegateWithIdentifier:@([self + identifierForDelegate:instance]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance: + webView]) + URL:URL + completion:completion]; +} + +- (void) + decidePolicyForNavigationActionForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + navigationAction:(WKNavigationAction *)navigationAction + completion: + (void (^)(FWFWKNavigationActionPolicyEnumData *_Nullable, + NSError *_Nullable))completion { + [self + decidePolicyForNavigationActionForDelegateWithIdentifier:@([self + identifierForDelegate:instance]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance: + webView]) + navigationAction: + FWFWKNavigationActionDataFromNavigationAction( + navigationAction) + completion:completion]; +} + +- (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView - URL:(NSString *)URL - completion: - (void (^)(NSError *_Nullable))completion { - [self didStartProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]) - URL:URL - completion:completion]; -} - -- (void)decidePolicyForNavigationActionForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - navigationAction:(WKNavigationAction *)navigationAction - completion:(void (^)(FWFWKNavigationActionPolicyEnumData - *_Nullable, - NSError *_Nullable))completion { - [self decidePolicyForNavigationActionForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier:@([self.instanceManager - identifierWithStrongReferenceForInstance:webView]) - navigationAction:FWFWKNavigationActionDataFromNavigationAction(navigationAction) - completion:completion]; -} - -- (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError * _Nullable))completion { + error:(NSError *)error + completion:(void (^)(NSError *_Nullable))completion { [self didFailNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]) error:FWFNSErrorDataFromNSError(error) completion:completion]; } -- (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError * _Nullable))completion { - [self didFailProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) - error:FWFNSErrorDataFromNSError(error) - completion:completion]; -} - -- (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView completion:(void (^)(NSError * _Nullable))completion { - [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) completion:completion]; +- (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + error:(NSError *)error + completion:(void (^)(NSError *_Nullable))completion { + [self + didFailProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]) + error:FWFNSErrorDataFromNSError(error) + completion:completion]; +} + +- (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance + webView:(WKWebView *)webView + completion:(void (^)(NSError *_Nullable))completion { + [self + webViewWebContentProcessDidTerminateForDelegateWithIdentifier: + @([self identifierForDelegate:instance]) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance: + webView]) + completion:completion]; } @end @@ -105,35 +132,57 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat } - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { - [self.navigationDelegateAPI didStartProvisionalNavigationForDelegate:self webView:webView URL:webView.URL.absoluteString - completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { - [self.navigationDelegateAPI decidePolicyForNavigationActionForDelegate:self webView:webView navigationAction:navigationAction completion:^(FWFWKNavigationActionPolicyEnumData *policy, NSError *error) { - NSAssert(!error, @"%@", error); - decisionHandler(FWFWKNavigationActionPolicyFromEnumData(policy)); - }]; -} - -- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { - [self.navigationDelegateAPI didFailNavigationForDelegate:self webView:webView error:error completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { - [self.navigationDelegateAPI didFailProvisionalNavigationForDelegate:self webView:webView error:error completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; + [self.navigationDelegateAPI didStartProvisionalNavigationForDelegate:self + webView:webView + URL:webView.URL.absoluteString + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webView:(WKWebView *)webView + decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction + decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { + [self.navigationDelegateAPI + decidePolicyForNavigationActionForDelegate:self + webView:webView + navigationAction:navigationAction + completion:^(FWFWKNavigationActionPolicyEnumData *policy, + NSError *error) { + NSAssert(!error, @"%@", error); + decisionHandler( + FWFWKNavigationActionPolicyFromEnumData(policy)); + }]; +} + +- (void)webView:(WKWebView *)webView + didFailNavigation:(WKNavigation *)navigation + withError:(NSError *)error { + [self.navigationDelegateAPI didFailNavigationForDelegate:self + webView:webView + error:error + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + +- (void)webView:(WKWebView *)webView + didFailProvisionalNavigation:(WKNavigation *)navigation + withError:(NSError *)error { + [self.navigationDelegateAPI didFailProvisionalNavigationForDelegate:self + webView:webView + error:error + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { - [self.navigationDelegateAPI webViewWebContentProcessDidTerminateForDelegate:self webView:webView completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; + [self.navigationDelegateAPI webViewWebContentProcessDidTerminateForDelegate:self + webView:webView + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index fbe698aaace2..65318feb0840 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -28,18 +28,19 @@ - (void)observeValueForObject:(NSObject *)instance keyPath:(NSString *)keyPath object:(NSObject *)object change:(NSDictionary *)change - completion:(void (^)(NSError * _Nullable))completion { + completion:(void (^)(NSError *_Nullable))completion { NSMutableArray *changeKeys = [NSMutableArray array]; NSMutableArray *changeValues = [NSMutableArray array]; - - [change enumerateKeysAndObjectsUsingBlock:^(NSKeyValueChangeKey key, id value, BOOL* stop) { + + [change enumerateKeysAndObjectsUsingBlock:^(NSKeyValueChangeKey key, id value, BOOL *stop) { [changeKeys addObject:FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey(key)]; [changeValues addObject:value]; }]; - + [self observeValueForObjectWithIdentifier:@([self identifierForObject:instance]) keyPath:keyPath - objectIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:object]) + objectIdentifier:@([self.instanceManager + identifierWithStrongReferenceForInstance:object]) changeKeys:changeKeys changeValues:changeValues completion:completion]; @@ -52,15 +53,22 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen self = [self init]; if (self) { _objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; + instanceManager:instanceManager]; } return self; } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - [self.objectApi observeValueForObject:self keyPath:keyPath object:object change:change completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + [self.objectApi observeValueForObject:self + keyPath:keyPath + object:object + change:change + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m index 7f39fd14c18a..d1cee6f83f15 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m @@ -25,12 +25,16 @@ - (long)identifierForHandler:(FWFScriptMessageHandler *)instance { } - (void)didReceiveScriptMessageForHandler:(FWFScriptMessageHandler *)instance - userContentController:(WKUserContentController *)userContentController - message:(WKScriptMessage *)message - completion:(void (^)(NSError * _Nullable))completion { + userContentController:(WKUserContentController *)userContentController + message:(WKScriptMessage *)message + completion:(void (^)(NSError *_Nullable))completion { [self didReceiveScriptMessageForHandlerWithIdentifier:@([self identifierForHandler:instance]) - userContentControllerIdentifier:@([self.instanceManager - identifierWithStrongReferenceForInstance:userContentController]) message:FWFWKScriptMessageDataFromWKScriptMessage(message) completion:completion]; + userContentControllerIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:userContentController]) + message:FWFWKScriptMessageDataFromWKScriptMessage( + message) + completion:completion]; } @end @@ -41,16 +45,19 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen if (self) { _scriptMessageHandlerAPI = [[FWFScriptMessageHandlerFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; + instanceManager:instanceManager]; } return self; } - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { - [self.scriptMessageHandlerAPI didReceiveScriptMessageForHandler:self userContentController:userContentController message:message completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; + [self.scriptMessageHandlerAPI didReceiveScriptMessageForHandler:self + userContentController:userContentController + message:message + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 8ba3884c6ee3..e36901d1fe93 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -3,8 +3,8 @@ // found in the LICENSE file. #import "FWFUIDelegateHostApi.h" -#import "FWFWebViewConfigurationHostApi.h" #import "FWFDataConverters.h" +#import "FWFWebViewConfigurationHostApi.h" @interface FWFUIDelegateFlutterApiImpl () // This reference must be weak to prevent a circular reference with the objects it stores. @@ -27,13 +27,18 @@ - (long)identifierForDelegate:(FWFUIDelegate *)instance { - (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance webView:(WKWebView *)webView - configuration:(WKWebViewConfiguration *)configuration - navigationAction:(WKNavigationAction *)navigationAction - completion:(void (^)(NSError * _Nullable))completion { + configuration:(WKWebViewConfiguration *)configuration + navigationAction:(WKNavigationAction *)navigationAction + completion:(void (^)(NSError *_Nullable))completion { [self onCreateWebViewForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:webView]) - configurationIdentifier:@([self.instanceManager identifierWithStrongReferenceForInstance:configuration]) - navigationAction:FWFWKNavigationActionDataFromNavigationAction(navigationAction) + webViewIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]) + configurationIdentifier: + @([self.instanceManager + identifierWithStrongReferenceForInstance:configuration]) + navigationAction:FWFWKNavigationActionDataFromNavigationAction( + navigationAction) completion:completion]; } @end @@ -43,21 +48,23 @@ - (instancetype)initWithBinaryMessenger:(id)binaryMessen instanceManager:(FWFInstanceManager *)instanceManager { self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; if (self) { - _UIDelegateAPI = - [[FWFUIDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; + _UIDelegateAPI = [[FWFUIDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger + instanceManager:instanceManager]; } return self; } -- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { +- (WKWebView *)webView:(WKWebView *)webView + createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration + forNavigationAction:(WKNavigationAction *)navigationAction + windowFeatures:(WKWindowFeatures *)windowFeatures { [self.UIDelegateAPI onCreateWebViewForDelegate:self webView:webView configuration:configuration navigationAction:navigationAction completion:^(NSError *error) { - NSAssert(!error, @"%@", error); - }]; + NSAssert(!error, @"%@", error); + }]; return nil; } @end From 03b5434d8bc6ac5a70cc6e93bb42bb450d90c93e Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 10:48:52 -0700 Subject: [PATCH 11/16] update generated code --- .../ios/Classes/FWFGeneratedWebKitApis.h | 4 ++-- .../ios/Classes/FWFGeneratedWebKitApis.m | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) 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 da21f4e3b473..ebd29f5cacad 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.h @@ -187,10 +187,10 @@ typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithCode:(NSNumber *)code domain:(NSString *)domain - localiziedDescription:(NSString *)localiziedDescription; + localizedDescription:(NSString *)localizedDescription; @property(nonatomic, strong) NSNumber *code; @property(nonatomic, copy) NSString *domain; -@property(nonatomic, copy) NSString *localiziedDescription; +@property(nonatomic, copy) NSString *localizedDescription; @end @interface FWFWKScriptMessageData : NSObject 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 b292b50a4ee4..592fa87ac9d1 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFGeneratedWebKitApis.m @@ -333,11 +333,11 @@ - (NSDictionary *)toMap { @implementation FWFNSErrorData + (instancetype)makeWithCode:(NSNumber *)code domain:(NSString *)domain - localiziedDescription:(NSString *)localiziedDescription { + localizedDescription:(NSString *)localizedDescription { FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; pigeonResult.code = code; pigeonResult.domain = domain; - pigeonResult.localiziedDescription = localiziedDescription; + pigeonResult.localizedDescription = localizedDescription; return pigeonResult; } + (FWFNSErrorData *)fromMap:(NSDictionary *)dict { @@ -346,15 +346,15 @@ + (FWFNSErrorData *)fromMap:(NSDictionary *)dict { NSAssert(pigeonResult.code != nil, @""); pigeonResult.domain = GetNullableObject(dict, @"domain"); NSAssert(pigeonResult.domain != nil, @""); - pigeonResult.localiziedDescription = GetNullableObject(dict, @"localiziedDescription"); - NSAssert(pigeonResult.localiziedDescription != 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]), - @"localiziedDescription" : (self.localiziedDescription ?: [NSNull null]), + @"localizedDescription" : (self.localizedDescription ?: [NSNull null]), }; } @end From 663689000504c0a63122e8c906ea913583587900 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 10:52:58 -0700 Subject: [PATCH 12/16] fix error name --- .../example/ios/Flutter/AppFrameworkInfo.plist | 2 +- .../webview_flutter_wkwebview/example/ios/Podfile | 2 +- .../example/ios/Runner.xcodeproj/project.pbxproj | 4 ++-- .../webview_flutter_wkwebview/example/ios/Runner/Info.plist | 2 ++ .../example/ios/RunnerTests/FWFDataConvertersTests.m | 2 +- .../webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/AppFrameworkInfo.plist b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/AppFrameworkInfo.plist index 8d4492f977ad..9625e105df39 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/AppFrameworkInfo.plist +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile index 66509fcae284..d01e899e347b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj index e7519af18e7c..4ed8769ea518 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj @@ -614,7 +614,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -664,7 +664,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist index a810c5a172c0..bea41604e8aa 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist @@ -41,5 +41,7 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m index 36128e1c946d..1fc5a95398bd 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m @@ -92,7 +92,7 @@ - (void)testFWFNSErrorDataFromNSError { FWFNSErrorData *data = FWFNSErrorDataFromNSError(error); XCTAssertEqualObjects(data.code, @23); XCTAssertEqualObjects(data.domain, @"domain"); - XCTAssertEqualObjects(data.localiziedDescription, @"description"); + XCTAssertEqualObjects(data.localizedDescription, @"description"); } - (void)testFWFWKScriptMessageDataFromWKScriptMessage { diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m index 140e88dde434..759bfedc1621 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m @@ -190,7 +190,7 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData( FWFNSErrorData *FWFNSErrorDataFromNSError(NSError *error) { return [FWFNSErrorData makeWithCode:@(error.code) domain:error.domain - localiziedDescription:error.localizedDescription]; + localizedDescription:error.localizedDescription]; } FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyValueChangeKey( From a177a7e9ed171c02a6bb6578a1608edafcc0f370 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 10:57:28 -0700 Subject: [PATCH 13/16] nonatomic flutter apis --- .../example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m | 2 +- .../ios/Classes/FWFNavigationDelegateHostApi.h | 2 +- .../webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h | 2 +- .../ios/Classes/FWFScriptMessageHandlerHostApi.h | 2 +- .../ios/Classes/FWFUIDelegateHostApi.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 5947f0bfe31f..5857f2609d09 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -17,7 +17,7 @@ - (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - ; + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; return OCMPartialMock(navigationDelegate); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h index c06ebfb372a3..da5939a3abed 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of WKNavigationDelegate for FWFNavigationDelegateHostApiImpl. */ @interface FWFNavigationDelegate : FWFObject -@property(readonly, nonnull) FWFNavigationDelegateFlutterApiImpl *navigationDelegateAPI; +@property(readonly, nonnull, nonatomic) FWFNavigationDelegateFlutterApiImpl *navigationDelegateAPI; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h index 84165c4b8f3d..1f7b2943974e 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of NSObject for FWFObjectHostApiImpl. */ @interface FWFObject : NSObject -@property(readonly, nonnull) FWFObjectFlutterApiImpl *objectApi; +@property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h index 9d5db94bd18e..c92818c01318 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of WKScriptMessageHandler for FWFScriptMessageHandlerHostApiImpl. */ @interface FWFScriptMessageHandler : FWFObject -@property(readonly, nonnull) FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; +@property(readonly, nonnull, nonatomic) FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h index 969366f33a16..65c148e6b0b1 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of WKUIDelegate for FWFUIDelegateHostApiImpl. */ @interface FWFUIDelegate : FWFObject -@property(readonly, nonnull) FWFUIDelegateFlutterApiImpl *UIDelegateAPI; +@property(readonly, nonnull, nonatomic) FWFUIDelegateFlutterApiImpl *UIDelegateAPI; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end From 2021594164cec17ba2871acc96fd870900869382 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 11:06:50 -0700 Subject: [PATCH 14/16] local variables --- .../Classes/FWFNavigationDelegateHostApi.m | 45 +++++++++---------- .../ios/Classes/FWFObjectHostApi.m | 5 ++- .../Classes/FWFScriptMessageHandlerHostApi.m | 10 ++--- .../ios/Classes/FWFUIDelegateHostApi.m | 11 ++--- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m index c362b9a6debc..ff967fac96cf 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m @@ -29,10 +29,10 @@ - (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView URL:(NSString *)URL completion:(void (^)(NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); [self didFinishNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]) + webViewIdentifier:webViewIdentifier URL:URL completion:completion]; } @@ -41,12 +41,11 @@ - (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instan webView:(WKWebView *)webView URL:(NSString *)URL completion:(void (^)(NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); [self didStartProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance: - webView]) + webViewIdentifier:webViewIdentifier URL:URL completion:completion]; } @@ -58,16 +57,15 @@ - (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instan completion: (void (^)(FWFWKNavigationActionPolicyEnumData *_Nullable, NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); + FWFWKNavigationActionData *navigationActionData = FWFWKNavigationActionDataFromNavigationAction( + navigationAction); [self decidePolicyForNavigationActionForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance: - webView]) - navigationAction: - FWFWKNavigationActionDataFromNavigationAction( - navigationAction) + webViewIdentifier:webViewIdentifier + navigationAction:navigationActionData completion:completion]; } @@ -75,10 +73,10 @@ - (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); [self didFailNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]) + webViewIdentifier:webViewIdentifier error:FWFNSErrorDataFromNSError(error) completion:completion]; } @@ -87,11 +85,11 @@ - (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instanc webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); [self didFailProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]) + webViewIdentifier:webViewIdentifier error:FWFNSErrorDataFromNSError(error) completion:completion]; } @@ -99,13 +97,12 @@ - (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instanc - (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView completion:(void (^)(NSError *_Nullable))completion { + NSNumber *webViewIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:webView]); [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier: @([self identifierForDelegate:instance]) - webViewIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance: - webView]) + webViewIdentifier:webViewIdentifier completion:completion]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index 65318feb0840..4093404f0884 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -37,10 +37,11 @@ - (void)observeValueForObject:(NSObject *)instance [changeValues addObject:value]; }]; + NSNumber *objectIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:object]); [self observeValueForObjectWithIdentifier:@([self identifierForObject:instance]) keyPath:keyPath - objectIdentifier:@([self.instanceManager - identifierWithStrongReferenceForInstance:object]) + objectIdentifier:objectIdentifier changeKeys:changeKeys changeValues:changeValues completion:completion]; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m index d1cee6f83f15..043b2097adc9 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m @@ -28,12 +28,12 @@ - (void)didReceiveScriptMessageForHandler:(FWFScriptMessageHandler *)instance userContentController:(WKUserContentController *)userContentController message:(WKScriptMessage *)message completion:(void (^)(NSError *_Nullable))completion { + NSNumber *userContentControllerIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:userContentController]); + FWFWKScriptMessageData *messageData = FWFWKScriptMessageDataFromWKScriptMessage(message); [self didReceiveScriptMessageForHandlerWithIdentifier:@([self identifierForHandler:instance]) - userContentControllerIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:userContentController]) - message:FWFWKScriptMessageDataFromWKScriptMessage( - message) + userContentControllerIdentifier:userContentControllerIdentifier + message:messageData completion:completion]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index e36901d1fe93..8587f96bc28d 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -30,15 +30,16 @@ - (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance configuration:(WKWebViewConfiguration *)configuration navigationAction:(WKNavigationAction *)navigationAction completion:(void (^)(NSError *_Nullable))completion { + NSNumber *configurationIdentifier = @([self.instanceManager + identifierWithStrongReferenceForInstance:configuration]); + FWFWKNavigationActionData *navigationActionData = FWFWKNavigationActionDataFromNavigationAction( + navigationAction); [self onCreateWebViewForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier: @([self.instanceManager identifierWithStrongReferenceForInstance:webView]) - configurationIdentifier: - @([self.instanceManager - identifierWithStrongReferenceForInstance:configuration]) - navigationAction:FWFWKNavigationActionDataFromNavigationAction( - navigationAction) + configurationIdentifier:configurationIdentifier + navigationAction:navigationActionData completion:completion]; } @end From 5d044a43e89a97d5945264ee993230d8e95379c1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 11:32:56 -0700 Subject: [PATCH 15/16] extra semi and docs --- .../FWFNavigationDelegateHostApiTests.m | 15 +++++++++++++++ .../ios/RunnerTests/FWFObjectHostApiTests.m | 17 ++++++++++++++++- .../FWFScriptMessageHandlerHostApiTests.m | 17 ++++++++++++++++- .../ios/RunnerTests/FWFUIDelegateHostApiTests.m | 17 ++++++++++++++++- 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 5857f2609d09..04a73496ca59 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -12,6 +12,14 @@ @interface FWFNavigationDelegateHostApiTests : XCTestCase @end @implementation FWFNavigationDelegateHostApiTests +/** + * Creates a partially mocked FWFNavigationDelegate and adds it to instanceManager. + * + * @param instanceManager Instance manager to add the delegate to. + * @param identifier Identifier for the delegate added to the instanceManager. + * + * @return A mock FWFNavigationDelegate. + */ - (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] @@ -22,6 +30,13 @@ - (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager return OCMPartialMock(navigationDelegate); } +/** + * Creates a mock FWFNavigationDelegateFlutterApiImpl with instanceManager. + * + * @param instanceManager Instance manager passed to the Flutter API. + * + * @return A mock FWFNavigationDelegateFlutterApiImpl. + */ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { FWFNavigationDelegateFlutterApiImpl *flutterAPI = [[FWFNavigationDelegateFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m index d555d14acb3f..01e8dfbd3478 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m @@ -12,15 +12,30 @@ @interface FWFObjectHostApiTests : XCTestCase @end @implementation FWFObjectHostApiTests +/** + * Creates a partially mocked FWFObject and adds it to instanceManager. + * + * @param instanceManager Instance manager to add the delegate to. + * @param identifier Identifier for the delegate added to the instanceManager. + * + * @return A mock FWFObject. + */ - (id)mockObjectWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { FWFObject *object = [[FWFObject alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - ; + [instanceManager addDartCreatedInstance:object withIdentifier:0]; return OCMPartialMock(object); } +/** + * Creates a mock FWFObjectFlutterApiImpl with instanceManager. + * + * @param instanceManager Instance manager passed to the Flutter API. + * + * @return A mock FWFObjectFlutterApiImpl. + */ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { FWFObjectFlutterApiImpl *flutterAPI = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index 0b1ee8b043b2..ea5ed5d52719 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -12,15 +12,30 @@ @interface FWFScriptMessageHandlerHostApiTests : XCTestCase @end @implementation FWFScriptMessageHandlerHostApiTests +/** + * Creates a partially mocked FWFScriptMessageHandler and adds it to instanceManager. + * + * @param instanceManager Instance manager to add the delegate to. + * @param identifier Identifier for the delegate added to the instanceManager. + * + * @return A mock FWFScriptMessageHandler. + */ - (id)mockHandlerWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { FWFScriptMessageHandler *handler = [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - ; + [instanceManager addDartCreatedInstance:handler withIdentifier:0]; return OCMPartialMock(handler); } +/** + * Creates a mock FWFScriptMessageHandlerFlutterApiImpl with instanceManager. + * + * @param instanceManager Instance manager passed to the Flutter API. + * + * @return A mock FWFScriptMessageHandlerFlutterApiImpl. + */ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { FWFScriptMessageHandlerFlutterApiImpl *flutterAPI = [[FWFScriptMessageHandlerFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index c4eed0167973..2368ba02bcf8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -12,15 +12,30 @@ @interface FWFUIDelegateHostApiTests : XCTestCase @end @implementation FWFUIDelegateHostApiTests +/** + * Creates a partially mocked FWFUIDelegate and adds it to instanceManager. + * + * @param instanceManager Instance manager to add the delegate to. + * @param identifier Identifier for the delegate added to the instanceManager. + * + * @return A mock FWFUIDelegate. + */ - (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { FWFUIDelegate *delegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - ; + [instanceManager addDartCreatedInstance:delegate withIdentifier:0]; return OCMPartialMock(delegate); } +/** + * Creates a mock FWFUIDelegateFlutterApiImpl with instanceManager. + * + * @param instanceManager Instance manager passed to the Flutter API. + * + * @return A mock FWFUIDelegateFlutterApiImpl. + */ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { FWFUIDelegateFlutterApiImpl *flutterAPI = [[FWFUIDelegateFlutterApiImpl alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) From 1123cd305f7a509e84fc33f33011e9569fcacb0c Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Jun 2022 11:42:32 -0700 Subject: [PATCH 16/16] formatting --- .../FWFNavigationDelegateHostApiTests.m | 2 +- .../ios/RunnerTests/FWFObjectHostApiTests.m | 2 +- .../FWFScriptMessageHandlerHostApiTests.m | 2 +- .../RunnerTests/FWFUIDelegateHostApiTests.m | 2 +- .../Classes/FWFNavigationDelegateHostApi.m | 37 +++++++++---------- .../ios/Classes/FWFObjectHostApi.m | 4 +- .../Classes/FWFScriptMessageHandlerHostApi.h | 3 +- .../Classes/FWFScriptMessageHandlerHostApi.m | 4 +- .../ios/Classes/FWFUIDelegateHostApi.m | 10 ++--- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m index 04a73496ca59..570a1f73ad9b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFNavigationDelegateHostApiTests.m @@ -25,7 +25,7 @@ - (id)mockNavigationDelegateWithManager:(FWFInstanceManager *)instanceManager FWFNavigationDelegate *navigationDelegate = [[FWFNavigationDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - + [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; return OCMPartialMock(navigationDelegate); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m index 01e8dfbd3478..b8e41d142331 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFObjectHostApiTests.m @@ -24,7 +24,7 @@ - (id)mockObjectWithManager:(FWFInstanceManager *)instanceManager identifier:(lo FWFObject *object = [[FWFObject alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - + [instanceManager addDartCreatedInstance:object withIdentifier:0]; return OCMPartialMock(object); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index ea5ed5d52719..5a51e7b980f8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -24,7 +24,7 @@ - (id)mockHandlerWithManager:(FWFInstanceManager *)instanceManager identifier:(l FWFScriptMessageHandler *handler = [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - + [instanceManager addDartCreatedInstance:handler withIdentifier:0]; return OCMPartialMock(handler); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index 2368ba02bcf8..17cb4367b3aa 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -24,7 +24,7 @@ - (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:( FWFUIDelegate *delegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) instanceManager:instanceManager]; - + [instanceManager addDartCreatedInstance:delegate withIdentifier:0]; return OCMPartialMock(delegate); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m index ff967fac96cf..6946783088d5 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m @@ -29,8 +29,8 @@ - (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView URL:(NSString *)URL completion:(void (^)(NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); [self didFinishNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:webViewIdentifier URL:URL @@ -41,8 +41,8 @@ - (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instan webView:(WKWebView *)webView URL:(NSString *)URL completion:(void (^)(NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); [self didStartProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:webViewIdentifier @@ -57,10 +57,10 @@ - (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instan completion: (void (^)(FWFWKNavigationActionPolicyEnumData *_Nullable, NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); - FWFWKNavigationActionData *navigationActionData = FWFWKNavigationActionDataFromNavigationAction( - navigationAction); + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); + FWFWKNavigationActionData *navigationActionData = + FWFWKNavigationActionDataFromNavigationAction(navigationAction); [self decidePolicyForNavigationActionForDelegateWithIdentifier:@([self identifierForDelegate:instance]) @@ -73,8 +73,8 @@ - (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); [self didFailNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:webViewIdentifier error:FWFNSErrorDataFromNSError(error) @@ -85,8 +85,8 @@ - (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instanc webView:(WKWebView *)webView error:(NSError *)error completion:(void (^)(NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); [self didFailProvisionalNavigationForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier:webViewIdentifier @@ -97,13 +97,12 @@ - (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instanc - (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance webView:(WKWebView *)webView completion:(void (^)(NSError *_Nullable))completion { - NSNumber *webViewIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:webView]); - [self - webViewWebContentProcessDidTerminateForDelegateWithIdentifier: - @([self identifierForDelegate:instance]) - webViewIdentifier:webViewIdentifier - completion:completion]; + NSNumber *webViewIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:webView]); + [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier: + @([self identifierForDelegate:instance]) + webViewIdentifier:webViewIdentifier + completion:completion]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index 4093404f0884..f88b91750493 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -37,8 +37,8 @@ - (void)observeValueForObject:(NSObject *)instance [changeValues addObject:value]; }]; - NSNumber *objectIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:object]); + NSNumber *objectIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:object]); [self observeValueForObjectWithIdentifier:@([self identifierForObject:instance]) keyPath:keyPath objectIdentifier:objectIdentifier diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h index c92818c01318..36f12feac3fe 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h @@ -25,7 +25,8 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of WKScriptMessageHandler for FWFScriptMessageHandlerHostApiImpl. */ @interface FWFScriptMessageHandler : FWFObject -@property(readonly, nonnull, nonatomic) FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; +@property(readonly, nonnull, nonatomic) + FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m index 043b2097adc9..69ace0202824 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m @@ -28,8 +28,8 @@ - (void)didReceiveScriptMessageForHandler:(FWFScriptMessageHandler *)instance userContentController:(WKUserContentController *)userContentController message:(WKScriptMessage *)message completion:(void (^)(NSError *_Nullable))completion { - NSNumber *userContentControllerIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:userContentController]); + NSNumber *userContentControllerIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:userContentController]); FWFWKScriptMessageData *messageData = FWFWKScriptMessageDataFromWKScriptMessage(message); [self didReceiveScriptMessageForHandlerWithIdentifier:@([self identifierForHandler:instance]) userContentControllerIdentifier:userContentControllerIdentifier diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 8587f96bc28d..4ec8b583b1f8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -30,16 +30,16 @@ - (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance configuration:(WKWebViewConfiguration *)configuration navigationAction:(WKNavigationAction *)navigationAction completion:(void (^)(NSError *_Nullable))completion { - NSNumber *configurationIdentifier = @([self.instanceManager - identifierWithStrongReferenceForInstance:configuration]); - FWFWKNavigationActionData *navigationActionData = FWFWKNavigationActionDataFromNavigationAction( - navigationAction); + NSNumber *configurationIdentifier = + @([self.instanceManager identifierWithStrongReferenceForInstance:configuration]); + FWFWKNavigationActionData *navigationActionData = + FWFWKNavigationActionDataFromNavigationAction(navigationAction); [self onCreateWebViewForDelegateWithIdentifier:@([self identifierForDelegate:instance]) webViewIdentifier: @([self.instanceManager identifierWithStrongReferenceForInstance:webView]) configurationIdentifier:configurationIdentifier - navigationAction:navigationActionData + navigationAction:navigationActionData completion:completion]; } @end