Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview] Instantiate a WKWebViewConfiguration in WKUIDelegate.onCreateWebView #5971

Merged
merged 5 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ - (void)testOnCreateWebViewForDelegateWithIdentifier {
[instanceManager addDartCreatedInstance:mockWebView withIdentifier:1];

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
[instanceManager addDartCreatedInstance:configuration withIdentifier:2];
id mockConfigurationFlutterApi = OCMPartialMock(mockFlutterAPI.webViewConfigurationFlutterApi);
NSNumber *__block configurationIdentifier;
OCMStub([mockConfigurationFlutterApi createWithIdentifier:[OCMArg checkWithBlock:^BOOL(id value) {
configurationIdentifier = value;
return YES;
}]
completion:OCMOCK_ANY]);

WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]);
OCMStub([mockNavigationAction request])
Expand All @@ -85,7 +91,7 @@ - (void)testOnCreateWebViewForDelegateWithIdentifier {
OCMVerify([mockFlutterAPI
onCreateWebViewForDelegateWithIdentifier:@0
webViewIdentifier:@1
configurationIdentifier:@2
configurationIdentifier:configurationIdentifier
navigationAction:[OCMArg
isKindOfClass:[FWFWKNavigationActionData class]]
completion:OCMOCK_ANY]);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.4), do not edit directly.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;
Expand Down Expand Up @@ -297,6 +297,14 @@ extern void FWFWKWebViewConfigurationHostApiSetup(
id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FWFWKWebViewConfigurationHostApi> *_Nullable api);

/// The codec used by FWFWKWebViewConfigurationFlutterApi.
NSObject<FlutterMessageCodec> *FWFWKWebViewConfigurationFlutterApiGetCodec(void);

@interface FWFWKWebViewConfigurationFlutterApi : NSObject
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
- (void)createWithIdentifier:(NSNumber *)identifier
completion:(void (^)(NSError *_Nullable))completion;
@end
/// The codec used by FWFWKUserContentControllerHostApi.
NSObject<FlutterMessageCodec> *FWFWKUserContentControllerHostApiGetCodec(void);

Expand Down
Original file line number Diff line number Diff line change
@@ -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.4), do not edit directly.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "FWFGeneratedWebKitApis.h"
#import <Flutter/Flutter.h>
Expand Down Expand Up @@ -35,58 +35,72 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {

@interface FWFNSKeyValueObservingOptionsEnumData ()
+ (FWFNSKeyValueObservingOptionsEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSKeyValueObservingOptionsEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFNSKeyValueChangeKeyEnumData ()
+ (FWFNSKeyValueChangeKeyEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSKeyValueChangeKeyEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKUserScriptInjectionTimeEnumData ()
+ (FWFWKUserScriptInjectionTimeEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKUserScriptInjectionTimeEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKAudiovisualMediaTypeEnumData ()
+ (FWFWKAudiovisualMediaTypeEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKAudiovisualMediaTypeEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKWebsiteDataTypeEnumData ()
+ (FWFWKWebsiteDataTypeEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKWebsiteDataTypeEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKNavigationActionPolicyEnumData ()
+ (FWFWKNavigationActionPolicyEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKNavigationActionPolicyEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFNSHttpCookiePropertyKeyEnumData ()
+ (FWFNSHttpCookiePropertyKeyEnumData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSHttpCookiePropertyKeyEnumData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFNSUrlRequestData ()
+ (FWFNSUrlRequestData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSUrlRequestData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKUserScriptData ()
+ (FWFWKUserScriptData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKUserScriptData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKNavigationActionData ()
+ (FWFWKNavigationActionData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKNavigationActionData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKFrameInfoData ()
+ (FWFWKFrameInfoData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKFrameInfoData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFNSErrorData ()
+ (FWFNSErrorData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSErrorData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFWKScriptMessageData ()
+ (FWFWKScriptMessageData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFWKScriptMessageData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end
@interface FWFNSHttpCookieData ()
+ (FWFNSHttpCookieData *)fromMap:(NSDictionary *)dict;
+ (nullable FWFNSHttpCookieData *)nullableFromMap:(NSDictionary *)dict;
- (NSDictionary *)toMap;
@end

Expand All @@ -103,6 +117,9 @@ + (FWFNSKeyValueObservingOptionsEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFNSKeyValueObservingOptionsEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSKeyValueObservingOptionsEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -121,6 +138,9 @@ + (FWFNSKeyValueChangeKeyEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFNSKeyValueChangeKeyEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSKeyValueChangeKeyEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -141,6 +161,9 @@ + (FWFWKUserScriptInjectionTimeEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFWKUserScriptInjectionTimeEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKUserScriptInjectionTimeEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -161,6 +184,9 @@ + (FWFWKAudiovisualMediaTypeEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFWKAudiovisualMediaTypeEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKAudiovisualMediaTypeEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -179,6 +205,9 @@ + (FWFWKWebsiteDataTypeEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFWKWebsiteDataTypeEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKWebsiteDataTypeEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -199,6 +228,9 @@ + (FWFWKNavigationActionPolicyEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFWKNavigationActionPolicyEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKNavigationActionPolicyEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand All @@ -219,6 +251,9 @@ + (FWFNSHttpCookiePropertyKeyEnumData *)fromMap:(NSDictionary *)dict {
pigeonResult.value = [GetNullableObject(dict, @"value") integerValue];
return pigeonResult;
}
+ (nullable FWFNSHttpCookiePropertyKeyEnumData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSHttpCookiePropertyKeyEnumData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"value" : @(self.value),
Expand Down Expand Up @@ -248,6 +283,9 @@ + (FWFNSUrlRequestData *)fromMap:(NSDictionary *)dict {
NSAssert(pigeonResult.allHttpHeaderFields != nil, @"");
return pigeonResult;
}
+ (nullable FWFNSUrlRequestData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSUrlRequestData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"url" : (self.url ?: [NSNull null]),
Expand All @@ -272,12 +310,15 @@ + (FWFWKUserScriptData *)fromMap:(NSDictionary *)dict {
FWFWKUserScriptData *pigeonResult = [[FWFWKUserScriptData alloc] init];
pigeonResult.source = GetNullableObject(dict, @"source");
NSAssert(pigeonResult.source != nil, @"");
pigeonResult.injectionTime =
[FWFWKUserScriptInjectionTimeEnumData fromMap:GetNullableObject(dict, @"injectionTime")];
pigeonResult.injectionTime = [FWFWKUserScriptInjectionTimeEnumData
nullableFromMap:GetNullableObject(dict, @"injectionTime")];
pigeonResult.isMainFrameOnly = GetNullableObject(dict, @"isMainFrameOnly");
NSAssert(pigeonResult.isMainFrameOnly != nil, @"");
return pigeonResult;
}
+ (nullable FWFWKUserScriptData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKUserScriptData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"source" : (self.source ?: [NSNull null]),
Expand All @@ -297,12 +338,16 @@ + (instancetype)makeWithRequest:(FWFNSUrlRequestData *)request
}
+ (FWFWKNavigationActionData *)fromMap:(NSDictionary *)dict {
FWFWKNavigationActionData *pigeonResult = [[FWFWKNavigationActionData alloc] init];
pigeonResult.request = [FWFNSUrlRequestData fromMap:GetNullableObject(dict, @"request")];
pigeonResult.request = [FWFNSUrlRequestData nullableFromMap:GetNullableObject(dict, @"request")];
NSAssert(pigeonResult.request != nil, @"");
pigeonResult.targetFrame = [FWFWKFrameInfoData fromMap:GetNullableObject(dict, @"targetFrame")];
pigeonResult.targetFrame =
[FWFWKFrameInfoData nullableFromMap:GetNullableObject(dict, @"targetFrame")];
NSAssert(pigeonResult.targetFrame != nil, @"");
return pigeonResult;
}
+ (nullable FWFWKNavigationActionData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKNavigationActionData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"request" : (self.request ? [self.request toMap] : [NSNull null]),
Expand All @@ -323,6 +368,9 @@ + (FWFWKFrameInfoData *)fromMap:(NSDictionary *)dict {
NSAssert(pigeonResult.isMainFrame != nil, @"");
return pigeonResult;
}
+ (nullable FWFWKFrameInfoData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKFrameInfoData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"isMainFrame" : (self.isMainFrame ?: [NSNull null]),
Expand Down Expand Up @@ -350,6 +398,9 @@ + (FWFNSErrorData *)fromMap:(NSDictionary *)dict {
NSAssert(pigeonResult.localizedDescription != nil, @"");
return pigeonResult;
}
+ (nullable FWFNSErrorData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSErrorData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"code" : (self.code ?: [NSNull null]),
Expand All @@ -373,6 +424,9 @@ + (FWFWKScriptMessageData *)fromMap:(NSDictionary *)dict {
pigeonResult.body = GetNullableObject(dict, @"body");
return pigeonResult;
}
+ (nullable FWFWKScriptMessageData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFWKScriptMessageData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"name" : (self.name ?: [NSNull null]),
Expand All @@ -397,6 +451,9 @@ + (FWFNSHttpCookieData *)fromMap:(NSDictionary *)dict {
NSAssert(pigeonResult.propertyValues != nil, @"");
return pigeonResult;
}
+ (nullable FWFNSHttpCookieData *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FWFNSHttpCookieData fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"propertyKeys" : (self.propertyKeys ?: [NSNull null]),
Expand Down Expand Up @@ -899,6 +956,63 @@ void FWFWKWebViewConfigurationHostApiSetup(id<FlutterBinaryMessenger> binaryMess
}
}
}
@interface FWFWKWebViewConfigurationFlutterApiCodecReader : FlutterStandardReader
@end
@implementation FWFWKWebViewConfigurationFlutterApiCodecReader
@end

@interface FWFWKWebViewConfigurationFlutterApiCodecWriter : FlutterStandardWriter
@end
@implementation FWFWKWebViewConfigurationFlutterApiCodecWriter
@end

@interface FWFWKWebViewConfigurationFlutterApiCodecReaderWriter : FlutterStandardReaderWriter
@end
@implementation FWFWKWebViewConfigurationFlutterApiCodecReaderWriter
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
return [[FWFWKWebViewConfigurationFlutterApiCodecWriter alloc] initWithData:data];
}
- (FlutterStandardReader *)readerWithData:(NSData *)data {
return [[FWFWKWebViewConfigurationFlutterApiCodecReader alloc] initWithData:data];
}
@end

NSObject<FlutterMessageCodec> *FWFWKWebViewConfigurationFlutterApiGetCodec() {
static dispatch_once_t sPred = 0;
static FlutterStandardMessageCodec *sSharedObject = nil;
dispatch_once(&sPred, ^{
FWFWKWebViewConfigurationFlutterApiCodecReaderWriter *readerWriter =
[[FWFWKWebViewConfigurationFlutterApiCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}

@interface FWFWKWebViewConfigurationFlutterApi ()
@property(nonatomic, strong) NSObject<FlutterBinaryMessenger> *binaryMessenger;
@end

@implementation FWFWKWebViewConfigurationFlutterApi

- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger> *)binaryMessenger {
self = [super init];
if (self) {
_binaryMessenger = binaryMessenger;
}
return self;
}
- (void)createWithIdentifier:(NSNumber *)arg_identifier
completion:(void (^)(NSError *_Nullable))completion {
FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.WKWebViewConfigurationFlutterApi.create"
binaryMessenger:self.binaryMessenger
codec:FWFWKWebViewConfigurationFlutterApiGetCodec()];
[channel sendMessage:@[ arg_identifier ?: [NSNull null] ]
reply:^(id reply) {
completion(nil);
}];
}
@end
@interface FWFWKUserContentControllerHostApiCodecReader : FlutterStandardReader
@end
@implementation FWFWKUserContentControllerHostApiCodecReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "FWFGeneratedWebKitApis.h"
#import "FWFInstanceManager.h"
#import "FWFObjectHostApi.h"
#import "FWFWebViewConfigurationHostApi.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -17,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
* Handles making callbacks to Dart for a WKUIDelegate.
*/
@interface FWFUIDelegateFlutterApiImpl : FWFWKUIDelegateFlutterApi
@property(readonly) FWFWebViewConfigurationFlutterApiImpl *webViewConfigurationFlutterApi;
bparrishMines marked this conversation as resolved.
Show resolved Hide resolved
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
instanceManager:(FWFInstanceManager *)instanceManager;
@end
Expand Down
Loading