diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index 0cd1ce8e29be..828b6ab70078 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 3.17.0 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Updates internal API wrapper to use ProxyApis. ## 3.16.3 diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CONTRIBUTING.md b/packages/webview_flutter/webview_flutter_wkwebview/CONTRIBUTING.md new file mode 100644 index 000000000000..b2c43ff47a7d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/CONTRIBUTING.md @@ -0,0 +1,57 @@ +# Contributing to `webview_flutter_wkwebview` + +Please start by taking a look at the general guide to contributing to the `flutter/packages` repo: +https://github.com/flutter/packages/blob/main/CONTRIBUTING.md + +## Package Structure + +This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins). +The sections below will provide an overview of how this plugin implements this portion with Android. + +For making changes to this package, please take a look at [changing federated plugins](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins). + +### Quick Overview + +This plugin implements the platform interface provided by `webview_flutter_platform_interface` using +the native WebKit APIs for Android. + +#### SDK Wrappers + +To access native APIS, this plugins uses Dart wrappers of the native library. The native library is +wrapped using using the `ProxyApi` feature from the `pigeon` package. + +The wrappers for the native library can be updated and modified by changing `pigeons/web_kit.dart`. + +The generated files are located: +* `lib/src/common/web_kit.g.dart` +* `darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift` + +To update the wrapper, follow the steps below: + +##### 1. Ensure the project has been built at least once + +Run `flutter build ios --simulator` in `example/`. + +##### 2. Make changes to the respective pigeon file that matches the native SDK + +* WebKit Dependency: https://developer.apple.com/documentation/webkit +* Pigeon file to update: `pigeons/web_kit.dart` + +##### 3. Run the code generator from the terminal + +Run: `dart run pigeon --input pigeons/web_kit.dart` + +##### 4. Update the generated APIs in native code + +Running the `flutter build` command from step 1 again should provide build errors and indicate what +needs to be done. Alternatively, it can be easier to update native code with the platform's specific +IDE: + +Open `example/android/` in a separate Android Studio project. + +##### 5. Write API tests + +Assuming a non-static method or constructor was added to the native wrapper, a native test will need +to be added. + +Tests location: `darwin/Tests` diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index 2822a0c232fb..58deca7792ca 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -29,5 +29,9 @@ Objective-C: Then you will have access to the native class `FWFWebViewFlutterWKWebViewExternalAPI`. +## Contributing + +For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md). + [1]: https://pub.dev/packages/webview_flutter [2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFDataConvertersTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFDataConvertersTests.m deleted file mode 100644 index 642c138d14ba..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFDataConvertersTests.m +++ /dev/null @@ -1,209 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFDataConvertersTests : XCTestCase -@end - -@implementation FWFDataConvertersTests -- (void)testFWFNSURLRequestFromRequestData { - NSURLRequest *request = FWFNativeNSURLRequestFromRequestData([FWFNSUrlRequestData - makeWithUrl:@"https://flutter.dev" - httpMethod:@"post" - httpBody:[FlutterStandardTypedData typedDataWithBytes:[NSData data]] - allHttpHeaderFields:@{@"a" : @"header"}]); - - XCTAssertEqualObjects(request.URL, [NSURL URLWithString:@"https://flutter.dev"]); - XCTAssertEqualObjects(request.HTTPMethod, @"POST"); - XCTAssertEqualObjects(request.HTTPBody, [NSData data]); - XCTAssertEqualObjects(request.allHTTPHeaderFields, @{@"a" : @"header"}); -} - -- (void)testFWFNSURLRequestFromRequestDataDoesNotOverrideDefaultValuesWithNull { - NSURLRequest *request = - FWFNativeNSURLRequestFromRequestData([FWFNSUrlRequestData makeWithUrl:@"https://flutter.dev" - httpMethod:nil - httpBody:nil - allHttpHeaderFields:@{}]); - - XCTAssertEqualObjects(request.HTTPMethod, @"GET"); -} - -- (void)testFWFNSHTTPCookieFromCookieData { - NSHTTPCookie *cookie = FWFNativeNSHTTPCookieFromCookieData([FWFNSHttpCookieData - makeWithPropertyKeys:@[ [FWFNSHttpCookiePropertyKeyEnumData - makeWithValue:FWFNSHttpCookiePropertyKeyEnumName] ] - propertyValues:@[ @"cookieName" ]]); - XCTAssertEqualObjects(cookie, - [NSHTTPCookie cookieWithProperties:@{NSHTTPCookieName : @"cookieName"}]); -} - -- (void)testFWFWKUserScriptFromScriptData { - WKUserScript *userScript = FWFNativeWKUserScriptFromScriptData([FWFWKUserScriptData - makeWithSource:@"mySource" - injectionTime:[FWFWKUserScriptInjectionTimeEnumData - makeWithValue:FWFWKUserScriptInjectionTimeEnumAtDocumentStart] - isMainFrameOnly:NO]); - - XCTAssertEqualObjects(userScript.source, @"mySource"); - XCTAssertEqual(userScript.injectionTime, WKUserScriptInjectionTimeAtDocumentStart); - XCTAssertEqual(userScript.isForMainFrameOnly, NO); -} - -- (void)testFWFWKNavigationActionDataFromNavigationAction { - WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); - - OCMStub([mockNavigationAction navigationType]).andReturn(WKNavigationTypeReload); - - NSURL *testURL = [NSURL URLWithString:@"https://www.flutter.dev/"]; - NSURLRequest *request = [NSURLRequest requestWithURL:testURL]; - OCMStub([mockNavigationAction request]).andReturn(request); - - WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); - OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); - OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); - - FWFWKNavigationActionData *data = - FWFWKNavigationActionDataFromNativeWKNavigationAction(mockNavigationAction); - XCTAssertNotNil(data); - XCTAssertEqual(data.navigationType, FWFWKNavigationTypeReload); -} - -- (void)testFWFNSUrlRequestDataFromNSURLRequest { - NSURL *testURL = [NSURL URLWithString:@"https://www.flutter.dev/"]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:testURL]; - request.HTTPMethod = @"POST"; - request.HTTPBody = [@"aString" dataUsingEncoding:NSUTF8StringEncoding]; - request.allHTTPHeaderFields = @{@"a" : @"field"}; - - FWFNSUrlRequestData *data = FWFNSUrlRequestDataFromNativeNSURLRequest(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 = FWFWKFrameInfoDataFromNativeWKFrameInfo(mockFrameInfo); - XCTAssertEqual(targetFrameData.isMainFrame, YES); -} - -- (void)testFWFNSErrorDataFromNSError { - NSObject *unsupportedType = [[NSObject alloc] init]; - NSError *error = [NSError errorWithDomain:@"domain" - code:23 - userInfo:@{@"a" : @"b", @"c" : unsupportedType}]; - - FWFNSErrorData *data = FWFNSErrorDataFromNativeNSError(error); - XCTAssertEqual(data.code, 23); - XCTAssertEqualObjects(data.domain, @"domain"); - - NSDictionary *userInfo = @{ - @"a" : @"b", - @"c" : [NSString stringWithFormat:@"Unsupported Type: %@", unsupportedType.description] - }; - XCTAssertEqualObjects(data.userInfo, userInfo); -} - -- (void)testFWFWKScriptMessageDataFromWKScriptMessage { - WKScriptMessage *mockScriptMessage = OCMClassMock([WKScriptMessage class]); - OCMStub([mockScriptMessage name]).andReturn(@"name"); - OCMStub([mockScriptMessage body]).andReturn(@"message"); - - FWFWKScriptMessageData *data = FWFWKScriptMessageDataFromNativeWKScriptMessage(mockScriptMessage); - XCTAssertEqualObjects(data.name, @"name"); - XCTAssertEqualObjects(data.body, @"message"); -} - -- (void)testFWFWKSecurityOriginDataFromWKSecurityOrigin { - WKSecurityOrigin *mockSecurityOrigin = OCMClassMock([WKSecurityOrigin class]); - OCMStub([mockSecurityOrigin host]).andReturn(@"host"); - OCMStub([mockSecurityOrigin port]).andReturn(2); - OCMStub([mockSecurityOrigin protocol]).andReturn(@"protocol"); - - FWFWKSecurityOriginData *data = - FWFWKSecurityOriginDataFromNativeWKSecurityOrigin(mockSecurityOrigin); - XCTAssertEqualObjects(data.host, @"host"); - XCTAssertEqual(data.port, 2); - XCTAssertEqualObjects(data.protocol, @"protocol"); -} - -- (void)testFWFWKPermissionDecisionFromData API_AVAILABLE(ios(15.0), macos(12)) { - XCTAssertEqual(FWFNativeWKPermissionDecisionFromData( - [FWFWKPermissionDecisionData makeWithValue:FWFWKPermissionDecisionDeny]), - WKPermissionDecisionDeny); - XCTAssertEqual(FWFNativeWKPermissionDecisionFromData( - [FWFWKPermissionDecisionData makeWithValue:FWFWKPermissionDecisionGrant]), - WKPermissionDecisionGrant); - XCTAssertEqual(FWFNativeWKPermissionDecisionFromData( - [FWFWKPermissionDecisionData makeWithValue:FWFWKPermissionDecisionPrompt]), - WKPermissionDecisionPrompt); -} - -- (void)testFWFWKMediaCaptureTypeDataFromWKMediaCaptureType API_AVAILABLE(ios(15.0), macos(12)) { - XCTAssertEqual( - FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType(WKMediaCaptureTypeCamera).value, - FWFWKMediaCaptureTypeCamera); - XCTAssertEqual( - FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType(WKMediaCaptureTypeMicrophone).value, - FWFWKMediaCaptureTypeMicrophone); - XCTAssertEqual( - FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType(WKMediaCaptureTypeCameraAndMicrophone) - .value, - FWFWKMediaCaptureTypeCameraAndMicrophone); -} - -- (void)testNSKeyValueChangeKeyConversionReturnsUnknownIfUnrecognized { - XCTAssertEqual( - FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey(@"SomeUnknownValue").value, - FWFNSKeyValueChangeKeyEnumUnknown); -} - -- (void)testWKNavigationTypeConversionReturnsUnknownIfUnrecognized { - XCTAssertEqual(FWFWKNavigationTypeFromNativeWKNavigationType(-15), FWFWKNavigationTypeUnknown); -} - -- (void)testFWFWKNavigationResponseDataFromNativeNavigationResponse { - WKNavigationResponse *mockResponse = OCMClassMock([WKNavigationResponse class]); - OCMStub([mockResponse isForMainFrame]).andReturn(YES); - - NSHTTPURLResponse *mockURLResponse = OCMClassMock([NSHTTPURLResponse class]); - OCMStub([mockURLResponse statusCode]).andReturn(1); - OCMStub([mockResponse response]).andReturn(mockURLResponse); - - FWFWKNavigationResponseData *data = - FWFWKNavigationResponseDataFromNativeNavigationResponse(mockResponse); - XCTAssertEqual(data.forMainFrame, YES); -} - -- (void)testFWFNSHttpUrlResponseDataFromNativeNSURLResponse { - NSHTTPURLResponse *mockResponse = OCMClassMock([NSHTTPURLResponse class]); - OCMStub([mockResponse statusCode]).andReturn(1); - - FWFNSHttpUrlResponseData *data = FWFNSHttpUrlResponseDataFromNativeNSURLResponse(mockResponse); - XCTAssertEqual(data.statusCode, 1); -} - -- (void)testFWFNativeWKNavigationResponsePolicyFromEnum { - XCTAssertEqual( - FWFNativeWKNavigationResponsePolicyFromEnum(FWFWKNavigationResponsePolicyEnumAllow), - WKNavigationResponsePolicyAllow); - XCTAssertEqual( - FWFNativeWKNavigationResponsePolicyFromEnum(FWFWKNavigationResponsePolicyEnumCancel), - WKNavigationResponsePolicyCancel); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFErrorTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFErrorTests.m deleted file mode 100644 index 422b7e49aee9..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFErrorTests.m +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -@import XCTest; - -#import - -@interface FWFErrorTests : XCTestCase -@end - -@implementation FWFErrorTests -- (void)testNSErrorUserInfoKey { - // These MUST match the String values in the Dart class NSErrorUserInfoKey. - XCTAssertEqualObjects(NSLocalizedDescriptionKey, @"NSLocalizedDescription"); - XCTAssertEqualObjects(NSURLErrorFailingURLStringErrorKey, @"NSErrorFailingURLStringKey"); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFHTTPCookieStoreHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFHTTPCookieStoreHostApiTests.m deleted file mode 100644 index eb1e6f250ff8..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFHTTPCookieStoreHostApiTests.m +++ /dev/null @@ -1,59 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFHTTPCookieStoreHostApiTests : XCTestCase -@end - -@implementation FWFHTTPCookieStoreHostApiTests -- (void)testCreateFromWebsiteDataStoreWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFHTTPCookieStoreHostApiImpl *hostAPI = - [[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - WKWebsiteDataStore *mockDataStore = OCMClassMock([WKWebsiteDataStore class]); - OCMStub([mockDataStore httpCookieStore]).andReturn(OCMClassMock([WKHTTPCookieStore class])); - [instanceManager addDartCreatedInstance:mockDataStore withIdentifier:0]; - - FlutterError *error; - [hostAPI createFromWebsiteDataStoreWithIdentifier:1 dataStoreIdentifier:0 error:&error]; - WKHTTPCookieStore *cookieStore = (WKHTTPCookieStore *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([cookieStore isKindOfClass:[WKHTTPCookieStore class]]); - XCTAssertNil(error); -} - -- (void)testSetCookie { - WKHTTPCookieStore *mockHttpCookieStore = OCMClassMock([WKHTTPCookieStore class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockHttpCookieStore withIdentifier:0]; - - FWFHTTPCookieStoreHostApiImpl *hostAPI = - [[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FWFNSHttpCookieData *cookieData = [FWFNSHttpCookieData - makeWithPropertyKeys:@[ [FWFNSHttpCookiePropertyKeyEnumData - makeWithValue:FWFNSHttpCookiePropertyKeyEnumName] ] - propertyValues:@[ @"hello" ]]; - FlutterError *__block blockError; - [hostAPI setCookieForStoreWithIdentifier:0 - cookie:cookieData - completion:^(FlutterError *error) { - blockError = error; - }]; - NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:@{NSHTTPCookieName : @"hello"}]; - OCMVerify([mockHttpCookieStore setCookie:cookie completionHandler:OCMOCK_ANY]); - XCTAssertNil(blockError); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFInstanceManagerTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFInstanceManagerTests.m deleted file mode 100644 index 710dcb791b2a..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFInstanceManagerTests.m +++ /dev/null @@ -1,73 +0,0 @@ -// 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. - -@import XCTest; - -@import webview_flutter_wkwebview; -#if __has_include() -@import webview_flutter_wkwebview.Test; -#endif - -@interface FWFInstanceManagerTests : XCTestCase -@end - -@implementation FWFInstanceManagerTests -- (void)testAddDartCreatedInstance { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - NSObject *object = [[NSObject alloc] init]; - - [instanceManager addDartCreatedInstance:object withIdentifier:0]; - XCTAssertEqualObjects([instanceManager instanceForIdentifier:0], object); - XCTAssertEqual([instanceManager identifierWithStrongReferenceForInstance:object], 0); -} - -- (void)testAddHostCreatedInstance { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - NSObject *object = [[NSObject alloc] init]; - [instanceManager addHostCreatedInstance:object]; - - long identifier = [instanceManager identifierWithStrongReferenceForInstance:object]; - XCTAssertNotEqual(identifier, NSNotFound); - XCTAssertEqualObjects([instanceManager instanceForIdentifier:identifier], object); -} - -- (void)testRemoveInstanceWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - NSObject *object = [[NSObject alloc] init]; - - [instanceManager addDartCreatedInstance:object withIdentifier:0]; - - XCTAssertEqualObjects([instanceManager removeInstanceWithIdentifier:0], object); - XCTAssertEqual([instanceManager strongInstanceCount], 0); -} - -- (void)testDeallocCallbackIsIgnoredIfNull { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnonnull" - // This sets deallocCallback to nil to test that uses are null checked. - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] initWithDeallocCallback:nil]; -#pragma clang diagnostic pop - - [instanceManager addDartCreatedInstance:[[NSObject alloc] init] withIdentifier:0]; - - // Tests that this doesn't cause a EXC_BAD_ACCESS crash. - [instanceManager removeInstanceWithIdentifier:0]; -} - -- (void)testObjectsAreStoredWithPointerHashcode { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - NSURL *url1 = [NSURL URLWithString:@"https://www.flutter.dev"]; - NSURL *url2 = [NSURL URLWithString:@"https://www.flutter.dev"]; - - // Ensure urls are considered equal. - XCTAssertTrue([url1 isEqual:url2]); - - [instanceManager addHostCreatedInstance:url1]; - [instanceManager addHostCreatedInstance:url2]; - - XCTAssertNotEqual([instanceManager identifierWithStrongReferenceForInstance:url1], - [instanceManager identifierWithStrongReferenceForInstance:url2]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFNavigationDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFNavigationDelegateHostApiTests.m deleted file mode 100644 index 4bd8337070b4..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFNavigationDelegateHostApiTests.m +++ /dev/null @@ -1,317 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@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] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:0]; - 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)) - instanceManager:instanceManager]; - return OCMPartialMock(flutterAPI); -} - -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFNavigationDelegateHostApiImpl *hostAPI = [[FWFNavigationDelegateHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createWithIdentifier:0 error:&error]; - FWFNavigationDelegate *navigationDelegate = - (FWFNavigationDelegate *)[instanceManager instanceForIdentifier:0]; - - XCTAssertTrue([navigationDelegate conformsToProtocol:@protocol(WKNavigationDelegate)]); - XCTAssertNil(error); -} - -- (void)testDidFinishNavigation { - 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]); - 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 *mockDelegate = [self mockNavigationDelegateWithManager:instanceManager - identifier:0]; - FWFNavigationDelegateFlutterApiImpl *mockFlutterAPI = - [self mockFlutterApiWithManager:instanceManager]; - - 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 - 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]; - - OCMStub([mockDelegate navigationDelegateAPI]).andReturn(mockFlutterAPI); - - WKWebView *mockWebView = OCMClassMock([WKWebView class]); - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:1]; - - WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); - NSURL *testURL = [NSURL URLWithString:@"https://www.flutter.dev"]; - OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:testURL]); - - 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); -} - -- (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]); -} - -- (void)testDidReceiveAuthenticationChallenge { - 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]; - - NSURLAuthenticationChallenge *mockChallenge = OCMClassMock([NSURLAuthenticationChallenge class]); - NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"host" - port:0 - protocol:nil - realm:@"realm" - authenticationMethod:nil]; - OCMStub([mockChallenge protectionSpace]).andReturn(protectionSpace); - [instanceManager addDartCreatedInstance:mockChallenge withIdentifier:2]; - - NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" - password:@"password" - persistence:NSURLCredentialPersistenceNone]; - [instanceManager addDartCreatedInstance:credential withIdentifier:5]; - - OCMStub([mockFlutterAPI - didReceiveAuthenticationChallengeForDelegateWithIdentifier:0 - webViewIdentifier:1 - challengeIdentifier:2 - completion: - ([OCMArg - invokeBlockWithArgs: - [FWFAuthenticationChallengeResponse - makeWithDisposition: - FWFNSUrlSessionAuthChallengeDispositionCancelAuthenticationChallenge - credentialIdentifier:@(5)], - [NSNull null], nil])]); - - NSURLSessionAuthChallengeDisposition __block callbackDisposition = -1; - NSURLCredential *__block callbackCredential; - [mockDelegate webView:mockWebView - didReceiveAuthenticationChallenge:mockChallenge - completionHandler:^(NSURLSessionAuthChallengeDisposition dispositionArg, - NSURLCredential *credentialArg) { - callbackDisposition = dispositionArg; - callbackCredential = credentialArg; - }]; - - XCTAssertEqual(callbackDisposition, NSURLSessionAuthChallengeCancelAuthenticationChallenge); - XCTAssertEqualObjects(callbackCredential, credential); -} - -- (void)testDecidePolicyForNavigationResponse { - 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]; - - WKNavigationResponse *mockNavigationResponse = OCMClassMock([WKNavigationResponse class]); - OCMStub([mockNavigationResponse isForMainFrame]).andReturn(YES); - - NSHTTPURLResponse *mockURLResponse = OCMClassMock([NSHTTPURLResponse class]); - OCMStub([mockURLResponse statusCode]).andReturn(1); - OCMStub([mockNavigationResponse response]).andReturn(mockURLResponse); - - OCMStub([mockFlutterAPI - decidePolicyForNavigationResponseForDelegateWithIdentifier:0 - webViewIdentifier:1 - navigationResponse:OCMOCK_ANY - completion: - ([OCMArg - invokeBlockWithArgs: - [[FWFWKNavigationResponsePolicyEnumBox - alloc] - initWithValue: - FWFWKNavigationResponsePolicyEnumAllow], - [NSNull null], nil])]); - - WKNavigationResponsePolicy __block callbackPolicy = -1; - [mockDelegate webView:mockWebView - decidePolicyForNavigationResponse:mockNavigationResponse - decisionHandler:^(WKNavigationResponsePolicy policy) { - callbackPolicy = policy; - }]; - XCTAssertEqual(callbackPolicy, WKNavigationResponsePolicyAllow); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFObjectHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFObjectHostApiTests.m deleted file mode 100644 index 4b4f576ffeef..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFObjectHostApiTests.m +++ /dev/null @@ -1,190 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@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)) - instanceManager:instanceManager]; - return OCMPartialMock(flutterAPI); -} - -- (void)testAddObserver { - NSObject *mockObject = OCMClassMock([NSObject class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockObject withIdentifier:0]; - - FWFObjectHostApiImpl *hostAPI = - [[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - NSObject *observerObject = [[NSObject alloc] init]; - [instanceManager addDartCreatedInstance:observerObject withIdentifier:1]; - - FlutterError *error; - [hostAPI - addObserverForObjectWithIdentifier:0 - observerIdentifier:1 - keyPath:@"myKey" - options:@[ - [FWFNSKeyValueObservingOptionsEnumData - makeWithValue:FWFNSKeyValueObservingOptionsEnumOldValue], - [FWFNSKeyValueObservingOptionsEnumData - makeWithValue:FWFNSKeyValueObservingOptionsEnumNewValue] - ] - error:&error]; - - OCMVerify([mockObject addObserver:observerObject - forKeyPath:@"myKey" - options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) - context:nil]); - XCTAssertNil(error); -} - -- (void)testRemoveObserver { - NSObject *mockObject = OCMClassMock([NSObject class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockObject withIdentifier:0]; - - FWFObjectHostApiImpl *hostAPI = - [[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - NSObject *observerObject = [[NSObject alloc] init]; - [instanceManager addDartCreatedInstance:observerObject withIdentifier:1]; - - FlutterError *error; - [hostAPI removeObserverForObjectWithIdentifier:0 - observerIdentifier:1 - keyPath:@"myKey" - error:&error]; - OCMVerify([mockObject removeObserver:observerObject forKeyPath:@"myKey"]); - XCTAssertNil(error); -} - -- (void)testDispose { - NSObject *object = [[NSObject alloc] init]; - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:object withIdentifier:0]; - - FWFObjectHostApiImpl *hostAPI = - [[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI disposeObjectWithIdentifier:0 error:&error]; - // Only the strong reference is removed, so the weak reference will remain until object is set to - // nil. - object = nil; - 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) { - FWFObjectOrIdentifier *changeObject = - (FWFObjectOrIdentifier *)value[0]; - return !changeObject.isIdentifier && - [@"key" isEqual:changeObject.value]; - }] - completion:OCMOCK_ANY]); -} - -- (void)testObserveValueForKeyPathWithIdentifier { - 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]; - - NSObject *returnedObject = [[NSObject alloc] init]; - [instanceManager addDartCreatedInstance:returnedObject withIdentifier:2]; - - [mockObject observeValueForKeyPath:@"keyPath" - ofObject:object - change:@{NSKeyValueChangeOldKey : returnedObject} - 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) { - FWFObjectOrIdentifier *changeObject = - (FWFObjectOrIdentifier *)value[0]; - return changeObject.isIdentifier && - [@(2) isEqual:changeObject.value]; - }] - completion:OCMOCK_ANY]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFPreferencesHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFPreferencesHostApiTests.m deleted file mode 100644 index f0f919619788..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFPreferencesHostApiTests.m +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFPreferencesHostApiTests : XCTestCase -@end - -@implementation FWFPreferencesHostApiTests -- (void)testCreateFromWebViewConfigurationWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFPreferencesHostApiImpl *hostAPI = - [[FWFPreferencesHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createFromWebViewConfigurationWithIdentifier:1 configurationIdentifier:0 error:&error]; - WKPreferences *preferences = (WKPreferences *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([preferences isKindOfClass:[WKPreferences class]]); - XCTAssertNil(error); -} - -- (void)testSetJavaScriptEnabled { - WKPreferences *mockPreferences = OCMClassMock([WKPreferences class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockPreferences withIdentifier:0]; - - FWFPreferencesHostApiImpl *hostAPI = - [[FWFPreferencesHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setJavaScriptEnabledForPreferencesWithIdentifier:0 isEnabled:YES error:&error]; - OCMVerify([mockPreferences setJavaScriptEnabled:YES]); - XCTAssertNil(error); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScriptMessageHandlerHostApiTests.m deleted file mode 100644 index 30064b5dfaa0..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScriptMessageHandlerHostApiTests.m +++ /dev/null @@ -1,92 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@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)) - instanceManager:instanceManager]; - return OCMPartialMock(flutterAPI); -} - -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFScriptMessageHandlerHostApiImpl *hostAPI = [[FWFScriptMessageHandlerHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createWithIdentifier:0 error:&error]; - - FWFScriptMessageHandler *scriptMessageHandler = - (FWFScriptMessageHandler *)[instanceManager instanceForIdentifier:0]; - - XCTAssertTrue([scriptMessageHandler conformsToProtocol:@protocol(WKScriptMessageHandler)]); - XCTAssertNil(error); -} - -- (void)testDidReceiveScriptMessageForHandler { - 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/darwin/Tests/FWFScrollViewDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScrollViewDelegateHostApiTests.m deleted file mode 100644 index 21a6f4e70201..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScrollViewDelegateHostApiTests.m +++ /dev/null @@ -1,89 +0,0 @@ -// 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. - -#include "TargetConditionals.h" - -// The scroll view delegate does not exist on macOS. -#if !TARGET_OS_OSX - -@import Flutter; -@import XCTest; -@import webview_flutter_wkwebview; - -#import - -@interface FWFScrollViewDelegateHostApiTests : XCTestCase - -@end - -@implementation FWFScrollViewDelegateHostApiTests -/** - * Creates a partially mocked FWFScrollViewDelegate 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 FWFScrollViewDelegate. - */ -- (id)mockDelegateWithManager:(FWFInstanceManager *)instanceManager identifier:(long)identifier { - FWFScrollViewDelegate *delegate = [[FWFScrollViewDelegate alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:delegate withIdentifier:0]; - return OCMPartialMock(delegate); -} - -/** - * Creates a mock FWFUIScrollViewDelegateFlutterApiImpl with instanceManager. - * - * @param instanceManager Instance manager passed to the Flutter API. - * - * @return A mock FWFUIScrollViewDelegateFlutterApiImpl. - */ -- (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { - FWFScrollViewDelegateFlutterApiImpl *flutterAPI = [[FWFScrollViewDelegateFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - return OCMPartialMock(flutterAPI); -} - -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFScrollViewDelegateHostApiImpl *hostAPI = [[FWFScrollViewDelegateHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createWithIdentifier:0 error:&error]; - FWFScrollViewDelegate *delegate = - (FWFScrollViewDelegate *)[instanceManager instanceForIdentifier:0]; - - XCTAssertTrue([delegate conformsToProtocol:@protocol(UIScrollViewDelegate)]); - XCTAssertNil(error); -} - -- (void)testOnScrollViewDidScrollForDelegateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFScrollViewDelegate *mockDelegate = [self mockDelegateWithManager:instanceManager identifier:0]; - FWFScrollViewDelegateFlutterApiImpl *mockFlutterAPI = - [self mockFlutterApiWithManager:instanceManager]; - - OCMStub([mockDelegate scrollViewDelegateAPI]).andReturn(mockFlutterAPI); - UIScrollView *scrollView = [[UIScrollView alloc] init]; - scrollView.contentOffset = CGPointMake(1.0, 2.0); - - [instanceManager addDartCreatedInstance:scrollView withIdentifier:1]; - - [mockDelegate scrollViewDidScroll:scrollView]; - OCMVerify([mockFlutterAPI scrollViewDidScrollWithIdentifier:0 - UIScrollViewIdentifier:1 - x:1.0 - y:2.0 - completion:OCMOCK_ANY]); -} -@end - -#endif // !TARGET_OS_OSX diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScrollViewHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScrollViewHostApiTests.m deleted file mode 100644 index 17512ce4b5c6..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFScrollViewHostApiTests.m +++ /dev/null @@ -1,88 +0,0 @@ -// 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. - -#import "TargetConditionals.h" - -// Scroll view APIs do not existing on macOS. -#if !TARGET_OS_OSX - -@import Flutter; -@import XCTest; -@import webview_flutter_wkwebview; - -#import - -@interface FWFScrollViewHostApiTests : XCTestCase -@end - -@implementation FWFScrollViewHostApiTests -- (void)testGetContentOffset { - UIScrollView *mockScrollView = OCMClassMock([UIScrollView class]); - OCMStub([mockScrollView contentOffset]).andReturn(CGPointMake(1.0, 2.0)); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockScrollView withIdentifier:0]; - - FWFScrollViewHostApiImpl *hostAPI = - [[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - NSArray *expectedValue = @[ @1.0, @2.0 ]; - XCTAssertEqualObjects([hostAPI contentOffsetForScrollViewWithIdentifier:0 error:&error], - expectedValue); - XCTAssertNil(error); -} - -- (void)testScrollBy { - UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; - scrollView.contentOffset = CGPointMake(1, 2); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:scrollView withIdentifier:0]; - - FWFScrollViewHostApiImpl *hostAPI = - [[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI scrollByForScrollViewWithIdentifier:0 x:1 y:2 error:&error]; - XCTAssertEqual(scrollView.contentOffset.x, 2); - XCTAssertEqual(scrollView.contentOffset.y, 4); - XCTAssertNil(error); -} - -- (void)testSetContentOffset { - UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:scrollView withIdentifier:0]; - - FWFScrollViewHostApiImpl *hostAPI = - [[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setContentOffsetForScrollViewWithIdentifier:0 toX:1 y:2 error:&error]; - XCTAssertEqual(scrollView.contentOffset.x, 1); - XCTAssertEqual(scrollView.contentOffset.y, 2); - XCTAssertNil(error); -} - -- (void)testSetDelegateForScrollView { - UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; - FWFScrollViewDelegate *delegate = [[FWFScrollViewDelegate alloc] init]; - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:scrollView withIdentifier:0]; - [instanceManager addDartCreatedInstance:delegate withIdentifier:1]; - - FWFScrollViewHostApiImpl *hostAPI = - [[FWFScrollViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setDelegateForScrollViewWithIdentifier:0 uiScrollViewDelegateIdentifier:@1 error:&error]; - XCTAssertEqual(scrollView.delegate, delegate); - XCTAssertNil(error); -} -@end - -#endif // !TARGET_OS_OSX diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIDelegateHostApiTests.m deleted file mode 100644 index 792d65da669e..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIDelegateHostApiTests.m +++ /dev/null @@ -1,148 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; -#if __has_include() -@import webview_flutter_wkwebview.Test; -#endif - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@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)) - instanceManager:instanceManager]; - return OCMPartialMock(flutterAPI); -} - -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFUIDelegateHostApiImpl *hostAPI = [[FWFUIDelegateHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createWithIdentifier:0 error:&error]; - FWFUIDelegate *delegate = (FWFUIDelegate *)[instanceManager instanceForIdentifier:0]; - - XCTAssertTrue([delegate conformsToProtocol:@protocol(WKUIDelegate)]); - XCTAssertNil(error); -} - -- (void)testOnCreateWebViewForDelegateWithIdentifier { - 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]; - id mockConfigurationFlutterApi = OCMPartialMock(mockFlutterAPI.webViewConfigurationFlutterApi); - OCMStub([mockConfigurationFlutterApi createWithIdentifier:0 completion:OCMOCK_ANY]) - .ignoringNonObjectArgs(); - - WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]); - NSURL *testURL = [NSURL URLWithString:@"https://www.flutter.dev"]; - OCMStub([mockNavigationAction request]).andReturn([NSURLRequest requestWithURL:testURL]); - - WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); - OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); - OCMStub([mockNavigationAction targetFrame]).andReturn(mockFrameInfo); - - // Creating the webview will create a configuration on the host side, using the next available - // identifier, so save that for checking against later. - NSInteger configurationIdentifier = instanceManager.nextIdentifier; - [mockDelegate webView:mockWebView - createWebViewWithConfiguration:configuration - forNavigationAction:mockNavigationAction - windowFeatures:OCMClassMock([WKWindowFeatures class])]; - OCMVerify([mockFlutterAPI - onCreateWebViewForDelegateWithIdentifier:0 - webViewIdentifier:1 - configurationIdentifier:configurationIdentifier - navigationAction:[OCMArg - isKindOfClass:[FWFWKNavigationActionData class]] - completion:OCMOCK_ANY]); -} - -- (void)testRequestMediaCapturePermissionForOrigin API_AVAILABLE(ios(15.0), macos(12)) { - 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]; - - WKSecurityOrigin *mockSecurityOrigin = OCMClassMock([WKSecurityOrigin class]); - OCMStub([mockSecurityOrigin host]).andReturn(@""); - OCMStub([mockSecurityOrigin port]).andReturn(0); - OCMStub([mockSecurityOrigin protocol]).andReturn(@""); - - WKFrameInfo *mockFrameInfo = OCMClassMock([WKFrameInfo class]); - OCMStub([mockFrameInfo isMainFrame]).andReturn(YES); - - [mockDelegate webView:mockWebView - requestMediaCapturePermissionForOrigin:mockSecurityOrigin - initiatedByFrame:mockFrameInfo - type:WKMediaCaptureTypeMicrophone - decisionHandler:^(WKPermissionDecision decision){ - }]; - - OCMVerify([mockFlutterAPI - requestMediaCapturePermissionForDelegateWithIdentifier:0 - webViewIdentifier:1 - origin:[OCMArg isKindOfClass: - [FWFWKSecurityOriginData - class]] - frame:[OCMArg - isKindOfClass:[FWFWKFrameInfoData - class]] - type:[OCMArg isKindOfClass: - [FWFWKMediaCaptureTypeData - class]] - completion:OCMOCK_ANY]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIViewHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIViewHostApiTests.m deleted file mode 100644 index 4c2ceecfaa9e..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUIViewHostApiTests.m +++ /dev/null @@ -1,55 +0,0 @@ -// 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. - -#import "TargetConditionals.h" - -#if !TARGET_OS_OSX - -@import Flutter; -@import XCTest; -@import webview_flutter_wkwebview; - -#import - -@interface FWFUIViewHostApiTests : XCTestCase -@end - -@implementation FWFUIViewHostApiTests -- (void)testSetBackgroundColor { - UIView *mockUIView = OCMClassMock([UIView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUIView withIdentifier:0]; - - FWFUIViewHostApiImpl *hostAPI = - [[FWFUIViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setBackgroundColorForViewWithIdentifier:0 toValue:@123 error:&error]; - - OCMVerify([mockUIView setBackgroundColor:[UIColor colorWithRed:(123 >> 16 & 0xff) / 255.0 - green:(123 >> 8 & 0xff) / 255.0 - blue:(123 & 0xff) / 255.0 - alpha:(123 >> 24 & 0xff) / 255.0]]); - XCTAssertNil(error); -} - -- (void)testSetOpaque { - UIView *mockUIView = OCMClassMock([UIView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUIView withIdentifier:0]; - - FWFUIViewHostApiImpl *hostAPI = - [[FWFUIViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setOpaqueForViewWithIdentifier:0 isOpaque:YES error:&error]; - OCMVerify([mockUIView setOpaque:YES]); - XCTAssertNil(error); -} - -@end - -#endif // !TARGET_OS_OSX diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLAuthenticationChallengeHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLAuthenticationChallengeHostApiTests.m deleted file mode 100644 index ff6fb663cf84..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLAuthenticationChallengeHostApiTests.m +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFURLAuthenticationChallengeHostApiTests : XCTestCase - -@end - -@implementation FWFURLAuthenticationChallengeHostApiTests -- (void)testFlutterApiCreate { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFURLAuthenticationChallengeFlutterApiImpl *flutterApi = - [[FWFURLAuthenticationChallengeFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - flutterApi.api = OCMClassMock([FWFNSUrlAuthenticationChallengeFlutterApi class]); - - NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"host" - port:0 - protocol:nil - realm:@"realm" - authenticationMethod:nil]; - - NSURLAuthenticationChallenge *mockChallenge = OCMClassMock([NSURLAuthenticationChallenge class]); - OCMStub([mockChallenge protectionSpace]).andReturn(protectionSpace); - - [flutterApi createWithInstance:mockChallenge - protectionSpace:protectionSpace - completion:^(FlutterError *error){ - - }]; - - long identifier = [instanceManager identifierWithStrongReferenceForInstance:mockChallenge]; - long protectionSpaceIdentifier = - [instanceManager identifierWithStrongReferenceForInstance:protectionSpace]; - OCMVerify([flutterApi.api createWithIdentifier:identifier - protectionSpaceIdentifier:protectionSpaceIdentifier - completion:OCMOCK_ANY]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLCredentialHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLCredentialHostApiTests.m deleted file mode 100644 index bcc9f59e506c..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLCredentialHostApiTests.m +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFURLCredentialHostApiTests : XCTestCase -@end - -@implementation FWFURLCredentialHostApiTests -- (void)testHostApiCreate { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - - FWFURLCredentialHostApiImpl *hostApi = [[FWFURLCredentialHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostApi createWithUserWithIdentifier:0 - user:@"user" - password:@"password" - persistence:FWFNSUrlCredentialPersistencePermanent - error:&error]; - XCTAssertNil(error); - - NSURLCredential *credential = (NSURLCredential *)[instanceManager instanceForIdentifier:0]; - XCTAssertEqualObjects(credential.user, @"user"); - XCTAssertEqualObjects(credential.password, @"password"); - XCTAssertEqual(credential.persistence, NSURLCredentialPersistencePermanent); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLProtectionSpaceHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLProtectionSpaceHostApiTests.m deleted file mode 100644 index be5738e919eb..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLProtectionSpaceHostApiTests.m +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFURLProtectionSpaceHostApiTests : XCTestCase -@end - -@implementation FWFURLProtectionSpaceHostApiTests -- (void)testFlutterApiCreate { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFURLProtectionSpaceFlutterApiImpl *flutterApi = [[FWFURLProtectionSpaceFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - flutterApi.api = OCMClassMock([FWFNSUrlProtectionSpaceFlutterApi class]); - - NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"host" - port:0 - protocol:nil - realm:@"realm" - authenticationMethod:nil]; - [flutterApi createWithInstance:protectionSpace - host:@"host" - realm:@"realm" - authenticationMethod:@"method" - completion:^(FlutterError *error){ - - }]; - - long identifier = [instanceManager identifierWithStrongReferenceForInstance:protectionSpace]; - OCMVerify([flutterApi.api createWithIdentifier:identifier - host:@"host" - realm:@"realm" - authenticationMethod:@"method" - completion:OCMOCK_ANY]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLTests.m deleted file mode 100644 index a2e88197ca84..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFURLTests.m +++ /dev/null @@ -1,53 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFURLTests : XCTestCase -@end - -@implementation FWFURLTests -- (void)testAbsoluteString { - NSURL *mockUrl = OCMClassMock([NSURL class]); - OCMStub([mockUrl absoluteString]).andReturn(@"https://www.google.com"); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUrl withIdentifier:0]; - - FWFURLHostApiImpl *hostApi = [[FWFURLHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostApi absoluteStringForNSURLWithIdentifier:0 error:&error], - @"https://www.google.com"); - XCTAssertNil(error); -} - -- (void)testFlutterApiCreate { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFURLFlutterApiImpl *flutterApi = [[FWFURLFlutterApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - flutterApi.api = OCMClassMock([FWFNSUrlFlutterApi class]); - - NSURL *url = [[NSURL alloc] initWithString:@"https://www.google.com"]; - [flutterApi create:url - completion:^(FlutterError *error){ - }]; - - long identifier = [instanceManager identifierWithStrongReferenceForInstance:url]; - OCMVerify([flutterApi.api createWithIdentifier:identifier completion:OCMOCK_ANY]); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUserContentControllerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUserContentControllerHostApiTests.m deleted file mode 100644 index 82ca3261d1a4..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFUserContentControllerHostApiTests.m +++ /dev/null @@ -1,132 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFUserContentControllerHostApiTests : XCTestCase -@end - -@implementation FWFUserContentControllerHostApiTests -- (void)testCreateFromWebViewConfigurationWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createFromWebViewConfigurationWithIdentifier:1 configurationIdentifier:0 error:&error]; - WKUserContentController *userContentController = - (WKUserContentController *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([userContentController isKindOfClass:[WKUserContentController class]]); - XCTAssertNil(error); -} - -- (void)testAddScriptMessageHandler { - WKUserContentController *mockUserContentController = - OCMClassMock([WKUserContentController class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0]; - - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - id mockMessageHandler = - OCMProtocolMock(@protocol(WKScriptMessageHandler)); - [instanceManager addDartCreatedInstance:mockMessageHandler withIdentifier:1]; - - FlutterError *error; - [hostAPI addScriptMessageHandlerForControllerWithIdentifier:0 - handlerIdentifier:1 - ofName:@"apple" - error:&error]; - OCMVerify([mockUserContentController addScriptMessageHandler:mockMessageHandler name:@"apple"]); - XCTAssertNil(error); -} - -- (void)testRemoveScriptMessageHandler { - WKUserContentController *mockUserContentController = - OCMClassMock([WKUserContentController class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0]; - - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI removeScriptMessageHandlerForControllerWithIdentifier:0 name:@"apple" error:&error]; - OCMVerify([mockUserContentController removeScriptMessageHandlerForName:@"apple"]); - XCTAssertNil(error); -} - -- (void)testRemoveAllScriptMessageHandlers API_AVAILABLE(ios(14.0), macos(11)) { - WKUserContentController *mockUserContentController = - OCMClassMock([WKUserContentController class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0]; - - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI removeAllScriptMessageHandlersForControllerWithIdentifier:0 error:&error]; - OCMVerify([mockUserContentController removeAllScriptMessageHandlers]); - XCTAssertNil(error); -} - -- (void)testAddUserScript { - WKUserContentController *mockUserContentController = - OCMClassMock([WKUserContentController class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0]; - - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI - addUserScriptForControllerWithIdentifier:0 - userScript: - [FWFWKUserScriptData - makeWithSource:@"runAScript" - injectionTime: - [FWFWKUserScriptInjectionTimeEnumData - makeWithValue: - FWFWKUserScriptInjectionTimeEnumAtDocumentEnd] - isMainFrameOnly:YES] - error:&error]; - - OCMVerify([mockUserContentController addUserScript:[OCMArg isKindOfClass:[WKUserScript class]]]); - XCTAssertNil(error); -} - -- (void)testRemoveAllUserScripts { - WKUserContentController *mockUserContentController = - OCMClassMock([WKUserContentController class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockUserContentController withIdentifier:0]; - - FWFUserContentControllerHostApiImpl *hostAPI = - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI removeAllUserScriptsForControllerWithIdentifier:0 error:&error]; - OCMVerify([mockUserContentController removeAllUserScripts]); - XCTAssertNil(error); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewConfigurationHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewConfigurationHostApiTests.m deleted file mode 100644 index 585f4cd047c6..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewConfigurationHostApiTests.m +++ /dev/null @@ -1,116 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFWebViewConfigurationHostApiTests : XCTestCase -@end - -@implementation FWFWebViewConfigurationHostApiTests -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createWithIdentifier:0 error:&error]; - WKWebViewConfiguration *configuration = - (WKWebViewConfiguration *)[instanceManager instanceForIdentifier:0]; - XCTAssertTrue([configuration isKindOfClass:[WKWebViewConfiguration class]]); - XCTAssertNil(error); -} - -- (void)testCreateFromWebViewWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - WKWebView *mockWebView = OCMClassMock([WKWebView class]); - OCMStub([mockWebView configuration]).andReturn(OCMClassMock([WKWebViewConfiguration class])); - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FlutterError *error; - [hostAPI createFromWebViewWithIdentifier:1 webViewIdentifier:0 error:&error]; - WKWebViewConfiguration *configuration = - (WKWebViewConfiguration *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([configuration isKindOfClass:[WKWebViewConfiguration class]]); - XCTAssertNil(error); -} - -- (void)testSetAllowsInlineMediaPlayback { - WKWebViewConfiguration *mockWebViewConfiguration = OCMClassMock([WKWebViewConfiguration class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebViewConfiguration withIdentifier:0]; - - FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:0 isAllowed:NO error:&error]; - // setAllowsInlineMediaPlayback does not existing on macOS; the call above should no-op for macOS. -#if !TARGET_OS_OSX - OCMVerify([mockWebViewConfiguration setAllowsInlineMediaPlayback:NO]); -#endif - XCTAssertNil(error); -} - -- (void)testSetLimitsNavigationsToAppBoundDomains API_AVAILABLE(ios(14.0), macos(11)) { - WKWebViewConfiguration *mockWebViewConfiguration = OCMClassMock([WKWebViewConfiguration class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebViewConfiguration withIdentifier:0]; - - FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:0 - isLimited:NO - error:&error]; - OCMVerify([mockWebViewConfiguration setLimitsNavigationsToAppBoundDomains:NO]); - XCTAssertNil(error); -} - -- (void)testSetMediaTypesRequiringUserActionForPlayback { - WKWebViewConfiguration *mockWebViewConfiguration = OCMClassMock([WKWebViewConfiguration class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebViewConfiguration withIdentifier:0]; - - FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI - setMediaTypesRequiresUserActionForConfigurationWithIdentifier:0 - forTypes:@[ - [FWFWKAudiovisualMediaTypeEnumData - makeWithValue: - FWFWKAudiovisualMediaTypeEnumAudio], - [FWFWKAudiovisualMediaTypeEnumData - makeWithValue: - FWFWKAudiovisualMediaTypeEnumVideo] - ] - error:&error]; - OCMVerify([mockWebViewConfiguration - setMediaTypesRequiringUserActionForPlayback:(WKAudiovisualMediaTypeAudio | - WKAudiovisualMediaTypeVideo)]); - XCTAssertNil(error); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.m deleted file mode 100644 index d4137c1997be..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.m +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -@import XCTest; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@import webview_flutter_wkwebview; - -@interface FWFWebViewFlutterWKWebViewExternalAPITests : XCTestCase -@end - -@implementation FWFWebViewFlutterWKWebViewExternalAPITests -- (void)testWebViewForIdentifier { - WKWebView *webView = [[WKWebView alloc] init]; - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:webView withIdentifier:0]; - - id mockPluginRegistry = OCMProtocolMock(@protocol(FlutterPluginRegistry)); - OCMStub([mockPluginRegistry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]) - .andReturn(instanceManager); - - XCTAssertEqualObjects( - [FWFWebViewFlutterWKWebViewExternalAPI webViewForIdentifier:0 - withPluginRegistry:mockPluginRegistry], - webView); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewHostApiTests.m deleted file mode 100644 index 49d5a20dd57c..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebViewHostApiTests.m +++ /dev/null @@ -1,520 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -// Only used in !OSX test code, and causes unused function error if not ifdef'd out. -#if !TARGET_OS_OSX -static bool feq(CGFloat a, CGFloat b) { return fabs(b - a) < FLT_EPSILON; } -#endif - -@interface FWFWebViewHostApiTests : XCTestCase -@end - -@implementation FWFWebViewHostApiTests -- (void)testCreateWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createWithIdentifier:1 configurationIdentifier:0 error:&error]; - WKWebView *webView = (WKWebView *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([webView isKindOfClass:[WKWebView class]]); - XCTAssertNil(error); -} - -- (void)testLoadRequest { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"https://www.flutter.dev" - httpMethod:@"get" - httpBody:nil - allHttpHeaderFields:@{@"a" : @"header"}]; - [hostAPI loadRequestForWebViewWithIdentifier:0 request:requestData error:&error]; - - NSURL *url = [NSURL URLWithString:@"https://www.flutter.dev"]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; - request.HTTPMethod = @"get"; - request.allHTTPHeaderFields = @{@"a" : @"header"}; - OCMVerify([mockWebView loadRequest:request]); - XCTAssertNil(error); -} - -- (void)testLoadRequestWithInvalidUrl { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - NSString *badURLString = @"%invalidUrl%"; - FlutterError *error; - FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:badURLString - httpMethod:nil - httpBody:nil - allHttpHeaderFields:@{}]; - [hostAPI loadRequestForWebViewWithIdentifier:0 request:requestData error:&error]; - // When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't - // fail to parse URLs, so the test must allow for either outcome. - if (error) { - XCTAssertEqualObjects(error.code, @"FWFURLRequestParsingError"); - XCTAssertEqualObjects(error.message, @"Failed instantiating an NSURLRequest."); - XCTAssertEqualObjects(error.details, @"URL was: '%invalidUrl%'"); - } else { - NSURL *badURL = [NSURL URLWithString:badURLString]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:badURL]; - OCMVerify([mockWebView loadRequest:request]); - } -} - -- (void)testSetCustomUserAgent { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setCustomUserAgentForWebViewWithIdentifier:0 userAgent:@"userA" error:&error]; - OCMVerify([mockWebView setCustomUserAgent:@"userA"]); - XCTAssertNil(error); -} - -- (void)testURL { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - OCMStub([mockWebView URL]).andReturn([NSURL URLWithString:@"https://www.flutter.dev/"]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI URLForWebViewWithIdentifier:0 error:&error], - @"https://www.flutter.dev/"); - XCTAssertNil(error); -} - -- (void)testCanGoBack { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - OCMStub([mockWebView canGoBack]).andReturn(YES); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI canGoBackForWebViewWithIdentifier:0 error:&error], @YES); - XCTAssertNil(error); -} - -- (void)testSetUIDelegate { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - id mockDelegate = OCMProtocolMock(@protocol(WKUIDelegate)); - [instanceManager addDartCreatedInstance:mockDelegate withIdentifier:1]; - - FlutterError *error; - [hostAPI setUIDelegateForWebViewWithIdentifier:0 delegateIdentifier:@1 error:&error]; - OCMVerify([mockWebView setUIDelegate:mockDelegate]); - XCTAssertNil(error); -} - -- (void)testSetNavigationDelegate { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - id mockDelegate = OCMProtocolMock(@protocol(WKNavigationDelegate)); - [instanceManager addDartCreatedInstance:mockDelegate withIdentifier:1]; - FlutterError *error; - - [hostAPI setNavigationDelegateForWebViewWithIdentifier:0 delegateIdentifier:@1 error:&error]; - OCMVerify([mockWebView setNavigationDelegate:mockDelegate]); - XCTAssertNil(error); -} - -- (void)testEstimatedProgress { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - OCMStub([mockWebView estimatedProgress]).andReturn(34.0); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI estimatedProgressForWebViewWithIdentifier:0 error:&error], @34.0); - XCTAssertNil(error); -} - -- (void)testloadHTMLString { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI loadHTMLForWebViewWithIdentifier:0 - HTMLString:@"myString" - baseURL:@"myBaseUrl" - error:&error]; - OCMVerify([mockWebView loadHTMLString:@"myString" baseURL:[NSURL URLWithString:@"myBaseUrl"]]); - XCTAssertNil(error); -} - -- (void)testLoadFileURL { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI loadFileForWebViewWithIdentifier:0 - fileURL:@"myFolder/apple.txt" - readAccessURL:@"myFolder" - error:&error]; - XCTAssertNil(error); - OCMVerify([mockWebView loadFileURL:[NSURL fileURLWithPath:@"myFolder/apple.txt" isDirectory:NO] - allowingReadAccessToURL:[NSURL fileURLWithPath:@"myFolder/" isDirectory:YES] - - ]); -} - -- (void)testLoadFlutterAsset { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFAssetManager *mockAssetManager = OCMClassMock([FWFAssetManager class]); - OCMStub([mockAssetManager lookupKeyForAsset:@"assets/index.html"]) - .andReturn(@"myFolder/assets/index.html"); - - NSBundle *mockBundle = OCMClassMock([NSBundle class]); - OCMStub([mockBundle URLForResource:@"myFolder/assets/index" withExtension:@"html"]) - .andReturn([NSURL URLWithString:@"webview_flutter/myFolder/assets/index.html"]); - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager - bundle:mockBundle - assetManager:mockAssetManager]; - - FlutterError *error; - [hostAPI loadAssetForWebViewWithIdentifier:0 assetKey:@"assets/index.html" error:&error]; - - XCTAssertNil(error); - NSURL *fileURL = [NSURL URLWithString:@"webview_flutter/myFolder/assets/index.html"]; - NSURL *directoryURL = [NSURL URLWithString:@"webview_flutter/myFolder/assets/"]; - OCMVerify([mockWebView loadFileURL:fileURL allowingReadAccessToURL:directoryURL]); -} - -- (void)testCanGoForward { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - OCMStub([mockWebView canGoForward]).andReturn(NO); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI canGoForwardForWebViewWithIdentifier:0 error:&error], @NO); - XCTAssertNil(error); -} - -- (void)testGoBack { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI goBackForWebViewWithIdentifier:0 error:&error]; - OCMVerify([mockWebView goBack]); - XCTAssertNil(error); -} - -- (void)testGoForward { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI goForwardForWebViewWithIdentifier:0 error:&error]; - OCMVerify([mockWebView goForward]); - XCTAssertNil(error); -} - -- (void)testReload { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI reloadWebViewWithIdentifier:0 error:&error]; - OCMVerify([mockWebView reload]); - XCTAssertNil(error); -} - -- (void)testTitle { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - OCMStub([mockWebView title]).andReturn(@"myTitle"); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI titleForWebViewWithIdentifier:0 error:&error], @"myTitle"); - XCTAssertNil(error); -} - -- (void)testSetAllowsBackForwardNavigationGestures { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setAllowsBackForwardForWebViewWithIdentifier:0 isAllowed:YES error:&error]; - OCMVerify([mockWebView setAllowsBackForwardNavigationGestures:YES]); - XCTAssertNil(error); -} - -- (void)testEvaluateJavaScript { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - OCMStub([mockWebView - evaluateJavaScript:@"runJavaScript" - completionHandler:([OCMArg invokeBlockWithArgs:@"result", [NSNull null], nil])]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - NSString __block *returnValue; - FlutterError __block *returnError; - [hostAPI evaluateJavaScriptForWebViewWithIdentifier:0 - javaScriptString:@"runJavaScript" - completion:^(id result, FlutterError *error) { - returnValue = result; - returnError = error; - }]; - - XCTAssertEqualObjects(returnValue, @"result"); - XCTAssertNil(returnError); -} - -- (void)testEvaluateJavaScriptReturnsNSErrorData { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - OCMStub([mockWebView - evaluateJavaScript:@"runJavaScript" - completionHandler:([OCMArg invokeBlockWithArgs:[NSNull null], - [NSError errorWithDomain:@"errorDomain" - code:0 - userInfo:@{ - NSLocalizedDescriptionKey : - @"description" - }], - nil])]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - NSString __block *returnValue; - FlutterError __block *returnError; - [hostAPI evaluateJavaScriptForWebViewWithIdentifier:0 - javaScriptString:@"runJavaScript" - completion:^(id result, FlutterError *error) { - returnValue = result; - returnError = error; - }]; - - XCTAssertNil(returnValue); - FWFNSErrorData *errorData = returnError.details; - XCTAssertTrue([errorData isKindOfClass:[FWFNSErrorData class]]); - XCTAssertEqual(errorData.code, 0); - XCTAssertEqualObjects(errorData.domain, @"errorDomain"); - XCTAssertEqualObjects(errorData.userInfo, @{NSLocalizedDescriptionKey : @"description"}); -} - -// Content inset APIs don't exist on macOS. -#if !TARGET_OS_OSX -- (void)testWebViewContentInsetBehaviorShouldBeNever { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createWithIdentifier:1 configurationIdentifier:0 error:&error]; - FWFWebView *webView = (FWFWebView *)[instanceManager instanceForIdentifier:1]; - - XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior, - UIScrollViewContentInsetAdjustmentNever); -} - -- (void)testScrollViewsAutomaticallyAdjustsScrollIndicatorInsetsShouldbeNoOnIOS13 API_AVAILABLE( - ios(13.0)) { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createWithIdentifier:1 configurationIdentifier:0 error:&error]; - FWFWebView *webView = (FWFWebView *)[instanceManager instanceForIdentifier:1]; - - XCTAssertFalse(webView.scrollView.automaticallyAdjustsScrollIndicatorInsets); -} - -- (void)testContentInsetsSumAlwaysZeroAfterSetFrame { - FWFWebView *webView = [[FWFWebView alloc] initWithFrame:CGRectMake(0, 0, 300, 400) - configuration:[[WKWebViewConfiguration alloc] init]]; - - webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 300, 0); - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero)); - - webView.frame = CGRectMake(0, 0, 300, 200); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero)); - XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 200))); - - // Make sure the contentInset compensates the adjustedContentInset. - UIScrollView *partialMockScrollView = OCMPartialMock(webView.scrollView); - UIEdgeInsets insetToAdjust = UIEdgeInsetsMake(0, 0, 300, 0); - OCMStub(partialMockScrollView.adjustedContentInset).andReturn(insetToAdjust); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero)); - - webView.frame = CGRectMake(0, 0, 300, 100); - XCTAssertTrue(feq(webView.scrollView.contentInset.bottom, -insetToAdjust.bottom)); - XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100))); -} -#endif // !TARGET_OS_OSX - -- (void)testSetInspectable API_AVAILABLE(ios(16.4), macos(13.3)) { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - [hostAPI setInspectableForWebViewWithIdentifier:0 inspectable:YES error:&error]; - OCMVerify([mockWebView setInspectable:YES]); - XCTAssertNil(error); -} - -- (void)testCustomUserAgent { - FWFWebView *mockWebView = OCMClassMock([FWFWebView class]); - - NSString *userAgent = @"str"; - OCMStub([mockWebView customUserAgent]).andReturn(userAgent); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - - FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) - instanceManager:instanceManager]; - - FlutterError *error; - XCTAssertEqualObjects([hostAPI customUserAgentForWebViewWithIdentifier:0 error:&error], - userAgent); - XCTAssertNil(error); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebsiteDataStoreHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebsiteDataStoreHostApiTests.m deleted file mode 100644 index bab732b88de2..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/FWFWebsiteDataStoreHostApiTests.m +++ /dev/null @@ -1,82 +0,0 @@ -// 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. - -@import XCTest; -@import webview_flutter_wkwebview; - -#if TARGET_OS_OSX -@import FlutterMacOS; -#else -@import Flutter; -#endif - -#import - -@interface FWFWebsiteDataStoreHostApiTests : XCTestCase -@end - -@implementation FWFWebsiteDataStoreHostApiTests -- (void)testCreateFromWebViewConfigurationWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebsiteDataStoreHostApiImpl *hostAPI = - [[FWFWebsiteDataStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; - - FlutterError *error; - [hostAPI createFromWebViewConfigurationWithIdentifier:1 configurationIdentifier:0 error:&error]; - WKWebsiteDataStore *dataStore = (WKWebsiteDataStore *)[instanceManager instanceForIdentifier:1]; - XCTAssertTrue([dataStore isKindOfClass:[WKWebsiteDataStore class]]); - XCTAssertNil(error); -} - -- (void)testCreateDefaultDataStoreWithIdentifier { - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebsiteDataStoreHostApiImpl *hostAPI = - [[FWFWebsiteDataStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - FlutterError *error; - [hostAPI createDefaultDataStoreWithIdentifier:0 error:&error]; - WKWebsiteDataStore *dataStore = (WKWebsiteDataStore *)[instanceManager instanceForIdentifier:0]; - XCTAssertEqualObjects(dataStore, [WKWebsiteDataStore defaultDataStore]); - XCTAssertNil(error); -} - -- (void)testRemoveDataOfTypes { - WKWebsiteDataStore *mockWebsiteDataStore = OCMClassMock([WKWebsiteDataStore class]); - - WKWebsiteDataRecord *mockDataRecord = OCMClassMock([WKWebsiteDataRecord class]); - OCMStub([mockWebsiteDataStore - fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeLocalStorage] - completionHandler:([OCMArg invokeBlockWithArgs:@[ mockDataRecord ], nil])]); - - OCMStub([mockWebsiteDataStore - removeDataOfTypes:[NSSet setWithObject:WKWebsiteDataTypeLocalStorage] - modifiedSince:[NSDate dateWithTimeIntervalSince1970:45.0] - completionHandler:([OCMArg invokeBlock])]); - - FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - [instanceManager addDartCreatedInstance:mockWebsiteDataStore withIdentifier:0]; - - FWFWebsiteDataStoreHostApiImpl *hostAPI = - [[FWFWebsiteDataStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]; - - NSNumber __block *returnValue; - FlutterError *__block blockError; - [hostAPI removeDataFromDataStoreWithIdentifier:0 - ofTypes:@[ - [FWFWKWebsiteDataTypeEnumData - makeWithValue:FWFWKWebsiteDataTypeEnumLocalStorage] - ] - modifiedSince:45.0 - completion:^(NSNumber *result, FlutterError *error) { - returnValue = result; - blockError = error; - }]; - XCTAssertEqualObjects(returnValue, @YES); - // Asserts whether the NSNumber will be deserialized by the standard codec as a boolean. - XCTAssertEqual(CFGetTypeID((__bridge CFTypeRef)(returnValue)), CFBooleanGetTypeID()); - XCTAssertNil(blockError); -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview.podspec b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview.podspec index af606661b6b5..fffed750558a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview.podspec +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview.podspec @@ -14,13 +14,17 @@ Downloaded by pub (not CocoaPods). s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview' } s.documentation_url = 'https://pub.dev/packages/webview_flutter' - s.source_files = 'webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/**/*.{h,m}' - s.public_header_files = 'webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/**/*.h' - s.module_map = 'webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/FlutterWebView.modulemap' + s.source_files = 'webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/**/*.{h,swift}' s.ios.dependency 'Flutter' s.osx.dependency 'FlutterMacOS' s.ios.deployment_target = '12.0' s.osx.deployment_target = '10.14' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } s.resource_bundles = {'webview_flutter_wkwebview_privacy' => ['webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/Resources/PrivacyInfo.xcprivacy']} + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + s.xcconfig = { + 'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift', + 'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift', + } + s.swift_version = '5.0' end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Package.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Package.swift index 127814584215..f152a5748f0c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Package.swift +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Package.swift @@ -20,12 +20,8 @@ let package = Package( .target( name: "webview_flutter_wkwebview", dependencies: [], - exclude: ["include/FlutterWebView.modulemap", "include/webview-umbrella.h"], resources: [ .process("Resources") - ], - cSettings: [ - .headerSearchPath("include/webview_flutter_wkwebview") ] ) ] diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponse.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponse.swift new file mode 100644 index 000000000000..067edd5c00fb --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponse.swift @@ -0,0 +1,20 @@ +// 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. + +import Foundation + +/// Data class used to respond to auth challenges from `WKNavigationDelegate`. +/// +/// The `webView(_:didReceive:completionHandler:)` method in `WKNavigationDelegate` +/// responds with a completion handler that takes two values. The wrapper returns this class instead to handle +/// this scenario. +class AuthenticationChallengeResponse { + let disposition: URLSession.AuthChallengeDisposition + let credential: URLCredential? + + init(disposition: URLSession.AuthChallengeDisposition, credential: URLCredential?) { + self.disposition = disposition + self.credential = credential + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponseProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponseProxyAPIDelegate.swift new file mode 100644 index 000000000000..7367e71990b6 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/AuthenticationChallengeResponseProxyAPIDelegate.swift @@ -0,0 +1,61 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `AuthenticationChallengeResponse`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class AuthenticationChallengeResponseProxyAPIDelegate: + PigeonApiDelegateAuthenticationChallengeResponse +{ + func pigeonDefaultConstructor( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + disposition: UrlSessionAuthChallengeDisposition, credential: URLCredential? + ) throws -> AuthenticationChallengeResponse { + let nativeDisposition: URLSession.AuthChallengeDisposition + + switch disposition { + case .useCredential: + nativeDisposition = .useCredential + case .performDefaultHandling: + nativeDisposition = .performDefaultHandling + case .cancelAuthenticationChallenge: + nativeDisposition = .cancelAuthenticationChallenge + case .rejectProtectionSpace: + nativeDisposition = .rejectProtectionSpace + case .unknown: + throw (pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar).createUnknownEnumError( + withEnum: disposition) + } + + return AuthenticationChallengeResponse(disposition: nativeDisposition, credential: credential) + } + + func disposition( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + pigeonInstance: AuthenticationChallengeResponse + ) throws -> UrlSessionAuthChallengeDisposition { + switch pigeonInstance.disposition { + case .useCredential: + return .useCredential + case .performDefaultHandling: + return .performDefaultHandling + case .cancelAuthenticationChallenge: + return .cancelAuthenticationChallenge + case .rejectProtectionSpace: + return .rejectProtectionSpace + @unknown default: + return .unknown + } + } + + func credential( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + pigeonInstance: AuthenticationChallengeResponse + ) throws -> URLCredential? { + return pigeonInstance.credential + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ErrorProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ErrorProxyAPIDelegate.swift new file mode 100644 index 000000000000..e82fe26dbbe1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ErrorProxyAPIDelegate.swift @@ -0,0 +1,23 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `NSError`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class ErrorProxyAPIDelegate: PigeonApiDelegateNSError { + func code(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> Int64 { + return Int64(pigeonInstance.code) + } + + func domain(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> String { + return pigeonInstance.domain + } + + func userInfo(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> [String: Any?] { + return pigeonInstance.userInfo + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.m deleted file mode 100644 index ffa5da84c408..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.m +++ /dev/null @@ -1,149 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.h" -#import "./include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h" -#import "./include/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFInstanceManager.h" -#import "./include/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFObjectHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFPreferencesHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFScrollViewHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFUIDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFUIViewHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFURLCredentialHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFURLHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFUserContentControllerHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h" - -@interface FWFWebViewFactory : NSObject -@property(nonatomic, weak) FWFInstanceManager *instanceManager; - -- (instancetype)initWithManager:(FWFInstanceManager *)manager; -@end - -@implementation FWFWebViewFactory -- (instancetype)initWithManager:(FWFInstanceManager *)manager { - self = [self init]; - if (self) { - _instanceManager = manager; - } - return self; -} - -#pragma mark FlutterPlatformViewFactory - -- (NSObject *)createArgsCodec { - return [FlutterStandardMessageCodec sharedInstance]; -} - -// The FlutterPlatformViewFactory protocol is slightly different on iOS and -// macOS. -#if TARGET_OS_IOS - -- (NSObject *)createWithFrame:(CGRect)frame - viewIdentifier:(int64_t)viewId - arguments:(id _Nullable)args { - NSNumber *identifier = (NSNumber *)args; - FWFWebView *webView = - (FWFWebView *)[self.instanceManager instanceForIdentifier:identifier.longValue]; - webView.frame = frame; - return webView; -} - -#else - -- (nonnull NSView *)createWithViewIdentifier:(int64_t)viewId arguments:(nullable id)args { - NSNumber *identifier = (NSNumber *)args; - FWFWebView *webView = - (FWFWebView *)[self.instanceManager instanceForIdentifier:identifier.longValue]; - return webView; -} - -#endif - -@end - -@implementation FLTWebViewFlutterPlugin - -+ (void)registerWithRegistrar:(NSObject *)registrar { - FWFInstanceManager *instanceManager = - [[FWFInstanceManager alloc] initWithDeallocCallback:^(long identifier) { - FWFObjectFlutterApiImpl *objectApi = [[FWFObjectFlutterApiImpl alloc] - initWithBinaryMessenger:registrar.messenger - instanceManager:[[FWFInstanceManager alloc] init]]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [objectApi disposeObjectWithIdentifier:identifier - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - }); - }]; - SetUpFWFWKHttpCookieStoreHostApi( - registrar.messenger, - [[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]); - SetUpFWFWKNavigationDelegateHostApi( - registrar.messenger, - [[FWFNavigationDelegateHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); - SetUpFWFNSObjectHostApi(registrar.messenger, - [[FWFObjectHostApiImpl alloc] initWithInstanceManager:instanceManager]); - SetUpFWFWKPreferencesHostApi(registrar.messenger, [[FWFPreferencesHostApiImpl alloc] - initWithInstanceManager:instanceManager]); - SetUpFWFWKScriptMessageHandlerHostApi( - registrar.messenger, - [[FWFScriptMessageHandlerHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); - SetUpFWFUIScrollViewHostApi(registrar.messenger, [[FWFScrollViewHostApiImpl alloc] - initWithInstanceManager:instanceManager]); - SetUpFWFWKUIDelegateHostApi(registrar.messenger, [[FWFUIDelegateHostApiImpl alloc] - initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); -#if TARGET_OS_IOS - SetUpFWFUIViewHostApi(registrar.messenger, - [[FWFUIViewHostApiImpl alloc] initWithInstanceManager:instanceManager]); -#endif - SetUpFWFWKUserContentControllerHostApi( - registrar.messenger, - [[FWFUserContentControllerHostApiImpl alloc] initWithInstanceManager:instanceManager]); - SetUpFWFWKWebsiteDataStoreHostApi( - registrar.messenger, - [[FWFWebsiteDataStoreHostApiImpl alloc] initWithInstanceManager:instanceManager]); - SetUpFWFWKWebViewConfigurationHostApi( - registrar.messenger, - [[FWFWebViewConfigurationHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); - SetUpFWFWKWebViewHostApi(registrar.messenger, [[FWFWebViewHostApiImpl alloc] - initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); - SetUpFWFNSUrlHostApi(registrar.messenger, - [[FWFURLHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); -#if TARGET_OS_IOS - SetUpFWFUIScrollViewDelegateHostApi( - registrar.messenger, - [[FWFScrollViewDelegateHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); -#endif - SetUpFWFNSUrlCredentialHostApi( - registrar.messenger, - [[FWFURLCredentialHostApiImpl alloc] initWithBinaryMessenger:registrar.messenger - instanceManager:instanceManager]); - - FWFWebViewFactory *webviewFactory = [[FWFWebViewFactory alloc] initWithManager:instanceManager]; - [registrar registerViewFactory:webviewFactory withId:@"plugins.flutter.io/webview"]; - - // InstanceManager is published so that a strong reference is maintained. - [registrar publish:instanceManager]; -} - -- (void)detachFromEngineForRegistrar:(NSObject *)registrar { - [registrar publish:[NSNull null]]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFDataConverters.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFDataConverters.m deleted file mode 100644 index ba752f3a8e33..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFDataConverters.m +++ /dev/null @@ -1,356 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NSURLRequest *_Nullable FWFNativeNSURLRequestFromRequestData(FWFNSUrlRequestData *data) { - NSURL *url = [NSURL URLWithString:data.url]; - if (!url) { - return nil; - } - - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; - if (!request) { - return nil; - } - - if (data.httpMethod) { - [request setHTTPMethod:data.httpMethod]; - } - if (data.httpBody) { - [request setHTTPBody:data.httpBody.data]; - } - [request setAllHTTPHeaderFields:data.allHttpHeaderFields]; - - return request; -} - -extern NSHTTPCookie *_Nullable FWFNativeNSHTTPCookieFromCookieData(FWFNSHttpCookieData *data) { - NSMutableDictionary *properties = [NSMutableDictionary dictionary]; - for (int i = 0; i < data.propertyKeys.count; i++) { - NSHTTPCookiePropertyKey cookieKey = - FWFNativeNSHTTPCookiePropertyKeyFromEnumData(data.propertyKeys[i]); - if (!cookieKey) { - // Some keys aren't supported on all versions, so this ignores keys - // that require a higher version or are unsupported. - continue; - } - [properties setObject:data.propertyValues[i] forKey:cookieKey]; - } - return [NSHTTPCookie cookieWithProperties:properties]; -} - -NSKeyValueObservingOptions FWFNativeNSKeyValueObservingOptionsFromEnumData( - FWFNSKeyValueObservingOptionsEnumData *data) { - switch (data.value) { - case FWFNSKeyValueObservingOptionsEnumNewValue: - return NSKeyValueObservingOptionNew; - case FWFNSKeyValueObservingOptionsEnumOldValue: - return NSKeyValueObservingOptionOld; - case FWFNSKeyValueObservingOptionsEnumInitialValue: - return NSKeyValueObservingOptionInitial; - case FWFNSKeyValueObservingOptionsEnumPriorNotification: - return NSKeyValueObservingOptionPrior; - } - - return -1; -} - -NSHTTPCookiePropertyKey _Nullable FWFNativeNSHTTPCookiePropertyKeyFromEnumData( - FWFNSHttpCookiePropertyKeyEnumData *data) { - switch (data.value) { - case FWFNSHttpCookiePropertyKeyEnumComment: - return NSHTTPCookieComment; - case FWFNSHttpCookiePropertyKeyEnumCommentUrl: - return NSHTTPCookieCommentURL; - case FWFNSHttpCookiePropertyKeyEnumDiscard: - return NSHTTPCookieDiscard; - case FWFNSHttpCookiePropertyKeyEnumDomain: - return NSHTTPCookieDomain; - case FWFNSHttpCookiePropertyKeyEnumExpires: - return NSHTTPCookieExpires; - case FWFNSHttpCookiePropertyKeyEnumMaximumAge: - return NSHTTPCookieMaximumAge; - case FWFNSHttpCookiePropertyKeyEnumName: - return NSHTTPCookieName; - case FWFNSHttpCookiePropertyKeyEnumOriginUrl: - return NSHTTPCookieOriginURL; - case FWFNSHttpCookiePropertyKeyEnumPath: - return NSHTTPCookiePath; - case FWFNSHttpCookiePropertyKeyEnumPort: - return NSHTTPCookiePort; - case FWFNSHttpCookiePropertyKeyEnumSameSitePolicy: - if (@available(iOS 13.0, macOS 10.15, *)) { - return NSHTTPCookieSameSitePolicy; - } else { - return nil; - } - case FWFNSHttpCookiePropertyKeyEnumSecure: - return NSHTTPCookieSecure; - case FWFNSHttpCookiePropertyKeyEnumValue: - return NSHTTPCookieValue; - case FWFNSHttpCookiePropertyKeyEnumVersion: - return NSHTTPCookieVersion; - } - - return nil; -} - -extern WKUserScript *FWFNativeWKUserScriptFromScriptData(FWFWKUserScriptData *data) { - return [[WKUserScript alloc] - initWithSource:data.source - injectionTime:FWFNativeWKUserScriptInjectionTimeFromEnumData(data.injectionTime) - forMainFrameOnly:data.isMainFrameOnly]; -} - -WKUserScriptInjectionTime FWFNativeWKUserScriptInjectionTimeFromEnumData( - FWFWKUserScriptInjectionTimeEnumData *data) { - switch (data.value) { - case FWFWKUserScriptInjectionTimeEnumAtDocumentStart: - return WKUserScriptInjectionTimeAtDocumentStart; - case FWFWKUserScriptInjectionTimeEnumAtDocumentEnd: - return WKUserScriptInjectionTimeAtDocumentEnd; - } - - return -1; -} - -WKAudiovisualMediaTypes FWFNativeWKAudiovisualMediaTypeFromEnumData( - FWFWKAudiovisualMediaTypeEnumData *data) { - switch (data.value) { - case FWFWKAudiovisualMediaTypeEnumNone: - return WKAudiovisualMediaTypeNone; - case FWFWKAudiovisualMediaTypeEnumAudio: - return WKAudiovisualMediaTypeAudio; - case FWFWKAudiovisualMediaTypeEnumVideo: - return WKAudiovisualMediaTypeVideo; - case FWFWKAudiovisualMediaTypeEnumAll: - return WKAudiovisualMediaTypeAll; - } - - return -1; -} - -NSString *_Nullable FWFNativeWKWebsiteDataTypeFromEnumData(FWFWKWebsiteDataTypeEnumData *data) { - switch (data.value) { - case FWFWKWebsiteDataTypeEnumCookies: - return WKWebsiteDataTypeCookies; - case FWFWKWebsiteDataTypeEnumMemoryCache: - return WKWebsiteDataTypeMemoryCache; - case FWFWKWebsiteDataTypeEnumDiskCache: - return WKWebsiteDataTypeDiskCache; - case FWFWKWebsiteDataTypeEnumOfflineWebApplicationCache: - return WKWebsiteDataTypeOfflineWebApplicationCache; - case FWFWKWebsiteDataTypeEnumLocalStorage: - return WKWebsiteDataTypeLocalStorage; - case FWFWKWebsiteDataTypeEnumSessionStorage: - return WKWebsiteDataTypeSessionStorage; - case FWFWKWebsiteDataTypeEnumWebSQLDatabases: - return WKWebsiteDataTypeWebSQLDatabases; - case FWFWKWebsiteDataTypeEnumIndexedDBDatabases: - return WKWebsiteDataTypeIndexedDBDatabases; - } - - return nil; -} - -FWFWKNavigationActionData *FWFWKNavigationActionDataFromNativeWKNavigationAction( - WKNavigationAction *action) { - return [FWFWKNavigationActionData - makeWithRequest:FWFNSUrlRequestDataFromNativeNSURLRequest(action.request) - targetFrame:FWFWKFrameInfoDataFromNativeWKFrameInfo(action.targetFrame) - navigationType:FWFWKNavigationTypeFromNativeWKNavigationType(action.navigationType)]; -} - -FWFNSUrlRequestData *FWFNSUrlRequestDataFromNativeNSURLRequest(NSURLRequest *request) { - return [FWFNSUrlRequestData - makeWithUrl:request.URL.absoluteString == nil ? @"" : request.URL.absoluteString - httpMethod:request.HTTPMethod - httpBody:request.HTTPBody - ? [FlutterStandardTypedData typedDataWithBytes:request.HTTPBody] - : nil - allHttpHeaderFields:request.allHTTPHeaderFields ? request.allHTTPHeaderFields : @{}]; -} - -FWFWKFrameInfoData *FWFWKFrameInfoDataFromNativeWKFrameInfo(WKFrameInfo *info) { - return [FWFWKFrameInfoData - makeWithIsMainFrame:info.isMainFrame - request:FWFNSUrlRequestDataFromNativeNSURLRequest(info.request)]; -} - -FWFWKNavigationResponseData *FWFWKNavigationResponseDataFromNativeNavigationResponse( - WKNavigationResponse *response) { - return [FWFWKNavigationResponseData - makeWithResponse:FWFNSHttpUrlResponseDataFromNativeNSURLResponse(response.response) - forMainFrame:response.forMainFrame]; -} - -/// Cast the NSURLResponse object to NSHTTPURLResponse. -/// -/// NSURLResponse doesn't contain the status code so it must be cast to NSHTTPURLResponse. -/// This cast will always succeed because the NSURLResponse object actually is an instance of -/// NSHTTPURLResponse. See: -/// https://developer.apple.com/documentation/foundation/nsurlresponse#overview -FWFNSHttpUrlResponseData *FWFNSHttpUrlResponseDataFromNativeNSURLResponse(NSURLResponse *response) { - NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; - return [FWFNSHttpUrlResponseData makeWithStatusCode:httpResponse.statusCode]; -} - -WKNavigationActionPolicy FWFNativeWKNavigationActionPolicyFromEnumData( - FWFWKNavigationActionPolicyEnumData *data) { - switch (data.value) { - case FWFWKNavigationActionPolicyEnumAllow: - return WKNavigationActionPolicyAllow; - case FWFWKNavigationActionPolicyEnumCancel: - return WKNavigationActionPolicyCancel; - } - - return -1; -} - -FWFNSErrorData *FWFNSErrorDataFromNativeNSError(NSError *error) { - NSMutableDictionary *userInfo; - if (error.userInfo) { - userInfo = [NSMutableDictionary dictionary]; - for (NSErrorUserInfoKey key in error.userInfo.allKeys) { - NSObject *value = error.userInfo[key]; - if ([value isKindOfClass:[NSString class]]) { - userInfo[key] = value; - } else { - userInfo[key] = [NSString stringWithFormat:@"Unsupported Type: %@", value.description]; - } - } - } - return [FWFNSErrorData makeWithCode:error.code domain:error.domain userInfo:userInfo]; -} - -WKNavigationResponsePolicy FWFNativeWKNavigationResponsePolicyFromEnum( - FWFWKNavigationResponsePolicyEnum policy) { - switch (policy) { - case FWFWKNavigationResponsePolicyEnumAllow: - return WKNavigationResponsePolicyAllow; - case FWFWKNavigationResponsePolicyEnumCancel: - return WKNavigationResponsePolicyCancel; - } - - return -1; -} - -FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey( - 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]; - } else { - return [FWFNSKeyValueChangeKeyEnumData makeWithValue:FWFNSKeyValueChangeKeyEnumUnknown]; - } - - return nil; -} - -FWFWKScriptMessageData *FWFWKScriptMessageDataFromNativeWKScriptMessage(WKScriptMessage *message) { - return [FWFWKScriptMessageData makeWithName:message.name body:message.body]; -} - -FWFWKNavigationType FWFWKNavigationTypeFromNativeWKNavigationType(WKNavigationType type) { - switch (type) { - case WKNavigationTypeLinkActivated: - return FWFWKNavigationTypeLinkActivated; - case WKNavigationTypeFormSubmitted: - return FWFWKNavigationTypeFormResubmitted; - case WKNavigationTypeBackForward: - return FWFWKNavigationTypeBackForward; - case WKNavigationTypeReload: - return FWFWKNavigationTypeReload; - case WKNavigationTypeFormResubmitted: - return FWFWKNavigationTypeFormResubmitted; - case WKNavigationTypeOther: - return FWFWKNavigationTypeOther; - } - - return FWFWKNavigationTypeUnknown; -} - -FWFWKSecurityOriginData *FWFWKSecurityOriginDataFromNativeWKSecurityOrigin( - WKSecurityOrigin *origin) { - return [FWFWKSecurityOriginData makeWithHost:origin.host - port:origin.port - protocol:origin.protocol]; -} - -WKPermissionDecision FWFNativeWKPermissionDecisionFromData(FWFWKPermissionDecisionData *data) { - switch (data.value) { - case FWFWKPermissionDecisionDeny: - return WKPermissionDecisionDeny; - case FWFWKPermissionDecisionGrant: - return WKPermissionDecisionGrant; - case FWFWKPermissionDecisionPrompt: - return WKPermissionDecisionPrompt; - } - - return -1; -} - -FWFWKMediaCaptureTypeData *FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType( - WKMediaCaptureType type) { - switch (type) { - case WKMediaCaptureTypeCamera: - return [FWFWKMediaCaptureTypeData makeWithValue:FWFWKMediaCaptureTypeCamera]; - case WKMediaCaptureTypeMicrophone: - return [FWFWKMediaCaptureTypeData makeWithValue:FWFWKMediaCaptureTypeMicrophone]; - case WKMediaCaptureTypeCameraAndMicrophone: - return [FWFWKMediaCaptureTypeData makeWithValue:FWFWKMediaCaptureTypeCameraAndMicrophone]; - default: - return [FWFWKMediaCaptureTypeData makeWithValue:FWFWKMediaCaptureTypeUnknown]; - } - - return nil; -} - -NSURLSessionAuthChallengeDisposition -FWFNativeNSURLSessionAuthChallengeDispositionFromFWFNSUrlSessionAuthChallengeDisposition( - FWFNSUrlSessionAuthChallengeDisposition value) { - switch (value) { - case FWFNSUrlSessionAuthChallengeDispositionUseCredential: - return NSURLSessionAuthChallengeUseCredential; - case FWFNSUrlSessionAuthChallengeDispositionPerformDefaultHandling: - return NSURLSessionAuthChallengePerformDefaultHandling; - case FWFNSUrlSessionAuthChallengeDispositionCancelAuthenticationChallenge: - return NSURLSessionAuthChallengeCancelAuthenticationChallenge; - case FWFNSUrlSessionAuthChallengeDispositionRejectProtectionSpace: - return NSURLSessionAuthChallengeRejectProtectionSpace; - } - - return -1; -} - -NSURLCredentialPersistence FWFNativeNSURLCredentialPersistenceFromFWFNSUrlCredentialPersistence( - FWFNSUrlCredentialPersistence value) { - switch (value) { - case FWFNSUrlCredentialPersistenceNone: - return NSURLCredentialPersistenceNone; - case FWFNSUrlCredentialPersistenceSession: - return NSURLCredentialPersistenceForSession; - case FWFNSUrlCredentialPersistencePermanent: - return NSURLCredentialPersistencePermanent; - case FWFNSUrlCredentialPersistenceSynchronizable: - return NSURLCredentialPersistenceSynchronizable; - } - - return -1; -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFGeneratedWebKitApis.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFGeneratedWebKitApis.m deleted file mode 100644 index 0ceb9214ddec..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFGeneratedWebKitApis.m +++ /dev/null @@ -1,4135 +0,0 @@ -// 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 (v18.0.0), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#import "./include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#if !__has_feature(objc_arc) -#error File requires ARC to be enabled. -#endif - -static NSArray *wrapResult(id result, FlutterError *error) { - if (error) { - return @[ - error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] - ]; - } - return @[ result ?: [NSNull null] ]; -} - -static FlutterError *createConnectionError(NSString *channelName) { - return [FlutterError - errorWithCode:@"channel-error" - message:[NSString stringWithFormat:@"%@/%@/%@", - @"Unable to establish connection on channel: '", - channelName, @"'."] - details:@""]; -} - -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { - id result = array[key]; - return (result == [NSNull null]) ? nil : result; -} - -/// Mirror of NSKeyValueObservingOptions. -/// -/// See -/// https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions?language=objc. -@implementation FWFNSKeyValueObservingOptionsEnumBox -- (instancetype)initWithValue:(FWFNSKeyValueObservingOptionsEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of NSKeyValueChange. -/// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange?language=objc. -@implementation FWFNSKeyValueChangeEnumBox -- (instancetype)initWithValue:(FWFNSKeyValueChangeEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of NSKeyValueChangeKey. -/// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey?language=objc. -@implementation FWFNSKeyValueChangeKeyEnumBox -- (instancetype)initWithValue:(FWFNSKeyValueChangeKeyEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of WKUserScriptInjectionTime. -/// -/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc. -@implementation FWFWKUserScriptInjectionTimeEnumBox -- (instancetype)initWithValue:(FWFWKUserScriptInjectionTimeEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of WKAudiovisualMediaTypes. -/// -/// See -/// [WKAudiovisualMediaTypes](https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes?language=objc). -@implementation FWFWKAudiovisualMediaTypeEnumBox -- (instancetype)initWithValue:(FWFWKAudiovisualMediaTypeEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of WKWebsiteDataTypes. -/// -/// See -/// https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types?language=objc. -@implementation FWFWKWebsiteDataTypeEnumBox -- (instancetype)initWithValue:(FWFWKWebsiteDataTypeEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of WKNavigationActionPolicy. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -@implementation FWFWKNavigationActionPolicyEnumBox -- (instancetype)initWithValue:(FWFWKNavigationActionPolicyEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of WKNavigationResponsePolicy. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -@implementation FWFWKNavigationResponsePolicyEnumBox -- (instancetype)initWithValue:(FWFWKNavigationResponsePolicyEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Mirror of NSHTTPCookiePropertyKey. -/// -/// See https://developer.apple.com/documentation/foundation/nshttpcookiepropertykey. -@implementation FWFNSHttpCookiePropertyKeyEnumBox -- (instancetype)initWithValue:(FWFNSHttpCookiePropertyKeyEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// An object that contains information about an action that causes navigation -/// to occur. -/// -/// Wraps -/// [WKNavigationType](https://developer.apple.com/documentation/webkit/wknavigationaction?language=objc). -@implementation FWFWKNavigationTypeBox -- (instancetype)initWithValue:(FWFWKNavigationType)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Possible permission decisions for device resource access. -/// -/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc. -@implementation FWFWKPermissionDecisionBox -- (instancetype)initWithValue:(FWFWKPermissionDecision)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// List of the types of media devices that can capture audio, video, or both. -/// -/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype?language=objc. -@implementation FWFWKMediaCaptureTypeBox -- (instancetype)initWithValue:(FWFWKMediaCaptureType)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Responses to an authentication challenge. -/// -/// See -/// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition?language=objc. -@implementation FWFNSUrlSessionAuthChallengeDispositionBox -- (instancetype)initWithValue:(FWFNSUrlSessionAuthChallengeDisposition)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -/// Specifies how long a credential will be kept. -@implementation FWFNSUrlCredentialPersistenceBox -- (instancetype)initWithValue:(FWFNSUrlCredentialPersistence)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -@interface FWFNSKeyValueObservingOptionsEnumData () -+ (FWFNSKeyValueObservingOptionsEnumData *)fromList:(NSArray *)list; -+ (nullable FWFNSKeyValueObservingOptionsEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSKeyValueChangeKeyEnumData () -+ (FWFNSKeyValueChangeKeyEnumData *)fromList:(NSArray *)list; -+ (nullable FWFNSKeyValueChangeKeyEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKUserScriptInjectionTimeEnumData () -+ (FWFWKUserScriptInjectionTimeEnumData *)fromList:(NSArray *)list; -+ (nullable FWFWKUserScriptInjectionTimeEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKAudiovisualMediaTypeEnumData () -+ (FWFWKAudiovisualMediaTypeEnumData *)fromList:(NSArray *)list; -+ (nullable FWFWKAudiovisualMediaTypeEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKWebsiteDataTypeEnumData () -+ (FWFWKWebsiteDataTypeEnumData *)fromList:(NSArray *)list; -+ (nullable FWFWKWebsiteDataTypeEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKNavigationActionPolicyEnumData () -+ (FWFWKNavigationActionPolicyEnumData *)fromList:(NSArray *)list; -+ (nullable FWFWKNavigationActionPolicyEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSHttpCookiePropertyKeyEnumData () -+ (FWFNSHttpCookiePropertyKeyEnumData *)fromList:(NSArray *)list; -+ (nullable FWFNSHttpCookiePropertyKeyEnumData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKPermissionDecisionData () -+ (FWFWKPermissionDecisionData *)fromList:(NSArray *)list; -+ (nullable FWFWKPermissionDecisionData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKMediaCaptureTypeData () -+ (FWFWKMediaCaptureTypeData *)fromList:(NSArray *)list; -+ (nullable FWFWKMediaCaptureTypeData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSUrlRequestData () -+ (FWFNSUrlRequestData *)fromList:(NSArray *)list; -+ (nullable FWFNSUrlRequestData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSHttpUrlResponseData () -+ (FWFNSHttpUrlResponseData *)fromList:(NSArray *)list; -+ (nullable FWFNSHttpUrlResponseData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKUserScriptData () -+ (FWFWKUserScriptData *)fromList:(NSArray *)list; -+ (nullable FWFWKUserScriptData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKNavigationActionData () -+ (FWFWKNavigationActionData *)fromList:(NSArray *)list; -+ (nullable FWFWKNavigationActionData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKNavigationResponseData () -+ (FWFWKNavigationResponseData *)fromList:(NSArray *)list; -+ (nullable FWFWKNavigationResponseData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKFrameInfoData () -+ (FWFWKFrameInfoData *)fromList:(NSArray *)list; -+ (nullable FWFWKFrameInfoData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSErrorData () -+ (FWFNSErrorData *)fromList:(NSArray *)list; -+ (nullable FWFNSErrorData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKScriptMessageData () -+ (FWFWKScriptMessageData *)fromList:(NSArray *)list; -+ (nullable FWFWKScriptMessageData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFWKSecurityOriginData () -+ (FWFWKSecurityOriginData *)fromList:(NSArray *)list; -+ (nullable FWFWKSecurityOriginData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFNSHttpCookieData () -+ (FWFNSHttpCookieData *)fromList:(NSArray *)list; -+ (nullable FWFNSHttpCookieData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFObjectOrIdentifier () -+ (FWFObjectOrIdentifier *)fromList:(NSArray *)list; -+ (nullable FWFObjectOrIdentifier *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface FWFAuthenticationChallengeResponse () -+ (FWFAuthenticationChallengeResponse *)fromList:(NSArray *)list; -+ (nullable FWFAuthenticationChallengeResponse *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@implementation FWFNSKeyValueObservingOptionsEnumData -+ (instancetype)makeWithValue:(FWFNSKeyValueObservingOptionsEnum)value { - FWFNSKeyValueObservingOptionsEnumData *pigeonResult = - [[FWFNSKeyValueObservingOptionsEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFNSKeyValueObservingOptionsEnumData *)fromList:(NSArray *)list { - FWFNSKeyValueObservingOptionsEnumData *pigeonResult = - [[FWFNSKeyValueObservingOptionsEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFNSKeyValueObservingOptionsEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSKeyValueObservingOptionsEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFNSKeyValueChangeKeyEnumData -+ (instancetype)makeWithValue:(FWFNSKeyValueChangeKeyEnum)value { - FWFNSKeyValueChangeKeyEnumData *pigeonResult = [[FWFNSKeyValueChangeKeyEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFNSKeyValueChangeKeyEnumData *)fromList:(NSArray *)list { - FWFNSKeyValueChangeKeyEnumData *pigeonResult = [[FWFNSKeyValueChangeKeyEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFNSKeyValueChangeKeyEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSKeyValueChangeKeyEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKUserScriptInjectionTimeEnumData -+ (instancetype)makeWithValue:(FWFWKUserScriptInjectionTimeEnum)value { - FWFWKUserScriptInjectionTimeEnumData *pigeonResult = - [[FWFWKUserScriptInjectionTimeEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKUserScriptInjectionTimeEnumData *)fromList:(NSArray *)list { - FWFWKUserScriptInjectionTimeEnumData *pigeonResult = - [[FWFWKUserScriptInjectionTimeEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKUserScriptInjectionTimeEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKUserScriptInjectionTimeEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKAudiovisualMediaTypeEnumData -+ (instancetype)makeWithValue:(FWFWKAudiovisualMediaTypeEnum)value { - FWFWKAudiovisualMediaTypeEnumData *pigeonResult = - [[FWFWKAudiovisualMediaTypeEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKAudiovisualMediaTypeEnumData *)fromList:(NSArray *)list { - FWFWKAudiovisualMediaTypeEnumData *pigeonResult = - [[FWFWKAudiovisualMediaTypeEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKAudiovisualMediaTypeEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKAudiovisualMediaTypeEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKWebsiteDataTypeEnumData -+ (instancetype)makeWithValue:(FWFWKWebsiteDataTypeEnum)value { - FWFWKWebsiteDataTypeEnumData *pigeonResult = [[FWFWKWebsiteDataTypeEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKWebsiteDataTypeEnumData *)fromList:(NSArray *)list { - FWFWKWebsiteDataTypeEnumData *pigeonResult = [[FWFWKWebsiteDataTypeEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKWebsiteDataTypeEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKWebsiteDataTypeEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKNavigationActionPolicyEnumData -+ (instancetype)makeWithValue:(FWFWKNavigationActionPolicyEnum)value { - FWFWKNavigationActionPolicyEnumData *pigeonResult = - [[FWFWKNavigationActionPolicyEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKNavigationActionPolicyEnumData *)fromList:(NSArray *)list { - FWFWKNavigationActionPolicyEnumData *pigeonResult = - [[FWFWKNavigationActionPolicyEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKNavigationActionPolicyEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKNavigationActionPolicyEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFNSHttpCookiePropertyKeyEnumData -+ (instancetype)makeWithValue:(FWFNSHttpCookiePropertyKeyEnum)value { - FWFNSHttpCookiePropertyKeyEnumData *pigeonResult = - [[FWFNSHttpCookiePropertyKeyEnumData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFNSHttpCookiePropertyKeyEnumData *)fromList:(NSArray *)list { - FWFNSHttpCookiePropertyKeyEnumData *pigeonResult = - [[FWFNSHttpCookiePropertyKeyEnumData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFNSHttpCookiePropertyKeyEnumData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSHttpCookiePropertyKeyEnumData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKPermissionDecisionData -+ (instancetype)makeWithValue:(FWFWKPermissionDecision)value { - FWFWKPermissionDecisionData *pigeonResult = [[FWFWKPermissionDecisionData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKPermissionDecisionData *)fromList:(NSArray *)list { - FWFWKPermissionDecisionData *pigeonResult = [[FWFWKPermissionDecisionData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKPermissionDecisionData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKPermissionDecisionData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFWKMediaCaptureTypeData -+ (instancetype)makeWithValue:(FWFWKMediaCaptureType)value { - FWFWKMediaCaptureTypeData *pigeonResult = [[FWFWKMediaCaptureTypeData alloc] init]; - pigeonResult.value = value; - return pigeonResult; -} -+ (FWFWKMediaCaptureTypeData *)fromList:(NSArray *)list { - FWFWKMediaCaptureTypeData *pigeonResult = [[FWFWKMediaCaptureTypeData alloc] init]; - pigeonResult.value = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKMediaCaptureTypeData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKMediaCaptureTypeData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.value), - ]; -} -@end - -@implementation FWFNSUrlRequestData -+ (instancetype)makeWithUrl:(NSString *)url - httpMethod:(nullable NSString *)httpMethod - httpBody:(nullable FlutterStandardTypedData *)httpBody - allHttpHeaderFields:(NSDictionary *)allHttpHeaderFields { - FWFNSUrlRequestData *pigeonResult = [[FWFNSUrlRequestData alloc] init]; - pigeonResult.url = url; - pigeonResult.httpMethod = httpMethod; - pigeonResult.httpBody = httpBody; - pigeonResult.allHttpHeaderFields = allHttpHeaderFields; - return pigeonResult; -} -+ (FWFNSUrlRequestData *)fromList:(NSArray *)list { - FWFNSUrlRequestData *pigeonResult = [[FWFNSUrlRequestData alloc] init]; - pigeonResult.url = GetNullableObjectAtIndex(list, 0); - pigeonResult.httpMethod = GetNullableObjectAtIndex(list, 1); - pigeonResult.httpBody = GetNullableObjectAtIndex(list, 2); - pigeonResult.allHttpHeaderFields = GetNullableObjectAtIndex(list, 3); - return pigeonResult; -} -+ (nullable FWFNSUrlRequestData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSUrlRequestData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.url ?: [NSNull null], - self.httpMethod ?: [NSNull null], - self.httpBody ?: [NSNull null], - self.allHttpHeaderFields ?: [NSNull null], - ]; -} -@end - -@implementation FWFNSHttpUrlResponseData -+ (instancetype)makeWithStatusCode:(NSInteger)statusCode { - FWFNSHttpUrlResponseData *pigeonResult = [[FWFNSHttpUrlResponseData alloc] init]; - pigeonResult.statusCode = statusCode; - return pigeonResult; -} -+ (FWFNSHttpUrlResponseData *)fromList:(NSArray *)list { - FWFNSHttpUrlResponseData *pigeonResult = [[FWFNSHttpUrlResponseData alloc] init]; - pigeonResult.statusCode = [GetNullableObjectAtIndex(list, 0) integerValue]; - return pigeonResult; -} -+ (nullable FWFNSHttpUrlResponseData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSHttpUrlResponseData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.statusCode), - ]; -} -@end - -@implementation FWFWKUserScriptData -+ (instancetype)makeWithSource:(NSString *)source - injectionTime:(nullable FWFWKUserScriptInjectionTimeEnumData *)injectionTime - isMainFrameOnly:(BOOL)isMainFrameOnly { - FWFWKUserScriptData *pigeonResult = [[FWFWKUserScriptData alloc] init]; - pigeonResult.source = source; - pigeonResult.injectionTime = injectionTime; - pigeonResult.isMainFrameOnly = isMainFrameOnly; - return pigeonResult; -} -+ (FWFWKUserScriptData *)fromList:(NSArray *)list { - FWFWKUserScriptData *pigeonResult = [[FWFWKUserScriptData alloc] init]; - pigeonResult.source = GetNullableObjectAtIndex(list, 0); - pigeonResult.injectionTime = - [FWFWKUserScriptInjectionTimeEnumData nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.isMainFrameOnly = [GetNullableObjectAtIndex(list, 2) boolValue]; - return pigeonResult; -} -+ (nullable FWFWKUserScriptData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKUserScriptData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.source ?: [NSNull null], - (self.injectionTime ? [self.injectionTime toList] : [NSNull null]), - @(self.isMainFrameOnly), - ]; -} -@end - -@implementation FWFWKNavigationActionData -+ (instancetype)makeWithRequest:(FWFNSUrlRequestData *)request - targetFrame:(FWFWKFrameInfoData *)targetFrame - navigationType:(FWFWKNavigationType)navigationType { - FWFWKNavigationActionData *pigeonResult = [[FWFWKNavigationActionData alloc] init]; - pigeonResult.request = request; - pigeonResult.targetFrame = targetFrame; - pigeonResult.navigationType = navigationType; - return pigeonResult; -} -+ (FWFWKNavigationActionData *)fromList:(NSArray *)list { - FWFWKNavigationActionData *pigeonResult = [[FWFWKNavigationActionData alloc] init]; - pigeonResult.request = [FWFNSUrlRequestData nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.targetFrame = - [FWFWKFrameInfoData nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.navigationType = [GetNullableObjectAtIndex(list, 2) integerValue]; - return pigeonResult; -} -+ (nullable FWFWKNavigationActionData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKNavigationActionData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - (self.request ? [self.request toList] : [NSNull null]), - (self.targetFrame ? [self.targetFrame toList] : [NSNull null]), - @(self.navigationType), - ]; -} -@end - -@implementation FWFWKNavigationResponseData -+ (instancetype)makeWithResponse:(FWFNSHttpUrlResponseData *)response - forMainFrame:(BOOL)forMainFrame { - FWFWKNavigationResponseData *pigeonResult = [[FWFWKNavigationResponseData alloc] init]; - pigeonResult.response = response; - pigeonResult.forMainFrame = forMainFrame; - return pigeonResult; -} -+ (FWFWKNavigationResponseData *)fromList:(NSArray *)list { - FWFWKNavigationResponseData *pigeonResult = [[FWFWKNavigationResponseData alloc] init]; - pigeonResult.response = - [FWFNSHttpUrlResponseData nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.forMainFrame = [GetNullableObjectAtIndex(list, 1) boolValue]; - return pigeonResult; -} -+ (nullable FWFWKNavigationResponseData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKNavigationResponseData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - (self.response ? [self.response toList] : [NSNull null]), - @(self.forMainFrame), - ]; -} -@end - -@implementation FWFWKFrameInfoData -+ (instancetype)makeWithIsMainFrame:(BOOL)isMainFrame request:(FWFNSUrlRequestData *)request { - FWFWKFrameInfoData *pigeonResult = [[FWFWKFrameInfoData alloc] init]; - pigeonResult.isMainFrame = isMainFrame; - pigeonResult.request = request; - return pigeonResult; -} -+ (FWFWKFrameInfoData *)fromList:(NSArray *)list { - FWFWKFrameInfoData *pigeonResult = [[FWFWKFrameInfoData alloc] init]; - pigeonResult.isMainFrame = [GetNullableObjectAtIndex(list, 0) boolValue]; - pigeonResult.request = [FWFNSUrlRequestData nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - return pigeonResult; -} -+ (nullable FWFWKFrameInfoData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKFrameInfoData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.isMainFrame), - (self.request ? [self.request toList] : [NSNull null]), - ]; -} -@end - -@implementation FWFNSErrorData -+ (instancetype)makeWithCode:(NSInteger)code - domain:(NSString *)domain - userInfo:(nullable NSDictionary *)userInfo { - FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; - pigeonResult.code = code; - pigeonResult.domain = domain; - pigeonResult.userInfo = userInfo; - return pigeonResult; -} -+ (FWFNSErrorData *)fromList:(NSArray *)list { - FWFNSErrorData *pigeonResult = [[FWFNSErrorData alloc] init]; - pigeonResult.code = [GetNullableObjectAtIndex(list, 0) integerValue]; - pigeonResult.domain = GetNullableObjectAtIndex(list, 1); - pigeonResult.userInfo = GetNullableObjectAtIndex(list, 2); - return pigeonResult; -} -+ (nullable FWFNSErrorData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSErrorData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.code), - self.domain ?: [NSNull null], - self.userInfo ?: [NSNull null], - ]; -} -@end - -@implementation FWFWKScriptMessageData -+ (instancetype)makeWithName:(NSString *)name body:(nullable id)body { - FWFWKScriptMessageData *pigeonResult = [[FWFWKScriptMessageData alloc] init]; - pigeonResult.name = name; - pigeonResult.body = body; - return pigeonResult; -} -+ (FWFWKScriptMessageData *)fromList:(NSArray *)list { - FWFWKScriptMessageData *pigeonResult = [[FWFWKScriptMessageData alloc] init]; - pigeonResult.name = GetNullableObjectAtIndex(list, 0); - pigeonResult.body = GetNullableObjectAtIndex(list, 1); - return pigeonResult; -} -+ (nullable FWFWKScriptMessageData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKScriptMessageData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.name ?: [NSNull null], - self.body ?: [NSNull null], - ]; -} -@end - -@implementation FWFWKSecurityOriginData -+ (instancetype)makeWithHost:(NSString *)host port:(NSInteger)port protocol:(NSString *)protocol { - FWFWKSecurityOriginData *pigeonResult = [[FWFWKSecurityOriginData alloc] init]; - pigeonResult.host = host; - pigeonResult.port = port; - pigeonResult.protocol = protocol; - return pigeonResult; -} -+ (FWFWKSecurityOriginData *)fromList:(NSArray *)list { - FWFWKSecurityOriginData *pigeonResult = [[FWFWKSecurityOriginData alloc] init]; - pigeonResult.host = GetNullableObjectAtIndex(list, 0); - pigeonResult.port = [GetNullableObjectAtIndex(list, 1) integerValue]; - pigeonResult.protocol = GetNullableObjectAtIndex(list, 2); - return pigeonResult; -} -+ (nullable FWFWKSecurityOriginData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFWKSecurityOriginData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.host ?: [NSNull null], - @(self.port), - self.protocol ?: [NSNull null], - ]; -} -@end - -@implementation FWFNSHttpCookieData -+ (instancetype)makeWithPropertyKeys:(NSArray *)propertyKeys - propertyValues:(NSArray *)propertyValues { - FWFNSHttpCookieData *pigeonResult = [[FWFNSHttpCookieData alloc] init]; - pigeonResult.propertyKeys = propertyKeys; - pigeonResult.propertyValues = propertyValues; - return pigeonResult; -} -+ (FWFNSHttpCookieData *)fromList:(NSArray *)list { - FWFNSHttpCookieData *pigeonResult = [[FWFNSHttpCookieData alloc] init]; - pigeonResult.propertyKeys = GetNullableObjectAtIndex(list, 0); - pigeonResult.propertyValues = GetNullableObjectAtIndex(list, 1); - return pigeonResult; -} -+ (nullable FWFNSHttpCookieData *)nullableFromList:(NSArray *)list { - return (list) ? [FWFNSHttpCookieData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.propertyKeys ?: [NSNull null], - self.propertyValues ?: [NSNull null], - ]; -} -@end - -@implementation FWFObjectOrIdentifier -+ (instancetype)makeWithValue:(nullable id)value isIdentifier:(BOOL)isIdentifier { - FWFObjectOrIdentifier *pigeonResult = [[FWFObjectOrIdentifier alloc] init]; - pigeonResult.value = value; - pigeonResult.isIdentifier = isIdentifier; - return pigeonResult; -} -+ (FWFObjectOrIdentifier *)fromList:(NSArray *)list { - FWFObjectOrIdentifier *pigeonResult = [[FWFObjectOrIdentifier alloc] init]; - pigeonResult.value = GetNullableObjectAtIndex(list, 0); - pigeonResult.isIdentifier = [GetNullableObjectAtIndex(list, 1) boolValue]; - return pigeonResult; -} -+ (nullable FWFObjectOrIdentifier *)nullableFromList:(NSArray *)list { - return (list) ? [FWFObjectOrIdentifier fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.value ?: [NSNull null], - @(self.isIdentifier), - ]; -} -@end - -@implementation FWFAuthenticationChallengeResponse -+ (instancetype)makeWithDisposition:(FWFNSUrlSessionAuthChallengeDisposition)disposition - credentialIdentifier:(nullable NSNumber *)credentialIdentifier { - FWFAuthenticationChallengeResponse *pigeonResult = - [[FWFAuthenticationChallengeResponse alloc] init]; - pigeonResult.disposition = disposition; - pigeonResult.credentialIdentifier = credentialIdentifier; - return pigeonResult; -} -+ (FWFAuthenticationChallengeResponse *)fromList:(NSArray *)list { - FWFAuthenticationChallengeResponse *pigeonResult = - [[FWFAuthenticationChallengeResponse alloc] init]; - pigeonResult.disposition = [GetNullableObjectAtIndex(list, 0) integerValue]; - pigeonResult.credentialIdentifier = GetNullableObjectAtIndex(list, 1); - return pigeonResult; -} -+ (nullable FWFAuthenticationChallengeResponse *)nullableFromList:(NSArray *)list { - return (list) ? [FWFAuthenticationChallengeResponse fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - @(self.disposition), - self.credentialIdentifier ?: [NSNull null], - ]; -} -@end - -@interface FWFWKWebsiteDataStoreHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKWebsiteDataStoreHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFWKWebsiteDataTypeEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKWebsiteDataStoreHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKWebsiteDataStoreHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFWKWebsiteDataTypeEnumData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKWebsiteDataStoreHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKWebsiteDataStoreHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKWebsiteDataStoreHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKWebsiteDataStoreHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKWebsiteDataStoreHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKWebsiteDataStoreHostApiCodecReaderWriter *readerWriter = - [[FWFWKWebsiteDataStoreHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFWKWebsiteDataStoreHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKWebsiteDataStoreHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKWebsiteDataStoreHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebsiteDataStoreHostApi.createFromWebViewConfiguration", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebsiteDataStoreHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(createFromWebViewConfigurationWithIdentifier: - configurationIdentifier:error:)], - @"FWFWKWebsiteDataStoreHostApi api (%@) doesn't respond to " - @"@selector(createFromWebViewConfigurationWithIdentifier:configurationIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_configurationIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebViewConfigurationWithIdentifier:arg_identifier - configurationIdentifier:arg_configurationIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebsiteDataStoreHostApi.createDefaultDataStore", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebsiteDataStoreHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createDefaultDataStoreWithIdentifier:error:)], - @"FWFWKWebsiteDataStoreHostApi api (%@) doesn't respond to " - @"@selector(createDefaultDataStoreWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createDefaultDataStoreWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebsiteDataStoreHostApi.removeDataOfTypes", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebsiteDataStoreHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector - (removeDataFromDataStoreWithIdentifier:ofTypes:modifiedSince:completion:)], - @"FWFWKWebsiteDataStoreHostApi api (%@) doesn't respond to " - @"@selector(removeDataFromDataStoreWithIdentifier:ofTypes:modifiedSince:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSArray *arg_dataTypes = GetNullableObjectAtIndex(args, 1); - double arg_modificationTimeInSecondsSinceEpoch = - [GetNullableObjectAtIndex(args, 2) doubleValue]; - [api removeDataFromDataStoreWithIdentifier:arg_identifier - ofTypes:arg_dataTypes - modifiedSince:arg_modificationTimeInSecondsSinceEpoch - completion:^(NSNumber *_Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFUIViewHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFUIViewHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFUIViewHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFUIViewHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIViewHostApi.setBackgroundColor", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setBackgroundColorForViewWithIdentifier: - toValue:error:)], - @"FWFUIViewHostApi api (%@) doesn't respond to " - @"@selector(setBackgroundColorForViewWithIdentifier:toValue:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSNumber *arg_value = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setBackgroundColorForViewWithIdentifier:arg_identifier toValue:arg_value error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIViewHostApi.setOpaque", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setOpaqueForViewWithIdentifier:isOpaque:error:)], - @"FWFUIViewHostApi api (%@) doesn't respond to " - @"@selector(setOpaqueForViewWithIdentifier:isOpaque:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_opaque = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setOpaqueForViewWithIdentifier:arg_identifier isOpaque:arg_opaque error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFUIScrollViewHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFUIScrollViewHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFUIScrollViewHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFUIScrollViewHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewHostApi.createFromWebView", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createFromWebViewWithIdentifier: - webViewIdentifier:error:)], - @"FWFUIScrollViewHostApi api (%@) doesn't respond to " - @"@selector(createFromWebViewWithIdentifier:webViewIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_webViewIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebViewWithIdentifier:arg_identifier - webViewIdentifier:arg_webViewIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewHostApi.getContentOffset", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(contentOffsetForScrollViewWithIdentifier:error:)], - @"FWFUIScrollViewHostApi api (%@) doesn't respond to " - @"@selector(contentOffsetForScrollViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSArray *output = [api contentOffsetForScrollViewWithIdentifier:arg_identifier - error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewHostApi.scrollBy", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(scrollByForScrollViewWithIdentifier:x:y:error:)], - @"FWFUIScrollViewHostApi api (%@) doesn't respond to " - @"@selector(scrollByForScrollViewWithIdentifier:x:y:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - double arg_x = [GetNullableObjectAtIndex(args, 1) doubleValue]; - double arg_y = [GetNullableObjectAtIndex(args, 2) doubleValue]; - FlutterError *error; - [api scrollByForScrollViewWithIdentifier:arg_identifier x:arg_x y:arg_y error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewHostApi.setContentOffset", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setContentOffsetForScrollViewWithIdentifier:toX:y:error:)], - @"FWFUIScrollViewHostApi api (%@) doesn't respond to " - @"@selector(setContentOffsetForScrollViewWithIdentifier:toX:y:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - double arg_x = [GetNullableObjectAtIndex(args, 1) doubleValue]; - double arg_y = [GetNullableObjectAtIndex(args, 2) doubleValue]; - FlutterError *error; - [api setContentOffsetForScrollViewWithIdentifier:arg_identifier - toX:arg_x - y:arg_y - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewHostApi.setDelegate", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setDelegateForScrollViewWithIdentifier: - uiScrollViewDelegateIdentifier:error:)], - @"FWFUIScrollViewHostApi api (%@) doesn't respond to " - @"@selector(setDelegateForScrollViewWithIdentifier:uiScrollViewDelegateIdentifier:" - @"error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSNumber *arg_uiScrollViewDelegateIdentifier = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setDelegateForScrollViewWithIdentifier:arg_identifier - uiScrollViewDelegateIdentifier:arg_uiScrollViewDelegateIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -@interface FWFWKWebViewConfigurationHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKWebViewConfigurationHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFWKAudiovisualMediaTypeEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKWebViewConfigurationHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKWebViewConfigurationHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFWKAudiovisualMediaTypeEnumData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKWebViewConfigurationHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKWebViewConfigurationHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKWebViewConfigurationHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKWebViewConfigurationHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKWebViewConfigurationHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKWebViewConfigurationHostApiCodecReaderWriter *readerWriter = - [[FWFWKWebViewConfigurationHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFWKWebViewConfigurationHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKWebViewConfigurationHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKWebViewConfigurationHostApiWithSuffix( - id binaryMessenger, NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewConfigurationHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewConfigurationHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier:error:)], - @"FWFWKWebViewConfigurationHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewConfigurationHostApi.createFromWebView", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewConfigurationHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createFromWebViewWithIdentifier: - webViewIdentifier:error:)], - @"FWFWKWebViewConfigurationHostApi api (%@) doesn't respond to " - @"@selector(createFromWebViewWithIdentifier:webViewIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_webViewIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebViewWithIdentifier:arg_identifier - webViewIdentifier:arg_webViewIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewConfigurationHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector - (setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:isAllowed:error:)], - @"FWFWKWebViewConfigurationHostApi api (%@) doesn't respond to " - @"@selector(setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:isAllowed:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_allow = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:arg_identifier - isAllowed:arg_allow - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewConfigurationHostApi." - @"setLimitsNavigationsToAppBoundDomains", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewConfigurationHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier: - isLimited:error:)], - @"FWFWKWebViewConfigurationHostApi api (%@) doesn't respond to " - @"@selector(setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:" - @"isLimited:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_limit = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:arg_identifier - isLimited:arg_limit - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewConfigurationHostApi." - @"setMediaTypesRequiringUserActionForPlayback", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewConfigurationHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setMediaTypesRequiresUserActionForConfigurationWithIdentifier: - forTypes:error:)], - @"FWFWKWebViewConfigurationHostApi api (%@) doesn't respond to " - @"@selector(setMediaTypesRequiresUserActionForConfigurationWithIdentifier:forTypes:" - @"error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSArray *arg_types = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setMediaTypesRequiresUserActionForConfigurationWithIdentifier:arg_identifier - forTypes:arg_types - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFWKWebViewConfigurationFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -@interface FWFWKWebViewConfigurationFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFWKWebViewConfigurationFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)createWithIdentifier:(NSInteger)arg_identifier - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationFlutterApi.create", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKWebViewConfigurationFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -@interface FWFWKUserContentControllerHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKUserContentControllerHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFWKUserScriptData fromList:[self readValue]]; - case 129: - return [FWFWKUserScriptInjectionTimeEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKUserContentControllerHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKUserContentControllerHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFWKUserScriptData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKUserScriptInjectionTimeEnumData class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKUserContentControllerHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKUserContentControllerHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKUserContentControllerHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKUserContentControllerHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKUserContentControllerHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKUserContentControllerHostApiCodecReaderWriter *readerWriter = - [[FWFWKUserContentControllerHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFWKUserContentControllerHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKUserContentControllerHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKUserContentControllerHostApiWithSuffix( - id binaryMessenger, NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.createFromWebViewConfiguration", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(createFromWebViewConfigurationWithIdentifier: - configurationIdentifier:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(createFromWebViewConfigurationWithIdentifier:configurationIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_configurationIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebViewConfigurationWithIdentifier:arg_identifier - configurationIdentifier:arg_configurationIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.addScriptMessageHandler", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (addScriptMessageHandlerForControllerWithIdentifier: - handlerIdentifier:ofName:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(addScriptMessageHandlerForControllerWithIdentifier:handlerIdentifier:" - @"ofName:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_handlerIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - NSString *arg_name = GetNullableObjectAtIndex(args, 2); - FlutterError *error; - [api addScriptMessageHandlerForControllerWithIdentifier:arg_identifier - handlerIdentifier:arg_handlerIdentifier - ofName:arg_name - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.removeScriptMessageHandler", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (removeScriptMessageHandlerForControllerWithIdentifier:name:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(removeScriptMessageHandlerForControllerWithIdentifier:name:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_name = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api removeScriptMessageHandlerForControllerWithIdentifier:arg_identifier - name:arg_name - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.removeAllScriptMessageHandlers", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (removeAllScriptMessageHandlersForControllerWithIdentifier:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(removeAllScriptMessageHandlersForControllerWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api removeAllScriptMessageHandlersForControllerWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.addUserScript", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(addUserScriptForControllerWithIdentifier: - userScript:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(addUserScriptForControllerWithIdentifier:userScript:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FWFWKUserScriptData *arg_userScript = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api addUserScriptForControllerWithIdentifier:arg_identifier - userScript:arg_userScript - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUserContentControllerHostApi.removeAllUserScripts", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUserContentControllerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (removeAllUserScriptsForControllerWithIdentifier:error:)], - @"FWFWKUserContentControllerHostApi api (%@) doesn't respond to " - @"@selector(removeAllUserScriptsForControllerWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api removeAllUserScriptsForControllerWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFWKPreferencesHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFWKPreferencesHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKPreferencesHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKPreferencesHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKPreferencesHostApi.createFromWebViewConfiguration", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKPreferencesHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(createFromWebViewConfigurationWithIdentifier: - configurationIdentifier:error:)], - @"FWFWKPreferencesHostApi api (%@) doesn't respond to " - @"@selector(createFromWebViewConfigurationWithIdentifier:configurationIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_configurationIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebViewConfigurationWithIdentifier:arg_identifier - configurationIdentifier:arg_configurationIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKPreferencesHostApi.setJavaScriptEnabled", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKPreferencesHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setJavaScriptEnabledForPreferencesWithIdentifier:isEnabled:error:)], - @"FWFWKPreferencesHostApi api (%@) doesn't respond to " - @"@selector(setJavaScriptEnabledForPreferencesWithIdentifier:isEnabled:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_enabled = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setJavaScriptEnabledForPreferencesWithIdentifier:arg_identifier - isEnabled:arg_enabled - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFWKScriptMessageHandlerHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFWKScriptMessageHandlerHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKScriptMessageHandlerHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKScriptMessageHandlerHostApiWithSuffix( - id binaryMessenger, NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKScriptMessageHandlerHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKScriptMessageHandlerHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier:error:)], - @"FWFWKScriptMessageHandlerHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -@interface FWFWKScriptMessageHandlerFlutterApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKScriptMessageHandlerFlutterApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFWKScriptMessageData fromList:[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 toList]]; - } 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(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter *readerWriter = - [[FWFWKScriptMessageHandlerFlutterApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -@interface FWFWKScriptMessageHandlerFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFWKScriptMessageHandlerFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void) - didReceiveScriptMessageForHandlerWithIdentifier:(NSInteger)arg_identifier - userContentControllerIdentifier:(NSInteger)arg_userContentControllerIdentifier - message:(FWFWKScriptMessageData *)arg_message - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKScriptMessageHandlerFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), @(arg_userContentControllerIdentifier), arg_message ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -NSObject *FWFWKNavigationDelegateHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFWKNavigationDelegateHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKNavigationDelegateHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKNavigationDelegateHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKNavigationDelegateHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier:error:)], - @"FWFWKNavigationDelegateHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -@interface FWFWKNavigationDelegateFlutterApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKNavigationDelegateFlutterApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFAuthenticationChallengeResponse fromList:[self readValue]]; - case 129: - return [FWFNSErrorData fromList:[self readValue]]; - case 130: - return [FWFNSHttpUrlResponseData fromList:[self readValue]]; - case 131: - return [FWFNSUrlRequestData fromList:[self readValue]]; - case 132: - return [FWFWKFrameInfoData fromList:[self readValue]]; - case 133: - return [FWFWKNavigationActionData fromList:[self readValue]]; - case 134: - return [FWFWKNavigationActionPolicyEnumData fromList:[self readValue]]; - case 135: - return [FWFWKNavigationResponseData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKNavigationDelegateFlutterApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKNavigationDelegateFlutterApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFAuthenticationChallengeResponse class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSErrorData class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSHttpUrlResponseData class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { - [self writeByte:131]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { - [self writeByte:132]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { - [self writeByte:133]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationActionPolicyEnumData class]]) { - [self writeByte:134]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationResponseData class]]) { - [self writeByte:135]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKNavigationDelegateFlutterApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKNavigationDelegateFlutterApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKNavigationDelegateFlutterApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKNavigationDelegateFlutterApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKNavigationDelegateFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKNavigationDelegateFlutterApiCodecReaderWriter *readerWriter = - [[FWFWKNavigationDelegateFlutterApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -@interface FWFWKNavigationDelegateFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFWKNavigationDelegateFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)didFinishNavigationForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - URL:(nullable NSString *)arg_url - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.didFinishNavigation", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier), arg_url ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)didStartProvisionalNavigationForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - URL:(nullable NSString *)arg_url - completion:(void (^)(FlutterError *_Nullable)) - completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.didStartProvisionalNavigation", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier), arg_url ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)decidePolicyForNavigationActionForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - navigationAction:(FWFWKNavigationActionData *) - arg_navigationAction - completion: - (void (^)( - FWFWKNavigationActionPolicyEnumData - *_Nullable, - FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), @(arg_webViewIdentifier), arg_navigationAction ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FWFWKNavigationActionPolicyEnumData *output = - reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -- (void)decidePolicyForNavigationResponseForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - navigationResponse:(FWFWKNavigationResponseData *) - arg_navigationResponse - completion: - (void (^)( - FWFWKNavigationResponsePolicyEnumBox - *_Nullable, - FlutterError *_Nullable)) - completion { - NSString *channelName = [NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), @(arg_webViewIdentifier), arg_navigationResponse ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSNumber *outputAsNumber = reply[0] == [NSNull null] ? nil : reply[0]; - FWFWKNavigationResponsePolicyEnumBox *output = - outputAsNumber == nil ? nil - : [[FWFWKNavigationResponsePolicyEnumBox alloc] - initWithValue:[outputAsNumber integerValue]]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -- (void)didFailNavigationForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - error:(FWFNSErrorData *)arg_error - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.didFailNavigation", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier), arg_error ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)didFailProvisionalNavigationForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - error:(FWFNSErrorData *)arg_error - completion:(void (^)(FlutterError *_Nullable)) - completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.didFailProvisionalNavigation", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier), arg_error ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)webViewWebContentProcessDidTerminateForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier: - (NSInteger)arg_webViewIdentifier - completion: - (void (^)(FlutterError *_Nullable)) - completion { - NSString *channelName = [NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void) - didReceiveAuthenticationChallengeForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - challengeIdentifier:(NSInteger)arg_challengeIdentifier - completion: - (void (^)(FWFAuthenticationChallengeResponse - *_Nullable, - FlutterError *_Nullable)) - completion { - NSString *channelName = [NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKNavigationDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_webViewIdentifier), @(arg_challengeIdentifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FWFAuthenticationChallengeResponse *output = - reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -@end - -@interface FWFNSObjectHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFNSObjectHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFNSKeyValueObservingOptionsEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFNSObjectHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFNSObjectHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFNSKeyValueObservingOptionsEnumData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFNSObjectHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFNSObjectHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFNSObjectHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFNSObjectHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFNSObjectHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFNSObjectHostApiCodecReaderWriter *readerWriter = - [[FWFNSObjectHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFNSObjectHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFNSObjectHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFNSObjectHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSObjectHostApi.dispose", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFNSObjectHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(disposeObjectWithIdentifier:error:)], - @"FWFNSObjectHostApi api (%@) doesn't respond to " - @"@selector(disposeObjectWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api disposeObjectWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSObjectHostApi.addObserver", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFNSObjectHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (addObserverForObjectWithIdentifier: - observerIdentifier:keyPath:options:error:)], - @"FWFNSObjectHostApi api (%@) doesn't respond to " - @"@selector(addObserverForObjectWithIdentifier:observerIdentifier:keyPath:options:" - @"error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_observerIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - NSString *arg_keyPath = GetNullableObjectAtIndex(args, 2); - NSArray *arg_options = - GetNullableObjectAtIndex(args, 3); - FlutterError *error; - [api addObserverForObjectWithIdentifier:arg_identifier - observerIdentifier:arg_observerIdentifier - keyPath:arg_keyPath - options:arg_options - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSObjectHostApi.removeObserver", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFNSObjectHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(removeObserverForObjectWithIdentifier: - observerIdentifier:keyPath:error:)], - @"FWFNSObjectHostApi api (%@) doesn't respond to " - @"@selector(removeObserverForObjectWithIdentifier:observerIdentifier:keyPath:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_observerIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - NSString *arg_keyPath = GetNullableObjectAtIndex(args, 2); - FlutterError *error; - [api removeObserverForObjectWithIdentifier:arg_identifier - observerIdentifier:arg_observerIdentifier - keyPath:arg_keyPath - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -@interface FWFNSObjectFlutterApiCodecReader : FlutterStandardReader -@end -@implementation FWFNSObjectFlutterApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFNSKeyValueChangeKeyEnumData fromList:[self readValue]]; - case 129: - return [FWFObjectOrIdentifier fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFNSObjectFlutterApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFNSObjectFlutterApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFNSKeyValueChangeKeyEnumData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFObjectOrIdentifier class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFNSObjectFlutterApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFNSObjectFlutterApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFNSObjectFlutterApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFNSObjectFlutterApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFNSObjectFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFNSObjectFlutterApiCodecReaderWriter *readerWriter = - [[FWFNSObjectFlutterApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -@interface FWFNSObjectFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFNSObjectFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)observeValueForObjectWithIdentifier:(NSInteger)arg_identifier - keyPath:(NSString *)arg_keyPath - objectIdentifier:(NSInteger)arg_objectIdentifier - changeKeys: - (NSArray *)arg_changeKeys - changeValues:(NSArray *)arg_changeValues - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat: - @"%@%@", @"dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFNSObjectFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), arg_keyPath ?: [NSNull null], @(arg_objectIdentifier), - arg_changeKeys ?: [NSNull null], arg_changeValues ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)disposeObjectWithIdentifier:(NSInteger)arg_identifier - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.dispose", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFNSObjectFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -@interface FWFWKWebViewHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKWebViewHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFAuthenticationChallengeResponse fromList:[self readValue]]; - case 129: - return [FWFNSErrorData fromList:[self readValue]]; - case 130: - return [FWFNSHttpCookieData fromList:[self readValue]]; - case 131: - return [FWFNSHttpCookiePropertyKeyEnumData fromList:[self readValue]]; - case 132: - return [FWFNSHttpUrlResponseData fromList:[self readValue]]; - case 133: - return [FWFNSKeyValueChangeKeyEnumData fromList:[self readValue]]; - case 134: - return [FWFNSKeyValueObservingOptionsEnumData fromList:[self readValue]]; - case 135: - return [FWFNSUrlRequestData fromList:[self readValue]]; - case 136: - return [FWFObjectOrIdentifier fromList:[self readValue]]; - case 137: - return [FWFWKAudiovisualMediaTypeEnumData fromList:[self readValue]]; - case 138: - return [FWFWKFrameInfoData fromList:[self readValue]]; - case 139: - return [FWFWKMediaCaptureTypeData fromList:[self readValue]]; - case 140: - return [FWFWKNavigationActionData fromList:[self readValue]]; - case 141: - return [FWFWKNavigationActionPolicyEnumData fromList:[self readValue]]; - case 142: - return [FWFWKNavigationResponseData fromList:[self readValue]]; - case 143: - return [FWFWKPermissionDecisionData fromList:[self readValue]]; - case 144: - return [FWFWKScriptMessageData fromList:[self readValue]]; - case 145: - return [FWFWKSecurityOriginData fromList:[self readValue]]; - case 146: - return [FWFWKUserScriptData fromList:[self readValue]]; - case 147: - return [FWFWKUserScriptInjectionTimeEnumData fromList:[self readValue]]; - case 148: - return [FWFWKWebsiteDataTypeEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKWebViewHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKWebViewHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFAuthenticationChallengeResponse class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSErrorData class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSHttpCookieData class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSHttpCookiePropertyKeyEnumData class]]) { - [self writeByte:131]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSHttpUrlResponseData class]]) { - [self writeByte:132]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSKeyValueChangeKeyEnumData class]]) { - [self writeByte:133]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSKeyValueObservingOptionsEnumData class]]) { - [self writeByte:134]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSUrlRequestData class]]) { - [self writeByte:135]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFObjectOrIdentifier class]]) { - [self writeByte:136]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKAudiovisualMediaTypeEnumData class]]) { - [self writeByte:137]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { - [self writeByte:138]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKMediaCaptureTypeData class]]) { - [self writeByte:139]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { - [self writeByte:140]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationActionPolicyEnumData class]]) { - [self writeByte:141]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationResponseData class]]) { - [self writeByte:142]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKPermissionDecisionData class]]) { - [self writeByte:143]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKScriptMessageData class]]) { - [self writeByte:144]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKSecurityOriginData class]]) { - [self writeByte:145]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKUserScriptData class]]) { - [self writeByte:146]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKUserScriptInjectionTimeEnumData class]]) { - [self writeByte:147]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKWebsiteDataTypeEnumData class]]) { - [self writeByte:148]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKWebViewHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKWebViewHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKWebViewHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKWebViewHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKWebViewHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKWebViewHostApiCodecReaderWriter *readerWriter = - [[FWFWKWebViewHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFWKWebViewHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKWebViewHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKWebViewHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier: - configurationIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:configurationIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_configurationIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier - configurationIdentifier:arg_configurationIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.setUIDelegate", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setUIDelegateForWebViewWithIdentifier: - delegateIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(setUIDelegateForWebViewWithIdentifier:delegateIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSNumber *arg_uiDelegateIdentifier = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setUIDelegateForWebViewWithIdentifier:arg_identifier - delegateIdentifier:arg_uiDelegateIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.setNavigationDelegate", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(setNavigationDelegateForWebViewWithIdentifier: - delegateIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(setNavigationDelegateForWebViewWithIdentifier:delegateIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSNumber *arg_navigationDelegateIdentifier = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setNavigationDelegateForWebViewWithIdentifier:arg_identifier - delegateIdentifier:arg_navigationDelegateIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.getUrl", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(URLForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(URLForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSString *output = [api URLForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.getEstimatedProgress", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(estimatedProgressForWebViewWithIdentifier: - error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(estimatedProgressForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSNumber *output = [api estimatedProgressForWebViewWithIdentifier:arg_identifier - error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.loadRequest", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(loadRequestForWebViewWithIdentifier: - request:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(loadRequestForWebViewWithIdentifier:request:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FWFNSUrlRequestData *arg_request = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api loadRequestForWebViewWithIdentifier:arg_identifier request:arg_request error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.loadHtmlString", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(loadHTMLForWebViewWithIdentifier: - HTMLString:baseURL:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(loadHTMLForWebViewWithIdentifier:HTMLString:baseURL:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_string = GetNullableObjectAtIndex(args, 1); - NSString *arg_baseUrl = GetNullableObjectAtIndex(args, 2); - FlutterError *error; - [api loadHTMLForWebViewWithIdentifier:arg_identifier - HTMLString:arg_string - baseURL:arg_baseUrl - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.loadFileUrl", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (loadFileForWebViewWithIdentifier:fileURL:readAccessURL:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(loadFileForWebViewWithIdentifier:fileURL:readAccessURL:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_url = GetNullableObjectAtIndex(args, 1); - NSString *arg_readAccessUrl = GetNullableObjectAtIndex(args, 2); - FlutterError *error; - [api loadFileForWebViewWithIdentifier:arg_identifier - fileURL:arg_url - readAccessURL:arg_readAccessUrl - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.loadFlutterAsset", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(loadAssetForWebViewWithIdentifier: - assetKey:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(loadAssetForWebViewWithIdentifier:assetKey:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_key = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api loadAssetForWebViewWithIdentifier:arg_identifier assetKey:arg_key error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.canGoBack", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(canGoBackForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(canGoBackForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSNumber *output = [api canGoBackForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.canGoForward", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(canGoForwardForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(canGoForwardForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSNumber *output = [api canGoForwardForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.goBack", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(goBackForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(goBackForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api goBackForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.goForward", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(goForwardForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(goForwardForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api goForwardForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.reload", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(reloadWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(reloadWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api reloadWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.getTitle", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(titleForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(titleForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSString *output = [api titleForWebViewWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.setAllowsBackForwardNavigationGestures", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setAllowsBackForwardForWebViewWithIdentifier:isAllowed:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(setAllowsBackForwardForWebViewWithIdentifier:isAllowed:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_allow = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setAllowsBackForwardForWebViewWithIdentifier:arg_identifier - isAllowed:arg_allow - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.setCustomUserAgent", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setCustomUserAgentForWebViewWithIdentifier:userAgent:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(setCustomUserAgentForWebViewWithIdentifier:userAgent:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_userAgent = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - [api setCustomUserAgentForWebViewWithIdentifier:arg_identifier - userAgent:arg_userAgent - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.evaluateJavaScript", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector - (evaluateJavaScriptForWebViewWithIdentifier:javaScriptString:completion:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(evaluateJavaScriptForWebViewWithIdentifier:javaScriptString:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_javaScriptString = GetNullableObjectAtIndex(args, 1); - [api evaluateJavaScriptForWebViewWithIdentifier:arg_identifier - javaScriptString:arg_javaScriptString - completion:^(id _Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.setInspectable", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setInspectableForWebViewWithIdentifier: - inspectable:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(setInspectableForWebViewWithIdentifier:inspectable:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - BOOL arg_inspectable = [GetNullableObjectAtIndex(args, 1) boolValue]; - FlutterError *error; - [api setInspectableForWebViewWithIdentifier:arg_identifier - inspectable:arg_inspectable - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKWebViewHostApi.getCustomUserAgent", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKWebViewHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(customUserAgentForWebViewWithIdentifier:error:)], - @"FWFWKWebViewHostApi api (%@) doesn't respond to " - @"@selector(customUserAgentForWebViewWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSString *output = [api customUserAgentForWebViewWithIdentifier:arg_identifier - error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFWKUIDelegateHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFWKUIDelegateHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKUIDelegateHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKUIDelegateHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUIDelegateHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKUIDelegateHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier:error:)], - @"FWFWKUIDelegateHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -@interface FWFWKUIDelegateFlutterApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKUIDelegateFlutterApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFNSUrlRequestData fromList:[self readValue]]; - case 129: - return [FWFWKFrameInfoData fromList:[self readValue]]; - case 130: - return [FWFWKMediaCaptureTypeData fromList:[self readValue]]; - case 131: - return [FWFWKNavigationActionData fromList:[self readValue]]; - case 132: - return [FWFWKPermissionDecisionData fromList:[self readValue]]; - case 133: - return [FWFWKSecurityOriginData fromList:[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 toList]]; - } else if ([value isKindOfClass:[FWFWKFrameInfoData class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKMediaCaptureTypeData class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKNavigationActionData class]]) { - [self writeByte:131]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKPermissionDecisionData class]]) { - [self writeByte:132]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFWKSecurityOriginData class]]) { - [self writeByte:133]; - [self writeValue:[value toList]]; - } 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(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKUIDelegateFlutterApiCodecReaderWriter *readerWriter = - [[FWFWKUIDelegateFlutterApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -@interface FWFWKUIDelegateFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFWKUIDelegateFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)onCreateWebViewForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - configurationIdentifier:(NSInteger)arg_configurationIdentifier - navigationAction:(FWFWKNavigationActionData *)arg_navigationAction - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKUIDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), @(arg_webViewIdentifier), @(arg_configurationIdentifier), - arg_navigationAction ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)requestMediaCapturePermissionForDelegateWithIdentifier:(NSInteger)arg_identifier - webViewIdentifier:(NSInteger)arg_webViewIdentifier - origin:(FWFWKSecurityOriginData *)arg_origin - frame:(FWFWKFrameInfoData *)arg_frame - type:(FWFWKMediaCaptureTypeData *)arg_type - completion: - (void (^)( - FWFWKPermissionDecisionData *_Nullable, - FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUIDelegateFlutterApi.requestMediaCapturePermission", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKUIDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), @(arg_webViewIdentifier), arg_origin ?: [NSNull null], - arg_frame ?: [NSNull null], arg_type ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FWFWKPermissionDecisionData *output = - reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -- (void)runJavaScriptAlertPanelForDelegateWithIdentifier:(NSInteger)arg_identifier - message:(NSString *)arg_message - frame:(FWFWKFrameInfoData *)arg_frame - completion: - (void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUIDelegateFlutterApi.runJavaScriptAlertPanel", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKUIDelegateFlutterApiGetCodec()]; - [channel - sendMessage:@[ @(arg_identifier), arg_message ?: [NSNull null], arg_frame ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -- (void)runJavaScriptConfirmPanelForDelegateWithIdentifier:(NSInteger)arg_identifier - message:(NSString *)arg_message - frame:(FWFWKFrameInfoData *)arg_frame - completion: - (void (^)(NSNumber *_Nullable, - FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUIDelegateFlutterApi.runJavaScriptConfirmPanel", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKUIDelegateFlutterApiGetCodec()]; - [channel - sendMessage:@[ @(arg_identifier), arg_message ?: [NSNull null], arg_frame ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSNumber *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -- (void)runJavaScriptTextInputPanelForDelegateWithIdentifier:(NSInteger)arg_identifier - prompt:(NSString *)arg_prompt - defaultText:(NSString *)arg_defaultText - frame:(FWFWKFrameInfoData *)arg_frame - completion:(void (^)(NSString *_Nullable, - FlutterError *_Nullable)) - completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKUIDelegateFlutterApi.runJavaScriptTextInputPanel", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFWKUIDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), arg_prompt ?: [NSNull null], arg_defaultText ?: [NSNull null], - arg_frame ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSString *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, createConnectionError(channelName)); - } - }]; -} -@end - -@interface FWFWKHttpCookieStoreHostApiCodecReader : FlutterStandardReader -@end -@implementation FWFWKHttpCookieStoreHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FWFNSHttpCookieData fromList:[self readValue]]; - case 129: - return [FWFNSHttpCookiePropertyKeyEnumData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FWFWKHttpCookieStoreHostApiCodecWriter : FlutterStandardWriter -@end -@implementation FWFWKHttpCookieStoreHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FWFNSHttpCookieData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[FWFNSHttpCookiePropertyKeyEnumData class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FWFWKHttpCookieStoreHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FWFWKHttpCookieStoreHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FWFWKHttpCookieStoreHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FWFWKHttpCookieStoreHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FWFWKHttpCookieStoreHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FWFWKHttpCookieStoreHostApiCodecReaderWriter *readerWriter = - [[FWFWKHttpCookieStoreHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void SetUpFWFWKHttpCookieStoreHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFWKHttpCookieStoreHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFWKHttpCookieStoreHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKHttpCookieStoreHostApi.createFromWebsiteDataStore", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKHttpCookieStoreHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createFromWebsiteDataStoreWithIdentifier: - dataStoreIdentifier:error:)], - @"FWFWKHttpCookieStoreHostApi api (%@) doesn't respond to " - @"@selector(createFromWebsiteDataStoreWithIdentifier:dataStoreIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSInteger arg_websiteDataStoreIdentifier = [GetNullableObjectAtIndex(args, 1) integerValue]; - FlutterError *error; - [api createFromWebsiteDataStoreWithIdentifier:arg_identifier - dataStoreIdentifier:arg_websiteDataStoreIdentifier - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"WKHttpCookieStoreHostApi.setCookie", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFWKHttpCookieStoreHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(setCookieForStoreWithIdentifier: - cookie:completion:)], - @"FWFWKHttpCookieStoreHostApi api (%@) doesn't respond to " - @"@selector(setCookieForStoreWithIdentifier:cookie:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FWFNSHttpCookieData *arg_cookie = GetNullableObjectAtIndex(args, 1); - [api setCookieForStoreWithIdentifier:arg_identifier - cookie:arg_cookie - completion:^(FlutterError *_Nullable error) { - callback(wrapResult(nil, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFNSUrlHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFNSUrlHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFNSUrlHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFNSUrlHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSUrlHostApi.getAbsoluteString", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFNSUrlHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(absoluteStringForNSURLWithIdentifier:error:)], - @"FWFNSUrlHostApi api (%@) doesn't respond to " - @"@selector(absoluteStringForNSURLWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - NSString *output = [api absoluteStringForNSURLWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFNSUrlFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -@interface FWFNSUrlFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFNSUrlFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)createWithIdentifier:(NSInteger)arg_identifier - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlFlutterApi.create", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFNSUrlFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -NSObject *FWFUIScrollViewDelegateHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFUIScrollViewDelegateHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFUIScrollViewDelegateHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFUIScrollViewDelegateHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewDelegateHostApi.create", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFUIScrollViewDelegateHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(createWithIdentifier:error:)], - @"FWFUIScrollViewDelegateHostApi api (%@) doesn't respond to " - @"@selector(createWithIdentifier:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - FlutterError *error; - [api createWithIdentifier:arg_identifier error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFUIScrollViewDelegateFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -@interface FWFUIScrollViewDelegateFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFUIScrollViewDelegateFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)scrollViewDidScrollWithIdentifier:(NSInteger)arg_identifier - UIScrollViewIdentifier:(NSInteger)arg_uiScrollViewIdentifier - x:(double)arg_x - y:(double)arg_y - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"UIScrollViewDelegateFlutterApi.scrollViewDidScroll", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFUIScrollViewDelegateFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_uiScrollViewIdentifier), @(arg_x), @(arg_y) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -NSObject *FWFNSUrlCredentialHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -void SetUpFWFNSUrlCredentialHostApi(id binaryMessenger, - NSObject *api) { - SetUpFWFNSUrlCredentialHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFWFNSUrlCredentialHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - /// Create a new native instance and add it to the `InstanceManager`. - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSUrlCredentialHostApi.createWithUser", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:FWFNSUrlCredentialHostApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (createWithUserWithIdentifier:user:password:persistence:error:)], - @"FWFNSUrlCredentialHostApi api (%@) doesn't respond to " - @"@selector(createWithUserWithIdentifier:user:password:persistence:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSInteger arg_identifier = [GetNullableObjectAtIndex(args, 0) integerValue]; - NSString *arg_user = GetNullableObjectAtIndex(args, 1); - NSString *arg_password = GetNullableObjectAtIndex(args, 2); - FWFNSUrlCredentialPersistence arg_persistence = - [GetNullableObjectAtIndex(args, 3) integerValue]; - FlutterError *error; - [api createWithUserWithIdentifier:arg_identifier - user:arg_user - password:arg_password - persistence:arg_persistence - error:&error]; - callback(wrapResult(nil, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -NSObject *FWFNSUrlProtectionSpaceFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -@interface FWFNSUrlProtectionSpaceFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFNSUrlProtectionSpaceFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)createWithIdentifier:(NSInteger)arg_identifier - host:(nullable NSString *)arg_host - realm:(nullable NSString *)arg_realm - authenticationMethod:(nullable NSString *)arg_authenticationMethod - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = [NSString - stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlProtectionSpaceFlutterApi.create", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFNSUrlProtectionSpaceFlutterApiGetCodec()]; - [channel sendMessage:@[ - @(arg_identifier), arg_host ?: [NSNull null], arg_realm ?: [NSNull null], - arg_authenticationMethod ?: [NSNull null] - ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end - -NSObject *FWFNSUrlAuthenticationChallengeFlutterApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - sSharedObject = [FlutterStandardMessageCodec sharedInstance]; - return sSharedObject; -} - -@interface FWFNSUrlAuthenticationChallengeFlutterApi () -@property(nonatomic, strong) NSObject *binaryMessenger; -@property(nonatomic, strong) NSString *messageChannelSuffix; -@end - -@implementation FWFNSUrlAuthenticationChallengeFlutterApi - -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; -} -- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _messageChannelSuffix = [messageChannelSuffix length] == 0 - ? @"" - : [NSString stringWithFormat:@".%@", messageChannelSuffix]; - } - return self; -} -- (void)createWithIdentifier:(NSInteger)arg_identifier - protectionSpaceIdentifier:(NSInteger)arg_protectionSpaceIdentifier - completion:(void (^)(FlutterError *_Nullable))completion { - NSString *channelName = - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.webview_flutter_wkwebview." - @"NSUrlAuthenticationChallengeFlutterApi.create", - _messageChannelSuffix]; - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:channelName - binaryMessenger:self.binaryMessenger - codec:FWFNSUrlAuthenticationChallengeFlutterApiGetCodec()]; - [channel sendMessage:@[ @(arg_identifier), @(arg_protectionSpaceIdentifier) ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion(createConnectionError(channelName)); - } - }]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.m deleted file mode 100644 index a2eb675286ac..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.m +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h" - -@interface FWFHTTPCookieStoreHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFHTTPCookieStoreHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (WKHTTPCookieStore *)HTTPCookieStoreForIdentifier:(NSInteger)identifier { - return (WKHTTPCookieStore *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createFromWebsiteDataStoreWithIdentifier:(NSInteger)identifier - dataStoreIdentifier:(NSInteger)websiteDataStoreIdentifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - WKWebsiteDataStore *dataStore = - (WKWebsiteDataStore *)[self.instanceManager instanceForIdentifier:websiteDataStoreIdentifier]; - [self.instanceManager addDartCreatedInstance:dataStore.httpCookieStore withIdentifier:identifier]; -} - -- (void)setCookieForStoreWithIdentifier:(NSInteger)identifier - cookie:(nonnull FWFNSHttpCookieData *)cookie - completion:(nonnull void (^)(FlutterError *_Nullable))completion { - NSHTTPCookie *nsCookie = FWFNativeNSHTTPCookieFromCookieData(cookie); - - [[self HTTPCookieStoreForIdentifier:identifier] setCookie:nsCookie - completionHandler:^{ - completion(nil); - }]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFInstanceManager.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFInstanceManager.m deleted file mode 100644 index 26182be6391a..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFInstanceManager.m +++ /dev/null @@ -1,173 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFInstanceManager.h" -#import "./include/webview_flutter_wkwebview/FWFInstanceManager_Test.h" - -#import - -// Attaches to an object to receive a callback when the object is deallocated. -@interface FWFFinalizer : NSObject -@end - -// Attaches to an object to receive a callback when the object is deallocated. -@implementation FWFFinalizer { - long _identifier; - // Callbacks are no longer made once FWFInstanceManager is inaccessible. - FWFOnDeallocCallback __weak _callback; -} - -- (instancetype)initWithIdentifier:(long)identifier callback:(FWFOnDeallocCallback)callback { - self = [self init]; - if (self) { - _identifier = identifier; - _callback = callback; - } - return self; -} - -+ (void)attachToInstance:(NSObject *)instance - withIdentifier:(long)identifier - callback:(FWFOnDeallocCallback)callback { - FWFFinalizer *finalizer = [[FWFFinalizer alloc] initWithIdentifier:identifier callback:callback]; - objc_setAssociatedObject(instance, _cmd, finalizer, OBJC_ASSOCIATION_RETAIN); -} - -+ (void)detachFromInstance:(NSObject *)instance { - objc_setAssociatedObject(instance, @selector(attachToInstance:withIdentifier:callback:), nil, - OBJC_ASSOCIATION_ASSIGN); -} - -- (void)dealloc { - if (_callback) { - _callback(_identifier); - } -} -@end - -@interface FWFInstanceManager () -@property dispatch_queue_t lockQueue; -@property NSMapTable *identifiers; -@property NSMapTable *weakInstances; -@property NSMapTable *strongInstances; -@end - -@implementation FWFInstanceManager -// Identifiers are locked to a specific range to avoid collisions with objects -// created simultaneously from Dart. -// Host uses identifiers >= 2^16 and Dart is expected to use values n where, -// 0 <= n < 2^16. -static long const FWFMinHostCreatedIdentifier = 65536; - -- (instancetype)init { - self = [super init]; - if (self) { - _deallocCallback = _deallocCallback ? _deallocCallback : ^(long identifier) { - }; - _lockQueue = dispatch_queue_create("FWFInstanceManager", DISPATCH_QUEUE_SERIAL); - // Pointer equality is used to prevent collisions of objects that override the `isEqualTo:` - // method. - _identifiers = - [NSMapTable mapTableWithKeyOptions:NSMapTableWeakMemory | NSMapTableObjectPointerPersonality - valueOptions:NSMapTableStrongMemory]; - _weakInstances = [NSMapTable - mapTableWithKeyOptions:NSMapTableStrongMemory - valueOptions:NSMapTableWeakMemory | NSMapTableObjectPointerPersonality]; - _strongInstances = [NSMapTable - mapTableWithKeyOptions:NSMapTableStrongMemory - valueOptions:NSMapTableStrongMemory | NSMapTableObjectPointerPersonality]; - _nextIdentifier = FWFMinHostCreatedIdentifier; - } - return self; -} - -- (instancetype)initWithDeallocCallback:(FWFOnDeallocCallback)callback { - self = [self init]; - if (self) { - _deallocCallback = callback; - } - return self; -} - -- (void)addDartCreatedInstance:(NSObject *)instance withIdentifier:(long)instanceIdentifier { - NSParameterAssert(instance); - NSParameterAssert(instanceIdentifier >= 0); - dispatch_async(_lockQueue, ^{ - [self addInstance:instance withIdentifier:instanceIdentifier]; - }); -} - -- (long)addHostCreatedInstance:(nonnull NSObject *)instance { - NSParameterAssert(instance); - long __block identifier = -1; - dispatch_sync(_lockQueue, ^{ - identifier = self.nextIdentifier++; - [self addInstance:instance withIdentifier:identifier]; - }); - return identifier; -} - -- (nullable NSObject *)removeInstanceWithIdentifier:(long)instanceIdentifier { - NSObject *__block instance = nil; - dispatch_sync(_lockQueue, ^{ - instance = [self.strongInstances objectForKey:@(instanceIdentifier)]; - if (instance) { - [self.strongInstances removeObjectForKey:@(instanceIdentifier)]; - } - }); - return instance; -} - -- (nullable NSObject *)instanceForIdentifier:(long)instanceIdentifier { - NSObject *__block instance = nil; - dispatch_sync(_lockQueue, ^{ - instance = [self.weakInstances objectForKey:@(instanceIdentifier)]; - }); - return instance; -} - -- (void)addInstance:(nonnull NSObject *)instance withIdentifier:(long)instanceIdentifier { - [self.identifiers setObject:@(instanceIdentifier) forKey:instance]; - [self.weakInstances setObject:instance forKey:@(instanceIdentifier)]; - [self.strongInstances setObject:instance forKey:@(instanceIdentifier)]; - [FWFFinalizer attachToInstance:instance - withIdentifier:instanceIdentifier - callback:self.deallocCallback]; -} - -- (long)identifierWithStrongReferenceForInstance:(nonnull NSObject *)instance { - NSNumber *__block identifierNumber = nil; - dispatch_sync(_lockQueue, ^{ - identifierNumber = [self.identifiers objectForKey:instance]; - if (identifierNumber != nil) { - [self.strongInstances setObject:instance forKey:identifierNumber]; - } - }); - return identifierNumber != nil ? identifierNumber.longValue : NSNotFound; -} - -- (BOOL)containsInstance:(nonnull NSObject *)instance { - BOOL __block containsInstance; - dispatch_sync(_lockQueue, ^{ - containsInstance = [self.identifiers objectForKey:instance] != nil; - }); - return containsInstance; -} - -- (NSUInteger)strongInstanceCount { - NSUInteger __block count = -1; - dispatch_sync(_lockQueue, ^{ - count = self.strongInstances.count; - }); - return count; -} - -- (NSUInteger)weakInstanceCount { - NSUInteger __block count = -1; - dispatch_sync(_lockQueue, ^{ - count = self.weakInstances.count; - }); - return count; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.m deleted file mode 100644 index d862de226207..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.m +++ /dev/null @@ -1,327 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" - -@interface FWFNavigationDelegateFlutterApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFNavigationDelegateFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithBinaryMessenger:binaryMessenger]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (long)identifierForDelegate:(FWFNavigationDelegate *)instance { - return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; -} - -- (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - URL:(NSString *)URL - completion:(void (^)(FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - [self didFinishNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - URL:URL - completion:completion]; -} - -- (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - URL:(NSString *)URL - completion:(void (^)(FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - [self didStartProvisionalNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - URL:URL - completion:completion]; -} - -- (void) - decidePolicyForNavigationActionForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - navigationAction:(WKNavigationAction *)navigationAction - completion: - (void (^)(FWFWKNavigationActionPolicyEnumData *_Nullable, - FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - FWFWKNavigationActionData *navigationActionData = - FWFWKNavigationActionDataFromNativeWKNavigationAction(navigationAction); - [self - decidePolicyForNavigationActionForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - navigationAction:navigationActionData - completion:completion]; -} - -- (void)decidePolicyForNavigationResponseForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - navigationResponse:(WKNavigationResponse *)navigationResponse - completion: - (void (^)(FWFWKNavigationResponsePolicyEnumBox *, - FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - FWFWKNavigationResponseData *navigationResponseData = - FWFWKNavigationResponseDataFromNativeNavigationResponse(navigationResponse); - [self - decidePolicyForNavigationResponseForDelegateWithIdentifier:[self - identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - navigationResponse:navigationResponseData - completion:completion]; -} - -- (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - error:(NSError *)error - completion:(void (^)(FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - [self didFailNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - error:FWFNSErrorDataFromNativeNSError(error) - completion:completion]; -} - -- (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - error:(NSError *)error - completion:(void (^)(FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - [self didFailProvisionalNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - error:FWFNSErrorDataFromNativeNSError(error) - completion:completion]; -} - -- (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - completion: - (void (^)(FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier: - [self identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - completion:completion]; -} - -- (void) - didReceiveAuthenticationChallengeForDelegate:(FWFNavigationDelegate *)instance - webView:(WKWebView *)webView - challenge:(NSURLAuthenticationChallenge *)challenge - completion: - (void (^)(FWFAuthenticationChallengeResponse *_Nullable, - FlutterError *_Nullable))completion { - NSInteger webViewIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:webView]; - - FWFURLAuthenticationChallengeFlutterApiImpl *challengeApi = - [[FWFURLAuthenticationChallengeFlutterApiImpl alloc] - initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [challengeApi createWithInstance:challenge - protectionSpace:challenge.protectionSpace - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - - [self - didReceiveAuthenticationChallengeForDelegateWithIdentifier:[self - identifierForDelegate:instance] - webViewIdentifier:webViewIdentifier - challengeIdentifier: - [self.instanceManager - identifierWithStrongReferenceForInstance: - challenge] - completion:completion]; -} -@end - -@implementation FWFNavigationDelegate -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; - if (self) { - _navigationDelegateAPI = - [[FWFNavigationDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; - } - return self; -} - -- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { - [self.navigationDelegateAPI didFinishNavigationForDelegate:self - webView:webView - URL:webView.URL.absoluteString - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { - [self.navigationDelegateAPI didStartProvisionalNavigationForDelegate:self - webView:webView - URL:webView.URL.absoluteString - completion:^(FlutterError *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, - FlutterError *error) { - NSAssert(!error, @"%@", error); - if (!error) { - decisionHandler( - FWFNativeWKNavigationActionPolicyFromEnumData( - policy)); - } else { - decisionHandler(WKNavigationActionPolicyCancel); - } - }]; -} - -- (void)webView:(WKWebView *)webView - decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse - decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler { - [self.navigationDelegateAPI - decidePolicyForNavigationResponseForDelegate:self - webView:webView - navigationResponse:navigationResponse - completion:^(FWFWKNavigationResponsePolicyEnumBox *policy, - FlutterError *error) { - NSAssert(!error, @"%@", error); - if (!error) { - decisionHandler( - FWFNativeWKNavigationResponsePolicyFromEnum( - policy.value)); - } else { - decisionHandler(WKNavigationResponsePolicyCancel); - } - }]; -} - -- (void)webView:(WKWebView *)webView - didFailNavigation:(WKNavigation *)navigation - withError:(NSError *)error { - [self.navigationDelegateAPI didFailNavigationForDelegate:self - webView:webView - error:error - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webView:(WKWebView *)webView - didFailProvisionalNavigation:(WKNavigation *)navigation - withError:(NSError *)error { - [self.navigationDelegateAPI didFailProvisionalNavigationForDelegate:self - webView:webView - error:error - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { - [self.navigationDelegateAPI - webViewWebContentProcessDidTerminateForDelegate:self - webView:webView - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -- (void)webView:(WKWebView *)webView - didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge - completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, - NSURLCredential *_Nullable))completionHandler { - [self.navigationDelegateAPI - didReceiveAuthenticationChallengeForDelegate:self - webView:webView - challenge:challenge - completion:^(FWFAuthenticationChallengeResponse *response, - FlutterError *error) { - NSAssert(!error, @"%@", error); - if (!error) { - NSURLSessionAuthChallengeDisposition disposition = - FWFNativeNSURLSessionAuthChallengeDispositionFromFWFNSUrlSessionAuthChallengeDisposition( - response.disposition); - - NSURLCredential *credential = - response.credentialIdentifier != nil - ? (NSURLCredential *)[self.navigationDelegateAPI - .instanceManager - instanceForIdentifier: - response.credentialIdentifier - .longValue] - : nil; - - completionHandler(disposition, credential); - } else { - completionHandler( - NSURLSessionAuthChallengeCancelAuthenticationChallenge, - nil); - } - }]; -} -@end - -@interface FWFNavigationDelegateHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFNavigationDelegateHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (FWFNavigationDelegate *)navigationDelegateForIdentifier:(NSInteger)identifier { - return (FWFNavigationDelegate *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - FWFNavigationDelegate *navigationDelegate = - [[FWFNavigationDelegate alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:identifier]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFObjectHostApi.m deleted file mode 100644 index 81e26a2f7d80..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFObjectHostApi.m +++ /dev/null @@ -1,147 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFObjectHostApi.h" -#import -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFURLHostApi.h" - -@interface FWFObjectFlutterApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFObjectFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithBinaryMessenger:binaryMessenger]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - 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 (^)(FlutterError *_Nullable))completion { - NSMutableArray *changeKeys = [NSMutableArray array]; - NSMutableArray *changeValues = [NSMutableArray array]; - - [change enumerateKeysAndObjectsUsingBlock:^(NSKeyValueChangeKey key, id value, BOOL *stop) { - [changeKeys addObject:FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey(key)]; - BOOL isIdentifier = NO; - if ([self.instanceManager containsInstance:value]) { - isIdentifier = YES; - } else if (object_getClass(value) == [NSURL class]) { - FWFURLFlutterApiImpl *flutterApi = - [[FWFURLFlutterApiImpl alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [flutterApi create:value - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - isIdentifier = YES; - } - - id returnValue = isIdentifier - ? @([self.instanceManager identifierWithStrongReferenceForInstance:value]) - : value; - [changeValues addObject:[FWFObjectOrIdentifier makeWithValue:returnValue - isIdentifier:isIdentifier]]; - }]; - - NSInteger objectIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:object]; - [self observeValueForObjectWithIdentifier:[self identifierForObject:instance] - keyPath:keyPath - objectIdentifier:objectIdentifier - changeKeys:changeKeys - changeValues:changeValues - completion:completion]; -} -@end - -@implementation FWFObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - 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:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} -@end - -@interface FWFObjectHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFObjectHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (NSObject *)objectForIdentifier:(NSInteger)identifier { - return (NSObject *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)addObserverForObjectWithIdentifier:(NSInteger)identifier - observerIdentifier:(NSInteger)observer - keyPath:(nonnull NSString *)keyPath - options: - (nonnull NSArray *) - options - error:(FlutterError *_Nullable *_Nonnull)error { - NSKeyValueObservingOptions optionsInt = 0; - for (FWFNSKeyValueObservingOptionsEnumData *data in options) { - optionsInt |= FWFNativeNSKeyValueObservingOptionsFromEnumData(data); - } - [[self objectForIdentifier:identifier] addObserver:[self objectForIdentifier:observer] - forKeyPath:keyPath - options:optionsInt - context:nil]; -} - -- (void)removeObserverForObjectWithIdentifier:(NSInteger)identifier - observerIdentifier:(NSInteger)observer - keyPath:(nonnull NSString *)keyPath - error:(FlutterError *_Nullable *_Nonnull)error { - [[self objectForIdentifier:identifier] removeObserver:[self objectForIdentifier:observer] - forKeyPath:keyPath]; -} - -- (void)disposeObjectWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error { - [self.instanceManager removeInstanceWithIdentifier:identifier]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFPreferencesHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFPreferencesHostApi.m deleted file mode 100644 index b2b442b3ffac..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFPreferencesHostApi.m +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFPreferencesHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" - -@interface FWFPreferencesHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFPreferencesHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (WKPreferences *)preferencesForIdentifier:(NSInteger)identifier { - return (WKPreferences *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error { - WKPreferences *preferences = [[WKPreferences alloc] init]; - [self.instanceManager addDartCreatedInstance:preferences withIdentifier:identifier]; -} - -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error { - WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager - instanceForIdentifier:configurationIdentifier]; - [self.instanceManager addDartCreatedInstance:configuration.preferences withIdentifier:identifier]; -} - -- (void)setJavaScriptEnabledForPreferencesWithIdentifier:(NSInteger)identifier - isEnabled:(BOOL)enabled - error:(FlutterError *_Nullable *_Nonnull)error { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - // TODO(stuartmorgan): Replace with new API. See https://github.com/flutter/flutter/issues/125901 - [[self preferencesForIdentifier:identifier] setJavaScriptEnabled:enabled]; -#pragma clang diagnostic pop -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.m deleted file mode 100644 index 2b44e5e397f5..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.m +++ /dev/null @@ -1,94 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" - -@interface FWFScriptMessageHandlerFlutterApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object 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 (^)(FlutterError *_Nullable))completion { - NSInteger userContentControllerIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:userContentController]; - FWFWKScriptMessageData *messageData = FWFWKScriptMessageDataFromNativeWKScriptMessage(message); - [self didReceiveScriptMessageForHandlerWithIdentifier:[self identifierForHandler:instance] - userContentControllerIdentifier:userContentControllerIdentifier - message:messageData - 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:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} -@end - -@interface FWFScriptMessageHandlerHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFScriptMessageHandlerHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (FWFScriptMessageHandler *)scriptMessageHandlerForIdentifier:(NSNumber *)identifier { - return (FWFScriptMessageHandler *)[self.instanceManager - instanceForIdentifier:identifier.longValue]; -} - -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFScriptMessageHandler *scriptMessageHandler = - [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:scriptMessageHandler withIdentifier:identifier]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.m deleted file mode 100644 index ec5e55587dc3..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.m +++ /dev/null @@ -1,97 +0,0 @@ -// 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. - -// Using directory structure to remove platform-specific files doesn't work -// well with umbrella headers and module maps, so just no-op the file for -// other platforms instead. -#if TARGET_OS_IOS - -#import "./include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewHostApi.h" - -@interface FWFScrollViewDelegateFlutterApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFScrollViewDelegateFlutterApiImpl - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithBinaryMessenger:binaryMessenger]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} -- (long)identifierForDelegate:(FWFScrollViewDelegate *)instance { - return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; -} - -- (void)scrollViewDidScrollForDelegate:(FWFScrollViewDelegate *)instance - uiScrollView:(UIScrollView *)scrollView - completion:(void (^)(FlutterError *_Nullable))completion { - [self scrollViewDidScrollWithIdentifier:[self identifierForDelegate:instance] - UIScrollViewIdentifier:[self.instanceManager - identifierWithStrongReferenceForInstance:scrollView] - x:scrollView.contentOffset.x - y:scrollView.contentOffset.y - completion:completion]; -} -@end - -@implementation FWFScrollViewDelegate - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager]; - if (self) { - _scrollViewDelegateAPI = - [[FWFScrollViewDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; - } - return self; -} - -- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - [self.scrollViewDelegateAPI scrollViewDidScrollForDelegate:self - uiScrollView:scrollView - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} -@end - -@interface FWFScrollViewDelegateHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFScrollViewDelegateHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFScrollViewDelegate *uiScrollViewDelegate = - [[FWFScrollViewDelegate alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:uiScrollViewDelegate withIdentifier:identifier]; -} -@end - -#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewHostApi.m deleted file mode 100644 index b57ba2a539a4..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFScrollViewHostApi.m +++ /dev/null @@ -1,88 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFScrollViewHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewHostApi.h" - -@interface FWFScrollViewHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; - -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFScrollViewHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -#if TARGET_OS_IOS -- (UIScrollView *)scrollViewForIdentifier:(NSInteger)identifier { - return (UIScrollView *)[self.instanceManager instanceForIdentifier:identifier]; -} -#endif - -- (void)createFromWebViewWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { -#if TARGET_OS_IOS - WKWebView *webView = (WKWebView *)[self.instanceManager instanceForIdentifier:webViewIdentifier]; - [self.instanceManager addDartCreatedInstance:webView.scrollView withIdentifier:identifier]; -#else - *error = [FlutterError errorWithCode:@"UnavailableApi" - message:@"scrollView is unavailable on macOS" - details:nil]; -#endif -} - -- (NSArray *) - contentOffsetForScrollViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error { -#if TARGET_OS_IOS - CGPoint point = [[self scrollViewForIdentifier:identifier] contentOffset]; - return @[ @(point.x), @(point.y) ]; -#else - return @[ @(0), @(0) ]; -#endif -} - -- (void)scrollByForScrollViewWithIdentifier:(NSInteger)identifier - x:(double)x - y:(double)y - error:(FlutterError *_Nullable *_Nonnull)error { -#if TARGET_OS_IOS - UIScrollView *scrollView = [self scrollViewForIdentifier:identifier]; - CGPoint contentOffset = scrollView.contentOffset; - [scrollView setContentOffset:CGPointMake(contentOffset.x + x, contentOffset.y + y)]; -#endif -} - -- (void)setContentOffsetForScrollViewWithIdentifier:(NSInteger)identifier - toX:(double)x - y:(double)y - error:(FlutterError *_Nullable *_Nonnull)error { -#if TARGET_OS_IOS - [[self scrollViewForIdentifier:identifier] setContentOffset:CGPointMake(x, y)]; -#endif -} - -- (void)setDelegateForScrollViewWithIdentifier:(NSInteger)identifier - uiScrollViewDelegateIdentifier:(nullable NSNumber *)uiScrollViewDelegateIdentifier - error:(FlutterError *_Nullable *_Nonnull)error { -#if TARGET_OS_IOS - [[self scrollViewForIdentifier:identifier] - setDelegate:uiScrollViewDelegateIdentifier - ? (FWFScrollViewDelegate *)[self.instanceManager - instanceForIdentifier:uiScrollViewDelegateIdentifier.longValue] - : nil]; -#endif -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIDelegateHostApi.m deleted file mode 100644 index e38635a3d218..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIDelegateHostApi.m +++ /dev/null @@ -1,255 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFUIDelegateHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" - -@interface FWFUIDelegateFlutterApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFUIDelegateFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithBinaryMessenger:binaryMessenger]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - _webViewConfigurationFlutterApi = - [[FWFWebViewConfigurationFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; - } - return self; -} - -- (long)identifierForDelegate:(FWFUIDelegate *)instance { - return [self.instanceManager identifierWithStrongReferenceForInstance:instance]; -} - -- (void)onCreateWebViewForDelegate:(FWFUIDelegate *)instance - webView:(WKWebView *)webView - configuration:(WKWebViewConfiguration *)configuration - navigationAction:(WKNavigationAction *)navigationAction - completion:(void (^)(FlutterError *_Nullable))completion { - if (![self.instanceManager containsInstance:configuration]) { - [self.webViewConfigurationFlutterApi createWithConfiguration:configuration - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - } - - NSInteger configurationIdentifier = - [self.instanceManager identifierWithStrongReferenceForInstance:configuration]; - FWFWKNavigationActionData *navigationActionData = - FWFWKNavigationActionDataFromNativeWKNavigationAction(navigationAction); - - [self - onCreateWebViewForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier:[self.instanceManager - identifierWithStrongReferenceForInstance:webView] - configurationIdentifier:configurationIdentifier - navigationAction:navigationActionData - completion:completion]; -} - -- (void)requestMediaCapturePermissionForDelegateWithIdentifier:(FWFUIDelegate *)instance - webView:(WKWebView *)webView - origin:(WKSecurityOrigin *)origin - frame:(WKFrameInfo *)frame - type:(WKMediaCaptureType)type - completion: - (void (^)(WKPermissionDecision))completion - API_AVAILABLE(ios(15.0), macos(12)) { - [self - requestMediaCapturePermissionForDelegateWithIdentifier:[self identifierForDelegate:instance] - webViewIdentifier: - [self.instanceManager - identifierWithStrongReferenceForInstance:webView] - origin: - FWFWKSecurityOriginDataFromNativeWKSecurityOrigin( - origin) - frame: - FWFWKFrameInfoDataFromNativeWKFrameInfo( - frame) - type: - FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType( - type) - completion:^( - FWFWKPermissionDecisionData *decision, - FlutterError *error) { - NSAssert(!error, @"%@", error); - completion( - FWFNativeWKPermissionDecisionFromData( - decision)); - }]; -} - -- (void)runJavaScriptAlertPanelForDelegateWithIdentifier:(FWFUIDelegate *)instance - message:(NSString *)message - frame:(WKFrameInfo *)frame - completionHandler:(void (^)(void))completionHandler { - [self runJavaScriptAlertPanelForDelegateWithIdentifier:[self identifierForDelegate:instance] - message:message - frame:FWFWKFrameInfoDataFromNativeWKFrameInfo( - frame) - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - completionHandler(); - }]; -} - -- (void)runJavaScriptConfirmPanelForDelegateWithIdentifier:(FWFUIDelegate *)instance - message:(NSString *)message - frame:(WKFrameInfo *)frame - completionHandler:(void (^)(BOOL))completionHandler { - [self runJavaScriptConfirmPanelForDelegateWithIdentifier:[self identifierForDelegate:instance] - message:message - frame:FWFWKFrameInfoDataFromNativeWKFrameInfo( - frame) - completion:^(NSNumber *isConfirmed, - FlutterError *error) { - NSAssert(!error, @"%@", error); - if (error) { - completionHandler(NO); - } else { - completionHandler(isConfirmed.boolValue); - } - }]; -} - -- (void)runJavaScriptTextInputPanelForDelegateWithIdentifier:(FWFUIDelegate *)instance - prompt:(NSString *)prompt - defaultText:(NSString *)defaultText - frame:(WKFrameInfo *)frame - completionHandler: - (void (^)(NSString *_Nullable))completionHandler { - [self - runJavaScriptTextInputPanelForDelegateWithIdentifier:[self identifierForDelegate:instance] - prompt:prompt - defaultText:defaultText - frame:FWFWKFrameInfoDataFromNativeWKFrameInfo( - frame) - completion:^(NSString *inputText, - FlutterError *error) { - NSAssert(!error, @"%@", error); - if (error) { - completionHandler(nil); - } else { - completionHandler(inputText); - } - }]; -} - -@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 - webView:webView - configuration:configuration - navigationAction:navigationAction - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - return nil; -} - -- (void)webView:(WKWebView *)webView - requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin - initiatedByFrame:(WKFrameInfo *)frame - type:(WKMediaCaptureType)type - decisionHandler:(void (^)(WKPermissionDecision))decisionHandler - API_AVAILABLE(ios(15.0), macos(12)) { - [self.UIDelegateAPI - requestMediaCapturePermissionForDelegateWithIdentifier:self - webView:webView - origin:origin - frame:frame - type:type - completion:^(WKPermissionDecision decision) { - decisionHandler(decision); - }]; -} - -- (void)webView:(WKWebView *)webView - runJavaScriptAlertPanelWithMessage:(NSString *)message - initiatedByFrame:(WKFrameInfo *)frame - completionHandler:(void (^)(void))completionHandler { - [self.UIDelegateAPI runJavaScriptAlertPanelForDelegateWithIdentifier:self - message:message - frame:frame - completionHandler:completionHandler]; -} - -- (void)webView:(WKWebView *)webView - runJavaScriptConfirmPanelWithMessage:(NSString *)message - initiatedByFrame:(WKFrameInfo *)frame - completionHandler:(void (^)(BOOL))completionHandler { - [self.UIDelegateAPI runJavaScriptConfirmPanelForDelegateWithIdentifier:self - message:message - frame:frame - completionHandler:completionHandler]; -} - -- (void)webView:(WKWebView *)webView - runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt - defaultText:(NSString *)defaultText - initiatedByFrame:(WKFrameInfo *)frame - completionHandler:(void (^)(NSString *_Nullable))completionHandler { - [self.UIDelegateAPI runJavaScriptTextInputPanelForDelegateWithIdentifier:self - prompt:prompt - defaultText:defaultText - frame:frame - completionHandler:completionHandler]; -} - -@end - -@interface FWFUIDelegateHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFUIDelegateHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (FWFUIDelegate *)delegateForIdentifier:(NSNumber *)identifier { - return (FWFUIDelegate *)[self.instanceManager instanceForIdentifier:identifier.longValue]; -} - -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFUIDelegate *uIDelegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:uIDelegate withIdentifier:identifier]; -} - -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIViewHostApi.m deleted file mode 100644 index 0a2c0dcc36f8..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUIViewHostApi.m +++ /dev/null @@ -1,51 +0,0 @@ -// 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. - -// Using directory structure to remove platform-specific files doesn't work -// well with umbrella headers and module maps, so just no-op the file for -// other platforms instead. -#if TARGET_OS_IOS - -#import "./include/webview_flutter_wkwebview/FWFUIViewHostApi.h" - -@interface FWFUIViewHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFUIViewHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (UIView *)viewForIdentifier:(NSInteger)identifier { - return (UIView *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)setBackgroundColorForViewWithIdentifier:(NSInteger)identifier - toValue:(nullable NSNumber *)color - error:(FlutterError *_Nullable *_Nonnull)error { - if (color == nil) { - [[self viewForIdentifier:identifier] setBackgroundColor:nil]; - } - int colorInt = color.intValue; - UIColor *colorObject = [UIColor colorWithRed:(colorInt >> 16 & 0xff) / 255.0 - green:(colorInt >> 8 & 0xff) / 255.0 - blue:(colorInt & 0xff) / 255.0 - alpha:(colorInt >> 24 & 0xff) / 255.0]; - [[self viewForIdentifier:identifier] setBackgroundColor:colorObject]; -} - -- (void)setOpaqueForViewWithIdentifier:(NSInteger)identifier - isOpaque:(BOOL)opaque - error:(FlutterError *_Nullable *_Nonnull)error { - [[self viewForIdentifier:identifier] setOpaque:opaque]; -} -@end - -#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.m deleted file mode 100644 index ac374b786c77..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.m +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.h" - -@interface FWFURLAuthenticationChallengeFlutterApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFURLAuthenticationChallengeFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - _api = - [[FWFNSUrlAuthenticationChallengeFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; - } - return self; -} - -- (void)createWithInstance:(NSURLAuthenticationChallenge *)instance - protectionSpace:(NSURLProtectionSpace *)protectionSpace - completion:(void (^)(FlutterError *_Nullable))completion { - if ([self.instanceManager containsInstance:instance]) { - return; - } - - FWFURLProtectionSpaceFlutterApiImpl *protectionSpaceApi = - [[FWFURLProtectionSpaceFlutterApiImpl alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [protectionSpaceApi createWithInstance:protectionSpace - host:protectionSpace.host - realm:protectionSpace.realm - authenticationMethod:protectionSpace.authenticationMethod - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; - - [self.api createWithIdentifier:[self.instanceManager addHostCreatedInstance:instance] - protectionSpaceIdentifier:[self.instanceManager - identifierWithStrongReferenceForInstance:protectionSpace] - completion:completion]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLCredentialHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLCredentialHostApi.m deleted file mode 100644 index 7ac0647a8f98..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLCredentialHostApi.m +++ /dev/null @@ -1,58 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFURLCredentialHostApi.h" - -@interface FWFURLCredentialHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFURLCredentialHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (void)createWithUserWithIdentifier:(NSInteger)identifier - user:(nonnull NSString *)user - password:(nonnull NSString *)password - persistence:(FWFNSUrlCredentialPersistence)persistence - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [self.instanceManager - addDartCreatedInstance: - [NSURLCredential - credentialWithUser:user - password:password - persistence: - FWFNativeNSURLCredentialPersistenceFromFWFNSUrlCredentialPersistence( - persistence)] - withIdentifier:identifier]; -} - -- (nullable NSURL *)credentialForIdentifier:(NSNumber *)identifier - error: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSURL *instance = (NSURL *)[self.instanceManager instanceForIdentifier:identifier.longValue]; - - if (!instance) { - NSString *message = - [NSString stringWithFormat:@"InstanceManager does not contain an NSURL with identifier: %@", - identifier]; - *error = [FlutterError errorWithCode:NSInternalInconsistencyException - message:message - details:nil]; - } - - return instance; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLHostApi.m deleted file mode 100644 index 3ed6474efc27..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLHostApi.m +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFURLHostApi.h" - -@interface FWFURLHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@interface FWFURLFlutterApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFURLHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (nullable NSString *) - absoluteStringForNSURLWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSURL *instance = [self urlForIdentifier:identifier error:error]; - if (*error) { - return nil; - } - - return instance.absoluteString; -} - -- (nullable NSURL *)urlForIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSURL *instance = (NSURL *)[self.instanceManager instanceForIdentifier:identifier]; - - if (!instance) { - NSString *message = [NSString - stringWithFormat:@"InstanceManager does not contain an NSURL with identifier: %li", - (long)identifier]; - *error = [FlutterError errorWithCode:NSInternalInconsistencyException - message:message - details:nil]; - } - - return instance; -} -@end - -@implementation FWFURLFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - _api = [[FWFNSUrlFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; - } - return self; -} - -- (void)create:(NSURL *)instance completion:(void (^)(FlutterError *_Nullable))completion { - [self.api createWithIdentifier:[self.instanceManager addHostCreatedInstance:instance] - completion:completion]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.m deleted file mode 100644 index f83889979dff..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.m +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.h" - -@interface FWFURLProtectionSpaceFlutterApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFURLProtectionSpaceFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - _api = [[FWFNSUrlProtectionSpaceFlutterApi alloc] initWithBinaryMessenger:binaryMessenger]; - } - return self; -} - -- (void)createWithInstance:(NSURLProtectionSpace *)instance - host:(nullable NSString *)host - realm:(nullable NSString *)realm - authenticationMethod:(nullable NSString *)authenticationMethod - completion:(void (^)(FlutterError *_Nullable))completion { - if (![self.instanceManager containsInstance:instance]) { - [self.api createWithIdentifier:[self.instanceManager addHostCreatedInstance:instance] - host:host - realm:realm - authenticationMethod:authenticationMethod - completion:completion]; - } -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUserContentControllerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUserContentControllerHostApi.m deleted file mode 100644 index 1cd80344e7f3..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFUserContentControllerHostApi.m +++ /dev/null @@ -1,80 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFUserContentControllerHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" - -@interface FWFUserContentControllerHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFUserContentControllerHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (WKUserContentController *)userContentControllerForIdentifier:(NSInteger)identifier { - return (WKUserContentController *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error { - WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager - instanceForIdentifier:configurationIdentifier]; - [self.instanceManager addDartCreatedInstance:configuration.userContentController - withIdentifier:identifier]; -} - -- (void)addScriptMessageHandlerForControllerWithIdentifier:(NSInteger)identifier - handlerIdentifier:(NSInteger)handler - ofName:(nonnull NSString *)name - error: - (FlutterError *_Nullable *_Nonnull)error { - [[self userContentControllerForIdentifier:identifier] - addScriptMessageHandler:(id)[self.instanceManager - instanceForIdentifier:handler] - name:name]; -} - -- (void)removeScriptMessageHandlerForControllerWithIdentifier:(NSInteger)identifier - name:(nonnull NSString *)name - error:(FlutterError *_Nullable *_Nonnull) - error { - [[self userContentControllerForIdentifier:identifier] removeScriptMessageHandlerForName:name]; -} - -- (void)removeAllScriptMessageHandlersForControllerWithIdentifier:(NSInteger)identifier - error: - (FlutterError *_Nullable *_Nonnull) - error { - if (@available(iOS 14.0, macOS 11, *)) { - [[self userContentControllerForIdentifier:identifier] removeAllScriptMessageHandlers]; - } else { - *error = [FlutterError - errorWithCode:@"FWFUnsupportedVersionError" - message:@"removeAllScriptMessageHandlers is only supported on iOS 14+ and macOS 11+." - details:nil]; - } -} - -- (void)addUserScriptForControllerWithIdentifier:(NSInteger)identifier - userScript:(nonnull FWFWKUserScriptData *)userScript - error:(FlutterError *_Nullable *_Nonnull)error { - [[self userContentControllerForIdentifier:identifier] - addUserScript:FWFNativeWKUserScriptFromScriptData(userScript)]; -} - -- (void)removeAllUserScriptsForControllerWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error { - [[self userContentControllerForIdentifier:identifier] removeAllUserScripts]; -} - -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.m deleted file mode 100644 index d97bf9bfe6ed..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.m +++ /dev/null @@ -1,139 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" - -@interface FWFWebViewConfigurationFlutterApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFWebViewConfigurationFlutterApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithBinaryMessenger:binaryMessenger]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (void)createWithConfiguration:(WKWebViewConfiguration *)configuration - completion:(void (^)(FlutterError *_Nullable))completion { - long identifier = [self.instanceManager addHostCreatedInstance:configuration]; - [self createWithIdentifier:identifier completion:completion]; -} -@end - -@implementation FWFWebViewConfiguration -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - 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:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} -@end - -@interface FWFWebViewConfigurationHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFWebViewConfigurationHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - } - return self; -} - -- (WKWebViewConfiguration *)webViewConfigurationForIdentifier:(NSInteger)identifier { - return (WKWebViewConfiguration *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFWebViewConfiguration *webViewConfiguration = - [[FWFWebViewConfiguration alloc] initWithBinaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:webViewConfiguration withIdentifier:identifier]; -} - -- (void)createFromWebViewWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - WKWebView *webView = (WKWebView *)[self.instanceManager instanceForIdentifier:webViewIdentifier]; - [self.instanceManager addDartCreatedInstance:webView.configuration withIdentifier:identifier]; -} - -- (void)setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:(NSInteger)identifier - isAllowed:(BOOL)allow - error: - (FlutterError *_Nullable *_Nonnull) - error { -#if TARGET_OS_IOS - [[self webViewConfigurationForIdentifier:identifier] setAllowsInlineMediaPlayback:allow]; -#endif - // No-op, rather than error out, on macOS, since it's not a meaningful option on macOS and it's - // easier for clients if it's just ignored. -} - -- (void)setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:(NSInteger)identifier - isLimited:(BOOL)limit - error:(FlutterError *_Nullable - *_Nonnull)error { - if (@available(iOS 14, macOS 11, *)) { - [[self webViewConfigurationForIdentifier:identifier] - setLimitsNavigationsToAppBoundDomains:limit]; - } else { - *error = [FlutterError errorWithCode:@"FWFUnsupportedVersionError" - message:@"setLimitsNavigationsToAppBoundDomains is only supported " - @"on iOS 14+ and macOS 11+." - details:nil]; - } -} - -- (void) - setMediaTypesRequiresUserActionForConfigurationWithIdentifier:(NSInteger)identifier - forTypes: - (nonnull NSArray< - FWFWKAudiovisualMediaTypeEnumData - *> *)types - error: - (FlutterError *_Nullable *_Nonnull) - error { - NSAssert(types.count, @"Types must not be empty."); - - WKWebViewConfiguration *configuration = - (WKWebViewConfiguration *)[self webViewConfigurationForIdentifier:identifier]; - WKAudiovisualMediaTypes typesInt = 0; - for (FWFWKAudiovisualMediaTypeEnumData *data in types) { - typesInt |= FWFNativeWKAudiovisualMediaTypeFromEnumData(data); - } - [configuration setMediaTypesRequiringUserActionForPlayback:typesInt]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.m deleted file mode 100644 index 8cf93183b8a9..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.m +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.h" -#import "./include/webview_flutter_wkwebview/FWFInstanceManager.h" - -@implementation FWFWebViewFlutterWKWebViewExternalAPI -+ (nullable WKWebView *)webViewForIdentifier:(long)identifier - withPluginRegistry:(id)registry { - FWFInstanceManager *instanceManager = - (FWFInstanceManager *)[registry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]; - - id instance = [instanceManager instanceForIdentifier:identifier]; - if ([instance isKindOfClass:[WKWebView class]]) { - return instance; - } - - return nil; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewHostApi.m deleted file mode 100644 index 2a937435c91f..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebViewHostApi.m +++ /dev/null @@ -1,318 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFWebViewHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" - -@implementation FWFAssetManager -- (NSString *)lookupKeyForAsset:(NSString *)asset { - return [FlutterDartProject lookupKeyForAsset:asset]; -} -@end - -@implementation FWFWebView -- (instancetype)initWithFrame:(CGRect)frame - configuration:(nonnull WKWebViewConfiguration *)configuration - binaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - self = [self initWithFrame:frame configuration:configuration]; - if (self) { - _objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager]; - -#if TARGET_OS_IOS - self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - if (@available(iOS 13.0, *)) { - self.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; - } -#endif - } - return self; -} - -- (void)setFrame:(CGRect)frame { - [super setFrame:frame]; -#if TARGET_OS_IOS - // Prevents the contentInsets from being adjusted by iOS and gives control to Flutter. - self.scrollView.contentInset = UIEdgeInsetsZero; - - // Adjust contentInset to compensate the adjustedContentInset so the sum will - // always be 0. - if (UIEdgeInsetsEqualToEdgeInsets(self.scrollView.adjustedContentInset, UIEdgeInsetsZero)) { - return; - } - UIEdgeInsets insetToAdjust = self.scrollView.adjustedContentInset; - self.scrollView.contentInset = UIEdgeInsetsMake(-insetToAdjust.top, -insetToAdjust.left, - -insetToAdjust.bottom, -insetToAdjust.right); -#endif -} - -- (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(id)object - change:(NSDictionary *)change - context:(void *)context { - [self.objectApi observeValueForObject:self - keyPath:keyPath - object:object - change:change - completion:^(FlutterError *error) { - NSAssert(!error, @"%@", error); - }]; -} - -#pragma mark FlutterPlatformView - -#if TARGET_OS_IOS -- (nonnull UIView *)view { - return self; -} -#endif -@end - -@interface FWFWebViewHostApiImpl () -// BinaryMessenger must be weak to prevent a circular reference with the host API it -// references. -@property(nonatomic, weak) id binaryMessenger; -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@property NSBundle *bundle; -@property FWFAssetManager *assetManager; -@end - -@implementation FWFWebViewHostApiImpl -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager { - return [self initWithBinaryMessenger:binaryMessenger - instanceManager:instanceManager - bundle:[NSBundle mainBundle] - assetManager:[[FWFAssetManager alloc] init]]; -} - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager - bundle:(NSBundle *)bundle - assetManager:(FWFAssetManager *)assetManager { - self = [self init]; - if (self) { - _binaryMessenger = binaryMessenger; - _instanceManager = instanceManager; - _bundle = bundle; - _assetManager = assetManager; - } - return self; -} - -- (FWFWebView *)webViewForIdentifier:(NSInteger)identifier { - return (FWFWebView *)[self.instanceManager instanceForIdentifier:identifier]; -} - -+ (nonnull FlutterError *)errorForURLString:(nonnull NSString *)string { - NSString *errorDetails = [NSString stringWithFormat:@"Initializing NSURL with the supplied " - @"'%@' path resulted in a nil value.", - string]; - return [FlutterError errorWithCode:@"FWFURLParsingError" - message:@"Failed parsing file path." - details:errorDetails]; -} - -- (void)createWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager - instanceForIdentifier:configurationIdentifier]; - FWFWebView *webView = [[FWFWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) - configuration:configuration - binaryMessenger:self.binaryMessenger - instanceManager:self.instanceManager]; - [self.instanceManager addDartCreatedInstance:webView withIdentifier:identifier]; -} - -- (void)loadRequestForWebViewWithIdentifier:(NSInteger)identifier - request:(nonnull FWFNSUrlRequestData *)request - error: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSURLRequest *urlRequest = FWFNativeNSURLRequestFromRequestData(request); - if (!urlRequest) { - *error = [FlutterError errorWithCode:@"FWFURLRequestParsingError" - message:@"Failed instantiating an NSURLRequest." - details:[NSString stringWithFormat:@"URL was: '%@'", request.url]]; - return; - } - [[self webViewForIdentifier:identifier] loadRequest:urlRequest]; -} - -- (void)setCustomUserAgentForWebViewWithIdentifier:(NSInteger)identifier - userAgent:(nullable NSString *)userAgent - error: - (FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - [[self webViewForIdentifier:identifier] setCustomUserAgent:userAgent]; -} - -- (nullable NSNumber *) - canGoBackForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - return @([self webViewForIdentifier:identifier].canGoBack); -} - -- (nullable NSString *) - URLForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - return [self webViewForIdentifier:identifier].URL.absoluteString; -} - -- (nullable NSNumber *) - canGoForwardForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - return @([[self webViewForIdentifier:identifier] canGoForward]); -} - -- (nullable NSNumber *) - estimatedProgressForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - return @([[self webViewForIdentifier:identifier] estimatedProgress]); -} - -- (void)evaluateJavaScriptForWebViewWithIdentifier:(NSInteger)identifier - javaScriptString:(nonnull NSString *)javaScriptString - completion: - (nonnull void (^)(id _Nullable, - FlutterError *_Nullable))completion { - [[self webViewForIdentifier:identifier] - evaluateJavaScript:javaScriptString - completionHandler:^(id _Nullable result, NSError *_Nullable error) { - id returnValue = nil; - FlutterError *flutterError = nil; - if (!error) { - if (!result || [result isKindOfClass:[NSString class]] || - [result isKindOfClass:[NSNumber class]]) { - returnValue = result; - } else if (![result isKindOfClass:[NSNull class]]) { - NSString *className = NSStringFromClass([result class]); - NSLog(@"Return type of evaluateJavaScript is not directly supported: %@. Returned " - @"description of value.", - className); - returnValue = [result description]; - } - } else { - flutterError = [FlutterError errorWithCode:@"FWFEvaluateJavaScriptError" - message:@"Failed evaluating JavaScript." - details:FWFNSErrorDataFromNativeNSError(error)]; - } - - completion(returnValue, flutterError); - }]; -} - -- (void)setInspectableForWebViewWithIdentifier:(NSInteger)identifier - inspectable:(BOOL)inspectable - error:(FlutterError *_Nullable *_Nonnull)error { - if (@available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) { -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 - [[self webViewForIdentifier:identifier] setInspectable:inspectable]; -#endif - } else { - *error = [FlutterError errorWithCode:@"FWFUnsupportedVersionError" - message:@"setInspectable is only supported on versions 16.4+." - details:nil]; - } -} - -- (void)goBackForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [[self webViewForIdentifier:identifier] goBack]; -} - -- (void)goForwardForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [[self webViewForIdentifier:identifier] goForward]; -} - -- (void)loadAssetForWebViewWithIdentifier:(NSInteger)identifier - assetKey:(nonnull NSString *)key - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSString *assetFilePath = [self.assetManager lookupKeyForAsset:key]; - - NSURL *url = [self.bundle URLForResource:[assetFilePath stringByDeletingPathExtension] - withExtension:assetFilePath.pathExtension]; - if (!url) { - *error = [FWFWebViewHostApiImpl errorForURLString:assetFilePath]; - } else { - [[self webViewForIdentifier:identifier] loadFileURL:url - allowingReadAccessToURL:[url URLByDeletingLastPathComponent]]; - } -} - -- (void)loadFileForWebViewWithIdentifier:(NSInteger)identifier - fileURL:(nonnull NSString *)url - readAccessURL:(nonnull NSString *)readAccessUrl - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - NSURL *fileURL = [NSURL fileURLWithPath:url isDirectory:NO]; - NSURL *readAccessNSURL = [NSURL fileURLWithPath:readAccessUrl isDirectory:YES]; - - if (!fileURL) { - *error = [FWFWebViewHostApiImpl errorForURLString:url]; - } else if (!readAccessNSURL) { - *error = [FWFWebViewHostApiImpl errorForURLString:readAccessUrl]; - } else { - [[self webViewForIdentifier:identifier] loadFileURL:fileURL - allowingReadAccessToURL:readAccessNSURL]; - } -} - -- (void)loadHTMLForWebViewWithIdentifier:(NSInteger)identifier - HTMLString:(nonnull NSString *)string - baseURL:(nullable NSString *)baseUrl - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [[self webViewForIdentifier:identifier] loadHTMLString:string - baseURL:[NSURL URLWithString:baseUrl]]; -} - -- (void)reloadWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [[self webViewForIdentifier:identifier] reload]; -} - -- (void) - setAllowsBackForwardForWebViewWithIdentifier:(NSInteger)identifier - isAllowed:(BOOL)allow - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - [[self webViewForIdentifier:identifier] setAllowsBackForwardNavigationGestures:allow]; -} - -- (void) - setNavigationDelegateForWebViewWithIdentifier:(NSInteger)identifier - delegateIdentifier:(nullable NSNumber *)navigationDelegateIdentifier - error: - (FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - id navigationDelegate = (id)[self.instanceManager - instanceForIdentifier:navigationDelegateIdentifier.longValue]; - [[self webViewForIdentifier:identifier] setNavigationDelegate:navigationDelegate]; -} - -- (void)setUIDelegateForWebViewWithIdentifier:(NSInteger)identifier - delegateIdentifier:(nullable NSNumber *)uiDelegateIdentifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - id navigationDelegate = - (id)[self.instanceManager instanceForIdentifier:uiDelegateIdentifier.longValue]; - [[self webViewForIdentifier:identifier] setUIDelegate:navigationDelegate]; -} - -- (nullable NSString *) - titleForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - return [[self webViewForIdentifier:identifier] title]; -} - -- (nullable NSString *) - customUserAgentForWebViewWithIdentifier:(NSInteger)identifier - error: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - return [[self webViewForIdentifier:identifier] customUserAgent]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.m deleted file mode 100644 index 7e7ead760efa..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.m +++ /dev/null @@ -1,66 +0,0 @@ -// 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. - -#import "./include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h" -#import "./include/webview_flutter_wkwebview/FWFDataConverters.h" -#import "./include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h" - -@interface FWFWebsiteDataStoreHostApiImpl () -// InstanceManager must be weak to prevent a circular reference with the object it stores. -@property(nonatomic, weak) FWFInstanceManager *instanceManager; -@end - -@implementation FWFWebsiteDataStoreHostApiImpl -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - self = [self init]; - if (self) { - _instanceManager = instanceManager; - } - return self; -} - -- (WKWebsiteDataStore *)websiteDataStoreForIdentifier:(NSInteger)identifier { - return (WKWebsiteDataStore *)[self.instanceManager instanceForIdentifier:identifier]; -} - -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error { - WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager - instanceForIdentifier:configurationIdentifier]; - [self.instanceManager addDartCreatedInstance:configuration.websiteDataStore - withIdentifier:identifier]; -} - -- (void)createDefaultDataStoreWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - [self.instanceManager addDartCreatedInstance:[WKWebsiteDataStore defaultDataStore] - withIdentifier:identifier]; -} - -- (void)removeDataFromDataStoreWithIdentifier:(NSInteger)identifier - ofTypes:(nonnull NSArray *) - dataTypes - modifiedSince:(double)modificationTimeInSecondsSinceEpoch - completion: - (nonnull void (^)(NSNumber *_Nullable, - FlutterError *_Nullable))completion { - NSMutableSet *stringDataTypes = [NSMutableSet set]; - for (FWFWKWebsiteDataTypeEnumData *type in dataTypes) { - [stringDataTypes addObject:FWFNativeWKWebsiteDataTypeFromEnumData(type)]; - } - - WKWebsiteDataStore *dataStore = [self websiteDataStoreForIdentifier:identifier]; - [dataStore fetchDataRecordsOfTypes:stringDataTypes - completionHandler:^(NSArray *records) { - [dataStore removeDataOfTypes:stringDataTypes - modifiedSince:[NSDate dateWithTimeIntervalSince1970: - modificationTimeInSecondsSinceEpoch] - completionHandler:^{ - completion([NSNumber numberWithBool:(records.count > 0)], nil); - }]; - }]; -} -@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterAssetManager.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterAssetManager.swift new file mode 100644 index 000000000000..2c66d735a46a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterAssetManager.swift @@ -0,0 +1,17 @@ +// 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. + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +open class FlutterAssetManager { + func lookupKeyForAsset(_ asset: String) -> String { + return FlutterDartProject.lookupKey(forAsset: asset) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift new file mode 100644 index 000000000000..ca8a8aa7f27d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift @@ -0,0 +1,74 @@ +// 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. + +import Foundation + +#if os(iOS) + import Flutter + import UIKit +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// Implementation of `FlutterPlatformViewFactory` that retrieves the view from the `WebKitLibraryPigeonInstanceManager`. +class FlutterViewFactory: NSObject, FlutterPlatformViewFactory { + unowned let instanceManager: WebKitLibraryPigeonInstanceManager + + #if os(iOS) + class PlatformViewImpl: NSObject, FlutterPlatformView { + let uiView: UIView + + init(uiView: UIView) { + self.uiView = uiView + } + + func view() -> UIView { + return uiView + } + } + #endif + + init(instanceManager: WebKitLibraryPigeonInstanceManager) { + self.instanceManager = instanceManager + } + + #if os(iOS) + func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) + -> FlutterPlatformView + { + let identifier: Int64 = args is Int64 ? args as! Int64 : Int64(args as! Int32) + let instance: AnyObject? = instanceManager.instance(forIdentifier: identifier) + + if let instance = instance as? FlutterPlatformView { + instance.view().frame = frame + return instance + } else { + let view = instance as! UIView + view.frame = frame + return PlatformViewImpl(uiView: view) + } + } + #elseif os(macOS) + func create( + withViewIdentifier viewId: Int64, + arguments args: Any? + ) -> NSView { + let identifier: Int64 = args is Int64 ? args as! Int64 : Int64(args as! Int32) + let instance: AnyObject? = instanceManager.instance(forIdentifier: identifier) + return instance as! NSView + } + #endif + + #if os(iOS) + func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol { + return FlutterStandardMessageCodec.sharedInstance() + } + #elseif os(macOS) + func createArgsCodec() -> (FlutterMessageCodec & NSObjectProtocol)? { + return FlutterStandardMessageCodec.sharedInstance() + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FrameInfoProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FrameInfoProxyAPIDelegate.swift new file mode 100644 index 000000000000..b14398e239b3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FrameInfoProxyAPIDelegate.swift @@ -0,0 +1,21 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKFrameInfo`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class FrameInfoProxyAPIDelegate: PigeonApiDelegateWKFrameInfo { + func isMainFrame(pigeonApi: PigeonApiWKFrameInfo, pigeonInstance: WKFrameInfo) throws -> Bool { + return pigeonInstance.isMainFrame + } + + func request(pigeonApi: PigeonApiWKFrameInfo, pigeonInstance: WKFrameInfo) throws + -> URLRequestWrapper + { + return URLRequestWrapper(pigeonInstance.request) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieProxyAPIDelegate.swift new file mode 100644 index 000000000000..0b6fca238a4a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieProxyAPIDelegate.swift @@ -0,0 +1,125 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `HTTPCookie`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class HTTPCookieProxyAPIDelegate: PigeonApiDelegateHTTPCookie { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiHTTPCookie, properties: [HttpCookiePropertyKey: Any] + ) throws -> HTTPCookie { + let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar + + let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> { + key, value in + + let newKey: HTTPCookiePropertyKey + switch key { + case .comment: + newKey = .comment + case .commentUrl: + newKey = .commentURL + case .discard: + newKey = .discard + case .domain: + newKey = .domain + case .expires: + newKey = .expires + case .maximumAge: + newKey = .maximumAge + case .name: + newKey = .name + case .originUrl: + newKey = .originURL + case .path: + newKey = .path + case .port: + newKey = .port + case .secure: + newKey = .secure + case .value: + newKey = .value + case .version: + newKey = .version + case .sameSitePolicy: + if #available(iOS 13.0, macOS 10.15, *) { + newKey = .sameSitePolicy + } else { + throw + registrar + .createUnsupportedVersionError( + method: "HTTPCookiePropertyKey.sameSitePolicy", + versionRequirements: "iOS 13.0, macOS 10.15") + } + case .unknown: + throw registrar.createUnknownEnumError( + withEnum: key) + } + + return (newKey, value) + } + + let nativeProperties = Dictionary(uniqueKeysWithValues: keyValueTuples) + let cookie = HTTPCookie(properties: nativeProperties) + if let cookie = cookie { + return cookie + } else { + throw registrar.createConstructorNullError( + type: HTTPCookie.self, parameters: ["properties": nativeProperties]) + } + } + + func getProperties(pigeonApi: PigeonApiHTTPCookie, pigeonInstance: HTTPCookie) throws + -> [HttpCookiePropertyKey: Any]? + { + if pigeonInstance.properties == nil { + return nil + } + + let keyValueTuples = pigeonInstance.properties!.map { key, value in + let newKey: HttpCookiePropertyKey + if #available(iOS 13.0, macOS 10.15, *), key == .sameSitePolicy { + newKey = .sameSitePolicy + } else { + switch key { + case .comment: + newKey = .comment + case .commentURL: + newKey = .commentUrl + case .discard: + newKey = .discard + case .domain: + newKey = .domain + case .expires: + newKey = .expires + case .maximumAge: + newKey = .maximumAge + case .name: + newKey = .name + case .originURL: + newKey = .originUrl + case .path: + newKey = .path + case .port: + newKey = .port + case .secure: + newKey = .secure + case .value: + newKey = .value + case .version: + newKey = .version + default: + newKey = .unknown + } + } + + return (newKey, value) + } + + return Dictionary(uniqueKeysWithValues: keyValueTuples) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieStoreProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieStoreProxyAPIDelegate.swift new file mode 100644 index 000000000000..5026783b3b24 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPCookieStoreProxyAPIDelegate.swift @@ -0,0 +1,21 @@ +// 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. + +import Foundation +import WebKit + +/// ProxyApi implementation for `WKHTTPCookieStore`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class HTTPCookieStoreProxyAPIDelegate: PigeonApiDelegateWKHTTPCookieStore { + func setCookie( + pigeonApi: PigeonApiWKHTTPCookieStore, pigeonInstance: WKHTTPCookieStore, cookie: HTTPCookie, + completion: @escaping (Result) -> Void + ) { + pigeonInstance.setCookie(cookie) { + completion(.success(Void())) + } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPURLResponseProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPURLResponseProxyAPIDelegate.swift new file mode 100644 index 000000000000..ed73f9a2130c --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/HTTPURLResponseProxyAPIDelegate.swift @@ -0,0 +1,17 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `HTTPURLResponse`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class HTTPURLResponseProxyAPIDelegate: PigeonApiDelegateHTTPURLResponse { + func statusCode(pigeonApi: PigeonApiHTTPURLResponse, pigeonInstance: HTTPURLResponse) throws + -> Int64 + { + return Int64(pigeonInstance.statusCode) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NSObjectProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NSObjectProxyAPIDelegate.swift new file mode 100644 index 000000000000..5cde55b97ac1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NSObjectProxyAPIDelegate.swift @@ -0,0 +1,107 @@ +// 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. + +import Foundation + +/// Implementation of `NSObject` that calls to Dart in callback methods. +class NSObjectImpl: NSObject { + let api: PigeonApiProtocolNSObject + unowned let registrar: ProxyAPIRegistrar + + init(api: PigeonApiProtocolNSObject, registrar: ProxyAPIRegistrar) { + self.api = api + self.registrar = registrar + } + + static func handleObserveValue( + withApi api: PigeonApiProtocolNSObject, registrar: ProxyAPIRegistrar, instance: NSObject, + forKeyPath keyPath: String?, + of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer? + ) { + let wrapperKeys: [KeyValueChangeKey: Any]? + if change != nil { + let keyValueTuples = change!.map { key, value in + let newKey: KeyValueChangeKey + switch key { + case .kindKey: + newKey = .kind + case .indexesKey: + newKey = .indexes + case .newKey: + newKey = .newValue + case .oldKey: + newKey = .oldValue + case .notificationIsPriorKey: + newKey = .notificationIsPrior + default: + newKey = .unknown + } + + return (newKey, value) + } + + wrapperKeys = Dictionary(uniqueKeysWithValues: keyValueTuples) + } else { + wrapperKeys = nil + } + + registrar.dispatchOnMainThread { onFailure in + api.observeValue( + pigeonInstance: instance, keyPath: keyPath, object: object as? NSObject, change: wrapperKeys + ) { result in + if case .failure(let error) = result { + onFailure("NSObject.observeValue", error) + } + } + } + } + + override func observeValue( + forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, + context: UnsafeMutableRawPointer? + ) { + NSObjectImpl.handleObserveValue( + withApi: api, registrar: registrar, instance: self as NSObject, forKeyPath: keyPath, + of: object, change: change, + context: context) + } +} + +/// ProxyApi implementation for `NSObject`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class NSObjectProxyAPIDelegate: PigeonApiDelegateNSObject { + func pigeonDefaultConstructor(pigeonApi: PigeonApiNSObject) throws -> NSObject { + return NSObjectImpl(api: pigeonApi, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + } + + func addObserver( + pigeonApi: PigeonApiNSObject, pigeonInstance: NSObject, observer: NSObject, keyPath: String, + options: [KeyValueObservingOptions] + ) throws { + var nativeOptions: NSKeyValueObservingOptions = [] + + for option in options { + switch option { + case .newValue: + nativeOptions.insert(.new) + case .oldValue: + nativeOptions.insert(.old) + case .initialValue: + nativeOptions.insert(.initial) + case .priorNotification: + nativeOptions.insert(.prior) + } + } + + pigeonInstance.addObserver(observer, forKeyPath: keyPath, options: nativeOptions, context: nil) + } + + func removeObserver( + pigeonApi: PigeonApiNSObject, pigeonInstance: NSObject, observer: NSObject, keyPath: String + ) throws { + pigeonInstance.removeObserver(observer, forKeyPath: keyPath) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationActionProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationActionProxyAPIDelegate.swift new file mode 100644 index 000000000000..752884eca3c1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationActionProxyAPIDelegate.swift @@ -0,0 +1,44 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for [WKNavigationAction]. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class NavigationActionProxyAPIDelegate: PigeonApiDelegateWKNavigationAction { + func request(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) throws + -> URLRequestWrapper + { + return URLRequestWrapper(pigeonInstance.request) + } + + func targetFrame(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) + throws -> WKFrameInfo? + { + return pigeonInstance.targetFrame + } + + func navigationType(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) + throws -> NavigationType + { + switch pigeonInstance.navigationType { + case .linkActivated: + return .linkActivated + case .formSubmitted: + return .formSubmitted + case .backForward: + return .backForward + case .reload: + return .reload + case .formResubmitted: + return .formResubmitted + case .other: + return .other + @unknown default: + return .unknown + } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationDelegateProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationDelegateProxyAPIDelegate.swift new file mode 100644 index 000000000000..4988bb60228a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationDelegateProxyAPIDelegate.swift @@ -0,0 +1,292 @@ +// 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. + +import WebKit + +/// Implementation of `WKNavigationDelegate` that calls to Dart in callback methods. +public class NavigationDelegateImpl: NSObject, WKNavigationDelegate { + let api: PigeonApiProtocolWKNavigationDelegate + unowned let registrar: ProxyAPIRegistrar + + init(api: PigeonApiProtocolWKNavigationDelegate, registrar: ProxyAPIRegistrar) { + self.api = api + self.registrar = registrar + } + + public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + registrar.dispatchOnMainThread { onFailure in + self.api.didFinishNavigation( + pigeonInstance: self, webView: webView, url: webView.url?.absoluteString + ) { result in + if case .failure(let error) = result { + onFailure("WKNavigationDelegate.didFinishNavigation", error) + } + } + } + } + + public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) + { + registrar.dispatchOnMainThread { onFailure in + self.api.didStartProvisionalNavigation( + pigeonInstance: self, webView: webView, url: webView.url?.absoluteString + ) { result in + if case .failure(let error) = result { + onFailure("WKNavigationDelegate.didStartProvisionalNavigation", error) + } + } + } + } + + public func webView( + _ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.didFailNavigation(pigeonInstance: self, webView: webView, error: error as NSError) { + result in + if case .failure(let error) = result { + onFailure("WKNavigationDelegate.didFailNavigation", error) + } + } + } + } + + public func webView( + _ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, + withError error: Error + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.didFailProvisionalNavigation( + pigeonInstance: self, webView: webView, error: error as NSError + ) { result in + if case .failure(let error) = result { + onFailure("WKNavigationDelegate.didFailProvisionalNavigation", error) + } + } + } + } + + public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) { + registrar.dispatchOnMainThread { onFailure in + self.api.webViewWebContentProcessDidTerminate(pigeonInstance: self, webView: webView) { + result in + if case .failure(let error) = result { + onFailure("WKNavigationDelegate.webViewWebContentProcessDidTerminate", error) + } + } + } + } + + #if compiler(>=6.0) + public func webView( + _ webView: WKWebView, decidePolicyFor navigationAction: WebKit.WKNavigationAction, + decisionHandler: @escaping @MainActor (WebKit.WKNavigationActionPolicy) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.decidePolicyForNavigationAction( + pigeonInstance: self, webView: webView, navigationAction: navigationAction + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let policy): + switch policy { + case .allow: + decisionHandler(.allow) + case .cancel: + decisionHandler(.cancel) + case .download: + if #available(iOS 14.5, macOS 11.3, *) { + decisionHandler(.download) + } else { + decisionHandler(.cancel) + assertionFailure( + self.registrar.createUnsupportedVersionMessage( + "WKNavigationActionPolicy.download", + versionRequirements: "iOS 14.5, macOS 11.3" + )) + } + } + case .failure(let error): + decisionHandler(.cancel) + onFailure("WKNavigationDelegate.decidePolicyForNavigationAction", error) + } + } + } + } + } + #else + public func webView( + _ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, + decisionHandler: @escaping (WKNavigationActionPolicy) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.decidePolicyForNavigationAction( + pigeonInstance: self, webView: webView, navigationAction: navigationAction + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let policy): + switch policy { + case .allow: + decisionHandler(.allow) + case .cancel: + decisionHandler(.cancel) + case .download: + if #available(iOS 14.5, macOS 11.3, *) { + decisionHandler(.download) + } else { + decisionHandler(.cancel) + assertionFailure( + self.registrar.createUnsupportedVersionMessage( + "WKNavigationActionPolicy.download", + versionRequirements: "iOS 14.5, macOS 11.3" + )) + } + } + case .failure(let error): + decisionHandler(.cancel) + onFailure("WKNavigationDelegate.decidePolicyForNavigationAction", error) + } + } + } + } + } + #endif + + #if compiler(>=6.0) + public func webView( + _ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, + decisionHandler: @escaping @MainActor (WKNavigationResponsePolicy) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.decidePolicyForNavigationResponse( + pigeonInstance: self, webView: webView, navigationResponse: navigationResponse + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let policy): + switch policy { + case .allow: + decisionHandler(.allow) + case .cancel: + decisionHandler(.cancel) + case .download: + if #available(iOS 14.5, macOS 11.3, *) { + decisionHandler(.download) + } else { + decisionHandler(.cancel) + assertionFailure( + self.registrar.createUnsupportedVersionMessage( + "WKNavigationResponsePolicy.download", + versionRequirements: "iOS 14.5, macOS 11.3" + )) + } + } + case .failure(let error): + decisionHandler(.cancel) + onFailure("WKNavigationDelegate.decidePolicyForNavigationResponse", error) + } + } + } + } + } + #else + public func webView( + _ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, + decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.decidePolicyForNavigationResponse( + pigeonInstance: self, webView: webView, navigationResponse: navigationResponse + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let policy): + switch policy { + case .allow: + decisionHandler(.allow) + case .cancel: + decisionHandler(.cancel) + case .download: + if #available(iOS 14.5, macOS 11.3, *) { + decisionHandler(.download) + } else { + decisionHandler(.cancel) + assertionFailure( + self.registrar.createUnsupportedVersionMessage( + "WKNavigationResponsePolicy.download", + versionRequirements: "iOS 14.5, macOS 11.3" + )) + } + } + case .failure(let error): + decisionHandler(.cancel) + onFailure("WKNavigationDelegate.decidePolicyForNavigationResponse", error) + } + } + } + } + } + #endif + + #if compiler(>=6.0) + public func webView( + _ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, + completionHandler: @escaping @MainActor (URLSession.AuthChallengeDisposition, URLCredential?) + -> + Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.didReceiveAuthenticationChallenge( + pigeonInstance: self, webView: webView, challenge: challenge + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let response): + completionHandler(response.disposition, response.credential) + case .failure(let error): + completionHandler(.cancelAuthenticationChallenge, nil) + onFailure("WKNavigationDelegate.didReceiveAuthenticationChallenge", error) + } + } + } + } + } + #else + public func webView( + _ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, + completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> + Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.didReceiveAuthenticationChallenge( + pigeonInstance: self, webView: webView, challenge: challenge + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let response): + completionHandler(response.disposition, response.credential) + case .failure(let error): + completionHandler(.cancelAuthenticationChallenge, nil) + onFailure("WKNavigationDelegate.didReceiveAuthenticationChallenge", error) + } + } + } + } + } + #endif +} + +/// ProxyApi implementation for `WKNavigationDelegate`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class NavigationDelegateProxyAPIDelegate: PigeonApiDelegateWKNavigationDelegate { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKNavigationDelegate) throws + -> WKNavigationDelegate + { + return NavigationDelegateImpl( + api: pigeonApi, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationResponseProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationResponseProxyAPIDelegate.swift new file mode 100644 index 000000000000..9cd75f80e390 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/NavigationResponseProxyAPIDelegate.swift @@ -0,0 +1,23 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKNavigationResponse`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class NavigationResponseProxyAPIDelegate: PigeonApiDelegateWKNavigationResponse { + func response(pigeonApi: PigeonApiWKNavigationResponse, pigeonInstance: WKNavigationResponse) + throws -> URLResponse + { + return pigeonInstance.response + } + + func isForMainFrame( + pigeonApi: PigeonApiWKNavigationResponse, pigeonInstance: WKNavigationResponse + ) throws -> Bool { + return pigeonInstance.isForMainFrame + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/PreferencesProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/PreferencesProxyAPIDelegate.swift new file mode 100644 index 000000000000..805f78a4e13f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/PreferencesProxyAPIDelegate.swift @@ -0,0 +1,17 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKPreferences`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class PreferencesProxyAPIDelegate: PigeonApiDelegateWKPreferences { + func setJavaScriptEnabled( + pigeonApi: PigeonApiWKPreferences, pigeonInstance: WKPreferences, enabled: Bool + ) throws { + pigeonInstance.javaScriptEnabled = enabled + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ProxyAPIRegistrar.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ProxyAPIRegistrar.swift new file mode 100644 index 000000000000..2f4343518eac --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ProxyAPIRegistrar.swift @@ -0,0 +1,275 @@ +// 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. + +import Foundation + +#if os(iOS) + import Flutter + import UIKit +#elseif os(macOS) + import FlutterMacOS + import Foundation +#else + #error("Unsupported platform.") +#endif + +/// Implementation of `WebKitLibraryPigeonProxyApiRegistrar` that provides any additional resources needed by API implementations. +open class ProxyAPIRegistrar: WebKitLibraryPigeonProxyApiRegistrar { + let assetManager = FlutterAssetManager() + let bundle = Bundle.main + + init(binaryMessenger: FlutterBinaryMessenger) { + super.init(binaryMessenger: binaryMessenger, apiDelegate: ProxyAPIDelegate()) + } + + /// Creates an error when the `unknown` enum value is passed to a host method. + func createUnknownEnumError(withEnum enumValue: Any) -> PigeonError { + return PigeonError( + code: "UnknownEnumError", message: "\(enumValue) doesn't represent a native value.", + details: nil) + } + + /// Creates an error when a method is called on an unsupported version. + func createUnsupportedVersionError(method: String, versionRequirements: String) -> PigeonError { + return PigeonError( + code: "FWFUnsupportedVersionError", + message: createUnsupportedVersionMessage(method, versionRequirements: versionRequirements), + details: nil) + } + + /// Creates the error message when a method is called on an unsupported version. + func createUnsupportedVersionMessage(_ method: String, versionRequirements: String) -> String { + return "`\(method)` requires \(versionRequirements)." + } + + // Creates an error when the constructor of a URL returns null. + // + // New methods should use `createConstructorNullError`, but this stays + // to keep error code consistent with previous plugin versions. + fileprivate func createNullURLError(url: String) -> PigeonError { + return PigeonError( + code: "FWFURLParsingError", message: "Failed parsing file path.", + details: "Initializing URL with the supplied '\(url)' path resulted in a nil value.") + } + + /// Creates an error when the constructor of a class returns null. + func createConstructorNullError(type: Any.Type, parameters: [String: Any?]) -> PigeonError { + if type == URL.self && parameters["string"] != nil { + return createNullURLError(url: parameters["string"] as! String) + } + + return PigeonError( + code: "ConstructorReturnedNullError", + message: "Failed to instantiate `\(String(describing: type))` with parameters: \(parameters)", + details: nil) + } + + // Creates an assertion failure when a Flutter method receives an error from Dart. + fileprivate func assertFlutterMethodFailure(_ error: PigeonError, methodName: String) { + assertionFailure( + "\(String(describing: error)): Error returned from calling \(methodName): \(String(describing: error.message))" + ) + } + + /// Handles calling a Flutter method on the main thread. + func dispatchOnMainThread( + execute work: @escaping ( + _ onFailure: @escaping (_ methodName: String, _ error: PigeonError) -> Void + ) -> Void + ) { + DispatchQueue.main.async { + work { methodName, error in + self.assertFlutterMethodFailure(error, methodName: methodName) + } + } + } +} + +/// Implementation of `WebKitLibraryPigeonProxyApiDelegate` that provides each ProxyApi delegate implementation. +class ProxyAPIDelegate: WebKitLibraryPigeonProxyApiDelegate { + func pigeonApiURLRequest(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiURLRequest + { + return PigeonApiURLRequest(pigeonRegistrar: registrar, delegate: URLRequestProxyAPIDelegate()) + } + + func pigeonApiHTTPURLResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiHTTPURLResponse + { + return PigeonApiHTTPURLResponse( + pigeonRegistrar: registrar, delegate: HTTPURLResponseProxyAPIDelegate()) + } + + func pigeonApiWKUserScript(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUserScript + { + return PigeonApiWKUserScript(pigeonRegistrar: registrar, delegate: UserScriptProxyAPIDelegate()) + } + + func pigeonApiWKNavigationAction(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationAction + { + return PigeonApiWKNavigationAction( + pigeonRegistrar: registrar, delegate: NavigationActionProxyAPIDelegate()) + } + + func pigeonApiWKNavigationResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationResponse + { + return PigeonApiWKNavigationResponse( + pigeonRegistrar: registrar, delegate: NavigationResponseProxyAPIDelegate()) + } + + func pigeonApiWKFrameInfo(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKFrameInfo + { + return PigeonApiWKFrameInfo(pigeonRegistrar: registrar, delegate: FrameInfoProxyAPIDelegate()) + } + + func pigeonApiNSError(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiNSError { + return PigeonApiNSError(pigeonRegistrar: registrar, delegate: ErrorProxyAPIDelegate()) + } + + func pigeonApiWKScriptMessage(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKScriptMessage + { + return PigeonApiWKScriptMessage( + pigeonRegistrar: registrar, delegate: ScriptMessageProxyAPIDelegate()) + } + + func pigeonApiWKSecurityOrigin(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKSecurityOrigin + { + return PigeonApiWKSecurityOrigin( + pigeonRegistrar: registrar, delegate: SecurityOriginProxyAPIDelegate()) + } + + func pigeonApiHTTPCookie(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiHTTPCookie + { + return PigeonApiHTTPCookie(pigeonRegistrar: registrar, delegate: HTTPCookieProxyAPIDelegate()) + } + + func pigeonApiAuthenticationChallengeResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiAuthenticationChallengeResponse + { + return PigeonApiAuthenticationChallengeResponse( + pigeonRegistrar: registrar, delegate: AuthenticationChallengeResponseProxyAPIDelegate()) + } + + func pigeonApiWKWebsiteDataStore(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKWebsiteDataStore + { + return PigeonApiWKWebsiteDataStore( + pigeonRegistrar: registrar, delegate: WebsiteDataStoreProxyAPIDelegate()) + } + + func pigeonApiUIView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiUIView { + return PigeonApiUIView(pigeonRegistrar: registrar, delegate: UIViewProxyAPIDelegate()) + } + + func pigeonApiUIScrollView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIScrollView + { + return PigeonApiUIScrollView(pigeonRegistrar: registrar, delegate: ScrollViewProxyAPIDelegate()) + } + + func pigeonApiWKWebViewConfiguration(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKWebViewConfiguration + { + return PigeonApiWKWebViewConfiguration( + pigeonRegistrar: registrar, delegate: WebViewConfigurationProxyAPIDelegate()) + } + + func pigeonApiWKUserContentController(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUserContentController + { + return PigeonApiWKUserContentController( + pigeonRegistrar: registrar, delegate: UserContentControllerProxyAPIDelegate()) + } + + func pigeonApiWKPreferences(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKPreferences + { + return PigeonApiWKPreferences( + pigeonRegistrar: registrar, delegate: PreferencesProxyAPIDelegate()) + } + + func pigeonApiWKScriptMessageHandler(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKScriptMessageHandler + { + return PigeonApiWKScriptMessageHandler( + pigeonRegistrar: registrar, delegate: ScriptMessageHandlerProxyAPIDelegate()) + } + + func pigeonApiWKNavigationDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationDelegate + { + return PigeonApiWKNavigationDelegate( + pigeonRegistrar: registrar, delegate: NavigationDelegateProxyAPIDelegate()) + } + + func pigeonApiNSObject(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiNSObject { + return PigeonApiNSObject(pigeonRegistrar: registrar, delegate: NSObjectProxyAPIDelegate()) + } + + func pigeonApiUIViewWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIViewWKWebView + { + return PigeonApiUIViewWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + } + + func pigeonApiNSViewWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiNSViewWKWebView + { + return PigeonApiNSViewWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + } + + func pigeonApiWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiWKWebView { + return PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + } + + func pigeonApiWKUIDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUIDelegate + { + return PigeonApiWKUIDelegate(pigeonRegistrar: registrar, delegate: UIDelegateProxyAPIDelegate()) + } + + func pigeonApiWKHTTPCookieStore(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKHTTPCookieStore + { + return PigeonApiWKHTTPCookieStore( + pigeonRegistrar: registrar, delegate: HTTPCookieStoreProxyAPIDelegate()) + } + + func pigeonApiUIScrollViewDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIScrollViewDelegate + { + return PigeonApiUIScrollViewDelegate( + pigeonRegistrar: registrar, delegate: ScrollViewDelegateProxyAPIDelegate()) + } + + func pigeonApiURLCredential(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLCredential + { + return PigeonApiURLCredential( + pigeonRegistrar: registrar, delegate: URLCredentialProxyAPIDelegate()) + } + + func pigeonApiURLProtectionSpace(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLProtectionSpace + { + return PigeonApiURLProtectionSpace( + pigeonRegistrar: registrar, delegate: URLProtectionSpaceProxyAPIDelegate()) + } + + func pigeonApiURLAuthenticationChallenge(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLAuthenticationChallenge + { + return PigeonApiURLAuthenticationChallenge( + pigeonRegistrar: registrar, delegate: URLAuthenticationChallengeProxyAPIDelegate()) + } + + func pigeonApiURL(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiURL { + return PigeonApiURL(pigeonRegistrar: registrar, delegate: URLProxyAPIDelegate()) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageHandlerProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageHandlerProxyAPIDelegate.swift new file mode 100644 index 000000000000..c34018a1ef19 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageHandlerProxyAPIDelegate.swift @@ -0,0 +1,43 @@ +// 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. + +import WebKit + +/// Implementation of `WKScriptMessageHandler` that calls to Dart in callback methods. +class ScriptMessageHandlerImpl: NSObject, WKScriptMessageHandler { + let api: PigeonApiProtocolWKScriptMessageHandler + unowned let registrar: ProxyAPIRegistrar + + init(api: PigeonApiProtocolWKScriptMessageHandler, registrar: ProxyAPIRegistrar) { + self.api = api + self.registrar = registrar + } + + func userContentController( + _ userContentController: WKUserContentController, didReceive message: WKScriptMessage + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.didReceiveScriptMessage( + pigeonInstance: self, controller: userContentController, message: message + ) { result in + if case .failure(let error) = result { + onFailure("WKScriptMessageHandler.didReceiveScriptMessage", error) + } + } + } + } +} + +/// ProxyApi implementation for `WKScriptMessageHandler`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class ScriptMessageHandlerProxyAPIDelegate: PigeonApiDelegateWKScriptMessageHandler { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKScriptMessageHandler) throws + -> WKScriptMessageHandler + { + return ScriptMessageHandlerImpl( + api: pigeonApi, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageProxyAPIDelegate.swift new file mode 100644 index 000000000000..9707b9156be3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScriptMessageProxyAPIDelegate.swift @@ -0,0 +1,19 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKScriptMessage`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class ScriptMessageProxyAPIDelegate: PigeonApiDelegateWKScriptMessage { + func name(pigeonApi: PigeonApiWKScriptMessage, pigeonInstance: WKScriptMessage) throws -> String { + return pigeonInstance.name + } + + func body(pigeonApi: PigeonApiWKScriptMessage, pigeonInstance: WKScriptMessage) throws -> Any? { + return pigeonInstance.body + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewDelegateProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewDelegateProxyAPIDelegate.swift new file mode 100644 index 000000000000..dcbca1356dcd --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewDelegateProxyAPIDelegate.swift @@ -0,0 +1,48 @@ +// 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. + +#if os(iOS) + import UIKit +#endif + +#if os(iOS) + /// Implementation of `UIScrollViewDelegate` that calls to Dart in callback methods. + class ScrollViewDelegateImpl: NSObject, UIScrollViewDelegate { + let api: PigeonApiProtocolUIScrollViewDelegate + unowned let registrar: ProxyAPIRegistrar + + init(api: PigeonApiProtocolUIScrollViewDelegate, registrar: ProxyAPIRegistrar) { + self.api = api + self.registrar = registrar + } + + func scrollViewDidScroll(_ scrollView: UIScrollView) { + registrar.dispatchOnMainThread { onFailure in + self.api.scrollViewDidScroll( + pigeonInstance: self, scrollView: scrollView, x: scrollView.contentOffset.x, + y: scrollView.contentOffset.y + ) { result in + if case .failure(let error) = result { + onFailure("UIScrollViewDelegate.scrollViewDidScroll", error) + } + } + } + } + } +#endif + +/// ProxyApi implementation for `UIScrollViewDelegate`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class ScrollViewDelegateProxyAPIDelegate: PigeonApiDelegateUIScrollViewDelegate { + #if os(iOS) + func pigeonDefaultConstructor(pigeonApi: PigeonApiUIScrollViewDelegate) throws + -> UIScrollViewDelegate + { + return ScrollViewDelegateImpl( + api: pigeonApi, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewProxyAPIDelegate.swift new file mode 100644 index 000000000000..3eec0e7cc48b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ScrollViewProxyAPIDelegate.swift @@ -0,0 +1,42 @@ +// 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. + +#if os(iOS) + import UIKit +#endif + +/// ProxyApi implementation for `UIScrollView`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class ScrollViewProxyAPIDelegate: PigeonApiDelegateUIScrollView { + #if os(iOS) + func getContentOffset(pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView) throws + -> [Double] + { + let offset = pigeonInstance.contentOffset + return [offset.x, offset.y] + } + + func scrollBy( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, x: Double, y: Double + ) throws { + let offset = pigeonInstance.contentOffset + pigeonInstance.contentOffset = CGPoint(x: offset.x + x, y: offset.y + y) + } + + func setContentOffset( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, x: Double, y: Double + ) throws { + pigeonInstance.contentOffset = CGPoint(x: x, y: y) + } + + func setDelegate( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, + delegate: UIScrollViewDelegate? + ) throws { + pigeonInstance.delegate = delegate + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/SecurityOriginProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/SecurityOriginProxyAPIDelegate.swift new file mode 100644 index 000000000000..de02e4bcde1d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/SecurityOriginProxyAPIDelegate.swift @@ -0,0 +1,27 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKSecurityOrigin`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class SecurityOriginProxyAPIDelegate: PigeonApiDelegateWKSecurityOrigin { + func host(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) throws -> String + { + return pigeonInstance.host + } + + func port(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) throws -> Int64 + { + return Int64(pigeonInstance.port) + } + + func securityProtocol(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) + throws -> String + { + return pigeonInstance.protocol + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/StructWrappers.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/StructWrappers.swift new file mode 100644 index 000000000000..a1af899fce41 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/StructWrappers.swift @@ -0,0 +1,17 @@ +// 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. + +import Foundation + +/// Wrapper around `URLRequest`. +/// +/// Since `URLRequest` is a struct, it is pass by value instead of pass by reference. This makes +/// it not possible to modify the properties of a struct with the typical ProxyAPI system. +class URLRequestWrapper { + var value: URLRequest + + init(_ value: URLRequest) { + self.value = value + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIDelegateProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIDelegateProxyAPIDelegate.swift new file mode 100644 index 000000000000..9fe50286e5ce --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIDelegateProxyAPIDelegate.swift @@ -0,0 +1,262 @@ +// 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. + +import WebKit + +/// Implementation of `WKUIDelegate` that calls to Dart in callback methods. +class UIDelegateImpl: NSObject, WKUIDelegate { + let api: PigeonApiProtocolWKUIDelegate + unowned let registrar: ProxyAPIRegistrar + + init(api: PigeonApiProtocolWKUIDelegate, registrar: ProxyAPIRegistrar) { + self.api = api + self.registrar = registrar + } + + func webView( + _ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, + for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures + ) -> WKWebView? { + registrar.dispatchOnMainThread { onFailure in + self.api.onCreateWebView( + pigeonInstance: self, webView: webView, configuration: configuration, + navigationAction: navigationAction + ) { result in + if case .failure(let error) = result { + onFailure("WKUIDelegate.onCreateWebView", error) + } + } + } + return nil + } + + #if compiler(>=6.0) + @available(iOS 15.0, macOS 12.0, *) + func webView( + _ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, + initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, + decisionHandler: @escaping @MainActor (WKPermissionDecision) -> Void + ) { + let wrapperCaptureType: MediaCaptureType + switch type { + case .camera: + wrapperCaptureType = .camera + case .microphone: + wrapperCaptureType = .microphone + case .cameraAndMicrophone: + wrapperCaptureType = .cameraAndMicrophone + @unknown default: + wrapperCaptureType = .unknown + } + + registrar.dispatchOnMainThread { onFailure in + self.api.requestMediaCapturePermission( + pigeonInstance: self, webView: webView, origin: origin, frame: frame, + type: wrapperCaptureType + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let decision): + switch decision { + case .deny: + decisionHandler(.deny) + case .grant: + decisionHandler(.grant) + case .prompt: + decisionHandler(.prompt) + } + case .failure(let error): + decisionHandler(.deny) + onFailure("WKUIDelegate.requestMediaCapturePermission", error) + } + } + } + } + } + #else + @available(iOS 15.0, macOS 12.0, *) + func webView( + _ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, + initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, + decisionHandler: @escaping (WKPermissionDecision) -> Void + ) { + let wrapperCaptureType: MediaCaptureType + switch type { + case .camera: + wrapperCaptureType = .camera + case .microphone: + wrapperCaptureType = .microphone + case .cameraAndMicrophone: + wrapperCaptureType = .cameraAndMicrophone + @unknown default: + wrapperCaptureType = .unknown + } + + registrar.dispatchOnMainThread { onFailure in + self.api.requestMediaCapturePermission( + pigeonInstance: self, webView: webView, origin: origin, frame: frame, + type: wrapperCaptureType + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let decision): + switch decision { + case .deny: + decisionHandler(.deny) + case .grant: + decisionHandler(.grant) + case .prompt: + decisionHandler(.prompt) + } + case .failure(let error): + decisionHandler(.deny) + onFailure("WKUIDelegate.requestMediaCapturePermission", error) + } + } + } + } + } + #endif + + #if compiler(>=6.0) + func webView( + _ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, + initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping @MainActor () -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptAlertPanel( + pigeonInstance: self, webView: webView, message: message, frame: frame + ) { result in + DispatchQueue.main.async { + if case .failure(let error) = result { + onFailure("WKUIDelegate.runJavaScriptAlertPanel", error) + } + completionHandler() + } + } + } + } + #else + func webView( + _ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, + initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptAlertPanel( + pigeonInstance: self, webView: webView, message: message, frame: frame + ) { result in + DispatchQueue.main.async { + if case .failure(let error) = result { + onFailure("WKUIDelegate.runJavaScriptAlertPanel", error) + } + completionHandler() + } + } + } + } + #endif + + #if compiler(>=6.0) + func webView( + _ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, + initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping @MainActor (Bool) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptConfirmPanel( + pigeonInstance: self, webView: webView, message: message, frame: frame + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let confirmed): + completionHandler(confirmed) + case .failure(let error): + completionHandler(false) + onFailure("WKUIDelegate.runJavaScriptConfirmPanel", error) + } + } + } + } + } + #else + func webView( + _ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, + initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptConfirmPanel( + pigeonInstance: self, webView: webView, message: message, frame: frame + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let confirmed): + completionHandler(confirmed) + case .failure(let error): + completionHandler(false) + onFailure("WKUIDelegate.runJavaScriptConfirmPanel", error) + } + } + } + } + } + #endif + + #if compiler(>=6.0) + func webView( + _ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, + defaultText: String?, initiatedByFrame frame: WKFrameInfo, + completionHandler: @escaping @MainActor (String?) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptTextInputPanel( + pigeonInstance: self, webView: webView, prompt: prompt, defaultText: defaultText, + frame: frame + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let response): + completionHandler(response) + case .failure(let error): + completionHandler(nil) + onFailure("WKUIDelegate.runJavaScriptTextInputPanel", error) + } + } + } + } + } + #else + func webView( + _ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, + defaultText: String?, initiatedByFrame frame: WKFrameInfo, + completionHandler: @escaping (String?) -> Void + ) { + registrar.dispatchOnMainThread { onFailure in + self.api.runJavaScriptTextInputPanel( + pigeonInstance: self, webView: webView, prompt: prompt, defaultText: defaultText, + frame: frame + ) { result in + DispatchQueue.main.async { + switch result { + case .success(let response): + completionHandler(response) + case .failure(let error): + completionHandler(nil) + onFailure("WKUIDelegate.runJavaScriptTextInputPanel", error) + } + } + } + } + } + #endif +} + +/// ProxyApi implementation for `WKUIDelegate`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class UIDelegateProxyAPIDelegate: PigeonApiDelegateWKUIDelegate { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKUIDelegate) throws -> WKUIDelegate { + return UIDelegateImpl( + api: pigeonApi, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIViewProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIViewProxyAPIDelegate.swift new file mode 100644 index 000000000000..6ebc5589f138 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UIViewProxyAPIDelegate.swift @@ -0,0 +1,34 @@ +// 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. + +#if os(iOS) + import UIKit +#endif + +/// ProxyApi implementation for `UIView`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class UIViewProxyAPIDelegate: PigeonApiDelegateUIView { + #if os(iOS) + func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: Int64?) + throws + { + if value == nil { + pigeonInstance.backgroundColor = nil + } else { + let red = CGFloat(Double((value! >> 16 & 0xff)) / 255.0) + let green = CGFloat(Double(value! >> 8 & 0xff) / 255.0) + let blue = CGFloat(Double(value! & 0xff) / 255.0) + let alpha = CGFloat(Double(value! >> 24 & 0xff) / 255.0) + + pigeonInstance.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: alpha) + } + } + + func setOpaque(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, opaque: Bool) throws { + pigeonInstance.isOpaque = opaque + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLAuthenticationChallengeProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLAuthenticationChallengeProxyAPIDelegate.swift new file mode 100644 index 000000000000..b934e467d7b4 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLAuthenticationChallengeProxyAPIDelegate.swift @@ -0,0 +1,17 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `URLAuthenticationChallenge`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class URLAuthenticationChallengeProxyAPIDelegate: PigeonApiDelegateURLAuthenticationChallenge { + func getProtectionSpace( + pigeonApi: PigeonApiURLAuthenticationChallenge, pigeonInstance: URLAuthenticationChallenge + ) throws -> URLProtectionSpace { + return pigeonInstance.protectionSpace + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLCredentialProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLCredentialProxyAPIDelegate.swift new file mode 100644 index 000000000000..d19f89bc3346 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLCredentialProxyAPIDelegate.swift @@ -0,0 +1,29 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `URLCredential`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class URLCredentialProxyAPIDelegate: PigeonApiDelegateURLCredential { + func withUser( + pigeonApi: PigeonApiURLCredential, user: String, password: String, + persistence: UrlCredentialPersistence + ) throws -> URLCredential { + let nativePersistence: URLCredential.Persistence + switch persistence { + case .none: + nativePersistence = .none + case .forSession: + nativePersistence = .forSession + case .permanent: + nativePersistence = .permanent + case .synchronizable: + nativePersistence = .synchronizable + } + return URLCredential(user: user, password: password, persistence: nativePersistence) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProtectionSpaceProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProtectionSpaceProxyAPIDelegate.swift new file mode 100644 index 000000000000..d7c59c67f287 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProtectionSpaceProxyAPIDelegate.swift @@ -0,0 +1,35 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `URLProtectionSpace`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class URLProtectionSpaceProxyAPIDelegate: PigeonApiDelegateURLProtectionSpace { + func host(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> String + { + return pigeonInstance.host + } + + func port(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> Int64 + { + return Int64(pigeonInstance.port) + } + + func realm(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> String? + { + return pigeonInstance.realm + } + + func authenticationMethod( + pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace + ) throws -> String? { + return pigeonInstance.authenticationMethod + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProxyAPIDelegate.swift new file mode 100644 index 000000000000..61fb522a3d1f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLProxyAPIDelegate.swift @@ -0,0 +1,15 @@ +// 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. + +import Foundation + +/// ProxyApi implementation for `URL`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class URLProxyAPIDelegate: PigeonApiDelegateURL { + func getAbsoluteString(pigeonApi: PigeonApiURL, pigeonInstance: URL) throws -> String { + return pigeonInstance.absoluteString + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLRequestProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLRequestProxyAPIDelegate.swift new file mode 100644 index 000000000000..62cb3ccf7d33 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/URLRequestProxyAPIDelegate.swift @@ -0,0 +1,78 @@ +// 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. + +import Foundation + +#if os(iOS) + import Flutter + import UIKit +#elseif os(macOS) + import FlutterMacOS + import Foundation +#else + #error("Unsupported platform.") +#endif + +/// ProxyApi implementation for `URLRequest`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class URLRequestProxyAPIDelegate: PigeonApiDelegateURLRequest { + func pigeonDefaultConstructor(pigeonApi: PigeonApiURLRequest, url: String) throws + -> URLRequestWrapper + { + let urlObject = URL(string: url) + if let urlObject = urlObject { + return URLRequestWrapper(URLRequest(url: urlObject)) + } else { + let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar + throw registrar.createConstructorNullError(type: NSURL.self, parameters: ["string": url]) + } + } + + func setHttpMethod( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, method: String? + ) throws { + pigeonInstance.value.httpMethod = method + } + + func setHttpBody( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, + body: FlutterStandardTypedData? + ) throws { + pigeonInstance.value.httpBody = body?.data + } + + func setAllHttpHeaderFields( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, fields: [String: String]? + ) throws { + pigeonInstance.value.allHTTPHeaderFields = fields + } + + func getUrl(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws -> String? { + return pigeonInstance.value.url?.absoluteString + } + + func getHttpMethod(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws + -> String? + { + return pigeonInstance.value.httpMethod + } + + func getHttpBody(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws + -> FlutterStandardTypedData? + { + if let httpBody = pigeonInstance.value.httpBody { + return FlutterStandardTypedData(bytes: httpBody) + } + + return nil + } + + func getAllHttpHeaderFields(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) + throws -> [String: String]? + { + return pigeonInstance.value.allHTTPHeaderFields + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserContentControllerProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserContentControllerProxyAPIDelegate.swift new file mode 100644 index 000000000000..c5cd9eedf7b3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserContentControllerProxyAPIDelegate.swift @@ -0,0 +1,51 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKUserContentController`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class UserContentControllerProxyAPIDelegate: PigeonApiDelegateWKUserContentController { + func addScriptMessageHandler( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + handler: WKScriptMessageHandler, name: String + ) throws { + pigeonInstance.add(handler, name: name) + } + + func removeScriptMessageHandler( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + name: String + ) throws { + pigeonInstance.removeScriptMessageHandler(forName: name) + } + + func removeAllScriptMessageHandlers( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController + ) throws { + if #available(iOS 14.0, macOS 11.0, *) { + pigeonInstance.removeAllScriptMessageHandlers() + } else { + throw (pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + .createUnsupportedVersionError( + method: "WKUserContentController.removeAllScriptMessageHandlers", + versionRequirements: "iOS 14.0, macOS 11.0") + } + } + + func addUserScript( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + userScript: WKUserScript + ) throws { + pigeonInstance.addUserScript(userScript) + } + + func removeAllUserScripts( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController + ) throws { + pigeonInstance.removeAllUserScripts() + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserScriptProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserScriptProxyAPIDelegate.swift new file mode 100644 index 000000000000..9cd0ae1ea087 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/UserScriptProxyAPIDelegate.swift @@ -0,0 +1,52 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKUserScript`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class UserScriptProxyAPIDelegate: PigeonApiDelegateWKUserScript { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiWKUserScript, source: String, injectionTime: UserScriptInjectionTime, + isForMainFrameOnly: Bool + ) throws -> WKUserScript { + var nativeInjectionTime: WKUserScriptInjectionTime + switch injectionTime { + case .atDocumentStart: + nativeInjectionTime = .atDocumentStart + case .atDocumentEnd: + nativeInjectionTime = .atDocumentEnd + case .unknown: + throw (pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar).createUnknownEnumError( + withEnum: injectionTime) + } + return WKUserScript( + source: source, injectionTime: nativeInjectionTime, forMainFrameOnly: isForMainFrameOnly) + } + + func source(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws -> String { + return pigeonInstance.source + } + + func injectionTime(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws + -> UserScriptInjectionTime + { + switch pigeonInstance.injectionTime { + case .atDocumentStart: + return .atDocumentStart + case .atDocumentEnd: + return .atDocumentEnd + @unknown default: + return .unknown + } + } + + func isForMainFrameOnly(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws + -> Bool + { + return pigeonInstance.isForMainFrameOnly + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift new file mode 100644 index 000000000000..27d3a1bed774 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift @@ -0,0 +1,6683 @@ +// 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 (v22.7.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +import WebKit + +#if os(iOS) + import UIKit +#endif + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details, + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)", + ] +} + +private func createConnectionError(withChannelName channelName: String) -> PigeonError { + return PigeonError( + code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", + details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} +/// Handles the callback when an object is deallocated. +protocol WebKitLibraryPigeonInternalFinalizerDelegate: AnyObject { + /// Invoked when the strong reference of an object is deallocated in an `InstanceManager`. + func onDeinit(identifier: Int64) +} + +// Attaches to an object to receive a callback when the object is deallocated. +internal final class WebKitLibraryPigeonInternalFinalizer { + private static let associatedObjectKey = malloc(1)! + + private let identifier: Int64 + // Reference to the delegate is weak because the callback should be ignored if the + // `InstanceManager` is deallocated. + private weak var delegate: WebKitLibraryPigeonInternalFinalizerDelegate? + + private init(identifier: Int64, delegate: WebKitLibraryPigeonInternalFinalizerDelegate) { + self.identifier = identifier + self.delegate = delegate + } + + internal static func attach( + to instance: AnyObject, identifier: Int64, + delegate: WebKitLibraryPigeonInternalFinalizerDelegate + ) { + let finalizer = WebKitLibraryPigeonInternalFinalizer(identifier: identifier, delegate: delegate) + objc_setAssociatedObject(instance, associatedObjectKey, finalizer, .OBJC_ASSOCIATION_RETAIN) + } + + static func detach(from instance: AnyObject) { + objc_setAssociatedObject(instance, associatedObjectKey, nil, .OBJC_ASSOCIATION_ASSIGN) + } + + deinit { + delegate?.onDeinit(identifier: identifier) + } +} + +/// Maintains instances used to communicate with the corresponding objects in Dart. +/// +/// Objects stored in this container are represented by an object in Dart that is also stored in +/// an InstanceManager with the same identifier. +/// +/// When an instance is added with an identifier, either can be used to retrieve the other. +/// +/// Added instances are added as a weak reference and a strong reference. When the strong +/// reference is removed and the weak reference is deallocated,`WebKitLibraryPigeonInternalFinalizerDelegate.onDeinit` +/// is called with the instance's identifier. However, if the strong reference is removed and then the identifier is +/// retrieved with the intention to pass the identifier to Dart (e.g. by calling `identifierWithStrongReference`), +/// the strong reference to the instance is re-added. The strong reference will then need to be removed manually +/// again. +/// +/// Accessing and inserting to an InstanceManager is thread safe. +final class WebKitLibraryPigeonInstanceManager { + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously from Dart. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + private static let minHostCreatedIdentifier: Int64 = 65536 + + private let lockQueue = DispatchQueue(label: "WebKitLibraryPigeonInstanceManager") + private let identifiers: NSMapTable = NSMapTable( + keyOptions: [.weakMemory, .objectPointerPersonality], valueOptions: .strongMemory) + private let weakInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.weakMemory, .objectPointerPersonality]) + private let strongInstances: NSMapTable = NSMapTable( + keyOptions: .strongMemory, valueOptions: [.strongMemory, .objectPointerPersonality]) + private let finalizerDelegate: WebKitLibraryPigeonInternalFinalizerDelegate + private var nextIdentifier: Int64 = minHostCreatedIdentifier + + public init(finalizerDelegate: WebKitLibraryPigeonInternalFinalizerDelegate) { + self.finalizerDelegate = finalizerDelegate + } + + /// Adds a new instance that was instantiated from Dart. + /// + /// The same instance can be added multiple times, but each identifier must be unique. This allows + /// two objects that are equivalent (e.g. conforms to `Equatable`) to both be added. + /// + /// - Parameters: + /// - instance: the instance to be stored + /// - identifier: the identifier to be paired with instance. This value must be >= 0 and unique + func addDartCreatedInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + lockQueue.async { + self.addInstance(instance, withIdentifier: identifier) + } + } + + /// Adds a new instance that was instantiated from the host platform. + /// + /// - Parameters: + /// - instance: the instance to be stored. This must be unique to all other added instances. + /// - Returns: the unique identifier (>= 0) stored with instance + func addHostCreatedInstance(_ instance: AnyObject) -> Int64 { + assert(!containsInstance(instance), "Instance of \(instance) has already been added.") + var identifier: Int64 = -1 + lockQueue.sync { + identifier = nextIdentifier + nextIdentifier += 1 + self.addInstance(instance, withIdentifier: identifier) + } + return identifier + } + + /// Removes `instanceIdentifier` and its associated strongly referenced instance, if present, from the manager. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier paired to an instance. + /// - Returns: removed instance if the manager contains the given identifier, otherwise `nil` if + /// the manager doesn't contain the value + func removeInstance(withIdentifier instanceIdentifier: Int64) throws -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = strongInstances.object(forKey: NSNumber(value: instanceIdentifier)) + strongInstances.removeObject(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + /// Retrieves the instance associated with identifier. + /// + /// - Parameters: + /// - instanceIdentifier: the identifier associated with an instance + /// - Returns: the instance associated with `instanceIdentifier` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func instance(forIdentifier instanceIdentifier: Int64) -> T? { + var instance: AnyObject? = nil + lockQueue.sync { + instance = weakInstances.object(forKey: NSNumber(value: instanceIdentifier)) + } + return instance as? T + } + + private func addInstance(_ instance: AnyObject, withIdentifier identifier: Int64) { + assert(identifier >= 0) + assert( + weakInstances.object(forKey: identifier as NSNumber) == nil, + "Identifier has already been added: \(identifier)") + identifiers.setObject(NSNumber(value: identifier), forKey: instance) + weakInstances.setObject(instance, forKey: NSNumber(value: identifier)) + strongInstances.setObject(instance, forKey: NSNumber(value: identifier)) + WebKitLibraryPigeonInternalFinalizer.attach( + to: instance, identifier: identifier, delegate: finalizerDelegate) + } + + /// Retrieves the identifier paired with an instance. + /// + /// If the manager contains a strong reference to `instance`, it will return the identifier + /// associated with `instance`. If the manager contains only a weak reference to `instance`, a new + /// strong reference to `instance` will be added and will need to be removed again with `removeInstance`. + /// + /// If this method returns a nonnull identifier, this method also expects the Dart + /// `WebKitLibraryPigeonInstanceManager` to have, or recreate, a weak reference to the Dart instance the + /// identifier is associated with. + /// + /// - Parameters: + /// - instance: an instance that may be stored in the manager + /// - Returns: the identifier associated with `instance` if the manager contains the value, otherwise + /// `nil` if the manager doesn't contain the value + func identifierWithStrongReference(forInstance instance: AnyObject) -> Int64? { + var identifier: Int64? = nil + lockQueue.sync { + if let existingIdentifier = identifiers.object(forKey: instance)?.int64Value { + strongInstances.setObject(instance, forKey: NSNumber(value: existingIdentifier)) + identifier = existingIdentifier + } + } + return identifier + } + + /// Whether this manager contains the given `instance`. + /// + /// - Parameters: + /// - instance: the instance whose presence in this manager is to be tested + /// - Returns: whether this manager contains the given `instance` + func containsInstance(_ instance: AnyObject) -> Bool { + var containsInstance = false + lockQueue.sync { + containsInstance = identifiers.object(forKey: instance) != nil + } + return containsInstance + } + + /// Removes all of the instances from this manager. + /// + /// The manager will be empty after this call returns. + func removeAllObjects() throws { + lockQueue.sync { + identifiers.removeAllObjects() + weakInstances.removeAllObjects() + strongInstances.removeAllObjects() + nextIdentifier = WebKitLibraryPigeonInstanceManager.minHostCreatedIdentifier + } + } + + /// The number of instances stored as a strong reference. + /// + /// For debugging and testing purposes. + internal var strongInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = strongInstances.count + } + return count + } + + /// The number of instances stored as a weak reference. + /// + /// For debugging and testing purposes. NSMapTables that store keys or objects as weak + /// reference will be reclaimed non-deterministically. + internal var weakInstanceCount: Int { + var count: Int = 0 + lockQueue.sync { + count = weakInstances.count + } + return count + } +} + +private class WebKitLibraryPigeonInstanceManagerApi { + /// The codec used for serializing messages. + var codec: FlutterStandardMessageCodec { WebKitLibraryPigeonCodec.shared } + + /// Handles sending and receiving messages with Dart. + unowned let binaryMessenger: FlutterBinaryMessenger + + init(binaryMessenger: FlutterBinaryMessenger) { + self.binaryMessenger = binaryMessenger + } + + /// Sets up an instance of `WebKitLibraryPigeonInstanceManagerApi` to handle messages through the `binaryMessenger`. + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, instanceManager: WebKitLibraryPigeonInstanceManager? + ) { + let codec = WebKitLibraryPigeonCodec.shared + let removeStrongReferenceChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + removeStrongReferenceChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let identifierArg = args[0] as! Int64 + do { + let _: AnyObject? = try instanceManager.removeInstance(withIdentifier: identifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeStrongReferenceChannel.setMessageHandler(nil) + } + let clearChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.clear", + binaryMessenger: binaryMessenger, codec: codec) + if let instanceManager = instanceManager { + clearChannel.setMessageHandler { _, reply in + do { + try instanceManager.removeAllObjects() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + clearChannel.setMessageHandler(nil) + } + } + + /// Sends a message to the Dart `InstanceManager` to remove the strong reference of the instance associated with `identifier`. + func removeStrongReference( + identifier identifierArg: Int64, completion: @escaping (Result) -> Void + ) { + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([identifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol WebKitLibraryPigeonProxyApiDelegate { + /// An implementation of [PigeonApiURLRequest] used to add a new Dart instance of + /// `URLRequest` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURLRequest(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiURLRequest + /// An implementation of [PigeonApiHTTPURLResponse] used to add a new Dart instance of + /// `HTTPURLResponse` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiHTTPURLResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiHTTPURLResponse + /// An implementation of [PigeonApiURLResponse] used to add a new Dart instance of + /// `URLResponse` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURLResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLResponse + /// An implementation of [PigeonApiWKUserScript] used to add a new Dart instance of + /// `WKUserScript` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKUserScript(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUserScript + /// An implementation of [PigeonApiWKNavigationAction] used to add a new Dart instance of + /// `WKNavigationAction` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKNavigationAction(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationAction + /// An implementation of [PigeonApiWKNavigationResponse] used to add a new Dart instance of + /// `WKNavigationResponse` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKNavigationResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationResponse + /// An implementation of [PigeonApiWKFrameInfo] used to add a new Dart instance of + /// `WKFrameInfo` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKFrameInfo(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKFrameInfo + /// An implementation of [PigeonApiNSError] used to add a new Dart instance of + /// `NSError` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiNSError(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiNSError + /// An implementation of [PigeonApiWKScriptMessage] used to add a new Dart instance of + /// `WKScriptMessage` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKScriptMessage(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKScriptMessage + /// An implementation of [PigeonApiWKSecurityOrigin] used to add a new Dart instance of + /// `WKSecurityOrigin` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKSecurityOrigin(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKSecurityOrigin + /// An implementation of [PigeonApiHTTPCookie] used to add a new Dart instance of + /// `HTTPCookie` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiHTTPCookie(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiHTTPCookie + /// An implementation of [PigeonApiAuthenticationChallengeResponse] used to add a new Dart instance of + /// `AuthenticationChallengeResponse` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiAuthenticationChallengeResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiAuthenticationChallengeResponse + /// An implementation of [PigeonApiWKWebsiteDataStore] used to add a new Dart instance of + /// `WKWebsiteDataStore` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKWebsiteDataStore(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKWebsiteDataStore + /// An implementation of [PigeonApiUIView] used to add a new Dart instance of + /// `UIView` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiUIView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiUIView + /// An implementation of [PigeonApiUIScrollView] used to add a new Dart instance of + /// `UIScrollView` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiUIScrollView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIScrollView + /// An implementation of [PigeonApiWKWebViewConfiguration] used to add a new Dart instance of + /// `WKWebViewConfiguration` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKWebViewConfiguration(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKWebViewConfiguration + /// An implementation of [PigeonApiWKUserContentController] used to add a new Dart instance of + /// `WKUserContentController` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKUserContentController(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUserContentController + /// An implementation of [PigeonApiWKPreferences] used to add a new Dart instance of + /// `WKPreferences` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKPreferences(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKPreferences + /// An implementation of [PigeonApiWKScriptMessageHandler] used to add a new Dart instance of + /// `WKScriptMessageHandler` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKScriptMessageHandler(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKScriptMessageHandler + /// An implementation of [PigeonApiWKNavigationDelegate] used to add a new Dart instance of + /// `WKNavigationDelegate` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKNavigationDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKNavigationDelegate + /// An implementation of [PigeonApiNSObject] used to add a new Dart instance of + /// `NSObject` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiNSObject(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiNSObject + /// An implementation of [PigeonApiUIViewWKWebView] used to add a new Dart instance of + /// `UIViewWKWebView` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiUIViewWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIViewWKWebView + /// An implementation of [PigeonApiNSViewWKWebView] used to add a new Dart instance of + /// `NSViewWKWebView` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiNSViewWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiNSViewWKWebView + /// An implementation of [PigeonApiWKWebView] used to add a new Dart instance of + /// `WKWebView` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiWKWebView + /// An implementation of [PigeonApiWKUIDelegate] used to add a new Dart instance of + /// `WKUIDelegate` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKUIDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKUIDelegate + /// An implementation of [PigeonApiWKHTTPCookieStore] used to add a new Dart instance of + /// `WKHTTPCookieStore` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiWKHTTPCookieStore(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiWKHTTPCookieStore + /// An implementation of [PigeonApiUIScrollViewDelegate] used to add a new Dart instance of + /// `UIScrollViewDelegate` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiUIScrollViewDelegate(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiUIScrollViewDelegate + /// An implementation of [PigeonApiURLCredential] used to add a new Dart instance of + /// `URLCredential` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURLCredential(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLCredential + /// An implementation of [PigeonApiURLProtectionSpace] used to add a new Dart instance of + /// `URLProtectionSpace` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURLProtectionSpace(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLProtectionSpace + /// An implementation of [PigeonApiURLAuthenticationChallenge] used to add a new Dart instance of + /// `URLAuthenticationChallenge` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURLAuthenticationChallenge(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLAuthenticationChallenge + /// An implementation of [PigeonApiURL] used to add a new Dart instance of + /// `URL` to the Dart `InstanceManager` and make calls to Dart. + func pigeonApiURL(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiURL +} + +extension WebKitLibraryPigeonProxyApiDelegate { + func pigeonApiURLResponse(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) + -> PigeonApiURLResponse + { + return PigeonApiURLResponse( + pigeonRegistrar: registrar, delegate: PigeonApiDelegateURLResponse()) + } + func pigeonApiWKWebView(_ registrar: WebKitLibraryPigeonProxyApiRegistrar) -> PigeonApiWKWebView { + return PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: PigeonApiDelegateWKWebView()) + } +} + +open class WebKitLibraryPigeonProxyApiRegistrar { + let binaryMessenger: FlutterBinaryMessenger + let apiDelegate: WebKitLibraryPigeonProxyApiDelegate + let instanceManager: WebKitLibraryPigeonInstanceManager + /// Whether APIs should ignore calling to Dart. + public var ignoreCallsToDart = false + private var _codec: FlutterStandardMessageCodec? + var codec: FlutterStandardMessageCodec { + if _codec == nil { + _codec = FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter(pigeonRegistrar: self)) + } + return _codec! + } + + private class InstanceManagerApiFinalizerDelegate: WebKitLibraryPigeonInternalFinalizerDelegate { + let api: WebKitLibraryPigeonInstanceManagerApi + + init(_ api: WebKitLibraryPigeonInstanceManagerApi) { + self.api = api + } + + public func onDeinit(identifier: Int64) { + api.removeStrongReference(identifier: identifier) { + _ in + } + } + } + + init(binaryMessenger: FlutterBinaryMessenger, apiDelegate: WebKitLibraryPigeonProxyApiDelegate) { + self.binaryMessenger = binaryMessenger + self.apiDelegate = apiDelegate + self.instanceManager = WebKitLibraryPigeonInstanceManager( + finalizerDelegate: InstanceManagerApiFinalizerDelegate( + WebKitLibraryPigeonInstanceManagerApi(binaryMessenger: binaryMessenger))) + } + + func setUp() { + WebKitLibraryPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: instanceManager) + PigeonApiURLRequest.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiURLRequest(self)) + PigeonApiWKUserScript.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKUserScript(self)) + PigeonApiHTTPCookie.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiHTTPCookie(self)) + PigeonApiAuthenticationChallengeResponse.setUpMessageHandlers( + binaryMessenger: binaryMessenger, + api: apiDelegate.pigeonApiAuthenticationChallengeResponse(self)) + PigeonApiWKWebsiteDataStore.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKWebsiteDataStore(self)) + PigeonApiUIView.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiUIView(self)) + PigeonApiUIScrollView.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiUIScrollView(self)) + PigeonApiWKWebViewConfiguration.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKWebViewConfiguration(self)) + PigeonApiWKUserContentController.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKUserContentController(self)) + PigeonApiWKPreferences.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKPreferences(self)) + PigeonApiWKScriptMessageHandler.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKScriptMessageHandler(self)) + PigeonApiWKNavigationDelegate.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKNavigationDelegate(self)) + PigeonApiNSObject.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiNSObject(self)) + PigeonApiUIViewWKWebView.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiUIViewWKWebView(self)) + PigeonApiNSViewWKWebView.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiNSViewWKWebView(self)) + PigeonApiWKUIDelegate.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKUIDelegate(self)) + PigeonApiWKHTTPCookieStore.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiWKHTTPCookieStore(self)) + PigeonApiUIScrollViewDelegate.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiUIScrollViewDelegate(self)) + PigeonApiURLCredential.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiURLCredential(self)) + PigeonApiURLAuthenticationChallenge.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiURLAuthenticationChallenge(self)) + PigeonApiURL.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: apiDelegate.pigeonApiURL(self)) + } + func tearDown() { + WebKitLibraryPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger: binaryMessenger, instanceManager: nil) + PigeonApiURLRequest.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKUserScript.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiHTTPCookie.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiAuthenticationChallengeResponse.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKWebsiteDataStore.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiUIView.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiUIScrollView.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKWebViewConfiguration.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKUserContentController.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKPreferences.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKScriptMessageHandler.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKNavigationDelegate.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiNSObject.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiUIViewWKWebView.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiNSViewWKWebView.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKUIDelegate.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiWKHTTPCookieStore.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiUIScrollViewDelegate.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiURLCredential.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + PigeonApiURLAuthenticationChallenge.setUpMessageHandlers( + binaryMessenger: binaryMessenger, api: nil) + PigeonApiURL.setUpMessageHandlers(binaryMessenger: binaryMessenger, api: nil) + } +} +private class WebKitLibraryPigeonInternalProxyApiCodecReaderWriter: FlutterStandardReaderWriter { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + + private class WebKitLibraryPigeonInternalProxyApiCodecReader: WebKitLibraryPigeonCodecReader { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + + init(data: Data, pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + let identifier = self.readValue() + let instance: AnyObject? = pigeonRegistrar.instanceManager.instance( + forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32)) + return instance + default: + return super.readValue(ofType: type) + } + } + } + + private class WebKitLibraryPigeonInternalProxyApiCodecWriter: WebKitLibraryPigeonCodecWriter { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + + init(data: NSMutableData, pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + super.init(data: data) + } + + override func writeValue(_ value: Any) { + if value is [Any] || value is Bool || value is Data || value is [AnyHashable: Any] + || value is Double || value is FlutterStandardTypedData || value is Int64 || value is String + || value is KeyValueObservingOptions || value is KeyValueChange + || value is KeyValueChangeKey || value is UserScriptInjectionTime + || value is AudiovisualMediaType || value is WebsiteDataType + || value is NavigationActionPolicy || value is NavigationResponsePolicy + || value is HttpCookiePropertyKey || value is NavigationType || value is PermissionDecision + || value is MediaCaptureType || value is UrlSessionAuthChallengeDisposition + || value is UrlCredentialPersistence + { + super.writeValue(value) + return + } + + if let instance = value as? URLRequestWrapper { + pigeonRegistrar.apiDelegate.pigeonApiURLRequest(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? HTTPURLResponse { + pigeonRegistrar.apiDelegate.pigeonApiHTTPURLResponse(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? URLResponse { + pigeonRegistrar.apiDelegate.pigeonApiURLResponse(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKUserScript { + pigeonRegistrar.apiDelegate.pigeonApiWKUserScript(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKNavigationAction { + pigeonRegistrar.apiDelegate.pigeonApiWKNavigationAction(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKNavigationResponse { + pigeonRegistrar.apiDelegate.pigeonApiWKNavigationResponse(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKFrameInfo { + pigeonRegistrar.apiDelegate.pigeonApiWKFrameInfo(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? NSError { + pigeonRegistrar.apiDelegate.pigeonApiNSError(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKScriptMessage { + pigeonRegistrar.apiDelegate.pigeonApiWKScriptMessage(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKSecurityOrigin { + pigeonRegistrar.apiDelegate.pigeonApiWKSecurityOrigin(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? HTTPCookie { + pigeonRegistrar.apiDelegate.pigeonApiHTTPCookie(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? AuthenticationChallengeResponse { + pigeonRegistrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKWebsiteDataStore { + pigeonRegistrar.apiDelegate.pigeonApiWKWebsiteDataStore(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + #if !os(macOS) + if let instance = value as? UIScrollView { + pigeonRegistrar.apiDelegate.pigeonApiUIScrollView(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + #endif + + if let instance = value as? WKWebViewConfiguration { + pigeonRegistrar.apiDelegate.pigeonApiWKWebViewConfiguration(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKUserContentController { + pigeonRegistrar.apiDelegate.pigeonApiWKUserContentController(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKPreferences { + pigeonRegistrar.apiDelegate.pigeonApiWKPreferences(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKScriptMessageHandler { + pigeonRegistrar.apiDelegate.pigeonApiWKScriptMessageHandler(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKNavigationDelegate { + pigeonRegistrar.apiDelegate.pigeonApiWKNavigationDelegate(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + #if !os(macOS) + if let instance = value as? WKWebView { + pigeonRegistrar.apiDelegate.pigeonApiUIViewWKWebView(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + #endif + #if !os(macOS) + if let instance = value as? UIView { + pigeonRegistrar.apiDelegate.pigeonApiUIView(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + #endif + #if !os(iOS) + if let instance = value as? WKWebView { + pigeonRegistrar.apiDelegate.pigeonApiNSViewWKWebView(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + #endif + + if let instance = value as? WKWebView { + pigeonRegistrar.apiDelegate.pigeonApiWKWebView(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKUIDelegate { + pigeonRegistrar.apiDelegate.pigeonApiWKUIDelegate(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? WKHTTPCookieStore { + pigeonRegistrar.apiDelegate.pigeonApiWKHTTPCookieStore(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + #if !os(macOS) + if let instance = value as? UIScrollViewDelegate { + pigeonRegistrar.apiDelegate.pigeonApiUIScrollViewDelegate(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + #endif + + if let instance = value as? URLCredential { + pigeonRegistrar.apiDelegate.pigeonApiURLCredential(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? URLProtectionSpace { + pigeonRegistrar.apiDelegate.pigeonApiURLProtectionSpace(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? URLAuthenticationChallenge { + pigeonRegistrar.apiDelegate.pigeonApiURLAuthenticationChallenge(pigeonRegistrar) + .pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? URL { + pigeonRegistrar.apiDelegate.pigeonApiURL(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as? NSObject { + pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar).pigeonNewInstance( + pigeonInstance: instance + ) { _ in } + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference( + forInstance: instance as AnyObject)!) + return + } + + if let instance = value as AnyObject?, + pigeonRegistrar.instanceManager.containsInstance(instance) + { + super.writeByte(128) + super.writeValue( + pigeonRegistrar.instanceManager.identifierWithStrongReference(forInstance: instance)!) + } else { + print("Unsupported value: \(value) of \(type(of: value))") + assert(false, "Unsupported value for WebKitLibraryPigeonInternalProxyApiCodecWriter") + } + + } + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar) { + self.pigeonRegistrar = pigeonRegistrar + } + + override func reader(with data: Data) -> FlutterStandardReader { + return WebKitLibraryPigeonInternalProxyApiCodecReader( + data: data, pigeonRegistrar: pigeonRegistrar) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return WebKitLibraryPigeonInternalProxyApiCodecWriter( + data: data, pigeonRegistrar: pigeonRegistrar) + } +} + +/// The values that can be returned in a change dictionary. +/// +/// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions. +enum KeyValueObservingOptions: Int { + /// Indicates that the change dictionary should provide the new attribute + /// value, if applicable. + case newValue = 0 + /// Indicates that the change dictionary should contain the old attribute + /// value, if applicable. + case oldValue = 1 + /// If specified, a notification should be sent to the observer immediately, + /// before the observer registration method even returns. + case initialValue = 2 + /// Whether separate notifications should be sent to the observer before and + /// after each change, instead of a single notification after the change. + case priorNotification = 3 +} + +/// The kinds of changes that can be observed. +/// +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange. +enum KeyValueChange: Int { + /// Indicates that the value of the observed key path was set to a new value. + case setting = 0 + /// Indicates that an object has been inserted into the to-many relationship + /// that is being observed. + case insertion = 1 + /// Indicates that an object has been removed from the to-many relationship + /// that is being observed. + case removal = 2 + /// Indicates that an object has been replaced in the to-many relationship + /// that is being observed. + case replacement = 3 + /// The value is not recognized by the wrapper. + case unknown = 4 +} + +/// The keys that can appear in the change dictionary. +/// +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey. +enum KeyValueChangeKey: Int { + /// If the value of the `KeyValueChangeKey.kind` entry is + /// `KeyValueChange.insertion`, `KeyValueChange.removal`, or + /// `KeyValueChange.replacement`, the value of this key is a Set object that + /// contains the indexes of the inserted, removed, or replaced objects. + case indexes = 0 + /// An object that contains a value corresponding to one of the + /// `KeyValueChange` enum, indicating what sort of change has occurred. + case kind = 1 + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting, and `KeyValueObservingOptions.newValue` was + /// specified when the observer was registered, the value of this key is the + /// new value for the attribute. + case newValue = 2 + /// If the `KeyValueObservingOptions.priorNotification` option was specified + /// when the observer was registered this notification is sent prior to a + /// change. + case notificationIsPrior = 3 + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting`, and `KeyValueObservingOptions.old` was specified + /// when the observer was registered, the value of this key is the value + /// before the attribute was changed. + case oldValue = 4 + /// The value is not recognized by the wrapper. + case unknown = 5 +} + +/// Constants for the times at which to inject script content into a webpage. +/// +/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime. +enum UserScriptInjectionTime: Int { + /// A constant to inject the script after the creation of the webpage’s + /// document element, but before loading any other content. + case atDocumentStart = 0 + /// A constant to inject the script after the document finishes loading, but + /// before loading any other subresources. + case atDocumentEnd = 1 + /// The value is not recognized by the wrapper. + case unknown = 2 +} + +/// The media types that require a user gesture to begin playing. +/// +/// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes. +enum AudiovisualMediaType: Int { + /// No media types require a user gesture to begin playing. + case none = 0 + /// Media types that contain audio require a user gesture to begin playing. + case audio = 1 + /// Media types that contain video require a user gesture to begin playing. + case video = 2 + /// All media types require a user gesture to begin playing. + case all = 3 +} + +/// A `WKWebsiteDataRecord` object includes these constants in its dataTypes +/// property. +/// +/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types. +enum WebsiteDataType: Int { + /// Cookies. + case cookies = 0 + /// In-memory caches. + case memoryCache = 1 + /// On-disk caches. + case diskCache = 2 + /// HTML offline web app caches. + case offlineWebApplicationCache = 3 + /// HTML local storage. + case localStorage = 4 + /// HTML session storage. + case sessionStorage = 5 + /// WebSQL databases. + case webSQLDatabases = 6 + /// IndexedDB databases. + case indexedDBDatabases = 7 +} + +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from an action. +/// +/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy. +enum NavigationActionPolicy: Int { + /// Allow the navigation to continue. + case allow = 0 + /// Cancel the navigation. + case cancel = 1 + /// Allow the download to proceed. + case download = 2 +} + +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from a response. +/// +/// See https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy. +enum NavigationResponsePolicy: Int { + /// Allow the navigation to continue. + case allow = 0 + /// Cancel the navigation. + case cancel = 1 + /// Allow the download to proceed. + case download = 2 +} + +/// Constants that define the supported keys in a cookie attributes dictionary. +/// +/// See https://developer.apple.com/documentation/foundation/httpcookiepropertykey. +enum HttpCookiePropertyKey: Int { + /// A String object containing the comment for the cookie. + case comment = 0 + /// An Uri object or String object containing the comment URL for the cookie. + case commentUrl = 1 + /// Aa String object stating whether the cookie should be discarded at the end + /// of the session. + case discard = 2 + /// An String object containing the domain for the cookie. + case domain = 3 + /// An Date object or String object specifying the expiration date for the + /// cookie. + case expires = 4 + /// An String object containing an integer value stating how long in seconds + /// the cookie should be kept, at most. + case maximumAge = 5 + /// An String object containing the name of the cookie (required). + case name = 6 + /// A URL or String object containing the URL that set this cookie. + case originUrl = 7 + /// A String object containing the path for the cookie. + case path = 8 + /// An String object containing comma-separated integer values specifying the + /// ports for the cookie. + case port = 9 + /// A string indicating the same-site policy for the cookie. + case sameSitePolicy = 10 + /// A String object indicating that the cookie should be transmitted only over + /// secure channels. + case secure = 11 + /// A String object containing the value of the cookie. + case value = 12 + /// A String object that specifies the version of the cookie. + case version = 13 + /// The value is not recognized by the wrapper. + case unknown = 14 +} + +/// The type of action that triggered the navigation. +/// +/// See https://developer.apple.com/documentation/webkit/wknavigationtype. +enum NavigationType: Int { + /// A link activation. + case linkActivated = 0 + /// A request to submit a form. + case formSubmitted = 1 + /// A request for the frame’s next or previous item. + case backForward = 2 + /// A request to reload the webpage. + case reload = 3 + /// A request to resubmit a form. + case formResubmitted = 4 + /// A navigation request that originates for some other reason. + case other = 5 + /// The value is not recognized by the wrapper. + case unknown = 6 +} + +/// Possible permission decisions for device resource access. +/// +/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision. +enum PermissionDecision: Int { + /// Deny permission for the requested resource. + case deny = 0 + /// Deny permission for the requested resource. + case grant = 1 + /// Prompt the user for permission for the requested resource. + case prompt = 2 +} + +/// List of the types of media devices that can capture audio, video, or both. +/// +/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype. +enum MediaCaptureType: Int { + /// A media device that can capture video. + case camera = 0 + /// A media device or devices that can capture audio and video. + case cameraAndMicrophone = 1 + /// A media device that can capture audio. + case microphone = 2 + /// The value is not recognized by the wrapper. + case unknown = 3 +} + +/// Responses to an authentication challenge. +/// +/// See https://developer.apple.com/documentation/foundation/urlsession/authchallengedisposition. +enum UrlSessionAuthChallengeDisposition: Int { + /// Use the specified credential, which may be nil. + case useCredential = 0 + /// Use the default handling for the challenge as though this delegate method + /// were not implemented. + case performDefaultHandling = 1 + /// Cancel the entire request. + case cancelAuthenticationChallenge = 2 + /// Reject this challenge, and call the authentication delegate method again + /// with the next authentication protection space. + case rejectProtectionSpace = 3 + /// The value is not recognized by the wrapper. + case unknown = 4 +} + +/// Specifies how long a credential will be kept. +/// +/// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence. +enum UrlCredentialPersistence: Int { + /// The credential should not be stored. + case none = 0 + /// The credential should be stored only for this session. + case forSession = 1 + /// The credential should be stored in the keychain. + case permanent = 2 + /// The credential should be stored permanently in the keychain, and in + /// addition should be distributed to other devices based on the owning Apple + /// ID. + case synchronizable = 3 +} + +private class WebKitLibraryPigeonCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 129: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return KeyValueObservingOptions(rawValue: enumResultAsInt) + } + return nil + case 130: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return KeyValueChange(rawValue: enumResultAsInt) + } + return nil + case 131: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return KeyValueChangeKey(rawValue: enumResultAsInt) + } + return nil + case 132: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return UserScriptInjectionTime(rawValue: enumResultAsInt) + } + return nil + case 133: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return AudiovisualMediaType(rawValue: enumResultAsInt) + } + return nil + case 134: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return WebsiteDataType(rawValue: enumResultAsInt) + } + return nil + case 135: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return NavigationActionPolicy(rawValue: enumResultAsInt) + } + return nil + case 136: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return NavigationResponsePolicy(rawValue: enumResultAsInt) + } + return nil + case 137: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return HttpCookiePropertyKey(rawValue: enumResultAsInt) + } + return nil + case 138: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return NavigationType(rawValue: enumResultAsInt) + } + return nil + case 139: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return PermissionDecision(rawValue: enumResultAsInt) + } + return nil + case 140: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return MediaCaptureType(rawValue: enumResultAsInt) + } + return nil + case 141: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return UrlSessionAuthChallengeDisposition(rawValue: enumResultAsInt) + } + return nil + case 142: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return UrlCredentialPersistence(rawValue: enumResultAsInt) + } + return nil + default: + return super.readValue(ofType: type) + } + } +} + +private class WebKitLibraryPigeonCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? KeyValueObservingOptions { + super.writeByte(129) + super.writeValue(value.rawValue) + } else if let value = value as? KeyValueChange { + super.writeByte(130) + super.writeValue(value.rawValue) + } else if let value = value as? KeyValueChangeKey { + super.writeByte(131) + super.writeValue(value.rawValue) + } else if let value = value as? UserScriptInjectionTime { + super.writeByte(132) + super.writeValue(value.rawValue) + } else if let value = value as? AudiovisualMediaType { + super.writeByte(133) + super.writeValue(value.rawValue) + } else if let value = value as? WebsiteDataType { + super.writeByte(134) + super.writeValue(value.rawValue) + } else if let value = value as? NavigationActionPolicy { + super.writeByte(135) + super.writeValue(value.rawValue) + } else if let value = value as? NavigationResponsePolicy { + super.writeByte(136) + super.writeValue(value.rawValue) + } else if let value = value as? HttpCookiePropertyKey { + super.writeByte(137) + super.writeValue(value.rawValue) + } else if let value = value as? NavigationType { + super.writeByte(138) + super.writeValue(value.rawValue) + } else if let value = value as? PermissionDecision { + super.writeByte(139) + super.writeValue(value.rawValue) + } else if let value = value as? MediaCaptureType { + super.writeByte(140) + super.writeValue(value.rawValue) + } else if let value = value as? UrlSessionAuthChallengeDisposition { + super.writeByte(141) + super.writeValue(value.rawValue) + } else if let value = value as? UrlCredentialPersistence { + super.writeByte(142) + super.writeValue(value.rawValue) + } else { + super.writeValue(value) + } + } +} + +private class WebKitLibraryPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return WebKitLibraryPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return WebKitLibraryPigeonCodecWriter(data: data) + } +} + +class WebKitLibraryPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = WebKitLibraryPigeonCodec(readerWriter: WebKitLibraryPigeonCodecReaderWriter()) +} + +protocol PigeonApiDelegateURLRequest { + func pigeonDefaultConstructor(pigeonApi: PigeonApiURLRequest, url: String) throws + -> URLRequestWrapper + /// The URL being requested. + func getUrl(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws -> String? + /// The HTTP request method. + func setHttpMethod( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, method: String?) throws + /// The HTTP request method. + func getHttpMethod(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws + -> String? + /// The request body. + func setHttpBody( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, + body: FlutterStandardTypedData?) throws + /// The request body. + func getHttpBody(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) throws + -> FlutterStandardTypedData? + /// A dictionary containing all of the HTTP header fields for a request. + func setAllHttpHeaderFields( + pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper, fields: [String: String]?) + throws + /// A dictionary containing all of the HTTP header fields for a request. + func getAllHttpHeaderFields(pigeonApi: PigeonApiURLRequest, pigeonInstance: URLRequestWrapper) + throws -> [String: String]? +} + +protocol PigeonApiProtocolURLRequest { +} + +final class PigeonApiURLRequest: PigeonApiProtocolURLRequest { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURLRequest + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateURLRequest) + { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiURLRequest? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let urlArg = args[1] as! String + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api, url: urlArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let getUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + do { + let result = try api.pigeonDelegate.getUrl( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getUrlChannel.setMessageHandler(nil) + } + let setHttpMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setHttpMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setHttpMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + let methodArg: String? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setHttpMethod( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, method: methodArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setHttpMethodChannel.setMessageHandler(nil) + } + let getHttpMethodChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getHttpMethod", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getHttpMethodChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + do { + let result = try api.pigeonDelegate.getHttpMethod( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getHttpMethodChannel.setMessageHandler(nil) + } + let setHttpBodyChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setHttpBody", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setHttpBodyChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + let bodyArg: FlutterStandardTypedData? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setHttpBody( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, body: bodyArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setHttpBodyChannel.setMessageHandler(nil) + } + let getHttpBodyChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getHttpBody", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getHttpBodyChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + do { + let result = try api.pigeonDelegate.getHttpBody( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getHttpBodyChannel.setMessageHandler(nil) + } + let setAllHttpHeaderFieldsChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setAllHttpHeaderFields", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setAllHttpHeaderFieldsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + let fieldsArg: [String: String]? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setAllHttpHeaderFields( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, fields: fieldsArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setAllHttpHeaderFieldsChannel.setMessageHandler(nil) + } + let getAllHttpHeaderFieldsChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getAllHttpHeaderFields", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getAllHttpHeaderFieldsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLRequestWrapper + do { + let result = try api.pigeonDelegate.getAllHttpHeaderFields( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getAllHttpHeaderFieldsChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of URLRequest and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URLRequestWrapper, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateHTTPURLResponse { + /// The response’s HTTP status code. + func statusCode(pigeonApi: PigeonApiHTTPURLResponse, pigeonInstance: HTTPURLResponse) throws + -> Int64 +} + +protocol PigeonApiProtocolHTTPURLResponse { +} + +final class PigeonApiHTTPURLResponse: PigeonApiProtocolHTTPURLResponse { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateHTTPURLResponse + ///An implementation of [URLResponse] used to access callback methods + var pigeonApiURLResponse: PigeonApiURLResponse { + return pigeonRegistrar.apiDelegate.pigeonApiURLResponse(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateHTTPURLResponse + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of HTTPURLResponse and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: HTTPURLResponse, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let statusCodeArg = try! pigeonDelegate.statusCode( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.HTTPURLResponse.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, statusCodeArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +open class PigeonApiDelegateURLResponse { +} + +protocol PigeonApiProtocolURLResponse { +} + +final class PigeonApiURLResponse: PigeonApiProtocolURLResponse { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURLResponse + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateURLResponse + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of URLResponse and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URLResponse, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.URLResponse.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKUserScript { + /// Creates a user script object that contains the specified source code and + /// attributes. + func pigeonDefaultConstructor( + pigeonApi: PigeonApiWKUserScript, source: String, injectionTime: UserScriptInjectionTime, + isForMainFrameOnly: Bool + ) throws -> WKUserScript + /// The script’s source code. + func source(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws -> String + /// The time at which to inject the script into the webpage. + func injectionTime(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws + -> UserScriptInjectionTime + /// A Boolean value that indicates whether to inject the script into the main + /// frame or all frames. + func isForMainFrameOnly(pigeonApi: PigeonApiWKUserScript, pigeonInstance: WKUserScript) throws + -> Bool +} + +protocol PigeonApiProtocolWKUserScript { +} + +final class PigeonApiWKUserScript: PigeonApiProtocolWKUserScript { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKUserScript + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateWKUserScript + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKUserScript? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let sourceArg = args[1] as! String + let injectionTimeArg = args[2] as! UserScriptInjectionTime + let isForMainFrameOnlyArg = args[3] as! Bool + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, source: sourceArg, injectionTime: injectionTimeArg, + isForMainFrameOnly: isForMainFrameOnlyArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKUserScript and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKUserScript, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let sourceArg = try! pigeonDelegate.source(pigeonApi: self, pigeonInstance: pigeonInstance) + let injectionTimeArg = try! pigeonDelegate.injectionTime( + pigeonApi: self, pigeonInstance: pigeonInstance) + let isForMainFrameOnlyArg = try! pigeonDelegate.isForMainFrameOnly( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [pigeonIdentifierArg, sourceArg, injectionTimeArg, isForMainFrameOnlyArg] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKNavigationAction { + /// The URL request object associated with the navigation action. + func request(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) throws + -> URLRequestWrapper + /// The frame in which to display the new content. + /// + /// If the target of the navigation is a new window, this property is nil. + func targetFrame(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) + throws -> WKFrameInfo? + /// The type of action that triggered the navigation. + func navigationType(pigeonApi: PigeonApiWKNavigationAction, pigeonInstance: WKNavigationAction) + throws -> NavigationType +} + +protocol PigeonApiProtocolWKNavigationAction { +} + +final class PigeonApiWKNavigationAction: PigeonApiProtocolWKNavigationAction { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKNavigationAction + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKNavigationAction + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKNavigationAction and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKNavigationAction, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let requestArg = try! pigeonDelegate.request(pigeonApi: self, pigeonInstance: pigeonInstance) + let targetFrameArg = try! pigeonDelegate.targetFrame( + pigeonApi: self, pigeonInstance: pigeonInstance) + let navigationTypeArg = try! pigeonDelegate.navigationType( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [pigeonIdentifierArg, requestArg, targetFrameArg, navigationTypeArg] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKNavigationResponse { + /// The frame’s response. + func response(pigeonApi: PigeonApiWKNavigationResponse, pigeonInstance: WKNavigationResponse) + throws -> URLResponse + /// A Boolean value that indicates whether the response targets the web view’s + /// main frame. + func isForMainFrame( + pigeonApi: PigeonApiWKNavigationResponse, pigeonInstance: WKNavigationResponse + ) throws -> Bool +} + +protocol PigeonApiProtocolWKNavigationResponse { +} + +final class PigeonApiWKNavigationResponse: PigeonApiProtocolWKNavigationResponse { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKNavigationResponse + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKNavigationResponse + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKNavigationResponse and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKNavigationResponse, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let responseArg = try! pigeonDelegate.response(pigeonApi: self, pigeonInstance: pigeonInstance) + let isForMainFrameArg = try! pigeonDelegate.isForMainFrame( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, responseArg, isForMainFrameArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKFrameInfo { + /// A Boolean value indicating whether the frame is the web site's main frame + /// or a subframe. + func isMainFrame(pigeonApi: PigeonApiWKFrameInfo, pigeonInstance: WKFrameInfo) throws -> Bool + /// The frame’s current request. + func request(pigeonApi: PigeonApiWKFrameInfo, pigeonInstance: WKFrameInfo) throws + -> URLRequestWrapper +} + +protocol PigeonApiProtocolWKFrameInfo { +} + +final class PigeonApiWKFrameInfo: PigeonApiProtocolWKFrameInfo { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKFrameInfo + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateWKFrameInfo + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKFrameInfo and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKFrameInfo, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let isMainFrameArg = try! pigeonDelegate.isMainFrame( + pigeonApi: self, pigeonInstance: pigeonInstance) + let requestArg = try! pigeonDelegate.request(pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, isMainFrameArg, requestArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateNSError { + /// The error code. + func code(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> Int64 + /// A string containing the error domain. + func domain(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> String + /// The user info dictionary. + func userInfo(pigeonApi: PigeonApiNSError, pigeonInstance: NSError) throws -> [String: Any?] +} + +protocol PigeonApiProtocolNSError { +} + +final class PigeonApiNSError: PigeonApiProtocolNSError { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateNSError + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateNSError) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of NSError and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: NSError, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let codeArg = try! pigeonDelegate.code(pigeonApi: self, pigeonInstance: pigeonInstance) + let domainArg = try! pigeonDelegate.domain(pigeonApi: self, pigeonInstance: pigeonInstance) + let userInfoArg = try! pigeonDelegate.userInfo(pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, codeArg, domainArg, userInfoArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKScriptMessage { + /// The name of the message handler to which the message is sent. + func name(pigeonApi: PigeonApiWKScriptMessage, pigeonInstance: WKScriptMessage) throws -> String + /// The body of the message. + func body(pigeonApi: PigeonApiWKScriptMessage, pigeonInstance: WKScriptMessage) throws -> Any? +} + +protocol PigeonApiProtocolWKScriptMessage { +} + +final class PigeonApiWKScriptMessage: PigeonApiProtocolWKScriptMessage { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKScriptMessage + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKScriptMessage + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKScriptMessage and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKScriptMessage, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let nameArg = try! pigeonDelegate.name(pigeonApi: self, pigeonInstance: pigeonInstance) + let bodyArg = try! pigeonDelegate.body(pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessage.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, nameArg, bodyArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKSecurityOrigin { + /// The security origin’s host. + func host(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) throws -> String + /// The security origin's port. + func port(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) throws -> Int64 + /// The security origin's protocol. + func securityProtocol(pigeonApi: PigeonApiWKSecurityOrigin, pigeonInstance: WKSecurityOrigin) + throws -> String +} + +protocol PigeonApiProtocolWKSecurityOrigin { +} + +final class PigeonApiWKSecurityOrigin: PigeonApiProtocolWKSecurityOrigin { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKSecurityOrigin + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKSecurityOrigin + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKSecurityOrigin and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKSecurityOrigin, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let hostArg = try! pigeonDelegate.host(pigeonApi: self, pigeonInstance: pigeonInstance) + let portArg = try! pigeonDelegate.port(pigeonApi: self, pigeonInstance: pigeonInstance) + let securityProtocolArg = try! pigeonDelegate.securityProtocol( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, hostArg, portArg, securityProtocolArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateHTTPCookie { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiHTTPCookie, properties: [HttpCookiePropertyKey: Any] + ) throws -> HTTPCookie + /// The cookie’s properties. + func getProperties(pigeonApi: PigeonApiHTTPCookie, pigeonInstance: HTTPCookie) throws + -> [HttpCookiePropertyKey: Any]? +} + +protocol PigeonApiProtocolHTTPCookie { +} + +final class PigeonApiHTTPCookie: PigeonApiProtocolHTTPCookie { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateHTTPCookie + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateHTTPCookie) + { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiHTTPCookie? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let propertiesArg = args[1] as? [HttpCookiePropertyKey: Any] + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, properties: propertiesArg!), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let getPropertiesChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.getProperties", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getPropertiesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! HTTPCookie + do { + let result = try api.pigeonDelegate.getProperties( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getPropertiesChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of HTTPCookie and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: HTTPCookie, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateAuthenticationChallengeResponse { + func pigeonDefaultConstructor( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + disposition: UrlSessionAuthChallengeDisposition, credential: URLCredential? + ) throws -> AuthenticationChallengeResponse + /// The option to use to handle the challenge. + func disposition( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + pigeonInstance: AuthenticationChallengeResponse + ) throws -> UrlSessionAuthChallengeDisposition + /// The credential to use for authentication when the disposition parameter + /// contains the value URLSession.AuthChallengeDisposition.useCredential. + func credential( + pigeonApi: PigeonApiAuthenticationChallengeResponse, + pigeonInstance: AuthenticationChallengeResponse + ) throws -> URLCredential? +} + +protocol PigeonApiProtocolAuthenticationChallengeResponse { +} + +final class PigeonApiAuthenticationChallengeResponse: + PigeonApiProtocolAuthenticationChallengeResponse +{ + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateAuthenticationChallengeResponse + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateAuthenticationChallengeResponse + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiAuthenticationChallengeResponse? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let dispositionArg = args[1] as! UrlSessionAuthChallengeDisposition + let credentialArg: URLCredential? = nilOrValue(args[2]) + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, disposition: dispositionArg, credential: credentialArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of AuthenticationChallengeResponse and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: AuthenticationChallengeResponse, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let dispositionArg = try! pigeonDelegate.disposition( + pigeonApi: self, pigeonInstance: pigeonInstance) + let credentialArg = try! pigeonDelegate.credential( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg, dispositionArg, credentialArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKWebsiteDataStore { + /// The default data store, which stores data persistently to disk. + func defaultDataStore(pigeonApi: PigeonApiWKWebsiteDataStore) throws -> WKWebsiteDataStore + /// The object that manages the HTTP cookies for your website. + func httpCookieStore(pigeonApi: PigeonApiWKWebsiteDataStore, pigeonInstance: WKWebsiteDataStore) + throws -> WKHTTPCookieStore + /// Removes the specified types of website data from one or more data records. + func removeDataOfTypes( + pigeonApi: PigeonApiWKWebsiteDataStore, pigeonInstance: WKWebsiteDataStore, + dataTypes: [WebsiteDataType], modificationTimeInSecondsSinceEpoch: Double, + completion: @escaping (Result) -> Void) +} + +protocol PigeonApiProtocolWKWebsiteDataStore { +} + +final class PigeonApiWKWebsiteDataStore: PigeonApiProtocolWKWebsiteDataStore { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKWebsiteDataStore + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKWebsiteDataStore + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKWebsiteDataStore? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let defaultDataStoreChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.defaultDataStore", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + defaultDataStoreChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.defaultDataStore(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + defaultDataStoreChannel.setMessageHandler(nil) + } + let httpCookieStoreChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.httpCookieStore", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + httpCookieStoreChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebsiteDataStore + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.httpCookieStore( + pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + httpCookieStoreChannel.setMessageHandler(nil) + } + let removeDataOfTypesChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.removeDataOfTypes", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + removeDataOfTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebsiteDataStore + let dataTypesArg = args[1] as! [WebsiteDataType] + let modificationTimeInSecondsSinceEpochArg = args[2] as! Double + api.pigeonDelegate.removeDataOfTypes( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, dataTypes: dataTypesArg, + modificationTimeInSecondsSinceEpoch: modificationTimeInSecondsSinceEpochArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + removeDataOfTypesChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKWebsiteDataStore and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKWebsiteDataStore, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateUIView { + #if !os(macOS) + /// The view’s background color. + func setBackgroundColor(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, value: Int64?) + throws + #endif + #if !os(macOS) + /// A Boolean value that determines whether the view is opaque. + func setOpaque(pigeonApi: PigeonApiUIView, pigeonInstance: UIView, opaque: Bool) throws + #endif +} + +protocol PigeonApiProtocolUIView { +} + +final class PigeonApiUIView: PigeonApiProtocolUIView { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateUIView + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateUIView) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: PigeonApiUIView?) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + #if !os(macOS) + let setBackgroundColorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIView.setBackgroundColor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setBackgroundColorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIView + let valueArg: Int64? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setBackgroundColor( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, value: valueArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setBackgroundColorChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setOpaqueChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIView.setOpaque", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setOpaqueChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIView + let opaqueArg = args[1] as! Bool + do { + try api.pigeonDelegate.setOpaque( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, opaque: opaqueArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setOpaqueChannel.setMessageHandler(nil) + } + #endif + } + + #if !os(macOS) + ///Creates a Dart instance of UIView and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: UIView, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.UIView.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif +} +protocol PigeonApiDelegateUIScrollView { + #if !os(macOS) + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + func getContentOffset(pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView) throws + -> [Double] + #endif + #if !os(macOS) + /// Move the scrolled position of your view. + /// + /// Convenience method to synchronize change to the x and y scroll position. + func scrollBy( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, x: Double, y: Double) throws + #endif + #if !os(macOS) + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + func setContentOffset( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, x: Double, y: Double) throws + #endif + #if !os(macOS) + /// The delegate of the scroll view. + func setDelegate( + pigeonApi: PigeonApiUIScrollView, pigeonInstance: UIScrollView, + delegate: UIScrollViewDelegate?) throws + #endif +} + +protocol PigeonApiProtocolUIScrollView { +} + +final class PigeonApiUIScrollView: PigeonApiProtocolUIScrollView { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateUIScrollView + ///An implementation of [UIView] used to access callback methods + var pigeonApiUIView: PigeonApiUIView { + return pigeonRegistrar.apiDelegate.pigeonApiUIView(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateUIScrollView + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiUIScrollView? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + #if !os(macOS) + let getContentOffsetChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.getContentOffset", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getContentOffsetChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIScrollView + do { + let result = try api.pigeonDelegate.getContentOffset( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getContentOffsetChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let scrollByChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.scrollBy", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + scrollByChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIScrollView + let xArg = args[1] as! Double + let yArg = args[2] as! Double + do { + try api.pigeonDelegate.scrollBy( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, x: xArg, y: yArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + scrollByChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setContentOffsetChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.setContentOffset", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setContentOffsetChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIScrollView + let xArg = args[1] as! Double + let yArg = args[2] as! Double + do { + try api.pigeonDelegate.setContentOffset( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, x: xArg, y: yArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setContentOffsetChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setDelegateChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.setDelegate", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setDelegateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! UIScrollView + let delegateArg: UIScrollViewDelegate? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setDelegate( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, delegate: delegateArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setDelegateChannel.setMessageHandler(nil) + } + #endif + } + + #if !os(macOS) + ///Creates a Dart instance of UIScrollView and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: UIScrollView, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif +} +protocol PigeonApiDelegateWKWebViewConfiguration { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKWebViewConfiguration) throws + -> WKWebViewConfiguration + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + func setUserContentController( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + controller: WKUserContentController) throws + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + func getUserContentController( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKUserContentController + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + func setWebsiteDataStore( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + dataStore: WKWebsiteDataStore) throws + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + func getWebsiteDataStore( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKWebsiteDataStore + /// The object that manages the preference-related settings for the web view. + func setPreferences( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + preferences: WKPreferences) throws + /// The object that manages the preference-related settings for the web view. + func getPreferences( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKPreferences + /// A Boolean value that indicates whether HTML5 videos play inline or use the + /// native full-screen controller. + func setAllowsInlineMediaPlayback( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, allow: Bool) + throws + /// A Boolean value that indicates whether the web view limits navigation to + /// pages within the app’s domain. + func setLimitsNavigationsToAppBoundDomains( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, limit: Bool) + throws + /// The media types that require a user gesture to begin playing. + func setMediaTypesRequiringUserActionForPlayback( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + type: AudiovisualMediaType) throws +} + +protocol PigeonApiProtocolWKWebViewConfiguration { +} + +final class PigeonApiWKWebViewConfiguration: PigeonApiProtocolWKWebViewConfiguration { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKWebViewConfiguration + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKWebViewConfiguration + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKWebViewConfiguration? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let setUserContentControllerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setUserContentController", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setUserContentControllerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let controllerArg = args[1] as! WKUserContentController + do { + try api.pigeonDelegate.setUserContentController( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, controller: controllerArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setUserContentControllerChannel.setMessageHandler(nil) + } + let getUserContentControllerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getUserContentController", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getUserContentControllerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + do { + let result = try api.pigeonDelegate.getUserContentController( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getUserContentControllerChannel.setMessageHandler(nil) + } + let setWebsiteDataStoreChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setWebsiteDataStore", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setWebsiteDataStoreChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let dataStoreArg = args[1] as! WKWebsiteDataStore + do { + try api.pigeonDelegate.setWebsiteDataStore( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, dataStore: dataStoreArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setWebsiteDataStoreChannel.setMessageHandler(nil) + } + let getWebsiteDataStoreChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getWebsiteDataStore", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getWebsiteDataStoreChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + do { + let result = try api.pigeonDelegate.getWebsiteDataStore( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getWebsiteDataStoreChannel.setMessageHandler(nil) + } + let setPreferencesChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setPreferences", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setPreferencesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let preferencesArg = args[1] as! WKPreferences + do { + try api.pigeonDelegate.setPreferences( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, preferences: preferencesArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setPreferencesChannel.setMessageHandler(nil) + } + let getPreferencesChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getPreferences", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getPreferencesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + do { + let result = try api.pigeonDelegate.getPreferences( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getPreferencesChannel.setMessageHandler(nil) + } + let setAllowsInlineMediaPlaybackChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setAllowsInlineMediaPlayback", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setAllowsInlineMediaPlaybackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let allowArg = args[1] as! Bool + do { + try api.pigeonDelegate.setAllowsInlineMediaPlayback( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, allow: allowArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setAllowsInlineMediaPlaybackChannel.setMessageHandler(nil) + } + let setLimitsNavigationsToAppBoundDomainsChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setLimitsNavigationsToAppBoundDomains", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setLimitsNavigationsToAppBoundDomainsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let limitArg = args[1] as! Bool + do { + try api.pigeonDelegate.setLimitsNavigationsToAppBoundDomains( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, limit: limitArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setLimitsNavigationsToAppBoundDomainsChannel.setMessageHandler(nil) + } + let setMediaTypesRequiringUserActionForPlaybackChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setMediaTypesRequiringUserActionForPlayback", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setMediaTypesRequiringUserActionForPlaybackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebViewConfiguration + let typeArg = args[1] as! AudiovisualMediaType + do { + try api.pigeonDelegate.setMediaTypesRequiringUserActionForPlayback( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, type: typeArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setMediaTypesRequiringUserActionForPlaybackChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKWebViewConfiguration and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKWebViewConfiguration, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKUserContentController { + /// Installs a message handler that you can call from your JavaScript code. + func addScriptMessageHandler( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + handler: WKScriptMessageHandler, name: String) throws + /// Uninstalls the custom message handler with the specified name from your + /// JavaScript code. + func removeScriptMessageHandler( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + name: String) throws + /// Uninstalls all custom message handlers associated with the user content + /// controller. + func removeAllScriptMessageHandlers( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController) throws + /// Injects the specified script into the webpage’s content. + func addUserScript( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController, + userScript: WKUserScript) throws + /// Removes all user scripts from the web view. + func removeAllUserScripts( + pigeonApi: PigeonApiWKUserContentController, pigeonInstance: WKUserContentController) throws +} + +protocol PigeonApiProtocolWKUserContentController { +} + +final class PigeonApiWKUserContentController: PigeonApiProtocolWKUserContentController { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKUserContentController + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKUserContentController + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKUserContentController? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let addScriptMessageHandlerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.addScriptMessageHandler", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + addScriptMessageHandlerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKUserContentController + let handlerArg = args[1] as! WKScriptMessageHandler + let nameArg = args[2] as! String + do { + try api.pigeonDelegate.addScriptMessageHandler( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, handler: handlerArg, name: nameArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + addScriptMessageHandlerChannel.setMessageHandler(nil) + } + let removeScriptMessageHandlerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeScriptMessageHandler", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + removeScriptMessageHandlerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKUserContentController + let nameArg = args[1] as! String + do { + try api.pigeonDelegate.removeScriptMessageHandler( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, name: nameArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeScriptMessageHandlerChannel.setMessageHandler(nil) + } + let removeAllScriptMessageHandlersChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeAllScriptMessageHandlers", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + removeAllScriptMessageHandlersChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKUserContentController + do { + try api.pigeonDelegate.removeAllScriptMessageHandlers( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeAllScriptMessageHandlersChannel.setMessageHandler(nil) + } + let addUserScriptChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.addUserScript", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + addUserScriptChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKUserContentController + let userScriptArg = args[1] as! WKUserScript + do { + try api.pigeonDelegate.addUserScript( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, userScript: userScriptArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + addUserScriptChannel.setMessageHandler(nil) + } + let removeAllUserScriptsChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeAllUserScripts", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + removeAllUserScriptsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKUserContentController + do { + try api.pigeonDelegate.removeAllUserScripts( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeAllUserScriptsChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKUserContentController and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKUserContentController, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKPreferences { + /// A Boolean value that indicates whether JavaScript is enabled. + func setJavaScriptEnabled( + pigeonApi: PigeonApiWKPreferences, pigeonInstance: WKPreferences, enabled: Bool) throws +} + +protocol PigeonApiProtocolWKPreferences { +} + +final class PigeonApiWKPreferences: PigeonApiProtocolWKPreferences { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKPreferences + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateWKPreferences + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKPreferences? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let setJavaScriptEnabledChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.setJavaScriptEnabled", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setJavaScriptEnabledChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKPreferences + let enabledArg = args[1] as! Bool + do { + try api.pigeonDelegate.setJavaScriptEnabled( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, enabled: enabledArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setJavaScriptEnabledChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKPreferences and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKPreferences, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKScriptMessageHandler { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKScriptMessageHandler) throws + -> WKScriptMessageHandler +} + +protocol PigeonApiProtocolWKScriptMessageHandler { + /// Tells the handler that a webpage sent a script message. + func didReceiveScriptMessage( + pigeonInstance pigeonInstanceArg: WKScriptMessageHandler, + controller controllerArg: WKUserContentController, message messageArg: WKScriptMessage, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiWKScriptMessageHandler: PigeonApiProtocolWKScriptMessageHandler { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKScriptMessageHandler + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKScriptMessageHandler + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKScriptMessageHandler? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKScriptMessageHandler and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKScriptMessageHandler, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + print( + "Error: Attempting to create a new Dart instance of WKScriptMessageHandler, but the class has a nonnull callback method." + ) + } + /// Tells the handler that a webpage sent a script message. + func didReceiveScriptMessage( + pigeonInstance pigeonInstanceArg: WKScriptMessageHandler, + controller controllerArg: WKUserContentController, message messageArg: WKScriptMessage, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, controllerArg, messageArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + +} +protocol PigeonApiDelegateWKNavigationDelegate { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKNavigationDelegate) throws + -> WKNavigationDelegate +} + +protocol PigeonApiProtocolWKNavigationDelegate { + /// Tells the delegate that navigation is complete. + func didFinishNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, completion: @escaping (Result) -> Void) + /// Tells the delegate that navigation from the main frame has started. + func didStartProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, completion: @escaping (Result) -> Void) + /// Asks the delegate for permission to navigate to new content based on the + /// specified action information. + func decidePolicyForNavigationAction( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping (Result) -> Void) + /// Asks the delegate for permission to navigate to new content after the + /// response to the navigation request is known. + func decidePolicyForNavigationResponse( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationResponse navigationResponseArg: WKNavigationResponse, + completion: @escaping (Result) -> Void) + /// Tells the delegate that an error occurred during navigation. + func didFailNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, completion: @escaping (Result) -> Void) + /// Tells the delegate that an error occurred during the early navigation + /// process. + func didFailProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, completion: @escaping (Result) -> Void) + /// Tells the delegate that the web view’s content process was terminated. + func webViewWebContentProcessDidTerminate( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + completion: @escaping (Result) -> Void) + /// Asks the delegate to respond to an authentication challenge. + func didReceiveAuthenticationChallenge( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + challenge challengeArg: URLAuthenticationChallenge, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiWKNavigationDelegate: PigeonApiProtocolWKNavigationDelegate { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKNavigationDelegate + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKNavigationDelegate + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKNavigationDelegate? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKNavigationDelegate and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKNavigationDelegate, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + /// Tells the delegate that navigation is complete. + func didFinishNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFinishNavigation" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, urlArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Tells the delegate that navigation from the main frame has started. + func didStartProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didStartProvisionalNavigation" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, urlArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Asks the delegate for permission to navigate to new content based on the + /// specified action information. + func decidePolicyForNavigationAction( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, navigationActionArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + PigeonError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NavigationActionPolicy + completion(.success(result)) + } + } + } + + /// Asks the delegate for permission to navigate to new content after the + /// response to the navigation request is known. + func decidePolicyForNavigationResponse( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationResponse navigationResponseArg: WKNavigationResponse, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, navigationResponseArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + PigeonError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NavigationResponsePolicy + completion(.success(result)) + } + } + } + + /// Tells the delegate that an error occurred during navigation. + func didFailNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, errorArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Tells the delegate that an error occurred during the early navigation + /// process. + func didFailProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, errorArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Tells the delegate that the web view’s content process was terminated. + func webViewWebContentProcessDidTerminate( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.webViewWebContentProcessDidTerminate" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Asks the delegate to respond to an authentication challenge. + func didReceiveAuthenticationChallenge( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + challenge challengeArg: URLAuthenticationChallenge, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, challengeArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + PigeonError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! AuthenticationChallengeResponse + completion(.success(result)) + } + } + } + +} +protocol PigeonApiDelegateNSObject { + func pigeonDefaultConstructor(pigeonApi: PigeonApiNSObject) throws -> NSObject + /// Registers the observer object to receive KVO notifications for the key + /// path relative to the object receiving this message. + func addObserver( + pigeonApi: PigeonApiNSObject, pigeonInstance: NSObject, observer: NSObject, keyPath: String, + options: [KeyValueObservingOptions]) throws + /// Stops the observer object from receiving change notifications for the + /// property specified by the key path relative to the object receiving this + /// message. + func removeObserver( + pigeonApi: PigeonApiNSObject, pigeonInstance: NSObject, observer: NSObject, keyPath: String) + throws +} + +protocol PigeonApiProtocolNSObject { + /// Informs the observing object when the value at the specified key path + /// relative to the observed object has changed. + func observeValue( + pigeonInstance pigeonInstanceArg: NSObject, keyPath keyPathArg: String?, + object objectArg: NSObject?, change changeArg: [KeyValueChangeKey: Any?]?, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiNSObject: PigeonApiProtocolNSObject { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateNSObject + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateNSObject) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: PigeonApiNSObject?) + { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + let addObserverChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.addObserver", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + addObserverChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! NSObject + let observerArg = args[1] as! NSObject + let keyPathArg = args[2] as! String + let optionsArg = args[3] as! [KeyValueObservingOptions] + do { + try api.pigeonDelegate.addObserver( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, observer: observerArg, + keyPath: keyPathArg, options: optionsArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + addObserverChannel.setMessageHandler(nil) + } + let removeObserverChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.removeObserver", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + removeObserverChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! NSObject + let observerArg = args[1] as! NSObject + let keyPathArg = args[2] as! String + do { + try api.pigeonDelegate.removeObserver( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, observer: observerArg, + keyPath: keyPathArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + removeObserverChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of NSObject and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: NSObject, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + /// Informs the observing object when the value at the specified key path + /// relative to the observed object has changed. + func observeValue( + pigeonInstance pigeonInstanceArg: NSObject, keyPath keyPathArg: String?, + object objectArg: NSObject?, change changeArg: [KeyValueChangeKey: Any?]?, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = "dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.observeValue" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, keyPathArg, objectArg, changeArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + +} +protocol PigeonApiDelegateUIViewWKWebView { + #if !os(macOS) + func pigeonDefaultConstructor( + pigeonApi: PigeonApiUIViewWKWebView, initialConfiguration: WKWebViewConfiguration + ) throws -> WKWebView + #endif + #if !os(macOS) + /// The object that contains the configuration details for the web view. + func configuration(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> WKWebViewConfiguration + #endif + #if !os(macOS) + /// The scroll view associated with the web view. + func scrollView(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> UIScrollView + #endif + #if !os(macOS) + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + func setUIDelegate( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, delegate: WKUIDelegate) throws + #endif + #if !os(macOS) + /// The object you use to manage navigation behavior for the web view. + func setNavigationDelegate( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, delegate: WKNavigationDelegate + ) throws + #endif + #if !os(macOS) + /// The URL for the current webpage. + func getUrl(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> String? + #endif + #if !os(macOS) + /// An estimate of what fraction of the current navigation has been loaded. + func getEstimatedProgress(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> Double + #endif + #if !os(macOS) + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + func load( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, request: URLRequestWrapper) + throws + #endif + #if !os(macOS) + /// Loads the contents of the specified HTML string and navigates to it. + func loadHtmlString( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, string: String, + baseUrl: String?) throws + #endif + #if !os(macOS) + /// Loads the web content from the specified file and navigates to it. + func loadFileUrl( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, url: String, + readAccessUrl: String) throws + #endif + #if !os(macOS) + /// Convenience method to load a Flutter asset. + func loadFlutterAsset( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, key: String) throws + #endif + #if !os(macOS) + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + func canGoBack(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> Bool + #endif + #if !os(macOS) + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + func canGoForward(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> Bool + #endif + #if !os(macOS) + /// Navigates to the back item in the back-forward list. + func goBack(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(macOS) + /// Navigates to the forward item in the back-forward list. + func goForward(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(macOS) + /// Reloads the current webpage. + func reload(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(macOS) + /// The page title. + func getTitle(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> String? + #endif + #if !os(macOS) + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + func setAllowsBackForwardNavigationGestures( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, allow: Bool) throws + #endif + #if !os(macOS) + /// The custom user agent string. + func setCustomUserAgent( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, userAgent: String?) throws + #endif + #if !os(macOS) + /// Evaluates the specified JavaScript string. + func evaluateJavaScript( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, javaScriptString: String, + completion: @escaping (Result) -> Void) + #endif + #if !os(macOS) + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + func setInspectable( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, inspectable: Bool) throws + #endif + #if !os(macOS) + /// The custom user agent string. + func getCustomUserAgent(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> String? + #endif +} + +protocol PigeonApiProtocolUIViewWKWebView { +} + +final class PigeonApiUIViewWKWebView: PigeonApiProtocolUIViewWKWebView { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateUIViewWKWebView + ///An implementation of [UIView] used to access callback methods + var pigeonApiUIView: PigeonApiUIView { + return pigeonRegistrar.apiDelegate.pigeonApiUIView(pigeonRegistrar) + } + + ///An implementation of [WKWebView] used to access callback methods + var pigeonApiWKWebView: PigeonApiWKWebView { + return pigeonRegistrar.apiDelegate.pigeonApiWKWebView(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateUIViewWKWebView + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiUIViewWKWebView? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + #if !os(macOS) + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let initialConfigurationArg = args[1] as! WKWebViewConfiguration + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, initialConfiguration: initialConfigurationArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let configurationChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.configuration", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + configurationChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.configuration( + pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + configurationChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let scrollViewChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.scrollView", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + scrollViewChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.scrollView(pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + scrollViewChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setUIDelegateChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setUIDelegate", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setUIDelegateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let delegateArg = args[1] as! WKUIDelegate + do { + try api.pigeonDelegate.setUIDelegate( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, delegate: delegateArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setUIDelegateChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setNavigationDelegateChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setNavigationDelegate", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setNavigationDelegateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let delegateArg = args[1] as! WKNavigationDelegate + do { + try api.pigeonDelegate.setNavigationDelegate( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, delegate: delegateArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setNavigationDelegateChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let getUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getUrl( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getUrlChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let getEstimatedProgressChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getEstimatedProgress", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getEstimatedProgressChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getEstimatedProgress( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getEstimatedProgressChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let loadChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.load", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let requestArg = args[1] as! URLRequestWrapper + do { + try api.pigeonDelegate.load( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, request: requestArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let loadHtmlStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadHtmlString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadHtmlStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let stringArg = args[1] as! String + let baseUrlArg: String? = nilOrValue(args[2]) + do { + try api.pigeonDelegate.loadHtmlString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, string: stringArg, + baseUrl: baseUrlArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadHtmlStringChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let loadFileUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadFileUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadFileUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let urlArg = args[1] as! String + let readAccessUrlArg = args[2] as! String + do { + try api.pigeonDelegate.loadFileUrl( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, url: urlArg, + readAccessUrl: readAccessUrlArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadFileUrlChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let loadFlutterAssetChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadFlutterAsset", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadFlutterAssetChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let keyArg = args[1] as! String + do { + try api.pigeonDelegate.loadFlutterAsset( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, key: keyArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadFlutterAssetChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let canGoBackChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.canGoBack", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + canGoBackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.canGoBack( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + canGoBackChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let canGoForwardChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.canGoForward", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + canGoForwardChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.canGoForward( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + canGoForwardChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let goBackChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.goBack", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + goBackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.goBack(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + goBackChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let goForwardChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.goForward", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + goForwardChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.goForward(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + goForwardChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let reloadChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.reload", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + reloadChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.reload(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + reloadChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let getTitleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getTitle", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getTitleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getTitle( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getTitleChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setAllowsBackForwardNavigationGesturesChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setAllowsBackForwardNavigationGestures", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setAllowsBackForwardNavigationGesturesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let allowArg = args[1] as! Bool + do { + try api.pigeonDelegate.setAllowsBackForwardNavigationGestures( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, allow: allowArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setAllowsBackForwardNavigationGesturesChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setCustomUserAgentChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setCustomUserAgent", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setCustomUserAgentChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let userAgentArg: String? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setCustomUserAgent( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, userAgent: userAgentArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setCustomUserAgentChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let evaluateJavaScriptChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.evaluateJavaScript", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + evaluateJavaScriptChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let javaScriptStringArg = args[1] as! String + api.pigeonDelegate.evaluateJavaScript( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, javaScriptString: javaScriptStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + evaluateJavaScriptChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let setInspectableChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setInspectable", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setInspectableChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let inspectableArg = args[1] as! Bool + do { + try api.pigeonDelegate.setInspectable( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, inspectable: inspectableArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setInspectableChannel.setMessageHandler(nil) + } + #endif + #if !os(macOS) + let getCustomUserAgentChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getCustomUserAgent", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getCustomUserAgentChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getCustomUserAgent( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getCustomUserAgentChannel.setMessageHandler(nil) + } + #endif + } + + #if !os(macOS) + ///Creates a Dart instance of UIViewWKWebView and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKWebView, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif +} +protocol PigeonApiDelegateNSViewWKWebView { + #if !os(iOS) + func pigeonDefaultConstructor( + pigeonApi: PigeonApiNSViewWKWebView, initialConfiguration: WKWebViewConfiguration + ) throws -> WKWebView + #endif + #if !os(iOS) + /// The object that contains the configuration details for the web view. + func configuration(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> WKWebViewConfiguration + #endif + #if !os(iOS) + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + func setUIDelegate( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, delegate: WKUIDelegate) throws + #endif + #if !os(iOS) + /// The object you use to manage navigation behavior for the web view. + func setNavigationDelegate( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, delegate: WKNavigationDelegate + ) throws + #endif + #if !os(iOS) + /// The URL for the current webpage. + func getUrl(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> String? + #endif + #if !os(iOS) + /// An estimate of what fraction of the current navigation has been loaded. + func getEstimatedProgress(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> Double + #endif + #if !os(iOS) + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + func load( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, request: URLRequestWrapper) + throws + #endif + #if !os(iOS) + /// Loads the contents of the specified HTML string and navigates to it. + func loadHtmlString( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, string: String, + baseUrl: String?) throws + #endif + #if !os(iOS) + /// Loads the web content from the specified file and navigates to it. + func loadFileUrl( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, url: String, + readAccessUrl: String) throws + #endif + #if !os(iOS) + /// Convenience method to load a Flutter asset. + func loadFlutterAsset( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, key: String) throws + #endif + #if !os(iOS) + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + func canGoBack(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> Bool + #endif + #if !os(iOS) + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + func canGoForward(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> Bool + #endif + #if !os(iOS) + /// Navigates to the back item in the back-forward list. + func goBack(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(iOS) + /// Navigates to the forward item in the back-forward list. + func goForward(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(iOS) + /// Reloads the current webpage. + func reload(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + #endif + #if !os(iOS) + /// The page title. + func getTitle(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> String? + #endif + #if !os(iOS) + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + func setAllowsBackForwardNavigationGestures( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, allow: Bool) throws + #endif + #if !os(iOS) + /// The custom user agent string. + func setCustomUserAgent( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, userAgent: String?) throws + #endif + #if !os(iOS) + /// Evaluates the specified JavaScript string. + func evaluateJavaScript( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, javaScriptString: String, + completion: @escaping (Result) -> Void) + #endif + #if !os(iOS) + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + func setInspectable( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, inspectable: Bool) throws + #endif + #if !os(iOS) + /// The custom user agent string. + func getCustomUserAgent(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> String? + #endif +} + +protocol PigeonApiProtocolNSViewWKWebView { +} + +final class PigeonApiNSViewWKWebView: PigeonApiProtocolNSViewWKWebView { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateNSViewWKWebView + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + ///An implementation of [WKWebView] used to access callback methods + var pigeonApiWKWebView: PigeonApiWKWebView { + return pigeonRegistrar.apiDelegate.pigeonApiWKWebView(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateNSViewWKWebView + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiNSViewWKWebView? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + #if !os(iOS) + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let initialConfigurationArg = args[1] as! WKWebViewConfiguration + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, initialConfiguration: initialConfigurationArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let configurationChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.configuration", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + configurationChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let pigeonIdentifierArg = args[1] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.configuration( + pigeonApi: api, pigeonInstance: pigeonInstanceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + configurationChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let setUIDelegateChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setUIDelegate", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setUIDelegateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let delegateArg = args[1] as! WKUIDelegate + do { + try api.pigeonDelegate.setUIDelegate( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, delegate: delegateArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setUIDelegateChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let setNavigationDelegateChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setNavigationDelegate", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setNavigationDelegateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let delegateArg = args[1] as! WKNavigationDelegate + do { + try api.pigeonDelegate.setNavigationDelegate( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, delegate: delegateArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setNavigationDelegateChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let getUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getUrl( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getUrlChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let getEstimatedProgressChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getEstimatedProgress", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getEstimatedProgressChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getEstimatedProgress( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getEstimatedProgressChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let loadChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.load", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let requestArg = args[1] as! URLRequestWrapper + do { + try api.pigeonDelegate.load( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, request: requestArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let loadHtmlStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadHtmlString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadHtmlStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let stringArg = args[1] as! String + let baseUrlArg: String? = nilOrValue(args[2]) + do { + try api.pigeonDelegate.loadHtmlString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, string: stringArg, + baseUrl: baseUrlArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadHtmlStringChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let loadFileUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadFileUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadFileUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let urlArg = args[1] as! String + let readAccessUrlArg = args[2] as! String + do { + try api.pigeonDelegate.loadFileUrl( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, url: urlArg, + readAccessUrl: readAccessUrlArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadFileUrlChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let loadFlutterAssetChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadFlutterAsset", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadFlutterAssetChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let keyArg = args[1] as! String + do { + try api.pigeonDelegate.loadFlutterAsset( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, key: keyArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadFlutterAssetChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let canGoBackChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.canGoBack", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + canGoBackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.canGoBack( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + canGoBackChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let canGoForwardChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.canGoForward", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + canGoForwardChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.canGoForward( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + canGoForwardChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let goBackChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.goBack", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + goBackChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.goBack(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + goBackChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let goForwardChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.goForward", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + goForwardChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.goForward(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + goForwardChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let reloadChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.reload", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + reloadChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + try api.pigeonDelegate.reload(pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + reloadChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let getTitleChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getTitle", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getTitleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getTitle( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getTitleChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let setAllowsBackForwardNavigationGesturesChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setAllowsBackForwardNavigationGestures", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setAllowsBackForwardNavigationGesturesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let allowArg = args[1] as! Bool + do { + try api.pigeonDelegate.setAllowsBackForwardNavigationGestures( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, allow: allowArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setAllowsBackForwardNavigationGesturesChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let setCustomUserAgentChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setCustomUserAgent", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setCustomUserAgentChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let userAgentArg: String? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setCustomUserAgent( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, userAgent: userAgentArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setCustomUserAgentChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let evaluateJavaScriptChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.evaluateJavaScript", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + evaluateJavaScriptChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let javaScriptStringArg = args[1] as! String + api.pigeonDelegate.evaluateJavaScript( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, javaScriptString: javaScriptStringArg + ) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + evaluateJavaScriptChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let setInspectableChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setInspectable", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setInspectableChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + let inspectableArg = args[1] as! Bool + do { + try api.pigeonDelegate.setInspectable( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, inspectable: inspectableArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setInspectableChannel.setMessageHandler(nil) + } + #endif + #if !os(iOS) + let getCustomUserAgentChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getCustomUserAgent", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getCustomUserAgentChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKWebView + do { + let result = try api.pigeonDelegate.getCustomUserAgent( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getCustomUserAgentChannel.setMessageHandler(nil) + } + #endif + } + + #if !os(iOS) + ///Creates a Dart instance of NSViewWKWebView and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKWebView, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif +} +open class PigeonApiDelegateWKWebView { +} + +protocol PigeonApiProtocolWKWebView { +} + +final class PigeonApiWKWebView: PigeonApiProtocolWKWebView { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKWebView + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateWKWebView) + { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of WKWebView and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKWebView, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKWebView.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateWKUIDelegate { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKUIDelegate) throws -> WKUIDelegate +} + +protocol PigeonApiProtocolWKUIDelegate { + /// Creates a new web view. + func onCreateWebView( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + configuration configurationArg: WKWebViewConfiguration, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping (Result) -> Void) + /// Determines whether a web resource, which the security origin object + /// describes, can access to the device’s microphone audio and camera video. + func requestMediaCapturePermission( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + origin originArg: WKSecurityOrigin, frame frameArg: WKFrameInfo, type typeArg: MediaCaptureType, + completion: @escaping (Result) -> Void) + /// Displays a JavaScript alert panel. + func runJavaScriptAlertPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void) + /// Displays a JavaScript confirm panel. + func runJavaScriptConfirmPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void) + /// Displays a JavaScript text input panel. + func runJavaScriptTextInputPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + prompt promptArg: String, defaultText defaultTextArg: String?, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void) +} + +final class PigeonApiWKUIDelegate: PigeonApiProtocolWKUIDelegate { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKUIDelegate + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateWKUIDelegate + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKUIDelegate? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKUIDelegate and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKUIDelegate, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + /// Creates a new web view. + func onCreateWebView( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + configuration configurationArg: WKWebViewConfiguration, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [pigeonInstanceArg, webViewArg, configurationArg, navigationActionArg] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Determines whether a web resource, which the security origin object + /// describes, can access to the device’s microphone audio and camera video. + func requestMediaCapturePermission( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + origin originArg: WKSecurityOrigin, frame frameArg: WKFrameInfo, type typeArg: MediaCaptureType, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, originArg, frameArg, typeArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + PigeonError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! PermissionDecision + completion(.success(result)) + } + } + } + + /// Displays a JavaScript alert panel. + func runJavaScriptAlertPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, messageArg, frameArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + + /// Displays a JavaScript confirm panel. + func runJavaScriptConfirmPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, webViewArg, messageArg, frameArg] as [Any?]) { + response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion( + .failure( + PigeonError( + code: "null-error", + message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! Bool + completion(.success(result)) + } + } + } + + /// Displays a JavaScript text input panel. + func runJavaScriptTextInputPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + prompt promptArg: String, defaultText defaultTextArg: String?, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [pigeonInstanceArg, webViewArg, promptArg, defaultTextArg, frameArg] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + let result: String? = nilOrValue(listResponse[0]) + completion(.success(result)) + } + } + } + +} +protocol PigeonApiDelegateWKHTTPCookieStore { + /// Sets a cookie policy that indicates whether the cookie store allows cookie + /// storage. + func setCookie( + pigeonApi: PigeonApiWKHTTPCookieStore, pigeonInstance: WKHTTPCookieStore, cookie: HTTPCookie, + completion: @escaping (Result) -> Void) +} + +protocol PigeonApiProtocolWKHTTPCookieStore { +} + +final class PigeonApiWKHTTPCookieStore: PigeonApiProtocolWKHTTPCookieStore { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateWKHTTPCookieStore + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateWKHTTPCookieStore + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiWKHTTPCookieStore? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let setCookieChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.setCookie", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setCookieChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! WKHTTPCookieStore + let cookieArg = args[1] as! HTTPCookie + api.pigeonDelegate.setCookie( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, cookie: cookieArg + ) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + setCookieChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of WKHTTPCookieStore and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: WKHTTPCookieStore, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateUIScrollViewDelegate { + #if !os(macOS) + func pigeonDefaultConstructor(pigeonApi: PigeonApiUIScrollViewDelegate) throws + -> UIScrollViewDelegate + #endif +} + +protocol PigeonApiProtocolUIScrollViewDelegate { + #if !os(macOS) + /// Tells the delegate when the user scrolls the content view within the + /// scroll view. + /// + /// Note that this is a convenient method that includes the `contentOffset` of + /// the `scrollView`. + func scrollViewDidScroll( + pigeonInstance pigeonInstanceArg: UIScrollViewDelegate, + scrollView scrollViewArg: UIScrollView, x xArg: Double, y yArg: Double, + completion: @escaping (Result) -> Void) + #endif + +} + +final class PigeonApiUIScrollViewDelegate: PigeonApiProtocolUIScrollViewDelegate { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateUIScrollViewDelegate + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateUIScrollViewDelegate + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiUIScrollViewDelegate? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + #if !os(macOS) + let pigeonDefaultConstructorChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_defaultConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + pigeonDefaultConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + pigeonDefaultConstructorChannel.setMessageHandler(nil) + } + #endif + } + + #if !os(macOS) + ///Creates a Dart instance of UIScrollViewDelegate and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: UIScrollViewDelegate, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif + #if !os(macOS) + /// Tells the delegate when the user scrolls the content view within the + /// scroll view. + /// + /// Note that this is a convenient method that includes the `contentOffset` of + /// the `scrollView`. + func scrollViewDidScroll( + pigeonInstance pigeonInstanceArg: UIScrollViewDelegate, + scrollView scrollViewArg: UIScrollView, x xArg: Double, y yArg: Double, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonInstanceArg, scrollViewArg, xArg, yArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } + #endif + +} +protocol PigeonApiDelegateURLCredential { + /// Creates a URL credential instance for internet password authentication + /// with a given user name and password, using a given persistence setting. + func withUser( + pigeonApi: PigeonApiURLCredential, user: String, password: String, + persistence: UrlCredentialPersistence + ) throws -> URLCredential +} + +protocol PigeonApiProtocolURLCredential { +} + +final class PigeonApiURLCredential: PigeonApiProtocolURLCredential { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURLCredential + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateURLCredential + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiURLCredential? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let withUserChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.withUser", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + withUserChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let userArg = args[1] as! String + let passwordArg = args[2] as! String + let persistenceArg = args[3] as! UrlCredentialPersistence + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.withUser( + pigeonApi: api, user: userArg, password: passwordArg, persistence: persistenceArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + withUserChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of URLCredential and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URLCredential, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateURLProtectionSpace { + /// The receiver’s host. + func host(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> String + /// The receiver’s port. + func port(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> Int64 + /// The receiver’s authentication realm. + func realm(pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace) throws + -> String? + /// The authentication method used by the receiver. + func authenticationMethod( + pigeonApi: PigeonApiURLProtectionSpace, pigeonInstance: URLProtectionSpace + ) throws -> String? +} + +protocol PigeonApiProtocolURLProtectionSpace { +} + +final class PigeonApiURLProtectionSpace: PigeonApiProtocolURLProtectionSpace { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURLProtectionSpace + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateURLProtectionSpace + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + ///Creates a Dart instance of URLProtectionSpace and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URLProtectionSpace, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let hostArg = try! pigeonDelegate.host(pigeonApi: self, pigeonInstance: pigeonInstance) + let portArg = try! pigeonDelegate.port(pigeonApi: self, pigeonInstance: pigeonInstance) + let realmArg = try! pigeonDelegate.realm(pigeonApi: self, pigeonInstance: pigeonInstance) + let authenticationMethodArg = try! pigeonDelegate.authenticationMethod( + pigeonApi: self, pigeonInstance: pigeonInstance) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage( + [pigeonIdentifierArg, hostArg, portArg, realmArg, authenticationMethodArg] as [Any?] + ) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateURLAuthenticationChallenge { + /// The receiver’s protection space. + func getProtectionSpace( + pigeonApi: PigeonApiURLAuthenticationChallenge, pigeonInstance: URLAuthenticationChallenge + ) throws -> URLProtectionSpace +} + +protocol PigeonApiProtocolURLAuthenticationChallenge { +} + +final class PigeonApiURLAuthenticationChallenge: PigeonApiProtocolURLAuthenticationChallenge { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURLAuthenticationChallenge + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init( + pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, + delegate: PigeonApiDelegateURLAuthenticationChallenge + ) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers( + binaryMessenger: FlutterBinaryMessenger, api: PigeonApiURLAuthenticationChallenge? + ) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let getProtectionSpaceChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.getProtectionSpace", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getProtectionSpaceChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URLAuthenticationChallenge + do { + let result = try api.pigeonDelegate.getProtectionSpace( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getProtectionSpaceChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of URLAuthenticationChallenge and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URLAuthenticationChallenge, + completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = + "dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} +protocol PigeonApiDelegateURL { + /// The absolute string for the URL. + func getAbsoluteString(pigeonApi: PigeonApiURL, pigeonInstance: URL) throws -> String +} + +protocol PigeonApiProtocolURL { +} + +final class PigeonApiURL: PigeonApiProtocolURL { + unowned let pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar + let pigeonDelegate: PigeonApiDelegateURL + ///An implementation of [NSObject] used to access callback methods + var pigeonApiNSObject: PigeonApiNSObject { + return pigeonRegistrar.apiDelegate.pigeonApiNSObject(pigeonRegistrar) + } + + init(pigeonRegistrar: WebKitLibraryPigeonProxyApiRegistrar, delegate: PigeonApiDelegateURL) { + self.pigeonRegistrar = pigeonRegistrar + self.pigeonDelegate = delegate + } + static func setUpMessageHandlers(binaryMessenger: FlutterBinaryMessenger, api: PigeonApiURL?) { + let codec: FlutterStandardMessageCodec = + api != nil + ? FlutterStandardMessageCodec( + readerWriter: WebKitLibraryPigeonInternalProxyApiCodecReaderWriter( + pigeonRegistrar: api!.pigeonRegistrar)) + : FlutterStandardMessageCodec.sharedInstance() + let getAbsoluteStringChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.webview_flutter_wkwebview.URL.getAbsoluteString", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getAbsoluteStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! URL + do { + let result = try api.pigeonDelegate.getAbsoluteString( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getAbsoluteStringChannel.setMessageHandler(nil) + } + } + + ///Creates a Dart instance of URL and attaches it to [pigeonInstance]. + func pigeonNewInstance( + pigeonInstance: URL, completion: @escaping (Result) -> Void + ) { + if pigeonRegistrar.ignoreCallsToDart { + completion( + .failure( + PigeonError( + code: "ignore-calls-error", + message: "Calls to Dart are being ignored.", details: ""))) + return + } + if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { + completion(.success(Void())) + return + } + let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( + pigeonInstance as AnyObject) + let binaryMessenger = pigeonRegistrar.binaryMessenger + let codec = pigeonRegistrar.codec + let channelName: String = "dev.flutter.pigeon.webview_flutter_wkwebview.URL.pigeon_newInstance" + let channel = FlutterBasicMessageChannel( + name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewConfigurationProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewConfigurationProxyAPIDelegate.swift new file mode 100644 index 000000000000..ec509742faec --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewConfigurationProxyAPIDelegate.swift @@ -0,0 +1,95 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKWebViewConfiguration`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class WebViewConfigurationProxyAPIDelegate: PigeonApiDelegateWKWebViewConfiguration { + func pigeonDefaultConstructor(pigeonApi: PigeonApiWKWebViewConfiguration) throws + -> WKWebViewConfiguration + { + return WKWebViewConfiguration() + } + + func setUserContentController( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + controller: WKUserContentController + ) throws { + pigeonInstance.userContentController = controller + } + + func getUserContentController( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKUserContentController { + return pigeonInstance.userContentController + } + + func setWebsiteDataStore( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + dataStore: WKWebsiteDataStore + ) throws { + pigeonInstance.websiteDataStore = dataStore + } + + func getWebsiteDataStore( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKWebsiteDataStore { + return pigeonInstance.websiteDataStore + } + + func setPreferences( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + preferences: WKPreferences + ) throws { + pigeonInstance.preferences = preferences + } + + func getPreferences( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration + ) throws -> WKPreferences { + return pigeonInstance.preferences + } + + func setAllowsInlineMediaPlayback( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, allow: Bool + ) throws { + #if !os(macOS) + pigeonInstance.allowsInlineMediaPlayback = allow + #endif + // No-op, rather than error out, on macOS, since it's not a meaningful option on macOS and it's + // easier for clients if it's just ignored. + } + + func setLimitsNavigationsToAppBoundDomains( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, limit: Bool + ) throws { + if #available(iOS 14.0, macOS 11.0, *) { + pigeonInstance.limitsNavigationsToAppBoundDomains = limit + } else { + throw (pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + .createUnsupportedVersionError( + method: "WKWebViewConfiguration.limitsNavigationsToAppBoundDomains", + versionRequirements: "iOS 14.0, macOS 11.0") + } + } + + func setMediaTypesRequiringUserActionForPlayback( + pigeonApi: PigeonApiWKWebViewConfiguration, pigeonInstance: WKWebViewConfiguration, + type: AudiovisualMediaType + ) throws { + switch type { + case .none: + pigeonInstance.mediaTypesRequiringUserActionForPlayback = [] + case .audio: + pigeonInstance.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypes.audio + case .video: + pigeonInstance.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypes.video + case .all: + pigeonInstance.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypes.all + } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterPlugin.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterPlugin.swift new file mode 100644 index 000000000000..bec8b2f2cb85 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterPlugin.swift @@ -0,0 +1,40 @@ +// 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. + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +public class WebViewFlutterPlugin: NSObject, FlutterPlugin { + var proxyApiRegistrar: ProxyAPIRegistrar? + + init(binaryMessenger: FlutterBinaryMessenger) { + proxyApiRegistrar = ProxyAPIRegistrar( + binaryMessenger: binaryMessenger) + proxyApiRegistrar?.setUp() + } + + public static func register(with registrar: FlutterPluginRegistrar) { + #if os(iOS) + let binaryMessenger = registrar.messenger() + #else + let binaryMessenger = registrar.messenger + #endif + let plugin = WebViewFlutterPlugin(binaryMessenger: binaryMessenger) + + let viewFactory = FlutterViewFactory(instanceManager: plugin.proxyApiRegistrar!.instanceManager) + registrar.register(viewFactory, withId: "plugins.flutter.io/webview") + registrar.publish(plugin) + } + + public func detachFromEngine(for registrar: FlutterPluginRegistrar) { + proxyApiRegistrar!.ignoreCallsToDart = true + proxyApiRegistrar!.tearDown() + proxyApiRegistrar = nil + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterWKWebViewExternalAPI.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterWKWebViewExternalAPI.swift new file mode 100644 index 000000000000..e91a93148d88 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewFlutterWKWebViewExternalAPI.swift @@ -0,0 +1,37 @@ +// 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. + +import WebKit + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// App and package facing native API provided by the `webview_flutter_wkwebview` plugin. +/// +/// This class follows the convention of breaking changes of the Dart API, which means that any +/// changes to the class that are not backwards compatible will only be made with a major version +/// change of the plugin. Native code other than this external API does not follow breaking change +/// conventions, so app or plugin clients should not use any other native APIs. +@objc(WebViewFlutterWKWebViewExternalAPI) +public class FWFWebViewFlutterWKWebViewExternalAPI: NSObject { + /// Retrieves the `WKWebView` that is associated with `identifier`. + /// + /// See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an + /// underlying `WKWebView`. + @objc + public static func webView( + forIdentifier identifier: Int64, with registry: FlutterPluginRegistry + ) -> WKWebView? { + let plugin = registry.valuePublished(byPlugin: "WebViewFlutterPlugin") as! WebViewFlutterPlugin + + let webView: WKWebView? = plugin.proxyApiRegistrar?.instanceManager.instance( + forIdentifier: identifier) + return webView + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewProxyAPIDelegate.swift new file mode 100644 index 000000000000..8159a8a69abe --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebViewProxyAPIDelegate.swift @@ -0,0 +1,385 @@ +// 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. + +import WebKit + +class WebViewImpl: WKWebView { + let api: PigeonApiProtocolWKWebView + unowned let registrar: ProxyAPIRegistrar + + init( + api: PigeonApiProtocolWKWebView, registrar: ProxyAPIRegistrar, frame: CGRect, + configuration: WKWebViewConfiguration + ) { + self.api = api + self.registrar = registrar + super.init(frame: frame, configuration: configuration) + #if os(iOS) + scrollView.contentInsetAdjustmentBehavior = .never + if #available(iOS 13.0, *) { + scrollView.automaticallyAdjustsScrollIndicatorInsets = false + } + #endif + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func observeValue( + forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, + context: UnsafeMutableRawPointer? + ) { + NSObjectImpl.handleObserveValue( + withApi: (api as! PigeonApiWKWebView).pigeonApiNSObject, registrar: registrar, + instance: self as NSObject, + forKeyPath: keyPath, of: object, change: change, context: context) + } + + override var frame: CGRect { + get { + return super.frame + } + set { + super.frame = newValue + #if os(iOS) + // Prevents the contentInsets from being adjusted by iOS and gives control to Flutter. + scrollView.contentInset = .zero + + // Adjust contentInset to compensate the adjustedContentInset so the sum will + // always be 0. + if scrollView.adjustedContentInset != .zero { + let insetToAdjust = scrollView.adjustedContentInset + scrollView.contentInset = UIEdgeInsets( + top: -insetToAdjust.top, left: -insetToAdjust.left, bottom: -insetToAdjust.bottom, + right: -insetToAdjust.right) + } + #endif + } + } +} + +/// ProxyApi implementation for `WKWebView`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class WebViewProxyAPIDelegate: PigeonApiDelegateWKWebView, PigeonApiDelegateUIViewWKWebView, + PigeonApiDelegateNSViewWKWebView +{ + func getUIViewWKWebViewAPI(_ api: PigeonApiNSViewWKWebView) -> PigeonApiUIViewWKWebView { + return api.pigeonRegistrar.apiDelegate.pigeonApiUIViewWKWebView(api.pigeonRegistrar) + } + + #if os(iOS) + func scrollView(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> UIScrollView + { + return pigeonInstance.scrollView + } + #endif + + func pigeonDefaultConstructor( + pigeonApi: PigeonApiUIViewWKWebView, initialConfiguration: WKWebViewConfiguration + ) throws -> WKWebView { + return WebViewImpl( + api: pigeonApi.pigeonApiWKWebView, registrar: pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar, + frame: CGRect(), configuration: initialConfiguration) + } + + func pigeonDefaultConstructor( + pigeonApi: PigeonApiNSViewWKWebView, initialConfiguration: WKWebViewConfiguration + ) throws -> WKWebView { + return try pigeonDefaultConstructor( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), initialConfiguration: initialConfiguration) + } + + func configuration(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) + -> WKWebViewConfiguration + { + return pigeonInstance.configuration + } + + func configuration(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> WKWebViewConfiguration + { + return configuration( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func setUIDelegate( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, delegate: WKUIDelegate + ) throws { + pigeonInstance.uiDelegate = delegate + } + + func setUIDelegate( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, delegate: WKUIDelegate + ) throws { + try setUIDelegate( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, + delegate: delegate) + } + + func setNavigationDelegate( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, delegate: WKNavigationDelegate + ) throws { + pigeonInstance.navigationDelegate = delegate + } + + func setNavigationDelegate( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, + delegate: WKNavigationDelegate + ) throws { + try setNavigationDelegate( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, + delegate: delegate) + } + + func getUrl(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> String? { + return pigeonInstance.url?.absoluteString + } + + func getUrl(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> String? { + return try getUrl(pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func getEstimatedProgress(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> Double + { + return pigeonInstance.estimatedProgress + } + + func getEstimatedProgress(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> Double + { + return try getEstimatedProgress( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func load( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, request: URLRequestWrapper + ) throws { + pigeonInstance.load(request.value) + } + + func load( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, request: URLRequestWrapper + ) throws { + try load( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, request: request) + } + + func loadHtmlString( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, string: String, baseUrl: String? + ) throws { + pigeonInstance.loadHTMLString(string, baseURL: baseUrl != nil ? URL(string: baseUrl!)! : nil) + } + + func loadHtmlString( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, string: String, baseUrl: String? + ) throws { + try loadHtmlString( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, string: string, + baseUrl: baseUrl) + } + + func loadFileUrl( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, url: String, + readAccessUrl: String + ) throws { + let fileURL = URL(fileURLWithPath: url, isDirectory: false) + let readAccessURL = URL(fileURLWithPath: readAccessUrl, isDirectory: true) + + pigeonInstance.loadFileURL(fileURL, allowingReadAccessTo: readAccessURL) + } + + func loadFileUrl( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, url: String, + readAccessUrl: String + ) throws { + try loadFileUrl( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, url: url, + readAccessUrl: readAccessUrl) + } + + func loadFlutterAsset(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, key: String) + throws + { + let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar + let assetFilePath = registrar.assetManager.lookupKeyForAsset(key) + + let url = registrar.bundle.url( + forResource: (assetFilePath as NSString).deletingPathExtension, + withExtension: (assetFilePath as NSString).pathExtension) + + if let url = url { + pigeonInstance.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent()) + } else { + throw PigeonError( + code: "FWFURLParsingError", + message: "Failed to find asset with filepath: `\(assetFilePath)`.", details: nil) + } + } + + func loadFlutterAsset(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, key: String) + throws + { + try loadFlutterAsset( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, key: key) + } + + func canGoBack(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> Bool { + return pigeonInstance.canGoBack + } + + func canGoBack(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> Bool { + return try canGoBack( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func canGoForward(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> Bool { + return pigeonInstance.canGoForward + } + + func canGoForward(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> Bool { + return try canGoForward( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func goBack(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws { + pigeonInstance.goBack() + } + + func goBack(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws { + try goBack(pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func goForward(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws { + pigeonInstance.goForward() + } + + func goForward(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws { + try goForward(pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func reload(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws { + pigeonInstance.reload() + } + + func reload(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws { + try reload(pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func getTitle(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws -> String? { + return pigeonInstance.title + } + + func getTitle(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws -> String? { + return try getTitle(pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } + + func setAllowsBackForwardNavigationGestures( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, allow: Bool + ) throws { + pigeonInstance.allowsBackForwardNavigationGestures = allow + } + + func setAllowsBackForwardNavigationGestures( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, allow: Bool + ) throws { + try setAllowsBackForwardNavigationGestures( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, allow: allow) + } + + func setCustomUserAgent( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, userAgent: String? + ) throws { + pigeonInstance.customUserAgent = userAgent + } + + func setCustomUserAgent( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, userAgent: String? + ) throws { + try setCustomUserAgent( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, + userAgent: userAgent) + } + + func evaluateJavaScript( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, javaScriptString: String, + completion: @escaping (Result) -> Void + ) { + pigeonInstance.evaluateJavaScript(javaScriptString) { result, error in + if error == nil { + if let optionalResult = result as Any?? { + switch optionalResult { + case .none: + completion(.success(nil)) + case .some(let value): + if value is String || value is NSNumber { + completion(.success(value)) + } else { + let className = String(describing: value) + debugPrint( + "Return type of evaluateJavaScript is not directly supported: \(className). Returned description of value." + ) + completion(.success((value as AnyObject).description)) + } + } + } + } else { + let error = PigeonError( + code: "FWFEvaluateJavaScriptError", message: "Failed evaluating JavaScript.", + details: error! as NSError) + completion(.failure(error)) + } + } + } + + func evaluateJavaScript( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, javaScriptString: String, + completion: @escaping (Result) -> Void + ) { + evaluateJavaScript( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, + javaScriptString: javaScriptString, completion: completion) + } + + func setInspectable( + pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, inspectable: Bool + ) throws { + if #available(iOS 16.4, macOS 13.3, *) { + pigeonInstance.isInspectable = inspectable + if pigeonInstance.responds(to: Selector(("isInspectable:"))) { + pigeonInstance.perform(Selector(("isInspectable:")), with: inspectable) + } + } else { + throw (pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar) + .createUnsupportedVersionError( + method: "WKWebView.inspectable", + versionRequirements: "iOS 16.4, macOS 13.3") + } + } + + func setInspectable( + pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, inspectable: Bool + ) throws { + try setInspectable( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, + inspectable: inspectable) + } + + func getCustomUserAgent(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws + -> String? + { + return pigeonInstance.customUserAgent + } + + func getCustomUserAgent(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws + -> String? + { + return try getCustomUserAgent( + pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebsiteDataStoreProxyAPIDelegate.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebsiteDataStoreProxyAPIDelegate.swift new file mode 100644 index 000000000000..d58e49628f02 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebsiteDataStoreProxyAPIDelegate.swift @@ -0,0 +1,62 @@ +// 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. + +import WebKit + +/// ProxyApi implementation for `WKWebsiteDataStore`. +/// +/// This class may handle instantiating native object instances that are attached to a Dart instance +/// or handle method calls on the associated native class or an instance of that class. +class WebsiteDataStoreProxyAPIDelegate: PigeonApiDelegateWKWebsiteDataStore { + func defaultDataStore(pigeonApi: PigeonApiWKWebsiteDataStore) -> WKWebsiteDataStore { + return WKWebsiteDataStore.default() + } + + func httpCookieStore(pigeonApi: PigeonApiWKWebsiteDataStore, pigeonInstance: WKWebsiteDataStore) + -> WKHTTPCookieStore + { + return pigeonInstance.httpCookieStore + } + + func removeDataOfTypes( + pigeonApi: PigeonApiWKWebsiteDataStore, pigeonInstance: WKWebsiteDataStore, + dataTypes: [WebsiteDataType], modificationTimeInSecondsSinceEpoch: Double, + completion: @escaping (Result) -> Void + ) { + let nativeDataTypes = Set( + dataTypes.map { + switch $0 { + case .cookies: + return WKWebsiteDataTypeCookies + case .memoryCache: + return WKWebsiteDataTypeMemoryCache + case .diskCache: + return WKWebsiteDataTypeDiskCache + case .offlineWebApplicationCache: + return WKWebsiteDataTypeOfflineWebApplicationCache + case .localStorage: + return WKWebsiteDataTypeLocalStorage + case .sessionStorage: + return WKWebsiteDataTypeSessionStorage + case .webSQLDatabases: + return WKWebsiteDataTypeWebSQLDatabases + case .indexedDBDatabases: + return WKWebsiteDataTypeIndexedDBDatabases + } + }) + + pigeonInstance.fetchDataRecords(ofTypes: nativeDataTypes) { records in + if records.isEmpty { + completion(.success(false)) + } else { + pigeonInstance.removeData( + ofTypes: nativeDataTypes, + modifiedSince: Date(timeIntervalSince1970: modificationTimeInSecondsSinceEpoch) + ) { + completion(.success(true)) + } + } + } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/FlutterWebView.modulemap b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/FlutterWebView.modulemap deleted file mode 100644 index 1b7eaf646ee9..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/FlutterWebView.modulemap +++ /dev/null @@ -1,10 +0,0 @@ -framework module webview_flutter_wkwebview { - umbrella header "webview-umbrella.h" - - export * - module * { export * } - - explicit module Test { - header "FWFInstanceManager_Test.h" - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview-umbrella.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview-umbrella.h deleted file mode 100644 index e553b0a288b6..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview-umbrella.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.h deleted file mode 100644 index e57f238d9aab..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FLTWebViewFlutterPlugin.h +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -@interface FLTWebViewFlutterPlugin : NSObject -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFDataConverters.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFDataConverters.h deleted file mode 100644 index b007ff901b98..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFDataConverters.h +++ /dev/null @@ -1,210 +0,0 @@ -// 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. - -#import "FWFGeneratedWebKitApis.h" - -#import - -NS_ASSUME_NONNULL_BEGIN - -/// Converts an FWFNSUrlRequestData to an NSURLRequest. -/// -/// @param data The data object containing information to create an NSURLRequest. -/// -/// @return An NSURLRequest or nil if data could not be converted. -extern NSURLRequest *_Nullable FWFNativeNSURLRequestFromRequestData(FWFNSUrlRequestData *data); - -/// Converts an FWFNSHttpCookieData to an NSHTTPCookie. -/// -/// @param data The data object containing information to create an NSHTTPCookie. -/// -/// @return An NSHTTPCookie or nil if data could not be converted. -extern NSHTTPCookie *_Nullable FWFNativeNSHTTPCookieFromCookieData(FWFNSHttpCookieData *data); - -/// Converts an FWFNSKeyValueObservingOptionsEnumData to an NSKeyValueObservingOptions. -/// -/// @param data The data object containing information to create an NSKeyValueObservingOptions. -/// -/// @return An NSKeyValueObservingOptions or -1 if data could not be converted. -extern NSKeyValueObservingOptions FWFNativeNSKeyValueObservingOptionsFromEnumData( - FWFNSKeyValueObservingOptionsEnumData *data); - -/// Converts an FWFNSHTTPCookiePropertyKeyEnumData to an NSHTTPCookiePropertyKey. -/// -/// @param data The data object containing information to create an NSHTTPCookiePropertyKey. -/// -/// @return An NSHttpCookiePropertyKey or nil if data could not be converted. -extern NSHTTPCookiePropertyKey _Nullable FWFNativeNSHTTPCookiePropertyKeyFromEnumData( - FWFNSHttpCookiePropertyKeyEnumData *data); - -/// Converts a WKUserScriptData to a WKUserScript. -/// -/// @param data The data object containing information to create a WKUserScript. -/// -/// @return A WKUserScript or nil if data could not be converted. -extern WKUserScript *FWFNativeWKUserScriptFromScriptData(FWFWKUserScriptData *data); - -/// Converts an FWFWKUserScriptInjectionTimeEnumData to a WKUserScriptInjectionTime. -/// -/// @param data The data object containing information to create a WKUserScriptInjectionTime. -/// -/// @return A WKUserScriptInjectionTime or -1 if data could not be converted. -extern WKUserScriptInjectionTime FWFNativeWKUserScriptInjectionTimeFromEnumData( - FWFWKUserScriptInjectionTimeEnumData *data); - -/// Converts an FWFWKAudiovisualMediaTypeEnumData to a WKAudiovisualMediaTypes. -/// -/// @param data The data object containing information to create a WKAudiovisualMediaTypes. -/// -/// @return A WKAudiovisualMediaType or -1 if data could not be converted. -extern WKAudiovisualMediaTypes FWFNativeWKAudiovisualMediaTypeFromEnumData( - FWFWKAudiovisualMediaTypeEnumData *data); - -/// Converts an FWFWKWebsiteDataTypeEnumData to a WKWebsiteDataType. -/// -/// @param data The data object containing information to create a WKWebsiteDataType. -/// -/// @return A WKWebsiteDataType or nil if data could not be converted. -extern NSString *_Nullable FWFNativeWKWebsiteDataTypeFromEnumData( - FWFWKWebsiteDataTypeEnumData *data); - -/// Converts a WKNavigationAction to an FWFWKNavigationActionData. -/// -/// @param action The object containing information to create a WKNavigationActionData. -/// -/// @return A FWFWKNavigationActionData. -extern FWFWKNavigationActionData *FWFWKNavigationActionDataFromNativeWKNavigationAction( - WKNavigationAction *action); - -/// Converts a NSURLRequest to an FWFNSUrlRequestData. -/// -/// @param request The object containing information to create a WKNavigationActionData. -/// -/// @return A FWFNSUrlRequestData. -extern FWFNSUrlRequestData *FWFNSUrlRequestDataFromNativeNSURLRequest(NSURLRequest *request); - -/** - * Converts a WKNavigationResponse to an FWFWKNavigationResponseData. - * - * @param response The object containing information to create a WKNavigationResponseData. - * - * @return A FWFWKNavigationResponseData. - */ -extern FWFWKNavigationResponseData *FWFWKNavigationResponseDataFromNativeNavigationResponse( - WKNavigationResponse *response); -/** - * Converts a NSURLResponse to an FWFNSHttpUrlResponseData. - * - * @param response The object containing information to create a WKNavigationActionData. - * - * @return A FWFNSHttpUrlResponseData. - */ -extern FWFNSHttpUrlResponseData *FWFNSHttpUrlResponseDataFromNativeNSURLResponse( - NSURLResponse *response); - -/** - * Converts a WKFrameInfo to an FWFWKFrameInfoData. - * - * @param info The object containing information to create a FWFWKFrameInfoData. - * - * @return A FWFWKFrameInfoData. - */ -extern FWFWKFrameInfoData *FWFWKFrameInfoDataFromNativeWKFrameInfo(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 FWFNativeWKNavigationActionPolicyFromEnumData( - FWFWKNavigationActionPolicyEnumData *data); - -/** - * Converts an FWFWKNavigationResponsePolicyEnumData to a WKNavigationResponsePolicy. - * - * @param policy The data object containing information to create a WKNavigationResponsePolicy. - * - * @return A WKNavigationResponsePolicy or -1 if data could not be converted. - */ -extern WKNavigationResponsePolicy FWFNativeWKNavigationResponsePolicyFromEnum( - FWFWKNavigationResponsePolicyEnum policy); - -/** - * Converts a NSError to an FWFNSErrorData. - * - * @param error The object containing information to create a FWFNSErrorData. - * - * @return A FWFNSErrorData. - */ -extern FWFNSErrorData *FWFNSErrorDataFromNativeNSError(NSError *error); - -/// Converts an NSKeyValueChangeKey to a FWFNSKeyValueChangeKeyEnumData. -/// -/// @param key The data object containing information to create a FWFNSKeyValueChangeKeyEnumData. -/// -/// @return A FWFNSKeyValueChangeKeyEnumData. -extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNativeNSKeyValueChangeKey( - NSKeyValueChangeKey key); - -/// Converts a WKScriptMessage to an FWFWKScriptMessageData. -/// -/// @param message The object containing information to create a FWFWKScriptMessageData. -/// -/// @return A FWFWKScriptMessageData. -extern FWFWKScriptMessageData *FWFWKScriptMessageDataFromNativeWKScriptMessage( - WKScriptMessage *message); - -/// Converts a WKNavigationType to an FWFWKNavigationType. -/// -/// @param type The object containing information to create a FWFWKNavigationType -/// -/// @return A FWFWKNavigationType. -extern FWFWKNavigationType FWFWKNavigationTypeFromNativeWKNavigationType(WKNavigationType type); - -/// Converts a WKSecurityOrigin to an FWFWKSecurityOriginData. -/// -/// @param origin The object containing information to create an FWFWKSecurityOriginData. -/// -/// @return An FWFWKSecurityOriginData. -extern FWFWKSecurityOriginData *FWFWKSecurityOriginDataFromNativeWKSecurityOrigin( - WKSecurityOrigin *origin); - -/// Converts an FWFWKPermissionDecisionData to a WKPermissionDecision. -/// -/// @param data The data object containing information to create a WKPermissionDecision. -/// -/// @return A WKPermissionDecision or -1 if data could not be converted. -API_AVAILABLE(ios(15.0), macos(12)) -extern WKPermissionDecision FWFNativeWKPermissionDecisionFromData( - FWFWKPermissionDecisionData *data); - -/// Converts an WKMediaCaptureType to a FWFWKMediaCaptureTypeData. -/// -/// @param type The data object containing information to create a FWFWKMediaCaptureTypeData. -/// -/// @return A FWFWKMediaCaptureTypeData or nil if data could not be converted. -API_AVAILABLE(ios(15.0), macos(12)) -extern FWFWKMediaCaptureTypeData *FWFWKMediaCaptureTypeDataFromNativeWKMediaCaptureType( - WKMediaCaptureType type); - -/// Converts an FWFNSUrlSessionAuthChallengeDisposition to an NSURLSessionAuthChallengeDisposition. -/// -/// @param value The object containing information to create an -/// NSURLSessionAuthChallengeDisposition. -/// -/// @return A NSURLSessionAuthChallengeDisposition or -1 if data could not be converted. -extern NSURLSessionAuthChallengeDisposition -FWFNativeNSURLSessionAuthChallengeDispositionFromFWFNSUrlSessionAuthChallengeDisposition( - FWFNSUrlSessionAuthChallengeDisposition value); - -/// Converts an FWFNSUrlCredentialPersistence to an NSURLCredentialPersistence. -/// -/// @param value The object containing information to create an NSURLCredentialPersistence. -/// -/// @return A NSURLCredentialPersistence or -1 if data could not be converted. -extern NSURLCredentialPersistence -FWFNativeNSURLCredentialPersistenceFromFWFNSUrlCredentialPersistence( - FWFNSUrlCredentialPersistence value); - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h deleted file mode 100644 index dd5fdf97bbcf..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h +++ /dev/null @@ -1,1251 +0,0 @@ -// 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 (v18.0.0), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#import - -@protocol FlutterBinaryMessenger; -@protocol FlutterMessageCodec; -@class FlutterError; -@class FlutterStandardTypedData; - -NS_ASSUME_NONNULL_BEGIN - -/// Mirror of NSKeyValueObservingOptions. -/// -/// See -/// https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions?language=objc. -typedef NS_ENUM(NSUInteger, FWFNSKeyValueObservingOptionsEnum) { - FWFNSKeyValueObservingOptionsEnumNewValue = 0, - FWFNSKeyValueObservingOptionsEnumOldValue = 1, - FWFNSKeyValueObservingOptionsEnumInitialValue = 2, - FWFNSKeyValueObservingOptionsEnumPriorNotification = 3, -}; - -/// Wrapper for FWFNSKeyValueObservingOptionsEnum to allow for nullability. -@interface FWFNSKeyValueObservingOptionsEnumBox : NSObject -@property(nonatomic, assign) FWFNSKeyValueObservingOptionsEnum value; -- (instancetype)initWithValue:(FWFNSKeyValueObservingOptionsEnum)value; -@end - -/// Mirror of NSKeyValueChange. -/// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange?language=objc. -typedef NS_ENUM(NSUInteger, FWFNSKeyValueChangeEnum) { - FWFNSKeyValueChangeEnumSetting = 0, - FWFNSKeyValueChangeEnumInsertion = 1, - FWFNSKeyValueChangeEnumRemoval = 2, - FWFNSKeyValueChangeEnumReplacement = 3, -}; - -/// Wrapper for FWFNSKeyValueChangeEnum to allow for nullability. -@interface FWFNSKeyValueChangeEnumBox : NSObject -@property(nonatomic, assign) FWFNSKeyValueChangeEnum value; -- (instancetype)initWithValue:(FWFNSKeyValueChangeEnum)value; -@end - -/// Mirror of NSKeyValueChangeKey. -/// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey?language=objc. -typedef NS_ENUM(NSUInteger, FWFNSKeyValueChangeKeyEnum) { - FWFNSKeyValueChangeKeyEnumIndexes = 0, - FWFNSKeyValueChangeKeyEnumKind = 1, - FWFNSKeyValueChangeKeyEnumNewValue = 2, - FWFNSKeyValueChangeKeyEnumNotificationIsPrior = 3, - FWFNSKeyValueChangeKeyEnumOldValue = 4, - FWFNSKeyValueChangeKeyEnumUnknown = 5, -}; - -/// Wrapper for FWFNSKeyValueChangeKeyEnum to allow for nullability. -@interface FWFNSKeyValueChangeKeyEnumBox : NSObject -@property(nonatomic, assign) FWFNSKeyValueChangeKeyEnum value; -- (instancetype)initWithValue:(FWFNSKeyValueChangeKeyEnum)value; -@end - -/// Mirror of WKUserScriptInjectionTime. -/// -/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKUserScriptInjectionTimeEnum) { - FWFWKUserScriptInjectionTimeEnumAtDocumentStart = 0, - FWFWKUserScriptInjectionTimeEnumAtDocumentEnd = 1, -}; - -/// Wrapper for FWFWKUserScriptInjectionTimeEnum to allow for nullability. -@interface FWFWKUserScriptInjectionTimeEnumBox : NSObject -@property(nonatomic, assign) FWFWKUserScriptInjectionTimeEnum value; -- (instancetype)initWithValue:(FWFWKUserScriptInjectionTimeEnum)value; -@end - -/// Mirror of WKAudiovisualMediaTypes. -/// -/// See -/// [WKAudiovisualMediaTypes](https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes?language=objc). -typedef NS_ENUM(NSUInteger, FWFWKAudiovisualMediaTypeEnum) { - FWFWKAudiovisualMediaTypeEnumNone = 0, - FWFWKAudiovisualMediaTypeEnumAudio = 1, - FWFWKAudiovisualMediaTypeEnumVideo = 2, - FWFWKAudiovisualMediaTypeEnumAll = 3, -}; - -/// Wrapper for FWFWKAudiovisualMediaTypeEnum to allow for nullability. -@interface FWFWKAudiovisualMediaTypeEnumBox : NSObject -@property(nonatomic, assign) FWFWKAudiovisualMediaTypeEnum value; -- (instancetype)initWithValue:(FWFWKAudiovisualMediaTypeEnum)value; -@end - -/// Mirror of WKWebsiteDataTypes. -/// -/// See -/// https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKWebsiteDataTypeEnum) { - FWFWKWebsiteDataTypeEnumCookies = 0, - FWFWKWebsiteDataTypeEnumMemoryCache = 1, - FWFWKWebsiteDataTypeEnumDiskCache = 2, - FWFWKWebsiteDataTypeEnumOfflineWebApplicationCache = 3, - FWFWKWebsiteDataTypeEnumLocalStorage = 4, - FWFWKWebsiteDataTypeEnumSessionStorage = 5, - FWFWKWebsiteDataTypeEnumWebSQLDatabases = 6, - FWFWKWebsiteDataTypeEnumIndexedDBDatabases = 7, -}; - -/// Wrapper for FWFWKWebsiteDataTypeEnum to allow for nullability. -@interface FWFWKWebsiteDataTypeEnumBox : NSObject -@property(nonatomic, assign) FWFWKWebsiteDataTypeEnum value; -- (instancetype)initWithValue:(FWFWKWebsiteDataTypeEnum)value; -@end - -/// Mirror of WKNavigationActionPolicy. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKNavigationActionPolicyEnum) { - FWFWKNavigationActionPolicyEnumAllow = 0, - FWFWKNavigationActionPolicyEnumCancel = 1, -}; - -/// Wrapper for FWFWKNavigationActionPolicyEnum to allow for nullability. -@interface FWFWKNavigationActionPolicyEnumBox : NSObject -@property(nonatomic, assign) FWFWKNavigationActionPolicyEnum value; -- (instancetype)initWithValue:(FWFWKNavigationActionPolicyEnum)value; -@end - -/// Mirror of WKNavigationResponsePolicy. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKNavigationResponsePolicyEnum) { - FWFWKNavigationResponsePolicyEnumAllow = 0, - FWFWKNavigationResponsePolicyEnumCancel = 1, -}; - -/// Wrapper for FWFWKNavigationResponsePolicyEnum to allow for nullability. -@interface FWFWKNavigationResponsePolicyEnumBox : NSObject -@property(nonatomic, assign) FWFWKNavigationResponsePolicyEnum value; -- (instancetype)initWithValue:(FWFWKNavigationResponsePolicyEnum)value; -@end - -/// Mirror of NSHTTPCookiePropertyKey. -/// -/// See https://developer.apple.com/documentation/foundation/nshttpcookiepropertykey. -typedef NS_ENUM(NSUInteger, FWFNSHttpCookiePropertyKeyEnum) { - FWFNSHttpCookiePropertyKeyEnumComment = 0, - FWFNSHttpCookiePropertyKeyEnumCommentUrl = 1, - FWFNSHttpCookiePropertyKeyEnumDiscard = 2, - FWFNSHttpCookiePropertyKeyEnumDomain = 3, - FWFNSHttpCookiePropertyKeyEnumExpires = 4, - FWFNSHttpCookiePropertyKeyEnumMaximumAge = 5, - FWFNSHttpCookiePropertyKeyEnumName = 6, - FWFNSHttpCookiePropertyKeyEnumOriginUrl = 7, - FWFNSHttpCookiePropertyKeyEnumPath = 8, - FWFNSHttpCookiePropertyKeyEnumPort = 9, - FWFNSHttpCookiePropertyKeyEnumSameSitePolicy = 10, - FWFNSHttpCookiePropertyKeyEnumSecure = 11, - FWFNSHttpCookiePropertyKeyEnumValue = 12, - FWFNSHttpCookiePropertyKeyEnumVersion = 13, -}; - -/// Wrapper for FWFNSHttpCookiePropertyKeyEnum to allow for nullability. -@interface FWFNSHttpCookiePropertyKeyEnumBox : NSObject -@property(nonatomic, assign) FWFNSHttpCookiePropertyKeyEnum value; -- (instancetype)initWithValue:(FWFNSHttpCookiePropertyKeyEnum)value; -@end - -/// An object that contains information about an action that causes navigation -/// to occur. -/// -/// Wraps -/// [WKNavigationType](https://developer.apple.com/documentation/webkit/wknavigationaction?language=objc). -typedef NS_ENUM(NSUInteger, FWFWKNavigationType) { - /// A link activation. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypelinkactivated?language=objc. - FWFWKNavigationTypeLinkActivated = 0, - /// A request to submit a form. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformsubmitted?language=objc. - FWFWKNavigationTypeSubmitted = 1, - /// A request for the frame’s next or previous item. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypebackforward?language=objc. - FWFWKNavigationTypeBackForward = 2, - /// A request to reload the webpage. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypereload?language=objc. - FWFWKNavigationTypeReload = 3, - /// A request to resubmit a form. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformresubmitted?language=objc. - FWFWKNavigationTypeFormResubmitted = 4, - /// A navigation request that originates for some other reason. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. - FWFWKNavigationTypeOther = 5, - /// An unknown navigation type. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. - FWFWKNavigationTypeUnknown = 6, -}; - -/// Wrapper for FWFWKNavigationType to allow for nullability. -@interface FWFWKNavigationTypeBox : NSObject -@property(nonatomic, assign) FWFWKNavigationType value; -- (instancetype)initWithValue:(FWFWKNavigationType)value; -@end - -/// Possible permission decisions for device resource access. -/// -/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKPermissionDecision) { - /// Deny permission for the requested resource. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiondeny?language=objc. - FWFWKPermissionDecisionDeny = 0, - /// Deny permission for the requested resource. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiongrant?language=objc. - FWFWKPermissionDecisionGrant = 1, - /// Prompt the user for permission for the requested resource. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisionprompt?language=objc. - FWFWKPermissionDecisionPrompt = 2, -}; - -/// Wrapper for FWFWKPermissionDecision to allow for nullability. -@interface FWFWKPermissionDecisionBox : NSObject -@property(nonatomic, assign) FWFWKPermissionDecision value; -- (instancetype)initWithValue:(FWFWKPermissionDecision)value; -@end - -/// List of the types of media devices that can capture audio, video, or both. -/// -/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype?language=objc. -typedef NS_ENUM(NSUInteger, FWFWKMediaCaptureType) { - /// A media device that can capture video. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecamera?language=objc. - FWFWKMediaCaptureTypeCamera = 0, - /// A media device or devices that can capture audio and video. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecameraandmicrophone?language=objc. - FWFWKMediaCaptureTypeCameraAndMicrophone = 1, - /// A media device that can capture audio. - /// - /// See - /// https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypemicrophone?language=objc. - FWFWKMediaCaptureTypeMicrophone = 2, - /// An unknown media device. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. - FWFWKMediaCaptureTypeUnknown = 3, -}; - -/// Wrapper for FWFWKMediaCaptureType to allow for nullability. -@interface FWFWKMediaCaptureTypeBox : NSObject -@property(nonatomic, assign) FWFWKMediaCaptureType value; -- (instancetype)initWithValue:(FWFWKMediaCaptureType)value; -@end - -/// Responses to an authentication challenge. -/// -/// See -/// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition?language=objc. -typedef NS_ENUM(NSUInteger, FWFNSUrlSessionAuthChallengeDisposition) { - /// Use the specified credential, which may be nil. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeusecredential?language=objc. - FWFNSUrlSessionAuthChallengeDispositionUseCredential = 0, - /// Use the default handling for the challenge as though this delegate method - /// were not implemented. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeperformdefaulthandling?language=objc. - FWFNSUrlSessionAuthChallengeDispositionPerformDefaultHandling = 1, - /// Cancel the entire request. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengecancelauthenticationchallenge?language=objc. - FWFNSUrlSessionAuthChallengeDispositionCancelAuthenticationChallenge = 2, - /// Reject this challenge, and call the authentication delegate method again - /// with the next authentication protection space. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengerejectprotectionspace?language=objc. - FWFNSUrlSessionAuthChallengeDispositionRejectProtectionSpace = 3, -}; - -/// Wrapper for FWFNSUrlSessionAuthChallengeDisposition to allow for nullability. -@interface FWFNSUrlSessionAuthChallengeDispositionBox : NSObject -@property(nonatomic, assign) FWFNSUrlSessionAuthChallengeDisposition value; -- (instancetype)initWithValue:(FWFNSUrlSessionAuthChallengeDisposition)value; -@end - -/// Specifies how long a credential will be kept. -typedef NS_ENUM(NSUInteger, FWFNSUrlCredentialPersistence) { - /// The credential should not be stored. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencenone?language=objc. - FWFNSUrlCredentialPersistenceNone = 0, - /// The credential should be stored only for this session. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistenceforsession?language=objc. - FWFNSUrlCredentialPersistenceSession = 1, - /// The credential should be stored in the keychain. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencepermanent?language=objc. - FWFNSUrlCredentialPersistencePermanent = 2, - /// The credential should be stored permanently in the keychain, and in - /// addition should be distributed to other devices based on the owning Apple - /// ID. - /// - /// See - /// https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencesynchronizable?language=objc. - FWFNSUrlCredentialPersistenceSynchronizable = 3, -}; - -/// Wrapper for FWFNSUrlCredentialPersistence to allow for nullability. -@interface FWFNSUrlCredentialPersistenceBox : NSObject -@property(nonatomic, assign) FWFNSUrlCredentialPersistence value; -- (instancetype)initWithValue:(FWFNSUrlCredentialPersistence)value; -@end - -@class FWFNSKeyValueObservingOptionsEnumData; -@class FWFNSKeyValueChangeKeyEnumData; -@class FWFWKUserScriptInjectionTimeEnumData; -@class FWFWKAudiovisualMediaTypeEnumData; -@class FWFWKWebsiteDataTypeEnumData; -@class FWFWKNavigationActionPolicyEnumData; -@class FWFNSHttpCookiePropertyKeyEnumData; -@class FWFWKPermissionDecisionData; -@class FWFWKMediaCaptureTypeData; -@class FWFNSUrlRequestData; -@class FWFNSHttpUrlResponseData; -@class FWFWKUserScriptData; -@class FWFWKNavigationActionData; -@class FWFWKNavigationResponseData; -@class FWFWKFrameInfoData; -@class FWFNSErrorData; -@class FWFWKScriptMessageData; -@class FWFWKSecurityOriginData; -@class FWFNSHttpCookieData; -@class FWFObjectOrIdentifier; -@class FWFAuthenticationChallengeResponse; - -@interface FWFNSKeyValueObservingOptionsEnumData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(FWFNSKeyValueObservingOptionsEnum)value; -@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; -+ (instancetype)makeWithValue:(FWFWKUserScriptInjectionTimeEnum)value; -@property(nonatomic, assign) FWFWKUserScriptInjectionTimeEnum value; -@end - -@interface FWFWKAudiovisualMediaTypeEnumData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(FWFWKAudiovisualMediaTypeEnum)value; -@property(nonatomic, assign) FWFWKAudiovisualMediaTypeEnum value; -@end - -@interface FWFWKWebsiteDataTypeEnumData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(FWFWKWebsiteDataTypeEnum)value; -@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; -+ (instancetype)makeWithValue:(FWFNSHttpCookiePropertyKeyEnum)value; -@property(nonatomic, assign) FWFNSHttpCookiePropertyKeyEnum value; -@end - -@interface FWFWKPermissionDecisionData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(FWFWKPermissionDecision)value; -@property(nonatomic, assign) FWFWKPermissionDecision value; -@end - -@interface FWFWKMediaCaptureTypeData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(FWFWKMediaCaptureType)value; -@property(nonatomic, assign) FWFWKMediaCaptureType value; -@end - -/// Mirror of NSURLRequest. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlrequest?language=objc. -@interface FWFNSUrlRequestData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithUrl:(NSString *)url - httpMethod:(nullable NSString *)httpMethod - httpBody:(nullable FlutterStandardTypedData *)httpBody - allHttpHeaderFields:(NSDictionary *)allHttpHeaderFields; -@property(nonatomic, copy) NSString *url; -@property(nonatomic, copy, nullable) NSString *httpMethod; -@property(nonatomic, strong, nullable) FlutterStandardTypedData *httpBody; -@property(nonatomic, copy) NSDictionary *allHttpHeaderFields; -@end - -/// Mirror of NSURLResponse. -/// -/// See https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc. -@interface FWFNSHttpUrlResponseData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithStatusCode:(NSInteger)statusCode; -@property(nonatomic, assign) NSInteger statusCode; -@end - -/// Mirror of WKUserScript. -/// -/// See https://developer.apple.com/documentation/webkit/wkuserscript?language=objc. -@interface FWFWKUserScriptData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithSource:(NSString *)source - injectionTime:(nullable FWFWKUserScriptInjectionTimeEnumData *)injectionTime - isMainFrameOnly:(BOOL)isMainFrameOnly; -@property(nonatomic, copy) NSString *source; -@property(nonatomic, strong, nullable) FWFWKUserScriptInjectionTimeEnumData *injectionTime; -@property(nonatomic, assign) BOOL isMainFrameOnly; -@end - -/// Mirror of WKNavigationAction. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationaction. -@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 - navigationType:(FWFWKNavigationType)navigationType; -@property(nonatomic, strong) FWFNSUrlRequestData *request; -@property(nonatomic, strong) FWFWKFrameInfoData *targetFrame; -@property(nonatomic, assign) FWFWKNavigationType navigationType; -@end - -/// Mirror of WKNavigationResponse. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationresponse. -@interface FWFWKNavigationResponseData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithResponse:(FWFNSHttpUrlResponseData *)response - forMainFrame:(BOOL)forMainFrame; -@property(nonatomic, strong) FWFNSHttpUrlResponseData *response; -@property(nonatomic, assign) BOOL forMainFrame; -@end - -/// Mirror of WKFrameInfo. -/// -/// See https://developer.apple.com/documentation/webkit/wkframeinfo?language=objc. -@interface FWFWKFrameInfoData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithIsMainFrame:(BOOL)isMainFrame request:(FWFNSUrlRequestData *)request; -@property(nonatomic, assign) BOOL isMainFrame; -@property(nonatomic, strong) FWFNSUrlRequestData *request; -@end - -/// Mirror of NSError. -/// -/// See https://developer.apple.com/documentation/foundation/nserror?language=objc. -@interface FWFNSErrorData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithCode:(NSInteger)code - domain:(NSString *)domain - userInfo:(nullable NSDictionary *)userInfo; -@property(nonatomic, assign) NSInteger code; -@property(nonatomic, copy) NSString *domain; -@property(nonatomic, copy, nullable) NSDictionary *userInfo; -@end - -/// Mirror of WKScriptMessage. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessage?language=objc. -@interface FWFWKScriptMessageData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithName:(NSString *)name body:(nullable id)body; -@property(nonatomic, copy) NSString *name; -@property(nonatomic, strong, nullable) id body; -@end - -/// Mirror of WKSecurityOrigin. -/// -/// See https://developer.apple.com/documentation/webkit/wksecurityorigin?language=objc. -@interface FWFWKSecurityOriginData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithHost:(NSString *)host port:(NSInteger)port protocol:(NSString *)protocol; -@property(nonatomic, copy) NSString *host; -@property(nonatomic, assign) NSInteger port; -@property(nonatomic, copy) NSString *protocol; -@end - -/// Mirror of NSHttpCookieData. -/// -/// See https://developer.apple.com/documentation/foundation/nshttpcookie?language=objc. -@interface FWFNSHttpCookieData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithPropertyKeys:(NSArray *)propertyKeys - propertyValues:(NSArray *)propertyValues; -@property(nonatomic, copy) NSArray *propertyKeys; -@property(nonatomic, copy) NSArray *propertyValues; -@end - -/// An object that can represent either a value supported by -/// `StandardMessageCodec`, a data class in this pigeon file, or an identifier -/// of an object stored in an `InstanceManager`. -@interface FWFObjectOrIdentifier : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithValue:(nullable id)value isIdentifier:(BOOL)isIdentifier; -@property(nonatomic, strong, nullable) id value; -/// Whether value is an int that is used to retrieve an instance stored in an -/// `InstanceManager`. -@property(nonatomic, assign) BOOL isIdentifier; -@end - -@interface FWFAuthenticationChallengeResponse : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithDisposition:(FWFNSUrlSessionAuthChallengeDisposition)disposition - credentialIdentifier:(nullable NSNumber *)credentialIdentifier; -@property(nonatomic, assign) FWFNSUrlSessionAuthChallengeDisposition disposition; -@property(nonatomic, strong, nullable) NSNumber *credentialIdentifier; -@end - -/// The codec used by FWFWKWebsiteDataStoreHostApi. -NSObject *FWFWKWebsiteDataStoreHostApiGetCodec(void); - -/// Mirror of WKWebsiteDataStore. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore?language=objc. -@protocol FWFWKWebsiteDataStoreHostApi -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)createDefaultDataStoreWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)removeDataFromDataStoreWithIdentifier:(NSInteger)identifier - ofTypes:(NSArray *)dataTypes - modifiedSince:(double)modificationTimeInSecondsSinceEpoch - completion:(void (^)(NSNumber *_Nullable, - FlutterError *_Nullable))completion; -@end - -extern void SetUpFWFWKWebsiteDataStoreHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKWebsiteDataStoreHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFUIViewHostApi. -NSObject *FWFUIViewHostApiGetCodec(void); - -/// Mirror of UIView. -/// -/// See https://developer.apple.com/documentation/uikit/uiview?language=objc. -@protocol FWFUIViewHostApi -- (void)setBackgroundColorForViewWithIdentifier:(NSInteger)identifier - toValue:(nullable NSNumber *)value - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setOpaqueForViewWithIdentifier:(NSInteger)identifier - isOpaque:(BOOL)opaque - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFUIViewHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFUIViewHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFUIScrollViewHostApi. -NSObject *FWFUIScrollViewHostApiGetCodec(void); - -/// Mirror of UIScrollView. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollview?language=objc. -@protocol FWFUIScrollViewHostApi -- (void)createFromWebViewWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. -- (nullable NSArray *) - contentOffsetForScrollViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)scrollByForScrollViewWithIdentifier:(NSInteger)identifier - x:(double)x - y:(double)y - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setContentOffsetForScrollViewWithIdentifier:(NSInteger)identifier - toX:(double)x - y:(double)y - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setDelegateForScrollViewWithIdentifier:(NSInteger)identifier - uiScrollViewDelegateIdentifier:(nullable NSNumber *)uiScrollViewDelegateIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFUIScrollViewHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFUIScrollViewHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFWKWebViewConfigurationHostApi. -NSObject *FWFWKWebViewConfigurationHostApiGetCodec(void); - -/// Mirror of WKWebViewConfiguration. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -@protocol FWFWKWebViewConfigurationHostApi -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error; -- (void)createFromWebViewWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:(NSInteger)identifier - isAllowed:(BOOL)allow - error: - (FlutterError *_Nullable *_Nonnull) - error; -- (void)setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:(NSInteger)identifier - isLimited:(BOOL)limit - error:(FlutterError *_Nullable - *_Nonnull)error; -- (void) - setMediaTypesRequiresUserActionForConfigurationWithIdentifier:(NSInteger)identifier - forTypes: - (NSArray< - FWFWKAudiovisualMediaTypeEnumData - *> *)types - error: - (FlutterError *_Nullable *_Nonnull) - error; -@end - -extern void SetUpFWFWKWebViewConfigurationHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKWebViewConfigurationHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFWKWebViewConfigurationFlutterApi. -NSObject *FWFWKWebViewConfigurationFlutterApiGetCodec(void); - -/// Handles callbacks from a WKWebViewConfiguration instance. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -@interface FWFWKWebViewConfigurationFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)createWithIdentifier:(NSInteger)identifier - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFWKUserContentControllerHostApi. -NSObject *FWFWKUserContentControllerHostApiGetCodec(void); - -/// Mirror of WKUserContentController. -/// -/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc. -@protocol FWFWKUserContentControllerHostApi -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)addScriptMessageHandlerForControllerWithIdentifier:(NSInteger)identifier - handlerIdentifier:(NSInteger)handlerIdentifier - ofName:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)removeScriptMessageHandlerForControllerWithIdentifier:(NSInteger)identifier - name:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull) - error; -- (void)removeAllScriptMessageHandlersForControllerWithIdentifier:(NSInteger)identifier - error: - (FlutterError *_Nullable *_Nonnull) - error; -- (void)addUserScriptForControllerWithIdentifier:(NSInteger)identifier - userScript:(FWFWKUserScriptData *)userScript - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)removeAllUserScriptsForControllerWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFWKUserContentControllerHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKUserContentControllerHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFWKPreferencesHostApi. -NSObject *FWFWKPreferencesHostApiGetCodec(void); - -/// Mirror of WKUserPreferences. -/// -/// See https://developer.apple.com/documentation/webkit/wkpreferences?language=objc. -@protocol FWFWKPreferencesHostApi -- (void)createFromWebViewConfigurationWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setJavaScriptEnabledForPreferencesWithIdentifier:(NSInteger)identifier - isEnabled:(BOOL)enabled - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFWKPreferencesHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKPreferencesHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFWKScriptMessageHandlerHostApi. -NSObject *FWFWKScriptMessageHandlerHostApiGetCodec(void); - -/// Mirror of WKScriptMessageHandler. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -@protocol FWFWKScriptMessageHandlerHostApi -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFWKScriptMessageHandlerHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKScriptMessageHandlerHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFWKScriptMessageHandlerFlutterApi. -NSObject *FWFWKScriptMessageHandlerFlutterApiGetCodec(void); - -/// Handles callbacks from a WKScriptMessageHandler instance. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -@interface FWFWKScriptMessageHandlerFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)didReceiveScriptMessageForHandlerWithIdentifier:(NSInteger)identifier - userContentControllerIdentifier:(NSInteger)userContentControllerIdentifier - message:(FWFWKScriptMessageData *)message - completion: - (void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFWKNavigationDelegateHostApi. -NSObject *FWFWKNavigationDelegateHostApiGetCodec(void); - -/// Mirror of WKNavigationDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -@protocol FWFWKNavigationDelegateHostApi -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFWKNavigationDelegateHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKNavigationDelegateHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFWKNavigationDelegateFlutterApi. -NSObject *FWFWKNavigationDelegateFlutterApiGetCodec(void); - -/// Handles callbacks from a WKNavigationDelegate instance. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -@interface FWFWKNavigationDelegateFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)didFinishNavigationForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - URL:(nullable NSString *)url - completion:(void (^)(FlutterError *_Nullable))completion; -- (void)didStartProvisionalNavigationForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - URL:(nullable NSString *)url - completion:(void (^)(FlutterError *_Nullable)) - completion; -- (void) - decidePolicyForNavigationActionForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - navigationAction: - (FWFWKNavigationActionData *)navigationAction - completion: - (void (^)(FWFWKNavigationActionPolicyEnumData - *_Nullable, - FlutterError *_Nullable))completion; -- (void)decidePolicyForNavigationResponseForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - navigationResponse:(FWFWKNavigationResponseData *) - navigationResponse - completion: - (void (^)( - FWFWKNavigationResponsePolicyEnumBox - *_Nullable, - FlutterError *_Nullable))completion; -- (void)didFailNavigationForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FWFNSErrorData *)error - completion:(void (^)(FlutterError *_Nullable))completion; -- (void)didFailProvisionalNavigationForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - error:(FWFNSErrorData *)error - completion:(void (^)(FlutterError *_Nullable)) - completion; -- (void)webViewWebContentProcessDidTerminateForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - completion: - (void (^)(FlutterError *_Nullable)) - completion; -- (void)didReceiveAuthenticationChallengeForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - challengeIdentifier:(NSInteger)challengeIdentifier - completion: - (void (^)( - FWFAuthenticationChallengeResponse - *_Nullable, - FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFNSObjectHostApi. -NSObject *FWFNSObjectHostApiGetCodec(void); - -/// Mirror of NSObject. -/// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -@protocol FWFNSObjectHostApi -- (void)disposeObjectWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)addObserverForObjectWithIdentifier:(NSInteger)identifier - observerIdentifier:(NSInteger)observerIdentifier - keyPath:(NSString *)keyPath - options: - (NSArray *)options - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)removeObserverForObjectWithIdentifier:(NSInteger)identifier - observerIdentifier:(NSInteger)observerIdentifier - keyPath:(NSString *)keyPath - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFNSObjectHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFNSObjectHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFNSObjectFlutterApi. -NSObject *FWFNSObjectFlutterApiGetCodec(void); - -/// Handles callbacks from an NSObject instance. -/// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -@interface FWFNSObjectFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)observeValueForObjectWithIdentifier:(NSInteger)identifier - keyPath:(NSString *)keyPath - objectIdentifier:(NSInteger)objectIdentifier - changeKeys:(NSArray *)changeKeys - changeValues:(NSArray *)changeValues - completion:(void (^)(FlutterError *_Nullable))completion; -- (void)disposeObjectWithIdentifier:(NSInteger)identifier - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFWKWebViewHostApi. -NSObject *FWFWKWebViewHostApiGetCodec(void); - -/// Mirror of WKWebView. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebview?language=objc. -@protocol FWFWKWebViewHostApi -- (void)createWithIdentifier:(NSInteger)identifier - configurationIdentifier:(NSInteger)configurationIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setUIDelegateForWebViewWithIdentifier:(NSInteger)identifier - delegateIdentifier:(nullable NSNumber *)uiDelegateIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setNavigationDelegateForWebViewWithIdentifier:(NSInteger)identifier - delegateIdentifier: - (nullable NSNumber *)navigationDelegateIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)URLForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. -- (nullable NSNumber *)estimatedProgressForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull) - error; -- (void)loadRequestForWebViewWithIdentifier:(NSInteger)identifier - request:(FWFNSUrlRequestData *)request - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)loadHTMLForWebViewWithIdentifier:(NSInteger)identifier - HTMLString:(NSString *)string - baseURL:(nullable NSString *)baseUrl - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)loadFileForWebViewWithIdentifier:(NSInteger)identifier - fileURL:(NSString *)url - readAccessURL:(NSString *)readAccessUrl - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)loadAssetForWebViewWithIdentifier:(NSInteger)identifier - assetKey:(NSString *)key - error:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. -- (nullable NSNumber *)canGoBackForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. -- (nullable NSNumber *)canGoForwardForWebViewWithIdentifier:(NSInteger)identifier - error: - (FlutterError *_Nullable *_Nonnull)error; -- (void)goBackForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)goForwardForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)reloadWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)titleForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setAllowsBackForwardForWebViewWithIdentifier:(NSInteger)identifier - isAllowed:(BOOL)allow - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setCustomUserAgentForWebViewWithIdentifier:(NSInteger)identifier - userAgent:(nullable NSString *)userAgent - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)evaluateJavaScriptForWebViewWithIdentifier:(NSInteger)identifier - javaScriptString:(NSString *)javaScriptString - completion:(void (^)(id _Nullable, - FlutterError *_Nullable))completion; -- (void)setInspectableForWebViewWithIdentifier:(NSInteger)identifier - inspectable:(BOOL)inspectable - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)customUserAgentForWebViewWithIdentifier:(NSInteger)identifier - error:(FlutterError *_Nullable *_Nonnull) - error; -@end - -extern void SetUpFWFWKWebViewHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKWebViewHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFWKUIDelegateHostApi. -NSObject *FWFWKUIDelegateHostApiGetCodec(void); - -/// Mirror of WKUIDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -@protocol FWFWKUIDelegateHostApi -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFWKUIDelegateHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKUIDelegateHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFWKUIDelegateFlutterApi. -NSObject *FWFWKUIDelegateFlutterApiGetCodec(void); - -/// Handles callbacks from a WKUIDelegate instance. -/// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -@interface FWFWKUIDelegateFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)onCreateWebViewForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - configurationIdentifier:(NSInteger)configurationIdentifier - navigationAction:(FWFWKNavigationActionData *)navigationAction - completion:(void (^)(FlutterError *_Nullable))completion; -/// Callback to Dart function `WKUIDelegate.requestMediaCapturePermission`. -- (void)requestMediaCapturePermissionForDelegateWithIdentifier:(NSInteger)identifier - webViewIdentifier:(NSInteger)webViewIdentifier - origin:(FWFWKSecurityOriginData *)origin - frame:(FWFWKFrameInfoData *)frame - type:(FWFWKMediaCaptureTypeData *)type - completion: - (void (^)( - FWFWKPermissionDecisionData *_Nullable, - FlutterError *_Nullable))completion; -/// Callback to Dart function `WKUIDelegate.runJavaScriptAlertPanel`. -- (void)runJavaScriptAlertPanelForDelegateWithIdentifier:(NSInteger)identifier - message:(NSString *)message - frame:(FWFWKFrameInfoData *)frame - completion: - (void (^)(FlutterError *_Nullable))completion; -/// Callback to Dart function `WKUIDelegate.runJavaScriptConfirmPanel`. -- (void)runJavaScriptConfirmPanelForDelegateWithIdentifier:(NSInteger)identifier - message:(NSString *)message - frame:(FWFWKFrameInfoData *)frame - completion: - (void (^)(NSNumber *_Nullable, - FlutterError *_Nullable))completion; -/// Callback to Dart function `WKUIDelegate.runJavaScriptTextInputPanel`. -- (void)runJavaScriptTextInputPanelForDelegateWithIdentifier:(NSInteger)identifier - prompt:(NSString *)prompt - defaultText:(NSString *)defaultText - frame:(FWFWKFrameInfoData *)frame - completion: - (void (^)(NSString *_Nullable, - FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFWKHttpCookieStoreHostApi. -NSObject *FWFWKHttpCookieStoreHostApiGetCodec(void); - -/// Mirror of WKHttpCookieStore. -/// -/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc. -@protocol FWFWKHttpCookieStoreHostApi -- (void)createFromWebsiteDataStoreWithIdentifier:(NSInteger)identifier - dataStoreIdentifier:(NSInteger)websiteDataStoreIdentifier - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)setCookieForStoreWithIdentifier:(NSInteger)identifier - cookie:(FWFNSHttpCookieData *)cookie - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -extern void SetUpFWFWKHttpCookieStoreHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFWKHttpCookieStoreHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFNSUrlHostApi. -NSObject *FWFNSUrlHostApiGetCodec(void); - -/// Host API for `NSUrl`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -@protocol FWFNSUrlHostApi -- (nullable NSString *)absoluteStringForNSURLWithIdentifier:(NSInteger)identifier - error: - (FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFNSUrlHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFNSUrlHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFNSUrlFlutterApi. -NSObject *FWFNSUrlFlutterApiGetCodec(void); - -/// Flutter API for `NSUrl`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -@interface FWFNSUrlFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)createWithIdentifier:(NSInteger)identifier - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFUIScrollViewDelegateHostApi. -NSObject *FWFUIScrollViewDelegateHostApiGetCodec(void); - -/// Host API for `UIScrollViewDelegate`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -@protocol FWFUIScrollViewDelegateHostApi -- (void)createWithIdentifier:(NSInteger)identifier error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFUIScrollViewDelegateHostApi( - id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFUIScrollViewDelegateHostApiWithSuffix( - id binaryMessenger, - NSObject *_Nullable api, NSString *messageChannelSuffix); - -/// The codec used by FWFUIScrollViewDelegateFlutterApi. -NSObject *FWFUIScrollViewDelegateFlutterApiGetCodec(void); - -/// Flutter API for `UIScrollViewDelegate`. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -@interface FWFUIScrollViewDelegateFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -- (void)scrollViewDidScrollWithIdentifier:(NSInteger)identifier - UIScrollViewIdentifier:(NSInteger)uiScrollViewIdentifier - x:(double)x - y:(double)y - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFNSUrlCredentialHostApi. -NSObject *FWFNSUrlCredentialHostApiGetCodec(void); - -/// Host API for `NSUrlCredential`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc. -@protocol FWFNSUrlCredentialHostApi -/// Create a new native instance and add it to the `InstanceManager`. -- (void)createWithUserWithIdentifier:(NSInteger)identifier - user:(NSString *)user - password:(NSString *)password - persistence:(FWFNSUrlCredentialPersistence)persistence - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void SetUpFWFNSUrlCredentialHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFWFNSUrlCredentialHostApiWithSuffix( - id binaryMessenger, NSObject *_Nullable api, - NSString *messageChannelSuffix); - -/// The codec used by FWFNSUrlProtectionSpaceFlutterApi. -NSObject *FWFNSUrlProtectionSpaceFlutterApiGetCodec(void); - -/// Flutter API for `NSUrlProtectionSpace`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlprotectionspace?language=objc. -@interface FWFNSUrlProtectionSpaceFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -/// Create a new Dart instance and add it to the `InstanceManager`. -- (void)createWithIdentifier:(NSInteger)identifier - host:(nullable NSString *)host - realm:(nullable NSString *)realm - authenticationMethod:(nullable NSString *)authenticationMethod - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// The codec used by FWFNSUrlAuthenticationChallengeFlutterApi. -NSObject *FWFNSUrlAuthenticationChallengeFlutterApiGetCodec(void); - -/// Flutter API for `NSUrlAuthenticationChallenge`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See -/// https://developer.apple.com/documentation/foundation/nsurlauthenticationchallenge?language=objc. -@interface FWFNSUrlAuthenticationChallengeFlutterApi : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - messageChannelSuffix:(nullable NSString *)messageChannelSuffix; -/// Create a new Dart instance and add it to the `InstanceManager`. -- (void)createWithIdentifier:(NSInteger)identifier - protectionSpaceIdentifier:(NSInteger)protectionSpaceIdentifier - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.h deleted file mode 100644 index bb2adfb19367..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFHTTPCookieStoreHostApi.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for WKHTTPCookieStore. -/// -/// Handles creating WKHTTPCookieStore that intercommunicate with a paired Dart object. -@interface FWFHTTPCookieStoreHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager.h deleted file mode 100644 index f88370598093..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager.h +++ /dev/null @@ -1,84 +0,0 @@ -// 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. - -#import - -NS_ASSUME_NONNULL_BEGIN - -typedef void (^FWFOnDeallocCallback)(long identifier); - -/// Maintains instances used to communicate with the corresponding objects in Dart. -/// -/// When an instance is added with an identifier, either can be used to retrieve the other. -/// -/// Added instances are added as a weak reference and a strong reference. When the strong reference -/// is removed with `removeStrongReferenceWithIdentifier:` and the weak reference is deallocated, -/// the `deallocCallback` is made with the instance's identifier. However, if the strong reference -/// is removed and then the identifier is retrieved with the intention to pass the identifier to -/// Dart (e.g. calling `identifierForInstance:identifierWillBePassedToFlutter:` with -/// `identifierWillBePassedToFlutter` set to YES), the strong reference to the instance is -/// recreated. The strong reference will then need to be removed manually again. -/// -/// Accessing and inserting to an InstanceManager is thread safe. -@interface FWFInstanceManager : NSObject -@property(readonly) FWFOnDeallocCallback deallocCallback; -- (instancetype)initWithDeallocCallback:(FWFOnDeallocCallback)callback; - -// TODO(bparrishMines): Pairs should not be able to be overwritten and this feature -// should be replaced with a call to clear the manager in the event of a hot restart. -/// Adds a new instance that was instantiated from Dart. -/// -/// If an instance or identifier has already been added, it will be replaced by the new values. The -/// Dart InstanceManager is considered the source of truth and has the capability to overwrite -/// stored pairs in response to hot restarts. -/// -/// @param instance The instance to be stored. -/// @param instanceIdentifier The identifier to be paired with instance. This value must be >= 0. -- (void)addDartCreatedInstance:(NSObject *)instance withIdentifier:(long)instanceIdentifier; - -/// Adds a new instance that was instantiated from the host platform. -/// -/// @param instance The instance to be stored. -/// @return The unique identifier stored with instance. -- (long)addHostCreatedInstance:(nonnull NSObject *)instance; - -/// Removes `instanceIdentifier` and its associated strongly referenced instance, if present, from -/// the manager. -/// -/// @param instanceIdentifier The identifier paired to an instance. -/// -/// @return The removed instance if the manager contains the given instanceIdentifier, otherwise -/// nil. -- (nullable NSObject *)removeInstanceWithIdentifier:(long)instanceIdentifier; - -/// Retrieves the instance associated with identifier. -/// -/// @param instanceIdentifier The identifier paired to an instance. -/// -/// @return The instance associated with `instanceIdentifier` if the manager contains the value, -/// otherwise nil. -- (nullable NSObject *)instanceForIdentifier:(long)instanceIdentifier; - -/// Retrieves the identifier paired with an instance. -/// -/// If the manager contains `instance`, as a strong or weak reference, the strong reference to -/// `instance` will be recreated and will need to be removed again with -/// `removeInstanceWithIdentifier:`. -/// -/// This method also expects the Dart `InstanceManager` to have, or recreate, a weak reference to -/// the instance the identifier is associated with once it receives it. -/// -/// @param instance An instance that may be stored in the manager. -/// -/// @return The identifier associated with `instance` if the manager contains the value, otherwise -/// NSNotFound. -- (long)identifierWithStrongReferenceForInstance:(nonnull NSObject *)instance; - -/// Returns whether this manager contains the given `instance`. -/// -/// @return Whether this manager contains the given `instance`. -- (BOOL)containsInstance:(nonnull NSObject *)instance; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager_Test.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager_Test.h deleted file mode 100644 index 20d1e4847da7..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFInstanceManager_Test.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface FWFInstanceManager () -/// The next identifier that will be used for a host-created instance. -@property long nextIdentifier; - -/// The number of instances stored as a strong reference. -/// -/// Added for debugging purposes. -- (NSUInteger)strongInstanceCount; - -/// The number of instances stored as a weak reference. -/// -/// Added for debugging purposes. NSMapTables that store keys or objects as weak reference will be -/// reclaimed nondeterministically. -- (NSUInteger)weakInstanceCount; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.h deleted file mode 100644 index db1edee310e9..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFNavigationDelegateHostApi.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -#import -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" -#import "FWFObjectHostApi.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter api implementation for WKNavigationDelegate. -/// -/// Handles making callbacks to Dart for a WKNavigationDelegate. -@interface FWFNavigationDelegateFlutterApiImpl : FWFWKNavigationDelegateFlutterApi -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Implementation of WKNavigationDelegate for FWFNavigationDelegateHostApiImpl. -@interface FWFNavigationDelegate : FWFObject -@property(readonly, nonnull, nonatomic) FWFNavigationDelegateFlutterApiImpl *navigationDelegateAPI; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for WKNavigationDelegate. -/// -/// Handles creating WKNavigationDelegate that intercommunicate with a paired Dart object. -@interface FWFNavigationDelegateHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFObjectHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFObjectHostApi.h deleted file mode 100644 index 8bdc7f6a0c00..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFObjectHostApi.h +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter api implementation for NSObject. -/// -/// Handles making callbacks to Dart for an NSObject. -@interface FWFObjectFlutterApiImpl : FWFNSObjectFlutterApi -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; - -- (void)observeValueForObject:(NSObject *)instance - keyPath:(NSString *)keyPath - object:(NSObject *)object - change:(NSDictionary *)change - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// Implementation of NSObject for FWFObjectHostApiImpl. -@interface FWFObject : NSObject -@property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for NSObject. -/// -/// Handles creating NSObject that intercommunicate with a paired Dart object. -@interface FWFObjectHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFPreferencesHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFPreferencesHostApi.h deleted file mode 100644 index de2b6dd63d52..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFPreferencesHostApi.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -#if TARGET_OS_OSX -#import -#else -#import -#endif -#import - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for WKPreferences. -/// -/// Handles creating WKPreferences that intercommunicate with a paired Dart object. -@interface FWFPreferencesHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.h deleted file mode 100644 index 2e79e40edc5d..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScriptMessageHandlerHostApi.h +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#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 : FWFObject -@property(readonly, nonnull, nonatomic) - FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for WKScriptMessageHandler. -/// -/// Handles creating WKScriptMessageHandler that intercommunicate with a paired Dart object. -@interface FWFScriptMessageHandlerHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h deleted file mode 100644 index 5608f79114cc..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewDelegateHostApi.h +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -// Using directory structure to remove platform-specific files doesn't work -// well with umbrella headers and module maps, so just no-op the file for -// other platforms instead. -#if TARGET_OS_IOS - -#import -#import -#import "FWFObjectHostApi.h" - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter api implementation for UIScrollViewDelegate. -/// -/// Handles making callbacks to Dart for a UIScrollViewDelegate. -@interface FWFScrollViewDelegateFlutterApiImpl : FWFUIScrollViewDelegateFlutterApi - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Implementation of WKUIScrollViewDelegate for FWFUIScrollViewDelegateHostApiImpl. -@interface FWFScrollViewDelegate : FWFObject -@property(readonly, nonnull, nonatomic) FWFScrollViewDelegateFlutterApiImpl *scrollViewDelegateAPI; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; - -@end - -/// Host api implementation for UIScrollViewDelegate. -/// -/// Handles creating UIScrollView that intercommunicate with a paired Dart object. -@interface FWFScrollViewDelegateHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END - -#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewHostApi.h deleted file mode 100644 index 5c65e129c85c..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFScrollViewHostApi.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for UIScrollView. -/// -/// Handles creating UIScrollView that intercommunicate with a paired Dart object. -@interface FWFScrollViewHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIDelegateHostApi.h deleted file mode 100644 index f5b52a52acf6..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIDelegateHostApi.h +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" -#import "FWFObjectHostApi.h" -#import "FWFWebViewConfigurationHostApi.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter api implementation for WKUIDelegate. -/// -/// Handles making callbacks to Dart for a WKUIDelegate. -@interface FWFUIDelegateFlutterApiImpl : FWFWKUIDelegateFlutterApi -@property(readonly, nonatomic) - FWFWebViewConfigurationFlutterApiImpl *webViewConfigurationFlutterApi; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Implementation of WKUIDelegate for FWFUIDelegateHostApiImpl. -@interface FWFUIDelegate : FWFObject -@property(readonly, nonnull, nonatomic) FWFUIDelegateFlutterApiImpl *UIDelegateAPI; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for WKUIDelegate. -/// -/// Handles creating WKUIDelegate that intercommunicate with a paired Dart object. -@interface FWFUIDelegateHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIViewHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIViewHostApi.h deleted file mode 100644 index cecd2ec6d3a0..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUIViewHostApi.h +++ /dev/null @@ -1,26 +0,0 @@ -// 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. - -// Using directory structure to remove platform-specific files doesn't work -// well with umbrella headers and module maps, so just no-op the file for -// other platforms instead. -#if TARGET_OS_IOS - -#import - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for UIView. -/// -/// Handles creating UIView that intercommunicate with a paired Dart object. -@interface FWFUIViewHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END - -#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.h deleted file mode 100644 index 4bc572072b2e..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLAuthenticationChallengeHostApi.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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. - -#import -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter API implementation for `NSURLAuthenticationChallenge`. -/// -/// This class may handle instantiating and adding Dart instances that are attached to a native -/// instance or sending callback methods from an overridden native class. -@interface FWFURLAuthenticationChallengeFlutterApiImpl : NSObject -/// The Flutter API used to send messages back to Dart. -@property FWFNSUrlAuthenticationChallengeFlutterApi *api; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -/// Sends a message to Dart to create a new Dart instance and add it to the `InstanceManager`. -- (void)createWithInstance:(NSURLAuthenticationChallenge *)instance - protectionSpace:(NSURLProtectionSpace *)protectionSpace - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLCredentialHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLCredentialHostApi.h deleted file mode 100644 index 3f731bdcc62b..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLCredentialHostApi.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -#import -#import "FWFDataConverters.h" -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -/// Host API implementation for `NSURLCredential`. -/// -/// This class may handle instantiating and adding native object instances that are attached to a -/// Dart instance or method calls on the associated native class or an instance of the class. -@interface FWFURLCredentialHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLHostApi.h deleted file mode 100644 index 9238f89590b4..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLHostApi.h +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host API implementation for `NSURL`. -/// -/// This class may handle instantiating and adding native object instances that are attached to a -/// Dart instance or method calls on the associated native class or an instance of the class. -@interface FWFURLHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Flutter API implementation for `NSURL`. -/// -/// This class may handle instantiating and adding Dart instances that are attached to a native -/// instance or sending callback methods from an overridden native class. -@interface FWFURLFlutterApiImpl : NSObject -/// The Flutter API used to send messages back to Dart. -@property FWFNSUrlFlutterApi *api; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; - -/// Sends a message to Dart to create a new Dart instance and add it to the `InstanceManager`. -- (void)create:(NSURL *)instance completion:(void (^)(FlutterError *_Nullable))completion; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.h deleted file mode 100644 index f87e09c573ee..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFURLProtectionSpaceHostApi.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -#import -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter API implementation for `NSURLProtectionSpace`. -/// -/// This class may handle instantiating and adding Dart instances that are attached to a native -/// instance or sending callback methods from an overridden native class. -@interface FWFURLProtectionSpaceFlutterApiImpl : NSObject -/// The Flutter API used to send messages back to Dart. -@property FWFNSUrlProtectionSpaceFlutterApi *api; -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -/// Sends a message to Dart to create a new Dart instance and add it to the `InstanceManager`. -- (void)createWithInstance:(NSURLProtectionSpace *)instance - host:(nullable NSString *)host - realm:(nullable NSString *)realm - authenticationMethod:(nullable NSString *)authenticationMethod - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUserContentControllerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUserContentControllerHostApi.h deleted file mode 100644 index 0905d3c7543a..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFUserContentControllerHostApi.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for WKUserContentController. -/// -/// Handles creating WKUserContentController that intercommunicate with a paired Dart object. -@interface FWFUserContentControllerHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h deleted file mode 100644 index a5dd32a153b2..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewConfigurationHostApi.h +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" -#import "FWFObjectHostApi.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Flutter api implementation for WKWebViewConfiguration. -/// -/// Handles making callbacks to Dart for a WKWebViewConfiguration. -@interface FWFWebViewConfigurationFlutterApiImpl : FWFWKWebViewConfigurationFlutterApi -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; - -- (void)createWithConfiguration:(WKWebViewConfiguration *)configuration - completion:(void (^)(FlutterError *_Nullable))completion; -@end - -/// Implementation of WKWebViewConfiguration for FWFWebViewConfigurationHostApiImpl. -@interface FWFWebViewConfiguration : WKWebViewConfiguration -@property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for WKWebViewConfiguration. -/// -/// Handles creating WKWebViewConfiguration that intercommunicate with a paired Dart object. -@interface FWFWebViewConfigurationHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.h deleted file mode 100644 index e4e6ff3a1dea..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewFlutterWKWebViewExternalAPI.h +++ /dev/null @@ -1,38 +0,0 @@ -// 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. - -#import -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -/// App and package facing native API provided by the `webview_flutter_wkwebview` plugin. -/// -/// This class follows the convention of breaking changes of the Dart API, which means that any -/// changes to the class that are not backwards compatible will only be made with a major version -/// change of the plugin. Native code other than this external API does not follow breaking change -/// conventions, so app or plugin clients should not use any other native APIs. -@interface FWFWebViewFlutterWKWebViewExternalAPI : NSObject -/// Retrieves the `WKWebView` that is associated with `identifier`. -/// -/// See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an -/// underlying `WKWebView`. -/// -/// @param identifier The associated identifier of the `WebView`. -/// @param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If -/// the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, -/// this method returns nil. -/// @return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated -/// with `identifier` could not be found. -+ (nullable WKWebView *)webViewForIdentifier:(long)identifier - withPluginRegistry:(id)registry; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewHostApi.h deleted file mode 100644 index 2f9f28bea6c2..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebViewHostApi.h +++ /dev/null @@ -1,54 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" -#import "FWFObjectHostApi.h" - -NS_ASSUME_NONNULL_BEGIN - -/// A set of Flutter and Dart assets used by a `FlutterEngine` to initialize execution. -/// -/// Default implementation delegates methods to FlutterDartProject. -@interface FWFAssetManager : NSObject -- (NSString *)lookupKeyForAsset:(NSString *)asset; -@end - -/// Implementation of WKWebView that can be used as a FlutterPlatformView. -@interface FWFWebView : WKWebView -// The macOS platform view API doesn't have a FlutterPlatformView abstraction, -// and uses NSView directly. -#if TARGET_OS_IOS - -#endif -@property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; - -- (instancetype)initWithFrame:(CGRect)frame - configuration:(nonnull WKWebViewConfiguration *)configuration - binaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; -@end - -/// Host api implementation for WKWebView. -/// -/// Handles creating WKWebViews that intercommunicate with a paired Dart object. -@interface FWFWebViewHostApiImpl : NSObject -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager; - -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger - instanceManager:(FWFInstanceManager *)instanceManager - bundle:(NSBundle *)bundle - assetManager:(FWFAssetManager *)assetManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h deleted file mode 100644 index a5969e5215bb..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFWebsiteDataStoreHostApi.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FWFGeneratedWebKitApis.h" -#import "FWFInstanceManager.h" - -NS_ASSUME_NONNULL_BEGIN - -/// Host api implementation for WKWebsiteDataStore. -/// -/// Handles creating WKWebsiteDataStore that intercommunicate with a paired Dart object. -@interface FWFWebsiteDataStoreHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/legacy/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/legacy/webview_flutter_test.dart index 47c6876d13d9..f03859f0f536 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/legacy/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/legacy/webview_flutter_test.dart @@ -16,8 +16,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; import 'package:webview_flutter_wkwebview/src/common/weak_reference_utils.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; import 'package:webview_flutter_wkwebview_example/legacy/navigation_decision.dart'; import 'package:webview_flutter_wkwebview_example/legacy/navigation_request.dart'; import 'package:webview_flutter_wkwebview_example/legacy/web_view.dart'; @@ -79,7 +79,7 @@ Future main() async { 'withWeakRefenceTo allows encapsulating class to be garbage collected', (WidgetTester tester) async { final Completer gcCompleter = Completer(); - final InstanceManager instanceManager = InstanceManager( + final PigeonInstanceManager instanceManager = PigeonInstanceManager( onWeakReferenceRemoved: gcCompleter.complete, ); @@ -1287,13 +1287,14 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback extends PigeonInternalProxyApiBaseClass { CopyableObjectWithCallback(this.callback); final VoidCallback callback; @override - CopyableObjectWithCallback copy() { + // ignore: non_constant_identifier_names + CopyableObjectWithCallback pigeon_copy() { return CopyableObjectWithCallback(callback); } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/webview_flutter_test.dart index 7ca004d40786..24e70d775b18 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/webview_flutter_test.dart @@ -16,9 +16,10 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; +import 'package:webview_flutter_wkwebview/src/common/platform_webview.dart'; import 'package:webview_flutter_wkwebview/src/common/weak_reference_utils.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; +import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; Future main() async { @@ -59,7 +60,7 @@ Future main() async { 'withWeakReferenceTo allows encapsulating class to be garbage collected', (WidgetTester tester) async { final Completer gcCompleter = Completer(); - final InstanceManager instanceManager = InstanceManager( + final PigeonInstanceManager instanceManager = PigeonInstanceManager( onWeakReferenceRemoved: gcCompleter.complete, ); @@ -83,48 +84,58 @@ Future main() async { testWidgets( 'WKWebView is released by garbage collection', (WidgetTester tester) async { - bool aWebViewHasBeenGarbageCollected = false; - - late final InstanceManager instanceManager; - instanceManager = - InstanceManager(onWeakReferenceRemoved: (int identifier) { - if (!aWebViewHasBeenGarbageCollected) { - final Copyable instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - if (instance is WKWebView) { - aWebViewHasBeenGarbageCollected = true; - } + final Completer webViewGCCompleter = Completer(); + + const int webViewToken = -1; + final Finalizer finalizer = Finalizer((int token) { + if (token == webViewToken) { + webViewGCCompleter.complete(); } }); // Wait for any WebView to be garbage collected. - while (!aWebViewHasBeenGarbageCollected) { - await tester.pumpWidget( - Builder( - builder: (BuildContext context) { - return PlatformWebViewWidget( - WebKitWebViewWidgetCreationParams( - instanceManager: instanceManager, - controller: PlatformWebViewController( - WebKitWebViewControllerCreationParams( - instanceManager: instanceManager, - ), + await tester.pumpWidget( + Builder( + builder: (BuildContext context) { + return PlatformWebViewWidget( + WebKitWebViewWidgetCreationParams( + controller: PlatformWebViewController( + WebKitWebViewControllerCreationParams( + webKitProxy: WebKitProxy(newPlatformWebView: ({ + required WKWebViewConfiguration initialConfiguration, + void Function( + NSObject, + String?, + NSObject?, + Map?, + )? observeValue, + }) { + final PlatformWebView platformWebView = PlatformWebView( + initialConfiguration: initialConfiguration, + ); + finalizer.attach( + platformWebView.nativeWebView, + webViewToken, + ); + return platformWebView; + }), ), ), - ).build(context); - }, - ), - ); - await tester.pumpAndSettle(); + ), + ).build(context); + }, + ), + ); + await tester.pumpAndSettle(); + await tester.pumpWidget(Container()); - await tester.pumpWidget(Container()); + // Force garbage collection. + await IntegrationTestWidgetsFlutterBinding.instance + .watchPerformance(() async { + await tester.pumpAndSettle(); + }); - // Force garbage collection. - await IntegrationTestWidgetsFlutterBinding.instance - .watchPerformance(() async { - await tester.pumpAndSettle(); - }); - } + await expectLater(webViewGCCompleter.future, completes); }, timeout: const Timeout(Duration(seconds: 30)), ); @@ -1684,13 +1695,14 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback extends PigeonInternalProxyApiBaseClass { CopyableObjectWithCallback(this.callback); final VoidCallback callback; @override - CopyableObjectWithCallback copy() { + // ignore: non_constant_identifier_names + CopyableObjectWithCallback pigeon_copy() { return CopyableObjectWithCallback(callback); } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Debug.xcconfig b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Debug.xcconfig index e8efba114687..ec97fc6f3021 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Debug.xcconfig +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Debug.xcconfig @@ -1,2 +1,2 @@ -#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Release.xcconfig b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Release.xcconfig index 399e9340e6f6..c4855bfe2000 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Release.xcconfig +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Flutter/Release.xcconfig @@ -1,2 +1,2 @@ -#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile index bcdae34190c9..c9339a034ebe 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Podfile @@ -29,7 +29,6 @@ flutter_ios_podfile_setup target 'Runner' do flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) - target 'RunnerTests' do inherit! :search_paths end 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 95f090b55eb7..02281ff2fac1 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 @@ -7,38 +7,46 @@ objects = { /* Begin PBXBuildFile section */ - 1096EF442A6BD9DB000CBDF7 /* FWFScrollViewDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1096EF432A6BD9DB000CBDF7 /* FWFScrollViewDelegateHostApiTests.m */; }; 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 4047B3FE2C3DEE8500A8BA05 /* OCMock in Frameworks */ = {isa = PBXBuildFile; productRef = 4047B3FD2C3DEE8500A8BA05 /* OCMock */; }; 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; }; - 8F4FF949299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */; }; - 8F4FF94B29AC223F000A6586 /* FWFURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4FF94A29AC223F000A6586 /* FWFURLTests.m */; }; - 8F562F902A56C02D00C2BED6 /* FWFURLCredentialHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F562F8F2A56C02D00C2BED6 /* FWFURLCredentialHostApiTests.m */; }; - 8F562F922A56C04F00C2BED6 /* FWFURLProtectionSpaceHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F562F912A56C04F00C2BED6 /* FWFURLProtectionSpaceHostApiTests.m */; }; - 8F562F942A56C07B00C2BED6 /* FWFURLAuthenticationChallengeHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F562F932A56C07B00C2BED6 /* FWFURLAuthenticationChallengeHostApiTests.m */; }; - 8F78EAAA2A02CB9100C2E520 /* FWFErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F78EAA92A02CB9100C2E520 /* FWFErrorTests.m */; }; - 8FA6A87928062CD000A4B183 /* FWFInstanceManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */; }; - 8FB79B5328134C3100C101D3 /* FWFWebViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */; }; - 8FB79B55281B24F600C101D3 /* FWFDataConvertersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */; }; - 8FB79B672820453400C101D3 /* FWFHTTPCookieStoreHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B662820453400C101D3 /* FWFHTTPCookieStoreHostApiTests.m */; }; - 8FB79B6928204E8700C101D3 /* FWFPreferencesHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B6828204E8700C101D3 /* FWFPreferencesHostApiTests.m */; }; - 8FB79B6B28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B6A28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m */; }; - 8FB79B6D2820533B00C101D3 /* FWFWebViewConfigurationHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B6C2820533B00C101D3 /* FWFWebViewConfigurationHostApiTests.m */; }; - 8FB79B73282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B72282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m */; }; - 8FB79B7928209D1300C101D3 /* FWFUserContentControllerHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B7828209D1300C101D3 /* FWFUserContentControllerHostApiTests.m */; }; - 8FB79B832820A39300C101D3 /* FWFNavigationDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B822820A39300C101D3 /* FWFNavigationDelegateHostApiTests.m */; }; - 8FB79B852820A3A400C101D3 /* FWFUIDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B842820A3A400C101D3 /* FWFUIDelegateHostApiTests.m */; }; - 8FB79B8F2820BAB300C101D3 /* FWFScrollViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B8E2820BAB300C101D3 /* FWFScrollViewHostApiTests.m */; }; - 8FB79B912820BAC700C101D3 /* FWFUIViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B902820BAC700C101D3 /* FWFUIViewHostApiTests.m */; }; - 8FB79B972821985200C101D3 /* FWFObjectHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B962821985200C101D3 /* FWFObjectHostApiTests.m */; }; + 8F66DB052D1534A1000835F9 /* WebViewProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DB042D1534A1000835F9 /* WebViewProxyAPITests.swift */; }; + 8F66DB062D1534A1000835F9 /* ScriptMessageHandlerProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF32D1534A1000835F9 /* ScriptMessageHandlerProxyAPITests.swift */; }; + 8F66DB072D1534A1000835F9 /* UIDelegateProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFA2D1534A1000835F9 /* UIDelegateProxyAPITests.swift */; }; + 8F66DB082D1534A1000835F9 /* URLCredentialProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFD2D1534A1000835F9 /* URLCredentialProxyAPITests.swift */; }; + 8F66DB092D1534A1000835F9 /* NavigationDelegateProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAEF2D1534A1000835F9 /* NavigationDelegateProxyAPITests.swift */; }; + 8F66DB0A2D1534A1000835F9 /* UIViewProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFB2D1534A1000835F9 /* UIViewProxyAPITests.swift */; }; + 8F66DB0B2D1534A1000835F9 /* NavigationActionProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAEE2D1534A1000835F9 /* NavigationActionProxyAPITests.swift */; }; + 8F66DB0C2D1534A1000835F9 /* WebViewConfigurationProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DB032D1534A1000835F9 /* WebViewConfigurationProxyAPITests.swift */; }; + 8F66DB0D2D1534A1000835F9 /* NavigationResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF02D1534A1000835F9 /* NavigationResponseProxyAPITests.swift */; }; + 8F66DB0E2D1534A1000835F9 /* TestProxyApiRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF92D1534A1000835F9 /* TestProxyApiRegistrar.swift */; }; + 8F66DB0F2D1534A1000835F9 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAEA2D1534A1000835F9 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift */; }; + 8F66DB102D1534A1000835F9 /* TestBinaryMessenger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF82D1534A1000835F9 /* TestBinaryMessenger.swift */; }; + 8F66DB112D1534A1000835F9 /* UserContentControllerProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DB002D1534A1000835F9 /* UserContentControllerProxyAPITests.swift */; }; + 8F66DB122D1534A1000835F9 /* SecurityOriginProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF72D1534A1000835F9 /* SecurityOriginProxyAPITests.swift */; }; + 8F66DB132D1534A1000835F9 /* AuthenticationChallengeResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAE72D1534A1000835F9 /* AuthenticationChallengeResponseProxyAPITests.swift */; }; + 8F66DB142D1534A1000835F9 /* HTTPCookieProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAEB2D1534A1000835F9 /* HTTPCookieProxyAPITests.swift */; }; + 8F66DB152D1534A1000835F9 /* UserScriptProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DB012D1534A1000835F9 /* UserScriptProxyAPITests.swift */; }; + 8F66DB162D1534A1000835F9 /* ScrollViewProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF62D1534A1000835F9 /* ScrollViewProxyAPITests.swift */; }; + 8F66DB172D1534A1000835F9 /* URLAuthenticationChallengeProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFC2D1534A1000835F9 /* URLAuthenticationChallengeProxyAPITests.swift */; }; + 8F66DB182D1534A1000835F9 /* WebsiteDataStoreProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DB022D1534A1000835F9 /* WebsiteDataStoreProxyAPITests.swift */; }; + 8F66DB192D1534A1000835F9 /* HTTPURLResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAED2D1534A1000835F9 /* HTTPURLResponseProxyAPITests.swift */; }; + 8F66DB1A2D1534A1000835F9 /* ErrorProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAE82D1534A1000835F9 /* ErrorProxyAPITests.swift */; }; + 8F66DB1B2D1534A1000835F9 /* ScrollViewDelegateProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF52D1534A1000835F9 /* ScrollViewDelegateProxyAPITests.swift */; }; + 8F66DB1C2D1534A1000835F9 /* ScriptMessageProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF42D1534A1000835F9 /* ScriptMessageProxyAPITests.swift */; }; + 8F66DB1D2D1534A1000835F9 /* URLProtectionSpaceProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFE2D1534A1000835F9 /* URLProtectionSpaceProxyAPITests.swift */; }; + 8F66DB1E2D1534A1000835F9 /* URLRequestProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAFF2D1534A1000835F9 /* URLRequestProxyAPITests.swift */; }; + 8F66DB1F2D1534A1000835F9 /* FrameInfoProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAE92D1534A1000835F9 /* FrameInfoProxyAPITests.swift */; }; + 8F66DB202D1534A1000835F9 /* NSObjectProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF12D1534A1000835F9 /* NSObjectProxyAPITests.swift */; }; + 8F66DB212D1534A1000835F9 /* HTTPCookieStoreProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAEC2D1534A1000835F9 /* HTTPCookieStoreProxyAPITests.swift */; }; + 8F66DB222D1534A1000835F9 /* PreferencesProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F66DAF22D1534A1000835F9 /* PreferencesProxyAPITests.swift */; }; + 904EA421B6925EC8D52ABE1B /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 573E8F1472CA1578A7CBDB63 /* libPods-RunnerTests.a */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - D7587C3652F6906210B3AE88 /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 17781D9462A1AEA7C99F8E45 /* libPods-RunnerTests.a */; }; - DAF0E91266956134538CC667 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 572FFC2B2BA326B420B22679 /* libPods-Runner.a */; }; + A1C354B092678F5A3DF18D01 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 185E08CFEB8AE9D939566DE6 /* libPods-Runner.a */; }; F7151F77266057800028CB91 /* FLTWebViewUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = F7151F76266057800028CB91 /* FLTWebViewUITests.m */; }; /* End PBXBuildFile section */ @@ -73,39 +81,50 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1096EF432A6BD9DB000CBDF7 /* FWFScrollViewDelegateHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFScrollViewDelegateHostApiTests.m; path = ../../darwin/Tests/FWFScrollViewDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 17781D9462A1AEA7C99F8E45 /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 2286ACB87EA8CA27E739AD6C /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; - 39B2BDAA45DC06EAB8A6C4E7 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; + 14B8C759112CB6E8AA62F003 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + 185E08CFEB8AE9D939566DE6 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 572FFC2B2BA326B420B22679 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4AA20286555659E34ACB3BE5 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + 56443D345A163E3A65320207 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; + 573E8F1472CA1578A7CBDB63 /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 68BDCAE923C3F7CB00D9C032 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 68BDCAED23C3F7CB00D9C032 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewFlutterWKWebViewExternalAPITests.m; path = ../../darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.m; sourceTree = SOURCE_ROOT; }; - 8F4FF94A29AC223F000A6586 /* FWFURLTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFURLTests.m; path = ../../darwin/Tests/FWFURLTests.m; sourceTree = SOURCE_ROOT; }; - 8F562F8F2A56C02D00C2BED6 /* FWFURLCredentialHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFURLCredentialHostApiTests.m; path = ../../darwin/Tests/FWFURLCredentialHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8F562F912A56C04F00C2BED6 /* FWFURLProtectionSpaceHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFURLProtectionSpaceHostApiTests.m; path = ../../darwin/Tests/FWFURLProtectionSpaceHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8F562F932A56C07B00C2BED6 /* FWFURLAuthenticationChallengeHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFURLAuthenticationChallengeHostApiTests.m; path = ../../darwin/Tests/FWFURLAuthenticationChallengeHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8F78EAA92A02CB9100C2E520 /* FWFErrorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFErrorTests.m; path = ../../darwin/Tests/FWFErrorTests.m; sourceTree = SOURCE_ROOT; }; - 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFInstanceManagerTests.m; path = ../../darwin/Tests/FWFInstanceManagerTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewHostApiTests.m; path = ../../darwin/Tests/FWFWebViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFDataConvertersTests.m; path = ../../darwin/Tests/FWFDataConvertersTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B662820453400C101D3 /* FWFHTTPCookieStoreHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFHTTPCookieStoreHostApiTests.m; path = ../../darwin/Tests/FWFHTTPCookieStoreHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B6828204E8700C101D3 /* FWFPreferencesHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFPreferencesHostApiTests.m; path = ../../darwin/Tests/FWFPreferencesHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B6A28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFWebsiteDataStoreHostApiTests.m; path = ../../darwin/Tests/FWFWebsiteDataStoreHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B6C2820533B00C101D3 /* FWFWebViewConfigurationHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewConfigurationHostApiTests.m; path = ../../darwin/Tests/FWFWebViewConfigurationHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B72282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFScriptMessageHandlerHostApiTests.m; path = ../../darwin/Tests/FWFScriptMessageHandlerHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B7828209D1300C101D3 /* FWFUserContentControllerHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFUserContentControllerHostApiTests.m; path = ../../darwin/Tests/FWFUserContentControllerHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B822820A39300C101D3 /* FWFNavigationDelegateHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFNavigationDelegateHostApiTests.m; path = ../../darwin/Tests/FWFNavigationDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B842820A3A400C101D3 /* FWFUIDelegateHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFUIDelegateHostApiTests.m; path = ../../darwin/Tests/FWFUIDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B8E2820BAB300C101D3 /* FWFScrollViewHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFScrollViewHostApiTests.m; path = ../../darwin/Tests/FWFScrollViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B902820BAC700C101D3 /* FWFUIViewHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFUIViewHostApiTests.m; path = ../../darwin/Tests/FWFUIViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 8FB79B962821985200C101D3 /* FWFObjectHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FWFObjectHostApiTests.m; path = ../../darwin/Tests/FWFObjectHostApiTests.m; sourceTree = SOURCE_ROOT; }; + 8F66D9D72D1362BE000835F9 /* RunnerTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RunnerTests-Bridging-Header.h"; sourceTree = ""; }; + 8F66DAE72D1534A1000835F9 /* AuthenticationChallengeResponseProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationChallengeResponseProxyAPITests.swift; sourceTree = ""; }; + 8F66DAE82D1534A1000835F9 /* ErrorProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorProxyAPITests.swift; sourceTree = ""; }; + 8F66DAE92D1534A1000835F9 /* FrameInfoProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameInfoProxyAPITests.swift; sourceTree = ""; }; + 8F66DAEA2D1534A1000835F9 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FWFWebViewFlutterWKWebViewExternalAPITests.swift; sourceTree = ""; }; + 8F66DAEB2D1534A1000835F9 /* HTTPCookieProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPCookieProxyAPITests.swift; sourceTree = ""; }; + 8F66DAEC2D1534A1000835F9 /* HTTPCookieStoreProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPCookieStoreProxyAPITests.swift; sourceTree = ""; }; + 8F66DAED2D1534A1000835F9 /* HTTPURLResponseProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPURLResponseProxyAPITests.swift; sourceTree = ""; }; + 8F66DAEE2D1534A1000835F9 /* NavigationActionProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationActionProxyAPITests.swift; sourceTree = ""; }; + 8F66DAEF2D1534A1000835F9 /* NavigationDelegateProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationDelegateProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF02D1534A1000835F9 /* NavigationResponseProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationResponseProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF12D1534A1000835F9 /* NSObjectProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSObjectProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF22D1534A1000835F9 /* PreferencesProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF32D1534A1000835F9 /* ScriptMessageHandlerProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptMessageHandlerProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF42D1534A1000835F9 /* ScriptMessageProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptMessageProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF52D1534A1000835F9 /* ScrollViewDelegateProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewDelegateProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF62D1534A1000835F9 /* ScrollViewProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF72D1534A1000835F9 /* SecurityOriginProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityOriginProxyAPITests.swift; sourceTree = ""; }; + 8F66DAF82D1534A1000835F9 /* TestBinaryMessenger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestBinaryMessenger.swift; sourceTree = ""; }; + 8F66DAF92D1534A1000835F9 /* TestProxyApiRegistrar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestProxyApiRegistrar.swift; sourceTree = ""; }; + 8F66DAFA2D1534A1000835F9 /* UIDelegateProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDelegateProxyAPITests.swift; sourceTree = ""; }; + 8F66DAFB2D1534A1000835F9 /* UIViewProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewProxyAPITests.swift; sourceTree = ""; }; + 8F66DAFC2D1534A1000835F9 /* URLAuthenticationChallengeProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLAuthenticationChallengeProxyAPITests.swift; sourceTree = ""; }; + 8F66DAFD2D1534A1000835F9 /* URLCredentialProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLCredentialProxyAPITests.swift; sourceTree = ""; }; + 8F66DAFE2D1534A1000835F9 /* URLProtectionSpaceProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLProtectionSpaceProxyAPITests.swift; sourceTree = ""; }; + 8F66DAFF2D1534A1000835F9 /* URLRequestProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLRequestProxyAPITests.swift; sourceTree = ""; }; + 8F66DB002D1534A1000835F9 /* UserContentControllerProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserContentControllerProxyAPITests.swift; sourceTree = ""; }; + 8F66DB012D1534A1000835F9 /* UserScriptProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserScriptProxyAPITests.swift; sourceTree = ""; }; + 8F66DB022D1534A1000835F9 /* WebsiteDataStoreProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsiteDataStoreProxyAPITests.swift; sourceTree = ""; }; + 8F66DB032D1534A1000835F9 /* WebViewConfigurationProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewConfigurationProxyAPITests.swift; sourceTree = ""; }; + 8F66DB042D1534A1000835F9 /* WebViewProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewProxyAPITests.swift; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -114,11 +133,10 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - B89AA31A64040E4A2F1E0CAF /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + C519E1940290A9B5DEBB9BCF /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; F7151F74266057800028CB91 /* RunnerUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; F7151F76266057800028CB91 /* FLTWebViewUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLTWebViewUITests.m; sourceTree = ""; }; F7151F78266057800028CB91 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - F7A1921261392D1CBDAEC2E8 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -126,8 +144,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4047B3FE2C3DEE8500A8BA05 /* OCMock in Frameworks */, - D7587C3652F6906210B3AE88 /* libPods-RunnerTests.a in Frameworks */, + 904EA421B6925EC8D52ABE1B /* libPods-RunnerTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -136,7 +153,7 @@ buildActionMask = 2147483647; files = ( 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */, - DAF0E91266956134538CC667 /* libPods-Runner.a in Frameworks */, + A1C354B092678F5A3DF18D01 /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -150,40 +167,41 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 52FBC2B567345431F81A0A0F /* Frameworks */ = { - isa = PBXGroup; - children = ( - 572FFC2B2BA326B420B22679 /* libPods-Runner.a */, - 17781D9462A1AEA7C99F8E45 /* libPods-RunnerTests.a */, - ); - name = Frameworks; - sourceTree = ""; - }; 68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = { isa = PBXGroup; children = ( + 8F66DAE72D1534A1000835F9 /* AuthenticationChallengeResponseProxyAPITests.swift */, + 8F66DAE82D1534A1000835F9 /* ErrorProxyAPITests.swift */, + 8F66DAE92D1534A1000835F9 /* FrameInfoProxyAPITests.swift */, + 8F66DAEA2D1534A1000835F9 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift */, + 8F66DAEB2D1534A1000835F9 /* HTTPCookieProxyAPITests.swift */, + 8F66DAEC2D1534A1000835F9 /* HTTPCookieStoreProxyAPITests.swift */, + 8F66DAED2D1534A1000835F9 /* HTTPURLResponseProxyAPITests.swift */, + 8F66DAEE2D1534A1000835F9 /* NavigationActionProxyAPITests.swift */, + 8F66DAEF2D1534A1000835F9 /* NavigationDelegateProxyAPITests.swift */, + 8F66DAF02D1534A1000835F9 /* NavigationResponseProxyAPITests.swift */, + 8F66DAF12D1534A1000835F9 /* NSObjectProxyAPITests.swift */, + 8F66DAF22D1534A1000835F9 /* PreferencesProxyAPITests.swift */, + 8F66DAF32D1534A1000835F9 /* ScriptMessageHandlerProxyAPITests.swift */, + 8F66DAF42D1534A1000835F9 /* ScriptMessageProxyAPITests.swift */, + 8F66DAF52D1534A1000835F9 /* ScrollViewDelegateProxyAPITests.swift */, + 8F66DAF62D1534A1000835F9 /* ScrollViewProxyAPITests.swift */, + 8F66DAF72D1534A1000835F9 /* SecurityOriginProxyAPITests.swift */, + 8F66DAF82D1534A1000835F9 /* TestBinaryMessenger.swift */, + 8F66DAF92D1534A1000835F9 /* TestProxyApiRegistrar.swift */, + 8F66DAFA2D1534A1000835F9 /* UIDelegateProxyAPITests.swift */, + 8F66DAFB2D1534A1000835F9 /* UIViewProxyAPITests.swift */, + 8F66DAFC2D1534A1000835F9 /* URLAuthenticationChallengeProxyAPITests.swift */, + 8F66DAFD2D1534A1000835F9 /* URLCredentialProxyAPITests.swift */, + 8F66DAFE2D1534A1000835F9 /* URLProtectionSpaceProxyAPITests.swift */, + 8F66DAFF2D1534A1000835F9 /* URLRequestProxyAPITests.swift */, + 8F66DB002D1534A1000835F9 /* UserContentControllerProxyAPITests.swift */, + 8F66DB012D1534A1000835F9 /* UserScriptProxyAPITests.swift */, + 8F66DB022D1534A1000835F9 /* WebsiteDataStoreProxyAPITests.swift */, + 8F66DB032D1534A1000835F9 /* WebViewConfigurationProxyAPITests.swift */, + 8F66DB042D1534A1000835F9 /* WebViewProxyAPITests.swift */, 68BDCAED23C3F7CB00D9C032 /* Info.plist */, - 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */, - 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */, - 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */, - 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */, - 8FB79B662820453400C101D3 /* FWFHTTPCookieStoreHostApiTests.m */, - 8FB79B6828204E8700C101D3 /* FWFPreferencesHostApiTests.m */, - 8FB79B6A28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m */, - 8FB79B6C2820533B00C101D3 /* FWFWebViewConfigurationHostApiTests.m */, - 8FB79B72282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m */, - 8FB79B7828209D1300C101D3 /* FWFUserContentControllerHostApiTests.m */, - 8FB79B822820A39300C101D3 /* FWFNavigationDelegateHostApiTests.m */, - 8FB79B842820A3A400C101D3 /* FWFUIDelegateHostApiTests.m */, - 8FB79B8E2820BAB300C101D3 /* FWFScrollViewHostApiTests.m */, - 8FB79B902820BAC700C101D3 /* FWFUIViewHostApiTests.m */, - 8FB79B962821985200C101D3 /* FWFObjectHostApiTests.m */, - 8F4FF94A29AC223F000A6586 /* FWFURLTests.m */, - 8F562F8F2A56C02D00C2BED6 /* FWFURLCredentialHostApiTests.m */, - 8F562F912A56C04F00C2BED6 /* FWFURLProtectionSpaceHostApiTests.m */, - 8F562F932A56C07B00C2BED6 /* FWFURLAuthenticationChallengeHostApiTests.m */, - 8F78EAA92A02CB9100C2E520 /* FWFErrorTests.m */, - 1096EF432A6BD9DB000CBDF7 /* FWFScrollViewDelegateHostApiTests.m */, + 8F66D9D72D1362BE000835F9 /* RunnerTests-Bridging-Header.h */, ); path = RunnerTests; sourceTree = ""; @@ -208,7 +226,7 @@ F7151F75266057800028CB91 /* RunnerUITests */, 97C146EF1CF9000F007C117D /* Products */, B8AEEA11D6ECBD09750349AE /* Pods */, - 52FBC2B567345431F81A0A0F /* Frameworks */, + CD4E515970E7228B6793AF9A /* Frameworks */, ); sourceTree = ""; }; @@ -249,14 +267,23 @@ B8AEEA11D6ECBD09750349AE /* Pods */ = { isa = PBXGroup; children = ( - F7A1921261392D1CBDAEC2E8 /* Pods-Runner.debug.xcconfig */, - B89AA31A64040E4A2F1E0CAF /* Pods-Runner.release.xcconfig */, - 39B2BDAA45DC06EAB8A6C4E7 /* Pods-RunnerTests.debug.xcconfig */, - 2286ACB87EA8CA27E739AD6C /* Pods-RunnerTests.release.xcconfig */, + 4AA20286555659E34ACB3BE5 /* Pods-Runner.debug.xcconfig */, + 14B8C759112CB6E8AA62F003 /* Pods-Runner.release.xcconfig */, + 56443D345A163E3A65320207 /* Pods-RunnerTests.debug.xcconfig */, + C519E1940290A9B5DEBB9BCF /* Pods-RunnerTests.release.xcconfig */, ); path = Pods; sourceTree = ""; }; + CD4E515970E7228B6793AF9A /* Frameworks */ = { + isa = PBXGroup; + children = ( + 185E08CFEB8AE9D939566DE6 /* libPods-Runner.a */, + 573E8F1472CA1578A7CBDB63 /* libPods-RunnerTests.a */, + ); + name = Frameworks; + sourceTree = ""; + }; F7151F75266057800028CB91 /* RunnerUITests */ = { isa = PBXGroup; children = ( @@ -273,7 +300,7 @@ isa = PBXNativeTarget; buildConfigurationList = 68BDCAF223C3F7CB00D9C032 /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( - AA38EF430495C2FB50F0F114 /* [CP] Check Pods Manifest.lock */, + 15992349B960AD5AE56B30FC /* [CP] Check Pods Manifest.lock */, 68BDCAE523C3F7CB00D9C032 /* Sources */, 68BDCAE623C3F7CB00D9C032 /* Frameworks */, 68BDCAE723C3F7CB00D9C032 /* Resources */, @@ -284,9 +311,6 @@ 68BDCAEF23C3F7CB00D9C032 /* PBXTargetDependency */, ); name = RunnerTests; - packageProductDependencies = ( - 4047B3FD2C3DEE8500A8BA05 /* OCMock */, - ); productName = webview_flutter_exampleTests; productReference = 68BDCAE923C3F7CB00D9C032 /* RunnerTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; @@ -295,7 +319,7 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 6F536C27DD48B395A30EBB65 /* [CP] Check Pods Manifest.lock */, + 9E2F8153891253EACD6E06D7 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, @@ -345,10 +369,12 @@ TargetAttributes = { 68BDCAE823C3F7CB00D9C032 = { DevelopmentTeam = 7624MWN53C; + LastSwiftMigration = 1610; ProvisioningStyle = Automatic; }; 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1610; }; F7151F73266057800028CB91 = { CreatedOnToolsVersion = 12.5; @@ -369,7 +395,6 @@ mainGroup = 97C146E51CF9000F007C117D; packageReferences = ( 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */, - 4047B3FC2C3DEE8500A8BA05 /* XCRemoteSwiftPackageReference "ocmock" */, ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; @@ -411,43 +436,43 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + 15992349B960AD5AE56B30FC /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); + inputFileListPaths = ( + ); inputPaths = ( - "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( ); - name = "Thin Binary"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; }; - 6F536C27DD48B395A30EBB65 /* [CP] Check Pods Manifest.lock */ = { + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); + name = "Thin Binary"; outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -464,7 +489,7 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; - AA38EF430495C2FB50F0F114 /* [CP] Check Pods Manifest.lock */ = { + 9E2F8153891253EACD6E06D7 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -479,7 +504,7 @@ outputFileListPaths = ( ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -493,27 +518,36 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8FA6A87928062CD000A4B183 /* FWFInstanceManagerTests.m in Sources */, - 8F78EAAA2A02CB9100C2E520 /* FWFErrorTests.m in Sources */, - 8F4FF94B29AC223F000A6586 /* FWFURLTests.m in Sources */, - 8FB79B852820A3A400C101D3 /* FWFUIDelegateHostApiTests.m in Sources */, - 8FB79B972821985200C101D3 /* FWFObjectHostApiTests.m in Sources */, - 8FB79B672820453400C101D3 /* FWFHTTPCookieStoreHostApiTests.m in Sources */, - 8F562F942A56C07B00C2BED6 /* FWFURLAuthenticationChallengeHostApiTests.m in Sources */, - 8FB79B5328134C3100C101D3 /* FWFWebViewHostApiTests.m in Sources */, - 8FB79B73282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m in Sources */, - 8FB79B7928209D1300C101D3 /* FWFUserContentControllerHostApiTests.m in Sources */, - 8F562F902A56C02D00C2BED6 /* FWFURLCredentialHostApiTests.m in Sources */, - 8F4FF949299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */, - 8FB79B6B28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m in Sources */, - 1096EF442A6BD9DB000CBDF7 /* FWFScrollViewDelegateHostApiTests.m in Sources */, - 8FB79B8F2820BAB300C101D3 /* FWFScrollViewHostApiTests.m in Sources */, - 8F562F922A56C04F00C2BED6 /* FWFURLProtectionSpaceHostApiTests.m in Sources */, - 8FB79B912820BAC700C101D3 /* FWFUIViewHostApiTests.m in Sources */, - 8FB79B55281B24F600C101D3 /* FWFDataConvertersTests.m in Sources */, - 8FB79B6D2820533B00C101D3 /* FWFWebViewConfigurationHostApiTests.m in Sources */, - 8FB79B832820A39300C101D3 /* FWFNavigationDelegateHostApiTests.m in Sources */, - 8FB79B6928204E8700C101D3 /* FWFPreferencesHostApiTests.m in Sources */, + 8F66DB052D1534A1000835F9 /* WebViewProxyAPITests.swift in Sources */, + 8F66DB062D1534A1000835F9 /* ScriptMessageHandlerProxyAPITests.swift in Sources */, + 8F66DB072D1534A1000835F9 /* UIDelegateProxyAPITests.swift in Sources */, + 8F66DB082D1534A1000835F9 /* URLCredentialProxyAPITests.swift in Sources */, + 8F66DB092D1534A1000835F9 /* NavigationDelegateProxyAPITests.swift in Sources */, + 8F66DB0A2D1534A1000835F9 /* UIViewProxyAPITests.swift in Sources */, + 8F66DB0B2D1534A1000835F9 /* NavigationActionProxyAPITests.swift in Sources */, + 8F66DB0C2D1534A1000835F9 /* WebViewConfigurationProxyAPITests.swift in Sources */, + 8F66DB0D2D1534A1000835F9 /* NavigationResponseProxyAPITests.swift in Sources */, + 8F66DB0E2D1534A1000835F9 /* TestProxyApiRegistrar.swift in Sources */, + 8F66DB0F2D1534A1000835F9 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift in Sources */, + 8F66DB102D1534A1000835F9 /* TestBinaryMessenger.swift in Sources */, + 8F66DB112D1534A1000835F9 /* UserContentControllerProxyAPITests.swift in Sources */, + 8F66DB122D1534A1000835F9 /* SecurityOriginProxyAPITests.swift in Sources */, + 8F66DB132D1534A1000835F9 /* AuthenticationChallengeResponseProxyAPITests.swift in Sources */, + 8F66DB142D1534A1000835F9 /* HTTPCookieProxyAPITests.swift in Sources */, + 8F66DB152D1534A1000835F9 /* UserScriptProxyAPITests.swift in Sources */, + 8F66DB162D1534A1000835F9 /* ScrollViewProxyAPITests.swift in Sources */, + 8F66DB172D1534A1000835F9 /* URLAuthenticationChallengeProxyAPITests.swift in Sources */, + 8F66DB182D1534A1000835F9 /* WebsiteDataStoreProxyAPITests.swift in Sources */, + 8F66DB192D1534A1000835F9 /* HTTPURLResponseProxyAPITests.swift in Sources */, + 8F66DB1A2D1534A1000835F9 /* ErrorProxyAPITests.swift in Sources */, + 8F66DB1B2D1534A1000835F9 /* ScrollViewDelegateProxyAPITests.swift in Sources */, + 8F66DB1C2D1534A1000835F9 /* ScriptMessageProxyAPITests.swift in Sources */, + 8F66DB1D2D1534A1000835F9 /* URLProtectionSpaceProxyAPITests.swift in Sources */, + 8F66DB1E2D1534A1000835F9 /* URLRequestProxyAPITests.swift in Sources */, + 8F66DB1F2D1534A1000835F9 /* FrameInfoProxyAPITests.swift in Sources */, + 8F66DB202D1534A1000835F9 /* NSObjectProxyAPITests.swift in Sources */, + 8F66DB212D1534A1000835F9 /* HTTPCookieStoreProxyAPITests.swift in Sources */, + 8F66DB222D1534A1000835F9 /* PreferencesProxyAPITests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -572,9 +606,10 @@ /* Begin XCBuildConfiguration section */ 68BDCAF023C3F7CB00D9C032 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 39B2BDAA45DC06EAB8A6C4E7 /* Pods-RunnerTests.debug.xcconfig */; + baseConfigurationReference = 56443D345A163E3A65320207 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -584,15 +619,20 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "RunnerTests/RunnerTests-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; + USE_HEADERMAP = NO; }; name = Debug; }; 68BDCAF123C3F7CB00D9C032 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 2286ACB87EA8CA27E739AD6C /* Pods-RunnerTests.release.xcconfig */; + baseConfigurationReference = C519E1940290A9B5DEBB9BCF /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -602,7 +642,11 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + SWIFT_OBJC_BRIDGING_HEADER = "RunnerTests/RunnerTests-Bridging-Header.h"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; + USE_HEADERMAP = NO; }; name = Release; }; @@ -658,6 +702,8 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SWIFT_STRICT_CONCURRENCY = minimal; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -707,6 +753,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_STRICT_CONCURRENCY = minimal; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -717,6 +765,7 @@ baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = 7624MWN53C; ENABLE_BITCODE = NO; @@ -735,6 +784,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.webviewFlutterExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "RunnerTests/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 6.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -744,6 +796,7 @@ baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = 7624MWN53C; ENABLE_BITCODE = NO; @@ -762,6 +815,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.webviewFlutterExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "RunnerTests/Runner-Bridging-Header.h"; + SWIFT_VERSION = 6.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; @@ -848,23 +903,7 @@ }; /* End XCLocalSwiftPackageReference section */ -/* Begin XCRemoteSwiftPackageReference section */ - 4047B3FC2C3DEE8500A8BA05 /* XCRemoteSwiftPackageReference "ocmock" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/erikdoe/ocmock"; - requirement = { - kind = revision; - revision = fe1661a3efed11831a6452f4b1a0c5e6ddc08c3d; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - /* Begin XCSwiftPackageProductDependency section */ - 4047B3FD2C3DEE8500A8BA05 /* OCMock */ = { - isa = XCSwiftPackageProductDependency; - package = 4047B3FC2C3DEE8500A8BA05 /* XCRemoteSwiftPackageReference "ocmock" */; - productName = OCMock; - }; 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = { isa = XCSwiftPackageProductDependency; productName = FlutterGeneratedPluginSwiftPackage; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/AuthenticationChallengeResponseProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/AuthenticationChallengeResponseProxyAPITests.swift new file mode 100644 index 000000000000..7283ada3926c --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/AuthenticationChallengeResponseProxyAPITests.swift @@ -0,0 +1,41 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class AuthenticationChallengeResponseProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, disposition: UrlSessionAuthChallengeDisposition.useCredential, + credential: URLCredential()) + XCTAssertNotNil(instance) + } + + func testDisposition() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar) + + let instance = AuthenticationChallengeResponse( + disposition: .useCredential, credential: URLCredential()) + let value = try? api.pigeonDelegate.disposition(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, UrlSessionAuthChallengeDisposition.useCredential) + } + + func testCredential() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiAuthenticationChallengeResponse(registrar) + + let instance = AuthenticationChallengeResponse( + disposition: .useCredential, credential: URLCredential()) + let value = try? api.pigeonDelegate.credential(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.credential) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ErrorProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ErrorProxyAPITests.swift new file mode 100644 index 000000000000..1ac1e1ec92e9 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ErrorProxyAPITests.swift @@ -0,0 +1,42 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class ErrorProxyAPITests: XCTestCase { + func testCode() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSError(registrar) + + let code = 0 + let instance = NSError(domain: "", code: code) + let value = try? api.pigeonDelegate.code(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, Int64(code)) + } + + func testDomain() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSError(registrar) + + let domain = "domain" + let instance = NSError(domain: domain, code: 0) + let value = try? api.pigeonDelegate.domain(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, domain) + } + + func testUserInfo() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSError(registrar) + + let userInfo: [String: String?] = ["some": "info"] + let instance = NSError(domain: "", code: 0, userInfo: userInfo as [String: Any]) + let value = try? api.pigeonDelegate.userInfo(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value as! [String: String?], userInfo) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.swift new file mode 100644 index 000000000000..08ecf264f6f4 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.swift @@ -0,0 +1,108 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +class FWFWebViewFlutterWKWebViewExternalAPITests: XCTestCase { + @MainActor func testWebViewForIdentifier() { + let registry = TestRegistry() + WebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "")!) + + let plugin = registry.registrar.plugin + + let webView = WKWebView(frame: .zero) + let webViewIdentifier = 0 + plugin?.proxyApiRegistrar?.instanceManager.addDartCreatedInstance( + webView, withIdentifier: Int64(webViewIdentifier)) + + let result = FWFWebViewFlutterWKWebViewExternalAPI.webView( + forIdentifier: Int64(webViewIdentifier), with: registry) + XCTAssertEqual(result, webView) + } +} + +class TestRegistry: NSObject, FlutterPluginRegistry { + let registrar = TestFlutterPluginRegistrar() + + func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar? { + return registrar + } + + func hasPlugin(_ pluginKey: String) -> Bool { + return true + } + + func valuePublished(byPlugin pluginKey: String) -> NSObject? { + if pluginKey == "WebViewFlutterPlugin" { + return registrar.plugin + } + return nil + } +} + +class TestFlutterTextureRegistry: NSObject, FlutterTextureRegistry { + func register(_ texture: FlutterTexture) -> Int64 { + return 0 + } + + func textureFrameAvailable(_ textureId: Int64) { + + } + + func unregisterTexture(_ textureId: Int64) { + + } +} + +class TestFlutterPluginRegistrar: NSObject, FlutterPluginRegistrar { + var plugin: WebViewFlutterPlugin? + + func messenger() -> FlutterBinaryMessenger { + return TestBinaryMessenger() + } + + func textures() -> FlutterTextureRegistry { + return TestFlutterTextureRegistry() + } + + func register(_ factory: FlutterPlatformViewFactory, withId factoryId: String) { + } + + func register( + _ factory: FlutterPlatformViewFactory, withId factoryId: String, + gestureRecognizersBlockingPolicy: FlutterPlatformViewGestureRecognizersBlockingPolicy + ) { + } + + func publish(_ value: NSObject) { + plugin = (value as! WebViewFlutterPlugin) + } + + func addMethodCallDelegate(_ delegate: FlutterPlugin, channel: FlutterMethodChannel) { + + } + + func addApplicationDelegate(_ delegate: FlutterPlugin) { + + } + + func lookupKey(forAsset asset: String) -> String { + return "" + } + + func lookupKey(forAsset asset: String, fromPackage package: String) -> String { + return "" + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FrameInfoProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FrameInfoProxyAPITests.swift new file mode 100644 index 000000000000..d9a382da4fee --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FrameInfoProxyAPITests.swift @@ -0,0 +1,41 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +@MainActor +class FrameInfoProxyAPITests: XCTestCase { + @MainActor func testIsMainFrame() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKFrameInfo(registrar) + + var instance: TestFrameInfo? = TestFrameInfo() + let value = try? api.pigeonDelegate.isMainFrame(pigeonApi: api, pigeonInstance: instance!) + + XCTAssertEqual(value, instance!.isMainFrame) + } + + @MainActor func testRequest() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKFrameInfo(registrar) + + var instance: TestFrameInfo? = TestFrameInfo() + let value = try? api.pigeonDelegate.request(pigeonApi: api, pigeonInstance: instance!) + + XCTAssertEqual(value?.value, instance!.request) + } +} + +class TestFrameInfo: WKFrameInfo { + override var isMainFrame: Bool { + return true + } + + override var request: URLRequest { + return URLRequest(url: URL(string: "https://google.com")!) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieProxyAPITests.swift new file mode 100644 index 000000000000..13e7754c491e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieProxyAPITests.swift @@ -0,0 +1,34 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class HTTPCookieProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiHTTPCookie(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, + properties: [.name: "foo", .value: "bar", .domain: "http://google.com", .path: "/anything"]) + XCTAssertNotNil(instance) + } + + func testGetProperties() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiHTTPCookie(registrar) + + let instance = HTTPCookie(properties: [ + .name: "foo", .value: "bar", .domain: "http://google.com", .path: "/anything", + ])! + let value = try? api.pigeonDelegate.getProperties(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value?[.name] as? String, "foo") + XCTAssertEqual(value?[.value] as? String, "bar") + XCTAssertEqual(value?[.domain] as? String, "http://google.com") + XCTAssertEqual(value?[.path] as? String, "/anything") + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieStoreProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieStoreProxyAPITests.swift new file mode 100644 index 000000000000..344b8207830b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPCookieStoreProxyAPITests.swift @@ -0,0 +1,68 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class HTTPCookieStoreProxyAPITests: XCTestCase { + @MainActor func testSetCookie() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKHTTPCookieStore(registrar) + + var instance: TestCookieStore? = TestCookieStore.customInit() + let cookie = HTTPCookie(properties: [ + .name: "foo", .value: "bar", .domain: "http://google.com", .path: "/anything", + ])! + + let expect = expectation(description: "Wait for setCookie.") + api.pigeonDelegate.setCookie(pigeonApi: api, pigeonInstance: instance!, cookie: cookie) { + result in + switch result { + case .success(_): + expect.fulfill() + case .failure(_): + break + } + } + + wait(for: [expect], timeout: 1.0) + XCTAssertEqual(instance!.setCookieArg, cookie) + + // Ensure instance is deallocated on main thread. + DispatchQueue.main.async { + instance = nil + } + } +} + +class TestCookieStore: WKHTTPCookieStore { + var setCookieArg: HTTPCookie? = nil + + // Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE + static func customInit() -> TestCookieStore { + let instance = + TestCookieStore.perform(NSSelectorFromString("new")).takeRetainedValue() as! TestCookieStore + return instance + } + + #if compiler(>=6.0) + public override func setCookie( + _ cookie: HTTPCookie, completionHandler: (@MainActor () -> Void)? = nil + ) { + setCookieArg = cookie + DispatchQueue.main.async { + completionHandler?() + } + } + #else + public override func setCookie(_ cookie: HTTPCookie, completionHandler: (() -> Void)? = nil) { + setCookieArg = cookie + DispatchQueue.main.async { + completionHandler?() + } + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPURLResponseProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPURLResponseProxyAPITests.swift new file mode 100644 index 000000000000..4199d189c057 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/HTTPURLResponseProxyAPITests.swift @@ -0,0 +1,20 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class HTTPURLResponseProxyAPITests: XCTestCase { + func testStatusCode() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiHTTPURLResponse(registrar) + + let instance = HTTPURLResponse( + url: URL(string: "http://google.com")!, statusCode: 400, httpVersion: nil, headerFields: nil)! + let value = try? api.pigeonDelegate.statusCode(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, Int64(instance.statusCode)) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NSObjectProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NSObjectProxyAPITests.swift new file mode 100644 index 000000000000..68b56079edea --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NSObjectProxyAPITests.swift @@ -0,0 +1,89 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class ObjectProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSObject(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + func testAddObserver() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSObject(registrar) + + let instance = TestObject() + let observer = NSObject() + let keyPath = "myString" + let options: [KeyValueObservingOptions] = [.newValue] + try? api.pigeonDelegate.addObserver( + pigeonApi: api, pigeonInstance: instance, observer: observer, keyPath: keyPath, + options: options) + + var nativeOptions: NSKeyValueObservingOptions = [] + nativeOptions.insert(.new) + + XCTAssertEqual(instance.addObserverArgs, [observer, keyPath, nativeOptions.rawValue]) + } + + func testRemoveObserver() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiNSObject(registrar) + + let instance = TestObject() + let object = NSObject() + let keyPath = "myString" + try? api.pigeonDelegate.removeObserver( + pigeonApi: api, pigeonInstance: instance, observer: object, keyPath: keyPath) + + XCTAssertEqual(instance.removeObserverArgs, [object, keyPath]) + } + + func testObserveValue() { + let api = TestObjectApi() + + let registrar = TestProxyApiRegistrar() + let instance = NSObjectImpl(api: api, registrar: registrar) + let keyPath = "myString" + let object = NSObject() + let change = [NSKeyValueChangeKey.indexesKey: -1] + instance.observeValue(forKeyPath: keyPath, of: object, change: change, context: nil) + + XCTAssertEqual(api.observeValueArgs, [keyPath, object, [KeyValueChangeKey.indexes: -1]]) + } +} + +class TestObject: NSObject { + var addObserverArgs: [AnyHashable?]? = nil + var removeObserverArgs: [AnyHashable?]? = nil + + override func addObserver( + _ observer: NSObject, forKeyPath keyPath: String, options: NSKeyValueObservingOptions = [], + context: UnsafeMutableRawPointer? + ) { + addObserverArgs = [observer, keyPath, options.rawValue] + } + + override func removeObserver(_ observer: NSObject, forKeyPath keyPath: String) { + removeObserverArgs = [observer, keyPath] + } +} + +class TestObjectApi: PigeonApiProtocolNSObject { + var observeValueArgs: [AnyHashable?]? = nil + + func observeValue( + pigeonInstance pigeonInstanceArg: NSObject, keyPath keyPathArg: String?, + object objectArg: NSObject?, change changeArg: [KeyValueChangeKey: Any?]?, + completion: @escaping (Result) -> Void + ) { + observeValueArgs = [keyPathArg, objectArg, changeArg! as! [KeyValueChangeKey: Int]] + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationActionProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationActionProxyAPITests.swift new file mode 100644 index 000000000000..6597d5ecf893 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationActionProxyAPITests.swift @@ -0,0 +1,71 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class NavigationActionProxyAPITests: XCTestCase { + @MainActor func testRequest() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationAction(registrar) + + var instance: TestNavigationAction? = TestNavigationAction() + let value = try? api.pigeonDelegate.request(pigeonApi: api, pigeonInstance: instance!) + + XCTAssertEqual(value?.value, instance!.request) + + // Ensure instance is deallocated on the main frame. + DispatchQueue.main.async { + instance = nil + } + } + + @MainActor func testTargetFrame() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationAction(registrar) + + var instance: TestNavigationAction? = TestNavigationAction() + let value = try? api.pigeonDelegate.targetFrame(pigeonApi: api, pigeonInstance: instance!) + + XCTAssertEqual(value, instance!.targetFrame) + + // Ensure instance is deallocated on the main frame. + DispatchQueue.main.async { + instance = nil + } + } + + @MainActor func testNavigationType() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationAction(registrar) + + var instance: TestNavigationAction? = TestNavigationAction() + let value = try? api.pigeonDelegate.navigationType(pigeonApi: api, pigeonInstance: instance!) + + XCTAssertEqual(value, .formSubmitted) + + // Ensure instance is deallocated on the main frame. + DispatchQueue.main.async { + instance = nil + } + } +} + +class TestNavigationAction: WKNavigationAction { + let internalTargetFrame = TestFrameInfo() + + override var request: URLRequest { + return URLRequest(url: URL(string: "http://google.com")!) + } + + override var targetFrame: WKFrameInfo? { + return internalTargetFrame + } + + override var navigationType: WKNavigationType { + return .formSubmitted + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationDelegateProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationDelegateProxyAPITests.swift new file mode 100644 index 000000000000..efeeb88cf6a9 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationDelegateProxyAPITests.swift @@ -0,0 +1,254 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class NavigationDelegateProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationDelegate(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + @MainActor func testDidFinishNavigation() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = TestWebView(frame: .zero) + + instance.webView(webView, didFinish: nil) + + XCTAssertEqual(api.didFinishNavigationArgs, [webView, webView.url?.absoluteString]) + } + + @MainActor func testDidStartProvisionalNavigation() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = TestWebView(frame: .zero) + instance.webView(webView, didStartProvisionalNavigation: nil) + + XCTAssertEqual(api.didStartProvisionalNavigationArgs, [webView, webView.url?.absoluteString]) + } + + @MainActor func testDecidePolicyForNavigationAction() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let navigationAction = TestNavigationAction() + + let callbackExpectation = expectation(description: "Wait for callback.") + var result: WKNavigationActionPolicy? + instance.webView(webView, decidePolicyFor: navigationAction) { policy in + result = policy + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual(api.decidePolicyForNavigationActionArgs, [webView, navigationAction]) + XCTAssertEqual(result, .allow) + } + + @MainActor func testDecidePolicyForNavigationResponse() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let navigationResponse = TestNavigationResponse() + + var result: WKNavigationResponsePolicy? + let callbackExpectation = expectation(description: "Wait for callback.") + instance.webView(webView, decidePolicyFor: navigationResponse) { policy in + result = policy + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual(api.decidePolicyForNavigationResponseArgs, [webView, navigationResponse]) + XCTAssertEqual(result, .cancel) + } + + @MainActor func testDidFailNavigation() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let error = NSError(domain: "", code: 12) + instance.webView(webView, didFail: nil, withError: error) + + XCTAssertEqual(api.didFailNavigationArgs, [webView, error]) + } + + @MainActor func testDidFailProvisionalNavigation() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let error = NSError(domain: "", code: 12) + instance.webView(webView, didFailProvisionalNavigation: nil, withError: error) + + XCTAssertEqual(api.didFailProvisionalNavigationArgs, [webView, error]) + } + + @MainActor func testWebViewWebContentProcessDidTerminate() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + instance.webViewWebContentProcessDidTerminate(webView) + + XCTAssertEqual(api.webViewWebContentProcessDidTerminateArgs, [webView]) + } + + @MainActor func testDidReceiveAuthenticationChallenge() { + let api = TestNavigationDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = NavigationDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let challenge = URLAuthenticationChallenge( + protectionSpace: URLProtectionSpace(), proposedCredential: nil, previousFailureCount: 32, + failureResponse: nil, error: nil, sender: TestURLAuthenticationChallengeSender()) + + var dispositionResult: URLSession.AuthChallengeDisposition? + var credentialResult: URLCredential? + let callbackExpectation = expectation(description: "Wait for callback.") + instance.webView(webView, didReceive: challenge) { disposition, credential in + dispositionResult = disposition + credentialResult = credential + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual(api.didReceiveAuthenticationChallengeArgs, [webView, challenge]) + XCTAssertEqual(dispositionResult, .useCredential) + XCTAssertNotNil(credentialResult) + } +} + +class TestNavigationDelegateApi: PigeonApiProtocolWKNavigationDelegate { + var didFinishNavigationArgs: [AnyHashable?]? = nil + var didStartProvisionalNavigationArgs: [AnyHashable?]? = nil + var decidePolicyForNavigationActionArgs: [AnyHashable?]? = nil + var decidePolicyForNavigationResponseArgs: [AnyHashable?]? = nil + var didFailNavigationArgs: [AnyHashable?]? = nil + var didFailProvisionalNavigationArgs: [AnyHashable?]? = nil + var webViewWebContentProcessDidTerminateArgs: [AnyHashable?]? = nil + var didReceiveAuthenticationChallengeArgs: [AnyHashable?]? = nil + + func registrar() -> ProxyAPIDelegate { + return ProxyAPIDelegate() + } + + func didFinishNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, + completion: @escaping (Result) -> Void + ) { + didFinishNavigationArgs = [webViewArg, urlArg] + } + + func didStartProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + url urlArg: String?, + completion: @escaping (Result) -> Void + ) { + didStartProvisionalNavigationArgs = [webViewArg, urlArg] + } + + func decidePolicyForNavigationAction( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping ( + Result< + webview_flutter_wkwebview.NavigationActionPolicy, webview_flutter_wkwebview.PigeonError + > + ) -> Void + ) { + decidePolicyForNavigationActionArgs = [webViewArg, navigationActionArg] + completion(.success(.allow)) + } + + func decidePolicyForNavigationResponse( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + navigationResponse navigationResponseArg: WKNavigationResponse, + completion: @escaping ( + Result< + webview_flutter_wkwebview.NavigationResponsePolicy, webview_flutter_wkwebview.PigeonError + > + ) -> Void + ) { + decidePolicyForNavigationResponseArgs = [webViewArg, navigationResponseArg] + completion(.success(.cancel)) + } + + func didFailNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, + completion: @escaping (Result) -> Void + ) { + didFailNavigationArgs = [webViewArg, errorArg] + } + + func didFailProvisionalNavigation( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + error errorArg: NSError, + completion: @escaping (Result) -> Void + ) { + didFailProvisionalNavigationArgs = [webViewArg, errorArg] + } + + func webViewWebContentProcessDidTerminate( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + completion: @escaping (Result) -> Void + ) { + webViewWebContentProcessDidTerminateArgs = [webViewArg] + } + + func didReceiveAuthenticationChallenge( + pigeonInstance pigeonInstanceArg: WKNavigationDelegate, webView webViewArg: WKWebView, + challenge challengeArg: URLAuthenticationChallenge, + completion: @escaping ( + Result< + webview_flutter_wkwebview.AuthenticationChallengeResponse, + webview_flutter_wkwebview.PigeonError + > + ) -> Void + ) { + didReceiveAuthenticationChallengeArgs = [webViewArg, challengeArg] + completion( + .success( + AuthenticationChallengeResponse(disposition: .useCredential, credential: URLCredential()))) + } +} + +class TestWebView: WKWebView { + override var url: URL? { + return URL(string: "http://google.com") + } +} + +class TestURLAuthenticationChallengeSender: NSObject, URLAuthenticationChallengeSender, @unchecked + Sendable +{ + func use(_ credential: URLCredential, for challenge: URLAuthenticationChallenge) { + + } + + func continueWithoutCredential(for challenge: URLAuthenticationChallenge) { + + } + + func cancel(_ challenge: URLAuthenticationChallenge) { + + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationResponseProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationResponseProxyAPITests.swift new file mode 100644 index 000000000000..c3367b0bb40b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/NavigationResponseProxyAPITests.swift @@ -0,0 +1,42 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class NavigationResponseProxyAPITests: XCTestCase { + @MainActor func testResponse() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationResponse(registrar) + + let instance = WKNavigationResponse() + let value = try? api.pigeonDelegate.response(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.response) + } + + @MainActor func testIsForMainFrame() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKNavigationResponse(registrar) + + let instance = TestNavigationResponse() + let value = try? api.pigeonDelegate.isForMainFrame(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.isForMainFrame) + } +} + +class TestNavigationResponse: WKNavigationResponse { + let testResponse = URLResponse() + + override var isForMainFrame: Bool { + return true + } + + override var response: URLResponse { + return testResponse + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/PreferencesProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/PreferencesProxyAPITests.swift new file mode 100644 index 000000000000..787ff4de54a8 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/PreferencesProxyAPITests.swift @@ -0,0 +1,22 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class PreferencesProxyAPITests: XCTestCase { + @MainActor func testSetJavaScriptEnabled() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKPreferences(registrar) + + let instance = WKPreferences() + let enabled = true + try? api.pigeonDelegate.setJavaScriptEnabled( + pigeonApi: api, pigeonInstance: instance, enabled: enabled) + + XCTAssertEqual(instance.javaScriptEnabled, enabled) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/RunnerTests-Bridging-Header.h b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/RunnerTests-Bridging-Header.h new file mode 100644 index 000000000000..e7217c7d7b3f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/RunnerTests-Bridging-Header.h @@ -0,0 +1,3 @@ +// 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. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageHandlerProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageHandlerProxyAPITests.swift new file mode 100644 index 000000000000..f784f77d3721 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageHandlerProxyAPITests.swift @@ -0,0 +1,42 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class ScriptMessageHandlerProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKScriptMessageHandler(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + @MainActor func testDidReceiveScriptMessage() { + let api = TestScriptMessageHandlerApi() + let registrar = TestProxyApiRegistrar() + let instance = ScriptMessageHandlerImpl(api: api, registrar: registrar) + let controller = WKUserContentController() + let message = WKScriptMessage() + + instance.userContentController(controller, didReceive: message) + + XCTAssertEqual(api.didReceiveScriptMessageArgs, [controller, message]) + } +} + +class TestScriptMessageHandlerApi: PigeonApiProtocolWKScriptMessageHandler { + var didReceiveScriptMessageArgs: [AnyHashable?]? = nil + + func didReceiveScriptMessage( + pigeonInstance pigeonInstanceArg: WKScriptMessageHandler, + controller controllerArg: WKUserContentController, message messageArg: WKScriptMessage, + completion: @escaping (Result) -> Void + ) { + didReceiveScriptMessageArgs = [controllerArg, messageArg] + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageProxyAPITests.swift new file mode 100644 index 000000000000..7170d5fe706d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScriptMessageProxyAPITests.swift @@ -0,0 +1,40 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class ScriptMessageProxyAPITests: XCTestCase { + @MainActor func testName() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKScriptMessage(registrar) + + let instance = TestScriptMessage() + let value = try? api.pigeonDelegate.name(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.name) + } + + @MainActor func testBody() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKScriptMessage(registrar) + + let instance = TestScriptMessage() + let value = try? api.pigeonDelegate.body(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value as! Int, 23) + } +} + +class TestScriptMessage: WKScriptMessage { + override var name: String { + return "myString" + } + + override var body: Any { + return NSNumber(integerLiteral: 23) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewDelegateProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewDelegateProxyAPITests.swift new file mode 100644 index 000000000000..08c606702037 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewDelegateProxyAPITests.swift @@ -0,0 +1,50 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import UIKit +#endif + +class ScrollViewDelegateProxyAPITests: XCTestCase { + #if os(iOS) + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIScrollViewDelegate(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + @MainActor func testScrollViewDidScroll() { + let api = TestScrollViewDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = ScrollViewDelegateImpl(api: api, registrar: registrar) + let scrollView = UIScrollView(frame: .zero) + let x = 1.0 + let y = 1.0 + scrollView.contentOffset = CGPoint(x: x, y: y) + instance.scrollViewDidScroll(scrollView) + + XCTAssertEqual(api.scrollViewDidScrollArgs, [scrollView, x, y]) + } + #endif +} + +#if os(iOS) + class TestScrollViewDelegateApi: PigeonApiProtocolUIScrollViewDelegate { + var scrollViewDidScrollArgs: [AnyHashable?]? = nil + + func scrollViewDidScroll( + pigeonInstance pigeonInstanceArg: UIScrollViewDelegate, + scrollView scrollViewArg: UIScrollView, x xArg: Double, y yArg: Double, + completion: @escaping (Result) -> Void + ) { + scrollViewDidScrollArgs = [scrollViewArg, xArg, yArg] + } + } +#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewProxyAPITests.swift new file mode 100644 index 000000000000..fa337b62b231 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/ScrollViewProxyAPITests.swift @@ -0,0 +1,86 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import UIKit +#endif + +class ScrollViewProxyAPITests: XCTestCase { + #if os(iOS) + @MainActor func testGetContentOffset() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIScrollView(registrar) + + let instance = TestScrollView(frame: .zero) + let value = try? api.pigeonDelegate.getContentOffset(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, [instance.contentOffset.x, instance.contentOffset.y]) + } + + @MainActor func testScrollBy() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIScrollView(registrar) + + let instance = TestScrollView(frame: .zero) + instance.contentOffset = CGPoint(x: 1.0, y: 1.0) + try? api.pigeonDelegate.scrollBy(pigeonApi: api, pigeonInstance: instance, x: 1.0, y: 1.0) + + XCTAssertEqual(instance.setContentOffsetArgs as? [Double], [2.0, 2.0]) + } + + @MainActor func testSetContentOffset() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIScrollView(registrar) + + let instance = TestScrollView(frame: .zero) + let x = 1.0 + let y = 1.0 + try? api.pigeonDelegate.setContentOffset(pigeonApi: api, pigeonInstance: instance, x: x, y: y) + + XCTAssertEqual(instance.setContentOffsetArgs as? [Double], [x, y]) + } + + @MainActor func testSetDelegate() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIScrollView(registrar) + + let instance = TestScrollView(frame: .zero) + let delegate = ScrollViewDelegateImpl( + api: registrar.apiDelegate.pigeonApiUIScrollViewDelegate(registrar), registrar: registrar) + try? api.pigeonDelegate.setDelegate( + pigeonApi: api, pigeonInstance: instance, delegate: delegate) + + XCTAssertEqual(instance.setDelegateArgs, [delegate]) + } + #endif +} + +#if os(iOS) + class TestScrollView: UIScrollView { + var setContentOffsetArgs: [AnyHashable?]? = nil + var setDelegateArgs: [AnyHashable?]? = nil + + override var contentOffset: CGPoint { + get { + return CGPoint(x: 1.0, y: 1.0) + } + set { + setContentOffsetArgs = [newValue.x, newValue.y] + } + } + + override var delegate: UIScrollViewDelegate? { + get { + return nil + } + set { + setDelegateArgs = ([newValue] as! [AnyHashable?]) + } + } + } +#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/SecurityOriginProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/SecurityOriginProxyAPITests.swift new file mode 100644 index 000000000000..d9bbea0a6219 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/SecurityOriginProxyAPITests.swift @@ -0,0 +1,65 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +@MainActor +class SecurityOriginProxyAPITests: XCTestCase { + static let testSecurityOrigin = TestSecurityOrigin.customInit() + + @MainActor func testHost() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKSecurityOrigin(registrar) + + let instance = SecurityOriginProxyAPITests.testSecurityOrigin + let value = try? api.pigeonDelegate.host(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.host) + } + + @MainActor func testPort() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKSecurityOrigin(registrar) + + let instance = SecurityOriginProxyAPITests.testSecurityOrigin + let value = try? api.pigeonDelegate.port(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, Int64(instance.port)) + } + + @MainActor func testSecurityProtocol() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKSecurityOrigin(registrar) + + let instance = SecurityOriginProxyAPITests.testSecurityOrigin + let value = try? api.pigeonDelegate.securityProtocol(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.`protocol`) + } +} + +class TestSecurityOrigin: WKSecurityOrigin { + // Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE + static func customInit() -> TestSecurityOrigin { + let instance = + TestSecurityOrigin.perform(NSSelectorFromString("new")).takeRetainedValue() + as! TestSecurityOrigin + return instance + } + + override var host: String { + return "host" + } + + override var port: Int { + return 23 + } + + override var `protocol`: String { + return "protocol" + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestBinaryMessenger.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestBinaryMessenger.swift new file mode 100644 index 000000000000..4c89531993c2 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestBinaryMessenger.swift @@ -0,0 +1,33 @@ +// 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. + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +class TestBinaryMessenger: NSObject, FlutterBinaryMessenger { + func send(onChannel channel: String, message: Data?) { + + } + + func send( + onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply? = nil + ) { + + } + + func setMessageHandlerOnChannel( + _ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil + ) -> FlutterBinaryMessengerConnection { + return 0 + } + + func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) { + + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestProxyApiRegistrar.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestProxyApiRegistrar.swift new file mode 100644 index 000000000000..a6c7397211a9 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/TestProxyApiRegistrar.swift @@ -0,0 +1,19 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class TestProxyApiRegistrar: ProxyAPIRegistrar { + init() { + super.init(binaryMessenger: TestBinaryMessenger()) + } + + override func dispatchOnMainThread( + execute work: @escaping (@escaping (String, PigeonError) -> Void) -> Void + ) { + work { _, _ in } + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIDelegateProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIDelegateProxyAPITests.swift new file mode 100644 index 000000000000..44f15e0bbe79 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIDelegateProxyAPITests.swift @@ -0,0 +1,175 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class UIDelegateProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUIDelegate(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + @MainActor func testOnCreateWebView() { + let api = TestDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = UIDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let configuration = WKWebViewConfiguration() + let navigationAction = TestNavigationAction() + + let result = instance.webView( + webView, createWebViewWith: configuration, for: navigationAction, + windowFeatures: WKWindowFeatures()) + + XCTAssertEqual(api.onCreateWebViewArgs, [webView, configuration, navigationAction]) + XCTAssertNil(result) + } + + @available(iOS 15.0, *) + @MainActor func testRequestMediaCapturePermission() { + let api = TestDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = UIDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let origin = SecurityOriginProxyAPITests.testSecurityOrigin + let frame = TestFrameInfo() + let type: WKMediaCaptureType = .camera + + var resultDecision: WKPermissionDecision? + let callbackExpectation = expectation(description: "Wait for callback.") + instance.webView( + webView, requestMediaCapturePermissionFor: origin, initiatedByFrame: frame, type: type + ) { decision in + resultDecision = decision + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual( + api.requestMediaCapturePermissionArgs, [webView, origin, frame, MediaCaptureType.camera]) + XCTAssertEqual(resultDecision, .prompt) + } + + @MainActor func testRunJavaScriptAlertPanel() { + let api = TestDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = UIDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let message = "myString" + let frame = TestFrameInfo() + + instance.webView(webView, runJavaScriptAlertPanelWithMessage: message, initiatedByFrame: frame) + { + } + + XCTAssertEqual(api.runJavaScriptAlertPanelArgs, [webView, message, frame]) + } + + @MainActor func testRunJavaScriptConfirmPanel() { + let api = TestDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = UIDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let message = "myString" + let frame = TestFrameInfo() + + var confirmedResult: Bool? + let callbackExpectation = expectation(description: "Wait for callback.") + instance.webView( + webView, runJavaScriptConfirmPanelWithMessage: message, initiatedByFrame: frame + ) { confirmed in + confirmedResult = confirmed + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual(api.runJavaScriptConfirmPanelArgs, [webView, message, frame]) + XCTAssertEqual(confirmedResult, true) + } + + @MainActor func testRunJavaScriptTextInputPanel() { + let api = TestDelegateApi() + let registrar = TestProxyApiRegistrar() + let instance = UIDelegateImpl(api: api, registrar: registrar) + let webView = WKWebView(frame: .zero) + let prompt = "myString" + let defaultText = "myString3" + let frame = TestFrameInfo() + + var inputResult: String? + let callbackExpectation = expectation(description: "Wait for callback.") + instance.webView( + webView, runJavaScriptTextInputPanelWithPrompt: prompt, defaultText: defaultText, + initiatedByFrame: frame + ) { input in + inputResult = input + callbackExpectation.fulfill() + } + + wait(for: [callbackExpectation], timeout: 1.0) + + XCTAssertEqual(api.runJavaScriptTextInputPanelArgs, [webView, prompt, defaultText, frame]) + XCTAssertEqual(inputResult, "myString2") + } +} + +class TestDelegateApi: PigeonApiProtocolWKUIDelegate { + var onCreateWebViewArgs: [AnyHashable?]? = nil + var requestMediaCapturePermissionArgs: [AnyHashable?]? = nil + var runJavaScriptAlertPanelArgs: [AnyHashable?]? = nil + var runJavaScriptConfirmPanelArgs: [AnyHashable?]? = nil + var runJavaScriptTextInputPanelArgs: [AnyHashable?]? = nil + + func onCreateWebView( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + configuration configurationArg: WKWebViewConfiguration, + navigationAction navigationActionArg: WKNavigationAction, + completion: @escaping (Result) -> Void + ) { + onCreateWebViewArgs = [webViewArg, configurationArg, navigationActionArg] + } + + func requestMediaCapturePermission( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + origin originArg: WKSecurityOrigin, frame frameArg: WKFrameInfo, type typeArg: MediaCaptureType, + completion: @escaping (Result) -> Void + ) { + requestMediaCapturePermissionArgs = [webViewArg, originArg, frameArg, typeArg] + completion(.success(.prompt)) + } + + func runJavaScriptAlertPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + runJavaScriptAlertPanelArgs = [webViewArg, messageArg, frameArg] + } + + func runJavaScriptConfirmPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + message messageArg: String, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + runJavaScriptConfirmPanelArgs = [webViewArg, messageArg, frameArg] + completion(.success(true)) + } + + func runJavaScriptTextInputPanel( + pigeonInstance pigeonInstanceArg: WKUIDelegate, webView webViewArg: WKWebView, + prompt promptArg: String, defaultText defaultTextArg: String?, frame frameArg: WKFrameInfo, + completion: @escaping (Result) -> Void + ) { + runJavaScriptTextInputPanelArgs = [webViewArg, promptArg, defaultTextArg, frameArg] + completion(.success("myString2")) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIViewProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIViewProxyAPITests.swift new file mode 100644 index 000000000000..d0b3191c107e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UIViewProxyAPITests.swift @@ -0,0 +1,44 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import UIKit +#endif + +class UIViewProxyAPITests: XCTestCase { + #if os(iOS) + @MainActor func testSetBackgroundColor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIView(registrar) + + let instance = UIView(frame: .zero) + let value = 0xFFF4_4336 + try? api.pigeonDelegate.setBackgroundColor( + pigeonApi: api, pigeonInstance: instance, value: Int64(value)) + + let red = CGFloat(Double((value >> 16 & 0xff)) / 255.0) + let green = CGFloat(Double(value >> 8 & 0xff) / 255.0) + let blue = CGFloat(Double(value & 0xff) / 255.0) + let alpha = CGFloat(Double(value >> 24 & 0xff) / 255.0) + + XCTAssertEqual( + instance.backgroundColor, UIColor(red: red, green: green, blue: blue, alpha: alpha)) + } + + @MainActor func testSetOpaque() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIView(registrar) + + let instance = UIView(frame: .zero) + let opaque = true + try? api.pigeonDelegate.setOpaque(pigeonApi: api, pigeonInstance: instance, opaque: opaque) + + XCTAssertEqual(instance.isOpaque, opaque) + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLAuthenticationChallengeProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLAuthenticationChallengeProxyAPITests.swift new file mode 100644 index 000000000000..5d8fbe9779fb --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLAuthenticationChallengeProxyAPITests.swift @@ -0,0 +1,21 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class URLAuthenticationChallengeProxyAPITests: XCTestCase { + func testGetProtectionSpace() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLAuthenticationChallenge(registrar) + + let instance = URLAuthenticationChallenge( + protectionSpace: URLProtectionSpace(), proposedCredential: nil, previousFailureCount: 3, + failureResponse: nil, error: nil, sender: TestURLAuthenticationChallengeSender()) + let value = try? api.pigeonDelegate.getProtectionSpace(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.protectionSpace) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLCredentialProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLCredentialProxyAPITests.swift new file mode 100644 index 000000000000..d7eb4b1192a5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLCredentialProxyAPITests.swift @@ -0,0 +1,18 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class URLCredentialProxyAPITests: XCTestCase { + func testWithUser() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLCredential(registrar) + + let instance = try? api.pigeonDelegate.withUser( + pigeonApi: api, user: "myString", password: "myString", persistence: .none) + XCTAssertNotNil(instance) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLProtectionSpaceProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLProtectionSpaceProxyAPITests.swift new file mode 100644 index 000000000000..fcb9e9e4fb94 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLProtectionSpaceProxyAPITests.swift @@ -0,0 +1,59 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +class ProtectionSpaceProxyAPITests: XCTestCase { + func testHost() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLProtectionSpace(registrar) + + let instance = URLProtectionSpace( + host: "host", port: 23, protocol: "protocol", realm: "realm", authenticationMethod: "myMethod" + ) + let value = try? api.pigeonDelegate.host(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.host) + } + + func testPort() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLProtectionSpace(registrar) + + let instance = URLProtectionSpace( + host: "host", port: 23, protocol: "protocol", realm: "realm", authenticationMethod: "myMethod" + ) + let value = try? api.pigeonDelegate.port(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, Int64(instance.port)) + } + + func testRealm() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLProtectionSpace(registrar) + + let instance = URLProtectionSpace( + host: "host", port: 23, protocol: "protocol", realm: "realm", authenticationMethod: "myMethod" + ) + let value = try? api.pigeonDelegate.realm(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.realm) + } + + func testAuthenticationMethod() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLProtectionSpace(registrar) + + let instance = URLProtectionSpace( + host: "host", port: 23, protocol: "protocol", realm: "realm", authenticationMethod: "myMethod" + ) + let value = try? api.pigeonDelegate.authenticationMethod( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.authenticationMethod) + } + +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLRequestProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLRequestProxyAPITests.swift new file mode 100644 index 000000000000..66c4782d7340 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/URLRequestProxyAPITests.swift @@ -0,0 +1,108 @@ +// 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. + +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +class RequestProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api, url: "myString") + XCTAssertNotNil(instance) + } + + func testGetUrl() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let value = try? api.pigeonDelegate.getUrl(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.value.url?.absoluteString) + } + + func testSetHttpMethod() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let method = "GET" + try? api.pigeonDelegate.setHttpMethod(pigeonApi: api, pigeonInstance: instance, method: method) + + XCTAssertEqual(instance.value.httpMethod, method) + } + + func testGetHttpMethod() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + + let method = "POST" + instance.value.httpMethod = method + let value = try? api.pigeonDelegate.getHttpMethod(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, method) + } + + func testSetHttpBody() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let body = FlutterStandardTypedData(bytes: Data()) + try? api.pigeonDelegate.setHttpBody(pigeonApi: api, pigeonInstance: instance, body: body) + + XCTAssertEqual(instance.value.httpBody, body.data) + } + + func testGetHttpBody() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let body = FlutterStandardTypedData(bytes: Data()) + instance.value.httpBody = body.data + let value = try? api.pigeonDelegate.getHttpBody(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value?.data, body.data) + } + + func testSetAllHttpHeaderFields() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let fields = ["key": "value"] + try? api.pigeonDelegate.setAllHttpHeaderFields( + pigeonApi: api, pigeonInstance: instance, fields: fields) + + XCTAssertEqual(instance.value.allHTTPHeaderFields, fields) + } + + func testGetAllHttpHeaderFields() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiURLRequest(registrar) + + let instance = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + let fields = ["key": "value"] + instance.value.allHTTPHeaderFields = fields + + let value = try? api.pigeonDelegate.getAllHttpHeaderFields( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, fields) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserContentControllerProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserContentControllerProxyAPITests.swift new file mode 100644 index 000000000000..5da00684e125 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserContentControllerProxyAPITests.swift @@ -0,0 +1,97 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class UserContentControllerProxyAPITests: XCTestCase { + @MainActor func testAddScriptMessageHandler() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserContentController(registrar) + + let instance = TestUserContentController() + let handler = ScriptMessageHandlerImpl( + api: registrar.apiDelegate.pigeonApiWKScriptMessageHandler(registrar), registrar: registrar) + let name = "myString" + try? api.pigeonDelegate.addScriptMessageHandler( + pigeonApi: api, pigeonInstance: instance, handler: handler, name: name) + + XCTAssertEqual(instance.addScriptMessageHandlerArgs, [handler, name]) + } + + @MainActor func testRemoveScriptMessageHandler() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserContentController(registrar) + + let instance = TestUserContentController() + let name = "myString" + try? api.pigeonDelegate.removeScriptMessageHandler( + pigeonApi: api, pigeonInstance: instance, name: name) + + XCTAssertEqual(instance.removeScriptMessageHandlerArgs, [name]) + } + + @MainActor func testRemoveAllScriptMessageHandlers() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserContentController(registrar) + + let instance = TestUserContentController() + try? api.pigeonDelegate.removeAllScriptMessageHandlers(pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.removeAllScriptMessageHandlersCalled) + } + + @MainActor func testAddUserScript() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserContentController(registrar) + + let instance = TestUserContentController() + let userScript = WKUserScript(source: "", injectionTime: .atDocumentEnd, forMainFrameOnly: true) + try? api.pigeonDelegate.addUserScript( + pigeonApi: api, pigeonInstance: instance, userScript: userScript) + + XCTAssertEqual(instance.addUserScriptArgs, [userScript]) + } + + @MainActor func testRemoveAllUserScripts() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserContentController(registrar) + + let instance = TestUserContentController() + try? api.pigeonDelegate.removeAllUserScripts(pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.removeAllUserScriptsCalled) + } + +} + +class TestUserContentController: WKUserContentController { + var addScriptMessageHandlerArgs: [AnyHashable?]? = nil + var removeScriptMessageHandlerArgs: [AnyHashable?]? = nil + var removeAllScriptMessageHandlersCalled = false + var addUserScriptArgs: [AnyHashable?]? = nil + var removeAllUserScriptsCalled = false + + override func add(_ scriptMessageHandler: WKScriptMessageHandler, name: String) { + addScriptMessageHandlerArgs = [scriptMessageHandler as! NSObject, name] + } + + override func removeScriptMessageHandler(forName name: String) { + removeScriptMessageHandlerArgs = [name] + } + + override func removeAllScriptMessageHandlers() { + removeAllScriptMessageHandlersCalled = true + } + + override func addUserScript(_ userScript: WKUserScript) { + addUserScriptArgs = [userScript] + } + + override func removeAllUserScripts() { + removeAllUserScriptsCalled = true + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserScriptProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserScriptProxyAPITests.swift new file mode 100644 index 000000000000..b9fbeebd9ded --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/UserScriptProxyAPITests.swift @@ -0,0 +1,52 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class UserScriptProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserScript(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, source: "myString", injectionTime: .atDocumentStart, isForMainFrameOnly: true) + XCTAssertNotNil(instance) + } + + @MainActor func testSource() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserScript(registrar) + + let instance = WKUserScript( + source: "source", injectionTime: .atDocumentEnd, forMainFrameOnly: false) + let value = try? api.pigeonDelegate.source(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.source) + } + + @MainActor func testInjectionTime() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserScript(registrar) + + let instance = WKUserScript( + source: "source", injectionTime: .atDocumentEnd, forMainFrameOnly: false) + let value = try? api.pigeonDelegate.injectionTime(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, .atDocumentEnd) + } + + @MainActor func testIsMainFrameOnly() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKUserScript(registrar) + + let instance = WKUserScript( + source: "source", injectionTime: .atDocumentEnd, forMainFrameOnly: false) + let value = try? api.pigeonDelegate.isForMainFrameOnly(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.isForMainFrameOnly) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewConfigurationProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewConfigurationProxyAPITests.swift new file mode 100644 index 000000000000..92a0695b0957 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewConfigurationProxyAPITests.swift @@ -0,0 +1,127 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class WebViewConfigurationProxyAPITests: XCTestCase { + func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) + XCTAssertNotNil(instance) + } + + @MainActor func testSetUserContentController() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let controller = WKUserContentController() + try? api.pigeonDelegate.setUserContentController( + pigeonApi: api, pigeonInstance: instance, controller: controller) + + XCTAssertEqual(instance.userContentController, controller) + } + + @MainActor func testGetUserContentController() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let value = try? api.pigeonDelegate.getUserContentController( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.userContentController) + } + + @available(iOS 17.0, *) + @MainActor func testSetWebsiteDataStore() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let dataStore = WKWebsiteDataStore(forIdentifier: UUID()) + try? api.pigeonDelegate.setWebsiteDataStore( + pigeonApi: api, pigeonInstance: instance, dataStore: dataStore) + + XCTAssertEqual(instance.websiteDataStore, dataStore) + } + + @MainActor func testGetWebsiteDataStore() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let value = try? api.pigeonDelegate.getWebsiteDataStore( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.websiteDataStore) + } + + @MainActor func testSetPreferences() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let preferences = WKPreferences() + try? api.pigeonDelegate.setPreferences( + pigeonApi: api, pigeonInstance: instance, preferences: preferences) + + XCTAssertEqual(instance.preferences, preferences) + } + + @MainActor func testGetPreferences() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let value = try? api.pigeonDelegate.getPreferences(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.preferences) + } + + @MainActor func testSetAllowsInlineMediaPlayback() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let allow = true + try? api.pigeonDelegate.setAllowsInlineMediaPlayback( + pigeonApi: api, pigeonInstance: instance, allow: allow) + + // setAllowsInlineMediaPlayback does not existing on macOS; the call above should no-op for macOS. + #if !os(macOS) + XCTAssertEqual(instance.allowsInlineMediaPlayback, allow) + #endif + } + + @available(iOS 14.0, *) + @MainActor func testSetLimitsNavigationsToAppBoundDomains() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let limit = true + try? api.pigeonDelegate.setLimitsNavigationsToAppBoundDomains( + pigeonApi: api, pigeonInstance: instance, limit: limit) + + XCTAssertEqual(instance.limitsNavigationsToAppBoundDomains, limit) + } + + @MainActor func testSetMediaTypesRequiringUserActionForPlayback() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebViewConfiguration(registrar) + + let instance = WKWebViewConfiguration() + let type: AudiovisualMediaType = .none + try? api.pigeonDelegate.setMediaTypesRequiringUserActionForPlayback( + pigeonApi: api, pigeonInstance: instance, type: type) + + XCTAssertEqual(instance.mediaTypesRequiringUserActionForPlayback, []) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewProxyAPITests.swift new file mode 100644 index 000000000000..86c9fb0e852f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebViewProxyAPITests.swift @@ -0,0 +1,471 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import UIKit +#endif + +class WebViewProxyAPITests: XCTestCase { + @MainActor func testPigeonDefaultConstructor() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( + pigeonApi: api, initialConfiguration: WKWebViewConfiguration()) + XCTAssertNotNil(instance) + } + + @MainActor func testConfiguration() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.configuration(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.configuration) + } + + #if os(iOS) + @MainActor func testScrollView() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.scrollView(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.scrollView) + } + #endif + + @MainActor func testSetUIDelegate() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let delegate = UIDelegateImpl( + api: registrar.apiDelegate.pigeonApiWKUIDelegate(registrar), registrar: registrar) + try? api.pigeonDelegate.setUIDelegate( + pigeonApi: api, pigeonInstance: instance, delegate: delegate) + + XCTAssertEqual(instance.uiDelegate as! UIDelegateImpl, delegate) + } + + @MainActor func testSetNavigationDelegate() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let delegate = NavigationDelegateImpl( + api: registrar.apiDelegate.pigeonApiWKNavigationDelegate(registrar), registrar: registrar) + try? api.pigeonDelegate.setNavigationDelegate( + pigeonApi: api, pigeonInstance: instance, delegate: delegate) + + XCTAssertEqual(instance.navigationDelegate as! NavigationDelegateImpl, delegate) + } + + @MainActor func testGetUrl() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.getUrl(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.url?.absoluteString) + } + + @MainActor func testGetEstimatedProgress() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.getEstimatedProgress( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.estimatedProgress) + } + + @MainActor func testLoad() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let request = URLRequestWrapper(URLRequest(url: URL(string: "http://google.com")!)) + try? api.pigeonDelegate.load(pigeonApi: api, pigeonInstance: instance, request: request) + + XCTAssertEqual(instance.loadArgs, [request.value]) + } + + @MainActor func testLoadHtmlString() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let string = "myString" + let baseUrl = "http://google.com" + try? api.pigeonDelegate.loadHtmlString( + pigeonApi: api, pigeonInstance: instance, string: string, baseUrl: baseUrl) + + XCTAssertEqual(instance.loadHtmlStringArgs, [string, URL(string: baseUrl)]) + } + + @MainActor func testLoadFileUrl() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let url = "myDirectory/myFile.txt" + let readAccessUrl = "myDirectory/" + try? api.pigeonDelegate.loadFileUrl( + pigeonApi: api, pigeonInstance: instance, url: url, readAccessUrl: readAccessUrl) + + XCTAssertEqual( + instance.loadFileUrlArgs, + [ + URL(fileURLWithPath: url, isDirectory: false), + URL(fileURLWithPath: readAccessUrl, isDirectory: true), + ]) + } + + @MainActor func testLoadFlutterAsset() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let key = "assets/www/index.html" + try? api.pigeonDelegate.loadFlutterAsset(pigeonApi: api, pigeonInstance: instance, key: key) + + XCTAssertEqual(instance.loadFileUrlArgs?.count, 2) + let url = try! XCTUnwrap(instance.loadFileUrlArgs![0]) + let readAccessURL = try! XCTUnwrap(instance.loadFileUrlArgs![1]) + + XCTAssertTrue(url.absoluteString.contains("index.html")) + XCTAssertTrue(readAccessURL.absoluteString.contains("assets/www/")) + } + + @MainActor func testCanGoBack() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.canGoBack(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.canGoBack) + } + + @MainActor func testCanGoForward() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.canGoForward(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.canGoForward) + } + + @MainActor func testGoBack() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + try? api.pigeonDelegate.goBack(pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.goBackCalled) + } + + @MainActor func testGoForward() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + try? api.pigeonDelegate.goForward(pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.goForwardCalled) + } + + @MainActor func testReload() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + try? api.pigeonDelegate.reload(pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.reloadCalled) + } + + @MainActor func testGetTitle() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.getTitle(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.title) + } + + @MainActor func testSetAllowsBackForwardNavigationGestures() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let allow = true + try? api.pigeonDelegate.setAllowsBackForwardNavigationGestures( + pigeonApi: api, pigeonInstance: instance, allow: allow) + + XCTAssertEqual(instance.setAllowsBackForwardNavigationGesturesArgs, [allow]) + } + + @MainActor func testSetCustomUserAgent() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let userAgent = "myString" + try? api.pigeonDelegate.setCustomUserAgent( + pigeonApi: api, pigeonInstance: instance, userAgent: userAgent) + + XCTAssertEqual(instance.setCustomUserAgentArgs, [userAgent]) + } + + @MainActor func testEvaluateJavaScript() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let javaScriptString = "myString" + + var resultValue: Any? + api.pigeonDelegate.evaluateJavaScript( + pigeonApi: api, pigeonInstance: instance, javaScriptString: javaScriptString, + completion: { result in + switch result { + case .success(let value): + resultValue = value + case .failure(_): + break + } + }) + + XCTAssertEqual(instance.evaluateJavaScriptArgs, [javaScriptString]) + XCTAssertEqual(resultValue as! String, "returnValue") + } + + @MainActor func testSetInspectable() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let inspectable = true + try? api.pigeonDelegate.setInspectable( + pigeonApi: api, pigeonInstance: instance, inspectable: inspectable) + + XCTAssertEqual(instance.setInspectableArgs, [inspectable]) + XCTAssertFalse(instance.isInspectable) + } + + @MainActor func testGetCustomUserAgent() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiUIViewWKWebView(registrar) + + let instance = TestViewWKWebView() + let value = try? api.pigeonDelegate.getCustomUserAgent(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.customUserAgent) + } + + #if os(iOS) + @MainActor func testWebViewContentInsetBehaviorShouldBeNever() { + let registrar = TestProxyApiRegistrar() + let api = PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + + let webView = WebViewImpl( + api: api, registrar: registrar, frame: .zero, configuration: WKWebViewConfiguration()) + + XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior, .never) + } + + @available(iOS 13.0, *) + @MainActor + func testScrollViewsAutomaticallyAdjustsScrollIndicatorInsetsShouldbeFalse() { + let registrar = TestProxyApiRegistrar() + let api = PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + + let webView = WebViewImpl( + api: api, registrar: registrar, frame: .zero, configuration: WKWebViewConfiguration()) + + XCTAssertFalse(webView.scrollView.automaticallyAdjustsScrollIndicatorInsets) + } + + @MainActor func testContentInsetsSumAlwaysZeroAfterSetFrame() { + let registrar = TestProxyApiRegistrar() + let api = PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + + let webView = WebViewImpl( + api: api, registrar: registrar, frame: .zero, configuration: WKWebViewConfiguration()) + + webView.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 300, right: 300) + + webView.frame = .zero + XCTAssertEqual(webView.scrollView.contentInset, .zero) + } + + @MainActor func testContentInsetsIsOppositeOfScrollViewAdjustedInset() { + let registrar = TestProxyApiRegistrar() + let api = PigeonApiWKWebView(pigeonRegistrar: registrar, delegate: WebViewProxyAPIDelegate()) + + let webView = WebViewImpl( + api: api, registrar: registrar, frame: .zero, configuration: WKWebViewConfiguration()) + + webView.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 300, right: 300) + + webView.frame = .zero + let contentInset: UIEdgeInsets = webView.scrollView.contentInset + XCTAssertEqual(contentInset.left, -webView.scrollView.adjustedContentInset.left) + XCTAssertEqual(contentInset.top, -webView.scrollView.adjustedContentInset.top) + XCTAssertEqual(contentInset.right, -webView.scrollView.adjustedContentInset.right) + XCTAssertEqual(contentInset.bottom, -webView.scrollView.adjustedContentInset.bottom) + } + #endif +} + +@MainActor +class TestViewWKWebView: WKWebView { + private var configurationTestValue = WKWebViewConfiguration() + #if os(iOS) + private var scrollViewTestValue = TestAdjustedScrollView(frame: .zero) + #endif + var getUrlCalled = false + var getEstimatedProgressCalled = false + var loadArgs: [AnyHashable?]? = nil + var loadHtmlStringArgs: [AnyHashable?]? = nil + var loadFileUrlArgs: [URL]? = nil + var canGoBackCalled = false + var canGoForwardCalled = false + var goBackCalled = false + var goForwardCalled = false + var reloadCalled = false + var getTitleCalled = false + var setAllowsBackForwardNavigationGesturesArgs: [AnyHashable?]? = nil + var setCustomUserAgentArgs: [AnyHashable?]? = nil + var evaluateJavaScriptArgs: [AnyHashable?]? = nil + var setInspectableArgs: [AnyHashable?]? = nil + var getCustomUserAgentCalled = false + + override var configuration: WKWebViewConfiguration { + return configurationTestValue + } + + #if os(iOS) + override var scrollView: UIScrollView { + return scrollViewTestValue + } + #endif + + override var url: URL? { + return URL(string: "http://google.com") + } + + override var estimatedProgress: Double { + return 2.0 + } + + override func load(_ request: URLRequest) -> WKNavigation? { + loadArgs = [request] + return nil + } + + override func loadHTMLString(_ string: String, baseURL: URL?) -> WKNavigation? { + loadHtmlStringArgs = [string, baseURL] + return nil + } + + override func loadFileURL(_ url: URL, allowingReadAccessTo readAccessURL: URL) -> WKNavigation? { + loadFileUrlArgs = [url, readAccessURL] + return nil + } + + override var canGoBack: Bool { + return false + } + + override var canGoForward: Bool { + return true + } + + override func goBack() -> WKNavigation? { + goBackCalled = true + return nil + } + + override func goForward() -> WKNavigation? { + goForwardCalled = true + return nil + } + + override func reload() -> WKNavigation? { + reloadCalled = true + return nil + } + + override var title: String? { + return "title" + } + + override var allowsBackForwardNavigationGestures: Bool { + set { + setAllowsBackForwardNavigationGesturesArgs = [newValue] + } + get { + return true + } + } + + override var customUserAgent: String? { + set { + setCustomUserAgentArgs = [newValue] + } + get { + return "myUserAgent" + } + } + + #if compiler(>=6.0) + public override func evaluateJavaScript( + _ javaScriptString: String, + completionHandler: (@MainActor @Sendable (Any?, (Error)?) -> Void)? = nil + ) { + evaluateJavaScriptArgs = [javaScriptString] + completionHandler?("returnValue", nil) + } + #else + public override func evaluateJavaScript( + _ javaScriptString: String, completionHandler: ((Any?, Error?) -> Void)? = nil + ) { + evaluateJavaScriptArgs = [javaScriptString] + completionHandler?("returnValue", nil) + } + #endif + + override var isInspectable: Bool { + set { + setInspectableArgs = [newValue] + } + get { + return false + } + } +} + +#if os(iOS) + @MainActor + class TestAdjustedScrollView: UIScrollView { + override var adjustedContentInset: UIEdgeInsets { + return UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40) + } + } +#endif diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebsiteDataStoreProxyAPITests.swift b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebsiteDataStoreProxyAPITests.swift new file mode 100644 index 000000000000..66459339c31c --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/WebsiteDataStoreProxyAPITests.swift @@ -0,0 +1,51 @@ +// 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. + +import WebKit +import XCTest + +@testable import webview_flutter_wkwebview + +class WebsiteDataStoreProxyAPITests: XCTestCase { + @available(iOS 17.0, *) + @MainActor func testHttpCookieStore() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebsiteDataStore(registrar) + + let instance = WKWebsiteDataStore.default() + let value = try? api.pigeonDelegate.httpCookieStore(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.httpCookieStore) + } + + @available(iOS 17.0, *) + @MainActor func testRemoveDataOfTypes() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiWKWebsiteDataStore(registrar) + + let instance = WKWebsiteDataStore.default() + let dataTypes: [WebsiteDataType] = [.localStorage] + let modificationTimeInSecondsSinceEpoch = 0.0 + + let removeDataOfTypesExpectation = expectation( + description: "Wait for result of removeDataOfTypes.") + + var removeDataOfTypesResult: Bool? + api.pigeonDelegate.removeDataOfTypes( + pigeonApi: api, pigeonInstance: instance, dataTypes: dataTypes, + modificationTimeInSecondsSinceEpoch: modificationTimeInSecondsSinceEpoch, + completion: { result in + switch result { + case .success(let hasRecords): + removeDataOfTypesResult = hasRecords + case .failure(_): break + } + + removeDataOfTypesExpectation.fulfill() + }) + + wait(for: [removeDataOfTypesExpectation], timeout: 10.0) + XCTAssertNotNil(removeDataOfTypesResult) + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/lib/main.dart b/packages/webview_flutter/webview_flutter_wkwebview/example/lib/main.dart index 2d23fe0386de..3bd0a5382ac8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/lib/main.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/lib/main.dart @@ -216,10 +216,7 @@ Page resource error: ); request.grant(); }, - ) - ..loadRequest(LoadRequestParams( - uri: Uri.parse('https://flutter.dev'), - )); + ); // setBackgroundColor and setOnScrollPositionChange are not supported on // macOS. @@ -328,6 +325,7 @@ Page resource error: } enum MenuOptions { + loadFlutterDev, showUserAgent, listCookies, clearCookies, @@ -365,6 +363,8 @@ class SampleMenu extends StatelessWidget { key: const ValueKey('ShowPopupMenu'), onSelected: (MenuOptions value) { switch (value) { + case MenuOptions.loadFlutterDev: + _loadFlutterDev(); case MenuOptions.showUserAgent: _onShowUserAgent(); case MenuOptions.listCookies: @@ -400,6 +400,10 @@ class SampleMenu extends StatelessWidget { } }, itemBuilder: (BuildContext context) => >[ + const PopupMenuItem( + value: MenuOptions.loadFlutterDev, + child: Text('Load flutter.dev'), + ), const PopupMenuItem( value: MenuOptions.showUserAgent, child: Text('Show user agent'), @@ -469,6 +473,12 @@ class SampleMenu extends StatelessWidget { ); } + Future _loadFlutterDev() { + return webViewController.loadRequest(LoadRequestParams( + uri: Uri.parse('https://flutter.dev'), + )); + } + Future _onShowUserAgent() { // Send a message with the user agent string to the Toaster JavaScript channel we registered // with the WebView. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/macos/Runner.xcodeproj/project.pbxproj b/packages/webview_flutter/webview_flutter_wkwebview/example/macos/Runner.xcodeproj/project.pbxproj index a0c219d687d5..7600fdbc199f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/macos/Runner.xcodeproj/project.pbxproj @@ -27,30 +27,9 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; - 33CF716F2C090A5900FB3AA4 /* FWFURLProtectionSpaceHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715A2C090A5800FB3AA4 /* FWFURLProtectionSpaceHostApiTests.m */; }; - 33CF71702C090A5900FB3AA4 /* FWFUIDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715B2C090A5800FB3AA4 /* FWFUIDelegateHostApiTests.m */; }; - 33CF71712C090A5900FB3AA4 /* FWFErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715C2C090A5800FB3AA4 /* FWFErrorTests.m */; }; - 33CF71722C090A5900FB3AA4 /* FWFUIViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715D2C090A5800FB3AA4 /* FWFUIViewHostApiTests.m */; }; - 33CF71732C090A5900FB3AA4 /* FWFDataConvertersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715E2C090A5800FB3AA4 /* FWFDataConvertersTests.m */; }; - 33CF71742C090A5900FB3AA4 /* FWFURLCredentialHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF715F2C090A5800FB3AA4 /* FWFURLCredentialHostApiTests.m */; }; - 33CF71752C090A5900FB3AA4 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71602C090A5800FB3AA4 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */; }; - 33CF71762C090A5900FB3AA4 /* FWFPreferencesHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71612C090A5800FB3AA4 /* FWFPreferencesHostApiTests.m */; }; - 33CF71772C090A5900FB3AA4 /* FWFWebViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71622C090A5800FB3AA4 /* FWFWebViewHostApiTests.m */; }; - 33CF71782C090A5900FB3AA4 /* FWFScrollViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71632C090A5800FB3AA4 /* FWFScrollViewHostApiTests.m */; }; - 33CF71792C090A5900FB3AA4 /* FWFInstanceManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71642C090A5800FB3AA4 /* FWFInstanceManagerTests.m */; }; - 33CF717A2C090A5900FB3AA4 /* FWFScrollViewDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71652C090A5800FB3AA4 /* FWFScrollViewDelegateHostApiTests.m */; }; - 33CF717B2C090A5900FB3AA4 /* FWFUserContentControllerHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71662C090A5800FB3AA4 /* FWFUserContentControllerHostApiTests.m */; }; - 33CF717C2C090A5900FB3AA4 /* FWFScriptMessageHandlerHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71672C090A5800FB3AA4 /* FWFScriptMessageHandlerHostApiTests.m */; }; - 33CF717D2C090A5900FB3AA4 /* FWFURLAuthenticationChallengeHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71682C090A5800FB3AA4 /* FWFURLAuthenticationChallengeHostApiTests.m */; }; - 33CF717E2C090A5900FB3AA4 /* FWFURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF71692C090A5800FB3AA4 /* FWFURLTests.m */; }; - 33CF717F2C090A5900FB3AA4 /* FWFWebViewConfigurationHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF716A2C090A5900FB3AA4 /* FWFWebViewConfigurationHostApiTests.m */; }; - 33CF71802C090A5900FB3AA4 /* FWFWebsiteDataStoreHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF716B2C090A5900FB3AA4 /* FWFWebsiteDataStoreHostApiTests.m */; }; - 33CF71812C090A5900FB3AA4 /* FWFHTTPCookieStoreHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF716C2C090A5900FB3AA4 /* FWFHTTPCookieStoreHostApiTests.m */; }; - 33CF71822C090A5900FB3AA4 /* FWFNavigationDelegateHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF716D2C090A5900FB3AA4 /* FWFNavigationDelegateHostApiTests.m */; }; - 33CF71832C090A5900FB3AA4 /* FWFObjectHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CF716E2C090A5900FB3AA4 /* FWFObjectHostApiTests.m */; }; - 696987BFFD9F58717569B4E4 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F0D686780FFBF662B127EB3 /* Pods_RunnerTests.framework */; }; + 6FBECA2F94D9B352000B75D7 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 418FB4EA49104BADE288A967 /* Pods_RunnerTests.framework */; }; 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; }; - 94A776FC184B2E22F5BB8688 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4396B0510D22FC1052724D77 /* Pods_Runner.framework */; }; + EC73D2F02E81CFF0A2CA5D1E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D183650EAE2ABECF7D9CBA94 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -84,9 +63,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 293218A8CB10C8BE4DB72BF6 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; - 2BB8CCF4A3B17FE9A00CF6B7 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; - 2F0D686780FFBF662B127EB3 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 02805256CB102DDACBC04AEE /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 331C80D5294CF71000263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; @@ -99,37 +76,18 @@ 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; - 33CF715A2C090A5800FB3AA4 /* FWFURLProtectionSpaceHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFURLProtectionSpaceHostApiTests.m; path = ../../darwin/Tests/FWFURLProtectionSpaceHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF715B2C090A5800FB3AA4 /* FWFUIDelegateHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFUIDelegateHostApiTests.m; path = ../../darwin/Tests/FWFUIDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF715C2C090A5800FB3AA4 /* FWFErrorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFErrorTests.m; path = ../../darwin/Tests/FWFErrorTests.m; sourceTree = SOURCE_ROOT; }; - 33CF715D2C090A5800FB3AA4 /* FWFUIViewHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFUIViewHostApiTests.m; path = ../../darwin/Tests/FWFUIViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF715E2C090A5800FB3AA4 /* FWFDataConvertersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFDataConvertersTests.m; path = ../../darwin/Tests/FWFDataConvertersTests.m; sourceTree = SOURCE_ROOT; }; - 33CF715F2C090A5800FB3AA4 /* FWFURLCredentialHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFURLCredentialHostApiTests.m; path = ../../darwin/Tests/FWFURLCredentialHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71602C090A5800FB3AA4 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewFlutterWKWebViewExternalAPITests.m; path = ../../darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.m; sourceTree = SOURCE_ROOT; }; - 33CF71612C090A5800FB3AA4 /* FWFPreferencesHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFPreferencesHostApiTests.m; path = ../../darwin/Tests/FWFPreferencesHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71622C090A5800FB3AA4 /* FWFWebViewHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewHostApiTests.m; path = ../../darwin/Tests/FWFWebViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71632C090A5800FB3AA4 /* FWFScrollViewHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFScrollViewHostApiTests.m; path = ../../darwin/Tests/FWFScrollViewHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71642C090A5800FB3AA4 /* FWFInstanceManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFInstanceManagerTests.m; path = ../../darwin/Tests/FWFInstanceManagerTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71652C090A5800FB3AA4 /* FWFScrollViewDelegateHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFScrollViewDelegateHostApiTests.m; path = ../../darwin/Tests/FWFScrollViewDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71662C090A5800FB3AA4 /* FWFUserContentControllerHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFUserContentControllerHostApiTests.m; path = ../../darwin/Tests/FWFUserContentControllerHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71672C090A5800FB3AA4 /* FWFScriptMessageHandlerHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFScriptMessageHandlerHostApiTests.m; path = ../../darwin/Tests/FWFScriptMessageHandlerHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71682C090A5800FB3AA4 /* FWFURLAuthenticationChallengeHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFURLAuthenticationChallengeHostApiTests.m; path = ../../darwin/Tests/FWFURLAuthenticationChallengeHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF71692C090A5800FB3AA4 /* FWFURLTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFURLTests.m; path = ../../darwin/Tests/FWFURLTests.m; sourceTree = SOURCE_ROOT; }; - 33CF716A2C090A5900FB3AA4 /* FWFWebViewConfigurationHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFWebViewConfigurationHostApiTests.m; path = ../../darwin/Tests/FWFWebViewConfigurationHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF716B2C090A5900FB3AA4 /* FWFWebsiteDataStoreHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFWebsiteDataStoreHostApiTests.m; path = ../../darwin/Tests/FWFWebsiteDataStoreHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF716C2C090A5900FB3AA4 /* FWFHTTPCookieStoreHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFHTTPCookieStoreHostApiTests.m; path = ../../darwin/Tests/FWFHTTPCookieStoreHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF716D2C090A5900FB3AA4 /* FWFNavigationDelegateHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFNavigationDelegateHostApiTests.m; path = ../../darwin/Tests/FWFNavigationDelegateHostApiTests.m; sourceTree = SOURCE_ROOT; }; - 33CF716E2C090A5900FB3AA4 /* FWFObjectHostApiTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FWFObjectHostApiTests.m; path = ../../darwin/Tests/FWFObjectHostApiTests.m; sourceTree = SOURCE_ROOT; }; 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; - 4396B0510D22FC1052724D77 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 7A8789C38AC8A7893DF1757D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + 418FB4EA49104BADE288A967 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 69E635CFAEEB8242654D4BBC /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; - 8E3B7819B86A3E8D5B2787F8 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; + 7D83F970E1160B09690C7723 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; - B29CEB47BBE7D438B12895F3 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; - BB0A609D94A71B55CFCFC007 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; + ADCB9E0C172AE7D0FAEDBF42 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + B8188FDAD7773BAC85CB6DE9 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; + D183650EAE2ABECF7D9CBA94 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D63AEC83B24957EBEB3AA850 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -138,7 +96,7 @@ buildActionMask = 2147483647; files = ( 337257E82C626C94005E6518 /* OCMock in Frameworks */, - 696987BFFD9F58717569B4E4 /* Pods_RunnerTests.framework in Frameworks */, + 6FBECA2F94D9B352000B75D7 /* Pods_RunnerTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -147,7 +105,7 @@ buildActionMask = 2147483647; files = ( 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */, - 94A776FC184B2E22F5BB8688 /* Pods_Runner.framework in Frameworks */, + EC73D2F02E81CFF0A2CA5D1E /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -157,27 +115,6 @@ 331C80D6294CF71000263BE5 /* RunnerTests */ = { isa = PBXGroup; children = ( - 33CF715E2C090A5800FB3AA4 /* FWFDataConvertersTests.m */, - 33CF715C2C090A5800FB3AA4 /* FWFErrorTests.m */, - 33CF716C2C090A5900FB3AA4 /* FWFHTTPCookieStoreHostApiTests.m */, - 33CF71642C090A5800FB3AA4 /* FWFInstanceManagerTests.m */, - 33CF716D2C090A5900FB3AA4 /* FWFNavigationDelegateHostApiTests.m */, - 33CF716E2C090A5900FB3AA4 /* FWFObjectHostApiTests.m */, - 33CF71612C090A5800FB3AA4 /* FWFPreferencesHostApiTests.m */, - 33CF71672C090A5800FB3AA4 /* FWFScriptMessageHandlerHostApiTests.m */, - 33CF71652C090A5800FB3AA4 /* FWFScrollViewDelegateHostApiTests.m */, - 33CF71632C090A5800FB3AA4 /* FWFScrollViewHostApiTests.m */, - 33CF715B2C090A5800FB3AA4 /* FWFUIDelegateHostApiTests.m */, - 33CF715D2C090A5800FB3AA4 /* FWFUIViewHostApiTests.m */, - 33CF71682C090A5800FB3AA4 /* FWFURLAuthenticationChallengeHostApiTests.m */, - 33CF715F2C090A5800FB3AA4 /* FWFURLCredentialHostApiTests.m */, - 33CF715A2C090A5800FB3AA4 /* FWFURLProtectionSpaceHostApiTests.m */, - 33CF71692C090A5800FB3AA4 /* FWFURLTests.m */, - 33CF71662C090A5800FB3AA4 /* FWFUserContentControllerHostApiTests.m */, - 33CF716B2C090A5900FB3AA4 /* FWFWebsiteDataStoreHostApiTests.m */, - 33CF716A2C090A5900FB3AA4 /* FWFWebViewConfigurationHostApiTests.m */, - 33CF71602C090A5800FB3AA4 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */, - 33CF71622C090A5800FB3AA4 /* FWFWebViewHostApiTests.m */, ); path = RunnerTests; sourceTree = ""; @@ -200,8 +137,8 @@ 33CEB47122A05771004F2AC0 /* Flutter */, 331C80D6294CF71000263BE5 /* RunnerTests */, 33CC10EE2044A3C60003C045 /* Products */, - D73912EC22F37F3D000D13A0 /* Frameworks */, 57E0600E4AC0FCC05F33A596 /* Pods */, + DEE7D4409B558EFC0D7C2BDC /* Frameworks */, ); sourceTree = ""; }; @@ -252,21 +189,21 @@ 57E0600E4AC0FCC05F33A596 /* Pods */ = { isa = PBXGroup; children = ( - 7A8789C38AC8A7893DF1757D /* Pods-Runner.debug.xcconfig */, - 293218A8CB10C8BE4DB72BF6 /* Pods-Runner.release.xcconfig */, - 2BB8CCF4A3B17FE9A00CF6B7 /* Pods-Runner.profile.xcconfig */, - BB0A609D94A71B55CFCFC007 /* Pods-RunnerTests.debug.xcconfig */, - 8E3B7819B86A3E8D5B2787F8 /* Pods-RunnerTests.release.xcconfig */, - B29CEB47BBE7D438B12895F3 /* Pods-RunnerTests.profile.xcconfig */, + 02805256CB102DDACBC04AEE /* Pods-Runner.debug.xcconfig */, + D63AEC83B24957EBEB3AA850 /* Pods-Runner.release.xcconfig */, + ADCB9E0C172AE7D0FAEDBF42 /* Pods-Runner.profile.xcconfig */, + 69E635CFAEEB8242654D4BBC /* Pods-RunnerTests.debug.xcconfig */, + 7D83F970E1160B09690C7723 /* Pods-RunnerTests.release.xcconfig */, + B8188FDAD7773BAC85CB6DE9 /* Pods-RunnerTests.profile.xcconfig */, ); path = Pods; sourceTree = ""; }; - D73912EC22F37F3D000D13A0 /* Frameworks */ = { + DEE7D4409B558EFC0D7C2BDC /* Frameworks */ = { isa = PBXGroup; children = ( - 4396B0510D22FC1052724D77 /* Pods_Runner.framework */, - 2F0D686780FFBF662B127EB3 /* Pods_RunnerTests.framework */, + D183650EAE2ABECF7D9CBA94 /* Pods_Runner.framework */, + 418FB4EA49104BADE288A967 /* Pods_RunnerTests.framework */, ); name = Frameworks; sourceTree = ""; @@ -278,7 +215,7 @@ isa = PBXNativeTarget; buildConfigurationList = 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( - 5B369AB3CC6C4456A15F9A02 /* [CP] Check Pods Manifest.lock */, + 05D7642BA03EFE4FAEF7BAB1 /* [CP] Check Pods Manifest.lock */, 331C80D1294CF70F00263BE5 /* Sources */, 331C80D2294CF70F00263BE5 /* Frameworks */, 331C80D3294CF70F00263BE5 /* Resources */, @@ -300,7 +237,7 @@ isa = PBXNativeTarget; buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 52BDF375441D3D4ACF9978EC /* [CP] Check Pods Manifest.lock */, + 4D1FE18AFCDA46E722527658 /* [CP] Check Pods Manifest.lock */, 33CC10E92044A3C60003C045 /* Sources */, 33CC10EA2044A3C60003C045 /* Frameworks */, 33CC10EB2044A3C60003C045 /* Resources */, @@ -361,7 +298,7 @@ ); mainGroup = 33CC10E42044A3C60003C045; packageReferences = ( - 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */, + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */, 337257E62C626C94005E6518 /* XCRemoteSwiftPackageReference "ocmock" */, ); productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; @@ -395,67 +332,67 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 3399D490228B24CF009A79C7 /* ShellScript */ = { + 05D7642BA03EFE4FAEF7BAB1 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( ); outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; }; - 33CC111E2044C6BF0003C045 /* ShellScript */ = { + 3399D490228B24CF009A79C7 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - Flutter/ephemeral/FlutterInputs.xcfilelist, ); inputPaths = ( - Flutter/ephemeral/tripwire, ); outputFileListPaths = ( - Flutter/ephemeral/FlutterOutputs.xcfilelist, ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; }; - 52BDF375441D3D4ACF9978EC /* [CP] Check Pods Manifest.lock */ = { + 33CC111E2044C6BF0003C045 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, ); inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", + Flutter/ephemeral/tripwire, ); - name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; }; - 5B369AB3CC6C4456A15F9A02 /* [CP] Check Pods Manifest.lock */ = { + 4D1FE18AFCDA46E722527658 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -470,7 +407,7 @@ outputFileListPaths = ( ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -484,27 +421,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 33CF71822C090A5900FB3AA4 /* FWFNavigationDelegateHostApiTests.m in Sources */, - 33CF71832C090A5900FB3AA4 /* FWFObjectHostApiTests.m in Sources */, - 33CF71762C090A5900FB3AA4 /* FWFPreferencesHostApiTests.m in Sources */, - 33CF717E2C090A5900FB3AA4 /* FWFURLTests.m in Sources */, - 33CF71702C090A5900FB3AA4 /* FWFUIDelegateHostApiTests.m in Sources */, - 33CF717C2C090A5900FB3AA4 /* FWFScriptMessageHandlerHostApiTests.m in Sources */, - 33CF716F2C090A5900FB3AA4 /* FWFURLProtectionSpaceHostApiTests.m in Sources */, - 33CF717A2C090A5900FB3AA4 /* FWFScrollViewDelegateHostApiTests.m in Sources */, - 33CF71782C090A5900FB3AA4 /* FWFScrollViewHostApiTests.m in Sources */, - 33CF71712C090A5900FB3AA4 /* FWFErrorTests.m in Sources */, - 33CF71812C090A5900FB3AA4 /* FWFHTTPCookieStoreHostApiTests.m in Sources */, - 33CF717F2C090A5900FB3AA4 /* FWFWebViewConfigurationHostApiTests.m in Sources */, - 33CF717B2C090A5900FB3AA4 /* FWFUserContentControllerHostApiTests.m in Sources */, - 33CF71802C090A5900FB3AA4 /* FWFWebsiteDataStoreHostApiTests.m in Sources */, - 33CF71752C090A5900FB3AA4 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */, - 33CF717D2C090A5900FB3AA4 /* FWFURLAuthenticationChallengeHostApiTests.m in Sources */, - 33CF71772C090A5900FB3AA4 /* FWFWebViewHostApiTests.m in Sources */, - 33CF71742C090A5900FB3AA4 /* FWFURLCredentialHostApiTests.m in Sources */, - 33CF71732C090A5900FB3AA4 /* FWFDataConvertersTests.m in Sources */, - 33CF71792C090A5900FB3AA4 /* FWFInstanceManagerTests.m in Sources */, - 33CF71722C090A5900FB3AA4 /* FWFUIViewHostApiTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -548,7 +464,7 @@ /* Begin XCBuildConfiguration section */ 331C80DB294CF71000263BE5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BB0A609D94A71B55CFCFC007 /* Pods-RunnerTests.debug.xcconfig */; + baseConfigurationReference = 69E635CFAEEB8242654D4BBC /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; @@ -565,7 +481,7 @@ }; 331C80DC294CF71000263BE5 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8E3B7819B86A3E8D5B2787F8 /* Pods-RunnerTests.release.xcconfig */; + baseConfigurationReference = 7D83F970E1160B09690C7723 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; @@ -581,7 +497,7 @@ }; 331C80DD294CF71000263BE5 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = B29CEB47BBE7D438B12895F3 /* Pods-RunnerTests.profile.xcconfig */; + baseConfigurationReference = B8188FDAD7773BAC85CB6DE9 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; @@ -868,7 +784,7 @@ /* End XCConfigurationList section */ /* Begin XCLocalSwiftPackageReference section */ - 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = { + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = { isa = XCLocalSwiftPackageReference; relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; }; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/instance_manager.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/instance_manager.dart deleted file mode 100644 index 3cc100aebd46..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/instance_manager.dart +++ /dev/null @@ -1,198 +0,0 @@ -// 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. - -import 'package:flutter/foundation.dart'; - -/// An immutable object that can provide functional copies of itself. -/// -/// All implementers are expected to be immutable as defined by the annotation. -@immutable -mixin Copyable { - /// Instantiates and returns a functionally identical object to oneself. - /// - /// Outside of tests, this method should only ever be called by - /// [InstanceManager]. - /// - /// Subclasses should always override their parent's implementation of this - /// method. - @protected - Copyable copy(); -} - -/// Maintains instances used to communicate with the native objects they -/// represent. -/// -/// Added instances are stored as weak references and their copies are stored -/// as strong references to maintain access to their variables and callback -/// methods. Both are stored with the same identifier. -/// -/// When a weak referenced instance becomes inaccessible, -/// [onWeakReferenceRemoved] is called with its associated identifier. -/// -/// If an instance is retrieved and has the possibility to be used, -/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference -/// is added as a weak reference with the same identifier. This prevents a -/// scenario where the weak referenced instance was released and then later -/// returned by the host platform. -class InstanceManager { - /// Constructs an [InstanceManager]. - InstanceManager({required void Function(int) onWeakReferenceRemoved}) { - this.onWeakReferenceRemoved = (int identifier) { - _weakInstances.remove(identifier); - onWeakReferenceRemoved(identifier); - }; - _finalizer = Finalizer(this.onWeakReferenceRemoved); - } - - // Identifiers are locked to a specific range to avoid collisions with objects - // created simultaneously by the host platform. - // Host uses identifiers >= 2^16 and Dart is expected to use values n where, - // 0 <= n < 2^16. - static const int _maxDartCreatedIdentifier = 65536; - - // Expando is used because it doesn't prevent its keys from becoming - // inaccessible. This allows the manager to efficiently retrieve an identifier - // of an instance without holding a strong reference to that instance. - // - // It also doesn't use `==` to search for identifiers, which would lead to an - // infinite loop when comparing an object to its copy. (i.e. which was caused - // by calling instanceManager.getIdentifier() inside of `==` while this was a - // HashMap). - final Expando _identifiers = Expando(); - final Map> _weakInstances = - >{}; - final Map _strongInstances = {}; - late final Finalizer _finalizer; - int _nextIdentifier = 0; - - /// Called when a weak referenced instance is removed by [removeWeakReference] - /// or becomes inaccessible. - late final void Function(int) onWeakReferenceRemoved; - - /// Adds a new instance that was instantiated by Dart. - /// - /// In other words, Dart wants to add a new instance that will represent - /// an object that will be instantiated on the host platform. - /// - /// Throws assertion error if the instance has already been added. - /// - /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance(Copyable instance) { - assert(getIdentifier(instance) == null); - - final int identifier = _nextUniqueIdentifier(); - _addInstanceWithIdentifier(instance, identifier); - return identifier; - } - - /// Removes the instance, if present, and call [onWeakReferenceRemoved] with - /// its identifier. - /// - /// Returns the identifier associated with the removed instance. Otherwise, - /// `null` if the instance was not found in this manager. - /// - /// This does not remove the the strong referenced instance associated with - /// [instance]. This can be done with [remove]. - int? removeWeakReference(Copyable instance) { - final int? identifier = getIdentifier(instance); - if (identifier == null) { - return null; - } - - _identifiers[instance] = null; - _finalizer.detach(instance); - onWeakReferenceRemoved(identifier); - - return identifier; - } - - /// Removes [identifier] and its associated strongly referenced instance, if - /// present, from the manager. - /// - /// Returns the strong referenced instance associated with [identifier] before - /// it was removed. Returns `null` if [identifier] was not associated with - /// any strong reference. - /// - /// This does not remove the the weak referenced instance associtated with - /// [identifier]. This can be done with [removeWeakReference]. - T? remove(int identifier) { - return _strongInstances.remove(identifier) as T?; - } - - /// Retrieves the instance associated with identifier. - /// - /// The value returned is chosen from the following order: - /// - /// 1. A weakly referenced instance associated with identifier. - /// 2. If the only instance associated with identifier is a strongly - /// referenced instance, a copy of the instance is added as a weak reference - /// with the same identifier. Returning the newly created copy. - /// 3. If no instance is associated with identifier, returns null. - /// - /// This method also expects the host `InstanceManager` to have a strong - /// reference to the instance the identifier is associated with. - T? getInstanceWithWeakReference(int identifier) { - final Copyable? weakInstance = _weakInstances[identifier]?.target; - - if (weakInstance == null) { - final Copyable? strongInstance = _strongInstances[identifier]; - if (strongInstance != null) { - final Copyable copy = strongInstance.copy(); - _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference(copy); - _finalizer.attach(copy, identifier, detach: copy); - return copy as T; - } - return strongInstance as T?; - } - - return weakInstance as T; - } - - /// Retrieves the identifier associated with instance. - int? getIdentifier(Copyable instance) { - return _identifiers[instance]; - } - - /// Adds a new instance that was instantiated by the host platform. - /// - /// In other words, the host platform wants to add a new instance that - /// represents an object on the host platform. Stored with [identifier]. - /// - /// Throws assertion error if the instance or its identifier has already been - /// added. - /// - /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance(Copyable instance, int identifier) { - assert(!containsIdentifier(identifier)); - assert(getIdentifier(instance) == null); - assert(identifier >= 0); - _addInstanceWithIdentifier(instance, identifier); - } - - void _addInstanceWithIdentifier(Copyable instance, int identifier) { - _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference(instance); - _finalizer.attach(instance, identifier, detach: instance); - - final Copyable copy = instance.copy(); - _identifiers[copy] = identifier; - _strongInstances[identifier] = copy; - } - - /// Whether this manager contains the given [identifier]. - bool containsIdentifier(int identifier) { - return _weakInstances.containsKey(identifier) || - _strongInstances.containsKey(identifier); - } - - int _nextUniqueIdentifier() { - late int identifier; - do { - identifier = _nextIdentifier; - _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; - } while (containsIdentifier(identifier)); - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/platform_webview.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/platform_webview.dart new file mode 100644 index 000000000000..7a9638ec0995 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/platform_webview.dart @@ -0,0 +1,400 @@ +// 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. + +import 'package:flutter/foundation.dart'; + +import 'web_kit.g.dart'; + +/// Platform agnostic native WebView. +/// +/// iOS and macOS reference different `WebView` implementations, so this handles +/// delegating calls to the implementation of the current platform. +class PlatformWebView { + /// Creates a [PlatformWebView]. + PlatformWebView({ + required WKWebViewConfiguration initialConfiguration, + void Function( + NSObject instance, + String? keyPath, + NSObject? object, + Map? change, + )? observeValue, + }) { + switch (defaultTargetPlatform) { + case TargetPlatform.iOS: + nativeWebView = UIViewWKWebView( + initialConfiguration: initialConfiguration, + observeValue: observeValue, + ); + case TargetPlatform.macOS: + nativeWebView = NSViewWKWebView( + initialConfiguration: initialConfiguration, + observeValue: observeValue, + ); + case _: + throw UnimplementedError('$defaultTargetPlatform is not supported.'); + } + } + + /// Creates a [PlatformWebView] with the native WebView instance. + PlatformWebView.fromNativeWebView(WKWebView webView) + : nativeWebView = webView; + + /// The underlying native WebView instance. + late final WKWebView nativeWebView; + + /// Registers the observer object to receive KVO notifications for the key + /// path relative to the object receiving this message. + Future addObserver( + NSObject observer, + String keyPath, + List options, + ) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.addObserver(observer, keyPath, options); + case NSViewWKWebView(): + return webView.addObserver(observer, keyPath, options); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + Future canGoBack() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.canGoBack(); + case NSViewWKWebView(): + return webView.canGoBack(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + Future canGoForward() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.canGoForward(); + case NSViewWKWebView(): + return webView.canGoForward(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The object that contains the configuration details for the web view. + WKWebViewConfiguration get configuration { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.configuration; + case NSViewWKWebView(): + return webView.configuration; + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Evaluates the specified JavaScript string. + Future evaluateJavaScript(String javaScriptString) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.evaluateJavaScript(javaScriptString); + case NSViewWKWebView(): + return webView.evaluateJavaScript(javaScriptString); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The custom user agent string. + Future getCustomUserAgent() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.getCustomUserAgent(); + case NSViewWKWebView(): + return webView.getCustomUserAgent(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// An estimate of what fraction of the current navigation has been loaded. + Future getEstimatedProgress() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.getEstimatedProgress(); + case NSViewWKWebView(): + return webView.getEstimatedProgress(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The page title. + Future getTitle() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.getTitle(); + case NSViewWKWebView(): + return webView.getTitle(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The URL being requested. + Future getUrl() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.getUrl(); + case NSViewWKWebView(): + return webView.getUrl(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Navigates to the back item in the back-forward list. + Future goBack() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.goBack(); + case NSViewWKWebView(): + return webView.goBack(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Navigates to the forward item in the back-forward list. + Future goForward() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.goForward(); + case NSViewWKWebView(): + return webView.goForward(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + Future load(URLRequest request) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.load(request); + case NSViewWKWebView(): + return webView.load(request); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Loads the web content from the specified file and navigates to it. + Future loadFileUrl(String url, String readAccessUrl) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.loadFileUrl(url, readAccessUrl); + case NSViewWKWebView(): + return webView.loadFileUrl(url, readAccessUrl); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Convenience method to load a Flutter asset. + Future loadFlutterAsset(String key) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.loadFlutterAsset(key); + case NSViewWKWebView(): + return webView.loadFlutterAsset(key); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Loads the contents of the specified HTML string and navigates to it. + Future loadHtmlString(String string, String? baseUrl) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.loadHtmlString(string, baseUrl); + case NSViewWKWebView(): + return webView.loadHtmlString(string, baseUrl); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Informs the observing object when the value at the specified key path + /// relative to the observed object has changed. + void Function(NSObject pigeonInstance, String? keyPath, NSObject? object, + Map? change)? get observeValue { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.observeValue; + case NSViewWKWebView(): + return webView.observeValue; + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Reloads the current webpage. + Future reload() { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.reload(); + case NSViewWKWebView(): + return webView.reload(); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// Stops the observer object from receiving change notifications for the + /// property specified by the key path relative to the object receiving this + /// message. + Future removeObserver(NSObject object, String keyPath) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.removeObserver(object, keyPath); + case NSViewWKWebView(): + return webView.removeObserver(object, keyPath); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The scroll view associated with the web view. + UIScrollView get scrollView { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.scrollView; + case NSViewWKWebView(): + throw UnimplementedError('scrollView is not implemented on macOS'); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + Future setAllowsBackForwardNavigationGestures(bool allow) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setAllowsBackForwardNavigationGestures(allow); + case NSViewWKWebView(): + return webView.setAllowsBackForwardNavigationGestures(allow); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The view’s background color. + Future setBackgroundColor(int? value) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setBackgroundColor(value); + case NSViewWKWebView(): + // TODO(stuartmorgan): Implement background color support. + throw UnimplementedError('backgroundColor is not implemented on macOS'); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The custom user agent string. + Future setCustomUserAgent(String? userAgent) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setCustomUserAgent(userAgent); + case NSViewWKWebView(): + return webView.setCustomUserAgent(userAgent); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + Future setInspectable(bool inspectable) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setInspectable(inspectable); + case NSViewWKWebView(): + return webView.setInspectable(inspectable); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The object you use to manage navigation behavior for the web view. + Future setNavigationDelegate(WKNavigationDelegate delegate) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setNavigationDelegate(delegate); + case NSViewWKWebView(): + return webView.setNavigationDelegate(delegate); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// A Boolean value that determines whether the view is opaque. + Future setOpaque(bool opaque) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setOpaque(opaque); + case NSViewWKWebView(): + throw UnimplementedError('opaque is not implemented on macOS'); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } + + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + Future setUIDelegate(WKUIDelegate delegate) { + final WKWebView webView = nativeWebView; + switch (webView) { + case UIViewWKWebView(): + return webView.setUIDelegate(delegate); + case NSViewWKWebView(): + return webView.setUIDelegate(delegate); + } + + throw UnimplementedError('${webView.runtimeType} is not supported.'); + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart index bd0ac2c02945..f96105fb67d0 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/web_kit.g.dart @@ -1,15 +1,17 @@ // 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 (v18.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.7.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; PlatformException _createConnectionError(String channelName) { return PlatformException( @@ -29,1355 +31,3356 @@ List wrapResponse( return [error.code, error.message, error.details]; } -/// Mirror of NSKeyValueObservingOptions. +/// An immutable object that serves as the base class for all ProxyApis and +/// can provide functional copies of itself. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions?language=objc. -enum NSKeyValueObservingOptionsEnum { +/// All implementers are expected to be [immutable] as defined by the annotation +/// and override [pigeon_copy] returning an instance of itself. +@immutable +abstract class PigeonInternalProxyApiBaseClass { + /// Construct a [PigeonInternalProxyApiBaseClass]. + PigeonInternalProxyApiBaseClass({ + this.pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + }) : pigeon_instanceManager = + pigeon_instanceManager ?? PigeonInstanceManager.instance; + + /// Sends and receives binary data across the Flutter platform barrier. + /// + /// If it is null, the default BinaryMessenger will be used, which routes to + /// the host platform. + @protected + final BinaryMessenger? pigeon_binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final PigeonInstanceManager pigeon_instanceManager; + + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [PigeonInstanceManager]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + PigeonInternalProxyApiBaseClass pigeon_copy(); +} + +/// Maintains instances used to communicate with the native objects they +/// represent. +/// +/// Added instances are stored as weak references and their copies are stored +/// as strong references to maintain access to their variables and callback +/// methods. Both are stored with the same identifier. +/// +/// When a weak referenced instance becomes inaccessible, +/// [onWeakReferenceRemoved] is called with its associated identifier. +/// +/// If an instance is retrieved and has the possibility to be used, +/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference +/// is added as a weak reference with the same identifier. This prevents a +/// scenario where the weak referenced instance was released and then later +/// returned by the host platform. +class PigeonInstanceManager { + /// Constructs a [PigeonInstanceManager]. + PigeonInstanceManager({required void Function(int) onWeakReferenceRemoved}) { + this.onWeakReferenceRemoved = (int identifier) { + _weakInstances.remove(identifier); + onWeakReferenceRemoved(identifier); + }; + _finalizer = Finalizer(this.onWeakReferenceRemoved); + } + + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously by the host platform. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + static const int _maxDartCreatedIdentifier = 65536; + + /// The default [PigeonInstanceManager] used by ProxyApis. + /// + /// On creation, this manager makes a call to clear the native + /// InstanceManager. This is to prevent identifier conflicts after a host + /// restart. + static final PigeonInstanceManager instance = _initInstance(); + + // Expando is used because it doesn't prevent its keys from becoming + // inaccessible. This allows the manager to efficiently retrieve an identifier + // of an instance without holding a strong reference to that instance. + // + // It also doesn't use `==` to search for identifiers, which would lead to an + // infinite loop when comparing an object to its copy. (i.e. which was caused + // by calling instanceManager.getIdentifier() inside of `==` while this was a + // HashMap). + final Expando _identifiers = Expando(); + final Map> + _weakInstances = >{}; + final Map _strongInstances = + {}; + late final Finalizer _finalizer; + int _nextIdentifier = 0; + + /// Called when a weak referenced instance is removed by [removeWeakReference] + /// or becomes inaccessible. + late final void Function(int) onWeakReferenceRemoved; + + static PigeonInstanceManager _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _PigeonInternalInstanceManagerApi api = + _PigeonInternalInstanceManagerApi(); + // Clears the native `PigeonInstanceManager` on the initial use of the Dart one. + api.clear(); + final PigeonInstanceManager instanceManager = PigeonInstanceManager( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _PigeonInternalInstanceManagerApi.setUpMessageHandlers( + instanceManager: instanceManager); + URLRequest.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + HTTPURLResponse.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + URLResponse.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKUserScript.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKNavigationAction.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKNavigationResponse.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKFrameInfo.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + NSError.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKScriptMessage.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKSecurityOrigin.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + HTTPCookie.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + AuthenticationChallengeResponse.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKWebsiteDataStore.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + UIView.pigeon_setUpMessageHandlers(pigeon_instanceManager: instanceManager); + UIScrollView.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKWebViewConfiguration.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKUserContentController.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKPreferences.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKScriptMessageHandler.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKNavigationDelegate.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + NSObject.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + UIViewWKWebView.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + NSViewWKWebView.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKWebView.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKUIDelegate.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WKHTTPCookieStore.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + UIScrollViewDelegate.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + URLCredential.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + URLProtectionSpace.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + URLAuthenticationChallenge.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + URL.pigeon_setUpMessageHandlers(pigeon_instanceManager: instanceManager); + return instanceManager; + } + + /// Adds a new instance that was instantiated by Dart. + /// + /// In other words, Dart wants to add a new instance that will represent + /// an object that will be instantiated on the host platform. + /// + /// Throws assertion error if the instance has already been added. + /// + /// Returns the randomly generated id of the [instance] added. + int addDartCreatedInstance(PigeonInternalProxyApiBaseClass instance) { + final int identifier = _nextUniqueIdentifier(); + _addInstanceWithIdentifier(instance, identifier); + return identifier; + } + + /// Removes the instance, if present, and call [onWeakReferenceRemoved] with + /// its identifier. + /// + /// Returns the identifier associated with the removed instance. Otherwise, + /// `null` if the instance was not found in this manager. + /// + /// This does not remove the strong referenced instance associated with + /// [instance]. This can be done with [remove]. + int? removeWeakReference(PigeonInternalProxyApiBaseClass instance) { + final int? identifier = getIdentifier(instance); + if (identifier == null) { + return null; + } + + _identifiers[instance] = null; + _finalizer.detach(instance); + onWeakReferenceRemoved(identifier); + + return identifier; + } + + /// Removes [identifier] and its associated strongly referenced instance, if + /// present, from the manager. + /// + /// Returns the strong referenced instance associated with [identifier] before + /// it was removed. Returns `null` if [identifier] was not associated with + /// any strong reference. + /// + /// This does not remove the weak referenced instance associated with + /// [identifier]. This can be done with [removeWeakReference]. + T? remove(int identifier) { + return _strongInstances.remove(identifier) as T?; + } + + /// Retrieves the instance associated with identifier. + /// + /// The value returned is chosen from the following order: + /// + /// 1. A weakly referenced instance associated with identifier. + /// 2. If the only instance associated with identifier is a strongly + /// referenced instance, a copy of the instance is added as a weak reference + /// with the same identifier. Returning the newly created copy. + /// 3. If no instance is associated with identifier, returns null. + /// + /// This method also expects the host `InstanceManager` to have a strong + /// reference to the instance the identifier is associated with. + T? getInstanceWithWeakReference( + int identifier) { + final PigeonInternalProxyApiBaseClass? weakInstance = + _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final PigeonInternalProxyApiBaseClass? strongInstance = + _strongInstances[identifier]; + if (strongInstance != null) { + final PigeonInternalProxyApiBaseClass copy = + strongInstance.pigeon_copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = + WeakReference(copy); + _finalizer.attach(copy, identifier, detach: copy); + return copy as T; + } + return strongInstance as T?; + } + + return weakInstance as T; + } + + /// Retrieves the identifier associated with instance. + int? getIdentifier(PigeonInternalProxyApiBaseClass instance) { + return _identifiers[instance]; + } + + /// Adds a new instance that was instantiated by the host platform. + /// + /// In other words, the host platform wants to add a new instance that + /// represents an object on the host platform. Stored with [identifier]. + /// + /// Throws assertion error if the instance or its identifier has already been + /// added. + /// + /// Returns unique identifier of the [instance] added. + void addHostCreatedInstance( + PigeonInternalProxyApiBaseClass instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier( + PigeonInternalProxyApiBaseClass instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = + WeakReference(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final PigeonInternalProxyApiBaseClass copy = instance.pigeon_copy(); + _identifiers[copy] = identifier; + _strongInstances[identifier] = copy; + } + + /// Whether this manager contains the given [identifier]. + bool containsIdentifier(int identifier) { + return _weakInstances.containsKey(identifier) || + _strongInstances.containsKey(identifier); + } + + int _nextUniqueIdentifier() { + late int identifier; + do { + identifier = _nextIdentifier; + _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; + } while (containsIdentifier(identifier)); + return identifier; + } +} + +/// Generated API for managing the Dart and native `PigeonInstanceManager`s. +class _PigeonInternalInstanceManagerApi { + /// Constructor for [_PigeonInternalInstanceManagerApi]. + _PigeonInternalInstanceManagerApi({BinaryMessenger? binaryMessenger}) + : pigeonVar_binaryMessenger = binaryMessenger; + + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + static void setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? binaryMessenger, + PigeonInstanceManager? instanceManager, + }) { + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference was null, expected non-null int.'); + try { + (instanceManager ?? PigeonInstanceManager.instance) + .remove(arg_identifier!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + Future removeStrongReference(int identifier) async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.removeStrongReference'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([identifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Clear the native `PigeonInstanceManager`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.PigeonInternalInstanceManager.clear'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } +} + +class _PigeonInternalProxyApiBaseCodec extends _PigeonCodec { + const _PigeonInternalProxyApiBaseCodec(this.instanceManager); + final PigeonInstanceManager instanceManager; + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonInternalProxyApiBaseClass) { + buffer.putUint8(128); + writeValue(buffer, instanceManager.getIdentifier(value)); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return instanceManager + .getInstanceWithWeakReference(readValue(buffer)! as int); + default: + return super.readValueOfType(type, buffer); + } + } +} + +/// The values that can be returned in a change dictionary. +/// +/// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions. +enum KeyValueObservingOptions { + /// Indicates that the change dictionary should provide the new attribute + /// value, if applicable. newValue, + + /// Indicates that the change dictionary should contain the old attribute + /// value, if applicable. oldValue, + + /// If specified, a notification should be sent to the observer immediately, + /// before the observer registration method even returns. initialValue, + + /// Whether separate notifications should be sent to the observer before and + /// after each change, instead of a single notification after the change. priorNotification, } -/// Mirror of NSKeyValueChange. +/// The kinds of changes that can be observed. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange?language=objc. -enum NSKeyValueChangeEnum { +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange. +enum KeyValueChange { + /// Indicates that the value of the observed key path was set to a new value. setting, + + /// Indicates that an object has been inserted into the to-many relationship + /// that is being observed. insertion, + + /// Indicates that an object has been removed from the to-many relationship + /// that is being observed. removal, + + /// Indicates that an object has been replaced in the to-many relationship + /// that is being observed. replacement, + + /// The value is not recognized by the wrapper. + unknown, } -/// Mirror of NSKeyValueChangeKey. +/// The keys that can appear in the change dictionary. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey?language=objc. -enum NSKeyValueChangeKeyEnum { +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey. +enum KeyValueChangeKey { + /// If the value of the `KeyValueChangeKey.kind` entry is + /// `KeyValueChange.insertion`, `KeyValueChange.removal`, or + /// `KeyValueChange.replacement`, the value of this key is a Set object that + /// contains the indexes of the inserted, removed, or replaced objects. indexes, + + /// An object that contains a value corresponding to one of the + /// `KeyValueChange` enum, indicating what sort of change has occurred. kind, + + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting, and `KeyValueObservingOptions.newValue` was + /// specified when the observer was registered, the value of this key is the + /// new value for the attribute. newValue, + + /// If the `KeyValueObservingOptions.priorNotification` option was specified + /// when the observer was registered this notification is sent prior to a + /// change. notificationIsPrior, + + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting`, and `KeyValueObservingOptions.old` was specified + /// when the observer was registered, the value of this key is the value + /// before the attribute was changed. oldValue, + + /// The value is not recognized by the wrapper. unknown, } -/// Mirror of WKUserScriptInjectionTime. +/// Constants for the times at which to inject script content into a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc. -enum WKUserScriptInjectionTimeEnum { +/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime. +enum UserScriptInjectionTime { + /// A constant to inject the script after the creation of the webpage’s + /// document element, but before loading any other content. atDocumentStart, + + /// A constant to inject the script after the document finishes loading, but + /// before loading any other subresources. atDocumentEnd, + + /// The value is not recognized by the wrapper. + unknown, } -/// Mirror of WKAudiovisualMediaTypes. +/// The media types that require a user gesture to begin playing. /// -/// See [WKAudiovisualMediaTypes](https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes?language=objc). -enum WKAudiovisualMediaTypeEnum { +/// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes. +enum AudiovisualMediaType { + /// No media types require a user gesture to begin playing. none, + + /// Media types that contain audio require a user gesture to begin playing. audio, + + /// Media types that contain video require a user gesture to begin playing. video, + + /// All media types require a user gesture to begin playing. all, } -/// Mirror of WKWebsiteDataTypes. +/// A `WKWebsiteDataRecord` object includes these constants in its dataTypes +/// property. /// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types?language=objc. -enum WKWebsiteDataTypeEnum { +/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types. +enum WebsiteDataType { + /// Cookies. cookies, + + /// In-memory caches. memoryCache, + + /// On-disk caches. diskCache, + + /// HTML offline web app caches. offlineWebApplicationCache, + + /// HTML local storage. localStorage, + + /// HTML session storage. sessionStorage, + + /// WebSQL databases. webSQLDatabases, + + /// IndexedDB databases. indexedDBDatabases, } -/// Mirror of WKNavigationActionPolicy. +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from an action. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -enum WKNavigationActionPolicyEnum { +/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy. +enum NavigationActionPolicy { + /// Allow the navigation to continue. allow, + + /// Cancel the navigation. cancel, + + /// Allow the download to proceed. + download, } -/// Mirror of WKNavigationResponsePolicy. +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from a response. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -enum WKNavigationResponsePolicyEnum { +/// See https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy. +enum NavigationResponsePolicy { + /// Allow the navigation to continue. allow, + + /// Cancel the navigation. cancel, + + /// Allow the download to proceed. + download, } -/// Mirror of NSHTTPCookiePropertyKey. +/// Constants that define the supported keys in a cookie attributes dictionary. /// -/// See https://developer.apple.com/documentation/foundation/nshttpcookiepropertykey. -enum NSHttpCookiePropertyKeyEnum { +/// See https://developer.apple.com/documentation/foundation/httpcookiepropertykey. +enum HttpCookiePropertyKey { + /// A String object containing the comment for the cookie. comment, + + /// An Uri object or String object containing the comment URL for the cookie. commentUrl, + + /// Aa String object stating whether the cookie should be discarded at the end + /// of the session. discard, + + /// An String object containing the domain for the cookie. domain, + + /// An Date object or String object specifying the expiration date for the + /// cookie. expires, + + /// An String object containing an integer value stating how long in seconds + /// the cookie should be kept, at most. maximumAge, + + /// An String object containing the name of the cookie (required). name, + + /// A URL or String object containing the URL that set this cookie. originUrl, + + /// A String object containing the path for the cookie. path, + + /// An String object containing comma-separated integer values specifying the + /// ports for the cookie. port, + + /// A string indicating the same-site policy for the cookie. sameSitePolicy, + + /// A String object indicating that the cookie should be transmitted only over + /// secure channels. secure, + + /// A String object containing the value of the cookie. value, + + /// A String object that specifies the version of the cookie. version, + + /// The value is not recognized by the wrapper. + unknown, } -/// An object that contains information about an action that causes navigation -/// to occur. +/// The type of action that triggered the navigation. /// -/// Wraps [WKNavigationType](https://developer.apple.com/documentation/webkit/wknavigationaction?language=objc). -enum WKNavigationType { +/// See https://developer.apple.com/documentation/webkit/wknavigationtype. +enum NavigationType { /// A link activation. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypelinkactivated?language=objc. linkActivated, /// A request to submit a form. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformsubmitted?language=objc. - submitted, + formSubmitted, /// A request for the frame’s next or previous item. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypebackforward?language=objc. backForward, /// A request to reload the webpage. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypereload?language=objc. reload, /// A request to resubmit a form. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformresubmitted?language=objc. formResubmitted, /// A navigation request that originates for some other reason. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. other, - /// An unknown navigation type. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. + /// The value is not recognized by the wrapper. unknown, } /// Possible permission decisions for device resource access. /// -/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc. -enum WKPermissionDecision { +/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision. +enum PermissionDecision { /// Deny permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiondeny?language=objc. deny, /// Deny permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiongrant?language=objc. grant, /// Prompt the user for permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisionprompt?language=objc. prompt, } /// List of the types of media devices that can capture audio, video, or both. /// -/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype?language=objc. -enum WKMediaCaptureType { +/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype. +enum MediaCaptureType { /// A media device that can capture video. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecamera?language=objc. camera, /// A media device or devices that can capture audio and video. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecameraandmicrophone?language=objc. cameraAndMicrophone, /// A media device that can capture audio. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypemicrophone?language=objc. microphone, - /// An unknown media device. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. + /// The value is not recognized by the wrapper. unknown, } /// Responses to an authentication challenge. /// -/// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition?language=objc. -enum NSUrlSessionAuthChallengeDisposition { +/// See https://developer.apple.com/documentation/foundation/urlsession/authchallengedisposition. +enum UrlSessionAuthChallengeDisposition { /// Use the specified credential, which may be nil. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeusecredential?language=objc. useCredential, /// Use the default handling for the challenge as though this delegate method /// were not implemented. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeperformdefaulthandling?language=objc. performDefaultHandling, /// Cancel the entire request. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengecancelauthenticationchallenge?language=objc. cancelAuthenticationChallenge, /// Reject this challenge, and call the authentication delegate method again /// with the next authentication protection space. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengerejectprotectionspace?language=objc. rejectProtectionSpace, + + /// The value is not recognized by the wrapper. + unknown, } /// Specifies how long a credential will be kept. -enum NSUrlCredentialPersistence { +/// +/// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence. +enum UrlCredentialPersistence { /// The credential should not be stored. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencenone?language=objc. none, /// The credential should be stored only for this session. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistenceforsession?language=objc. - session, + forSession, /// The credential should be stored in the keychain. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencepermanent?language=objc. permanent, /// The credential should be stored permanently in the keychain, and in /// addition should be distributed to other devices based on the owning Apple /// ID. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencesynchronizable?language=objc. synchronizable, } -class NSKeyValueObservingOptionsEnumData { - NSKeyValueObservingOptionsEnumData({ - required this.value, - }); - - NSKeyValueObservingOptionsEnum value; - - Object encode() { - return [ - value.index, - ]; - } - - static NSKeyValueObservingOptionsEnumData decode(Object result) { - result as List; - return NSKeyValueObservingOptionsEnumData( - value: NSKeyValueObservingOptionsEnum.values[result[0]! as int], - ); - } -} - -class NSKeyValueChangeKeyEnumData { - NSKeyValueChangeKeyEnumData({ - required this.value, - }); - - NSKeyValueChangeKeyEnum value; - - Object encode() { - return [ - value.index, - ]; +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is KeyValueObservingOptions) { + buffer.putUint8(129); + writeValue(buffer, value.index); + } else if (value is KeyValueChange) { + buffer.putUint8(130); + writeValue(buffer, value.index); + } else if (value is KeyValueChangeKey) { + buffer.putUint8(131); + writeValue(buffer, value.index); + } else if (value is UserScriptInjectionTime) { + buffer.putUint8(132); + writeValue(buffer, value.index); + } else if (value is AudiovisualMediaType) { + buffer.putUint8(133); + writeValue(buffer, value.index); + } else if (value is WebsiteDataType) { + buffer.putUint8(134); + writeValue(buffer, value.index); + } else if (value is NavigationActionPolicy) { + buffer.putUint8(135); + writeValue(buffer, value.index); + } else if (value is NavigationResponsePolicy) { + buffer.putUint8(136); + writeValue(buffer, value.index); + } else if (value is HttpCookiePropertyKey) { + buffer.putUint8(137); + writeValue(buffer, value.index); + } else if (value is NavigationType) { + buffer.putUint8(138); + writeValue(buffer, value.index); + } else if (value is PermissionDecision) { + buffer.putUint8(139); + writeValue(buffer, value.index); + } else if (value is MediaCaptureType) { + buffer.putUint8(140); + writeValue(buffer, value.index); + } else if (value is UrlSessionAuthChallengeDisposition) { + buffer.putUint8(141); + writeValue(buffer, value.index); + } else if (value is UrlCredentialPersistence) { + buffer.putUint8(142); + writeValue(buffer, value.index); + } else { + super.writeValue(buffer, value); + } } - static NSKeyValueChangeKeyEnumData decode(Object result) { - result as List; - return NSKeyValueChangeKeyEnumData( - value: NSKeyValueChangeKeyEnum.values[result[0]! as int], - ); + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 129: + final int? value = readValue(buffer) as int?; + return value == null ? null : KeyValueObservingOptions.values[value]; + case 130: + final int? value = readValue(buffer) as int?; + return value == null ? null : KeyValueChange.values[value]; + case 131: + final int? value = readValue(buffer) as int?; + return value == null ? null : KeyValueChangeKey.values[value]; + case 132: + final int? value = readValue(buffer) as int?; + return value == null ? null : UserScriptInjectionTime.values[value]; + case 133: + final int? value = readValue(buffer) as int?; + return value == null ? null : AudiovisualMediaType.values[value]; + case 134: + final int? value = readValue(buffer) as int?; + return value == null ? null : WebsiteDataType.values[value]; + case 135: + final int? value = readValue(buffer) as int?; + return value == null ? null : NavigationActionPolicy.values[value]; + case 136: + final int? value = readValue(buffer) as int?; + return value == null ? null : NavigationResponsePolicy.values[value]; + case 137: + final int? value = readValue(buffer) as int?; + return value == null ? null : HttpCookiePropertyKey.values[value]; + case 138: + final int? value = readValue(buffer) as int?; + return value == null ? null : NavigationType.values[value]; + case 139: + final int? value = readValue(buffer) as int?; + return value == null ? null : PermissionDecision.values[value]; + case 140: + final int? value = readValue(buffer) as int?; + return value == null ? null : MediaCaptureType.values[value]; + case 141: + final int? value = readValue(buffer) as int?; + return value == null + ? null + : UrlSessionAuthChallengeDisposition.values[value]; + case 142: + final int? value = readValue(buffer) as int?; + return value == null ? null : UrlCredentialPersistence.values[value]; + default: + return super.readValueOfType(type, buffer); + } } } -class WKUserScriptInjectionTimeEnumData { - WKUserScriptInjectionTimeEnumData({ - required this.value, - }); - - WKUserScriptInjectionTimeEnum value; - - Object encode() { - return [ - value.index, - ]; +/// A URL load request that is independent of protocol or URL scheme. +/// +/// See https://developer.apple.com/documentation/foundation/urlrequest. +class URLRequest extends NSObject { + URLRequest({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required String url, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier, url]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); } - static WKUserScriptInjectionTimeEnumData decode(Object result) { - result as List; - return WKUserScriptInjectionTimeEnumData( - value: WKUserScriptInjectionTimeEnum.values[result[0]! as int], - ); - } -} - -class WKAudiovisualMediaTypeEnumData { - WKAudiovisualMediaTypeEnumData({ - required this.value, - }); - - WKAudiovisualMediaTypeEnum value; - - Object encode() { - return [ - value.index, - ]; + /// Constructs [URLRequest] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URLRequest.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecURLRequest = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URLRequest Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + URLRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKAudiovisualMediaTypeEnumData decode(Object result) { - result as List; - return WKAudiovisualMediaTypeEnumData( - value: WKAudiovisualMediaTypeEnum.values[result[0]! as int], + /// The URL being requested. + Future getUrl() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); - } -} - -class WKWebsiteDataTypeEnumData { - WKWebsiteDataTypeEnumData({ - required this.value, - }); - - WKWebsiteDataTypeEnum value; - - Object encode() { - return [ - value.index, - ]; + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } } - static WKWebsiteDataTypeEnumData decode(Object result) { - result as List; - return WKWebsiteDataTypeEnumData( - value: WKWebsiteDataTypeEnum.values[result[0]! as int], + /// The HTTP request method. + Future setHttpMethod(String? method) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setHttpMethod'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); - } -} - -class WKNavigationActionPolicyEnumData { - WKNavigationActionPolicyEnumData({ - required this.value, - }); - - WKNavigationActionPolicyEnum value; - - Object encode() { - return [ - value.index, - ]; + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, method]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } } - static WKNavigationActionPolicyEnumData decode(Object result) { - result as List; - return WKNavigationActionPolicyEnumData( - value: WKNavigationActionPolicyEnum.values[result[0]! as int], + /// The HTTP request method. + Future getHttpMethod() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getHttpMethod'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); - } -} - -class NSHttpCookiePropertyKeyEnumData { - NSHttpCookiePropertyKeyEnumData({ - required this.value, - }); - - NSHttpCookiePropertyKeyEnum value; - - Object encode() { - return [ - value.index, - ]; + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } } - static NSHttpCookiePropertyKeyEnumData decode(Object result) { - result as List; - return NSHttpCookiePropertyKeyEnumData( - value: NSHttpCookiePropertyKeyEnum.values[result[0]! as int], + /// The request body. + Future setHttpBody(Uint8List? body) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setHttpBody'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, body]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } } -} -class WKPermissionDecisionData { - WKPermissionDecisionData({ - required this.value, - }); - - WKPermissionDecision value; - - Object encode() { - return [ - value.index, - ]; + /// The request body. + Future getHttpBody() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getHttpBody'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as Uint8List?); + } } - static WKPermissionDecisionData decode(Object result) { - result as List; - return WKPermissionDecisionData( - value: WKPermissionDecision.values[result[0]! as int], + /// A dictionary containing all of the HTTP header fields for a request. + Future setAllHttpHeaderFields(Map? fields) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.setAllHttpHeaderFields'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, fields]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } } -} -class WKMediaCaptureTypeData { - WKMediaCaptureTypeData({ - required this.value, - }); - - WKMediaCaptureType value; - - Object encode() { - return [ - value.index, - ]; + /// A dictionary containing all of the HTTP header fields for a request. + Future?> getAllHttpHeaderFields() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLRequest.getAllHttpHeaderFields'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as Map?) + ?.cast(); + } } - static WKMediaCaptureTypeData decode(Object result) { - result as List; - return WKMediaCaptureTypeData( - value: WKMediaCaptureType.values[result[0]! as int], + @override + URLRequest pigeon_copy() { + return URLRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); } } -/// Mirror of NSURLRequest. +/// The metadata associated with the response to an HTTP protocol URL load +/// request. /// -/// See https://developer.apple.com/documentation/foundation/nsurlrequest?language=objc. -class NSUrlRequestData { - NSUrlRequestData({ - required this.url, - this.httpMethod, - this.httpBody, - required this.allHttpHeaderFields, - }); - - String url; - - String? httpMethod; - - Uint8List? httpBody; +/// See https://developer.apple.com/documentation/foundation/httpurlresponse. +class HTTPURLResponse extends URLResponse { + /// Constructs [HTTPURLResponse] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + HTTPURLResponse.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.statusCode, + super.observeValue, + }) : super.pigeon_detached(); - Map allHttpHeaderFields; + /// The response’s HTTP status code. + final int statusCode; - Object encode() { - return [ - url, - httpMethod, - httpBody, - allHttpHeaderFields, - ]; + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + HTTPURLResponse Function(int statusCode)? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.HTTPURLResponse.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.HTTPURLResponse.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.HTTPURLResponse.pigeon_newInstance was null, expected non-null int.'); + final int? arg_statusCode = (args[1] as int?); + assert(arg_statusCode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.HTTPURLResponse.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_statusCode!) ?? + HTTPURLResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + statusCode: arg_statusCode!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static NSUrlRequestData decode(Object result) { - result as List; - return NSUrlRequestData( - url: result[0]! as String, - httpMethod: result[1] as String?, - httpBody: result[2] as Uint8List?, - allHttpHeaderFields: - (result[3] as Map?)!.cast(), + @override + HTTPURLResponse pigeon_copy() { + return HTTPURLResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + statusCode: statusCode, + observeValue: observeValue, ); } } -/// Mirror of NSURLResponse. +/// The metadata associated with the response to a URL load request, independent +/// of protocol and URL scheme. /// -/// See https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc. -class NSHttpUrlResponseData { - NSHttpUrlResponseData({ - required this.statusCode, - }); - - int statusCode; - - Object encode() { - return [ - statusCode, - ]; +/// See https://developer.apple.com/documentation/foundation/urlresponse. +class URLResponse extends NSObject { + /// Constructs [URLResponse] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URLResponse.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URLResponse Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLResponse.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLResponse.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLResponse.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + URLResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static NSHttpUrlResponseData decode(Object result) { - result as List; - return NSHttpUrlResponseData( - statusCode: result[0]! as int, + @override + URLResponse pigeon_copy() { + return URLResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); } } -/// Mirror of WKUserScript. +/// A script that the web view injects into a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkuserscript?language=objc. -class WKUserScriptData { - WKUserScriptData({ +/// See https://developer.apple.com/documentation/webkit/wkuserscript. +class WKUserScript extends NSObject { + /// Creates a user script object that contains the specified source code and + /// attributes. + WKUserScript({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.source, - this.injectionTime, - required this.isMainFrameOnly, - }); - - String source; - - WKUserScriptInjectionTimeEnumData? injectionTime; - - bool isMainFrameOnly; + required this.injectionTime, + required this.isForMainFrameOnly, + super.observeValue, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserScript; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([ + pigeonVar_instanceIdentifier, + source, + injectionTime, + isForMainFrameOnly + ]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - Object encode() { - return [ - source, - injectionTime?.encode(), - isMainFrameOnly, - ]; + /// Constructs [WKUserScript] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKUserScript.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.source, + required this.injectionTime, + required this.isForMainFrameOnly, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWKUserScript = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The script’s source code. + final String source; + + /// The time at which to inject the script into the webpage. + final UserScriptInjectionTime injectionTime; + + /// A Boolean value that indicates whether to inject the script into the main + /// frame or all frames. + final bool isForMainFrameOnly; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKUserScript Function( + String source, + UserScriptInjectionTime injectionTime, + bool isForMainFrameOnly, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance was null, expected non-null int.'); + final String? arg_source = (args[1] as String?); + assert(arg_source != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance was null, expected non-null String.'); + final UserScriptInjectionTime? arg_injectionTime = + (args[2] as UserScriptInjectionTime?); + assert(arg_injectionTime != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance was null, expected non-null UserScriptInjectionTime.'); + final bool? arg_isForMainFrameOnly = (args[3] as bool?); + assert(arg_isForMainFrameOnly != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserScript.pigeon_newInstance was null, expected non-null bool.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_source!, arg_injectionTime!, + arg_isForMainFrameOnly!) ?? + WKUserScript.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + source: arg_source!, + injectionTime: arg_injectionTime!, + isForMainFrameOnly: arg_isForMainFrameOnly!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKUserScriptData decode(Object result) { - result as List; - return WKUserScriptData( - source: result[0]! as String, - injectionTime: result[1] != null - ? WKUserScriptInjectionTimeEnumData.decode( - result[1]! as List) - : null, - isMainFrameOnly: result[2]! as bool, + @override + WKUserScript pigeon_copy() { + return WKUserScript.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + source: source, + injectionTime: injectionTime, + isForMainFrameOnly: isForMainFrameOnly, + observeValue: observeValue, ); } } -/// Mirror of WKNavigationAction. +/// An object that contains information about an action that causes navigation +/// to occur. /// /// See https://developer.apple.com/documentation/webkit/wknavigationaction. -class WKNavigationActionData { - WKNavigationActionData({ +class WKNavigationAction extends NSObject { + /// Constructs [WKNavigationAction] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKNavigationAction.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.request, - required this.targetFrame, + this.targetFrame, required this.navigationType, - }); - - NSUrlRequestData request; - - WKFrameInfoData targetFrame; + super.observeValue, + }) : super.pigeon_detached(); - WKNavigationType navigationType; + /// The URL request object associated with the navigation action. + final URLRequest request; - Object encode() { - return [ - request.encode(), - targetFrame.encode(), - navigationType.index, - ]; + /// The frame in which to display the new content. + /// + /// If the target of the navigation is a new window, this property is nil. + final WKFrameInfo? targetFrame; + + /// The type of action that triggered the navigation. + final NavigationType navigationType; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKNavigationAction Function( + URLRequest request, + WKFrameInfo? targetFrame, + NavigationType navigationType, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance was null, expected non-null int.'); + final URLRequest? arg_request = (args[1] as URLRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance was null, expected non-null URLRequest.'); + final WKFrameInfo? arg_targetFrame = (args[2] as WKFrameInfo?); + final NavigationType? arg_navigationType = + (args[3] as NavigationType?); + assert(arg_navigationType != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationAction.pigeon_newInstance was null, expected non-null NavigationType.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call( + arg_request!, arg_targetFrame, arg_navigationType!) ?? + WKNavigationAction.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + request: arg_request!, + targetFrame: arg_targetFrame, + navigationType: arg_navigationType!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKNavigationActionData decode(Object result) { - result as List; - return WKNavigationActionData( - request: NSUrlRequestData.decode(result[0]! as List), - targetFrame: WKFrameInfoData.decode(result[1]! as List), - navigationType: WKNavigationType.values[result[2]! as int], + @override + WKNavigationAction pigeon_copy() { + return WKNavigationAction.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + request: request, + targetFrame: targetFrame, + navigationType: navigationType, + observeValue: observeValue, ); } } -/// Mirror of WKNavigationResponse. +/// An object that contains the response to a navigation request, and which you +/// use to make navigation-related policy decisions. /// /// See https://developer.apple.com/documentation/webkit/wknavigationresponse. -class WKNavigationResponseData { - WKNavigationResponseData({ +class WKNavigationResponse extends NSObject { + /// Constructs [WKNavigationResponse] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKNavigationResponse.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.response, - required this.forMainFrame, - }); - - NSHttpUrlResponseData response; - - bool forMainFrame; - - Object encode() { - return [ - response.encode(), - forMainFrame, - ]; + required this.isForMainFrame, + super.observeValue, + }) : super.pigeon_detached(); + + /// The frame’s response. + final URLResponse response; + + /// A Boolean value that indicates whether the response targets the web view’s + /// main frame. + final bool isForMainFrame; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKNavigationResponse Function( + URLResponse response, + bool isForMainFrame, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance was null, expected non-null int.'); + final URLResponse? arg_response = (args[1] as URLResponse?); + assert(arg_response != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance was null, expected non-null URLResponse.'); + final bool? arg_isForMainFrame = (args[2] as bool?); + assert(arg_isForMainFrame != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationResponse.pigeon_newInstance was null, expected non-null bool.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_response!, arg_isForMainFrame!) ?? + WKNavigationResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + response: arg_response!, + isForMainFrame: arg_isForMainFrame!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKNavigationResponseData decode(Object result) { - result as List; - return WKNavigationResponseData( - response: NSHttpUrlResponseData.decode(result[0]! as List), - forMainFrame: result[1]! as bool, + @override + WKNavigationResponse pigeon_copy() { + return WKNavigationResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + response: response, + isForMainFrame: isForMainFrame, + observeValue: observeValue, ); } } -/// Mirror of WKFrameInfo. +/// An object that contains information about a frame on a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkframeinfo?language=objc. -class WKFrameInfoData { - WKFrameInfoData({ +/// See https://developer.apple.com/documentation/webkit/wkframeinfo. +class WKFrameInfo extends NSObject { + /// Constructs [WKFrameInfo] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKFrameInfo.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.isMainFrame, required this.request, - }); - - bool isMainFrame; - - NSUrlRequestData request; - - Object encode() { - return [ - isMainFrame, - request.encode(), - ]; + super.observeValue, + }) : super.pigeon_detached(); + + /// A Boolean value indicating whether the frame is the web site's main frame + /// or a subframe. + final bool isMainFrame; + + /// The frame’s current request. + final URLRequest request; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKFrameInfo Function( + bool isMainFrame, + URLRequest request, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance was null, expected non-null int.'); + final bool? arg_isMainFrame = (args[1] as bool?); + assert(arg_isMainFrame != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance was null, expected non-null bool.'); + final URLRequest? arg_request = (args[2] as URLRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKFrameInfo.pigeon_newInstance was null, expected non-null URLRequest.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_isMainFrame!, arg_request!) ?? + WKFrameInfo.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + isMainFrame: arg_isMainFrame!, + request: arg_request!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKFrameInfoData decode(Object result) { - result as List; - return WKFrameInfoData( - isMainFrame: result[0]! as bool, - request: NSUrlRequestData.decode(result[1]! as List), + @override + WKFrameInfo pigeon_copy() { + return WKFrameInfo.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + isMainFrame: isMainFrame, + request: request, + observeValue: observeValue, ); } } -/// Mirror of NSError. +/// Information about an error condition including a domain, a domain-specific +/// error code, and application-specific information. /// -/// See https://developer.apple.com/documentation/foundation/nserror?language=objc. -class NSErrorData { - NSErrorData({ +/// See https://developer.apple.com/documentation/foundation/nserror. +class NSError extends NSObject { + /// Constructs [NSError] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + NSError.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.code, required this.domain, - this.userInfo, - }); - - int code; - - String domain; - - Map? userInfo; - - Object encode() { - return [ - code, - domain, - userInfo, - ]; + required this.userInfo, + super.observeValue, + }) : super.pigeon_detached(); + + /// The error code. + final int code; + + /// A string containing the error domain. + final String domain; + + /// The user info dictionary. + final Map userInfo; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + NSError Function( + int code, + String domain, + Map userInfo, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance was null, expected non-null int.'); + final int? arg_code = (args[1] as int?); + assert(arg_code != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance was null, expected non-null int.'); + final String? arg_domain = (args[2] as String?); + assert(arg_domain != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance was null, expected non-null String.'); + final Map? arg_userInfo = + (args[3] as Map?)?.cast(); + assert(arg_userInfo != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSError.pigeon_newInstance was null, expected non-null Map.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_code!, arg_domain!, arg_userInfo!) ?? + NSError.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + code: arg_code!, + domain: arg_domain!, + userInfo: arg_userInfo!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static NSErrorData decode(Object result) { - result as List; - return NSErrorData( - code: result[0]! as int, - domain: result[1]! as String, - userInfo: (result[2] as Map?)?.cast(), + @override + NSError pigeon_copy() { + return NSError.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + code: code, + domain: domain, + userInfo: userInfo, + observeValue: observeValue, ); } } -/// Mirror of WKScriptMessage. +/// An object that encapsulates a message sent by JavaScript code from a +/// webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessage?language=objc. -class WKScriptMessageData { - WKScriptMessageData({ +/// See https://developer.apple.com/documentation/webkit/wkscriptmessage. +class WKScriptMessage extends NSObject { + /// Constructs [WKScriptMessage] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKScriptMessage.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.name, this.body, - }); - - String name; - - Object? body; - - Object encode() { - return [ - name, - body, - ]; + super.observeValue, + }) : super.pigeon_detached(); + + /// The name of the message handler to which the message is sent. + final String name; + + /// The body of the message. + final Object? body; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKScriptMessage Function( + String name, + Object? body, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessage.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessage.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessage.pigeon_newInstance was null, expected non-null int.'); + final String? arg_name = (args[1] as String?); + assert(arg_name != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessage.pigeon_newInstance was null, expected non-null String.'); + final Object? arg_body = (args[2] as Object?); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_name!, arg_body) ?? + WKScriptMessage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + name: arg_name!, + body: arg_body, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKScriptMessageData decode(Object result) { - result as List; - return WKScriptMessageData( - name: result[0]! as String, - body: result[1], + @override + WKScriptMessage pigeon_copy() { + return WKScriptMessage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + name: name, + body: body, + observeValue: observeValue, ); } } -/// Mirror of WKSecurityOrigin. +/// An object that identifies the origin of a particular resource. /// -/// See https://developer.apple.com/documentation/webkit/wksecurityorigin?language=objc. -class WKSecurityOriginData { - WKSecurityOriginData({ +/// See https://developer.apple.com/documentation/webkit/wksecurityorigin. +class WKSecurityOrigin extends NSObject { + /// Constructs [WKSecurityOrigin] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKSecurityOrigin.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, required this.host, required this.port, - required this.protocol, - }); - - String host; - - int port; - - String protocol; - - Object encode() { - return [ - host, - port, - protocol, - ]; + required this.securityProtocol, + super.observeValue, + }) : super.pigeon_detached(); + + /// The security origin’s host. + final String host; + + /// The security origin's port. + final int port; + + /// The security origin's protocol. + final String securityProtocol; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKSecurityOrigin Function( + String host, + int port, + String securityProtocol, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance was null, expected non-null int.'); + final String? arg_host = (args[1] as String?); + assert(arg_host != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance was null, expected non-null String.'); + final int? arg_port = (args[2] as int?); + assert(arg_port != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance was null, expected non-null int.'); + final String? arg_securityProtocol = (args[3] as String?); + assert(arg_securityProtocol != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKSecurityOrigin.pigeon_newInstance was null, expected non-null String.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call( + arg_host!, arg_port!, arg_securityProtocol!) ?? + WKSecurityOrigin.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + host: arg_host!, + port: arg_port!, + securityProtocol: arg_securityProtocol!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static WKSecurityOriginData decode(Object result) { - result as List; - return WKSecurityOriginData( - host: result[0]! as String, - port: result[1]! as int, - protocol: result[2]! as String, + @override + WKSecurityOrigin pigeon_copy() { + return WKSecurityOrigin.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + host: host, + port: port, + securityProtocol: securityProtocol, + observeValue: observeValue, ); } } -/// Mirror of NSHttpCookieData. +/// A representation of an HTTP cookie. /// -/// See https://developer.apple.com/documentation/foundation/nshttpcookie?language=objc. -class NSHttpCookieData { - NSHttpCookieData({ - required this.propertyKeys, - required this.propertyValues, - }); - - List propertyKeys; +/// See https://developer.apple.com/documentation/foundation/httpcookie. +class HTTPCookie extends NSObject { + HTTPCookie({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required Map properties, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecHTTPCookie; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier, properties]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - List propertyValues; + /// Constructs [HTTPCookie] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + HTTPCookie.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecHTTPCookie = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + HTTPCookie Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + HTTPCookie.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } - Object encode() { - return [ - propertyKeys, - propertyValues, - ]; + /// The cookie’s properties. + Future?> getProperties() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecHTTPCookie; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.HTTPCookie.getProperties'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as Map?) + ?.cast(); + } } - static NSHttpCookieData decode(Object result) { - result as List; - return NSHttpCookieData( - propertyKeys: (result[0] as List?)! - .cast(), - propertyValues: (result[1] as List?)!.cast(), + @override + HTTPCookie pigeon_copy() { + return HTTPCookie.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); } } -/// An object that can represent either a value supported by -/// `StandardMessageCodec`, a data class in this pigeon file, or an identifier -/// of an object stored in an `InstanceManager`. -class ObjectOrIdentifier { - ObjectOrIdentifier({ - this.value, - required this.isIdentifier, - }); - - Object? value; +/// Response object used to return multiple values to an auth challenge received +/// by a `WKNavigationDelegate` auth challenge. +/// +/// The `webView(_:didReceive:completionHandler:)` method in +/// `WKNavigationDelegate` responds with a completion handler that takes two +/// values. The wrapper returns this class instead to handle this scenario. +class AuthenticationChallengeResponse extends PigeonInternalProxyApiBaseClass { + AuthenticationChallengeResponse({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.disposition, + this.credential, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecAuthenticationChallengeResponse; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel.send( + [pigeonVar_instanceIdentifier, disposition, credential]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - /// Whether value is an int that is used to retrieve an instance stored in an - /// `InstanceManager`. - bool isIdentifier; + /// Constructs [AuthenticationChallengeResponse] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + AuthenticationChallengeResponse.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.disposition, + this.credential, + }); - Object encode() { - return [ - value, - isIdentifier, - ]; + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecAuthenticationChallengeResponse = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The option to use to handle the challenge. + final UrlSessionAuthChallengeDisposition disposition; + + /// The credential to use for authentication when the disposition parameter + /// contains the value URLSession.AuthChallengeDisposition.useCredential. + final URLCredential? credential; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + AuthenticationChallengeResponse Function( + UrlSessionAuthChallengeDisposition disposition, + URLCredential? credential, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_newInstance was null, expected non-null int.'); + final UrlSessionAuthChallengeDisposition? arg_disposition = + (args[1] as UrlSessionAuthChallengeDisposition?); + assert(arg_disposition != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.AuthenticationChallengeResponse.pigeon_newInstance was null, expected non-null UrlSessionAuthChallengeDisposition.'); + final URLCredential? arg_credential = (args[2] as URLCredential?); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_disposition!, arg_credential) ?? + AuthenticationChallengeResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + disposition: arg_disposition!, + credential: arg_credential, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } - static ObjectOrIdentifier decode(Object result) { - result as List; - return ObjectOrIdentifier( - value: result[0], - isIdentifier: result[1]! as bool, + @override + AuthenticationChallengeResponse pigeon_copy() { + return AuthenticationChallengeResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + disposition: disposition, + credential: credential, ); } } -class AuthenticationChallengeResponse { - AuthenticationChallengeResponse({ - required this.disposition, - this.credentialIdentifier, - }); - - NSUrlSessionAuthChallengeDisposition disposition; - - int? credentialIdentifier; +/// An object that manages cookies, disk and memory caches, and other types of +/// data for a web view. +/// +/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore. +class WKWebsiteDataStore extends NSObject { + /// Constructs [WKWebsiteDataStore] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKWebsiteDataStore.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKWebsiteDataStore = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The default data store, which stores data persistently to disk. + static final WKWebsiteDataStore defaultDataStore = + pigeonVar_defaultDataStore(); + + /// The object that manages the HTTP cookies for your website. + late final WKHTTPCookieStore httpCookieStore = pigeonVar_httpCookieStore(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKWebsiteDataStore Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKWebsiteDataStore.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } - Object encode() { - return [ - disposition.index, - credentialIdentifier, - ]; + static WKWebsiteDataStore pigeonVar_defaultDataStore() { + final WKWebsiteDataStore pigeonVar_instance = + WKWebsiteDataStore.pigeon_detached(); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec(PigeonInstanceManager.instance); + final BinaryMessenger pigeonVar_binaryMessenger = + ServicesBinding.instance.defaultBinaryMessenger; + final int pigeonVar_instanceIdentifier = PigeonInstanceManager.instance + .addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.defaultDataStore'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; } - static AuthenticationChallengeResponse decode(Object result) { - result as List; - return AuthenticationChallengeResponse( - disposition: - NSUrlSessionAuthChallengeDisposition.values[result[0]! as int], - credentialIdentifier: result[1] as int?, + WKHTTPCookieStore pigeonVar_httpCookieStore() { + final WKHTTPCookieStore pigeonVar_instance = + WKHTTPCookieStore.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, ); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebsiteDataStore; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.httpCookieStore'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, pigeonVar_instanceIdentifier]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; } -} -class _WKWebsiteDataStoreHostApiCodec extends StandardMessageCodec { - const _WKWebsiteDataStoreHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKWebsiteDataTypeEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); + /// Removes the specified types of website data from one or more data records. + Future removeDataOfTypes( + List dataTypes, + double modificationTimeInSecondsSinceEpoch, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebsiteDataStore; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStore.removeDataOfTypes'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel.send( + [this, dataTypes, modificationTimeInSecondsSinceEpoch]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); } else { - super.writeValue(buffer, value); + return (pigeonVar_replyList[0] as bool?)!; } } @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } + WKWebsiteDataStore pigeon_copy() { + return WKWebsiteDataStore.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); } } -/// Mirror of WKWebsiteDataStore. +/// An object that manages the content for a rectangular area on the screen. /// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore?language=objc. -class WKWebsiteDataStoreHostApi { - /// Constructor for [WKWebsiteDataStoreHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKWebsiteDataStoreHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - _WKWebsiteDataStoreHostApiCodec(); - - final String __pigeon_messageChannelSuffix; +/// See https://developer.apple.com/documentation/uikit/uiview. +class UIView extends NSObject { + /// Constructs [UIView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + UIView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecUIView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + UIView Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIView.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIView.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIView.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + UIView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } - Future createFromWebViewConfiguration( - int identifier, int configurationIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createFromWebViewConfiguration$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The view’s background color. + Future setBackgroundColor(int? value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIView.setBackgroundColor'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, configurationIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future createDefaultDataStore(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createDefaultDataStore$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that determines whether the view is opaque. + Future setOpaque(bool opaque) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIView.setOpaque'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, opaque]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeDataOfTypes( - int identifier, - List dataTypes, - double modificationTimeInSecondsSinceEpoch) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + @override + UIView pigeon_copy() { + return UIView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } +} + +/// A view that allows the scrolling and zooming of its contained views. +/// +/// See https://developer.apple.com/documentation/uikit/uiscrollview. +class UIScrollView extends UIView { + /// Constructs [UIScrollView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + UIScrollView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecUIScrollView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + UIScrollView Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + UIScrollView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + Future> getContentOffset() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIScrollView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.getContentOffset'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([ - identifier, - dataTypes, - modificationTimeInSecondsSinceEpoch - ]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as bool?)!; + return (pigeonVar_replyList[0] as List?)!.cast(); } } -} - -/// Mirror of UIView. -/// -/// See https://developer.apple.com/documentation/uikit/uiview?language=objc. -class UIViewHostApi { - /// Constructor for [UIViewHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - UIViewHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - final String __pigeon_messageChannelSuffix; + /// Move the scrolled position of your view. + /// + /// Convenience method to synchronize change to the x and y scroll position. + Future scrollBy( + double x, + double y, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIScrollView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.scrollBy'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, x, y]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } - Future setBackgroundColor(int identifier, int? value) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setBackgroundColor$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + Future setContentOffset( + double x, + double y, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIScrollView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.setContentOffset'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, value]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, x, y]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setOpaque(int identifier, bool opaque) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setOpaque$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The delegate of the scroll view. + Future setDelegate(UIScrollViewDelegate? delegate) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIScrollView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollView.setDelegate'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, opaque]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, delegate]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } -} - -/// Mirror of UIScrollView. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollview?language=objc. -class UIScrollViewHostApi { - /// Constructor for [UIScrollViewHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - UIScrollViewHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - final String __pigeon_messageChannelSuffix; - Future createFromWebView(int identifier, int webViewIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.createFromWebView$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + @override + UIScrollView pigeon_copy() { + return UIScrollView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } +} + +/// A collection of properties that you use to initialize a web view.. +/// +/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration. +class WKWebViewConfiguration extends NSObject { + WKWebViewConfiguration({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [WKWebViewConfiguration] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKWebViewConfiguration.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKWebViewConfiguration = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKWebViewConfiguration Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKWebViewConfiguration.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + Future setUserContentController( + WKUserContentController controller) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setUserContentController'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, webViewIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, controller]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future> getContentOffset(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.getContentOffset$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + Future getUserContentController() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getUserContentController'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as List?)!.cast(); + return (pigeonVar_replyList[0] as WKUserContentController?)!; } } - Future scrollBy(int identifier, double x, double y) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + Future setWebsiteDataStore(WKWebsiteDataStore dataStore) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setWebsiteDataStore'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, x, y]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, dataStore]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setContentOffset(int identifier, double x, double y) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + Future getWebsiteDataStore() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getWebsiteDataStore'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, x, y]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else { - return; - } - } - - Future setDelegate( - int identifier, int? uiScrollViewDelegateIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setDelegate$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, - ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, uiScrollViewDelegateIdentifier]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', ); } else { - return; - } - } -} - -class _WKWebViewConfigurationHostApiCodec extends StandardMessageCodec { - const _WKWebViewConfigurationHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKAudiovisualMediaTypeEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); + return (pigeonVar_replyList[0] as WKWebsiteDataStore?)!; } } -} - -/// Mirror of WKWebViewConfiguration. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -class WKWebViewConfigurationHostApi { - /// Constructor for [WKWebViewConfigurationHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKWebViewConfigurationHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - _WKWebViewConfigurationHostApiCodec(); - final String __pigeon_messageChannelSuffix; - - Future create(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object that manages the preference-related settings for the web view. + Future setPreferences(WKPreferences preferences) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setPreferences'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, preferences]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future createFromWebView(int identifier, int webViewIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.createFromWebView$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object that manages the preference-related settings for the web view. + Future getPreferences() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.getPreferences'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, webViewIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', ); } else { - return; + return (pigeonVar_replyList[0] as WKPreferences?)!; } } - Future setAllowsInlineMediaPlayback(int identifier, bool allow) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether HTML5 videos play inline or use the + /// native full-screen controller. + Future setAllowsInlineMediaPlayback(bool allow) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setAllowsInlineMediaPlayback'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, allow]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, allow]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setLimitsNavigationsToAppBoundDomains( - int identifier, bool limit) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setLimitsNavigationsToAppBoundDomains$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether the web view limits navigation to + /// pages within the app’s domain. + Future setLimitsNavigationsToAppBoundDomains(bool limit) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setLimitsNavigationsToAppBoundDomains'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, limit]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, limit]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } + /// The media types that require a user gesture to begin playing. Future setMediaTypesRequiringUserActionForPlayback( - int identifier, List types) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setMediaTypesRequiringUserActionForPlayback$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + AudiovisualMediaType type) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKWebViewConfiguration; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfiguration.setMediaTypesRequiringUserActionForPlayback'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, types]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, type]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } + + @override + WKWebViewConfiguration pigeon_copy() { + return WKWebViewConfiguration.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } } -/// Handles callbacks from a WKWebViewConfiguration instance. +/// An object for managing interactions between JavaScript code and your web +/// view, and for filtering content in your web view. /// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -abstract class WKWebViewConfigurationFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); - - static void setUp( - WKWebViewConfigurationFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', +/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller. +class WKUserContentController extends NSObject { + /// Constructs [WKUserContentController] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKUserContentController.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKUserContentController = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKUserContentController Function()? pigeon_newInstance, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationFlutterApi.create$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationFlutterApi.create was null, expected non-null int.'); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.pigeon_newInstance was null, expected non-null int.'); try { - api.create(arg_identifier!); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKUserContentController.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -1389,382 +3392,391 @@ abstract class WKWebViewConfigurationFlutterApi { } } } -} - -class _WKUserContentControllerHostApiCodec extends StandardMessageCodec { - const _WKUserContentControllerHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKUserScriptData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKUserScriptData.decode(readValue(buffer)!); - case 129: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKUserContentController. -/// -/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc. -class WKUserContentControllerHostApi { - /// Constructor for [WKUserContentControllerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKUserContentControllerHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - _WKUserContentControllerHostApiCodec(); - final String __pigeon_messageChannelSuffix; - - Future createFromWebViewConfiguration( - int identifier, int configurationIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.createFromWebViewConfiguration$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Installs a message handler that you can call from your JavaScript code. + Future addScriptMessageHandler( + WKScriptMessageHandler handler, + String name, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserContentController; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.addScriptMessageHandler'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, configurationIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, handler, name]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future addScriptMessageHandler( - int identifier, int handlerIdentifier, String name) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Uninstalls the custom message handler with the specified name from your + /// JavaScript code. + Future removeScriptMessageHandler(String name) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserContentController; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeScriptMessageHandler'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, handlerIdentifier, name]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, name]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeScriptMessageHandler(int identifier, String name) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeScriptMessageHandler$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Uninstalls all custom message handlers associated with the user content + /// controller. + Future removeAllScriptMessageHandlers() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserContentController; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeAllScriptMessageHandlers'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, name]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeAllScriptMessageHandlers(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllScriptMessageHandlers$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Injects the specified script into the webpage’s content. + Future addUserScript(WKUserScript userScript) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserContentController; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.addUserScript'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, userScript]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future addUserScript( - int identifier, WKUserScriptData userScript) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addUserScript$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Removes all user scripts from the web view. + Future removeAllUserScripts() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUserContentController; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentController.removeAllUserScripts'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, userScript]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeAllUserScripts(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllUserScripts$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + @override + WKUserContentController pigeon_copy() { + return WKUserContentController.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } } } -/// Mirror of WKUserPreferences. +/// An object that encapsulates the standard behaviors to apply to websites. /// -/// See https://developer.apple.com/documentation/webkit/wkpreferences?language=objc. -class WKPreferencesHostApi { - /// Constructor for [WKPreferencesHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKPreferencesHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - final String __pigeon_messageChannelSuffix; - - Future createFromWebViewConfiguration( - int identifier, int configurationIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.createFromWebViewConfiguration$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, - ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, configurationIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } - } - - Future setJavaScriptEnabled(int identifier, bool enabled) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.setJavaScriptEnabled$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, - ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, enabled]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; +/// See https://developer.apple.com/documentation/webkit/wkpreferences. +class WKPreferences extends NSObject { + /// Constructs [WKPreferences] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKPreferences.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWKPreferences = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKPreferences Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKPreferences.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } } } -} - -/// Mirror of WKScriptMessageHandler. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -class WKScriptMessageHandlerHostApi { - /// Constructor for [WKScriptMessageHandlerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKScriptMessageHandlerHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - final String __pigeon_messageChannelSuffix; - - Future create(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether JavaScript is enabled. + Future setJavaScriptEnabled(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKPreferences; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferences.setJavaScriptEnabled'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } -} - -class _WKScriptMessageHandlerFlutterApiCodec extends StandardMessageCodec { - const _WKScriptMessageHandlerFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKScriptMessageData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKScriptMessageData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } + WKPreferences pigeon_copy() { + return WKPreferences.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); } } -/// Handles callbacks from a WKScriptMessageHandler instance. +/// An interface for receiving messages from JavaScript code running in a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -abstract class WKScriptMessageHandlerFlutterApi { - static const MessageCodec pigeonChannelCodec = - _WKScriptMessageHandlerFlutterApiCodec(); - - void didReceiveScriptMessage(int identifier, - int userContentControllerIdentifier, WKScriptMessageData message); +/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler. +class WKScriptMessageHandler extends NSObject { + WKScriptMessageHandler({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required this.didReceiveScriptMessage, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKScriptMessageHandler; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - static void setUp( - WKScriptMessageHandlerFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', + /// Constructs [WKScriptMessageHandler] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKScriptMessageHandler.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required this.didReceiveScriptMessage, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKScriptMessageHandler = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Tells the handler that a webpage sent a script message. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKScriptMessageHandler instance = WKScriptMessageHandler( + /// didReceiveScriptMessage: (WKScriptMessageHandler pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKScriptMessageHandler pigeon_instance, + WKUserContentController controller, + WKScriptMessage message, + ) didReceiveScriptMessage; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + void Function( + WKScriptMessageHandler pigeon_instance, + WKUserContentController controller, + WKScriptMessage message, + )? didReceiveScriptMessage, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null int.'); - final int? arg_userContentControllerIdentifier = (args[1] as int?); - assert(arg_userContentControllerIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null int.'); - final WKScriptMessageData? arg_message = - (args[2] as WKScriptMessageData?); + final WKScriptMessageHandler? arg_pigeon_instance = + (args[0] as WKScriptMessageHandler?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage was null, expected non-null WKScriptMessageHandler.'); + final WKUserContentController? arg_controller = + (args[1] as WKUserContentController?); + assert(arg_controller != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage was null, expected non-null WKUserContentController.'); + final WKScriptMessage? arg_message = (args[2] as WKScriptMessage?); assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerFlutterApi.didReceiveScriptMessage was null, expected non-null WKScriptMessageData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandler.didReceiveScriptMessage was null, expected non-null WKScriptMessage.'); try { - api.didReceiveScriptMessage(arg_identifier!, - arg_userContentControllerIdentifier!, arg_message!); + (didReceiveScriptMessage ?? + arg_pigeon_instance!.didReceiveScriptMessage) + .call(arg_pigeon_instance!, arg_controller!, arg_message!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -1776,174 +3788,403 @@ abstract class WKScriptMessageHandlerFlutterApi { } } } -} - -/// Mirror of WKNavigationDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -class WKNavigationDelegateHostApi { - /// Constructor for [WKNavigationDelegateHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKNavigationDelegateHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - final String __pigeon_messageChannelSuffix; - - Future create(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + @override + WKScriptMessageHandler pigeon_copy() { + return WKScriptMessageHandler.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + didReceiveScriptMessage: didReceiveScriptMessage, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } } } -class _WKNavigationDelegateFlutterApiCodec extends StandardMessageCodec { - const _WKNavigationDelegateFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is AuthenticationChallengeResponse) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NSErrorData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is NSHttpUrlResponseData) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else if (value is NSUrlRequestData) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is WKFrameInfoData) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionData) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionPolicyEnumData) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationResponseData) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } +/// Methods for accepting or rejecting navigation changes, and for tracking the +/// progress of navigation requests. +/// +/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate. +class WKNavigationDelegate extends NSObject { + WKNavigationDelegate({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.didFinishNavigation, + this.didStartProvisionalNavigation, + this.decidePolicyForNavigationAction, + this.decidePolicyForNavigationResponse, + this.didFailNavigation, + this.didFailProvisionalNavigation, + this.webViewWebContentProcessDidTerminate, + this.didReceiveAuthenticationChallenge, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKNavigationDelegate; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); } - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return AuthenticationChallengeResponse.decode(readValue(buffer)!); - case 129: - return NSErrorData.decode(readValue(buffer)!); - case 130: - return NSHttpUrlResponseData.decode(readValue(buffer)!); - case 131: - return NSUrlRequestData.decode(readValue(buffer)!); - case 132: - return WKFrameInfoData.decode(readValue(buffer)!); - case 133: - return WKNavigationActionData.decode(readValue(buffer)!); - case 134: - return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); - case 135: - return WKNavigationResponseData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); + /// Constructs [WKNavigationDelegate] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKNavigationDelegate.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.didFinishNavigation, + this.didStartProvisionalNavigation, + this.decidePolicyForNavigationAction, + this.decidePolicyForNavigationResponse, + this.didFailNavigation, + this.didFailProvisionalNavigation, + this.webViewWebContentProcessDidTerminate, + this.didReceiveAuthenticationChallenge, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKNavigationDelegate = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Tells the delegate that navigation is complete. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// didFinishNavigation: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + String? url, + )? didFinishNavigation; + + /// Tells the delegate that navigation from the main frame has started. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// didStartProvisionalNavigation: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + String? url, + )? didStartProvisionalNavigation; + + /// Asks the delegate for permission to navigate to new content based on the + /// specified action information. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// decidePolicyForNavigationAction: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + WKNavigationAction navigationAction, + )? decidePolicyForNavigationAction; + + /// Asks the delegate for permission to navigate to new content after the + /// response to the navigation request is known. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// decidePolicyForNavigationResponse: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + WKNavigationResponse navigationResponse, + )? decidePolicyForNavigationResponse; + + /// Tells the delegate that an error occurred during navigation. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// didFailNavigation: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + NSError error, + )? didFailNavigation; + + /// Tells the delegate that an error occurred during the early navigation + /// process. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// didFailProvisionalNavigation: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + NSError error, + )? didFailProvisionalNavigation; + + /// Tells the delegate that the web view’s content process was terminated. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// webViewWebContentProcessDidTerminate: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + )? webViewWebContentProcessDidTerminate; + + /// Asks the delegate to respond to an authentication challenge. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKNavigationDelegate instance = WKNavigationDelegate( + /// didReceiveAuthenticationChallenge: (WKNavigationDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + URLAuthenticationChallenge challenge, + )? didReceiveAuthenticationChallenge; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKNavigationDelegate Function()? pigeon_newInstance, + void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + String? url, + )? didFinishNavigation, + void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + String? url, + )? didStartProvisionalNavigation, + Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + WKNavigationAction navigationAction, + )? decidePolicyForNavigationAction, + Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + WKNavigationResponse navigationResponse, + )? decidePolicyForNavigationResponse, + void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + NSError error, + )? didFailNavigation, + void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + NSError error, + )? didFailProvisionalNavigation, + void Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + )? webViewWebContentProcessDidTerminate, + Future Function( + WKNavigationDelegate pigeon_instance, + WKWebView webView, + URLAuthenticationChallenge challenge, + )? didReceiveAuthenticationChallenge, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKNavigationDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } } - } -} - -/// Handles callbacks from a WKNavigationDelegate instance. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -abstract class WKNavigationDelegateFlutterApi { - static const MessageCodec pigeonChannelCodec = - _WKNavigationDelegateFlutterApiCodec(); - - void didFinishNavigation(int identifier, int webViewIdentifier, String? url); - void didStartProvisionalNavigation( - int identifier, int webViewIdentifier, String? url); - - Future decidePolicyForNavigationAction( - int identifier, - int webViewIdentifier, - WKNavigationActionData navigationAction); - - Future decidePolicyForNavigationResponse( - int identifier, - int webViewIdentifier, - WKNavigationResponseData navigationResponse); - - void didFailNavigation( - int identifier, int webViewIdentifier, NSErrorData error); - - void didFailProvisionalNavigation( - int identifier, int webViewIdentifier, NSErrorData error); - - void webViewWebContentProcessDidTerminate( - int identifier, int webViewIdentifier); - - Future didReceiveAuthenticationChallenge( - int identifier, int webViewIdentifier, int challengeIdentifier); - - static void setUp( - WKNavigationDelegateFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFinishNavigation$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFinishNavigation', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFinishNavigation was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFinishNavigation was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFinishNavigation was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFinishNavigation was null, expected non-null int.'); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFinishNavigation was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFinishNavigation was null, expected non-null WKWebView.'); final String? arg_url = (args[2] as String?); try { - api.didFinishNavigation( - arg_identifier!, arg_webViewIdentifier!, arg_url); + (didFinishNavigation ?? arg_pigeon_instance!.didFinishNavigation) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -1954,29 +4195,33 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didStartProvisionalNavigation', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didStartProvisionalNavigation was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didStartProvisionalNavigation was null, expected non-null int.'); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didStartProvisionalNavigation was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didStartProvisionalNavigation was null, expected non-null WKWebView.'); final String? arg_url = (args[2] as String?); try { - api.didStartProvisionalNavigation( - arg_identifier!, arg_webViewIdentifier!, arg_url); + (didStartProvisionalNavigation ?? + arg_pigeon_instance!.didStartProvisionalNavigation) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -1987,33 +4232,38 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null int.'); - final WKNavigationActionData? arg_navigationAction = - (args[2] as WKNavigationActionData?); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction was null, expected non-null WKWebView.'); + final WKNavigationAction? arg_navigationAction = + (args[2] as WKNavigationAction?); assert(arg_navigationAction != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationAction was null, expected non-null WKNavigationActionData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationAction was null, expected non-null WKNavigationAction.'); try { - final WKNavigationActionPolicyEnumData output = - await api.decidePolicyForNavigationAction(arg_identifier!, - arg_webViewIdentifier!, arg_navigationAction!); + final NavigationActionPolicy? output = + await (decidePolicyForNavigationAction ?? + arg_pigeon_instance!.decidePolicyForNavigationAction) + ?.call(arg_pigeon_instance!, arg_webView!, + arg_navigationAction!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2024,34 +4274,39 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse was null, expected non-null int.'); - final WKNavigationResponseData? arg_navigationResponse = - (args[2] as WKNavigationResponseData?); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse was null, expected non-null WKWebView.'); + final WKNavigationResponse? arg_navigationResponse = + (args[2] as WKNavigationResponse?); assert(arg_navigationResponse != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.decidePolicyForNavigationResponse was null, expected non-null WKNavigationResponseData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.decidePolicyForNavigationResponse was null, expected non-null WKNavigationResponse.'); try { - final WKNavigationResponsePolicyEnum output = - await api.decidePolicyForNavigationResponse(arg_identifier!, - arg_webViewIdentifier!, arg_navigationResponse!); - return wrapResponse(result: output.index); + final NavigationResponsePolicy? output = + await (decidePolicyForNavigationResponse ?? + arg_pigeon_instance!.decidePolicyForNavigationResponse) + ?.call(arg_pigeon_instance!, arg_webView!, + arg_navigationResponse!); + return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); } catch (e) { @@ -2061,31 +4316,34 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailNavigation$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailNavigation was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null int.'); - final NSErrorData? arg_error = (args[2] as NSErrorData?); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation was null, expected non-null WKWebView.'); + final NSError? arg_error = (args[2] as NSError?); assert(arg_error != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailNavigation was null, expected non-null NSErrorData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailNavigation was null, expected non-null NSError.'); try { - api.didFailNavigation( - arg_identifier!, arg_webViewIdentifier!, arg_error!); + (didFailNavigation ?? arg_pigeon_instance!.didFailNavigation) + ?.call(arg_pigeon_instance!, arg_webView!, arg_error!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2096,31 +4354,35 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null int.'); - final NSErrorData? arg_error = (args[2] as NSErrorData?); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation was null, expected non-null WKWebView.'); + final NSError? arg_error = (args[2] as NSError?); assert(arg_error != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didFailProvisionalNavigation was null, expected non-null NSErrorData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didFailProvisionalNavigation was null, expected non-null NSError.'); try { - api.didFailProvisionalNavigation( - arg_identifier!, arg_webViewIdentifier!, arg_error!); + (didFailProvisionalNavigation ?? + arg_pigeon_instance!.didFailProvisionalNavigation) + ?.call(arg_pigeon_instance!, arg_webView!, arg_error!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2131,28 +4393,32 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.webViewWebContentProcessDidTerminate', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.webViewWebContentProcessDidTerminate was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.webViewWebContentProcessDidTerminate was null, expected non-null int.'); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.webViewWebContentProcessDidTerminate was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.webViewWebContentProcessDidTerminate was null, expected non-null WKWebView.'); try { - api.webViewWebContentProcessDidTerminate( - arg_identifier!, arg_webViewIdentifier!); + (webViewWebContentProcessDidTerminate ?? + arg_pigeon_instance!.webViewWebContentProcessDidTerminate) + ?.call(arg_pigeon_instance!, arg_webView!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2163,32 +4429,37 @@ abstract class WKNavigationDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge was null, expected non-null int.'); - final int? arg_challengeIdentifier = (args[2] as int?); - assert(arg_challengeIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateFlutterApi.didReceiveAuthenticationChallenge was null, expected non-null int.'); + final WKNavigationDelegate? arg_pigeon_instance = + (args[0] as WKNavigationDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge was null, expected non-null WKNavigationDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge was null, expected non-null WKWebView.'); + final URLAuthenticationChallenge? arg_challenge = + (args[2] as URLAuthenticationChallenge?); + assert(arg_challenge != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegate.didReceiveAuthenticationChallenge was null, expected non-null URLAuthenticationChallenge.'); try { - final AuthenticationChallengeResponse output = - await api.didReceiveAuthenticationChallenge(arg_identifier!, - arg_webViewIdentifier!, arg_challengeIdentifier!); + final AuthenticationChallengeResponse? output = + await (didReceiveAuthenticationChallenge ?? + arg_pigeon_instance!.didReceiveAuthenticationChallenge) + ?.call(arg_pigeon_instance!, arg_webView!, arg_challenge!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2200,239 +4471,1126 @@ abstract class WKNavigationDelegateFlutterApi { } } } -} -class _NSObjectHostApiCodec extends StandardMessageCodec { - const _NSObjectHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSKeyValueObservingOptionsEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); + @override + WKNavigationDelegate pigeon_copy() { + return WKNavigationDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + didFinishNavigation: didFinishNavigation, + didStartProvisionalNavigation: didStartProvisionalNavigation, + decidePolicyForNavigationAction: decidePolicyForNavigationAction, + decidePolicyForNavigationResponse: decidePolicyForNavigationResponse, + didFailNavigation: didFailNavigation, + didFailProvisionalNavigation: didFailProvisionalNavigation, + webViewWebContentProcessDidTerminate: + webViewWebContentProcessDidTerminate, + didReceiveAuthenticationChallenge: didReceiveAuthenticationChallenge, + ); + } +} + +/// The root class of most Objective-C class hierarchies, from which subclasses +/// inherit a basic interface to the runtime system and the ability to behave as +/// Objective-C objects. +/// +/// See https://developer.apple.com/documentation/objectivec/nsobject. +class NSObject extends PigeonInternalProxyApiBaseClass { + NSObject({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.observeValue, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSObject; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [NSObject] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + NSObject.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.observeValue, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecNSObject = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Informs the observing object when the value at the specified key path + /// relative to the observed object has changed. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final NSObject instance = NSObject( + /// observeValue: (NSObject pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + NSObject pigeon_instance, + String? keyPath, + NSObject? object, + Map? change, + )? observeValue; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + NSObject Function()? pigeon_newInstance, + void Function( + NSObject pigeon_instance, + String? keyPath, + NSObject? object, + Map? change, + )? observeValue, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + NSObject.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.observeValue', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.observeValue was null.'); + final List args = (message as List?)!; + final NSObject? arg_pigeon_instance = (args[0] as NSObject?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.observeValue was null, expected non-null NSObject.'); + final String? arg_keyPath = (args[1] as String?); + final NSObject? arg_object = (args[2] as NSObject?); + final Map? arg_change = + (args[3] as Map?) + ?.cast(); + try { + (observeValue ?? arg_pigeon_instance!.observeValue)?.call( + arg_pigeon_instance!, arg_keyPath, arg_object, arg_change); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Registers the observer object to receive KVO notifications for the key + /// path relative to the object receiving this message. + Future addObserver( + NSObject observer, + String keyPath, + List options, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSObject; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.addObserver'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, observer, keyPath, options]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Stops the observer object from receiving change notifications for the + /// property specified by the key path relative to the object receiving this + /// message. + Future removeObserver( + NSObject observer, + String keyPath, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSObject; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObject.removeObserver'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, observer, keyPath]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + NSObject pigeon_copy() { + return NSObject.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } +} + +/// An object that displays interactive web content, such as for an in-app +/// browser. +/// +/// See https://developer.apple.com/documentation/webkit/wkwebview. +class UIViewWKWebView extends UIView implements WKWebView { + UIViewWKWebView({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required WKWebViewConfiguration initialConfiguration, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel.send( + [pigeonVar_instanceIdentifier, initialConfiguration]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [UIViewWKWebView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + UIViewWKWebView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecUIViewWKWebView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The object that contains the configuration details for the web view. + late final WKWebViewConfiguration configuration = pigeonVar_configuration(); + + /// The scroll view associated with the web view. + late final UIScrollView scrollView = pigeonVar_scrollView(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + UIViewWKWebView Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + UIViewWKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + WKWebViewConfiguration pigeonVar_configuration() { + final WKWebViewConfiguration pigeonVar_instance = + WKWebViewConfiguration.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.configuration'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, pigeonVar_instanceIdentifier]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + UIScrollView pigeonVar_scrollView() { + final UIScrollView pigeonVar_instance = UIScrollView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.scrollView'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, pigeonVar_instanceIdentifier]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + Future setUIDelegate(WKUIDelegate delegate) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setUIDelegate'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, delegate]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// The object you use to manage navigation behavior for the web view. + Future setNavigationDelegate(WKNavigationDelegate delegate) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setNavigationDelegate'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, delegate]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// The URL for the current webpage. + Future getUrl() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } + } + + /// An estimate of what fraction of the current navigation has been loaded. + Future getEstimatedProgress() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getEstimatedProgress'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as double?)!; + } + } + + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + Future load(URLRequest request) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.load'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, request]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Loads the contents of the specified HTML string and navigates to it. + Future loadHtmlString( + String string, + String? baseUrl, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadHtmlString'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, string, baseUrl]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Loads the web content from the specified file and navigates to it. + Future loadFileUrl( + String url, + String readAccessUrl, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadFileUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, url, readAccessUrl]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Convenience method to load a Flutter asset. + Future loadFlutterAsset(String key) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.loadFlutterAsset'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + Future canGoBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.canGoBack'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); } else { - super.writeValue(buffer, value); + return (pigeonVar_replyList[0] as bool?)!; } } - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + Future canGoForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.canGoForward'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; } } -} -/// Mirror of NSObject. -/// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -class NSObjectHostApi { - /// Constructor for [NSObjectHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - NSObjectHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; + /// Navigates to the back item in the back-forward list. + Future goBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.goBack'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Navigates to the forward item in the back-forward list. + Future goForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.goForward'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } - static const MessageCodec pigeonChannelCodec = - _NSObjectHostApiCodec(); + /// Reloads the current webpage. + Future reload() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.reload'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } - final String __pigeon_messageChannelSuffix; + /// The page title. + Future getTitle() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getTitle'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } + } - Future dispose(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.dispose$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + Future setAllowsBackForwardNavigationGestures(bool allow) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setAllowsBackForwardNavigationGestures'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, allow]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future addObserver(int identifier, int observerIdentifier, - String keyPath, List options) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The custom user agent string. + Future setCustomUserAgent(String? userAgent) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setCustomUserAgent'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, observerIdentifier, keyPath, options]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, userAgent]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeObserver( - int identifier, int observerIdentifier, String keyPath) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Evaluates the specified JavaScript string. + Future evaluateJavaScript(String javaScriptString) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.evaluateJavaScript'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, observerIdentifier, keyPath]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, javaScriptString]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return pigeonVar_replyList[0]; + } + } + + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + Future setInspectable(bool inspectable) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setInspectable'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, inspectable]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } -} -class _NSObjectFlutterApiCodec extends StandardMessageCodec { - const _NSObjectFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSKeyValueChangeKeyEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is ObjectOrIdentifier) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); + /// The custom user agent string. + Future getCustomUserAgent() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.getCustomUserAgent'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); } else { - super.writeValue(buffer, value); + return (pigeonVar_replyList[0] as String?); } } @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); - case 129: - return ObjectOrIdentifier.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } + UIViewWKWebView pigeon_copy() { + return UIViewWKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); } } -/// Handles callbacks from an NSObject instance. +/// An object that displays interactive web content, such as for an in-app +/// browser. /// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -abstract class NSObjectFlutterApi { - static const MessageCodec pigeonChannelCodec = - _NSObjectFlutterApiCodec(); - - void observeValue( - int identifier, - String keyPath, - int objectIdentifier, - List changeKeys, - List changeValues); - - void dispose(int identifier); - - static void setUp( - NSObjectFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); +/// See https://developer.apple.com/documentation/webkit/wkwebview. +class NSViewWKWebView extends NSObject implements WKWebView { + NSViewWKWebView({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required WKWebViewConfiguration initialConfiguration, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel.send( + [pigeonVar_instanceIdentifier, initialConfiguration]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); } else { - __pigeon_channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null, expected non-null int.'); - final String? arg_keyPath = (args[1] as String?); - assert(arg_keyPath != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null, expected non-null String.'); - final int? arg_objectIdentifier = (args[2] as int?); - assert(arg_objectIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null, expected non-null int.'); - final List? arg_changeKeys = - (args[3] as List?)?.cast(); - assert(arg_changeKeys != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null, expected non-null List.'); - final List? arg_changeValues = - (args[4] as List?)?.cast(); - assert(arg_changeValues != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.observeValue was null, expected non-null List.'); - try { - api.observeValue(arg_identifier!, arg_keyPath!, - arg_objectIdentifier!, arg_changeKeys!, arg_changeValues!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); + return; } - } + }(); + } + + /// Constructs [NSViewWKWebView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + NSViewWKWebView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecNSViewWKWebView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The object that contains the configuration details for the web view. + late final WKWebViewConfiguration configuration = pigeonVar_configuration(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + NSViewWKWebView Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.dispose$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.dispose was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectFlutterApi.dispose was null, expected non-null int.'); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.pigeon_newInstance was null, expected non-null int.'); try { - api.dispose(arg_identifier!); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + NSViewWKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -2444,810 +5602,1000 @@ abstract class NSObjectFlutterApi { } } } -} - -class _WKWebViewHostApiCodec extends StandardMessageCodec { - const _WKWebViewHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is AuthenticationChallengeResponse) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NSErrorData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookieData) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is NSHttpUrlResponseData) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is NSKeyValueChangeKeyEnumData) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else if (value is NSKeyValueObservingOptionsEnumData) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is NSUrlRequestData) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else if (value is ObjectOrIdentifier) { - buffer.putUint8(136); - writeValue(buffer, value.encode()); - } else if (value is WKAudiovisualMediaTypeEnumData) { - buffer.putUint8(137); - writeValue(buffer, value.encode()); - } else if (value is WKFrameInfoData) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); - } else if (value is WKMediaCaptureTypeData) { - buffer.putUint8(139); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionData) { - buffer.putUint8(140); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionPolicyEnumData) { - buffer.putUint8(141); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationResponseData) { - buffer.putUint8(142); - writeValue(buffer, value.encode()); - } else if (value is WKPermissionDecisionData) { - buffer.putUint8(143); - writeValue(buffer, value.encode()); - } else if (value is WKScriptMessageData) { - buffer.putUint8(144); - writeValue(buffer, value.encode()); - } else if (value is WKSecurityOriginData) { - buffer.putUint8(145); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptData) { - buffer.putUint8(146); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { - buffer.putUint8(147); - writeValue(buffer, value.encode()); - } else if (value is WKWebsiteDataTypeEnumData) { - buffer.putUint8(148); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return AuthenticationChallengeResponse.decode(readValue(buffer)!); - case 129: - return NSErrorData.decode(readValue(buffer)!); - case 130: - return NSHttpCookieData.decode(readValue(buffer)!); - case 131: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); - case 132: - return NSHttpUrlResponseData.decode(readValue(buffer)!); - case 133: - return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); - case 134: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); - case 135: - return NSUrlRequestData.decode(readValue(buffer)!); - case 136: - return ObjectOrIdentifier.decode(readValue(buffer)!); - case 137: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); - case 138: - return WKFrameInfoData.decode(readValue(buffer)!); - case 139: - return WKMediaCaptureTypeData.decode(readValue(buffer)!); - case 140: - return WKNavigationActionData.decode(readValue(buffer)!); - case 141: - return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); - case 142: - return WKNavigationResponseData.decode(readValue(buffer)!); - case 143: - return WKPermissionDecisionData.decode(readValue(buffer)!); - case 144: - return WKScriptMessageData.decode(readValue(buffer)!); - case 145: - return WKSecurityOriginData.decode(readValue(buffer)!); - case 146: - return WKUserScriptData.decode(readValue(buffer)!); - case 147: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); - case 148: - return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKWebView. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebview?language=objc. -class WKWebViewHostApi { - /// Constructor for [WKWebViewHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKWebViewHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - _WKWebViewHostApiCodec(); - final String __pigeon_messageChannelSuffix; - - Future create(int identifier, int configurationIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + WKWebViewConfiguration pigeonVar_configuration() { + final WKWebViewConfiguration pigeonVar_instance = + WKWebViewConfiguration.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, configurationIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.configuration'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, ); - } else { - return; - } + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, pigeonVar_instanceIdentifier]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; } - Future setUIDelegate(int identifier, int? uiDelegateIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setUIDelegate$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + Future setUIDelegate(WKUIDelegate delegate) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setUIDelegate'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, uiDelegateIdentifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, delegate]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setNavigationDelegate( - int identifier, int? navigationDelegateIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setNavigationDelegate$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The object you use to manage navigation behavior for the web view. + Future setNavigationDelegate(WKNavigationDelegate delegate) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setNavigationDelegate'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, navigationDelegateIdentifier]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, delegate]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future getUrl(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getUrl$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The URL for the current webpage. + Future getUrl() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getUrl'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (__pigeon_replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } - Future getEstimatedProgress(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getEstimatedProgress$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// An estimate of what fraction of the current navigation has been loaded. + Future getEstimatedProgress() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getEstimatedProgress'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as double?)!; + return (pigeonVar_replyList[0] as double?)!; } } - Future loadRequest(int identifier, NSUrlRequestData request) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadRequest$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + Future load(URLRequest request) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.load'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, request]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, request]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } + /// Loads the contents of the specified HTML string and navigates to it. Future loadHtmlString( - int identifier, String string, String? baseUrl) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadHtmlString$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + String string, + String? baseUrl, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadHtmlString'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, string, baseUrl]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, string, baseUrl]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } + /// Loads the web content from the specified file and navigates to it. Future loadFileUrl( - int identifier, String url, String readAccessUrl) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + String url, + String readAccessUrl, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadFileUrl'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, url, readAccessUrl]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, url, readAccessUrl]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future loadFlutterAsset(int identifier, String key) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFlutterAsset$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Convenience method to load a Flutter asset. + Future loadFlutterAsset(String key) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.loadFlutterAsset'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, key]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future canGoBack(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoBack$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + Future canGoBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.canGoBack'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as bool?)!; + return (pigeonVar_replyList[0] as bool?)!; } } - Future canGoForward(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoForward$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + Future canGoForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.canGoForward'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as bool?)!; + return (pigeonVar_replyList[0] as bool?)!; } } - Future goBack(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goBack$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Navigates to the back item in the back-forward list. + Future goBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.goBack'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future goForward(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goForward$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Navigates to the forward item in the back-forward list. + Future goForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.goForward'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future reload(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.reload$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Reloads the current webpage. + Future reload() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.reload'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future getTitle(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getTitle$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The page title. + Future getTitle() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getTitle'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (__pigeon_replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } - Future setAllowsBackForwardNavigationGestures( - int identifier, bool allow) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setAllowsBackForwardNavigationGestures$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + Future setAllowsBackForwardNavigationGestures(bool allow) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setAllowsBackForwardNavigationGestures'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, allow]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, allow]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setCustomUserAgent(int identifier, String? userAgent) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setCustomUserAgent$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The custom user agent string. + Future setCustomUserAgent(String? userAgent) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setCustomUserAgent'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, userAgent]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, userAgent]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future evaluateJavaScript( - int identifier, String javaScriptString) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.evaluateJavaScript$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Evaluates the specified JavaScript string. + Future evaluateJavaScript(String javaScriptString) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.evaluateJavaScript'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, javaScriptString]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, javaScriptString]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return __pigeon_replyList[0]; + return pigeonVar_replyList[0]; } } - Future setInspectable(int identifier, bool inspectable) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setInspectable$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + Future setInspectable(bool inspectable) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setInspectable'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, inspectable]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, inspectable]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future getCustomUserAgent(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getCustomUserAgent$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// The custom user agent string. + Future getCustomUserAgent() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecNSViewWKWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.getCustomUserAgent'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (__pigeon_replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } -} - -/// Mirror of WKUIDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -class WKUIDelegateHostApi { - /// Constructor for [WKUIDelegateHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKUIDelegateHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - final String __pigeon_messageChannelSuffix; - - Future create(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + @override + NSViewWKWebView pigeon_copy() { + return NSViewWKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } } } -class _WKUIDelegateFlutterApiCodec extends StandardMessageCodec { - const _WKUIDelegateFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSUrlRequestData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is WKFrameInfoData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is WKMediaCaptureTypeData) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionData) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is WKPermissionDecisionData) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is WKSecurityOriginData) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); +/// An object that displays interactive web content, such as for an in-app +/// browser. +/// +/// See https://developer.apple.com/documentation/webkit/wkwebview. +class WKWebView extends NSObject { + /// Constructs [WKWebView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKWebView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKWebView Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebView.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebView.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebView.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } } } @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSUrlRequestData.decode(readValue(buffer)!); - case 129: - return WKFrameInfoData.decode(readValue(buffer)!); - case 130: - return WKMediaCaptureTypeData.decode(readValue(buffer)!); - case 131: - return WKNavigationActionData.decode(readValue(buffer)!); - case 132: - return WKPermissionDecisionData.decode(readValue(buffer)!); - case 133: - return WKSecurityOriginData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } + WKWebView pigeon_copy() { + return WKWebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } +} + +/// The methods for presenting native user interface elements on behalf of a +/// webpage. +/// +/// See https://developer.apple.com/documentation/webkit/wkuidelegate. +class WKUIDelegate extends NSObject { + WKUIDelegate({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.onCreateWebView, + this.requestMediaCapturePermission, + this.runJavaScriptAlertPanel, + this.runJavaScriptConfirmPanel, + this.runJavaScriptTextInputPanel, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKUIDelegate; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); } -} -/// Handles callbacks from a WKUIDelegate instance. -/// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -abstract class WKUIDelegateFlutterApi { - static const MessageCodec pigeonChannelCodec = - _WKUIDelegateFlutterApiCodec(); - - void onCreateWebView(int identifier, int webViewIdentifier, - int configurationIdentifier, WKNavigationActionData navigationAction); - - /// Callback to Dart function `WKUIDelegate.requestMediaCapturePermission`. - Future requestMediaCapturePermission( - int identifier, - int webViewIdentifier, - WKSecurityOriginData origin, - WKFrameInfoData frame, - WKMediaCaptureTypeData type); - - /// Callback to Dart function `WKUIDelegate.runJavaScriptAlertPanel`. - Future runJavaScriptAlertPanel( - int identifier, String message, WKFrameInfoData frame); - - /// Callback to Dart function `WKUIDelegate.runJavaScriptConfirmPanel`. - Future runJavaScriptConfirmPanel( - int identifier, String message, WKFrameInfoData frame); - - /// Callback to Dart function `WKUIDelegate.runJavaScriptTextInputPanel`. - Future runJavaScriptTextInputPanel( - int identifier, String prompt, String defaultText, WKFrameInfoData frame); - - static void setUp( - WKUIDelegateFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', + /// Constructs [WKUIDelegate] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKUIDelegate.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.onCreateWebView, + this.requestMediaCapturePermission, + this.runJavaScriptAlertPanel, + this.runJavaScriptConfirmPanel, + this.runJavaScriptTextInputPanel, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWKUIDelegate = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Creates a new web view. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKUIDelegate instance = WKUIDelegate( + /// onCreateWebView: (WKUIDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + )? onCreateWebView; + + /// Determines whether a web resource, which the security origin object + /// describes, can access to the device’s microphone audio and camera video. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKUIDelegate instance = WKUIDelegate( + /// requestMediaCapturePermission: (WKUIDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + WKSecurityOrigin origin, + WKFrameInfo frame, + MediaCaptureType type, + )? requestMediaCapturePermission; + + /// Displays a JavaScript alert panel. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKUIDelegate instance = WKUIDelegate( + /// runJavaScriptAlertPanel: (WKUIDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String message, + WKFrameInfo frame, + )? runJavaScriptAlertPanel; + + /// Displays a JavaScript confirm panel. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKUIDelegate instance = WKUIDelegate( + /// runJavaScriptConfirmPanel: (WKUIDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String message, + WKFrameInfo frame, + )? runJavaScriptConfirmPanel; + + /// Displays a JavaScript text input panel. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WKUIDelegate instance = WKUIDelegate( + /// runJavaScriptTextInputPanel: (WKUIDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String prompt, + String? defaultText, + WKFrameInfo frame, + )? runJavaScriptTextInputPanel; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKUIDelegate Function()? pigeon_newInstance, + void Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + )? onCreateWebView, + Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + WKSecurityOrigin origin, + WKFrameInfo frame, + MediaCaptureType type, + )? requestMediaCapturePermission, + Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String message, + WKFrameInfo frame, + )? runJavaScriptAlertPanel, + Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String message, + WKFrameInfo frame, + )? runJavaScriptConfirmPanel, + Future Function( + WKUIDelegate pigeon_instance, + WKWebView webView, + String prompt, + String? defaultText, + WKFrameInfo frame, + )? runJavaScriptTextInputPanel, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); - final int? arg_configurationIdentifier = (args[2] as int?); - assert(arg_configurationIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null int.'); - final WKNavigationActionData? arg_navigationAction = - (args[3] as WKNavigationActionData?); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKUIDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView was null.'); + final List args = (message as List?)!; + final WKUIDelegate? arg_pigeon_instance = (args[0] as WKUIDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView was null, expected non-null WKUIDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView was null, expected non-null WKWebView.'); + final WKWebViewConfiguration? arg_configuration = + (args[2] as WKWebViewConfiguration?); + assert(arg_configuration != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView was null, expected non-null WKWebViewConfiguration.'); + final WKNavigationAction? arg_navigationAction = + (args[3] as WKNavigationAction?); assert(arg_navigationAction != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.onCreateWebView was null, expected non-null WKNavigationActionData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.onCreateWebView was null, expected non-null WKNavigationAction.'); try { - api.onCreateWebView(arg_identifier!, arg_webViewIdentifier!, - arg_configurationIdentifier!, arg_navigationAction!); + (onCreateWebView ?? arg_pigeon_instance!.onCreateWebView)?.call( + arg_pigeon_instance!, + arg_webView!, + arg_configuration!, + arg_navigationAction!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3258,40 +6606,42 @@ abstract class WKUIDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null, expected non-null int.'); - final WKSecurityOriginData? arg_origin = - (args[2] as WKSecurityOriginData?); + final WKUIDelegate? arg_pigeon_instance = (args[0] as WKUIDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null, expected non-null WKUIDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null, expected non-null WKWebView.'); + final WKSecurityOrigin? arg_origin = (args[2] as WKSecurityOrigin?); assert(arg_origin != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null, expected non-null WKSecurityOriginData.'); - final WKFrameInfoData? arg_frame = (args[3] as WKFrameInfoData?); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null, expected non-null WKSecurityOrigin.'); + final WKFrameInfo? arg_frame = (args[3] as WKFrameInfo?); assert(arg_frame != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null, expected non-null WKFrameInfoData.'); - final WKMediaCaptureTypeData? arg_type = - (args[4] as WKMediaCaptureTypeData?); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null, expected non-null WKFrameInfo.'); + final MediaCaptureType? arg_type = (args[4] as MediaCaptureType?); assert(arg_type != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.requestMediaCapturePermission was null, expected non-null WKMediaCaptureTypeData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.requestMediaCapturePermission was null, expected non-null MediaCaptureType.'); try { - final WKPermissionDecisionData output = - await api.requestMediaCapturePermission(arg_identifier!, - arg_webViewIdentifier!, arg_origin!, arg_frame!, arg_type!); + final PermissionDecision? output = + await (requestMediaCapturePermission ?? + arg_pigeon_instance!.requestMediaCapturePermission) + ?.call(arg_pigeon_instance!, arg_webView!, arg_origin!, + arg_frame!, arg_type!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3302,31 +6652,38 @@ abstract class WKUIDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptAlertPanel$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptAlertPanel was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptAlertPanel was null, expected non-null int.'); - final String? arg_message = (args[1] as String?); + final WKUIDelegate? arg_pigeon_instance = (args[0] as WKUIDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel was null, expected non-null WKUIDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel was null, expected non-null WKWebView.'); + final String? arg_message = (args[2] as String?); assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptAlertPanel was null, expected non-null String.'); - final WKFrameInfoData? arg_frame = (args[2] as WKFrameInfoData?); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel was null, expected non-null String.'); + final WKFrameInfo? arg_frame = (args[3] as WKFrameInfo?); assert(arg_frame != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptAlertPanel was null, expected non-null WKFrameInfoData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptAlertPanel was null, expected non-null WKFrameInfo.'); try { - await api.runJavaScriptAlertPanel( - arg_identifier!, arg_message!, arg_frame!); + await (runJavaScriptAlertPanel ?? + arg_pigeon_instance!.runJavaScriptAlertPanel) + ?.call(arg_pigeon_instance!, arg_webView!, arg_message!, + arg_frame!); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3337,31 +6694,38 @@ abstract class WKUIDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptConfirmPanel$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptConfirmPanel was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptConfirmPanel was null, expected non-null int.'); - final String? arg_message = (args[1] as String?); + final WKUIDelegate? arg_pigeon_instance = (args[0] as WKUIDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel was null, expected non-null WKUIDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel was null, expected non-null WKWebView.'); + final String? arg_message = (args[2] as String?); assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptConfirmPanel was null, expected non-null String.'); - final WKFrameInfoData? arg_frame = (args[2] as WKFrameInfoData?); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel was null, expected non-null String.'); + final WKFrameInfo? arg_frame = (args[3] as WKFrameInfo?); assert(arg_frame != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptConfirmPanel was null, expected non-null WKFrameInfoData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptConfirmPanel was null, expected non-null WKFrameInfo.'); try { - final bool output = await api.runJavaScriptConfirmPanel( - arg_identifier!, arg_message!, arg_frame!); + final bool? output = await (runJavaScriptConfirmPanel ?? + arg_pigeon_instance!.runJavaScriptConfirmPanel) + ?.call(arg_pigeon_instance!, arg_webView!, arg_message!, + arg_frame!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3372,34 +6736,39 @@ abstract class WKUIDelegateFlutterApi { }); } } + { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel was null, expected non-null int.'); - final String? arg_prompt = (args[1] as String?); + final WKUIDelegate? arg_pigeon_instance = (args[0] as WKUIDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel was null, expected non-null WKUIDelegate.'); + final WKWebView? arg_webView = (args[1] as WKWebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel was null, expected non-null WKWebView.'); + final String? arg_prompt = (args[2] as String?); assert(arg_prompt != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel was null, expected non-null String.'); - final String? arg_defaultText = (args[2] as String?); - assert(arg_defaultText != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel was null, expected non-null String.'); - final WKFrameInfoData? arg_frame = (args[3] as WKFrameInfoData?); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel was null, expected non-null String.'); + final String? arg_defaultText = (args[3] as String?); + final WKFrameInfo? arg_frame = (args[4] as WKFrameInfo?); assert(arg_frame != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateFlutterApi.runJavaScriptTextInputPanel was null, expected non-null WKFrameInfoData.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegate.runJavaScriptTextInputPanel was null, expected non-null WKFrameInfo.'); try { - final String output = await api.runJavaScriptTextInputPanel( - arg_identifier!, arg_prompt!, arg_defaultText!, arg_frame!); + final String? output = await (runJavaScriptTextInputPanel ?? + arg_pigeon_instance!.runJavaScriptTextInputPanel) + ?.call(arg_pigeon_instance!, arg_webView!, arg_prompt!, + arg_defaultText, arg_frame!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3411,192 +6780,424 @@ abstract class WKUIDelegateFlutterApi { } } } -} - -class _WKHttpCookieStoreHostApiCodec extends StandardMessageCodec { - const _WKHttpCookieStoreHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSHttpCookieData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSHttpCookieData.decode(readValue(buffer)!); - case 129: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } + WKUIDelegate pigeon_copy() { + return WKUIDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + onCreateWebView: onCreateWebView, + requestMediaCapturePermission: requestMediaCapturePermission, + runJavaScriptAlertPanel: runJavaScriptAlertPanel, + runJavaScriptConfirmPanel: runJavaScriptConfirmPanel, + runJavaScriptTextInputPanel: runJavaScriptTextInputPanel, + ); } } -/// Mirror of WKHttpCookieStore. +/// An object that manages the HTTP cookies associated with a particular web +/// view. /// -/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc. -class WKHttpCookieStoreHostApi { - /// Constructor for [WKHttpCookieStoreHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WKHttpCookieStoreHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - _WKHttpCookieStoreHostApiCodec(); - - final String __pigeon_messageChannelSuffix; - - Future createFromWebsiteDataStore( - int identifier, int websiteDataStoreIdentifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.createFromWebsiteDataStore$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, - ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, websiteDataStoreIdentifier]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; +/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore. +class WKHTTPCookieStore extends NSObject { + /// Constructs [WKHTTPCookieStore] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WKHTTPCookieStore.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecWKHTTPCookieStore = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WKHTTPCookieStore Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WKHTTPCookieStore.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } } } - Future setCookie(int identifier, NSHttpCookieData cookie) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.setCookie$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + /// Sets a cookie policy that indicates whether the cookie store allows cookie + /// storage. + Future setCookie(HTTPCookie cookie) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWKHTTPCookieStore; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHTTPCookieStore.setCookie'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, cookie]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, cookie]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } + + @override + WKHTTPCookieStore pigeon_copy() { + return WKHTTPCookieStore.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } } -/// Host API for `NSUrl`. +/// The interface for the delegate of a scroll view. /// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -class NSUrlHostApi { - /// Constructor for [NSUrlHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - NSUrlHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; +/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate. +class UIScrollViewDelegate extends NSObject { + UIScrollViewDelegate({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.scrollViewDidScroll, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecUIScrollViewDelegate; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + /// Constructs [UIScrollViewDelegate] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + UIScrollViewDelegate.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + this.scrollViewDidScroll, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecUIScrollViewDelegate = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Tells the delegate when the user scrolls the content view within the + /// scroll view. + /// + /// Note that this is a convenient method that includes the `contentOffset` of + /// the `scrollView`. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final UIScrollViewDelegate instance = UIScrollViewDelegate( + /// scrollViewDidScroll: (UIScrollViewDelegate pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + UIScrollViewDelegate pigeon_instance, + UIScrollView scrollView, + double x, + double y, + )? scrollViewDidScroll; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + UIScrollViewDelegate Function()? pigeon_newInstance, + void Function( + UIScrollViewDelegate pigeon_instance, + UIScrollView scrollView, + double x, + double y, + )? scrollViewDidScroll, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + UIScrollViewDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } - final String __pigeon_messageChannelSuffix; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll was null.'); + final List args = (message as List?)!; + final UIScrollViewDelegate? arg_pigeon_instance = + (args[0] as UIScrollViewDelegate?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll was null, expected non-null UIScrollViewDelegate.'); + final UIScrollView? arg_scrollView = (args[1] as UIScrollView?); + assert(arg_scrollView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll was null, expected non-null UIScrollView.'); + final double? arg_x = (args[2] as double?); + assert(arg_x != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll was null, expected non-null double.'); + final double? arg_y = (args[3] as double?); + assert(arg_y != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegate.scrollViewDidScroll was null, expected non-null double.'); + try { + (scrollViewDidScroll ?? arg_pigeon_instance!.scrollViewDidScroll) + ?.call(arg_pigeon_instance!, arg_scrollView!, arg_x!, arg_y!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } - Future getAbsoluteString(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlHostApi.getAbsoluteString$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + @override + UIScrollViewDelegate pigeon_copy() { + return UIScrollViewDelegate.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + scrollViewDidScroll: scrollViewDidScroll, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return (__pigeon_replyList[0] as String?); - } } } -/// Flutter API for `NSUrl`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. +/// An authentication credential consisting of information specific to the type +/// of credential and the type of persistent storage to use, if any. /// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -abstract class NSUrlFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); +/// See https://developer.apple.com/documentation/foundation/urlcredential. +class URLCredential extends NSObject { + /// Creates a URL credential instance for internet password authentication + /// with a given user name and password, using a given persistence setting. + URLCredential.withUser({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + required String user, + required String password, + required UrlCredentialPersistence persistence, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLCredential; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.withUser'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([ + pigeonVar_instanceIdentifier, + user, + password, + persistence + ]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } - static void setUp( - NSUrlFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', + /// Constructs [URLCredential] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URLCredential.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecURLCredential = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URLCredential Function()? pigeon_newInstance, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlFlutterApi.create$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlFlutterApi.create was null, expected non-null int.'); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLCredential.pigeon_newInstance was null, expected non-null int.'); try { - api.create(arg_identifier!); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + URLCredential.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3608,101 +7209,104 @@ abstract class NSUrlFlutterApi { } } } -} - -/// Host API for `UIScrollViewDelegate`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -class UIScrollViewDelegateHostApi { - /// Constructor for [UIScrollViewDelegateHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - UIScrollViewDelegateHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - final String __pigeon_messageChannelSuffix; - - Future create(int identifier) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateHostApi.create$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + @override + URLCredential pigeon_copy() { + return URLCredential.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([identifier]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } } } -/// Flutter API for `UIScrollViewDelegate`. +/// A server or an area on a server, commonly referred to as a realm, that +/// requires authentication. /// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -abstract class UIScrollViewDelegateFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void scrollViewDidScroll( - int identifier, int uiScrollViewIdentifier, double x, double y); - - static void setUp( - UIScrollViewDelegateFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', +/// See https://developer.apple.com/documentation/foundation/urlprotectionspace. +class URLProtectionSpace extends NSObject { + /// Constructs [URLProtectionSpace] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URLProtectionSpace.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.host, + required this.port, + this.realm, + this.authenticationMethod, + super.observeValue, + }) : super.pigeon_detached(); + + /// The receiver’s host. + final String host; + + /// The receiver’s port. + final int port; + + /// The receiver’s authentication realm. + final String? realm; + + /// The authentication method used by the receiver. + final String? authenticationMethod; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URLProtectionSpace Function( + String host, + int port, + String? realm, + String? authenticationMethod, + )? pigeon_newInstance, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll was null, expected non-null int.'); - final int? arg_uiScrollViewIdentifier = (args[1] as int?); - assert(arg_uiScrollViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll was null, expected non-null int.'); - final double? arg_x = (args[2] as double?); - assert(arg_x != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll was null, expected non-null double.'); - final double? arg_y = (args[3] as double?); - assert(arg_y != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateFlutterApi.scrollViewDidScroll was null, expected non-null double.'); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance was null, expected non-null int.'); + final String? arg_host = (args[1] as String?); + assert(arg_host != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance was null, expected non-null String.'); + final int? arg_port = (args[2] as int?); + assert(arg_port != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLProtectionSpace.pigeon_newInstance was null, expected non-null int.'); + final String? arg_realm = (args[3] as String?); + final String? arg_authenticationMethod = (args[4] as String?); try { - api.scrollViewDidScroll( - arg_identifier!, arg_uiScrollViewIdentifier!, arg_x!, arg_y!); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_host!, arg_port!, arg_realm, + arg_authenticationMethod) ?? + URLProtectionSpace.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + host: arg_host!, + port: arg_port!, + realm: arg_realm, + authenticationMethod: arg_authenticationMethod, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3714,103 +7318,77 @@ abstract class UIScrollViewDelegateFlutterApi { } } } -} -/// Host API for `NSUrlCredential`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc. -class NSUrlCredentialHostApi { - /// Constructor for [NSUrlCredentialHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - NSUrlCredentialHostApi( - {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; - - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - final String __pigeon_messageChannelSuffix; - - /// Create a new native instance and add it to the `InstanceManager`. - Future createWithUser(int identifier, String user, String password, - NSUrlCredentialPersistence persistence) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( - __pigeon_channelName, - pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, - ); - final List? __pigeon_replyList = await __pigeon_channel - .send([identifier, user, password, persistence.index]) - as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { - throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], - ); - } else { - return; - } + @override + URLProtectionSpace pigeon_copy() { + return URLProtectionSpace.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + host: host, + port: port, + realm: realm, + authenticationMethod: authenticationMethod, + observeValue: observeValue, + ); } } -/// Flutter API for `NSUrlProtectionSpace`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. +/// A challenge from a server requiring authentication from the client. /// -/// See https://developer.apple.com/documentation/foundation/nsurlprotectionspace?language=objc. -abstract class NSUrlProtectionSpaceFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier, String? host, String? realm, - String? authenticationMethod); - - static void setUp( - NSUrlProtectionSpaceFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', +/// See https://developer.apple.com/documentation/foundation/urlauthenticationchallenge. +class URLAuthenticationChallenge extends NSObject { + /// Constructs [URLAuthenticationChallenge] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URLAuthenticationChallenge.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecURLAuthenticationChallenge = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URLAuthenticationChallenge Function()? pigeon_newInstance, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlProtectionSpaceFlutterApi.create$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlProtectionSpaceFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlProtectionSpaceFlutterApi.create was null, expected non-null int.'); - final String? arg_host = (args[1] as String?); - final String? arg_realm = (args[2] as String?); - final String? arg_authenticationMethod = (args[3] as String?); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.pigeon_newInstance was null, expected non-null int.'); try { - api.create( - arg_identifier!, arg_host, arg_realm, arg_authenticationMethod); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + URLAuthenticationChallenge.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3822,50 +7400,106 @@ abstract class NSUrlProtectionSpaceFlutterApi { } } } -} -/// Flutter API for `NSUrlAuthenticationChallenge`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlauthenticationchallenge?language=objc. -abstract class NSUrlAuthenticationChallengeFlutterApi { - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); + /// The receiver’s protection space. + Future getProtectionSpace() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURLAuthenticationChallenge; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URLAuthenticationChallenge.getProtectionSpace'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as URLProtectionSpace?)!; + } + } - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier, int protectionSpaceIdentifier); + @override + URLAuthenticationChallenge pigeon_copy() { + return URLAuthenticationChallenge.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } +} - static void setUp( - NSUrlAuthenticationChallengeFlutterApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', +/// A value that identifies the location of a resource, such as an item on a +/// remote server or the path to a local file.. +/// +/// See https://developer.apple.com/documentation/foundation/url. +class URL extends NSObject { + /// Constructs [URL] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + URL.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + super.observeValue, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecURL = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + URL Function()? pigeon_newInstance, }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlAuthenticationChallengeFlutterApi.create$messageChannelSuffix', + 'dev.flutter.pigeon.webview_flutter_wkwebview.URL.pigeon_newInstance', pigeonChannelCodec, binaryMessenger: binaryMessenger); - if (api == null) { - __pigeon_channel.setMessageHandler(null); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); } else { - __pigeon_channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlAuthenticationChallengeFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URL.pigeon_newInstance was null.'); final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlAuthenticationChallengeFlutterApi.create was null, expected non-null int.'); - final int? arg_protectionSpaceIdentifier = (args[1] as int?); - assert(arg_protectionSpaceIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlAuthenticationChallengeFlutterApi.create was null, expected non-null int.'); + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.URL.pigeon_newInstance was null, expected non-null int.'); try { - api.create(arg_identifier!, arg_protectionSpaceIdentifier!); + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + URL.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3877,4 +7511,46 @@ abstract class NSUrlAuthenticationChallengeFlutterApi { } } } + + /// The absolute string for the URL. + Future getAbsoluteString() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecURL; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_wkwebview.URL.getAbsoluteString'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as String?)!; + } + } + + @override + URL pigeon_copy() { + return URL.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + observeValue: observeValue, + ); + } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/webkit_constants.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/webkit_constants.dart new file mode 100644 index 000000000000..281df86ce5e6 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/common/webkit_constants.dart @@ -0,0 +1,72 @@ +// 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. + +import 'web_kit.g.dart'; + +/// Possible error values that WebKit APIs can return. +/// +/// See https://developer.apple.com/documentation/webkit/wkerrorcode. +class WKErrorCode { + WKErrorCode._(); + + /// Indicates an unknown issue occurred. + /// + /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorunknown. + static const int unknown = 1; + + /// Indicates the web process that contains the content is no longer running. + /// + /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorwebcontentprocessterminated. + static const int webContentProcessTerminated = 2; + + /// Indicates the web view was invalidated. + /// + /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorwebviewinvalidated. + static const int webViewInvalidated = 3; + + /// Indicates a JavaScript exception occurred. + /// + /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorjavascriptexceptionoccurred. + static const int javaScriptExceptionOccurred = 4; + + /// Indicates the result of JavaScript execution could not be returned. + /// + /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorjavascriptresulttypeisunsupported. + static const int javaScriptResultTypeIsUnsupported = 5; +} + +/// Keys that may exist in the user info map of `NSError`. +class NSErrorUserInfoKey { + NSErrorUserInfoKey._(); + + /// The corresponding value is a localized string representation of the error + /// that, if present, will be returned by [NSError.localizedDescription]. + /// + /// See https://developer.apple.com/documentation/foundation/nslocalizeddescriptionkey. + static const String NSLocalizedDescription = 'NSLocalizedDescription'; + + /// The URL which caused a load to fail. + /// + /// See https://developer.apple.com/documentation/foundation/nsurlerrorfailingurlstringerrorkey?language=objc. + static const String NSURLErrorFailingURLStringError = + 'NSErrorFailingURLStringKey'; +} + +/// The authentication method used by the receiver. +class NSUrlAuthenticationMethod { + /// Use the default authentication method for a protocol. + static const String default_ = 'NSURLAuthenticationMethodDefault'; + + /// Use HTML form authentication for this protection space. + static const String htmlForm = 'NSURLAuthenticationMethodHTMLForm'; + + /// Use HTTP basic authentication for this protection space. + static const String httpBasic = 'NSURLAuthenticationMethodHTTPBasic'; + + /// Use HTTP digest authentication for this protection space. + static const String httpDigest = 'NSURLAuthenticationMethodHTTPDigest'; + + /// Use NTLM authentication for this protection space. + static const String httpNtlm = 'NSURLAuthenticationMethodNTLM'; +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart deleted file mode 100644 index 2df5c9efc6cd..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ /dev/null @@ -1,538 +0,0 @@ -// 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. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../common/weak_reference_utils.dart'; -import 'foundation_api_impls.dart'; - -export 'foundation_api_impls.dart' - show NSUrlCredentialPersistence, NSUrlSessionAuthChallengeDisposition; - -/// The values that can be returned in a change map. -/// -/// Wraps [NSKeyValueObservingOptions](https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions?language=objc). -enum NSKeyValueObservingOptions { - /// Indicates that the change map should provide the new attribute value, if applicable. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions/nskeyvalueobservingoptionnew?language=objc. - newValue, - - /// Indicates that the change map should contain the old attribute value, if applicable. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions/nskeyvalueobservingoptionold?language=objc. - oldValue, - - /// Indicates a notification should be sent to the observer immediately. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions/nskeyvalueobservingoptioninitial?language=objc. - initialValue, - - /// Whether separate notifications should be sent to the observer before and after each change. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions/nskeyvalueobservingoptionprior?language=objc. - priorNotification, -} - -/// The kinds of changes that can be observed. -/// -/// Wraps [NSKeyValueChange](https://developer.apple.com/documentation/foundation/nskeyvaluechange?language=objc). -enum NSKeyValueChange { - /// Indicates that the value of the observed key path was set to a new value. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechange/nskeyvaluechangesetting?language=objc. - setting, - - /// Indicates that an object has been inserted into the to-many relationship that is being observed. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechange/nskeyvaluechangeinsertion?language=objc. - insertion, - - /// Indicates that an object has been removed from the to-many relationship that is being observed. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechange/nskeyvaluechangeremoval?language=objc. - removal, - - /// Indicates that an object has been replaced in the to-many relationship that is being observed. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechange/nskeyvaluechangereplacement?language=objc. - replacement, -} - -/// The keys that can appear in the change map. -/// -/// Wraps [NSKeyValueChangeKey](https://developer.apple.com/documentation/foundation/nskeyvaluechangekey?language=objc). -enum NSKeyValueChangeKey { - /// Indicates changes made in a collection. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangeindexeskey?language=objc. - indexes, - - /// Indicates what sort of change has occurred. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekindkey?language=objc. - kind, - - /// Indicates the new value for the attribute. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangenewkey?language=objc. - newValue, - - /// Indicates a notification is sent prior to a change. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangenotificationispriorkey?language=objc. - notificationIsPrior, - - /// Indicates the value of this key is the value before the attribute was changed. - /// - /// See https://developer.apple.com/documentation/foundation/nskeyvaluechangeoldkey?language=objc. - oldValue, - - /// An unknown change key. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. - unknown, -} - -/// The supported keys in a cookie attributes dictionary. -/// -/// Wraps [NSHTTPCookiePropertyKey](https://developer.apple.com/documentation/foundation/nshttpcookiepropertykey). -enum NSHttpCookiePropertyKey { - /// A String object containing the comment for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiecomment. - comment, - - /// A String object containing the comment URL for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiecommenturl. - commentUrl, - - /// A String object stating whether the cookie should be discarded at the end of the session. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiediscard. - discard, - - /// A String object specifying the expiration date for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiedomain. - domain, - - /// A String object specifying the expiration date for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookieexpires. - expires, - - /// A String object containing an integer value stating how long in seconds the cookie should be kept, at most. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiemaximumage. - maximumAge, - - /// A String object containing the name of the cookie (required). - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiename. - name, - - /// A String object containing the URL that set this cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookieoriginurl. - originUrl, - - /// A String object containing the path for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiepath. - path, - - /// A String object containing comma-separated integer values specifying the ports for the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookieport. - port, - - /// A String indicating the same-site policy for the cookie. - /// - /// This is only supported on iOS version 13+. This value will be ignored on - /// versions < 13. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiesamesitepolicy. - sameSitePolicy, - - /// A String object indicating that the cookie should be transmitted only over secure channels. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookiesecure. - secure, - - /// A String object containing the value of the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookievalue. - value, - - /// A String object that specifies the version of the cookie. - /// - /// See https://developer.apple.com/documentation/foundation/nshttpcookieversion. - version, -} - -/// A URL load request that is independent of protocol or URL scheme. -/// -/// Wraps [NSUrlRequest](https://developer.apple.com/documentation/foundation/nsurlrequest?language=objc). -@immutable -class NSUrlRequest { - /// Constructs an [NSUrlRequest]. - const NSUrlRequest({ - required this.url, - this.httpMethod, - this.httpBody, - this.allHttpHeaderFields = const {}, - }); - - /// The URL being requested. - final String url; - - /// The HTTP request method. - /// - /// The default HTTP method is “GET”. - final String? httpMethod; - - /// Data sent as the message body of a request, as in an HTTP POST request. - final Uint8List? httpBody; - - /// All of the HTTP header fields for a request. - final Map allHttpHeaderFields; -} - -/// Keys that may exist in the user info map of `NSError`. -class NSErrorUserInfoKey { - NSErrorUserInfoKey._(); - - /// The corresponding value is a localized string representation of the error - /// that, if present, will be returned by [NSError.localizedDescription]. - /// - /// See https://developer.apple.com/documentation/foundation/nslocalizeddescriptionkey. - static const String NSLocalizedDescription = 'NSLocalizedDescription'; - - /// The URL which caused a load to fail. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlerrorfailingurlstringerrorkey?language=objc. - static const String NSURLErrorFailingURLStringError = - 'NSErrorFailingURLStringKey'; -} - -/// The metadata associated with the response to an HTTP protocol URL load -/// request. -/// -/// Wraps [NSHttpUrlResponse](https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc). -@immutable -class NSHttpUrlResponse { - /// Constructs an [NSHttpUrlResponse]. - const NSHttpUrlResponse({ - required this.statusCode, - }); - - /// The response’s HTTP status code. - final int statusCode; -} - -/// Information about an error condition. -/// -/// Wraps [NSError](https://developer.apple.com/documentation/foundation/nserror?language=objc). -@immutable -class NSError { - /// Constructs an [NSError]. - const NSError({ - required this.code, - required this.domain, - this.userInfo = const {}, - }); - - /// The error code. - /// - /// Error codes are [domain]-specific. - final int code; - - /// A string containing the error domain. - final String domain; - - /// Map of arbitrary data. - /// - /// See [NSErrorUserInfoKey] for possible keys (non-exhaustive). - /// - /// This currently only supports values that are a String. - final Map userInfo; - - /// A string containing the localized description of the error. - String? get localizedDescription => - userInfo[NSErrorUserInfoKey.NSLocalizedDescription] as String?; - - @override - String toString() { - if (localizedDescription?.isEmpty ?? true) { - return 'Error $domain:$code:$userInfo'; - } - return '$localizedDescription ($domain:$code:$userInfo)'; - } -} - -/// A representation of an HTTP cookie. -/// -/// Wraps [NSHTTPCookie](https://developer.apple.com/documentation/foundation/nshttpcookie). -@immutable -class NSHttpCookie { - /// Initializes an HTTP cookie object using the provided properties. - const NSHttpCookie.withProperties(this.properties); - - /// Properties of the new cookie object. - final Map properties; -} - -/// An object that represents the location of a resource, such as an item on a -/// remote server or the path to a local file. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -class NSUrl extends NSObject { - /// Instantiates a [NSUrl] without creating and attaching to an instance - /// of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - NSUrl.detached({super.binaryMessenger, super.instanceManager}) - : _nsUrlHostApi = NSUrlHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final NSUrlHostApiImpl _nsUrlHostApi; - - /// The URL string for the receiver as an absolute URL. (read-only) - /// - /// Represents [NSURL.absoluteString](https://developer.apple.com/documentation/foundation/nsurl/1409868-absolutestring?language=objc). - Future getAbsoluteString() { - return _nsUrlHostApi.getAbsoluteStringFromInstances(this); - } - - @override - NSObject copy() { - return NSUrl.detached( - binaryMessenger: _nsUrlHostApi.binaryMessenger, - instanceManager: _nsUrlHostApi.instanceManager, - ); - } -} - -/// The root class of most Objective-C class hierarchies. -@immutable -class NSObject with Copyable { - /// Constructs a [NSObject] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - NSObject.detached({ - this.observeValue, - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _api = NSObjectHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ) { - // Ensures FlutterApis for the Foundation library are set up. - FoundationFlutterApis.instance.ensureSetUp(); - } - - /// Release the reference to the Objective-C object. - static void dispose(NSObject instance) { - instance._api.instanceManager.removeWeakReference(instance); - } - - /// Global instance of [InstanceManager]. - static final InstanceManager globalInstanceManager = - InstanceManager(onWeakReferenceRemoved: (int instanceId) { - NSObjectHostApiImpl().dispose(instanceId); - }); - - final NSObjectHostApiImpl _api; - - /// Informs the observing object when the value at the specified key path has - /// changed. - /// - /// {@template webview_flutter_wkwebview.foundation.callbacks} - /// For the associated Objective-C object to be automatically garbage - /// collected, it is required that this Function doesn't contain a strong - /// reference to the encapsulating class instance. Consider using - /// `WeakReference` when referencing an object not received as a parameter. - /// Otherwise, use [NSObject.dispose] to release the associated Objective-C - /// object manually. - /// - /// See [withWeakReferenceTo]. - /// {@endtemplate} - final void Function( - String keyPath, - NSObject object, - Map change, - )? observeValue; - - /// Registers the observer object to receive KVO notifications. - Future addObserver( - NSObject observer, { - required String keyPath, - required Set options, - }) { - assert(options.isNotEmpty); - return _api.addObserverForInstances( - this, - observer, - keyPath, - options, - ); - } - - /// Stops the observer object from receiving change notifications for the property. - Future removeObserver(NSObject observer, {required String keyPath}) { - return _api.removeObserverForInstances(this, observer, keyPath); - } - - @override - NSObject copy() { - return NSObject.detached( - observeValue: observeValue, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// An authentication credential consisting of information specific to the type -/// of credential and the type of persistent storage to use, if any. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc. -class NSUrlCredential extends NSObject { - /// Creates a URL credential instance for internet password authentication - /// with a given user name and password, using a given persistence setting. - NSUrlCredential.withUser({ - required String user, - required String password, - required NSUrlCredentialPersistence persistence, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : _urlCredentialApi = NSUrlCredentialHostApiImpl( - binaryMessenger: binaryMessenger, instanceManager: instanceManager), - super.detached() { - // Ensures Flutter Apis are setup. - FoundationFlutterApis.instance.ensureSetUp(); - _urlCredentialApi.createWithUserFromInstances( - this, - user, - password, - persistence, - ); - } - - /// Instantiates a [NSUrlCredential] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - NSUrlCredential.detached({super.binaryMessenger, super.instanceManager}) - : _urlCredentialApi = NSUrlCredentialHostApiImpl( - binaryMessenger: binaryMessenger, instanceManager: instanceManager), - super.detached(); - - final NSUrlCredentialHostApiImpl _urlCredentialApi; - - @override - NSObject copy() { - return NSUrlCredential.detached( - binaryMessenger: _urlCredentialApi.binaryMessenger, - instanceManager: _urlCredentialApi.instanceManager, - ); - } -} - -/// A server or an area on a server, commonly referred to as a realm, that -/// requires authentication. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlprotectionspace?language=objc. -class NSUrlProtectionSpace extends NSObject { - /// Instantiates a [NSUrlProtectionSpace] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - NSUrlProtectionSpace.detached({ - required this.host, - required this.realm, - required this.authenticationMethod, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// The receiver’s host. - final String? host; - - /// The receiver’s authentication realm. - final String? realm; - - /// The authentication method used by the receiver. - final String? authenticationMethod; - - @override - NSUrlProtectionSpace copy() { - return NSUrlProtectionSpace.detached( - host: host, - realm: realm, - authenticationMethod: authenticationMethod, - ); - } -} - -/// The authentication method used by the receiver. -class NSUrlAuthenticationMethod { - /// Use the default authentication method for a protocol. - static const String default_ = 'NSURLAuthenticationMethodDefault'; - - /// Use HTML form authentication for this protection space. - static const String htmlForm = 'NSURLAuthenticationMethodHTMLForm'; - - /// Use HTTP basic authentication for this protection space. - static const String httpBasic = 'NSURLAuthenticationMethodHTTPBasic'; - - /// Use HTTP digest authentication for this protection space. - static const String httpDigest = 'NSURLAuthenticationMethodHTTPDigest'; - - /// Use NTLM authentication for this protection space. - static const String httpNtlm = 'NSURLAuthenticationMethodNTLM'; -} - -/// A challenge from a server requiring authentication from the client. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlauthenticationchallenge?language=objc. -class NSUrlAuthenticationChallenge extends NSObject { - /// Instantiates a [NSUrlAuthenticationChallenge] without creating and - /// attaching to an instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - NSUrlAuthenticationChallenge.detached({ - required this.protectionSpace, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// The receiver’s protection space. - late final NSUrlProtectionSpace protectionSpace; - - @override - NSUrlAuthenticationChallenge copy() { - return NSUrlAuthenticationChallenge.detached( - protectionSpace: protectionSpace, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart deleted file mode 100644 index 293ce29bbbec..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart +++ /dev/null @@ -1,392 +0,0 @@ -// 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. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../common/web_kit.g.dart'; -import 'foundation.dart'; - -export '../common/web_kit.g.dart' - show NSUrlCredentialPersistence, NSUrlSessionAuthChallengeDisposition; - -Iterable - _toNSKeyValueObservingOptionsEnumData( - Iterable options, -) { - return options.map(( - NSKeyValueObservingOptions option, - ) { - late final NSKeyValueObservingOptionsEnum? value; - switch (option) { - case NSKeyValueObservingOptions.newValue: - value = NSKeyValueObservingOptionsEnum.newValue; - case NSKeyValueObservingOptions.oldValue: - value = NSKeyValueObservingOptionsEnum.oldValue; - case NSKeyValueObservingOptions.initialValue: - value = NSKeyValueObservingOptionsEnum.initialValue; - case NSKeyValueObservingOptions.priorNotification: - value = NSKeyValueObservingOptionsEnum.priorNotification; - } - - return NSKeyValueObservingOptionsEnumData(value: value); - }); -} - -extension _NSKeyValueChangeKeyEnumDataConverter on NSKeyValueChangeKeyEnumData { - NSKeyValueChangeKey toNSKeyValueChangeKey() { - return NSKeyValueChangeKey.values.firstWhere( - (NSKeyValueChangeKey element) => element.name == value.name, - ); - } -} - -/// Handles initialization of Flutter APIs for the Foundation library. -class FoundationFlutterApis { - /// Constructs a [FoundationFlutterApis]. - @visibleForTesting - FoundationFlutterApis({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _binaryMessenger = binaryMessenger, - object = NSObjectFlutterApiImpl(instanceManager: instanceManager), - url = NSUrlFlutterApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - urlProtectionSpace = NSUrlProtectionSpaceFlutterApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - urlAuthenticationChallenge = NSUrlAuthenticationChallengeFlutterApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - - static FoundationFlutterApis _instance = FoundationFlutterApis(); - - /// Sets the global instance containing the Flutter Apis for the Foundation library. - @visibleForTesting - static set instance(FoundationFlutterApis instance) { - _instance = instance; - } - - /// Global instance containing the Flutter Apis for the Foundation library. - static FoundationFlutterApis get instance { - return _instance; - } - - final BinaryMessenger? _binaryMessenger; - bool _hasBeenSetUp = false; - - /// Flutter Api for [NSObject]. - @visibleForTesting - final NSObjectFlutterApiImpl object; - - /// Flutter Api for [NSUrl]. - @visibleForTesting - final NSUrlFlutterApiImpl url; - - /// Flutter Api for [NSUrlProtectionSpace]. - @visibleForTesting - final NSUrlProtectionSpaceFlutterApiImpl urlProtectionSpace; - - /// Flutter Api for [NSUrlAuthenticationChallenge]. - @visibleForTesting - final NSUrlAuthenticationChallengeFlutterApiImpl urlAuthenticationChallenge; - - /// Ensures all the Flutter APIs have been set up to receive calls from native code. - void ensureSetUp() { - if (!_hasBeenSetUp) { - NSObjectFlutterApi.setUp( - object, - binaryMessenger: _binaryMessenger, - ); - NSUrlFlutterApi.setUp(url, binaryMessenger: _binaryMessenger); - NSUrlProtectionSpaceFlutterApi.setUp( - urlProtectionSpace, - binaryMessenger: _binaryMessenger, - ); - NSUrlAuthenticationChallengeFlutterApi.setUp( - urlAuthenticationChallenge, - binaryMessenger: _binaryMessenger, - ); - _hasBeenSetUp = true; - } - } -} - -/// Host api implementation for [NSObject]. -class NSObjectHostApiImpl extends NSObjectHostApi { - /// Constructs an [NSObjectHostApiImpl]. - NSObjectHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [addObserver] with the ids of the provided object instances. - Future addObserverForInstances( - NSObject instance, - NSObject observer, - String keyPath, - Set options, - ) { - return addObserver( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(observer)!, - keyPath, - _toNSKeyValueObservingOptionsEnumData(options).toList(), - ); - } - - /// Calls [removeObserver] with the ids of the provided object instances. - Future removeObserverForInstances( - NSObject instance, - NSObject observer, - String keyPath, - ) { - return removeObserver( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(observer)!, - keyPath, - ); - } -} - -/// Flutter api implementation for [NSObject]. -class NSObjectFlutterApiImpl extends NSObjectFlutterApi { - /// Constructs a [NSObjectFlutterApiImpl]. - NSObjectFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - NSObject _getObject(int identifier) { - return instanceManager.getInstanceWithWeakReference(identifier)!; - } - - @override - void observeValue( - int identifier, - String keyPath, - int objectIdentifier, - List changeKeys, - List changeValues, - ) { - final void Function(String, NSObject, Map)? - function = _getObject(identifier).observeValue; - function?.call( - keyPath, - instanceManager.getInstanceWithWeakReference(objectIdentifier)! - as NSObject, - Map.fromIterables( - changeKeys.map( - (NSKeyValueChangeKeyEnumData? data) { - return data!.toNSKeyValueChangeKey(); - }, - ), - changeValues.map((ObjectOrIdentifier? value) { - if (value != null && value.isIdentifier) { - return instanceManager.getInstanceWithWeakReference( - value.value! as int, - ); - } - return value?.value; - }), - ), - ); - } - - @override - void dispose(int identifier) { - instanceManager.remove(identifier); - } -} - -/// Host api implementation for [NSUrl]. -class NSUrlHostApiImpl extends NSUrlHostApi { - /// Constructs an [NSUrlHostApiImpl]. - NSUrlHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [getAbsoluteString] with the ids of the provided object instances. - Future getAbsoluteStringFromInstances(NSUrl instance) { - return getAbsoluteString(instanceManager.getIdentifier(instance)!); - } -} - -/// Flutter API implementation for [NSUrl]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class NSUrlFlutterApiImpl implements NSUrlFlutterApi { - /// Constructs a [NSUrlFlutterApiImpl]. - NSUrlFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int identifier) { - instanceManager.addHostCreatedInstance( - NSUrl.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Host api implementation for [NSUrlCredential]. -class NSUrlCredentialHostApiImpl extends NSUrlCredentialHostApi { - /// Constructs an [NSUrlCredentialHostApiImpl]. - NSUrlCredentialHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createWithUser] with the ids of the provided object instances. - Future createWithUserFromInstances( - NSUrlCredential instance, - String user, - String password, - NSUrlCredentialPersistence persistence, - ) { - return createWithUser( - instanceManager.addDartCreatedInstance(instance), - user, - password, - persistence, - ); - } -} - -/// Flutter API implementation for [NSUrlProtectionSpace]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -@protected -class NSUrlProtectionSpaceFlutterApiImpl - implements NSUrlProtectionSpaceFlutterApi { - /// Constructs a [NSUrlProtectionSpaceFlutterApiImpl]. - NSUrlProtectionSpaceFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create( - int identifier, - String? host, - String? realm, - String? authenticationMethod, - ) { - instanceManager.addHostCreatedInstance( - NSUrlProtectionSpace.detached( - host: host, - realm: realm, - authenticationMethod: authenticationMethod, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Flutter API implementation for [NSUrlAuthenticationChallenge]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -@protected -class NSUrlAuthenticationChallengeFlutterApiImpl - implements NSUrlAuthenticationChallengeFlutterApi { - /// Constructs a [NSUrlAuthenticationChallengeFlutterApiImpl]. - NSUrlAuthenticationChallengeFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create( - int identifier, - int protectionSpaceIdentifier, - ) { - instanceManager.addHostCreatedInstance( - NSUrlAuthenticationChallenge.detached( - protectionSpace: instanceManager.getInstanceWithWeakReference( - protectionSpaceIdentifier, - )!, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/web_kit_webview_widget.dart index 7a3795096dec..d347ce077bce 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/web_kit_webview_widget.dart @@ -4,7 +4,6 @@ import 'dart:async'; import 'dart:io'; -import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -12,9 +11,10 @@ import 'package:path/path.dart' as path; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; +import '../common/platform_webview.dart'; import '../common/weak_reference_utils.dart'; -import '../foundation/foundation.dart'; -import '../web_kit/web_kit.dart'; +import '../common/web_kit.g.dart'; +import '../common/webkit_constants.dart'; /// A [Widget] that displays a [WKWebView]. class WebKitWebViewWidget extends StatefulWidget { @@ -112,18 +112,23 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { final WebViewWidgetProxy webViewProxy; /// Represents the WebView maintained by platform code. - late final WKWebView webView; + late final PlatformWebView webView; /// Used to integrate custom user interface elements into web view interactions. @visibleForTesting late final WKUIDelegate uiDelegate = webViewProxy.createUIDelgate( onCreateWebView: ( + WKUIDelegate instance, WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, ) { - if (!navigationAction.targetFrame.isMainFrame) { - webView.loadRequest(navigationAction.request); + final bool isForMainFrame = + navigationAction.targetFrame?.isMainFrame ?? false; + if (!isForMainFrame) { + PlatformWebView.fromNativeWebView(webView).load( + navigationAction.request, + ); } }, ); @@ -134,45 +139,46 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { this, (WeakReference weakReference) { return webViewProxy.createNavigationDelegate( - didFinishNavigation: (WKWebView webView, String? url) { + didFinishNavigation: (_, __, String? url) { weakReference.target?.callbacksHandler.onPageFinished(url ?? ''); }, - didStartProvisionalNavigation: (WKWebView webView, String? url) { + didStartProvisionalNavigation: (_, __, String? url) { weakReference.target?.callbacksHandler.onPageStarted(url ?? ''); }, decidePolicyForNavigationAction: ( - WKWebView webView, + _, + __, WKNavigationAction action, ) async { if (weakReference.target == null) { - return WKNavigationActionPolicy.allow; + return NavigationActionPolicy.allow; } if (!weakReference.target!._hasNavigationDelegate) { - return WKNavigationActionPolicy.allow; + return NavigationActionPolicy.allow; } final bool allow = await weakReference.target!.callbacksHandler.onNavigationRequest( - url: action.request.url, - isForMainFrame: action.targetFrame.isMainFrame, + url: await action.request.getUrl() ?? '', + isForMainFrame: action.targetFrame?.isMainFrame ?? false, ); return allow - ? WKNavigationActionPolicy.allow - : WKNavigationActionPolicy.cancel; + ? NavigationActionPolicy.allow + : NavigationActionPolicy.cancel; }, - didFailNavigation: (WKWebView webView, NSError error) { + didFailNavigation: (_, __, NSError error) { weakReference.target?.callbacksHandler.onWebResourceError( _toWebResourceError(error), ); }, - didFailProvisionalNavigation: (WKWebView webView, NSError error) { + didFailProvisionalNavigation: (_, __, NSError error) { weakReference.target?.callbacksHandler.onWebResourceError( _toWebResourceError(error), ); }, - webViewWebContentProcessDidTerminate: (WKWebView webView) { + webViewWebContentProcessDidTerminate: (_, __) { weakReference.target?.callbacksHandler.onWebResourceError( WebResourceError( errorCode: WKErrorCode.webContentProcessTerminated, @@ -183,6 +189,15 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { ), ); }, + decidePolicyForNavigationResponse: (_, __, ___) async { + return NavigationResponsePolicy.allow; + }, + didReceiveAuthenticationChallenge: (_, __, ___) async { + return AuthenticationChallengeResponse( + disposition: + UrlSessionAuthChallengeDisposition.performDefaultHandling, + ); + }, ); }, ); @@ -205,10 +220,10 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { return ( String keyPath, NSObject object, - Map change, + Map change, ) { final double progress = - change[NSKeyValueChangeKey.newValue]! as double; + change[KeyValueChangeKey.newValue]! as double; weakReference.target?.onProgress((progress * 100).round()); }; }, @@ -230,16 +245,11 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { } if (params.backgroundColor != null) { - final WKWebView webView = this.webView; - if (webView is WKWebViewIOS) { - unawaited(webView.setOpaque(false)); - unawaited(webView.setBackgroundColor(Colors.transparent)); - unawaited( - webView.scrollView.setBackgroundColor(params.backgroundColor)); - } else { - // TODO(stuartmorgan): Investigate doing this via JS instead. - throw UnimplementedError('Background color is yet supported on macOS'); - } + unawaited(webView.setOpaque(false)); + unawaited(webView.setBackgroundColor(Colors.transparent.value)); + unawaited( + webView.scrollView.setBackgroundColor(params.backgroundColor?.value), + ); } if (params.initialUrl != null) { @@ -264,36 +274,36 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { requiresUserAction = false; } - configuration - .setMediaTypesRequiringUserActionForPlayback({ - if (requiresUserAction) WKAudiovisualMediaType.all, - if (!requiresUserAction) WKAudiovisualMediaType.none, - }); + configuration.setMediaTypesRequiringUserActionForPlayback( + requiresUserAction ? AudiovisualMediaType.all : AudiovisualMediaType.none, + ); } @override Future loadHtmlString(String html, {String? baseUrl}) { - return webView.loadHtmlString(html, baseUrl: baseUrl); + return webView.loadHtmlString(html, baseUrl); } @override Future loadFile(String absoluteFilePath) async { await webView.loadFileUrl( absoluteFilePath, - readAccessUrl: path.dirname(absoluteFilePath), + path.dirname(absoluteFilePath), ); } @override - Future clearCache() { - return webView.configuration.websiteDataStore.removeDataOfTypes( - { - WKWebsiteDataType.memoryCache, - WKWebsiteDataType.diskCache, - WKWebsiteDataType.offlineWebApplicationCache, - WKWebsiteDataType.localStorage, - }, - DateTime.fromMillisecondsSinceEpoch(0), + Future clearCache() async { + final WKWebsiteDataStore dataStore = + await webView.configuration.getWebsiteDataStore(); + await dataStore.removeDataOfTypes( + [ + WebsiteDataType.memoryCache, + WebsiteDataType.diskCache, + WebsiteDataType.offlineWebApplicationCache, + WebsiteDataType.localStorage, + ], + 0, ); } @@ -305,11 +315,11 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { @override Future loadUrl(String url, Map? headers) async { - final NSUrlRequest request = NSUrlRequest( - url: url, - allHttpHeaderFields: headers ?? {}, + final URLRequest request = webViewProxy.createRequest(url: url); + unawaited( + request.setAllHttpHeaderFields(headers ?? const {}), ); - return webView.loadRequest(request); + return webView.load(request); } @override @@ -318,14 +328,14 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); } - final NSUrlRequest urlRequest = NSUrlRequest( + final URLRequest urlRequest = webViewProxy.createRequest( url: request.uri.toString(), - allHttpHeaderFields: request.headers, - httpMethod: request.method.name, - httpBody: request.body, ); + unawaited(urlRequest.setAllHttpHeaderFields(request.headers)); + unawaited(urlRequest.setHttpMethod(request.method.name)); + unawaited(urlRequest.setHttpBody(request.body)); - return webView.loadRequest(urlRequest); + return webView.load(urlRequest); } @override @@ -385,51 +395,25 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { Future currentUrl() => webView.getUrl(); @override - Future scrollTo(int x, int y) async { - final WKWebView webView = this.webView; - if (webView is WKWebViewIOS) { - return webView.scrollView.setContentOffset(Point( - x.toDouble(), - y.toDouble(), - )); - } else { - throw UnimplementedError('scrollTo is not supported on macOS'); - } + Future scrollTo(int x, int y) { + return webView.scrollView.setContentOffset(x.toDouble(), y.toDouble()); } @override Future scrollBy(int x, int y) async { - final WKWebView webView = this.webView; - if (webView is WKWebViewIOS) { - await webView.scrollView.scrollBy(Point( - x.toDouble(), - y.toDouble(), - )); - } else { - throw UnimplementedError('scrollBy is not supported on macOS'); - } + return webView.scrollView.scrollBy(x.toDouble(), y.toDouble()); } @override Future getScrollX() async { - final WKWebView webView = this.webView; - if (webView is WKWebViewIOS) { - final Point offset = await webView.scrollView.getContentOffset(); - return offset.x.toInt(); - } else { - throw UnimplementedError('getScrollX is not supported on macOS'); - } + final List offset = await webView.scrollView.getContentOffset(); + return offset[0].toInt(); } @override Future getScrollY() async { - final WKWebView webView = this.webView; - if (webView is WKWebViewIOS) { - final Point offset = await webView.scrollView.getContentOffset(); - return offset.y.toInt(); - } else { - throw UnimplementedError('getScrollY is not supported on macOS'); - } + final List offset = await webView.scrollView.getContentOffset(); + return offset[1].toInt(); } @override @@ -459,13 +443,14 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { return !_scriptMessageHandlers.containsKey(channelName); }, ).map>( - (String channelName) { + (String channelName) async { final WKScriptMessageHandler handler = webViewProxy.createScriptMessageHandler( didReceiveScriptMessage: withWeakReferenceTo( javascriptChannelRegistry, (WeakReference weakReference) { return ( + WKScriptMessageHandler instance, WKUserContentController userContentController, WKScriptMessage message, ) { @@ -482,14 +467,14 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { final String wrapperSource = 'window.$channelName = webkit.messageHandlers.$channelName;'; final WKUserScript wrapperScript = WKUserScript( - wrapperSource, - WKUserScriptInjectionTime.atDocumentStart, - isMainFrameOnly: false, + source: wrapperSource, + injectionTime: UserScriptInjectionTime.atDocumentStart, + isForMainFrameOnly: false, ); - webView.configuration.userContentController - .addUserScript(wrapperScript); - return webView.configuration.userContentController - .addScriptMessageHandler( + final WKUserContentController controller = + await webView.configuration.getUserContentController(); + unawaited(controller.addUserScript(wrapperScript)); + await controller.addScriptMessageHandler( handler, channelName, ); @@ -513,25 +498,25 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { if (hasProgressTracking) { _progressObserverSet = true; await webView.addObserver( - webView, - keyPath: 'estimatedProgress', - options: { - NSKeyValueObservingOptions.newValue, - }, + webView.nativeWebView, + 'estimatedProgress', + [KeyValueObservingOptions.newValue], ); } else if (_progressObserverSet) { // Calls to removeObserver before addObserver causes a crash. _progressObserverSet = false; - await webView.removeObserver(webView, keyPath: 'estimatedProgress'); + await webView.removeObserver(webView.nativeWebView, 'estimatedProgress'); } } - Future _setJavaScriptMode(JavascriptMode mode) { + Future _setJavaScriptMode(JavascriptMode mode) async { + final WKPreferences preferences = + await webView.configuration.getPreferences(); switch (mode) { case JavascriptMode.disabled: - return webView.configuration.preferences.setJavaScriptEnabled(false); + await preferences.setJavaScriptEnabled(false); case JavascriptMode.unrestricted: - return webView.configuration.preferences.setJavaScriptEnabled(true); + await preferences.setJavaScriptEnabled(true); } } @@ -554,18 +539,19 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { return _resetUserScripts(); } - Future _disableZoom() { - const WKUserScript userScript = WKUserScript( - "var meta = document.createElement('meta');\n" - "meta.name = 'viewport';\n" - "meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, " - "user-scalable=no';\n" - "var head = document.getElementsByTagName('head')[0];head.appendChild(meta);", - WKUserScriptInjectionTime.atDocumentEnd, - isMainFrameOnly: true, + Future _disableZoom() async { + final WKUserScript userScript = WKUserScript( + source: "var meta = document.createElement('meta');\n" + "meta.name = 'viewport';\n" + "meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, " + "user-scalable=no';\n" + "var head = document.getElementsByTagName('head')[0];head.appendChild(meta);", + injectionTime: UserScriptInjectionTime.atDocumentEnd, + isForMainFrameOnly: true, ); - return webView.configuration.userContentController - .addUserScript(userScript); + final WKUserContentController controller = + await webView.configuration.getUserContentController(); + return controller.addUserScript(userScript); } // WkWebView does not support removing a single user script, so all user @@ -576,15 +562,13 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { Future _resetUserScripts({ Set removedJavaScriptChannels = const {}, }) async { - unawaited( - webView.configuration.userContentController.removeAllUserScripts(), - ); + final WKUserContentController controller = + await webView.configuration.getUserContentController(); + unawaited(controller.removeAllUserScripts()); // TODO(bparrishMines): This can be replaced with // `removeAllScriptMessageHandlers` once Dart supports runtime version // checking. (e.g. The equivalent to @availability in Objective-C.) - _scriptMessageHandlers.keys.forEach( - webView.configuration.userContentController.removeScriptMessageHandler, - ); + _scriptMessageHandlers.keys.forEach(controller.removeScriptMessageHandler); removedJavaScriptChannels.forEach(_scriptMessageHandlers.remove); final Set remainingNames = _scriptMessageHandlers.keys.toSet(); @@ -617,7 +601,9 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { return WebResourceError( errorCode: error.code, domain: error.domain, - description: error.localizedDescription ?? '', + description: error.userInfo[NSErrorUserInfoKey.NSLocalizedDescription] + as String? ?? + '', errorType: errorType, ); } @@ -675,24 +661,26 @@ class WebViewWidgetProxy { final bool? overriddenIsMacOS; /// Constructs a [WKWebView]. - WKWebView createWebView( + PlatformWebView createWebView( WKWebViewConfiguration configuration, { void Function( String keyPath, NSObject object, - Map change, + Map change, )? observeValue, }) { - if (overriddenIsMacOS ?? Platform.isMacOS) { - return WKWebViewMacOS(configuration, observeValue: observeValue); - } else { - return WKWebViewIOS(configuration, observeValue: observeValue); - } + return PlatformWebView(initialConfiguration: configuration); + } + + /// Constructs a [URLRequest]. + URLRequest createRequest({required String url}) { + return URLRequest(url: url); } /// Constructs a [WKScriptMessageHandler]. WKScriptMessageHandler createScriptMessageHandler({ required void Function( + WKScriptMessageHandler instance, WKUserContentController userContentController, WKScriptMessage message, ) didReceiveScriptMessage, @@ -705,6 +693,7 @@ class WebViewWidgetProxy { /// Constructs a [WKUIDelegate]. WKUIDelegate createUIDelgate({ void Function( + WKUIDelegate instance, WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, @@ -715,17 +704,31 @@ class WebViewWidgetProxy { /// Constructs a [WKNavigationDelegate]. WKNavigationDelegate createNavigationDelegate({ - void Function(WKWebView webView, String? url)? didFinishNavigation, - void Function(WKWebView webView, String? url)? + void Function(WKNavigationDelegate, WKWebView webView, String? url)? + didFinishNavigation, + void Function(WKNavigationDelegate, WKWebView webView, String? url)? didStartProvisionalNavigation, - Future Function( + required Future Function( + WKNavigationDelegate, WKWebView webView, WKNavigationAction navigationAction, - )? decidePolicyForNavigationAction, - void Function(WKWebView webView, NSError error)? didFailNavigation, - void Function(WKWebView webView, NSError error)? + ) decidePolicyForNavigationAction, + void Function(WKNavigationDelegate, WKWebView webView, NSError error)? + didFailNavigation, + void Function(WKNavigationDelegate, WKWebView webView, NSError error)? didFailProvisionalNavigation, - void Function(WKWebView webView)? webViewWebContentProcessDidTerminate, + void Function(WKNavigationDelegate, WKWebView webView)? + webViewWebContentProcessDidTerminate, + required Future Function( + WKNavigationDelegate, + WKWebView webView, + WKNavigationResponse navigationResponse, + ) decidePolicyForNavigationResponse, + required Future Function( + WKNavigationDelegate, + WKWebView webView, + URLAuthenticationChallenge challenge, + ) didReceiveAuthenticationChallenge, }) { return WKNavigationDelegate( didFinishNavigation: didFinishNavigation, @@ -735,6 +738,8 @@ class WebViewWidgetProxy { didFailProvisionalNavigation: didFailProvisionalNavigation, webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate, + decidePolicyForNavigationResponse: decidePolicyForNavigationResponse, + didReceiveAuthenticationChallenge: didReceiveAuthenticationChallenge, ); } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/webview_cupertino.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/webview_cupertino.dart index 5ad959ca79be..6d9de39d005a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/webview_cupertino.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/webview_cupertino.dart @@ -11,7 +11,7 @@ import 'package:flutter/widgets.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../foundation/foundation.dart'; +import '../common/web_kit.g.dart'; import 'web_kit_webview_widget.dart'; /// Builds an iOS webview. @@ -42,8 +42,9 @@ class CupertinoWebView implements WebViewPlatform { } }, gestureRecognizers: gestureRecognizers, - creationParams: - NSObject.globalInstanceManager.getIdentifier(controller.webView), + creationParams: PigeonInstanceManager.instance.getIdentifier( + controller.webView.nativeWebView, + ), creationParamsCodec: const StandardMessageCodec(), ); }, diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/wkwebview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/wkwebview_cookie_manager.dart index 59dce559f12c..faa654836f22 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/wkwebview_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/wkwebview_cookie_manager.dart @@ -2,27 +2,33 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../foundation/foundation.dart'; -import '../web_kit/web_kit.dart'; +import '../common/web_kit.g.dart'; +import '../webkit_proxy.dart'; /// Handles all cookie operations for the WebView platform. class WKWebViewCookieManager extends WebViewCookieManagerPlatform { /// Constructs a [WKWebViewCookieManager]. - WKWebViewCookieManager({WKWebsiteDataStore? websiteDataStore}) - : websiteDataStore = - websiteDataStore ?? WKWebsiteDataStore.defaultDataStore; + WKWebViewCookieManager({ + WKWebsiteDataStore? websiteDataStore, + @visibleForTesting WebKitProxy webKitProxy = const WebKitProxy(), + }) : _webKitProxy = webKitProxy, + websiteDataStore = websiteDataStore ?? + webKitProxy.defaultDataStoreWKWebsiteDataStore(); /// Manages stored data for [WKWebView]s. final WKWebsiteDataStore websiteDataStore; + final WebKitProxy _webKitProxy; + @override Future clearCookies() async { return websiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, - DateTime.fromMillisecondsSinceEpoch(0), + [WebsiteDataType.cookies], + 0, ); } @@ -34,12 +40,12 @@ class WKWebViewCookieManager extends WebViewCookieManagerPlatform { } return websiteDataStore.httpCookieStore.setCookie( - NSHttpCookie.withProperties( - { - NSHttpCookiePropertyKey.name: cookie.name, - NSHttpCookiePropertyKey.value: cookie.value, - NSHttpCookiePropertyKey.domain: cookie.domain, - NSHttpCookiePropertyKey.path: cookie.path, + _webKitProxy.newHTTPCookie( + properties: { + HttpCookiePropertyKey.name: cookie.name, + HttpCookiePropertyKey.value: cookie.value, + HttpCookiePropertyKey.domain: cookie.domain, + HttpCookiePropertyKey.path: cookie.path, }, ), ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart deleted file mode 100644 index fe5a0a3343b1..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart +++ /dev/null @@ -1,212 +0,0 @@ -// 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. - -import 'dart:async'; -import 'dart:math'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../foundation/foundation.dart'; -import '../web_kit/web_kit.dart'; -import '../web_kit/web_kit_api_impls.dart'; -import 'ui_kit_api_impls.dart'; - -/// A view that allows the scrolling and zooming of its contained views. -/// -/// Wraps [UIScrollView](https://developer.apple.com/documentation/uikit/uiscrollview?language=objc). -@immutable -class UIScrollView extends UIViewBase { - /// Constructs a [UIScrollView] that is owned by [webView]. - factory UIScrollView.fromWebView( - WKWebView webView, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final UIScrollView scrollView = UIScrollView.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - scrollView._scrollViewApi.createFromWebViewForInstances( - scrollView, - webView, - ); - return scrollView; - } - - /// Constructs a [UIScrollView] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - UIScrollView.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _scrollViewApi = UIScrollViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final UIScrollViewHostApiImpl _scrollViewApi; - - /// Point at which the origin of the content view is offset from the origin of the scroll view. - /// - /// Represents [WKWebView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset?language=objc). - Future> getContentOffset() { - return _scrollViewApi.getContentOffsetForInstances(this); - } - - /// Move the scrolled position of this view. - /// - /// This method is not a part of UIKit and is only a helper method to make - /// scrollBy atomic. - Future scrollBy(Point offset) { - return _scrollViewApi.scrollByForInstances(this, offset); - } - - /// Set point at which the origin of the content view is offset from the origin of the scroll view. - /// - /// The default value is `Point(0.0, 0.0)`. - /// - /// Sets [WKWebView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset?language=objc). - Future setContentOffset(Point offset) { - return _scrollViewApi.setContentOffsetForInstances(this, offset); - } - - /// Set the delegate to this scroll view. - /// - /// Represents [UIScrollView.delegate](https://developer.apple.com/documentation/uikit/uiscrollview/1619430-delegate?language=objc). - Future setDelegate(UIScrollViewDelegate? delegate) { - return _scrollViewApi.setDelegateForInstances(this, delegate); - } - - @override - UIScrollView copy() { - return UIScrollView.detached( - observeValue: observeValue, - binaryMessenger: _viewApi.binaryMessenger, - instanceManager: _viewApi.instanceManager, - ); - } -} - -/// Methods that anything implementing a class that inherits from UIView on the -/// native side must implement. -/// -/// Classes without a multiple inheritence problem should extend UIViewBase -/// instead of implementing this directly. -abstract class UIView implements NSObject { - /// The view’s background color. - /// - /// The default value is null, which results in a transparent background color. - /// - /// Sets [UIView.backgroundColor](https://developer.apple.com/documentation/uikit/uiview/1622591-backgroundcolor?language=objc). - Future setBackgroundColor(Color? color); - - /// Determines whether the view is opaque. - /// - /// Sets [UIView.opaque](https://developer.apple.com/documentation/uikit/uiview?language=objc). - Future setOpaque(bool opaque); -} - -/// Manages the content for a rectangular area on the screen. -/// -/// Wraps [UIView](https://developer.apple.com/documentation/uikit/uiview?language=objc). -@immutable -class UIViewBase extends NSObject implements UIView { - /// Constructs a [UIView] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - UIViewBase.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _viewApi = UIViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final UIViewHostApiImpl _viewApi; - - @override - Future setBackgroundColor(Color? color) { - return _viewApi.setBackgroundColorForInstances(this, color); - } - - @override - Future setOpaque(bool opaque) { - return _viewApi.setOpaqueForInstances(this, opaque); - } - - @override - UIView copy() { - return UIViewBase.detached( - observeValue: observeValue, - binaryMessenger: _viewApi.binaryMessenger, - instanceManager: _viewApi.instanceManager, - ); - } -} - -/// Responding to scroll view interactions. -/// -/// Represent [UIScrollViewDelegate](https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc). -@immutable -class UIScrollViewDelegate extends NSObject { - /// Constructs a [UIScrollViewDelegate]. - UIScrollViewDelegate({ - this.scrollViewDidScroll, - super.binaryMessenger, - super.instanceManager, - }) : _scrollViewDelegateApi = UIScrollViewDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _scrollViewDelegateApi.createForInstance(this); - } - - /// Constructs a [UIScrollViewDelegate] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - UIScrollViewDelegate.detached({ - this.scrollViewDidScroll, - super.binaryMessenger, - super.instanceManager, - }) : _scrollViewDelegateApi = UIScrollViewDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final UIScrollViewDelegateHostApiImpl _scrollViewDelegateApi; - - /// Called when scroll view did scroll. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function( - UIScrollView scrollView, - double x, - double y, - )? scrollViewDidScroll; - - @override - UIScrollViewDelegate copy() { - return UIScrollViewDelegate.detached( - scrollViewDidScroll: scrollViewDidScroll, - binaryMessenger: _scrollViewDelegateApi.binaryMessenger, - instanceManager: _scrollViewDelegateApi.instanceManager, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit_api_impls.dart deleted file mode 100644 index 6f15f7d6a9a6..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit_api_impls.dart +++ /dev/null @@ -1,181 +0,0 @@ -// 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. - -import 'dart:async'; -import 'dart:math'; - -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../common/web_kit.g.dart'; -import '../foundation/foundation.dart'; -import '../web_kit/web_kit.dart'; -import 'ui_kit.dart'; - -/// Host api implementation for [UIScrollView]. -class UIScrollViewHostApiImpl extends UIScrollViewHostApi { - /// Constructs a [UIScrollViewHostApiImpl]. - UIScrollViewHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createFromWebView] with the ids of the provided object instances. - Future createFromWebViewForInstances( - UIScrollView instance, - WKWebView webView, - ) { - return createFromWebView( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(webView)!, - ); - } - - /// Calls [getContentOffset] with the ids of the provided object instances. - Future> getContentOffsetForInstances( - UIScrollView instance, - ) async { - final List point = await getContentOffset( - instanceManager.getIdentifier(instance)!, - ); - return Point(point[0]!, point[1]!); - } - - /// Calls [scrollBy] with the ids of the provided object instances. - Future scrollByForInstances( - UIScrollView instance, - Point offset, - ) { - return scrollBy( - instanceManager.getIdentifier(instance)!, - offset.x, - offset.y, - ); - } - - /// Calls [setContentOffset] with the ids of the provided object instances. - Future setContentOffsetForInstances( - UIScrollView instance, - Point offset, - ) async { - return setContentOffset( - instanceManager.getIdentifier(instance)!, - offset.x, - offset.y, - ); - } - - /// Calls [setDelegate] with the ids of the provided object instances. - Future setDelegateForInstances( - UIScrollView instance, - UIScrollViewDelegate? delegate, - ) async { - return setDelegate( - instanceManager.getIdentifier(instance)!, - delegate != null ? instanceManager.getIdentifier(delegate) : null, - ); - } -} - -/// Host api implementation for [UIView]. -class UIViewHostApiImpl extends UIViewHostApi { - /// Constructs a [UIViewHostApiImpl]. - UIViewHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [setBackgroundColor] with the ids of the provided object instances. - Future setBackgroundColorForInstances( - UIView instance, - Color? color, - ) async { - return setBackgroundColor( - instanceManager.getIdentifier(instance)!, - color?.value, - ); - } - - /// Calls [setOpaque] with the ids of the provided object instances. - Future setOpaqueForInstances( - UIView instance, - bool opaque, - ) async { - return setOpaque(instanceManager.getIdentifier(instance)!, opaque); - } -} - -/// Flutter api implementation for [UIScrollViewDelegate]. -class UIScrollViewDelegateFlutterApiImpl - extends UIScrollViewDelegateFlutterApi { - /// Constructs a [UIScrollViewDelegateFlutterApiImpl]. - UIScrollViewDelegateFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - UIScrollViewDelegate _getDelegate(int identifier) { - return instanceManager.getInstanceWithWeakReference(identifier)!; - } - - @override - void scrollViewDidScroll( - int identifier, - int uiScrollViewIdentifier, - double x, - double y, - ) { - final void Function(UIScrollView, double, double)? callback = - _getDelegate(identifier).scrollViewDidScroll; - final UIScrollView? uiScrollView = instanceManager - .getInstanceWithWeakReference(uiScrollViewIdentifier) as UIScrollView?; - assert(uiScrollView != null); - callback?.call(uiScrollView!, x, y); - } -} - -/// Host api implementation for [UIScrollViewDelegate]. -class UIScrollViewDelegateHostApiImpl extends UIScrollViewDelegateHostApi { - /// Constructs a [UIScrollViewDelegateHostApiImpl]. - UIScrollViewDelegateHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstance(UIScrollViewDelegate instance) async { - return create(instanceManager.addDartCreatedInstance(instance)); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart deleted file mode 100644 index d5dcf0fff309..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ /dev/null @@ -1,1308 +0,0 @@ -// 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. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../foundation/foundation.dart'; -import '../ui_kit/ui_kit.dart'; -import '../ui_kit/ui_kit_api_impls.dart' show UIViewHostApiImpl; -import 'web_kit_api_impls.dart'; - -export 'web_kit_api_impls.dart' - show WKMediaCaptureType, WKNavigationType, WKPermissionDecision; - -/// Times at which to inject script content into a webpage. -/// -/// Wraps [WKUserScriptInjectionTime](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc). -enum WKUserScriptInjectionTime { - /// Inject the script after the creation of the webpage’s document element, but before loading any other content. - /// - /// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentstart?language=objc. - atDocumentStart, - - /// Inject the script after the document finishes loading, but before loading any other subresources. - /// - /// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentend?language=objc. - atDocumentEnd, -} - -/// The media types that require a user gesture to begin playing. -/// -/// Wraps [WKAudiovisualMediaTypes](https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes?language=objc). -enum WKAudiovisualMediaType { - /// No media types require a user gesture to begin playing. - /// - /// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes/wkaudiovisualmediatypenone?language=objc. - none, - - /// Media types that contain audio require a user gesture to begin playing. - /// - /// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes/wkaudiovisualmediatypeaudio?language=objc. - audio, - - /// Media types that contain video require a user gesture to begin playing. - /// - /// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes/wkaudiovisualmediatypevideo?language=objc. - video, - - /// All media types require a user gesture to begin playing. - /// - /// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes/wkaudiovisualmediatypeall?language=objc. - all, -} - -/// Types of data that websites store. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types?language=objc. -enum WKWebsiteDataType { - /// Cookies. - cookies, - - /// In-memory caches. - memoryCache, - - /// On-disk caches. - diskCache, - - /// HTML offline web app caches. - offlineWebApplicationCache, - - /// HTML local storage. - localStorage, - - /// HTML session storage. - sessionStorage, - - /// WebSQL databases. - webSQLDatabases, - - /// IndexedDB databases. - indexedDBDatabases, -} - -/// Indicate whether to allow or cancel navigation to a webpage. -/// -/// Wraps [WKNavigationActionPolicy](https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc). -enum WKNavigationActionPolicy { - /// Allow navigation to continue. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy/wknavigationactionpolicyallow?language=objc. - allow, - - /// Cancel navigation. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy/wknavigationactionpolicycancel?language=objc. - cancel, -} - -/// Indicate whether to allow or cancel navigation to a webpage. -/// -/// Wraps [WKNavigationResponsePolicy](https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy?language=objc). -enum WKNavigationResponsePolicy { - /// Allow navigation to continue. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy/wknavigationresponsepolicyallow?language=objc. - allow, - - /// Cancel navigation. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy/wknavigationresponsepolicycancel?language=objc. - cancel, -} - -/// Possible error values that WebKit APIs can return. -/// -/// See https://developer.apple.com/documentation/webkit/wkerrorcode. -class WKErrorCode { - WKErrorCode._(); - - /// Indicates an unknown issue occurred. - /// - /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorunknown. - static const int unknown = 1; - - /// Indicates the web process that contains the content is no longer running. - /// - /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorwebcontentprocessterminated. - static const int webContentProcessTerminated = 2; - - /// Indicates the web view was invalidated. - /// - /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorwebviewinvalidated. - static const int webViewInvalidated = 3; - - /// Indicates a JavaScript exception occurred. - /// - /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorjavascriptexceptionoccurred. - static const int javaScriptExceptionOccurred = 4; - - /// Indicates the result of JavaScript execution could not be returned. - /// - /// See https://developer.apple.com/documentation/webkit/wkerrorcode/wkerrorjavascriptresulttypeisunsupported. - static const int javaScriptResultTypeIsUnsupported = 5; -} - -/// A record of the data that a particular website stores persistently. -/// -/// Wraps [WKWebsiteDataRecord](https://developer.apple.com/documentation/webkit/wkwebsitedatarecord?language=objc). -@immutable -class WKWebsiteDataRecord { - /// Constructs a [WKWebsiteDataRecord]. - const WKWebsiteDataRecord({required this.displayName}); - - /// Identifying information that you display to users. - final String displayName; -} - -/// An object that contains information about an action that causes navigation to occur. -/// -/// Wraps [WKNavigationAction](https://developer.apple.com/documentation/webkit/wknavigationaction?language=objc). -@immutable -class WKNavigationAction { - /// Constructs a [WKNavigationAction]. - const WKNavigationAction({ - required this.request, - required this.targetFrame, - required this.navigationType, - }); - - /// The URL request object associated with the navigation action. - final NSUrlRequest request; - - /// The frame in which to display the new content. - final WKFrameInfo targetFrame; - - /// The type of action that triggered the navigation. - final WKNavigationType navigationType; -} - -/// An object that contains information about a response to a navigation request. -/// -/// Wraps [WKNavigationResponse](https://developer.apple.com/documentation/webkit/wknavigationresponse?language=objc). -@immutable -class WKNavigationResponse { - /// Constructs a [WKNavigationResponse]. - const WKNavigationResponse({ - required this.response, - required this.forMainFrame, - }); - - /// The URL request object associated with the navigation action. - final NSHttpUrlResponse response; - - /// The frame in which to display the new content. - final bool forMainFrame; -} - -/// An object that contains information about a frame on a webpage. -/// -/// An instance of this class is a transient, data-only object; it does not -/// uniquely identify a frame across multiple delegate method calls. -/// -/// Wraps [WKFrameInfo](https://developer.apple.com/documentation/webkit/wkframeinfo?language=objc). -@immutable -class WKFrameInfo { - /// Construct a [WKFrameInfo]. - const WKFrameInfo({ - required this.isMainFrame, - required this.request, - }); - - /// Indicates whether the frame is the web site's main frame or a subframe. - final bool isMainFrame; - - /// The URL request object associated with the navigation action. - final NSUrlRequest request; -} - -/// A script that the web view injects into a webpage. -/// -/// Wraps [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript?language=objc). -@immutable -class WKUserScript { - /// Constructs a [UserScript]. - const WKUserScript( - this.source, - this.injectionTime, { - required this.isMainFrameOnly, - }); - - /// The script’s source code. - final String source; - - /// The time at which to inject the script into the webpage. - final WKUserScriptInjectionTime injectionTime; - - /// Indicates whether to inject the script into the main frame or all frames. - final bool isMainFrameOnly; -} - -/// An object that encapsulates a message sent by JavaScript code from a webpage. -/// -/// Wraps [WKScriptMessage](https://developer.apple.com/documentation/webkit/wkscriptmessage?language=objc). -@immutable -class WKScriptMessage { - /// Constructs a [WKScriptMessage]. - const WKScriptMessage({required this.name, this.body}); - - /// The name of the message handler to which the message is sent. - final String name; - - /// The body of the message. - /// - /// Allowed types are [num], [String], [List], [Map], and `null`. - final Object? body; -} - -/// Encapsulates the standard behaviors to apply to websites. -/// -/// Wraps [WKPreferences](https://developer.apple.com/documentation/webkit/wkpreferences?language=objc). -@immutable -class WKPreferences extends NSObject { - /// Constructs a [WKPreferences] that is owned by [configuration]. - factory WKPreferences.fromWebViewConfiguration( - WKWebViewConfiguration configuration, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKPreferences preferences = WKPreferences.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - preferences._preferencesApi.createFromWebViewConfigurationForInstances( - preferences, - configuration, - ); - return preferences; - } - - /// Constructs a [WKPreferences] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - WKPreferences.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _preferencesApi = WKPreferencesHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKPreferencesHostApiImpl _preferencesApi; - - // TODO(bparrishMines): Deprecated for iOS 14.0+. Add support for alternative. - /// Sets whether JavaScript is enabled. - /// - /// The default value is true. - Future setJavaScriptEnabled(bool enabled) { - return _preferencesApi.setJavaScriptEnabledForInstances(this, enabled); - } - - @override - WKPreferences copy() { - return WKPreferences.detached( - observeValue: observeValue, - binaryMessenger: _preferencesApi.binaryMessenger, - instanceManager: _preferencesApi.instanceManager, - ); - } -} - -/// Manages cookies, disk and memory caches, and other types of data for a web view. -/// -/// Wraps [WKWebsiteDataStore](https://developer.apple.com/documentation/webkit/wkwebsitedatastore?language=objc). -@immutable -class WKWebsiteDataStore extends NSObject { - /// Constructs a [WKWebsiteDataStore] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - WKWebsiteDataStore.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _websiteDataStoreApi = WKWebsiteDataStoreHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - factory WKWebsiteDataStore._defaultDataStore() { - final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore.detached(); - websiteDataStore._websiteDataStoreApi.createDefaultDataStoreForInstances( - websiteDataStore, - ); - return websiteDataStore; - } - - /// Constructs a [WKWebsiteDataStore] that is owned by [configuration]. - factory WKWebsiteDataStore.fromWebViewConfiguration( - WKWebViewConfiguration configuration, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - websiteDataStore._websiteDataStoreApi - .createFromWebViewConfigurationForInstances( - websiteDataStore, - configuration, - ); - return websiteDataStore; - } - - /// Default data store that stores data persistently to disk. - static final WKWebsiteDataStore defaultDataStore = - WKWebsiteDataStore._defaultDataStore(); - - final WKWebsiteDataStoreHostApiImpl _websiteDataStoreApi; - - /// Manages the HTTP cookies associated with a particular web view. - late final WKHttpCookieStore httpCookieStore = - WKHttpCookieStore.fromWebsiteDataStore(this); - - /// Removes website data that changed after the specified date. - /// - /// Returns whether any data was removed. - Future removeDataOfTypes( - Set dataTypes, - DateTime since, - ) { - return _websiteDataStoreApi.removeDataOfTypesForInstances( - this, - dataTypes, - secondsModifiedSinceEpoch: since.millisecondsSinceEpoch / 1000, - ); - } - - @override - WKWebsiteDataStore copy() { - return WKWebsiteDataStore.detached( - observeValue: observeValue, - binaryMessenger: _websiteDataStoreApi.binaryMessenger, - instanceManager: _websiteDataStoreApi.instanceManager, - ); - } -} - -/// An object that manages the HTTP cookies associated with a particular web view. -/// -/// Wraps [WKHTTPCookieStore](https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc). -@immutable -class WKHttpCookieStore extends NSObject { - /// Constructs a [WKHttpCookieStore] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - WKHttpCookieStore.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _httpCookieStoreApi = WKHttpCookieStoreHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - /// Constructs a [WKHttpCookieStore] that is owned by [dataStore]. - factory WKHttpCookieStore.fromWebsiteDataStore( - WKWebsiteDataStore dataStore, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKHttpCookieStore cookieStore = WKHttpCookieStore.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - cookieStore._httpCookieStoreApi.createFromWebsiteDataStoreForInstances( - cookieStore, - dataStore, - ); - return cookieStore; - } - - final WKHttpCookieStoreHostApiImpl _httpCookieStoreApi; - - /// Adds a cookie to the cookie store. - Future setCookie(NSHttpCookie cookie) { - return _httpCookieStoreApi.setCookieForInstances(this, cookie); - } - - @override - WKHttpCookieStore copy() { - return WKHttpCookieStore.detached( - observeValue: observeValue, - binaryMessenger: _httpCookieStoreApi.binaryMessenger, - instanceManager: _httpCookieStoreApi.instanceManager, - ); - } -} - -/// An interface for receiving messages from JavaScript code running in a webpage. -/// -/// Wraps [WKScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc). -@immutable -class WKScriptMessageHandler extends NSObject { - /// Constructs a [WKScriptMessageHandler]. - WKScriptMessageHandler({ - required this.didReceiveScriptMessage, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _scriptMessageHandlerApi.createForInstances(this); - } - - /// Constructs a [WKScriptMessageHandler] without creating the associated - /// Objective-C object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - WKScriptMessageHandler.detached({ - required this.didReceiveScriptMessage, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKScriptMessageHandlerHostApiImpl _scriptMessageHandlerApi; - - /// Tells the handler that a webpage sent a script message. - /// - /// Use this method to respond to a message sent from the webpage’s - /// JavaScript code. Use the [message] parameter to get the message contents and - /// to determine the originating web view. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function( - WKUserContentController userContentController, - WKScriptMessage message, - ) didReceiveScriptMessage; - - @override - WKScriptMessageHandler copy() { - return WKScriptMessageHandler.detached( - didReceiveScriptMessage: didReceiveScriptMessage, - observeValue: observeValue, - binaryMessenger: _scriptMessageHandlerApi.binaryMessenger, - instanceManager: _scriptMessageHandlerApi.instanceManager, - ); - } -} - -/// Manages interactions between JavaScript code and your web view. -/// -/// Use this object to do the following: -/// -/// * Inject JavaScript code into webpages running in your web view. -/// * Install custom JavaScript functions that call through to your app’s native -/// code. -/// -/// Wraps [WKUserContentController](https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc). -@immutable -class WKUserContentController extends NSObject { - /// Constructs a [WKUserContentController] that is owned by [configuration]. - factory WKUserContentController.fromWebViewConfiguration( - WKWebViewConfiguration configuration, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKUserContentController userContentController = - WKUserContentController.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - userContentController._userContentControllerApi - .createFromWebViewConfigurationForInstances( - userContentController, - configuration, - ); - return userContentController; - } - - /// Constructs a [WKUserContentController] without creating the associated - /// Objective-C object. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an InstanceManager. - WKUserContentController.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _userContentControllerApi = WKUserContentControllerHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKUserContentControllerHostApiImpl _userContentControllerApi; - - /// Installs a message handler that you can call from your JavaScript code. - /// - /// This name of the parameter must be unique within the user content - /// controller and must not be an empty string. The user content controller - /// uses this parameter to define a JavaScript function for your message - /// handler in the page’s main content world. The name of this function is - /// `window.webkit.messageHandlers..postMessage()`, where - /// `` corresponds to the value of this parameter. For example, if you - /// specify the string `MyFunction`, the user content controller defines the ` - /// `window.webkit.messageHandlers.MyFunction.postMessage()` function in - /// JavaScript. - Future addScriptMessageHandler( - WKScriptMessageHandler handler, - String name, - ) { - assert(name.isNotEmpty); - return _userContentControllerApi.addScriptMessageHandlerForInstances( - this, - handler, - name, - ); - } - - /// Uninstalls the custom message handler with the specified name from your JavaScript code. - /// - /// If no message handler with this name exists in the user content - /// controller, this method does nothing. - /// - /// Use this method to remove a message handler that you previously installed - /// using the [addScriptMessageHandler] method. This method removes the - /// message handler from the page content world. If you installed the message - /// handler in a different content world, this method doesn’t remove it. - Future removeScriptMessageHandler(String name) { - return _userContentControllerApi.removeScriptMessageHandlerForInstances( - this, - name, - ); - } - - /// Uninstalls all custom message handlers associated with the user content - /// controller. - /// - /// Only supported on iOS version 14+. - Future removeAllScriptMessageHandlers() { - return _userContentControllerApi.removeAllScriptMessageHandlersForInstances( - this, - ); - } - - /// Injects the specified script into the webpage’s content. - Future addUserScript(WKUserScript userScript) { - return _userContentControllerApi.addUserScriptForInstances( - this, userScript); - } - - /// Removes all user scripts from the web view. - Future removeAllUserScripts() { - return _userContentControllerApi.removeAllUserScriptsForInstances(this); - } - - @override - WKUserContentController copy() { - return WKUserContentController.detached( - observeValue: observeValue, - binaryMessenger: _userContentControllerApi.binaryMessenger, - instanceManager: _userContentControllerApi.instanceManager, - ); - } -} - -/// A collection of properties that you use to initialize a web view. -/// -/// Wraps [WKWebViewConfiguration](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc). -@immutable -class WKWebViewConfiguration extends NSObject { - /// Constructs a [WKWebViewConfiguration]. - WKWebViewConfiguration({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _webViewConfigurationApi = WKWebViewConfigurationHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _webViewConfigurationApi.createForInstances(this); - } - - /// A WKWebViewConfiguration that is owned by webView. - @visibleForTesting - factory WKWebViewConfiguration.fromWebView( - WKWebView webView, { - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKWebViewConfiguration configuration = - WKWebViewConfiguration.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - configuration._webViewConfigurationApi.createFromWebViewForInstances( - configuration, - webView, - ); - return configuration; - } - - /// Constructs a [WKWebViewConfiguration] without creating the associated - /// Objective-C object. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an InstanceManager. - WKWebViewConfiguration.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _webViewConfigurationApi = WKWebViewConfigurationHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - late final WKWebViewConfigurationHostApiImpl _webViewConfigurationApi; - - /// Coordinates interactions between your app’s code and the webpage’s scripts and other content. - late final WKUserContentController userContentController = - WKUserContentController.fromWebViewConfiguration( - this, - binaryMessenger: _webViewConfigurationApi.binaryMessenger, - instanceManager: _webViewConfigurationApi.instanceManager, - ); - - /// Manages the preference-related settings for the web view. - late final WKPreferences preferences = WKPreferences.fromWebViewConfiguration( - this, - binaryMessenger: _webViewConfigurationApi.binaryMessenger, - instanceManager: _webViewConfigurationApi.instanceManager, - ); - - /// Used to get and set the site’s cookies and to track the cached data objects. - /// - /// Represents [WKWebViewConfiguration.webSiteDataStore](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/1395661-websitedatastore?language=objc). - late final WKWebsiteDataStore websiteDataStore = - WKWebsiteDataStore.fromWebViewConfiguration( - this, - binaryMessenger: _webViewConfigurationApi.binaryMessenger, - instanceManager: _webViewConfigurationApi.instanceManager, - ); - - /// Indicates whether HTML5 videos play inline or use the native full-screen controller. - /// - /// Sets [WKWebViewConfiguration.allowsInlineMediaPlayback](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/1614793-allowsinlinemediaplayback?language=objc). - Future setAllowsInlineMediaPlayback(bool allow) { - return _webViewConfigurationApi.setAllowsInlineMediaPlaybackForInstances( - this, - allow, - ); - } - - /// Indicates whether the web view limits navigation to pages within the app’s domain. - /// - /// When navigation is limited, Javascript evaluation is unrestricted. - /// See https://webkit.org/blog/10882/app-bound-domains/ - /// - /// Sets [WKWebViewConfiguration.limitsNavigationsToAppBoundDomains](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/3585117-limitsnavigationstoappbounddomai?language=objc). - Future setLimitsNavigationsToAppBoundDomains(bool limit) { - return _webViewConfigurationApi - .setLimitsNavigationsToAppBoundDomainsForInstances( - this, - limit, - ); - } - - /// The media types that require a user gesture to begin playing. - /// - /// Use [WKAudiovisualMediaType.none] to indicate that no user gestures are - /// required to begin playing media. - /// - /// Sets [WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/1851524-mediatypesrequiringuseractionfor?language=objc). - Future setMediaTypesRequiringUserActionForPlayback( - Set types, - ) { - assert(types.isNotEmpty); - return _webViewConfigurationApi - .setMediaTypesRequiringUserActionForPlaybackForInstances( - this, - types, - ); - } - - @override - WKWebViewConfiguration copy() { - return WKWebViewConfiguration.detached( - observeValue: observeValue, - binaryMessenger: _webViewConfigurationApi.binaryMessenger, - instanceManager: _webViewConfigurationApi.instanceManager, - ); - } -} - -/// The methods for presenting native user interface elements on behalf of a webpage. -/// -/// Wraps [WKUIDelegate](https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc). -@immutable -class WKUIDelegate extends NSObject { - /// Constructs a [WKUIDelegate]. - WKUIDelegate({ - this.onCreateWebView, - this.requestMediaCapturePermission, - this.runJavaScriptAlertDialog, - this.runJavaScriptConfirmDialog, - this.runJavaScriptTextInputDialog, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _uiDelegateApi = WKUIDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _uiDelegateApi.createForInstances(this); - } - - /// Constructs a [WKUIDelegate] without creating the associated Objective-C - /// object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - WKUIDelegate.detached({ - this.onCreateWebView, - this.requestMediaCapturePermission, - this.runJavaScriptAlertDialog, - this.runJavaScriptConfirmDialog, - this.runJavaScriptTextInputDialog, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _uiDelegateApi = WKUIDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKUIDelegateHostApiImpl _uiDelegateApi; - - /// Indicates a new [WKWebView] was requested to be created with [configuration]. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function( - WKWebView webView, - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, - )? onCreateWebView; - - /// Determines whether a web resource, which the security origin object - /// describes, can gain access to the device’s microphone audio and camera - /// video. - final Future Function( - WKUIDelegate instance, - WKWebView webView, - WKSecurityOrigin origin, - WKFrameInfo frame, - WKMediaCaptureType type, - )? requestMediaCapturePermission; - - /// Notifies the host application that the web page - /// wants to display a JavaScript alert() dialog. - final Future Function(String message, WKFrameInfo frame)? - runJavaScriptAlertDialog; - - /// Notifies the host application that the web page - /// wants to display a JavaScript confirm() dialog. - final Future Function(String message, WKFrameInfo frame)? - runJavaScriptConfirmDialog; - - /// Notifies the host application that the web page - /// wants to display a JavaScript prompt() dialog. - final Future Function( - String prompt, String defaultText, WKFrameInfo frame)? - runJavaScriptTextInputDialog; - - @override - WKUIDelegate copy() { - return WKUIDelegate.detached( - onCreateWebView: onCreateWebView, - requestMediaCapturePermission: requestMediaCapturePermission, - runJavaScriptAlertDialog: runJavaScriptAlertDialog, - runJavaScriptConfirmDialog: runJavaScriptConfirmDialog, - runJavaScriptTextInputDialog: runJavaScriptTextInputDialog, - observeValue: observeValue, - binaryMessenger: _uiDelegateApi.binaryMessenger, - instanceManager: _uiDelegateApi.instanceManager, - ); - } -} - -/// An object that identifies the origin of a particular resource. -/// -/// Wraps https://developer.apple.com/documentation/webkit/wksecurityorigin?language=objc. -@immutable -class WKSecurityOrigin { - /// Constructs an [WKSecurityOrigin]. - const WKSecurityOrigin({ - required this.host, - required this.port, - required this.protocol, - }); - - /// The security origin’s host. - final String host; - - /// The security origin's port. - final int port; - - /// The security origin's protocol. - final String protocol; -} - -/// Methods for handling navigation changes and tracking navigation requests. -/// -/// Set the methods of the [WKNavigationDelegate] in the object you use to -/// coordinate changes in your web view’s main frame. -/// -/// Wraps [WKNavigationDelegate](https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc). -@immutable -class WKNavigationDelegate extends NSObject { - /// Constructs a [WKNavigationDelegate]. - WKNavigationDelegate({ - this.didFinishNavigation, - this.didStartProvisionalNavigation, - this.decidePolicyForNavigationAction, - this.decidePolicyForNavigationResponse, - this.didFailNavigation, - this.didFailProvisionalNavigation, - this.webViewWebContentProcessDidTerminate, - this.didReceiveAuthenticationChallenge, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _navigationDelegateApi.createForInstances(this); - } - - /// Constructs a [WKNavigationDelegate] without creating the associated - /// Objective-C object. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an InstanceManager. - WKNavigationDelegate.detached({ - this.didFinishNavigation, - this.didStartProvisionalNavigation, - this.decidePolicyForNavigationAction, - this.decidePolicyForNavigationResponse, - this.didFailNavigation, - this.didFailProvisionalNavigation, - this.webViewWebContentProcessDidTerminate, - this.didReceiveAuthenticationChallenge, - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKNavigationDelegateHostApiImpl _navigationDelegateApi; - - /// Called when navigation is complete. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function(WKWebView webView, String? url)? didFinishNavigation; - - /// Called when navigation from the main frame has started. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function(WKWebView webView, String? url)? - didStartProvisionalNavigation; - - /// Called when permission is needed to navigate to new content. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final Future Function( - WKWebView webView, - WKNavigationAction navigationAction, - )? decidePolicyForNavigationAction; - - /// Called when permission is needed to navigate to new content. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final Future Function( - WKWebView webView, - WKNavigationResponse navigationResponse, - )? decidePolicyForNavigationResponse; - - /// Called when an error occurred during navigation. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function(WKWebView webView, NSError error)? didFailNavigation; - - /// Called when an error occurred during the early navigation process. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function(WKWebView webView, NSError error)? - didFailProvisionalNavigation; - - /// Called when the web view’s content process was terminated. - /// - /// {@macro webview_flutter_wkwebview.foundation.callbacks} - final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate; - - /// Called when the delegate needs a response to an authentication challenge. - final void Function( - WKWebView webView, - NSUrlAuthenticationChallenge challenge, - void Function( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ) completionHandler, - )? didReceiveAuthenticationChallenge; - - @override - WKNavigationDelegate copy() { - return WKNavigationDelegate.detached( - didFinishNavigation: didFinishNavigation, - didStartProvisionalNavigation: didStartProvisionalNavigation, - decidePolicyForNavigationAction: decidePolicyForNavigationAction, - decidePolicyForNavigationResponse: decidePolicyForNavigationResponse, - didFailNavigation: didFailNavigation, - didFailProvisionalNavigation: didFailProvisionalNavigation, - webViewWebContentProcessDidTerminate: - webViewWebContentProcessDidTerminate, - didReceiveAuthenticationChallenge: didReceiveAuthenticationChallenge, - observeValue: observeValue, - binaryMessenger: _navigationDelegateApi.binaryMessenger, - instanceManager: _navigationDelegateApi.instanceManager, - ); - } -} - -/// Object that displays interactive web content, such as for an in-app browser. -/// -/// Wraps [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview?language=objc). -/// -/// This is abstract, since iOS and macOS WKWebViews have different -/// implementation details; the concrete implementations are [WKWebViewIOS] and -/// [WKWebViewMacOS]. -@immutable -abstract class WKWebView extends NSObject { - /// Constructs a [WKWebView]. - /// - /// [configuration] contains the configuration details for the web view. This - /// method saves a copy of your configuration object. Changes you make to your - /// original object after calling this method have no effect on the web view’s - /// configuration. For a list of configuration options and their default - /// values, see [WKWebViewConfiguration]. If you didn’t create your web view - /// using the `configuration` parameter, this value uses a default - /// configuration object. - WKWebView( - WKWebViewConfiguration configuration, { - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _webViewApi = WKWebViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached() { - // Ensures FlutterApis for the WebKit library are set up. - WebKitFlutterApis.instance.ensureSetUp(); - _webViewApi.createForInstances(this, configuration); - } - - /// Constructs a [WKWebView] without creating the associated Objective-C - /// object. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an InstanceManager. - WKWebView.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _webViewApi = WKWebViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final WKWebViewHostApiImpl _webViewApi; - - /// Contains the configuration details for the web view. - /// - /// Use the object in this property to obtain information about your web - /// view’s configuration. Because this property returns a copy of the - /// configuration object, changes you make to that object don’t affect the web - /// view’s configuration. - /// - /// If you didn’t create your web view with a [WKWebViewConfiguration] this - /// property contains a default configuration object. - late final WKWebViewConfiguration configuration = - WKWebViewConfiguration.fromWebView( - this, - binaryMessenger: _webViewApi.binaryMessenger, - instanceManager: _webViewApi.instanceManager, - ); - - /// Used to integrate custom user interface elements into web view interactions. - /// - /// Sets [WKWebView.UIDelegate](https://developer.apple.com/documentation/webkit/wkwebview/1415009-uidelegate?language=objc). - Future setUIDelegate(WKUIDelegate? delegate) { - return _webViewApi.setUIDelegateForInstances(this, delegate); - } - - /// The object you use to manage navigation behavior for the web view. - /// - /// Sets [WKWebView.navigationDelegate](https://developer.apple.com/documentation/webkit/wkwebview/1414971-navigationdelegate?language=objc). - Future setNavigationDelegate(WKNavigationDelegate? delegate) { - return _webViewApi.setNavigationDelegateForInstances(this, delegate); - } - - /// The URL for the current webpage. - /// - /// Represents [WKWebView.URL](https://developer.apple.com/documentation/webkit/wkwebview/1415005-url?language=objc). - Future getUrl() { - return _webViewApi.getUrlForInstances(this); - } - - /// An estimate of what fraction of the current navigation has been loaded. - /// - /// This value ranges from 0.0 to 1.0. - /// - /// Represents [WKWebView.estimatedProgress](https://developer.apple.com/documentation/webkit/wkwebview/1415007-estimatedprogress?language=objc). - Future getEstimatedProgress() { - return _webViewApi.getEstimatedProgressForInstances(this); - } - - /// Loads the web content referenced by the specified URL request object and navigates to it. - /// - /// Use this method to load a page from a local or network-based URL. For - /// example, you might use it to navigate to a network-based webpage. - Future loadRequest(NSUrlRequest request) { - return _webViewApi.loadRequestForInstances(this, request); - } - - /// Loads the contents of the specified HTML string and navigates to it. - Future loadHtmlString(String string, {String? baseUrl}) { - return _webViewApi.loadHtmlStringForInstances(this, string, baseUrl); - } - - /// Loads the web content from the specified file and navigates to it. - Future loadFileUrl(String url, {required String readAccessUrl}) { - return _webViewApi.loadFileUrlForInstances(this, url, readAccessUrl); - } - - /// Loads the Flutter asset specified in the pubspec.yaml file. - /// - /// This method is not a part of WebKit and is only a Flutter specific helper - /// method. - Future loadFlutterAsset(String key) { - return _webViewApi.loadFlutterAssetForInstances(this, key); - } - - /// Indicates whether there is a valid back item in the back-forward list. - Future canGoBack() { - return _webViewApi.canGoBackForInstances(this); - } - - /// Indicates whether there is a valid forward item in the back-forward list. - Future canGoForward() { - return _webViewApi.canGoForwardForInstances(this); - } - - /// Navigates to the back item in the back-forward list. - Future goBack() { - return _webViewApi.goBackForInstances(this); - } - - /// Navigates to the forward item in the back-forward list. - Future goForward() { - return _webViewApi.goForwardForInstances(this); - } - - /// Reloads the current webpage. - Future reload() { - return _webViewApi.reloadForInstances(this); - } - - /// The page title. - /// - /// Represents [WKWebView.title](https://developer.apple.com/documentation/webkit/wkwebview/1415015-title?language=objc). - Future getTitle() { - return _webViewApi.getTitleForInstances(this); - } - - /// The custom user agent string. - /// - /// Represents [WKWebView.customUserAgent](https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent?language=objc). - Future getCustomUserAgent() { - return _webViewApi.getCustomUserAgentForInstances(this); - } - - /// Indicates whether horizontal swipe gestures trigger page navigation. - /// - /// The default value is false. - /// - /// Sets [WKWebView.allowsBackForwardNavigationGestures](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu?language=objc). - Future setAllowsBackForwardNavigationGestures(bool allow) { - return _webViewApi.setAllowsBackForwardNavigationGesturesForInstances( - this, - allow, - ); - } - - /// The custom user agent string. - /// - /// The default value of this property is null. - /// - /// Sets [WKWebView.customUserAgent](https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent?language=objc). - Future setCustomUserAgent(String? userAgent) { - return _webViewApi.setCustomUserAgentForInstances(this, userAgent); - } - - /// Evaluates the specified JavaScript string. - /// - /// Throws a `PlatformException` if an error occurs or return value is not - /// supported. - Future evaluateJavaScript(String javaScriptString) { - return _webViewApi.evaluateJavaScriptForInstances( - this, - javaScriptString, - ); - } - - /// Enables debugging of web contents (HTML / CSS / JavaScript) in the - /// underlying WebView. - /// - /// This flag can be enabled in order to facilitate debugging of web layouts - /// and JavaScript code running inside WebViews. Please refer to [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview?language=objc). - /// documentation for the debugging guide. - /// - /// Starting from macOS version 13.3, iOS version 16.4, and tvOS version 16.4, - /// the default value is set to false. - /// - /// Defaults to true in previous versions. - Future setInspectable(bool inspectable) { - return _webViewApi.setInspectableForInstances( - this, - inspectable, - ); - } -} - -/// The iOS version of a WKWebView. -class WKWebViewIOS extends WKWebView implements UIView { - /// Constructs a new iOS WKWebView; see [WKWebView] for details. - WKWebViewIOS( - super.configuration, { - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _viewApi = UIViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super(); - - /// See [WKWebView.detached]. - WKWebViewIOS.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : _viewApi = UIViewHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - /// The scrollable view associated with the web view. - late final UIScrollView scrollView = UIScrollView.fromWebView( - this, - binaryMessenger: _webViewApi.binaryMessenger, - instanceManager: _webViewApi.instanceManager, - ); - - @override - WKWebView copy() { - return WKWebViewIOS.detached( - observeValue: observeValue, - binaryMessenger: _webViewApi.binaryMessenger, - instanceManager: _webViewApi.instanceManager, - ); - } - - final UIViewHostApiImpl _viewApi; - - // UIView implementations. This is duplicated from the UIViewBase class since - // WKWebView can't inherit from UIView, so this is a workaround to multiple - // inheritance limitations. This is a way of dealing with the lack of - // preprocessor in Dart, which is how the native side has different base - // classes. If the amount of code here grows, this could become a mixin used - // by both UIViewBase and this class (at the cost of exposing the view API - // object, or adjusting files to allow it to stay private). - @override - Future setBackgroundColor(Color? color) { - return _viewApi.setBackgroundColorForInstances(this, color); - } - - @override - Future setOpaque(bool opaque) { - return _viewApi.setOpaqueForInstances(this, opaque); - } -} - -/// The macOS version of a WKWebView. -class WKWebViewMacOS extends WKWebView { - /// Constructs a new macOS WKWebView; see [WKWebView] for details. - WKWebViewMacOS( - super.configuration, { - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : super(); - - /// See [WKWebView.detached]. - WKWebViewMacOS.detached({ - super.observeValue, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - @override - WKWebView copy() { - return WKWebViewMacOS.detached( - observeValue: observeValue, - binaryMessenger: _webViewApi.binaryMessenger, - instanceManager: _webViewApi.instanceManager, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart deleted file mode 100644 index 1caa1ccc5b09..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart +++ /dev/null @@ -1,1213 +0,0 @@ -// 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. - -import 'dart:async'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import '../common/instance_manager.dart'; -import '../common/web_kit.g.dart'; -import '../foundation/foundation.dart'; -import '../ui_kit/ui_kit.dart'; -import '../ui_kit/ui_kit_api_impls.dart'; -import 'web_kit.dart'; - -export '../common/web_kit.g.dart' - show WKMediaCaptureType, WKNavigationType, WKPermissionDecision; - -Iterable _toWKWebsiteDataTypeEnumData( - Iterable types) { - return types.map((WKWebsiteDataType type) { - late final WKWebsiteDataTypeEnum value; - switch (type) { - case WKWebsiteDataType.cookies: - value = WKWebsiteDataTypeEnum.cookies; - case WKWebsiteDataType.memoryCache: - value = WKWebsiteDataTypeEnum.memoryCache; - case WKWebsiteDataType.diskCache: - value = WKWebsiteDataTypeEnum.diskCache; - case WKWebsiteDataType.offlineWebApplicationCache: - value = WKWebsiteDataTypeEnum.offlineWebApplicationCache; - case WKWebsiteDataType.localStorage: - value = WKWebsiteDataTypeEnum.localStorage; - case WKWebsiteDataType.sessionStorage: - value = WKWebsiteDataTypeEnum.sessionStorage; - case WKWebsiteDataType.webSQLDatabases: - value = WKWebsiteDataTypeEnum.webSQLDatabases; - case WKWebsiteDataType.indexedDBDatabases: - value = WKWebsiteDataTypeEnum.indexedDBDatabases; - } - - return WKWebsiteDataTypeEnumData(value: value); - }); -} - -extension _NSHttpCookieConverter on NSHttpCookie { - NSHttpCookieData toNSHttpCookieData() { - final Iterable keys = properties.keys; - return NSHttpCookieData( - propertyKeys: keys.map( - (NSHttpCookiePropertyKey key) { - return key.toNSHttpCookiePropertyKeyEnumData(); - }, - ).toList(), - propertyValues: keys - .map((NSHttpCookiePropertyKey key) => properties[key]!) - .toList(), - ); - } -} - -extension _WKNavigationActionPolicyConverter on WKNavigationActionPolicy { - WKNavigationActionPolicyEnumData toWKNavigationActionPolicyEnumData() { - return WKNavigationActionPolicyEnumData( - value: WKNavigationActionPolicyEnum.values.firstWhere( - (WKNavigationActionPolicyEnum element) => element.name == name, - ), - ); - } -} - -extension _WKNavigationResponsePolicyConverter on WKNavigationResponsePolicy { - WKNavigationResponsePolicyEnum toWKNavigationResponsePolicyEnumData() { - return WKNavigationResponsePolicyEnum.values.firstWhere( - (WKNavigationResponsePolicyEnum element) => element.name == name, - ); - } -} - -extension _NSHttpCookiePropertyKeyConverter on NSHttpCookiePropertyKey { - NSHttpCookiePropertyKeyEnumData toNSHttpCookiePropertyKeyEnumData() { - late final NSHttpCookiePropertyKeyEnum value; - switch (this) { - case NSHttpCookiePropertyKey.comment: - value = NSHttpCookiePropertyKeyEnum.comment; - case NSHttpCookiePropertyKey.commentUrl: - value = NSHttpCookiePropertyKeyEnum.commentUrl; - case NSHttpCookiePropertyKey.discard: - value = NSHttpCookiePropertyKeyEnum.discard; - case NSHttpCookiePropertyKey.domain: - value = NSHttpCookiePropertyKeyEnum.domain; - case NSHttpCookiePropertyKey.expires: - value = NSHttpCookiePropertyKeyEnum.expires; - case NSHttpCookiePropertyKey.maximumAge: - value = NSHttpCookiePropertyKeyEnum.maximumAge; - case NSHttpCookiePropertyKey.name: - value = NSHttpCookiePropertyKeyEnum.name; - case NSHttpCookiePropertyKey.originUrl: - value = NSHttpCookiePropertyKeyEnum.originUrl; - case NSHttpCookiePropertyKey.path: - value = NSHttpCookiePropertyKeyEnum.path; - case NSHttpCookiePropertyKey.port: - value = NSHttpCookiePropertyKeyEnum.port; - case NSHttpCookiePropertyKey.sameSitePolicy: - value = NSHttpCookiePropertyKeyEnum.sameSitePolicy; - case NSHttpCookiePropertyKey.secure: - value = NSHttpCookiePropertyKeyEnum.secure; - case NSHttpCookiePropertyKey.value: - value = NSHttpCookiePropertyKeyEnum.value; - case NSHttpCookiePropertyKey.version: - value = NSHttpCookiePropertyKeyEnum.version; - } - - return NSHttpCookiePropertyKeyEnumData(value: value); - } -} - -extension _WKUserScriptInjectionTimeConverter on WKUserScriptInjectionTime { - WKUserScriptInjectionTimeEnumData toWKUserScriptInjectionTimeEnumData() { - late final WKUserScriptInjectionTimeEnum value; - switch (this) { - case WKUserScriptInjectionTime.atDocumentStart: - value = WKUserScriptInjectionTimeEnum.atDocumentStart; - case WKUserScriptInjectionTime.atDocumentEnd: - value = WKUserScriptInjectionTimeEnum.atDocumentEnd; - } - - return WKUserScriptInjectionTimeEnumData(value: value); - } -} - -Iterable _toWKAudiovisualMediaTypeEnumData( - Iterable types, -) { - return types - .map((WKAudiovisualMediaType type) { - late final WKAudiovisualMediaTypeEnum value; - switch (type) { - case WKAudiovisualMediaType.none: - value = WKAudiovisualMediaTypeEnum.none; - case WKAudiovisualMediaType.audio: - value = WKAudiovisualMediaTypeEnum.audio; - case WKAudiovisualMediaType.video: - value = WKAudiovisualMediaTypeEnum.video; - case WKAudiovisualMediaType.all: - value = WKAudiovisualMediaTypeEnum.all; - } - - return WKAudiovisualMediaTypeEnumData(value: value); - }); -} - -extension _NavigationActionDataConverter on WKNavigationActionData { - WKNavigationAction toNavigationAction() { - return WKNavigationAction( - request: request.toNSUrlRequest(), - targetFrame: targetFrame.toWKFrameInfo(), - navigationType: navigationType, - ); - } -} - -extension _NavigationResponseDataConverter on WKNavigationResponseData { - WKNavigationResponse toNavigationResponse() { - return WKNavigationResponse( - response: response.toNSUrlResponse(), forMainFrame: forMainFrame); - } -} - -extension _WKFrameInfoDataConverter on WKFrameInfoData { - WKFrameInfo toWKFrameInfo() { - return WKFrameInfo( - isMainFrame: isMainFrame, - request: request.toNSUrlRequest(), - ); - } -} - -extension _NSUrlRequestDataConverter on NSUrlRequestData { - NSUrlRequest toNSUrlRequest() { - return NSUrlRequest( - url: url, - httpBody: httpBody, - httpMethod: httpMethod, - allHttpHeaderFields: allHttpHeaderFields.cast(), - ); - } -} - -extension _NSUrlResponseDataConverter on NSHttpUrlResponseData { - NSHttpUrlResponse toNSUrlResponse() { - return NSHttpUrlResponse(statusCode: statusCode); - } -} - -extension _WKNSErrorDataConverter on NSErrorData { - NSError toNSError() { - return NSError( - domain: domain, - code: code, - userInfo: userInfo?.cast() ?? {}, - ); - } -} - -extension _WKScriptMessageDataConverter on WKScriptMessageData { - WKScriptMessage toWKScriptMessage() { - return WKScriptMessage(name: name, body: body); - } -} - -extension _WKUserScriptConverter on WKUserScript { - WKUserScriptData toWKUserScriptData() { - return WKUserScriptData( - source: source, - injectionTime: injectionTime.toWKUserScriptInjectionTimeEnumData(), - isMainFrameOnly: isMainFrameOnly, - ); - } -} - -extension _NSUrlRequestConverter on NSUrlRequest { - NSUrlRequestData toNSUrlRequestData() { - return NSUrlRequestData( - url: url, - httpMethod: httpMethod, - httpBody: httpBody, - allHttpHeaderFields: allHttpHeaderFields, - ); - } -} - -extension _WKSecurityOriginConverter on WKSecurityOriginData { - WKSecurityOrigin toWKSecurityOrigin() { - return WKSecurityOrigin(host: host, port: port, protocol: protocol); - } -} - -/// Handles initialization of Flutter APIs for WebKit. -class WebKitFlutterApis { - /// Constructs a [WebKitFlutterApis]. - @visibleForTesting - WebKitFlutterApis({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _binaryMessenger = binaryMessenger, - navigationDelegate = WKNavigationDelegateFlutterApiImpl( - instanceManager: instanceManager, - ), - scriptMessageHandler = WKScriptMessageHandlerFlutterApiImpl( - instanceManager: instanceManager, - ), - uiDelegate = WKUIDelegateFlutterApiImpl( - instanceManager: instanceManager, - ), - webViewConfiguration = WKWebViewConfigurationFlutterApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - uiScrollViewDelegate = UIScrollViewDelegateFlutterApiImpl( - instanceManager: instanceManager, - ); - - static WebKitFlutterApis _instance = WebKitFlutterApis(); - - /// Sets the global instance containing the Flutter Apis for the WebKit library. - @visibleForTesting - static set instance(WebKitFlutterApis instance) { - _instance = instance; - } - - /// Global instance containing the Flutter Apis for the WebKit library. - static WebKitFlutterApis get instance { - return _instance; - } - - final BinaryMessenger? _binaryMessenger; - bool _hasBeenSetUp = false; - - /// Flutter Api for [WKNavigationDelegate]. - @visibleForTesting - final WKNavigationDelegateFlutterApiImpl navigationDelegate; - - /// Flutter Api for [WKScriptMessageHandler]. - @visibleForTesting - final WKScriptMessageHandlerFlutterApiImpl scriptMessageHandler; - - /// Flutter Api for [WKUIDelegate]. - @visibleForTesting - final WKUIDelegateFlutterApiImpl uiDelegate; - - /// Flutter Api for [WKWebViewConfiguration]. - @visibleForTesting - final WKWebViewConfigurationFlutterApiImpl webViewConfiguration; - - /// Flutter Api for [UIScrollViewDelegate]. - @visibleForTesting - final UIScrollViewDelegateFlutterApiImpl uiScrollViewDelegate; - - /// Ensures all the Flutter APIs have been set up to receive calls from native code. - void ensureSetUp() { - if (!_hasBeenSetUp) { - WKNavigationDelegateFlutterApi.setUp( - navigationDelegate, - binaryMessenger: _binaryMessenger, - ); - WKScriptMessageHandlerFlutterApi.setUp( - scriptMessageHandler, - binaryMessenger: _binaryMessenger, - ); - WKUIDelegateFlutterApi.setUp( - uiDelegate, - binaryMessenger: _binaryMessenger, - ); - WKWebViewConfigurationFlutterApi.setUp( - webViewConfiguration, - binaryMessenger: _binaryMessenger, - ); - UIScrollViewDelegateFlutterApi.setUp(uiScrollViewDelegate, - binaryMessenger: _binaryMessenger); - _hasBeenSetUp = true; - } - } -} - -/// Host api implementation for [WKWebSiteDataStore]. -class WKWebsiteDataStoreHostApiImpl extends WKWebsiteDataStoreHostApi { - /// Constructs a [WebsiteDataStoreHostApiImpl]. - WKWebsiteDataStoreHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createFromWebViewConfiguration] with the ids of the provided object instances. - Future createFromWebViewConfigurationForInstances( - WKWebsiteDataStore instance, - WKWebViewConfiguration configuration, - ) { - return createFromWebViewConfiguration( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(configuration)!, - ); - } - - /// Calls [createDefaultDataStore] with the ids of the provided object instances. - Future createDefaultDataStoreForInstances( - WKWebsiteDataStore instance, - ) { - return createDefaultDataStore( - instanceManager.addDartCreatedInstance(instance), - ); - } - - /// Calls [removeDataOfTypes] with the ids of the provided object instances. - Future removeDataOfTypesForInstances( - WKWebsiteDataStore instance, - Set dataTypes, { - required double secondsModifiedSinceEpoch, - }) { - return removeDataOfTypes( - instanceManager.getIdentifier(instance)!, - _toWKWebsiteDataTypeEnumData(dataTypes).toList(), - secondsModifiedSinceEpoch, - ); - } -} - -/// Host api implementation for [WKScriptMessageHandler]. -class WKScriptMessageHandlerHostApiImpl extends WKScriptMessageHandlerHostApi { - /// Constructs a [WKScriptMessageHandlerHostApiImpl]. - WKScriptMessageHandlerHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstances(WKScriptMessageHandler instance) { - return create(instanceManager.addDartCreatedInstance(instance)); - } -} - -/// Flutter api implementation for [WKScriptMessageHandler]. -class WKScriptMessageHandlerFlutterApiImpl - extends WKScriptMessageHandlerFlutterApi { - /// Constructs a [WKScriptMessageHandlerFlutterApiImpl]. - WKScriptMessageHandlerFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - WKScriptMessageHandler _getHandler(int identifier) { - return instanceManager.getInstanceWithWeakReference(identifier)!; - } - - @override - void didReceiveScriptMessage( - int identifier, - int userContentControllerIdentifier, - WKScriptMessageData message, - ) { - _getHandler(identifier).didReceiveScriptMessage( - instanceManager.getInstanceWithWeakReference( - userContentControllerIdentifier, - )! as WKUserContentController, - message.toWKScriptMessage(), - ); - } -} - -/// Host api implementation for [WKPreferences]. -class WKPreferencesHostApiImpl extends WKPreferencesHostApi { - /// Constructs a [WKPreferencesHostApiImpl]. - WKPreferencesHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createFromWebViewConfiguration] with the ids of the provided object instances. - Future createFromWebViewConfigurationForInstances( - WKPreferences instance, - WKWebViewConfiguration configuration, - ) { - return createFromWebViewConfiguration( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(configuration)!, - ); - } - - /// Calls [setJavaScriptEnabled] with the ids of the provided object instances. - Future setJavaScriptEnabledForInstances( - WKPreferences instance, - bool enabled, - ) { - return setJavaScriptEnabled( - instanceManager.getIdentifier(instance)!, - enabled, - ); - } -} - -/// Host api implementation for [WKHttpCookieStore]. -class WKHttpCookieStoreHostApiImpl extends WKHttpCookieStoreHostApi { - /// Constructs a [WKHttpCookieStoreHostApiImpl]. - WKHttpCookieStoreHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createFromWebsiteDataStore] with the ids of the provided object instances. - Future createFromWebsiteDataStoreForInstances( - WKHttpCookieStore instance, - WKWebsiteDataStore dataStore, - ) { - return createFromWebsiteDataStore( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(dataStore)!, - ); - } - - /// Calls [setCookie] with the ids of the provided object instances. - Future setCookieForInstances( - WKHttpCookieStore instance, - NSHttpCookie cookie, - ) { - return setCookie( - instanceManager.getIdentifier(instance)!, - cookie.toNSHttpCookieData(), - ); - } -} - -/// Host api implementation for [WKUserContentController]. -class WKUserContentControllerHostApiImpl - extends WKUserContentControllerHostApi { - /// Constructs a [WKUserContentControllerHostApiImpl]. - WKUserContentControllerHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [createFromWebViewConfiguration] with the ids of the provided object instances. - Future createFromWebViewConfigurationForInstances( - WKUserContentController instance, - WKWebViewConfiguration configuration, - ) { - return createFromWebViewConfiguration( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(configuration)!, - ); - } - - /// Calls [addScriptMessageHandler] with the ids of the provided object instances. - Future addScriptMessageHandlerForInstances( - WKUserContentController instance, - WKScriptMessageHandler handler, - String name, - ) { - return addScriptMessageHandler( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(handler)!, - name, - ); - } - - /// Calls [removeScriptMessageHandler] with the ids of the provided object instances. - Future removeScriptMessageHandlerForInstances( - WKUserContentController instance, - String name, - ) { - return removeScriptMessageHandler( - instanceManager.getIdentifier(instance)!, - name, - ); - } - - /// Calls [removeAllScriptMessageHandlers] with the ids of the provided object instances. - Future removeAllScriptMessageHandlersForInstances( - WKUserContentController instance, - ) { - return removeAllScriptMessageHandlers( - instanceManager.getIdentifier(instance)!, - ); - } - - /// Calls [addUserScript] with the ids of the provided object instances. - Future addUserScriptForInstances( - WKUserContentController instance, - WKUserScript userScript, - ) { - return addUserScript( - instanceManager.getIdentifier(instance)!, - userScript.toWKUserScriptData(), - ); - } - - /// Calls [removeAllUserScripts] with the ids of the provided object instances. - Future removeAllUserScriptsForInstances( - WKUserContentController instance, - ) { - return removeAllUserScripts(instanceManager.getIdentifier(instance)!); - } -} - -/// Host api implementation for [WKWebViewConfiguration]. -class WKWebViewConfigurationHostApiImpl extends WKWebViewConfigurationHostApi { - /// Constructs a [WKWebViewConfigurationHostApiImpl]. - WKWebViewConfigurationHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstances(WKWebViewConfiguration instance) { - return create(instanceManager.addDartCreatedInstance(instance)); - } - - /// Calls [createFromWebView] with the ids of the provided object instances. - Future createFromWebViewForInstances( - WKWebViewConfiguration instance, - WKWebView webView, - ) { - return createFromWebView( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(webView)!, - ); - } - - /// Calls [setAllowsInlineMediaPlayback] with the ids of the provided object instances. - Future setAllowsInlineMediaPlaybackForInstances( - WKWebViewConfiguration instance, - bool allow, - ) { - return setAllowsInlineMediaPlayback( - instanceManager.getIdentifier(instance)!, - allow, - ); - } - - /// Calls [setLimitsNavigationsToAppBoundDomains] with the ids of the provided object instances. - Future setLimitsNavigationsToAppBoundDomainsForInstances( - WKWebViewConfiguration instance, - bool limit, - ) { - return setLimitsNavigationsToAppBoundDomains( - instanceManager.getIdentifier(instance)!, - limit, - ); - } - - /// Calls [setMediaTypesRequiringUserActionForPlayback] with the ids of the provided object instances. - Future setMediaTypesRequiringUserActionForPlaybackForInstances( - WKWebViewConfiguration instance, - Set types, - ) { - return setMediaTypesRequiringUserActionForPlayback( - instanceManager.getIdentifier(instance)!, - _toWKAudiovisualMediaTypeEnumData(types).toList(), - ); - } -} - -/// Flutter api implementation for [WKWebViewConfiguration]. -@immutable -class WKWebViewConfigurationFlutterApiImpl - extends WKWebViewConfigurationFlutterApi { - /// Constructs a [WKWebViewConfigurationFlutterApiImpl]. - WKWebViewConfigurationFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int identifier) { - instanceManager.addHostCreatedInstance( - WKWebViewConfiguration.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Host api implementation for [WKUIDelegate]. -class WKUIDelegateHostApiImpl extends WKUIDelegateHostApi { - /// Constructs a [WKUIDelegateHostApiImpl]. - WKUIDelegateHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstances(WKUIDelegate instance) async { - return create(instanceManager.addDartCreatedInstance(instance)); - } -} - -/// Flutter api implementation for [WKUIDelegate]. -class WKUIDelegateFlutterApiImpl extends WKUIDelegateFlutterApi { - /// Constructs a [WKUIDelegateFlutterApiImpl]. - WKUIDelegateFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - WKUIDelegate _getDelegate(int identifier) { - return instanceManager.getInstanceWithWeakReference(identifier)!; - } - - @override - void onCreateWebView( - int identifier, - int webViewIdentifier, - int configurationIdentifier, - WKNavigationActionData navigationAction, - ) { - final void Function(WKWebView, WKWebViewConfiguration, WKNavigationAction)? - function = _getDelegate(identifier).onCreateWebView; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - instanceManager.getInstanceWithWeakReference(configurationIdentifier)! - as WKWebViewConfiguration, - navigationAction.toNavigationAction(), - ); - } - - @override - Future requestMediaCapturePermission( - int identifier, - int webViewIdentifier, - WKSecurityOriginData origin, - WKFrameInfoData frame, - WKMediaCaptureTypeData type, - ) async { - final WKUIDelegate instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - - late final WKPermissionDecision decision; - if (instance.requestMediaCapturePermission != null) { - decision = await instance.requestMediaCapturePermission!( - instance, - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - origin.toWKSecurityOrigin(), - frame.toWKFrameInfo(), - type.value, - ); - } else { - // The default response for iOS is to prompt. See - // https://developer.apple.com/documentation/webkit/wkuidelegate/3763087-webview?language=objc - decision = WKPermissionDecision.prompt; - } - - return WKPermissionDecisionData(value: decision); - } - - @override - Future runJavaScriptAlertPanel( - int identifier, String message, WKFrameInfoData frame) { - final WKUIDelegate instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - return instance.runJavaScriptAlertDialog! - .call(message, frame.toWKFrameInfo()); - } - - @override - Future runJavaScriptConfirmPanel( - int identifier, String message, WKFrameInfoData frame) { - final WKUIDelegate instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - return instance.runJavaScriptConfirmDialog! - .call(message, frame.toWKFrameInfo()); - } - - @override - Future runJavaScriptTextInputPanel(int identifier, String prompt, - String defaultText, WKFrameInfoData frame) { - final WKUIDelegate instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - return instance.runJavaScriptTextInputDialog! - .call(prompt, defaultText, frame.toWKFrameInfo()); - } -} - -/// Host api implementation for [WKNavigationDelegate]. -class WKNavigationDelegateHostApiImpl extends WKNavigationDelegateHostApi { - /// Constructs a [WKNavigationDelegateHostApiImpl]. - WKNavigationDelegateHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstances(WKNavigationDelegate instance) async { - return create(instanceManager.addDartCreatedInstance(instance)); - } -} - -/// Flutter api implementation for [WKNavigationDelegate]. -class WKNavigationDelegateFlutterApiImpl - extends WKNavigationDelegateFlutterApi { - /// Constructs a [WKNavigationDelegateFlutterApiImpl]. - WKNavigationDelegateFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? NSObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - WKNavigationDelegate _getDelegate(int identifier) { - return instanceManager.getInstanceWithWeakReference(identifier)!; - } - - @override - void didFinishNavigation( - int identifier, - int webViewIdentifier, - String? url, - ) { - final void Function(WKWebView, String?)? function = - _getDelegate(identifier).didFinishNavigation; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - url, - ); - } - - @override - Future decidePolicyForNavigationAction( - int identifier, - int webViewIdentifier, - WKNavigationActionData navigationAction, - ) async { - final Future Function( - WKWebView, - WKNavigationAction navigationAction, - )? function = _getDelegate(identifier).decidePolicyForNavigationAction; - - if (function == null) { - return WKNavigationActionPolicyEnumData( - value: WKNavigationActionPolicyEnum.allow, - ); - } - - final WKNavigationActionPolicy policy = await function( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - navigationAction.toNavigationAction(), - ); - return policy.toWKNavigationActionPolicyEnumData(); - } - - @override - void didFailNavigation( - int identifier, - int webViewIdentifier, - NSErrorData error, - ) { - final void Function(WKWebView, NSError)? function = - _getDelegate(identifier).didFailNavigation; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - error.toNSError(), - ); - } - - @override - void didFailProvisionalNavigation( - int identifier, - int webViewIdentifier, - NSErrorData error, - ) { - final void Function(WKWebView, NSError)? function = - _getDelegate(identifier).didFailProvisionalNavigation; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - error.toNSError(), - ); - } - - @override - void didStartProvisionalNavigation( - int identifier, - int webViewIdentifier, - String? url, - ) { - final void Function(WKWebView, String?)? function = - _getDelegate(identifier).didStartProvisionalNavigation; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - url, - ); - } - - @override - Future decidePolicyForNavigationResponse( - int identifier, - int webViewIdentifier, - WKNavigationResponseData navigationResponse, - ) async { - final Future Function( - WKWebView, - WKNavigationResponse navigationResponse, - )? function = _getDelegate(identifier).decidePolicyForNavigationResponse; - - if (function == null) { - return WKNavigationResponsePolicyEnum.allow; - } - - final WKNavigationResponsePolicy policy = await function( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - navigationResponse.toNavigationResponse(), - ); - return policy.toWKNavigationResponsePolicyEnumData(); - } - - @override - void webViewWebContentProcessDidTerminate( - int identifier, - int webViewIdentifier, - ) { - final void Function(WKWebView)? function = - _getDelegate(identifier).webViewWebContentProcessDidTerminate; - function?.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - ); - } - - @override - Future didReceiveAuthenticationChallenge( - int identifier, - int webViewIdentifier, - int challengeIdentifier, - ) async { - final void Function( - WKWebView webView, - NSUrlAuthenticationChallenge challenge, - void Function( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ), - )? function = _getDelegate(identifier).didReceiveAuthenticationChallenge; - - if (function == null) { - return AuthenticationChallengeResponse( - disposition: NSUrlSessionAuthChallengeDisposition.rejectProtectionSpace, - ); - } - - final Completer responseCompleter = - Completer(); - - function.call( - instanceManager.getInstanceWithWeakReference(webViewIdentifier)! - as WKWebView, - instanceManager.getInstanceWithWeakReference(challengeIdentifier)! - as NSUrlAuthenticationChallenge, - ( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ) { - responseCompleter.complete( - AuthenticationChallengeResponse( - disposition: disposition, - credentialIdentifier: credential != null - ? instanceManager.getIdentifier(credential) - : null, - ), - ); - }, - ); - - return responseCompleter.future; - } -} - -/// Host api implementation for [WKWebView]. -class WKWebViewHostApiImpl extends WKWebViewHostApi { - /// Constructs a [WKWebViewHostApiImpl]. - WKWebViewHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with Objective-C objects. - final InstanceManager instanceManager; - - /// Calls [create] with the ids of the provided object instances. - Future createForInstances( - WKWebView instance, - WKWebViewConfiguration configuration, - ) { - return create( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(configuration)!, - ); - } - - /// Calls [loadRequest] with the ids of the provided object instances. - Future loadRequestForInstances( - WKWebView webView, - NSUrlRequest request, - ) { - return loadRequest( - instanceManager.getIdentifier(webView)!, - request.toNSUrlRequestData(), - ); - } - - /// Calls [loadHtmlString] with the ids of the provided object instances. - Future loadHtmlStringForInstances( - WKWebView instance, - String string, - String? baseUrl, - ) { - return loadHtmlString( - instanceManager.getIdentifier(instance)!, - string, - baseUrl, - ); - } - - /// Calls [loadFileUrl] with the ids of the provided object instances. - Future loadFileUrlForInstances( - WKWebView instance, - String url, - String readAccessUrl, - ) { - return loadFileUrl( - instanceManager.getIdentifier(instance)!, - url, - readAccessUrl, - ); - } - - /// Calls [loadFlutterAsset] with the ids of the provided object instances. - Future loadFlutterAssetForInstances(WKWebView instance, String key) { - return loadFlutterAsset( - instanceManager.getIdentifier(instance)!, - key, - ); - } - - /// Calls [canGoBack] with the ids of the provided object instances. - Future canGoBackForInstances(WKWebView instance) { - return canGoBack(instanceManager.getIdentifier(instance)!); - } - - /// Calls [canGoForward] with the ids of the provided object instances. - Future canGoForwardForInstances(WKWebView instance) { - return canGoForward(instanceManager.getIdentifier(instance)!); - } - - /// Calls [goBack] with the ids of the provided object instances. - Future goBackForInstances(WKWebView instance) { - return goBack(instanceManager.getIdentifier(instance)!); - } - - /// Calls [goForward] with the ids of the provided object instances. - Future goForwardForInstances(WKWebView instance) { - return goForward(instanceManager.getIdentifier(instance)!); - } - - /// Calls [reload] with the ids of the provided object instances. - Future reloadForInstances(WKWebView instance) { - return reload(instanceManager.getIdentifier(instance)!); - } - - /// Calls [getUrl] with the ids of the provided object instances. - Future getUrlForInstances(WKWebView instance) { - return getUrl(instanceManager.getIdentifier(instance)!); - } - - /// Calls [getTitle] with the ids of the provided object instances. - Future getTitleForInstances(WKWebView instance) { - return getTitle(instanceManager.getIdentifier(instance)!); - } - - /// Calls [getEstimatedProgress] with the ids of the provided object instances. - Future getEstimatedProgressForInstances(WKWebView instance) { - return getEstimatedProgress(instanceManager.getIdentifier(instance)!); - } - - /// Calls [setAllowsBackForwardNavigationGestures] with the ids of the provided object instances. - Future setAllowsBackForwardNavigationGesturesForInstances( - WKWebView instance, - bool allow, - ) { - return setAllowsBackForwardNavigationGestures( - instanceManager.getIdentifier(instance)!, - allow, - ); - } - - /// Calls [setCustomUserAgent] with the ids of the provided object instances. - Future setCustomUserAgentForInstances( - WKWebView instance, - String? userAgent, - ) { - return setCustomUserAgent( - instanceManager.getIdentifier(instance)!, - userAgent, - ); - } - - /// Calls [evaluateJavaScript] with the ids of the provided object instances. - Future evaluateJavaScriptForInstances( - WKWebView instance, - String javaScriptString, - ) async { - try { - final Object? result = await evaluateJavaScript( - instanceManager.getIdentifier(instance)!, - javaScriptString, - ); - return result; - } on PlatformException catch (exception) { - if (exception.details is! NSErrorData) { - rethrow; - } - - throw PlatformException( - code: exception.code, - message: exception.message, - stacktrace: exception.stacktrace, - details: (exception.details as NSErrorData).toNSError(), - ); - } - } - - /// Calls [setInspectable] with the ids of the provided object instances. - Future setInspectableForInstances( - WKWebView instance, - bool inspectable, - ) async { - return setInspectable( - instanceManager.getIdentifier(instance)!, - inspectable, - ); - } - - /// Calls [getCustomUserAgent] with the ids of the provided object instances. - Future getCustomUserAgentForInstances(WKWebView instance) { - return getCustomUserAgent(instanceManager.getIdentifier(instance)!); - } - - /// Calls [setNavigationDelegate] with the ids of the provided object instances. - Future setNavigationDelegateForInstances( - WKWebView instance, - WKNavigationDelegate? delegate, - ) { - return setNavigationDelegate( - instanceManager.getIdentifier(instance)!, - delegate != null ? instanceManager.getIdentifier(delegate)! : null, - ); - } - - /// Calls [setUIDelegate] with the ids of the provided object instances. - Future setUIDelegateForInstances( - WKWebView instance, - WKUIDelegate? delegate, - ) { - return setUIDelegate( - instanceManager.getIdentifier(instance)!, - delegate != null ? instanceManager.getIdentifier(delegate)! : null, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_proxy.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_proxy.dart index 82277babadee..5c3638bd04c5 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_proxy.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_proxy.dart @@ -2,147 +2,189 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io'; - -import 'common/instance_manager.dart'; -import 'foundation/foundation.dart'; -import 'ui_kit/ui_kit.dart'; -import 'web_kit/web_kit.dart'; - -// This convenience method was added because Dart doesn't support constant -// function literals: https://github.com/dart-lang/language/issues/1048. -WKWebsiteDataStore _defaultWebsiteDataStore() => - WKWebsiteDataStore.defaultDataStore; - -// This convenience method was added because Dart doesn't support constant -// function literals: https://github.com/dart-lang/language/issues/1048. -WKWebView _platformWebViewConstructor( - WKWebViewConfiguration configuration, { - void Function( - String keyPath, - NSObject object, - Map change, - )? observeValue, - InstanceManager? instanceManager, -}) { - return Platform.isIOS - ? WKWebViewIOS(configuration, - observeValue: observeValue, instanceManager: instanceManager) - : WKWebViewMacOS(configuration, - observeValue: observeValue, instanceManager: instanceManager); -} +import 'common/platform_webview.dart'; +import 'common/web_kit.g.dart'; -/// Handles constructing objects and calling static methods for the WebKit -/// native library. +/// Handles constructing objects and calling static methods for the Darwin +/// WebKit native library. /// /// This class provides dependency injection for the implementations of the /// platform interface classes. Improving the ease of unit testing and/or -/// overriding the underlying WebKit classes. +/// overriding the underlying Darwin classes. /// -/// By default each function calls the default constructor of the WebKit class -/// it intends to return. +/// By default each function calls the default constructor of the class it +/// intends to return. class WebKitProxy { - /// Constructs a [WebKitProxy]. + /// Constructs an [WebKitProxy]. const WebKitProxy({ - this.createWebView = _platformWebViewConstructor, - this.createWebViewConfiguration = WKWebViewConfiguration.new, - this.createScriptMessageHandler = WKScriptMessageHandler.new, - this.defaultWebsiteDataStore = _defaultWebsiteDataStore, - this.createNavigationDelegate = WKNavigationDelegate.new, - this.createUIDelegate = WKUIDelegate.new, - this.createUIScrollViewDelegate = UIScrollViewDelegate.new, + this.newURLRequest = URLRequest.new, + this.newWKUserScript = WKUserScript.new, + this.newHTTPCookie = HTTPCookie.new, + this.newAuthenticationChallengeResponse = + AuthenticationChallengeResponse.new, + this.newWKWebViewConfiguration = WKWebViewConfiguration.new, + this.newWKScriptMessageHandler = WKScriptMessageHandler.new, + this.newWKNavigationDelegate = WKNavigationDelegate.new, + this.newNSObject = NSObject.new, + this.newPlatformWebView = PlatformWebView.new, + this.newWKUIDelegate = WKUIDelegate.new, + this.newUIScrollViewDelegate = UIScrollViewDelegate.new, + this.withUserURLCredential = URLCredential.withUser, + this.defaultDataStoreWKWebsiteDataStore = + _defaultDataStoreWKWebsiteDataStore, }); - /// Constructs a [WKWebView]. - final WKWebView Function( - WKWebViewConfiguration configuration, { - void Function( - String keyPath, - NSObject object, - Map change, - )? observeValue, - InstanceManager? instanceManager, - }) createWebView; + /// Constructs [URLRequest]. + final URLRequest Function({required String url}) newURLRequest; + + /// Constructs [WKUserScript]. + final WKUserScript Function({ + required String source, + required UserScriptInjectionTime injectionTime, + required bool isForMainFrameOnly, + }) newWKUserScript; + + /// Constructs [HTTPCookie]. + final HTTPCookie Function( + {required Map properties}) newHTTPCookie; - /// Constructs a [WKWebViewConfiguration]. - final WKWebViewConfiguration Function({ - InstanceManager? instanceManager, - }) createWebViewConfiguration; + /// Constructs [AuthenticationChallengeResponse]. + final AuthenticationChallengeResponse Function({ + required UrlSessionAuthChallengeDisposition disposition, + URLCredential? credential, + }) newAuthenticationChallengeResponse; - /// Constructs a [WKScriptMessageHandler]. + /// Constructs [WKWebViewConfiguration]. + final WKWebViewConfiguration Function() newWKWebViewConfiguration; + + /// Constructs [WKScriptMessageHandler]. final WKScriptMessageHandler Function({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, - }) createScriptMessageHandler; - - /// The default [WKWebsiteDataStore]. - final WKWebsiteDataStore Function() defaultWebsiteDataStore; + }) newWKScriptMessageHandler; - /// Constructs a [WKNavigationDelegate]. + /// Constructs [WKNavigationDelegate]. final WKNavigationDelegate Function({ - void Function(WKWebView webView, String? url)? didFinishNavigation, - void Function(WKWebView webView, String? url)? - didStartProvisionalNavigation, - Future Function( - WKWebView webView, - WKNavigationAction navigationAction, + void Function( + WKNavigationDelegate, + WKWebView, + String?, + )? didFinishNavigation, + void Function( + WKNavigationDelegate, + WKWebView, + String?, + )? didStartProvisionalNavigation, + Future Function( + WKNavigationDelegate, + WKWebView, + WKNavigationAction, )? decidePolicyForNavigationAction, - Future Function( - WKWebView webView, - WKNavigationResponse navigationResponse, + Future Function( + WKNavigationDelegate, + WKWebView, + WKNavigationResponse, )? decidePolicyForNavigationResponse, - void Function(WKWebView webView, NSError error)? didFailNavigation, - void Function(WKWebView webView, NSError error)? - didFailProvisionalNavigation, - void Function(WKWebView webView)? webViewWebContentProcessDidTerminate, void Function( - WKWebView webView, - NSUrlAuthenticationChallenge challenge, - void Function( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ) completionHandler, + WKNavigationDelegate, + WKWebView, + NSError, + )? didFailNavigation, + void Function( + WKNavigationDelegate, + WKWebView, + NSError, + )? didFailProvisionalNavigation, + void Function( + WKNavigationDelegate, + WKWebView, + )? webViewWebContentProcessDidTerminate, + Future Function( + WKNavigationDelegate, + WKWebView, + URLAuthenticationChallenge, )? didReceiveAuthenticationChallenge, - }) createNavigationDelegate; + }) newWKNavigationDelegate; + + /// Constructs [NSObject]. + final NSObject Function( + {void Function( + NSObject, + String?, + NSObject?, + Map?, + )? observeValue}) newNSObject; + + /// Constructs [PlatformWebView]. + final PlatformWebView Function({ + required WKWebViewConfiguration initialConfiguration, + void Function( + NSObject, + String?, + NSObject?, + Map?, + )? observeValue, + }) newPlatformWebView; - /// Constructs a [WKUIDelegate]. + /// Constructs [WKUIDelegate]. final WKUIDelegate Function({ void Function( - WKWebView webView, - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, + WKUIDelegate, + WKWebView, + WKWebViewConfiguration, + WKNavigationAction, )? onCreateWebView, - Future Function( - WKUIDelegate instance, - WKWebView webView, - WKSecurityOrigin origin, - WKFrameInfo frame, - WKMediaCaptureType type, + Future Function( + WKUIDelegate, + WKWebView, + WKSecurityOrigin, + WKFrameInfo, + MediaCaptureType, )? requestMediaCapturePermission, Future Function( - String message, - WKFrameInfo frame, - )? runJavaScriptAlertDialog, + WKUIDelegate, + WKWebView, + String, + WKFrameInfo, + )? runJavaScriptAlertPanel, Future Function( - String message, - WKFrameInfo frame, - )? runJavaScriptConfirmDialog, - Future Function( - String prompt, - String defaultText, - WKFrameInfo frame, - )? runJavaScriptTextInputDialog, - InstanceManager? instanceManager, - }) createUIDelegate; - - /// Constructs a [UIScrollViewDelegate]. + WKUIDelegate, + WKWebView, + String, + WKFrameInfo, + )? runJavaScriptConfirmPanel, + Future Function( + WKUIDelegate, + WKWebView, + String, + String?, + WKFrameInfo, + )? runJavaScriptTextInputPanel, + }) newWKUIDelegate; + + /// Constructs [UIScrollViewDelegate]. final UIScrollViewDelegate Function({ void Function( - UIScrollView scrollView, - double x, - double y, + UIScrollViewDelegate, + UIScrollView, + double, + double, )? scrollViewDidScroll, - }) createUIScrollViewDelegate; + }) newUIScrollViewDelegate; + + /// Constructs [URLCredential]. + final URLCredential Function({ + required String user, + required String password, + required UrlCredentialPersistence persistence, + }) withUserURLCredential; + + /// Calls to [WKWebsiteDataStore.defaultDataStore]. + final WKWebsiteDataStore Function() defaultDataStoreWKWebsiteDataStore; + + static WKWebsiteDataStore _defaultDataStoreWKWebsiteDataStore() => + WKWebsiteDataStore.defaultDataStore; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart index ae254ef52fe3..c234d2389f4a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart @@ -4,19 +4,17 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; -import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path/path.dart' as path; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'common/instance_manager.dart'; +import 'common/platform_webview.dart'; import 'common/weak_reference_utils.dart'; -import 'foundation/foundation.dart'; -import 'ui_kit/ui_kit.dart'; -import 'web_kit/web_kit.dart'; +import 'common/web_kit.g.dart'; +import 'common/webkit_constants.dart'; import 'webkit_proxy.dart'; /// Media types that can require a user gesture to begin playing. @@ -29,12 +27,12 @@ enum PlaybackMediaTypes { /// A media type that contains video. video; - WKAudiovisualMediaType _toWKAudiovisualMediaType() { + AudiovisualMediaType _toWKAudiovisualMediaType() { switch (this) { case PlaybackMediaTypes.audio: - return WKAudiovisualMediaType.audio; + return AudiovisualMediaType.audio; case PlaybackMediaTypes.video: - return WKAudiovisualMediaType.video; + return AudiovisualMediaType.video; } } } @@ -52,23 +50,21 @@ class WebKitWebViewControllerCreationParams }, this.allowsInlineMediaPlayback = false, this.limitsNavigationsToAppBoundDomains = false, - @visibleForTesting InstanceManager? instanceManager, - }) : _instanceManager = instanceManager ?? NSObject.globalInstanceManager { - _configuration = webKitProxy.createWebViewConfiguration( - instanceManager: _instanceManager, - ); + @visibleForTesting PigeonInstanceManager? instanceManager, + }) : _instanceManager = instanceManager ?? PigeonInstanceManager.instance { + _configuration = webKitProxy.newWKWebViewConfiguration(); if (mediaTypesRequiringUserAction.isEmpty) { _configuration.setMediaTypesRequiringUserActionForPlayback( - {WKAudiovisualMediaType.none}, + AudiovisualMediaType.none, + ); + } else if (mediaTypesRequiringUserAction.length == 1) { + _configuration.setMediaTypesRequiringUserActionForPlayback( + mediaTypesRequiringUserAction.single._toWKAudiovisualMediaType(), ); } else { _configuration.setMediaTypesRequiringUserActionForPlayback( - mediaTypesRequiringUserAction - .map( - (PlaybackMediaTypes type) => type._toWKAudiovisualMediaType(), - ) - .toSet(), + AudiovisualMediaType.all, ); } _configuration.setAllowsInlineMediaPlayback(allowsInlineMediaPlayback); @@ -96,7 +92,7 @@ class WebKitWebViewControllerCreationParams }, bool allowsInlineMediaPlayback = false, bool limitsNavigationsToAppBoundDomains = false, - @visibleForTesting InstanceManager? instanceManager, + @visibleForTesting PigeonInstanceManager? instanceManager, }) : this( webKitProxy: webKitProxy, mediaTypesRequiringUserAction: mediaTypesRequiringUserAction, @@ -133,7 +129,7 @@ class WebKitWebViewControllerCreationParams // Maintains instances used to communicate with the native objects they // represent. - final InstanceManager _instanceManager; + final PigeonInstanceManager _instanceManager; } /// An implementation of [PlatformWebViewController] with the WebKit api. @@ -145,32 +141,31 @@ class WebKitWebViewController extends PlatformWebViewController { : WebKitWebViewControllerCreationParams .fromPlatformWebViewControllerCreationParams(params)) { _webView.addObserver( - _webView, - keyPath: 'estimatedProgress', - options: { - NSKeyValueObservingOptions.newValue, - }, + _webView.nativeWebView, + 'estimatedProgress', + [KeyValueObservingOptions.newValue], ); - _webView.addObserver( - _webView, - keyPath: 'URL', - options: { - NSKeyValueObservingOptions.newValue, - }, + _webView.nativeWebView, + 'URL', + [KeyValueObservingOptions.newValue], ); final WeakReference weakThis = WeakReference(this); - _uiDelegate = _webKitParams.webKitProxy.createUIDelegate( - instanceManager: _webKitParams._instanceManager, + _uiDelegate = _webKitParams.webKitProxy.newWKUIDelegate( onCreateWebView: ( + _, WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction navigationAction, ) { - if (!navigationAction.targetFrame.isMainFrame) { - webView.loadRequest(navigationAction.request); + final bool isForMainFrame = + navigationAction.targetFrame?.isMainFrame ?? false; + if (!isForMainFrame) { + PlatformWebView.fromNativeWebView(webView).load( + navigationAction.request, + ); } }, requestMediaCapturePermission: ( @@ -178,7 +173,7 @@ class WebKitWebViewController extends PlatformWebViewController { WKWebView webView, WKSecurityOrigin origin, WKFrameInfo frame, - WKMediaCaptureType type, + MediaCaptureType type, ) async { final void Function(PlatformWebViewPermissionRequest)? callback = weakThis.target?._onPermissionRequestCallback; @@ -186,31 +181,31 @@ class WebKitWebViewController extends PlatformWebViewController { if (callback == null) { // The default response for iOS is to prompt. See // https://developer.apple.com/documentation/webkit/wkuidelegate/3763087-webview?language=objc - return WKPermissionDecision.prompt; + return PermissionDecision.prompt; } else { late final Set types; switch (type) { - case WKMediaCaptureType.camera: + case MediaCaptureType.camera: types = { WebViewPermissionResourceType.camera }; - case WKMediaCaptureType.cameraAndMicrophone: + case MediaCaptureType.cameraAndMicrophone: types = { WebViewPermissionResourceType.camera, WebViewPermissionResourceType.microphone }; - case WKMediaCaptureType.microphone: + case MediaCaptureType.microphone: types = { WebViewPermissionResourceType.microphone }; - case WKMediaCaptureType.unknown: + case MediaCaptureType.unknown: // The default response for iOS is to prompt. See // https://developer.apple.com/documentation/webkit/wkuidelegate/3763087-webview?language=objc - return WKPermissionDecision.prompt; + return PermissionDecision.prompt; } - final Completer decisionCompleter = - Completer(); + final Completer decisionCompleter = + Completer(); callback( WebKitWebViewPermissionRequest._( @@ -222,39 +217,58 @@ class WebKitWebViewController extends PlatformWebViewController { return decisionCompleter.future; } }, - runJavaScriptAlertDialog: (String message, WKFrameInfo frame) async { + runJavaScriptAlertPanel: ( + _, + __, + String message, + WKFrameInfo frame, + ) async { final Future Function(JavaScriptAlertDialogRequest request)? callback = weakThis.target?._onJavaScriptAlertDialog; if (callback != null) { final JavaScriptAlertDialogRequest request = JavaScriptAlertDialogRequest( - message: message, url: frame.request.url); + message: message, + url: await frame.request.getUrl() ?? '', + ); await callback.call(request); return; } }, - runJavaScriptConfirmDialog: (String message, WKFrameInfo frame) async { + runJavaScriptConfirmPanel: ( + _, + __, + String message, + WKFrameInfo frame, + ) async { final Future Function(JavaScriptConfirmDialogRequest request)? callback = weakThis.target?._onJavaScriptConfirmDialog; if (callback != null) { final JavaScriptConfirmDialogRequest request = JavaScriptConfirmDialogRequest( - message: message, url: frame.request.url); + message: message, + url: await frame.request.getUrl() ?? '', + ); final bool result = await callback.call(request); return result; } return false; }, - runJavaScriptTextInputDialog: - (String prompt, String defaultText, WKFrameInfo frame) async { + runJavaScriptTextInputPanel: ( + _, + __, + String prompt, + String? defaultText, + WKFrameInfo frame, + ) async { final Future Function(JavaScriptTextInputDialogRequest request)? callback = weakThis.target?._onJavaScriptTextInputDialog; if (callback != null) { final JavaScriptTextInputDialogRequest request = JavaScriptTextInputDialogRequest( message: prompt, - url: frame.request.url, + url: await frame.request.getUrl() ?? '', defaultText: defaultText); final String result = await callback.call(request); return result; @@ -268,18 +282,20 @@ class WebKitWebViewController extends PlatformWebViewController { } /// The WebKit WebView being controlled. - late final WKWebView _webView = _webKitParams.webKitProxy.createWebView( - _webKitParams._configuration, + late final PlatformWebView _webView = + _webKitParams.webKitProxy.newPlatformWebView( + initialConfiguration: _webKitParams._configuration, observeValue: withWeakReferenceTo(this, ( WeakReference weakReference, ) { return ( - String keyPath, - NSObject object, - Map change, + _, + String? keyPath, + NSObject? object, + Map? change, ) async { final WebKitWebViewController? controller = weakReference.target; - if (controller == null) { + if (controller == null || change == null) { return; } @@ -289,20 +305,19 @@ class WebKitWebViewController extends PlatformWebViewController { controller._currentNavigationDelegate?._onProgress; if (progressCallback != null) { final double progress = - change[NSKeyValueChangeKey.newValue]! as double; + change[KeyValueChangeKey.newValue]! as double; progressCallback((progress * 100).round()); } case 'URL': final UrlChangeCallback? urlChangeCallback = controller._currentNavigationDelegate?._onUrlChange; if (urlChangeCallback != null) { - final NSUrl? url = change[NSKeyValueChangeKey.newValue] as NSUrl?; + final URL? url = change[KeyValueChangeKey.newValue] as URL?; urlChangeCallback(UrlChange(url: await url?.getAbsoluteString())); } } }; }), - instanceManager: _webKitParams._instanceManager, ); late final WKUIDelegate _uiDelegate; @@ -339,13 +354,13 @@ class WebKitWebViewController extends PlatformWebViewController { /// See Objective-C method /// `FLTWebViewFlutterPlugin:webViewForIdentifier:withPluginRegistry`. int get webViewIdentifier => - _webKitParams._instanceManager.getIdentifier(_webView)!; + _webKitParams._instanceManager.getIdentifier(_webView.nativeWebView)!; @override Future loadFile(String absoluteFilePath) { return _webView.loadFileUrl( absoluteFilePath, - readAccessUrl: path.dirname(absoluteFilePath), + path.dirname(absoluteFilePath), ); } @@ -357,7 +372,7 @@ class WebKitWebViewController extends PlatformWebViewController { @override Future loadHtmlString(String html, {String? baseUrl}) { - return _webView.loadHtmlString(html, baseUrl: baseUrl); + return _webView.loadHtmlString(html, baseUrl); } @override @@ -368,18 +383,18 @@ class WebKitWebViewController extends PlatformWebViewController { ); } - return _webView.loadRequest(NSUrlRequest( - url: params.uri.toString(), - allHttpHeaderFields: params.headers, - httpMethod: params.method.name, - httpBody: params.body, - )); + return _webView.load( + _webKitParams.webKitProxy.newURLRequest(url: params.uri.toString()) + ..setAllHttpHeaderFields(params.headers) + ..setHttpMethod(params.method.name) + ..setHttpBody(params.body), + ); } @override Future addJavaScriptChannel( JavaScriptChannelParams javaScriptChannelParams, - ) { + ) async { final String channelName = javaScriptChannelParams.name; if (_javaScriptChannelParams.containsKey(channelName)) { throw ArgumentError( @@ -398,16 +413,23 @@ class WebKitWebViewController extends PlatformWebViewController { final String wrapperSource = 'window.${webKitParams.name} = webkit.messageHandlers.${webKitParams.name};'; - final WKUserScript wrapperScript = WKUserScript( - wrapperSource, - WKUserScriptInjectionTime.atDocumentStart, - isMainFrameOnly: false, - ); - _webView.configuration.userContentController.addUserScript(wrapperScript); - return _webView.configuration.userContentController.addScriptMessageHandler( - webKitParams._messageHandler, - webKitParams.name, + final WKUserScript wrapperScript = + _webKitParams.webKitProxy.newWKUserScript( + source: wrapperSource, + injectionTime: UserScriptInjectionTime.atDocumentStart, + isForMainFrameOnly: false, ); + + final WKUserContentController contentController = + await _webView.configuration.getUserContentController(); + + await Future.wait(>[ + contentController.addUserScript(wrapperScript), + contentController.addScriptMessageHandler( + webKitParams._messageHandler, + webKitParams.name, + ), + ]); } @override @@ -438,22 +460,26 @@ class WebKitWebViewController extends PlatformWebViewController { Future reload() => _webView.reload(); @override - Future clearCache() { - return _webView.configuration.websiteDataStore.removeDataOfTypes( - { - WKWebsiteDataType.memoryCache, - WKWebsiteDataType.diskCache, - WKWebsiteDataType.offlineWebApplicationCache, - }, - DateTime.fromMillisecondsSinceEpoch(0), + Future clearCache() async { + final WKWebsiteDataStore dataStore = + await _webView.configuration.getWebsiteDataStore(); + await dataStore.removeDataOfTypes( + [ + WebsiteDataType.memoryCache, + WebsiteDataType.diskCache, + WebsiteDataType.offlineWebApplicationCache, + ], + 0, ); } @override - Future clearLocalStorage() { - return _webView.configuration.websiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.localStorage}, - DateTime.fromMillisecondsSinceEpoch(0), + Future clearLocalStorage() async { + final WKWebsiteDataStore dataStore = + await _webView.configuration.getWebsiteDataStore(); + await dataStore.removeDataOfTypes( + [WebsiteDataType.localStorage], + 0, ); } @@ -491,42 +517,21 @@ class WebKitWebViewController extends PlatformWebViewController { @override Future scrollTo(int x, int y) { - final WKWebView webView = _webView; - if (webView is WKWebViewIOS) { - return webView.scrollView.setContentOffset(Point( - x.toDouble(), - y.toDouble(), - )); - } else { - // TODO(stuartmorgan): Investigate doing this via JS instead. - throw UnimplementedError('scrollTo is not implemented on macOS'); - } + // TODO(stuartmorgan): Investigate doing this via on macOS with JS instead. + return _webView.scrollView.setContentOffset(x.toDouble(), y.toDouble()); } @override - Future scrollBy(int x, int y) { - final WKWebView webView = _webView; - if (webView is WKWebViewIOS) { - return webView.scrollView.scrollBy(Point( - x.toDouble(), - y.toDouble(), - )); - } else { - // TODO(stuartmorgan): Investigate doing this via JS instead. - throw UnimplementedError('scrollBy is not implemented on macOS'); - } + Future scrollBy(int x, int y) async { + // TODO(stuartmorgan): Investigate doing this via on macOS with JS instead. + return _webView.scrollView.scrollBy(x.toDouble(), y.toDouble()); } @override Future getScrollPosition() async { - final WKWebView webView = _webView; - if (webView is WKWebViewIOS) { - final Point offset = await webView.scrollView.getContentOffset(); - return Offset(offset.x, offset.y); - } else { - // TODO(stuartmorgan): Investigate doing this via JS instead. - throw UnimplementedError('scrollTo is not implemented on macOS'); - } + // TODO(stuartmorgan): Investigate doing this via on macOS with JS instead. + final List position = await _webView.scrollView.getContentOffset(); + return Offset(position[0], position[1]); } /// Whether horizontal swipe gestures trigger page navigation. @@ -536,28 +541,23 @@ class WebKitWebViewController extends PlatformWebViewController { @override Future setBackgroundColor(Color color) { - final WKWebView webView = _webView; - if (webView is WKWebViewIOS) { - return Future.wait(>[ - webView.setOpaque(false), - webView.setBackgroundColor(Colors.transparent), - // This method must be called last. - webView.scrollView.setBackgroundColor(color), - ]); - } else { - // TODO(stuartmorgan): Implement background color support. - throw UnimplementedError( - 'Background color is not yet supported on macOS.'); - } + return Future.wait(>[ + _webView.setOpaque(false), + _webView.setBackgroundColor(Colors.transparent.value), + // This method must be called last. + _webView.scrollView.setBackgroundColor(color.value), + ]); } @override - Future setJavaScriptMode(JavaScriptMode javaScriptMode) { + Future setJavaScriptMode(JavaScriptMode javaScriptMode) async { + final WKPreferences preferences = + await _webView.configuration.getPreferences(); switch (javaScriptMode) { case JavaScriptMode.disabled: - return _webView.configuration.preferences.setJavaScriptEnabled(false); + await preferences.setJavaScriptEnabled(false); case JavaScriptMode.unrestricted: - return _webView.configuration.preferences.setJavaScriptEnabled(true); + await preferences.setJavaScriptEnabled(true); } } @@ -588,18 +588,19 @@ class WebKitWebViewController extends PlatformWebViewController { return _webView.setNavigationDelegate(handler._navigationDelegate); } - Future _disableZoom() { - const WKUserScript userScript = WKUserScript( - "var meta = document.createElement('meta');\n" - "meta.name = 'viewport';\n" - "meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, " - "user-scalable=no';\n" - "var head = document.getElementsByTagName('head')[0];head.appendChild(meta);", - WKUserScriptInjectionTime.atDocumentEnd, - isMainFrameOnly: true, + Future _disableZoom() async { + final WKUserScript userScript = _webKitParams.webKitProxy.newWKUserScript( + source: "var meta = document.createElement('meta');\n" + "meta.name = 'viewport';\n" + "meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, " + "user-scalable=no';\n" + "var head = document.getElementsByTagName('head')[0];head.appendChild(meta);", + injectionTime: UserScriptInjectionTime.atDocumentEnd, + isForMainFrameOnly: true, ); - return _webView.configuration.userContentController - .addUserScript(userScript); + final WKUserContentController controller = + await _webView.configuration.getUserContentController(); + await controller.addUserScript(userScript); } /// Sets a callback that notifies the host application of any log messages @@ -654,7 +655,7 @@ class WebKitWebViewController extends PlatformWebViewController { return _injectConsoleOverride(); } - Future _injectConsoleOverride() { + Future _injectConsoleOverride() async { // Within overrideScript, a series of console output methods such as // console.log will be rewritten to pass the output content to the Flutter // end. @@ -669,8 +670,9 @@ class WebKitWebViewController extends PlatformWebViewController { // the cyclic object is not important, so remove it. // Therefore, the replacer parameter of JSON.stringify() is used and the // removeCyclicObject method is passed in to solve the error. - const WKUserScript overrideScript = WKUserScript( - ''' + final WKUserScript overrideScript = + _webKitParams.webKitProxy.newWKUserScript( + source: ''' var _flutter_webview_plugin_overrides = _flutter_webview_plugin_overrides || { removeCyclicObject: function() { const traversalStack = []; @@ -719,12 +721,13 @@ window.addEventListener("error", function(e) { log("error", e.message + " at " + e.filename + ":" + e.lineno + ":" + e.colno); }); ''', - WKUserScriptInjectionTime.atDocumentStart, - isMainFrameOnly: true, + injectionTime: UserScriptInjectionTime.atDocumentStart, + isForMainFrameOnly: true, ); - return _webView.configuration.userContentController - .addUserScript(overrideScript); + final WKUserContentController controller = + await _webView.configuration.getUserContentController(); + await controller.addUserScript(overrideScript); } // WKWebView does not support removing a single user script, so all user @@ -733,14 +736,14 @@ window.addEventListener("error", function(e) { // workaround could interfere with exposing support for custom scripts from // applications. Future _resetUserScripts({String? removedJavaScriptChannel}) async { - unawaited( - _webView.configuration.userContentController.removeAllUserScripts(), - ); + final WKUserContentController controller = + await _webView.configuration.getUserContentController(); + unawaited(controller.removeAllUserScripts()); // TODO(bparrishMines): This can be replaced with // `removeAllScriptMessageHandlers` once Dart supports runtime version // checking. (e.g. The equivalent to @availability in Objective-C.) _javaScriptChannelParams.keys.forEach( - _webView.configuration.userContentController.removeScriptMessageHandler, + controller.removeScriptMessageHandler, ); final Map remainingChannelParams = Map.from( @@ -772,26 +775,25 @@ window.addEventListener("error", function(e) { @override Future setOnScrollPositionChange( void Function(ScrollPositionChange scrollPositionChange)? - onScrollPositionChange) async { - final WKWebView webView = _webView; - if (webView is WKWebViewIOS) { + onScrollPositionChange) { + if (defaultTargetPlatform == TargetPlatform.iOS) { _onScrollPositionChangeCallback = onScrollPositionChange; if (onScrollPositionChange != null) { final WeakReference weakThis = WeakReference(this); _uiScrollViewDelegate = - _webKitParams.webKitProxy.createUIScrollViewDelegate( - scrollViewDidScroll: (UIScrollView uiScrollView, double x, double y) { + _webKitParams.webKitProxy.newUIScrollViewDelegate( + scrollViewDidScroll: (_, __, double x, double y) { weakThis.target?._onScrollPositionChangeCallback?.call( ScrollPositionChange(x, y), ); }, ); - return webView.scrollView.setDelegate(_uiScrollViewDelegate); + return _webView.scrollView.setDelegate(_uiScrollViewDelegate); } else { _uiScrollViewDelegate = null; - return webView.scrollView.setDelegate(null); + return _webView.scrollView.setDelegate(null); } } else { // TODO(stuartmorgan): Investigate doing this via JS instead. @@ -859,14 +861,11 @@ class WebKitJavaScriptChannelParams extends JavaScriptChannelParams { required super.onMessageReceived, @visibleForTesting WebKitProxy webKitProxy = const WebKitProxy(), }) : assert(name.isNotEmpty), - _messageHandler = webKitProxy.createScriptMessageHandler( + _messageHandler = webKitProxy.newWKScriptMessageHandler( didReceiveScriptMessage: withWeakReferenceTo( onMessageReceived, (WeakReference weakReference) { - return ( - WKUserContentController controller, - WKScriptMessage message, - ) { + return (_, __, WKScriptMessage message) { if (weakReference.target != null) { weakReference.target!( JavaScriptMessage(message: message.body!.toString()), @@ -901,14 +900,14 @@ class WebKitWebViewWidgetCreationParams required super.controller, super.layoutDirection, super.gestureRecognizers, - @visibleForTesting InstanceManager? instanceManager, - }) : _instanceManager = instanceManager ?? NSObject.globalInstanceManager; + @visibleForTesting PigeonInstanceManager? instanceManager, + }) : _instanceManager = instanceManager ?? PigeonInstanceManager.instance; /// Constructs a [WebKitWebViewWidgetCreationParams] using a /// [PlatformWebViewWidgetCreationParams]. WebKitWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams( PlatformWebViewWidgetCreationParams params, { - InstanceManager? instanceManager, + PigeonInstanceManager? instanceManager, }) : this( key: params.key, controller: params.controller, @@ -919,7 +918,7 @@ class WebKitWebViewWidgetCreationParams // Maintains instances used to communicate with the native objects they // represent. - final InstanceManager _instanceManager; + final PigeonInstanceManager _instanceManager; @override int get hashCode => Object.hash( @@ -958,7 +957,7 @@ class WebKitWebViewWidget extends PlatformWebViewWidget { final Key key = _webKitParams.key ?? ValueKey( params as WebKitWebViewWidgetCreationParams); - if (Platform.isMacOS) { + if (defaultTargetPlatform == TargetPlatform.macOS) { return AppKitView( key: key, viewType: 'plugins.flutter.io/webview', @@ -966,7 +965,8 @@ class WebKitWebViewWidget extends PlatformWebViewWidget { layoutDirection: params.layoutDirection, gestureRecognizers: params.gestureRecognizers, creationParams: _webKitParams._instanceManager.getIdentifier( - (params.controller as WebKitWebViewController)._webView), + (params.controller as WebKitWebViewController)._webView.nativeWebView, + ), creationParamsCodec: const StandardMessageCodec(), ); } else { @@ -977,7 +977,9 @@ class WebKitWebViewWidget extends PlatformWebViewWidget { layoutDirection: params.layoutDirection, gestureRecognizers: params.gestureRecognizers, creationParams: _webKitParams._instanceManager.getIdentifier( - (params.controller as WebKitWebViewController)._webView), + (params.controller as WebKitWebViewController) + ._webView + .nativeWebView), creationParamsCodec: const StandardMessageCodec(), ); } @@ -992,7 +994,10 @@ class WebKitWebResourceError extends WebResourceError { required super.url, }) : super( errorCode: _nsError.code, - description: _nsError.localizedDescription ?? '', + description: + _nsError.userInfo[NSErrorUserInfoKey.NSLocalizedDescription] + as String? ?? + '', errorType: _toWebResourceErrorType(_nsError.code), isForMainFrame: isForMainFrame, ); @@ -1057,53 +1062,56 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate { _navigationDelegate = (this.params as WebKitNavigationDelegateCreationParams) .webKitProxy - .createNavigationDelegate( - didFinishNavigation: (WKWebView webView, String? url) { + .newWKNavigationDelegate( + didFinishNavigation: (_, __, String? url) { if (weakThis.target?._onPageFinished != null) { weakThis.target!._onPageFinished!(url ?? ''); } }, - didStartProvisionalNavigation: (WKWebView webView, String? url) { + didStartProvisionalNavigation: (_, __, String? url) { if (weakThis.target?._onPageStarted != null) { weakThis.target!._onPageStarted!(url ?? ''); } }, decidePolicyForNavigationResponse: - (WKWebView webView, WKNavigationResponse response) async { + (_, __, WKNavigationResponse response) async { + final URLResponse urlResponse = response.response; if (weakThis.target?._onHttpError != null && - response.response.statusCode >= 400) { + urlResponse is HTTPURLResponse && + urlResponse.statusCode >= 400) { weakThis.target!._onHttpError!( HttpResponseError( response: WebResourceResponse( uri: null, - statusCode: response.response.statusCode, + statusCode: urlResponse.statusCode, ), ), ); } - return WKNavigationResponsePolicy.allow; + return NavigationResponsePolicy.allow; }, decidePolicyForNavigationAction: ( - WKWebView webView, + _, + __, WKNavigationAction action, ) async { if (weakThis.target?._onNavigationRequest != null) { final NavigationDecision decision = await weakThis.target!._onNavigationRequest!(NavigationRequest( - url: action.request.url, - isMainFrame: action.targetFrame.isMainFrame, + url: await action.request.getUrl() ?? '', + isMainFrame: action.targetFrame?.isMainFrame ?? false, )); switch (decision) { case NavigationDecision.prevent: - return WKNavigationActionPolicy.cancel; + return NavigationActionPolicy.cancel; case NavigationDecision.navigate: - return WKNavigationActionPolicy.allow; + return NavigationActionPolicy.allow; } } - return WKNavigationActionPolicy.allow; + return NavigationActionPolicy.allow; }, - didFailNavigation: (WKWebView webView, NSError error) { + didFailNavigation: (_, __, NSError error) { if (weakThis.target?._onWebResourceError != null) { weakThis.target!._onWebResourceError!( WebKitWebResourceError._( @@ -1115,7 +1123,7 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate { ); } }, - didFailProvisionalNavigation: (WKWebView webView, NSError error) { + didFailProvisionalNavigation: (_, __, NSError error) { if (weakThis.target?._onWebResourceError != null) { weakThis.target!._onWebResourceError!( WebKitWebResourceError._( @@ -1127,14 +1135,15 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate { ); } }, - webViewWebContentProcessDidTerminate: (WKWebView webView) { + webViewWebContentProcessDidTerminate: (_, __) { if (weakThis.target?._onWebResourceError != null) { weakThis.target!._onWebResourceError!( WebKitWebResourceError._( - const NSError( + NSError.pigeon_detached( code: WKErrorCode.webContentProcessTerminated, // Value from https://developer.apple.com/documentation/webkit/wkerrordomain?language=objc. domain: 'WKErrorDomain', + userInfo: const {}, ), isForMainFrame: true, url: null, @@ -1143,53 +1152,65 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate { } }, didReceiveAuthenticationChallenge: ( - WKWebView webView, - NSUrlAuthenticationChallenge challenge, - void Function( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ) completionHandler, - ) { - if (challenge.protectionSpace.authenticationMethod == + _, + __, + URLAuthenticationChallenge challenge, + ) async { + final URLProtectionSpace protectionSpace = + await challenge.getProtectionSpace(); + + final bool isBasicOrNtlm = protectionSpace.authenticationMethod == NSUrlAuthenticationMethod.httpBasic || - challenge.protectionSpace.authenticationMethod == - NSUrlAuthenticationMethod.httpNtlm) { - final void Function(HttpAuthRequest)? callback = - weakThis.target?._onHttpAuthRequest; - final String? host = challenge.protectionSpace.host; - final String? realm = challenge.protectionSpace.realm; - - if (callback != null && host != null) { - callback( - HttpAuthRequest( - onProceed: (WebViewCredential credential) { - completionHandler( - NSUrlSessionAuthChallengeDisposition.useCredential, - NSUrlCredential.withUser( - user: credential.user, - password: credential.password, - persistence: NSUrlCredentialPersistence.session, - ), - ); - }, - onCancel: () { - completionHandler( - NSUrlSessionAuthChallengeDisposition - .cancelAuthenticationChallenge, - null, - ); - }, - host: host, - realm: realm, - ), - ); - return; - } + protectionSpace.authenticationMethod == + NSUrlAuthenticationMethod.httpNtlm; + + final void Function(HttpAuthRequest)? callback = + weakThis.target?._onHttpAuthRequest; + + final WebKitProxy? proxy = + (weakThis.target?.params as WebKitNavigationDelegateCreationParams?) + ?.webKitProxy; + + if (isBasicOrNtlm && callback != null && proxy != null) { + final String host = protectionSpace.host; + final String? realm = protectionSpace.realm; + + final Completer responseCompleter = + Completer(); + + callback( + HttpAuthRequest( + host: host, + realm: realm, + onProceed: (WebViewCredential credential) { + final AuthenticationChallengeResponse response = + proxy.newAuthenticationChallengeResponse( + disposition: UrlSessionAuthChallengeDisposition.useCredential, + credential: URLCredential.withUser( + user: credential.user, + password: credential.password, + persistence: UrlCredentialPersistence.forSession, + ), + ); + responseCompleter.complete(response); + }, + onCancel: () { + final AuthenticationChallengeResponse response = + proxy.newAuthenticationChallengeResponse( + disposition: UrlSessionAuthChallengeDisposition + .cancelAuthenticationChallenge, + ); + responseCompleter.complete(response); + }, + ), + ); + + return responseCompleter.future; } - completionHandler( - NSUrlSessionAuthChallengeDisposition.performDefaultHandling, - null, + return AuthenticationChallengeResponse( + disposition: + UrlSessionAuthChallengeDisposition.performDefaultHandling, ); }, ); @@ -1258,23 +1279,23 @@ class WebKitNavigationDelegate extends PlatformNavigationDelegate { class WebKitWebViewPermissionRequest extends PlatformWebViewPermissionRequest { const WebKitWebViewPermissionRequest._({ required super.types, - required void Function(WKPermissionDecision decision) onDecision, + required void Function(PermissionDecision decision) onDecision, }) : _onDecision = onDecision; - final void Function(WKPermissionDecision) _onDecision; + final void Function(PermissionDecision) _onDecision; @override Future grant() async { - _onDecision(WKPermissionDecision.grant); + _onDecision(PermissionDecision.grant); } @override Future deny() async { - _onDecision(WKPermissionDecision.deny); + _onDecision(PermissionDecision.deny); } /// Prompt the user for permission for the requested resource. Future prompt() async { - _onDecision(WKPermissionDecision.prompt); + _onDecision(PermissionDecision.prompt); } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_cookie_manager.dart index 00e97011c559..1350eee52aee 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_cookie_manager.dart @@ -5,8 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'foundation/foundation.dart'; -import 'web_kit/web_kit.dart'; +import 'common/web_kit.g.dart'; import 'webkit_proxy.dart'; /// Object specifying creation parameters for a [WebKitWebViewCookieManager]. @@ -33,7 +32,7 @@ class WebKitWebViewCookieManagerCreationParams /// Manages stored data for [WKWebView]s. late final WKWebsiteDataStore _websiteDataStore = - webKitProxy.defaultWebsiteDataStore(); + webKitProxy.defaultDataStoreWKWebsiteDataStore(); } /// An implementation of [PlatformWebViewCookieManager] with the WebKit api. @@ -53,8 +52,8 @@ class WebKitWebViewCookieManager extends PlatformWebViewCookieManager { @override Future clearCookies() { return _webkitParams._websiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, - DateTime.fromMillisecondsSinceEpoch(0), + [WebsiteDataType.cookies], + 0.0, ); } @@ -67,12 +66,12 @@ class WebKitWebViewCookieManager extends PlatformWebViewCookieManager { } return _webkitParams._websiteDataStore.httpCookieStore.setCookie( - NSHttpCookie.withProperties( - { - NSHttpCookiePropertyKey.name: cookie.name, - NSHttpCookiePropertyKey.value: cookie.value, - NSHttpCookiePropertyKey.domain: cookie.domain, - NSHttpCookiePropertyKey.path: cookie.path, + _webkitParams.webKitProxy.newHTTPCookie( + properties: { + HttpCookiePropertyKey.name: cookie.name, + HttpCookiePropertyKey.value: cookie.value, + HttpCookiePropertyKey.domain: cookie.domain, + HttpCookiePropertyKey.path: cookie.path, }, ), ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart index a7d2fbd488d2..463cf97fcde6 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart @@ -2,1007 +2,1073 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: avoid_unused_constructor_parameters + import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/common/web_kit.g.dart', - dartTestOut: 'test/src/common/test_web_kit.g.dart', - objcHeaderOut: - 'darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h', - objcSourceOut: - 'darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FWFGeneratedWebKitApis.m', - objcOptions: ObjcOptions( - headerIncludePath: - './include/webview_flutter_wkwebview/FWFGeneratedWebKitApis.h', - prefix: 'FWF', - ), copyrightHeader: 'pigeons/copyright.txt', + swiftOut: + 'darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/WebKitLibrary.g.swift', ), ) -/// Mirror of NSKeyValueObservingOptions. +/// The values that can be returned in a change dictionary. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions?language=objc. -enum NSKeyValueObservingOptionsEnum { +/// See https://developer.apple.com/documentation/foundation/nskeyvalueobservingoptions. +enum KeyValueObservingOptions { + /// Indicates that the change dictionary should provide the new attribute + /// value, if applicable. newValue, + + /// Indicates that the change dictionary should contain the old attribute + /// value, if applicable. oldValue, + + /// If specified, a notification should be sent to the observer immediately, + /// before the observer registration method even returns. initialValue, - priorNotification, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class NSKeyValueObservingOptionsEnumData { - late NSKeyValueObservingOptionsEnum value; + /// Whether separate notifications should be sent to the observer before and + /// after each change, instead of a single notification after the change. + priorNotification, } -/// Mirror of NSKeyValueChange. +/// The kinds of changes that can be observed. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange?language=objc. -enum NSKeyValueChangeEnum { +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechange. +enum KeyValueChange { + /// Indicates that the value of the observed key path was set to a new value. setting, + + /// Indicates that an object has been inserted into the to-many relationship + /// that is being observed. insertion, + + /// Indicates that an object has been removed from the to-many relationship + /// that is being observed. removal, + + /// Indicates that an object has been replaced in the to-many relationship + /// that is being observed. replacement, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class NSKeyValueChangeEnumData { - late NSKeyValueChangeEnum value; + /// The value is not recognized by the wrapper. + unknown, } -/// Mirror of NSKeyValueChangeKey. +/// The keys that can appear in the change dictionary. /// -/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey?language=objc. -enum NSKeyValueChangeKeyEnum { +/// See https://developer.apple.com/documentation/foundation/nskeyvaluechangekey. +enum KeyValueChangeKey { + /// If the value of the `KeyValueChangeKey.kind` entry is + /// `KeyValueChange.insertion`, `KeyValueChange.removal`, or + /// `KeyValueChange.replacement`, the value of this key is a Set object that + /// contains the indexes of the inserted, removed, or replaced objects. indexes, + + /// An object that contains a value corresponding to one of the + /// `KeyValueChange` enum, indicating what sort of change has occurred. kind, + + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting, and `KeyValueObservingOptions.newValue` was + /// specified when the observer was registered, the value of this key is the + /// new value for the attribute. newValue, + + /// If the `KeyValueObservingOptions.priorNotification` option was specified + /// when the observer was registered this notification is sent prior to a + /// change. notificationIsPrior, + + /// If the value of the `KeyValueChange.kind` entry is + /// `KeyValueChange.setting`, and `KeyValueObservingOptions.old` was specified + /// when the observer was registered, the value of this key is the value + /// before the attribute was changed. oldValue, - unknown, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class NSKeyValueChangeKeyEnumData { - late NSKeyValueChangeKeyEnum value; + /// The value is not recognized by the wrapper. + unknown, } -/// Mirror of WKUserScriptInjectionTime. +/// Constants for the times at which to inject script content into a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc. -enum WKUserScriptInjectionTimeEnum { +/// See https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime. +enum UserScriptInjectionTime { + /// A constant to inject the script after the creation of the webpage’s + /// document element, but before loading any other content. atDocumentStart, + + /// A constant to inject the script after the document finishes loading, but + /// before loading any other subresources. atDocumentEnd, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKUserScriptInjectionTimeEnumData { - late WKUserScriptInjectionTimeEnum value; + /// The value is not recognized by the wrapper. + unknown, } -/// Mirror of WKAudiovisualMediaTypes. +/// The media types that require a user gesture to begin playing. /// -/// See [WKAudiovisualMediaTypes](https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes?language=objc). -enum WKAudiovisualMediaTypeEnum { +/// See https://developer.apple.com/documentation/webkit/wkaudiovisualmediatypes. +enum AudiovisualMediaType { + /// No media types require a user gesture to begin playing. none, + + /// Media types that contain audio require a user gesture to begin playing. audio, + + /// Media types that contain video require a user gesture to begin playing. video, - all, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKAudiovisualMediaTypeEnumData { - late WKAudiovisualMediaTypeEnum value; + /// All media types require a user gesture to begin playing. + all, } -/// Mirror of WKWebsiteDataTypes. +/// A `WKWebsiteDataRecord` object includes these constants in its dataTypes +/// property. /// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types?language=objc. -enum WKWebsiteDataTypeEnum { +/// See https://developer.apple.com/documentation/webkit/wkwebsitedatarecord/data_store_record_types. +enum WebsiteDataType { + /// Cookies. cookies, + + /// In-memory caches. memoryCache, + + /// On-disk caches. diskCache, + + /// HTML offline web app caches. offlineWebApplicationCache, + + /// HTML local storage. localStorage, + + /// HTML session storage. sessionStorage, + + /// WebSQL databases. webSQLDatabases, - indexedDBDatabases, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKWebsiteDataTypeEnumData { - late WKWebsiteDataTypeEnum value; + /// IndexedDB databases. + indexedDBDatabases, } -/// Mirror of WKNavigationActionPolicy. +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from an action. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -enum WKNavigationActionPolicyEnum { +/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy. +enum NavigationActionPolicy { + /// Allow the navigation to continue. allow, + + /// Cancel the navigation. cancel, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKNavigationActionPolicyEnumData { - late WKNavigationActionPolicyEnum value; + /// Allow the download to proceed. + download, } -/// Mirror of WKNavigationResponsePolicy. +/// Constants that indicate whether to allow or cancel navigation to a webpage +/// from a response. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationactionpolicy?language=objc. -enum WKNavigationResponsePolicyEnum { +/// See https://developer.apple.com/documentation/webkit/wknavigationresponsepolicy. +enum NavigationResponsePolicy { + /// Allow the navigation to continue. allow, + + /// Cancel the navigation. cancel, + + /// Allow the download to proceed. + download, } -/// Mirror of NSHTTPCookiePropertyKey. +/// Constants that define the supported keys in a cookie attributes dictionary. /// -/// See https://developer.apple.com/documentation/foundation/nshttpcookiepropertykey. -enum NSHttpCookiePropertyKeyEnum { +/// See https://developer.apple.com/documentation/foundation/httpcookiepropertykey. +enum HttpCookiePropertyKey { + /// A String object containing the comment for the cookie. comment, + + /// An Uri object or String object containing the comment URL for the cookie. commentUrl, + + /// Aa String object stating whether the cookie should be discarded at the end + /// of the session. discard, + + /// An String object containing the domain for the cookie. domain, + + /// An Date object or String object specifying the expiration date for the + /// cookie. expires, + + /// An String object containing an integer value stating how long in seconds + /// the cookie should be kept, at most. maximumAge, + + /// An String object containing the name of the cookie (required). name, + + /// A URL or String object containing the URL that set this cookie. originUrl, + + /// A String object containing the path for the cookie. path, + + /// An String object containing comma-separated integer values specifying the + /// ports for the cookie. port, + + /// A string indicating the same-site policy for the cookie. sameSitePolicy, + + /// A String object indicating that the cookie should be transmitted only over + /// secure channels. secure, + + /// A String object containing the value of the cookie. value, + + /// A String object that specifies the version of the cookie. version, -} -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class NSHttpCookiePropertyKeyEnumData { - late NSHttpCookiePropertyKeyEnum value; + /// The value is not recognized by the wrapper. + unknown, } -/// An object that contains information about an action that causes navigation -/// to occur. +/// The type of action that triggered the navigation. /// -/// Wraps [WKNavigationType](https://developer.apple.com/documentation/webkit/wknavigationaction?language=objc). -enum WKNavigationType { +/// See https://developer.apple.com/documentation/webkit/wknavigationtype. +enum NavigationType { /// A link activation. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypelinkactivated?language=objc. linkActivated, /// A request to submit a form. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformsubmitted?language=objc. - submitted, + formSubmitted, /// A request for the frame’s next or previous item. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypebackforward?language=objc. backForward, /// A request to reload the webpage. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypereload?language=objc. reload, /// A request to resubmit a form. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeformresubmitted?language=objc. formResubmitted, /// A navigation request that originates for some other reason. - /// - /// See https://developer.apple.com/documentation/webkit/wknavigationtype/wknavigationtypeother?language=objc. other, - /// An unknown navigation type. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. + /// The value is not recognized by the wrapper. unknown, } /// Possible permission decisions for device resource access. /// -/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc. -enum WKPermissionDecision { +/// See https://developer.apple.com/documentation/webkit/wkpermissiondecision. +enum PermissionDecision { /// Deny permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiondeny?language=objc. deny, /// Deny permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisiongrant?language=objc. grant, /// Prompt the user for permission for the requested resource. - /// - /// See https://developer.apple.com/documentation/webkit/wkpermissiondecision/wkpermissiondecisionprompt?language=objc. prompt, } -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKPermissionDecisionData { - late WKPermissionDecision value; -} - /// List of the types of media devices that can capture audio, video, or both. /// -/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype?language=objc. -enum WKMediaCaptureType { +/// See https://developer.apple.com/documentation/webkit/wkmediacapturetype. +enum MediaCaptureType { /// A media device that can capture video. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecamera?language=objc. camera, /// A media device or devices that can capture audio and video. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypecameraandmicrophone?language=objc. cameraAndMicrophone, /// A media device that can capture audio. - /// - /// See https://developer.apple.com/documentation/webkit/wkmediacapturetype/wkmediacapturetypemicrophone?language=objc. microphone, - /// An unknown media device. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. + /// The value is not recognized by the wrapper. unknown, } -// TODO(bparrishMines): Enums need be wrapped in a data class because they can't -// be used as primitive arguments. See https://github.com/flutter/flutter/issues/87307 -class WKMediaCaptureTypeData { - late WKMediaCaptureType value; -} - /// Responses to an authentication challenge. /// -/// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition?language=objc. -enum NSUrlSessionAuthChallengeDisposition { +/// See https://developer.apple.com/documentation/foundation/urlsession/authchallengedisposition. +enum UrlSessionAuthChallengeDisposition { /// Use the specified credential, which may be nil. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeusecredential?language=objc. useCredential, /// Use the default handling for the challenge as though this delegate method /// were not implemented. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengeperformdefaulthandling?language=objc. performDefaultHandling, /// Cancel the entire request. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengecancelauthenticationchallenge?language=objc. cancelAuthenticationChallenge, /// Reject this challenge, and call the authentication delegate method again /// with the next authentication protection space. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlsessionauthchallengedisposition/nsurlsessionauthchallengerejectprotectionspace?language=objc. rejectProtectionSpace, + + /// The value is not recognized by the wrapper. + unknown, } /// Specifies how long a credential will be kept. -enum NSUrlCredentialPersistence { +/// +/// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence. +enum UrlCredentialPersistence { /// The credential should not be stored. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencenone?language=objc. none, /// The credential should be stored only for this session. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistenceforsession?language=objc. - session, + forSession, /// The credential should be stored in the keychain. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencepermanent?language=objc. permanent, /// The credential should be stored permanently in the keychain, and in /// addition should be distributed to other devices based on the owning Apple /// ID. - /// - /// See https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence/nsurlcredentialpersistencesynchronizable?language=objc. synchronizable, } -/// Mirror of NSURLRequest. +/// A URL load request that is independent of protocol or URL scheme. /// -/// See https://developer.apple.com/documentation/foundation/nsurlrequest?language=objc. -class NSUrlRequestData { - late String url; - late String? httpMethod; - late Uint8List? httpBody; - late Map allHttpHeaderFields; +/// See https://developer.apple.com/documentation/foundation/urlrequest. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(name: 'URLRequestWrapper')) +abstract class URLRequest extends NSObject { + URLRequest(String url); + + /// The URL being requested. + String? getUrl(); + + /// The HTTP request method. + void setHttpMethod(String? method); + + /// The HTTP request method. + String? getHttpMethod(); + + /// The request body. + void setHttpBody(Uint8List? body); + + /// The request body. + Uint8List? getHttpBody(); + + /// A dictionary containing all of the HTTP header fields for a request. + void setAllHttpHeaderFields(Map? fields); + + /// A dictionary containing all of the HTTP header fields for a request. + Map? getAllHttpHeaderFields(); } -/// Mirror of NSURLResponse. +/// The metadata associated with the response to an HTTP protocol URL load +/// request. /// -/// See https://developer.apple.com/documentation/foundation/nshttpurlresponse?language=objc. -class NSHttpUrlResponseData { +/// See https://developer.apple.com/documentation/foundation/httpurlresponse. +@ProxyApi() +abstract class HTTPURLResponse extends URLResponse { + /// The response’s HTTP status code. late int statusCode; } -/// Mirror of WKUserScript. +/// The metadata associated with the response to a URL load request, independent +/// of protocol and URL scheme. +/// +/// See https://developer.apple.com/documentation/foundation/urlresponse. +@ProxyApi() +abstract class URLResponse extends NSObject {} + +/// A script that the web view injects into a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkuserscript?language=objc. -class WKUserScriptData { +/// See https://developer.apple.com/documentation/webkit/wkuserscript. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKUserScript extends NSObject { + /// Creates a user script object that contains the specified source code and + /// attributes. + WKUserScript(); + + /// The script’s source code. late String source; - late WKUserScriptInjectionTimeEnumData? injectionTime; - late bool isMainFrameOnly; + + /// The time at which to inject the script into the webpage. + late UserScriptInjectionTime injectionTime; + + /// A Boolean value that indicates whether to inject the script into the main + /// frame or all frames. + late bool isForMainFrameOnly; } -/// Mirror of WKNavigationAction. +/// An object that contains information about an action that causes navigation +/// to occur. /// /// See https://developer.apple.com/documentation/webkit/wknavigationaction. -class WKNavigationActionData { - late NSUrlRequestData request; - late WKFrameInfoData targetFrame; - late WKNavigationType navigationType; +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKNavigationAction extends NSObject { + /// The URL request object associated with the navigation action. + late URLRequest request; + + /// The frame in which to display the new content. + /// + /// If the target of the navigation is a new window, this property is nil. + late WKFrameInfo? targetFrame; + + /// The type of action that triggered the navigation. + late NavigationType navigationType; } -/// Mirror of WKNavigationResponse. +/// An object that contains the response to a navigation request, and which you +/// use to make navigation-related policy decisions. /// /// See https://developer.apple.com/documentation/webkit/wknavigationresponse. -class WKNavigationResponseData { - late NSHttpUrlResponseData response; - late bool forMainFrame; +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKNavigationResponse extends NSObject { + /// The frame’s response. + late URLResponse response; + + /// A Boolean value that indicates whether the response targets the web view’s + /// main frame. + late bool isForMainFrame; } -/// Mirror of WKFrameInfo. +/// An object that contains information about a frame on a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkframeinfo?language=objc. -class WKFrameInfoData { +/// See https://developer.apple.com/documentation/webkit/wkframeinfo. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKFrameInfo extends NSObject { + /// A Boolean value indicating whether the frame is the web site's main frame + /// or a subframe. late bool isMainFrame; - late NSUrlRequestData request; + + /// The frame’s current request. + late URLRequest request; } -/// Mirror of NSError. +/// Information about an error condition including a domain, a domain-specific +/// error code, and application-specific information. /// -/// See https://developer.apple.com/documentation/foundation/nserror?language=objc. -class NSErrorData { +/// See https://developer.apple.com/documentation/foundation/nserror. +@ProxyApi() +abstract class NSError extends NSObject { + /// The error code. late int code; + + /// A string containing the error domain. late String domain; - late Map? userInfo; + + /// The user info dictionary. + late Map userInfo; } -/// Mirror of WKScriptMessage. +/// An object that encapsulates a message sent by JavaScript code from a +/// webpage. /// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessage?language=objc. -class WKScriptMessageData { +/// See https://developer.apple.com/documentation/webkit/wkscriptmessage. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKScriptMessage extends NSObject { + /// The name of the message handler to which the message is sent. late String name; + + /// The body of the message. late Object? body; } -/// Mirror of WKSecurityOrigin. +/// An object that identifies the origin of a particular resource. /// -/// See https://developer.apple.com/documentation/webkit/wksecurityorigin?language=objc. -class WKSecurityOriginData { +/// See https://developer.apple.com/documentation/webkit/wksecurityorigin. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKSecurityOrigin extends NSObject { + /// The security origin’s host. late String host; + + /// The security origin's port. late int port; - late String protocol; -} -/// Mirror of NSHttpCookieData. -/// -/// See https://developer.apple.com/documentation/foundation/nshttpcookie?language=objc. -class NSHttpCookieData { - // TODO(bparrishMines): Change to a map when Objective-C data classes conform - // to `NSCopying`. See https://github.com/flutter/flutter/issues/103383. - // `NSDictionary`s are unable to use data classes as keys because they don't - // conform to `NSCopying`. This splits the map of properties into a list of - // keys and values with the ordered maintained. - late List propertyKeys; - late List propertyValues; + /// The security origin's protocol. + late String securityProtocol; } -/// An object that can represent either a value supported by -/// `StandardMessageCodec`, a data class in this pigeon file, or an identifier -/// of an object stored in an `InstanceManager`. -class ObjectOrIdentifier { - late Object? value; +/// A representation of an HTTP cookie. +/// +/// See https://developer.apple.com/documentation/foundation/httpcookie. +@ProxyApi() +abstract class HTTPCookie extends NSObject { + HTTPCookie(Map properties); - /// Whether value is an int that is used to retrieve an instance stored in an - /// `InstanceManager`. - late bool isIdentifier; + /// The cookie’s properties. + Map? getProperties(); } -class AuthenticationChallengeResponse { - late NSUrlSessionAuthChallengeDisposition disposition; - late int? credentialIdentifier; +/// Response object used to return multiple values to an auth challenge received +/// by a `WKNavigationDelegate` auth challenge. +/// +/// The `webView(_:didReceive:completionHandler:)` method in +/// `WKNavigationDelegate` responds with a completion handler that takes two +/// values. The wrapper returns this class instead to handle this scenario. +@ProxyApi() +abstract class AuthenticationChallengeResponse { + AuthenticationChallengeResponse(); + + /// The option to use to handle the challenge. + late UrlSessionAuthChallengeDisposition disposition; + + /// The credential to use for authentication when the disposition parameter + /// contains the value URLSession.AuthChallengeDisposition.useCredential. + late URLCredential? credential; } -/// Mirror of WKWebsiteDataStore. +/// An object that manages cookies, disk and memory caches, and other types of +/// data for a web view. /// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore?language=objc. -@HostApi(dartHostTestHandler: 'TestWKWebsiteDataStoreHostApi') -abstract class WKWebsiteDataStoreHostApi { - @ObjCSelector( - 'createFromWebViewConfigurationWithIdentifier:configurationIdentifier:', - ) - void createFromWebViewConfiguration( - int identifier, - int configurationIdentifier, - ); - - @ObjCSelector('createDefaultDataStoreWithIdentifier:') - void createDefaultDataStore(int identifier); - - @ObjCSelector( - 'removeDataFromDataStoreWithIdentifier:ofTypes:modifiedSince:', - ) +/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKWebsiteDataStore extends NSObject { + /// The default data store, which stores data persistently to disk. + @static + late WKWebsiteDataStore defaultDataStore; + + /// The object that manages the HTTP cookies for your website. + @attached + late WKHTTPCookieStore httpCookieStore; + + /// Removes the specified types of website data from one or more data records. @async bool removeDataOfTypes( - int identifier, - List dataTypes, + List dataTypes, double modificationTimeInSecondsSinceEpoch, ); } -/// Mirror of UIView. +/// An object that manages the content for a rectangular area on the screen. /// -/// See https://developer.apple.com/documentation/uikit/uiview?language=objc. -@HostApi(dartHostTestHandler: 'TestUIViewHostApi') -abstract class UIViewHostApi { - @ObjCSelector('setBackgroundColorForViewWithIdentifier:toValue:') - void setBackgroundColor(int identifier, int? value); +/// See https://developer.apple.com/documentation/uikit/uiview. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions(import: 'UIKit', supportsMacos: false), +) +abstract class UIView extends NSObject { + /// The view’s background color. + void setBackgroundColor(int? value); - @ObjCSelector('setOpaqueForViewWithIdentifier:isOpaque:') - void setOpaque(int identifier, bool opaque); + /// A Boolean value that determines whether the view is opaque. + void setOpaque(bool opaque); } -/// Mirror of UIScrollView. +/// A view that allows the scrolling and zooming of its contained views. /// -/// See https://developer.apple.com/documentation/uikit/uiscrollview?language=objc. -@HostApi(dartHostTestHandler: 'TestUIScrollViewHostApi') -abstract class UIScrollViewHostApi { - @ObjCSelector('createFromWebViewWithIdentifier:webViewIdentifier:') - void createFromWebView(int identifier, int webViewIdentifier); - - @ObjCSelector('contentOffsetForScrollViewWithIdentifier:') - List getContentOffset(int identifier); +/// See https://developer.apple.com/documentation/uikit/uiscrollview. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions(import: 'UIKit', supportsMacos: false), +) +abstract class UIScrollView extends UIView { + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + List getContentOffset(); - @ObjCSelector('scrollByForScrollViewWithIdentifier:x:y:') - void scrollBy(int identifier, double x, double y); + /// Move the scrolled position of your view. + /// + /// Convenience method to synchronize change to the x and y scroll position. + void scrollBy(double x, double y); - @ObjCSelector('setContentOffsetForScrollViewWithIdentifier:toX:y:') - void setContentOffset(int identifier, double x, double y); + /// The point at which the origin of the content view is offset from the + /// origin of the scroll view. + void setContentOffset(double x, double y); - @ObjCSelector( - 'setDelegateForScrollViewWithIdentifier:uiScrollViewDelegateIdentifier:') - void setDelegate(int identifier, int? uiScrollViewDelegateIdentifier); + /// The delegate of the scroll view. + void setDelegate(UIScrollViewDelegate? delegate); } -/// Mirror of WKWebViewConfiguration. +/// A collection of properties that you use to initialize a web view.. /// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -@HostApi(dartHostTestHandler: 'TestWKWebViewConfigurationHostApi') -abstract class WKWebViewConfigurationHostApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); +/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKWebViewConfiguration extends NSObject { + WKWebViewConfiguration(); - @ObjCSelector('createFromWebViewWithIdentifier:webViewIdentifier:') - void createFromWebView(int identifier, int webViewIdentifier); + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + void setUserContentController(WKUserContentController controller); - @ObjCSelector( - 'setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:isAllowed:', - ) - void setAllowsInlineMediaPlayback(int identifier, bool allow); + /// The object that coordinates interactions between your app’s native code + /// and the webpage’s scripts and other content. + WKUserContentController getUserContentController(); - @ObjCSelector( - 'setLimitsNavigationsToAppBoundDomainsForConfigurationWithIdentifier:isLimited:', - ) - void setLimitsNavigationsToAppBoundDomains(int identifier, bool limit); + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + void setWebsiteDataStore(WKWebsiteDataStore dataStore); - @ObjCSelector( - 'setMediaTypesRequiresUserActionForConfigurationWithIdentifier:forTypes:', - ) - void setMediaTypesRequiringUserActionForPlayback( - int identifier, - List types, - ); -} + /// The object you use to get and set the site’s cookies and to track the + /// cached data objects. + WKWebsiteDataStore getWebsiteDataStore(); -/// Handles callbacks from a WKWebViewConfiguration instance. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -@FlutterApi() -abstract class WKWebViewConfigurationFlutterApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); -} + /// The object that manages the preference-related settings for the web view. + void setPreferences(WKPreferences preferences); -/// Mirror of WKUserContentController. -/// -/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc. -@HostApi(dartHostTestHandler: 'TestWKUserContentControllerHostApi') -abstract class WKUserContentControllerHostApi { - @ObjCSelector( - 'createFromWebViewConfigurationWithIdentifier:configurationIdentifier:', - ) - void createFromWebViewConfiguration( - int identifier, - int configurationIdentifier, - ); + /// The object that manages the preference-related settings for the web view. + WKPreferences getPreferences(); - @ObjCSelector( - 'addScriptMessageHandlerForControllerWithIdentifier:handlerIdentifier:ofName:', - ) - void addScriptMessageHandler( - int identifier, - int handlerIdentifier, - String name, - ); + /// A Boolean value that indicates whether HTML5 videos play inline or use the + /// native full-screen controller. + void setAllowsInlineMediaPlayback(bool allow); - @ObjCSelector('removeScriptMessageHandlerForControllerWithIdentifier:name:') - void removeScriptMessageHandler(int identifier, String name); + /// A Boolean value that indicates whether the web view limits navigation to + /// pages within the app’s domain. + void setLimitsNavigationsToAppBoundDomains(bool limit); - @ObjCSelector('removeAllScriptMessageHandlersForControllerWithIdentifier:') - void removeAllScriptMessageHandlers(int identifier); - - @ObjCSelector('addUserScriptForControllerWithIdentifier:userScript:') - void addUserScript(int identifier, WKUserScriptData userScript); - - @ObjCSelector('removeAllUserScriptsForControllerWithIdentifier:') - void removeAllUserScripts(int identifier); + /// The media types that require a user gesture to begin playing. + void setMediaTypesRequiringUserActionForPlayback(AudiovisualMediaType type); } -/// Mirror of WKUserPreferences. +/// An object for managing interactions between JavaScript code and your web +/// view, and for filtering content in your web view. /// -/// See https://developer.apple.com/documentation/webkit/wkpreferences?language=objc. -@HostApi(dartHostTestHandler: 'TestWKPreferencesHostApi') -abstract class WKPreferencesHostApi { - @ObjCSelector( - 'createFromWebViewConfigurationWithIdentifier:configurationIdentifier:', - ) - void createFromWebViewConfiguration( - int identifier, - int configurationIdentifier, - ); +/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKUserContentController extends NSObject { + /// Installs a message handler that you can call from your JavaScript code. + void addScriptMessageHandler(WKScriptMessageHandler handler, String name); - @ObjCSelector('setJavaScriptEnabledForPreferencesWithIdentifier:isEnabled:') - void setJavaScriptEnabled(int identifier, bool enabled); -} + /// Uninstalls the custom message handler with the specified name from your + /// JavaScript code. + void removeScriptMessageHandler(String name); -/// Mirror of WKScriptMessageHandler. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -@HostApi(dartHostTestHandler: 'TestWKScriptMessageHandlerHostApi') -abstract class WKScriptMessageHandlerHostApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); + /// Uninstalls all custom message handlers associated with the user content + /// controller. + void removeAllScriptMessageHandlers(); + + /// Injects the specified script into the webpage’s content. + void addUserScript(WKUserScript userScript); + + /// Removes all user scripts from the web view. + void removeAllUserScripts(); } -/// Handles callbacks from a WKScriptMessageHandler instance. +/// An object that encapsulates the standard behaviors to apply to websites. /// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -@FlutterApi() -abstract class WKScriptMessageHandlerFlutterApi { - @ObjCSelector( - 'didReceiveScriptMessageForHandlerWithIdentifier:userContentControllerIdentifier:message:', - ) - void didReceiveScriptMessage( - int identifier, - int userContentControllerIdentifier, - WKScriptMessageData message, - ); +/// See https://developer.apple.com/documentation/webkit/wkpreferences. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKPreferences extends NSObject { + /// A Boolean value that indicates whether JavaScript is enabled. + void setJavaScriptEnabled(bool enabled); } -/// Mirror of WKNavigationDelegate. +/// An interface for receiving messages from JavaScript code running in a webpage. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -@HostApi(dartHostTestHandler: 'TestWKNavigationDelegateHostApi') -abstract class WKNavigationDelegateHostApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); +/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKScriptMessageHandler extends NSObject { + WKScriptMessageHandler(); + + /// Tells the handler that a webpage sent a script message. + late void Function( + WKUserContentController controller, + WKScriptMessage message, + ) didReceiveScriptMessage; } -/// Handles callbacks from a WKNavigationDelegate instance. +/// Methods for accepting or rejecting navigation changes, and for tracking the +/// progress of navigation requests. /// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -@FlutterApi() -abstract class WKNavigationDelegateFlutterApi { - @ObjCSelector( - 'didFinishNavigationForDelegateWithIdentifier:webViewIdentifier:URL:', - ) - void didFinishNavigation( - int identifier, - int webViewIdentifier, - String? url, - ); +/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKNavigationDelegate extends NSObject { + WKNavigationDelegate(); - @ObjCSelector( - 'didStartProvisionalNavigationForDelegateWithIdentifier:webViewIdentifier:URL:', - ) - void didStartProvisionalNavigation( - int identifier, - int webViewIdentifier, + /// Tells the delegate that navigation is complete. + late void Function(WKWebView webView, String? url)? didFinishNavigation; + + /// Tells the delegate that navigation from the main frame has started. + late void Function( + WKWebView webView, String? url, - ); + )? didStartProvisionalNavigation; - @ObjCSelector( - 'decidePolicyForNavigationActionForDelegateWithIdentifier:webViewIdentifier:navigationAction:', - ) + /// Asks the delegate for permission to navigate to new content based on the + /// specified action information. @async - WKNavigationActionPolicyEnumData decidePolicyForNavigationAction( - int identifier, - int webViewIdentifier, - WKNavigationActionData navigationAction, - ); + NavigationActionPolicy Function( + WKWebView webView, + WKNavigationAction navigationAction, + )? decidePolicyForNavigationAction; - @ObjCSelector( - 'decidePolicyForNavigationResponseForDelegateWithIdentifier:webViewIdentifier:navigationResponse:', - ) + /// Asks the delegate for permission to navigate to new content after the + /// response to the navigation request is known. @async - WKNavigationResponsePolicyEnum decidePolicyForNavigationResponse( - int identifier, - int webViewIdentifier, - WKNavigationResponseData navigationResponse, - ); + NavigationResponsePolicy Function( + WKWebView webView, + WKNavigationResponse navigationResponse, + )? decidePolicyForNavigationResponse; - @ObjCSelector( - 'didFailNavigationForDelegateWithIdentifier:webViewIdentifier:error:', - ) - void didFailNavigation( - int identifier, - int webViewIdentifier, - NSErrorData error, - ); + /// Tells the delegate that an error occurred during navigation. + void Function(WKWebView webView, NSError error)? didFailNavigation; - @ObjCSelector( - 'didFailProvisionalNavigationForDelegateWithIdentifier:webViewIdentifier:error:', - ) - void didFailProvisionalNavigation( - int identifier, - int webViewIdentifier, - NSErrorData error, - ); + /// Tells the delegate that an error occurred during the early navigation + /// process. + void Function(WKWebView webView, NSError error)? didFailProvisionalNavigation; - @ObjCSelector( - 'webViewWebContentProcessDidTerminateForDelegateWithIdentifier:webViewIdentifier:', - ) - void webViewWebContentProcessDidTerminate( - int identifier, - int webViewIdentifier, - ); + /// Tells the delegate that the web view’s content process was terminated. + void Function(WKWebView webView)? webViewWebContentProcessDidTerminate; + /// Asks the delegate to respond to an authentication challenge. @async - @ObjCSelector( - 'didReceiveAuthenticationChallengeForDelegateWithIdentifier:webViewIdentifier:challengeIdentifier:', - ) - AuthenticationChallengeResponse didReceiveAuthenticationChallenge( - int identifier, - int webViewIdentifier, - int challengeIdentifier, - ); + AuthenticationChallengeResponse Function( + WKWebView webView, + URLAuthenticationChallenge challenge, + )? didReceiveAuthenticationChallenge; } -/// Mirror of NSObject. +/// The root class of most Objective-C class hierarchies, from which subclasses +/// inherit a basic interface to the runtime system and the ability to behave as +/// Objective-C objects. /// /// See https://developer.apple.com/documentation/objectivec/nsobject. -@HostApi(dartHostTestHandler: 'TestNSObjectHostApi') -abstract class NSObjectHostApi { - @ObjCSelector('disposeObjectWithIdentifier:') - void dispose(int identifier); - - @ObjCSelector( - 'addObserverForObjectWithIdentifier:observerIdentifier:keyPath:options:', - ) +@ProxyApi() +abstract class NSObject { + NSObject(); + + /// Informs the observing object when the value at the specified key path + /// relative to the observed object has changed. + late void Function( + String? keyPath, + NSObject? object, + Map? change, + )? observeValue; + + /// Registers the observer object to receive KVO notifications for the key + /// path relative to the object receiving this message. void addObserver( - int identifier, - int observerIdentifier, + NSObject observer, String keyPath, - List options, + List options, ); - @ObjCSelector( - 'removeObserverForObjectWithIdentifier:observerIdentifier:keyPath:', - ) - void removeObserver(int identifier, int observerIdentifier, String keyPath); + /// Stops the observer object from receiving change notifications for the + /// property specified by the key path relative to the object receiving this + /// message. + void removeObserver(NSObject observer, String keyPath); } -/// Handles callbacks from an NSObject instance. +/// An object that displays interactive web content, such as for an in-app +/// browser. /// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -@FlutterApi() -abstract class NSObjectFlutterApi { - @ObjCSelector( - 'observeValueForObjectWithIdentifier:keyPath:objectIdentifier:changeKeys:changeValues:', - ) - void observeValue( - int identifier, - String keyPath, - int objectIdentifier, - // TODO(bparrishMines): Change to a map when Objective-C data classes conform - // to `NSCopying`. See https://github.com/flutter/flutter/issues/103383. - // `NSDictionary`s are unable to use data classes as keys because they don't - // conform to `NSCopying`. This splits the map of properties into a list of - // keys and values with the ordered maintained. - List changeKeys, - List changeValues, - ); +/// See https://developer.apple.com/documentation/webkit/wkwebview. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions( + import: 'WebKit', + name: 'WKWebView', + supportsMacos: false, + ), +) +abstract class UIViewWKWebView extends UIView implements WKWebView { + UIViewWKWebView(WKWebViewConfiguration initialConfiguration); - @ObjCSelector('disposeObjectWithIdentifier:') - void dispose(int identifier); -} + /// The object that contains the configuration details for the web view. + @attached + late WKWebViewConfiguration configuration; -/// Mirror of WKWebView. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebview?language=objc. -@HostApi(dartHostTestHandler: 'TestWKWebViewHostApi') -abstract class WKWebViewHostApi { - @ObjCSelector('createWithIdentifier:configurationIdentifier:') - void create(int identifier, int configurationIdentifier); + /// The scroll view associated with the web view. + @attached + late UIScrollView scrollView; - @ObjCSelector('setUIDelegateForWebViewWithIdentifier:delegateIdentifier:') - void setUIDelegate(int identifier, int? uiDelegateIdentifier); + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + void setUIDelegate(WKUIDelegate delegate); - @ObjCSelector( - 'setNavigationDelegateForWebViewWithIdentifier:delegateIdentifier:', - ) - void setNavigationDelegate(int identifier, int? navigationDelegateIdentifier); + /// The object you use to manage navigation behavior for the web view. + void setNavigationDelegate(WKNavigationDelegate delegate); - @ObjCSelector('URLForWebViewWithIdentifier:') - String? getUrl(int identifier); + /// The URL for the current webpage. + String? getUrl(); - @ObjCSelector('estimatedProgressForWebViewWithIdentifier:') - double getEstimatedProgress(int identifier); + /// An estimate of what fraction of the current navigation has been loaded. + double getEstimatedProgress(); - @ObjCSelector('loadRequestForWebViewWithIdentifier:request:') - void loadRequest(int identifier, NSUrlRequestData request); + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + void load(URLRequest request); - @ObjCSelector('loadHTMLForWebViewWithIdentifier:HTMLString:baseURL:') - void loadHtmlString(int identifier, String string, String? baseUrl); + /// Loads the contents of the specified HTML string and navigates to it. + void loadHtmlString(String string, String? baseUrl); - @ObjCSelector('loadFileForWebViewWithIdentifier:fileURL:readAccessURL:') - void loadFileUrl(int identifier, String url, String readAccessUrl); + /// Loads the web content from the specified file and navigates to it. + void loadFileUrl(String url, String readAccessUrl); - @ObjCSelector('loadAssetForWebViewWithIdentifier:assetKey:') - void loadFlutterAsset(int identifier, String key); + /// Convenience method to load a Flutter asset. + void loadFlutterAsset(String key); - @ObjCSelector('canGoBackForWebViewWithIdentifier:') - bool canGoBack(int identifier); + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + bool canGoBack(); - @ObjCSelector('canGoForwardForWebViewWithIdentifier:') - bool canGoForward(int identifier); + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + bool canGoForward(); - @ObjCSelector('goBackForWebViewWithIdentifier:') - void goBack(int identifier); + /// Navigates to the back item in the back-forward list. + void goBack(); - @ObjCSelector('goForwardForWebViewWithIdentifier:') - void goForward(int identifier); + /// Navigates to the forward item in the back-forward list. + void goForward(); - @ObjCSelector('reloadWebViewWithIdentifier:') - void reload(int identifier); + /// Reloads the current webpage. + void reload(); - @ObjCSelector('titleForWebViewWithIdentifier:') - String? getTitle(int identifier); + /// The page title. + String? getTitle(); - @ObjCSelector('setAllowsBackForwardForWebViewWithIdentifier:isAllowed:') - void setAllowsBackForwardNavigationGestures(int identifier, bool allow); + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + void setAllowsBackForwardNavigationGestures(bool allow); - @ObjCSelector('setCustomUserAgentForWebViewWithIdentifier:userAgent:') - void setCustomUserAgent(int identifier, String? userAgent); + /// The custom user agent string. + void setCustomUserAgent(String? userAgent); - @ObjCSelector('evaluateJavaScriptForWebViewWithIdentifier:javaScriptString:') + /// Evaluates the specified JavaScript string. @async - Object? evaluateJavaScript(int identifier, String javaScriptString); + Object? evaluateJavaScript(String javaScriptString); - @ObjCSelector('setInspectableForWebViewWithIdentifier:inspectable:') - void setInspectable(int identifier, bool inspectable); + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + void setInspectable(bool inspectable); - @ObjCSelector('customUserAgentForWebViewWithIdentifier:') - String? getCustomUserAgent(int identifier); + /// The custom user agent string. + String? getCustomUserAgent(); } -/// Mirror of WKUIDelegate. +/// An object that displays interactive web content, such as for an in-app +/// browser. /// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -@HostApi(dartHostTestHandler: 'TestWKUIDelegateHostApi') -abstract class WKUIDelegateHostApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); +/// See https://developer.apple.com/documentation/webkit/wkwebview. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions( + import: 'WebKit', + name: 'WKWebView', + supportsIos: false, + ), +) +abstract class NSViewWKWebView extends NSObject implements WKWebView { + NSViewWKWebView(WKWebViewConfiguration initialConfiguration); + + /// The object that contains the configuration details for the web view. + @attached + late WKWebViewConfiguration configuration; + + /// The object you use to integrate custom user interface elements, such as + /// contextual menus or panels, into web view interactions. + void setUIDelegate(WKUIDelegate delegate); + + /// The object you use to manage navigation behavior for the web view. + void setNavigationDelegate(WKNavigationDelegate delegate); + + /// The URL for the current webpage. + String? getUrl(); + + /// An estimate of what fraction of the current navigation has been loaded. + double getEstimatedProgress(); + + /// Loads the web content that the specified URL request object references and + /// navigates to that content. + void load(URLRequest request); + + /// Loads the contents of the specified HTML string and navigates to it. + void loadHtmlString(String string, String? baseUrl); + + /// Loads the web content from the specified file and navigates to it. + void loadFileUrl(String url, String readAccessUrl); + + /// Convenience method to load a Flutter asset. + void loadFlutterAsset(String key); + + /// A Boolean value that indicates whether there is a valid back item in the + /// back-forward list. + bool canGoBack(); + + /// A Boolean value that indicates whether there is a valid forward item in + /// the back-forward list. + bool canGoForward(); + + /// Navigates to the back item in the back-forward list. + void goBack(); + + /// Navigates to the forward item in the back-forward list. + void goForward(); + + /// Reloads the current webpage. + void reload(); + + /// The page title. + String? getTitle(); + + /// A Boolean value that indicates whether horizontal swipe gestures trigger + /// backward and forward page navigation. + void setAllowsBackForwardNavigationGestures(bool allow); + + /// The custom user agent string. + void setCustomUserAgent(String? userAgent); + + /// Evaluates the specified JavaScript string. + @async + Object? evaluateJavaScript(String javaScriptString); + + /// A Boolean value that indicates whether you can inspect the view with + /// Safari Web Inspector. + void setInspectable(bool inspectable); + + /// The custom user agent string. + String? getCustomUserAgent(); } -/// Handles callbacks from a WKUIDelegate instance. +/// An object that displays interactive web content, such as for an in-app +/// browser. /// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -@FlutterApi() -abstract class WKUIDelegateFlutterApi { - @ObjCSelector( - 'onCreateWebViewForDelegateWithIdentifier:webViewIdentifier:configurationIdentifier:navigationAction:', - ) - void onCreateWebView( - int identifier, - int webViewIdentifier, - int configurationIdentifier, - WKNavigationActionData navigationAction, - ); +/// See https://developer.apple.com/documentation/webkit/wkwebview. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions( + import: 'WebKit', + name: 'WKWebView', + ), +) +abstract class WKWebView extends NSObject {} - /// Callback to Dart function `WKUIDelegate.requestMediaCapturePermission`. - @ObjCSelector( - 'requestMediaCapturePermissionForDelegateWithIdentifier:webViewIdentifier:origin:frame:type:', - ) +/// The methods for presenting native user interface elements on behalf of a +/// webpage. +/// +/// See https://developer.apple.com/documentation/webkit/wkuidelegate. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKUIDelegate extends NSObject { + WKUIDelegate(); + + /// Creates a new web view. + void Function( + WKWebView webView, + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + )? onCreateWebView; + + /// Determines whether a web resource, which the security origin object + /// describes, can access to the device’s microphone audio and camera video. @async - WKPermissionDecisionData requestMediaCapturePermission( - int identifier, - int webViewIdentifier, - WKSecurityOriginData origin, - WKFrameInfoData frame, - WKMediaCaptureTypeData type, - ); - - /// Callback to Dart function `WKUIDelegate.runJavaScriptAlertPanel`. - @ObjCSelector( - 'runJavaScriptAlertPanelForDelegateWithIdentifier:message:frame:', - ) + PermissionDecision Function( + WKWebView webView, + WKSecurityOrigin origin, + WKFrameInfo frame, + MediaCaptureType type, + )? requestMediaCapturePermission; + + /// Displays a JavaScript alert panel. @async - void runJavaScriptAlertPanel( - int identifier, + void Function( + WKWebView webView, String message, - WKFrameInfoData frame, - ); + WKFrameInfo frame, + )? runJavaScriptAlertPanel; - /// Callback to Dart function `WKUIDelegate.runJavaScriptConfirmPanel`. - @ObjCSelector( - 'runJavaScriptConfirmPanelForDelegateWithIdentifier:message:frame:', - ) + /// Displays a JavaScript confirm panel. @async - bool runJavaScriptConfirmPanel( - int identifier, + bool Function( + WKWebView webView, String message, - WKFrameInfoData frame, - ); + WKFrameInfo frame, + )? runJavaScriptConfirmPanel; - /// Callback to Dart function `WKUIDelegate.runJavaScriptTextInputPanel`. - @ObjCSelector( - 'runJavaScriptTextInputPanelForDelegateWithIdentifier:prompt:defaultText:frame:', - ) + /// Displays a JavaScript text input panel. @async - String runJavaScriptTextInputPanel( - int identifier, + String? Function( + WKWebView webView, String prompt, - String defaultText, - WKFrameInfoData frame, - ); + String? defaultText, + WKFrameInfo frame, + )? runJavaScriptTextInputPanel; } -/// Mirror of WKHttpCookieStore. +/// An object that manages the HTTP cookies associated with a particular web +/// view. /// -/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc. -@HostApi(dartHostTestHandler: 'TestWKHttpCookieStoreHostApi') -abstract class WKHttpCookieStoreHostApi { - @ObjCSelector('createFromWebsiteDataStoreWithIdentifier:dataStoreIdentifier:') - void createFromWebsiteDataStore( - int identifier, - int websiteDataStoreIdentifier, - ); - - @ObjCSelector('setCookieForStoreWithIdentifier:cookie:') +/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(import: 'WebKit')) +abstract class WKHTTPCookieStore extends NSObject { + /// Sets a cookie policy that indicates whether the cookie store allows cookie + /// storage. @async - void setCookie(int identifier, NSHttpCookieData cookie); + void setCookie(HTTPCookie cookie); } -/// Host API for `NSUrl`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. +/// The interface for the delegate of a scroll view. /// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -@HostApi(dartHostTestHandler: 'TestNSUrlHostApi') -abstract class NSUrlHostApi { - @ObjCSelector('absoluteStringForNSURLWithIdentifier:') - String? getAbsoluteString(int identifier); -} - -/// Flutter API for `NSUrl`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -@FlutterApi() -abstract class NSUrlFlutterApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); -} - -/// Host API for `UIScrollViewDelegate`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -@HostApi(dartHostTestHandler: 'TestUIScrollViewDelegateHostApi') -abstract class UIScrollViewDelegateHostApi { - @ObjCSelector('createWithIdentifier:') - void create(int identifier); -} +/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate. +@ProxyApi( + swiftOptions: SwiftProxyApiOptions(import: 'UIKit', supportsMacos: false), +) +abstract class UIScrollViewDelegate extends NSObject { + UIScrollViewDelegate(); -/// Flutter API for `UIScrollViewDelegate`. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -@FlutterApi() -abstract class UIScrollViewDelegateFlutterApi { - @ObjCSelector( - 'scrollViewDidScrollWithIdentifier:UIScrollViewIdentifier:x:y:', - ) - void scrollViewDidScroll( - int identifier, - int uiScrollViewIdentifier, + /// Tells the delegate when the user scrolls the content view within the + /// scroll view. + /// + /// Note that this is a convenient method that includes the `contentOffset` of + /// the `scrollView`. + void Function( + UIScrollView scrollView, double x, double y, - ); + )? scrollViewDidScroll; } -/// Host API for `NSUrlCredential`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. +/// An authentication credential consisting of information specific to the type +/// of credential and the type of persistent storage to use, if any. /// -/// See https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc. -@HostApi(dartHostTestHandler: 'TestNSUrlCredentialHostApi') -abstract class NSUrlCredentialHostApi { - /// Create a new native instance and add it to the `InstanceManager`. - @ObjCSelector( - 'createWithUserWithIdentifier:user:password:persistence:', - ) - void createWithUser( - int identifier, +/// See https://developer.apple.com/documentation/foundation/urlcredential. +@ProxyApi() +abstract class URLCredential extends NSObject { + /// Creates a URL credential instance for internet password authentication + /// with a given user name and password, using a given persistence setting. + URLCredential.withUser( String user, String password, - NSUrlCredentialPersistence persistence, + UrlCredentialPersistence persistence, ); } -/// Flutter API for `NSUrlProtectionSpace`. +/// A server or an area on a server, commonly referred to as a realm, that +/// requires authentication. /// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlprotectionspace?language=objc. -@FlutterApi() -abstract class NSUrlProtectionSpaceFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - @ObjCSelector('createWithIdentifier:host:realm:authenticationMethod:') - void create( - int identifier, - String? host, - String? realm, - String? authenticationMethod, - ); +/// See https://developer.apple.com/documentation/foundation/urlprotectionspace. +@ProxyApi() +abstract class URLProtectionSpace extends NSObject { + /// The receiver’s host. + late String host; + + /// The receiver’s port. + late int port; + + /// The receiver’s authentication realm. + late String? realm; + + /// The authentication method used by the receiver. + late String? authenticationMethod; } -/// Flutter API for `NSUrlAuthenticationChallenge`. +/// A challenge from a server requiring authentication from the client. /// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. +/// See https://developer.apple.com/documentation/foundation/urlauthenticationchallenge. +@ProxyApi() +abstract class URLAuthenticationChallenge extends NSObject { + /// The receiver’s protection space. + URLProtectionSpace getProtectionSpace(); +} + +/// A value that identifies the location of a resource, such as an item on a +/// remote server or the path to a local file.. /// -/// See https://developer.apple.com/documentation/foundation/nsurlauthenticationchallenge?language=objc. -@FlutterApi() -abstract class NSUrlAuthenticationChallengeFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - @ObjCSelector('createWithIdentifier:protectionSpaceIdentifier:') - void create(int identifier, int protectionSpaceIdentifier); +/// See https://developer.apple.com/documentation/foundation/url. +@ProxyApi(swiftOptions: SwiftProxyApiOptions(name: 'URL')) +abstract class URL extends NSObject { + /// The absolute string for the URL. + String getAbsoluteString(); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 735efa3f86ed..4e726c0364de 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_wkwebview description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.16.3 +version: 3.17.0 environment: sdk: ^3.5.0 @@ -13,11 +13,11 @@ flutter: implements: webview_flutter platforms: ios: - pluginClass: FLTWebViewFlutterPlugin + pluginClass: WebViewFlutterPlugin dartPluginClass: WebKitWebViewPlatform sharedDarwinSource: true macos: - pluginClass: FLTWebViewFlutterPlugin + pluginClass: WebViewFlutterPlugin dartPluginClass: WebKitWebViewPlatform sharedDarwinSource: true @@ -32,7 +32,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - pigeon: ^18.0.0 + pigeon: ^22.7.0 topics: - html diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.dart index 4f775df9e11c..9b5dca1393a4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.dart @@ -6,14 +6,14 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; import 'package:webview_flutter_wkwebview/src/legacy/wkwebview_cookie_manager.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'web_kit_cookie_manager_test.mocks.dart'; @GenerateMocks([ - WKHttpCookieStore, + WKHTTPCookieStore, WKWebsiteDataStore, ]) void main() { @@ -21,28 +21,41 @@ void main() { group('WebKitWebViewWidget', () { late MockWKWebsiteDataStore mockWebsiteDataStore; - late MockWKHttpCookieStore mockWKHttpCookieStore; + late MockWKHTTPCookieStore mockWKHttpCookieStore; late WKWebViewCookieManager cookieManager; + late HTTPCookie cookie; + late Map cookieProperties; setUp(() { mockWebsiteDataStore = MockWKWebsiteDataStore(); - mockWKHttpCookieStore = MockWKHttpCookieStore(); + mockWKHttpCookieStore = MockWKHTTPCookieStore(); when(mockWebsiteDataStore.httpCookieStore) .thenReturn(mockWKHttpCookieStore); - cookieManager = - WKWebViewCookieManager(websiteDataStore: mockWebsiteDataStore); + cookieManager = WKWebViewCookieManager( + websiteDataStore: mockWebsiteDataStore, + webKitProxy: WebKitProxy( + newHTTPCookie: ({ + required Map properties, + }) { + cookieProperties = properties; + return cookie = HTTPCookie.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ); + }, + ), + ); }); test('clearCookies', () async { when(mockWebsiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, any)) + [WebsiteDataType.cookies], any)) .thenAnswer((_) => Future.value(true)); expect(cookieManager.clearCookies(), completion(true)); when(mockWebsiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, any)) + [WebsiteDataType.cookies], any)) .thenAnswer((_) => Future.value(false)); expect(cookieManager.clearCookies(), completion(false)); }); @@ -52,16 +65,14 @@ void main() { const WebViewCookie(name: 'a', value: 'b', domain: 'c', path: 'd'), ); - final NSHttpCookie cookie = - verify(mockWKHttpCookieStore.setCookie(captureAny)).captured.single - as NSHttpCookie; + verify(mockWKHttpCookieStore.setCookie(cookie)); expect( - cookie.properties, - { - NSHttpCookiePropertyKey.name: 'a', - NSHttpCookiePropertyKey.value: 'b', - NSHttpCookiePropertyKey.domain: 'c', - NSHttpCookiePropertyKey.path: 'd', + cookieProperties, + { + HttpCookiePropertyKey.name: 'a', + HttpCookiePropertyKey.value: 'b', + HttpCookiePropertyKey.domain: 'c', + HttpCookiePropertyKey.path: 'd', }, ); }); @@ -81,3 +92,8 @@ void main() { }); }); } + +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.mocks.dart index fe13a87048e5..887a7152dec2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_cookie_manager_test.mocks.dart @@ -6,9 +6,7 @@ import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i4; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -23,9 +21,9 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeWKHttpCookieStore_0 extends _i1.SmartFake - implements _i2.WKHttpCookieStore { - _FakeWKHttpCookieStore_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,9 +32,20 @@ class _FakeWKHttpCookieStore_0 extends _i1.SmartFake ); } -class _FakeWKWebsiteDataStore_1 extends _i1.SmartFake +class _FakeWKHTTPCookieStore_1 extends _i1.SmartFake + implements _i2.WKHTTPCookieStore { + _FakeWKHTTPCookieStore_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWKWebsiteDataStore_2 extends _i1.SmartFake implements _i2.WKWebsiteDataStore { - _FakeWKWebsiteDataStore_1( + _FakeWKWebsiteDataStore_2( Object parent, Invocation parentInvocation, ) : super( @@ -45,17 +54,25 @@ class _FakeWKWebsiteDataStore_1 extends _i1.SmartFake ); } -/// A class which mocks [WKHttpCookieStore]. +/// A class which mocks [WKHTTPCookieStore]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { - MockWKHttpCookieStore() { +class MockWKHTTPCookieStore extends _i1.Mock implements _i2.WKHTTPCookieStore { + MockWKHTTPCookieStore() { _i1.throwOnMissingStub(this); } @override - _i3.Future setCookie(_i4.NSHttpCookie? cookie) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future setCookie(_i2.HTTPCookie? cookie) => (super.noSuchMethod( Invocation.method( #setCookie, [cookie], @@ -65,34 +82,34 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { ) as _i3.Future); @override - _i2.WKHttpCookieStore copy() => (super.noSuchMethod( + _i2.WKHTTPCookieStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKHttpCookieStore_0( + returnValue: _FakeWKHTTPCookieStore_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i2.WKHttpCookieStore); + ) as _i2.WKHTTPCookieStore); @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -100,14 +117,16 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -117,7 +136,6 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { /// A class which mocks [WKWebsiteDataStore]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKWebsiteDataStore extends _i1.Mock implements _i2.WKWebsiteDataStore { MockWKWebsiteDataStore() { @@ -125,40 +143,64 @@ class MockWKWebsiteDataStore extends _i1.Mock } @override - _i2.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod( + _i2.WKHTTPCookieStore get httpCookieStore => (super.noSuchMethod( Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_0( + returnValue: _FakeWKHTTPCookieStore_1( this, Invocation.getter(#httpCookieStore), ), - ) as _i2.WKHttpCookieStore); + ) as _i2.WKHTTPCookieStore); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKHTTPCookieStore pigeonVar_httpCookieStore() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + returnValue: _FakeWKHTTPCookieStore_1( + this, + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + ), + ) as _i2.WKHTTPCookieStore); @override _i3.Future removeDataOfTypes( - Set<_i2.WKWebsiteDataType>? dataTypes, - DateTime? since, + List<_i2.WebsiteDataType>? dataTypes, + double? modificationTimeInSecondsSinceEpoch, ) => (super.noSuchMethod( Invocation.method( #removeDataOfTypes, [ dataTypes, - since, + modificationTimeInSecondsSinceEpoch, ], ), returnValue: _i3.Future.value(false), ) as _i3.Future); @override - _i2.WKWebsiteDataStore copy() => (super.noSuchMethod( + _i2.WKWebsiteDataStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebsiteDataStore_1( + returnValue: _FakeWKWebsiteDataStore_2( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -166,18 +208,18 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -185,14 +227,16 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.dart index ac2f19804ffd..6b0e8816a9f6 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.dart @@ -3,28 +3,29 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; +import 'package:webview_flutter_wkwebview/src/common/platform_webview.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; +import 'package:webview_flutter_wkwebview/src/common/webkit_constants.dart'; import 'package:webview_flutter_wkwebview/src/legacy/web_kit_webview_widget.dart'; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; import 'web_kit_webview_widget_test.mocks.dart'; @GenerateMocks([ UIScrollView, + URLRequest, WKNavigationDelegate, WKPreferences, WKScriptMessageHandler, - WKWebViewIOS, - WKWebViewMacOS, + WKWebView, + UIViewWKWebView, WKWebViewConfiguration, WKWebsiteDataStore, WKUIDelegate, @@ -39,7 +40,7 @@ void main() { group('WebKitWebViewWidget', () { _WebViewMocks configureMocks() { final _WebViewMocks mocks = _WebViewMocks( - webView: MockWKWebViewIOS(), + webView: MockUIViewWKWebView(), webViewWidgetProxy: MockWebViewWidgetProxy(), userContentController: MockWKUserContentController(), preferences: MockWKPreferences(), @@ -56,7 +57,7 @@ void main() { any, observeValue: anyNamed('observeValue'), ), - ).thenReturn(mocks.webView); + ).thenReturn(PlatformWebView.fromNativeWebView(mocks.webView)); when( mocks.webViewWidgetProxy.createUIDelgate( onCreateWebView: captureAnyNamed('onCreateWebView'), @@ -72,18 +73,24 @@ void main() { didFailProvisionalNavigation: anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), )).thenReturn(mocks.navigationDelegate); when(mocks.webView.configuration).thenReturn(mocks.webViewConfiguration); - when(mocks.webViewConfiguration.userContentController).thenReturn( - mocks.userContentController, + when(mocks.webViewConfiguration.getUserContentController()).thenAnswer( + (_) => Future.value( + mocks.userContentController, + ), ); - when(mocks.webViewConfiguration.preferences) - .thenReturn(mocks.preferences); + when(mocks.webViewConfiguration.getPreferences()) + .thenAnswer((_) => Future.value(mocks.preferences)); when(mocks.webView.scrollView).thenReturn(mocks.scrollView); - when(mocks.webViewConfiguration.websiteDataStore).thenReturn( - mocks.websiteDataStore, + when(mocks.webViewConfiguration.getWebsiteDataStore()).thenAnswer( + (_) => Future.value(mocks.websiteDataStore), ); return mocks; } @@ -130,31 +137,50 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView, WKWebViewConfiguration, WKNavigationAction) - onCreateWebView = verify(mocks.webViewWidgetProxy.createUIDelgate( - onCreateWebView: captureAnyNamed('onCreateWebView'))) - .captured - .single - as void Function( - WKWebView, WKWebViewConfiguration, WKNavigationAction); + final void Function( + WKUIDelegate, + WKWebView, + WKWebViewConfiguration, + WKNavigationAction, + ) onCreateWebView = verify(mocks.webViewWidgetProxy.createUIDelgate( + onCreateWebView: captureAnyNamed('onCreateWebView'))) + .captured + .single as void Function( + WKUIDelegate, + WKWebView, + WKWebViewConfiguration, + WKNavigationAction, + ); - const NSUrlRequest request = NSUrlRequest(url: 'https://google.com'); + final URLRequest request = URLRequest.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ); onCreateWebView( + MockWKUIDelegate(), mocks.webView, mocks.webViewConfiguration, - const WKNavigationAction( + WKNavigationAction.pigeon_detached( request: request, - targetFrame: WKFrameInfo(isMainFrame: false, request: request), - navigationType: WKNavigationType.linkActivated, + targetFrame: WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: request, + pigeon_instanceManager: TestInstanceManager(), + ), + navigationType: NavigationType.linkActivated, + pigeon_instanceManager: TestInstanceManager(), ), ); - verify(mocks.webView.loadRequest(request)); + verify(mocks.webView.load(request)); }); group('CreationParams', () { testWidgets('initialUrl', (WidgetTester tester) async { final _WebViewMocks mocks = configureMocks(); + when( + mocks.webViewWidgetProxy.createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await buildWidget( tester, mocks, @@ -166,14 +192,15 @@ void main() { ), ), ); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); + + verify(mocks.webView.load(captureAny)).captured.single as URLRequest; }); testWidgets('backgroundColor', (WidgetTester tester) async { final _WebViewMocks mocks = configureMocks(); + + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await buildWidget( tester, mocks, @@ -187,8 +214,10 @@ void main() { ); verify(mocks.webView.setOpaque(false)); - verify(mocks.webView.setBackgroundColor(Colors.transparent)); - verify(mocks.scrollView.setBackgroundColor(Colors.red)); + verify(mocks.webView.setBackgroundColor(Colors.transparent.value)); + verify(mocks.scrollView.setBackgroundColor(Colors.red.value)); + + debugDefaultTargetPlatformOverride = null; }); testWidgets('userAgent', (WidgetTester tester) async { @@ -222,9 +251,9 @@ void main() { ); verify(mocks.webViewConfiguration - .setMediaTypesRequiringUserActionForPlayback({ - WKAudiovisualMediaType.all, - })); + .setMediaTypesRequiringUserActionForPlayback( + AudiovisualMediaType.all, + )); }); testWidgets('autoMediaPlaybackPolicy false', (WidgetTester tester) async { @@ -242,9 +271,9 @@ void main() { ); verify(mocks.webViewConfiguration - .setMediaTypesRequiringUserActionForPlayback({ - WKAudiovisualMediaType.none, - })); + .setMediaTypesRequiringUserActionForPlayback( + AudiovisualMediaType.none, + )); }); testWidgets('javascriptChannelNames', (WidgetTester tester) async { @@ -422,9 +451,9 @@ void main() { verify(mocks.userContentController.addUserScript(captureAny)) .captured .first as WKUserScript; - expect(zoomScript.isMainFrameOnly, isTrue); - expect(zoomScript.injectionTime, - WKUserScriptInjectionTime.atDocumentEnd); + expect(zoomScript.isForMainFrameOnly, isTrue); + expect( + zoomScript.injectionTime, UserScriptInjectionTime.atDocumentEnd); expect( zoomScript.source, "var meta = document.createElement('meta');\n" @@ -460,12 +489,9 @@ void main() { await buildWidget(tester, mocks); await testController.loadFile('/path/to/file.html'); - verify(mocks.webView.loadFileUrl( - '/path/to/file.html', - readAccessUrl: '/path/to', - )); + verify(mocks.webView.loadFileUrl('/path/to/file.html', '/path/to')); }); - + // testWidgets('loadFlutterAsset', (WidgetTester tester) async { final _WebViewMocks mocks = configureMocks(); final WebKitWebViewPlatformController testController = @@ -480,12 +506,13 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); - const String htmlString = 'Test data.'; + const String htmlString = + 'Test data.'; await testController.loadHtmlString(htmlString, baseUrl: 'baseUrl'); verify(mocks.webView.loadHtmlString( - 'Test data.', - baseUrl: 'baseUrl', + 'Test data.', + 'baseUrl', )); }); @@ -494,16 +521,19 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + when( + mocks.webViewWidgetProxy.createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await testController.loadUrl( 'https://www.google.com', {'a': 'header'}, ); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.allHttpHeaderFields, {'a': 'header'}); + final URLRequest request = verify(mocks.webView.load(captureAny)) + .captured + .single as URLRequest; + verify(request.setAllHttpHeaderFields({'a': 'header'})); }); group('loadRequest', () { @@ -528,17 +558,21 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + when( + mocks.webViewWidgetProxy + .createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await testController.loadRequest(WebViewRequest( uri: Uri.parse('https://www.google.com'), method: WebViewRequestMethod.get, )); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.allHttpHeaderFields, {}); - expect(request.httpMethod, 'get'); + final URLRequest request = verify(mocks.webView.load(captureAny)) + .captured + .single as URLRequest; + verify(request.setAllHttpHeaderFields({})); + verify(request.setHttpMethod('get')); }); testWidgets('GET with headers', (WidgetTester tester) async { @@ -546,18 +580,24 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + when( + mocks.webViewWidgetProxy + .createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await testController.loadRequest(WebViewRequest( uri: Uri.parse('https://www.google.com'), method: WebViewRequestMethod.get, headers: {'a': 'header'}, )); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.allHttpHeaderFields, {'a': 'header'}); - expect(request.httpMethod, 'get'); + final URLRequest request = verify(mocks.webView.load(captureAny)) + .captured + .single as URLRequest; + verify( + request.setAllHttpHeaderFields({'a': 'header'}), + ); + verify(request.setHttpMethod('get')); }); testWidgets('POST without body', (WidgetTester tester) async { @@ -565,16 +605,20 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + when( + mocks.webViewWidgetProxy + .createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await testController.loadRequest(WebViewRequest( uri: Uri.parse('https://www.google.com'), method: WebViewRequestMethod.post, )); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.httpMethod, 'post'); + final URLRequest request = verify(mocks.webView.load(captureAny)) + .captured + .single as URLRequest; + verify(request.setHttpMethod('post')); }); testWidgets('POST with body', (WidgetTester tester) async { @@ -582,19 +626,22 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + when( + mocks.webViewWidgetProxy + .createRequest(url: 'https://www.google.com'), + ).thenReturn(MockURLRequest()); + await testController.loadRequest(WebViewRequest( uri: Uri.parse('https://www.google.com'), method: WebViewRequestMethod.post, body: Uint8List.fromList('Test Body'.codeUnits))); - final NSUrlRequest request = - verify(mocks.webView.loadRequest(captureAny)).captured.single - as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.httpMethod, 'post'); - expect( - request.httpBody, - Uint8List.fromList('Test Body'.codeUnits), + final URLRequest request = verify(mocks.webView.load(captureAny)) + .captured + .single as URLRequest; + verify(request.setHttpMethod('post')); + verify( + request.setHttpBody(Uint8List.fromList('Test Body'.codeUnits)), ); }); }); @@ -846,9 +893,10 @@ void main() { when(mocks.webView.evaluateJavaScript('runJavaScript')) .thenThrow(PlatformException( code: '', - details: const NSError( + details: NSError.pigeon_detached( code: WKErrorCode.javaScriptResultTypeIsUnsupported, domain: '', + userInfo: const {}, ), )); expect( @@ -882,9 +930,12 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await testController.scrollTo(2, 4); - verify( - mocks.scrollView.setContentOffset(const Point(2.0, 4.0))); + verify(mocks.scrollView.setContentOffset(2.0, 4.0)); + + debugDefaultTargetPlatformOverride = null; }); testWidgets('scrollBy', (WidgetTester tester) async { @@ -892,8 +943,12 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await testController.scrollBy(2, 4); - verify(mocks.scrollView.scrollBy(const Point(2.0, 4.0))); + verify(mocks.scrollView.scrollBy(2.0, 4.0)); + + debugDefaultTargetPlatformOverride = null; }); testWidgets('getScrollX', (WidgetTester tester) async { @@ -901,9 +956,13 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + when(mocks.scrollView.getContentOffset()).thenAnswer( - (_) => Future>.value(const Point(8.0, 16.0))); + (_) => Future>.value(const [8.0, 16.0])); expect(testController.getScrollX(), completion(8.0)); + + debugDefaultTargetPlatformOverride = null; }); testWidgets('getScrollY', (WidgetTester tester) async { @@ -911,9 +970,13 @@ void main() { final WebKitWebViewPlatformController testController = await buildWidget(tester, mocks); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + when(mocks.scrollView.getContentOffset()).thenAnswer( - (_) => Future>.value(const Point(8.0, 16.0))); + (_) => Future>.value(const [8.0, 16.0])); expect(testController.getScrollY(), completion(16.0)); + + debugDefaultTargetPlatformOverride = null; }); testWidgets('clearCache', (WidgetTester tester) async { @@ -922,13 +985,13 @@ void main() { await buildWidget(tester, mocks); when( mocks.websiteDataStore.removeDataOfTypes( - { - WKWebsiteDataType.memoryCache, - WKWebsiteDataType.diskCache, - WKWebsiteDataType.offlineWebApplicationCache, - WKWebsiteDataType.localStorage, - }, - DateTime.fromMillisecondsSinceEpoch(0), + [ + WebsiteDataType.memoryCache, + WebsiteDataType.diskCache, + WebsiteDataType.offlineWebApplicationCache, + WebsiteDataType.localStorage, + ], + 0, ), ).thenAnswer((_) => Future.value(false)); @@ -971,15 +1034,15 @@ void main() { expect(userScripts[0].source, 'window.c = webkit.messageHandlers.c;'); expect( userScripts[0].injectionTime, - WKUserScriptInjectionTime.atDocumentStart, + UserScriptInjectionTime.atDocumentStart, ); - expect(userScripts[0].isMainFrameOnly, false); + expect(userScripts[0].isForMainFrameOnly, false); expect(userScripts[1].source, 'window.d = webkit.messageHandlers.d;'); expect( userScripts[1].injectionTime, - WKUserScriptInjectionTime.atDocumentStart, + UserScriptInjectionTime.atDocumentStart, ); - expect(userScripts[0].isMainFrameOnly, false); + expect(userScripts[0].isForMainFrameOnly, false); }); testWidgets('removeJavascriptChannels', (WidgetTester tester) async { @@ -1023,9 +1086,9 @@ void main() { expect(userScripts[0].source, 'window.d = webkit.messageHandlers.d;'); expect( userScripts[0].injectionTime, - WKUserScriptInjectionTime.atDocumentStart, + UserScriptInjectionTime.atDocumentStart, ); - expect(userScripts[0].isMainFrameOnly, false); + expect(userScripts[0].isForMainFrameOnly, false); }); testWidgets('removeJavascriptChannels with zoom disabled', @@ -1060,9 +1123,8 @@ void main() { verify(mocks.userContentController.addUserScript(captureAny)) .captured .first as WKUserScript; - expect(zoomScript.isMainFrameOnly, isTrue); - expect( - zoomScript.injectionTime, WKUserScriptInjectionTime.atDocumentEnd); + expect(zoomScript.isForMainFrameOnly, isTrue); + expect(zoomScript.injectionTime, UserScriptInjectionTime.atDocumentEnd); expect( zoomScript.source, "var meta = document.createElement('meta');\n" @@ -1079,7 +1141,8 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView, String) didStartProvisionalNavigation = + final void Function(WKNavigationDelegate, WKWebView, String) + didStartProvisionalNavigation = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1091,8 +1154,17 @@ void main() { anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as void Function(WKWebView, String); - didStartProvisionalNavigation(mocks.webView, 'https://google.com'); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as void Function( + WKNavigationDelegate, WKWebView, String); + didStartProvisionalNavigation( + mocks.navigationDelegate, + mocks.webView, + 'https://google.com', + ); verify(mocks.callbacksHandler.onPageStarted('https://google.com')); }); @@ -1101,7 +1173,8 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView, String) didFinishNavigation = + final void Function(WKNavigationDelegate, WKWebView, String) + didFinishNavigation = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: captureAnyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1113,8 +1186,17 @@ void main() { anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as void Function(WKWebView, String); - didFinishNavigation(mocks.webView, 'https://google.com'); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as void Function( + WKNavigationDelegate, WKWebView, String); + didFinishNavigation( + mocks.navigationDelegate, + mocks.webView, + 'https://google.com', + ); verify(mocks.callbacksHandler.onPageFinished('https://google.com')); }); @@ -1124,7 +1206,8 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView, NSError) didFailNavigation = + final void Function(WKNavigationDelegate, WKWebView, NSError) + didFailNavigation = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1136,16 +1219,23 @@ void main() { anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as void Function(WKWebView, NSError); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as void Function( + WKNavigationDelegate, WKWebView, NSError); didFailNavigation( + mocks.navigationDelegate, mocks.webView, - const NSError( + NSError.pigeon_detached( code: WKErrorCode.webViewInvalidated, domain: 'domain', - userInfo: { + userInfo: const { NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', }, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -1164,7 +1254,8 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView, NSError) didFailProvisionalNavigation = + final void Function(WKNavigationDelegate, WKWebView, NSError) + didFailProvisionalNavigation = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1176,16 +1267,23 @@ void main() { captureAnyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as void Function(WKWebView, NSError); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as void Function( + WKNavigationDelegate, WKWebView, NSError); didFailProvisionalNavigation( + mocks.navigationDelegate, mocks.webView, - const NSError( + NSError.pigeon_detached( code: WKErrorCode.webContentProcessTerminated, domain: 'domain', - userInfo: { + userInfo: const { NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', }, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -1208,7 +1306,8 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks); - final void Function(WKWebView) webViewWebContentProcessDidTerminate = + final void Function(WKNavigationDelegate, WKWebView) + webViewWebContentProcessDidTerminate = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1220,8 +1319,15 @@ void main() { anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: captureAnyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as void Function(WKWebView); - webViewWebContentProcessDidTerminate(mocks.webView); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as void Function(WKNavigationDelegate, WKWebView); + webViewWebContentProcessDidTerminate( + mocks.navigationDelegate, + mocks.webView, + ); final WebResourceError error = verify(mocks.callbacksHandler.onWebResourceError(captureAny)) @@ -1241,8 +1347,9 @@ void main() { final _WebViewMocks mocks = configureMocks(); await buildWidget(tester, mocks, hasNavigationDelegate: true); - final Future Function( - WKWebView, WKNavigationAction) decidePolicyForNavigationAction = + final Future Function( + WKNavigationDelegate, WKWebView, WKNavigationAction) + decidePolicyForNavigationAction = verify(mocks.webViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -1254,26 +1361,39 @@ void main() { anyNamed('didFailProvisionalNavigation'), webViewWebContentProcessDidTerminate: anyNamed('webViewWebContentProcessDidTerminate'), - )).captured.single as Future Function( - WKWebView, WKNavigationAction); + decidePolicyForNavigationResponse: + anyNamed('decidePolicyForNavigationResponse'), + didReceiveAuthenticationChallenge: + anyNamed('didReceiveAuthenticationChallenge'), + )).captured.single as Future Function( + WKNavigationDelegate, WKWebView, WKNavigationAction); when(mocks.callbacksHandler.onNavigationRequest( isForMainFrame: argThat(isFalse, named: 'isForMainFrame'), url: 'https://google.com', )).thenReturn(true); + final MockURLRequest mockRequest = MockURLRequest(); + when(mockRequest.getUrl()).thenAnswer( + (_) => Future.value('https://google.com'), + ); + expect( - decidePolicyForNavigationAction( + await decidePolicyForNavigationAction( + mocks.navigationDelegate, mocks.webView, - const WKNavigationAction( - request: NSUrlRequest(url: 'https://google.com'), - targetFrame: WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com')), - navigationType: WKNavigationType.linkActivated, + WKNavigationAction.pigeon_detached( + request: mockRequest, + targetFrame: WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: mockRequest, + pigeon_instanceManager: TestInstanceManager(), + ), + navigationType: NavigationType.linkActivated, + pigeon_instanceManager: TestInstanceManager(), ), ), - completion(WKNavigationActionPolicy.allow), + NavigationActionPolicy.allow, ); verify(mocks.callbacksHandler.onNavigationRequest( @@ -1288,24 +1408,22 @@ void main() { verify(mocks.webView.addObserver( mocks.webView, - keyPath: 'estimatedProgress', - options: { - NSKeyValueObservingOptions.newValue, - }, + 'estimatedProgress', + [KeyValueObservingOptions.newValue], )); - final void Function(String, NSObject, Map) + final void Function(String, NSObject, Map) observeValue = verify(mocks.webViewWidgetProxy.createWebView(any, observeValue: captureAnyNamed('observeValue'))) .captured .single as void Function( - String, NSObject, Map); + String, NSObject, Map); observeValue( 'estimatedProgress', mocks.webView, - {NSKeyValueChangeKey.newValue: 0.32}, + {KeyValueChangeKey.newValue: 0.32}, ); verify(mocks.callbacksHandler.onProgress(32)); @@ -1318,7 +1436,7 @@ void main() { verifyNever(mocks.webView.removeObserver( mocks.webView, - keyPath: 'estimatedProgress', + 'estimatedProgress', )); }); }); @@ -1338,18 +1456,24 @@ void main() { await buildWidget(tester, mocks); await testController.addJavascriptChannels({'hello'}); - final void Function(WKUserContentController, WKScriptMessage) - didReceiveScriptMessage = verify(mocks.webViewWidgetProxy - .createScriptMessageHandler( - didReceiveScriptMessage: - captureAnyNamed('didReceiveScriptMessage'))) - .captured - .single - as void Function(WKUserContentController, WKScriptMessage); + final void Function(WKScriptMessageHandler, WKUserContentController, + WKScriptMessage) didReceiveScriptMessage = verify( + mocks.webViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: + captureAnyNamed('didReceiveScriptMessage'))) + .captured + .single + as void Function(WKScriptMessageHandler, WKUserContentController, + WKScriptMessage); didReceiveScriptMessage( + MockWKScriptMessageHandler(), mocks.userContentController, - const WKScriptMessage(name: 'hello', body: 'A message.'), + WKScriptMessage.pigeon_detached( + name: 'hello', + body: 'A message.', + pigeon_instanceManager: TestInstanceManager(), + ), ); verify(mocks.javascriptChannelRegistry.onJavascriptChannelMessage( 'hello', @@ -1376,7 +1500,7 @@ class _WebViewMocks { required this.javascriptChannelRegistry, }); - final MockWKWebViewIOS webView; + final MockUIViewWKWebView webView; final MockWebViewWidgetProxy webViewWidgetProxy; final MockWKUserContentController userContentController; final MockWKPreferences preferences; @@ -1388,3 +1512,8 @@ class _WebViewMocks { final MockWebViewPlatformCallbacksHandler callbacksHandler; final MockJavascriptChannelRegistry javascriptChannelRegistry; } + +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.mocks.dart index 0c8876b9df03..db74eb203580 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/legacy/web_kit_webview_widget_test.mocks.dart @@ -3,23 +3,21 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; -import 'dart:math' as _i2; -import 'dart:ui' as _i6; +import 'dart:async' as _i4; +import 'dart:typed_data' as _i5; import 'package:mockito/mockito.dart' as _i1; import 'package:webview_flutter_platform_interface/src/legacy/types/javascript_channel.dart' - as _i9; + as _i7; import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' - as _i10; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart' as _i8; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i7; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart' + as _i6; +import 'package:webview_flutter_wkwebview/src/common/platform_webview.dart' + as _i3; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; import 'package:webview_flutter_wkwebview/src/legacy/web_kit_webview_widget.dart' - as _i11; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart' as _i3; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i4; + as _i9; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -34,9 +32,9 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i4; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakePoint_0 extends _i1.SmartFake - implements _i2.Point { - _FakePoint_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -45,7 +43,7 @@ class _FakePoint_0 extends _i1.SmartFake ); } -class _FakeUIScrollView_1 extends _i1.SmartFake implements _i3.UIScrollView { +class _FakeUIScrollView_1 extends _i1.SmartFake implements _i2.UIScrollView { _FakeUIScrollView_1( Object parent, Invocation parentInvocation, @@ -55,9 +53,8 @@ class _FakeUIScrollView_1 extends _i1.SmartFake implements _i3.UIScrollView { ); } -class _FakeWKNavigationDelegate_2 extends _i1.SmartFake - implements _i4.WKNavigationDelegate { - _FakeWKNavigationDelegate_2( +class _FakeURLRequest_2 extends _i1.SmartFake implements _i2.URLRequest { + _FakeURLRequest_2( Object parent, Invocation parentInvocation, ) : super( @@ -66,8 +63,9 @@ class _FakeWKNavigationDelegate_2 extends _i1.SmartFake ); } -class _FakeWKPreferences_3 extends _i1.SmartFake implements _i4.WKPreferences { - _FakeWKPreferences_3( +class _FakeWKNavigationDelegate_3 extends _i1.SmartFake + implements _i2.WKNavigationDelegate { + _FakeWKNavigationDelegate_3( Object parent, Invocation parentInvocation, ) : super( @@ -76,9 +74,8 @@ class _FakeWKPreferences_3 extends _i1.SmartFake implements _i4.WKPreferences { ); } -class _FakeWKScriptMessageHandler_4 extends _i1.SmartFake - implements _i4.WKScriptMessageHandler { - _FakeWKScriptMessageHandler_4( +class _FakeWKPreferences_4 extends _i1.SmartFake implements _i2.WKPreferences { + _FakeWKPreferences_4( Object parent, Invocation parentInvocation, ) : super( @@ -87,9 +84,9 @@ class _FakeWKScriptMessageHandler_4 extends _i1.SmartFake ); } -class _FakeWKWebViewConfiguration_5 extends _i1.SmartFake - implements _i4.WKWebViewConfiguration { - _FakeWKWebViewConfiguration_5( +class _FakeWKScriptMessageHandler_5 extends _i1.SmartFake + implements _i2.WKScriptMessageHandler { + _FakeWKScriptMessageHandler_5( Object parent, Invocation parentInvocation, ) : super( @@ -98,7 +95,7 @@ class _FakeWKWebViewConfiguration_5 extends _i1.SmartFake ); } -class _FakeWKWebView_6 extends _i1.SmartFake implements _i4.WKWebView { +class _FakeWKWebView_6 extends _i1.SmartFake implements _i2.WKWebView { _FakeWKWebView_6( Object parent, Invocation parentInvocation, @@ -108,9 +105,20 @@ class _FakeWKWebView_6 extends _i1.SmartFake implements _i4.WKWebView { ); } -class _FakeWKUserContentController_7 extends _i1.SmartFake - implements _i4.WKUserContentController { - _FakeWKUserContentController_7( +class _FakeWKWebViewConfiguration_7 extends _i1.SmartFake + implements _i2.WKWebViewConfiguration { + _FakeWKWebViewConfiguration_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUIViewWKWebView_8 extends _i1.SmartFake + implements _i2.UIViewWKWebView { + _FakeUIViewWKWebView_8( Object parent, Invocation parentInvocation, ) : super( @@ -119,9 +127,9 @@ class _FakeWKUserContentController_7 extends _i1.SmartFake ); } -class _FakeWKWebsiteDataStore_8 extends _i1.SmartFake - implements _i4.WKWebsiteDataStore { - _FakeWKWebsiteDataStore_8( +class _FakeWKUserContentController_9 extends _i1.SmartFake + implements _i2.WKUserContentController { + _FakeWKUserContentController_9( Object parent, Invocation parentInvocation, ) : super( @@ -130,9 +138,9 @@ class _FakeWKWebsiteDataStore_8 extends _i1.SmartFake ); } -class _FakeWKHttpCookieStore_9 extends _i1.SmartFake - implements _i4.WKHttpCookieStore { - _FakeWKHttpCookieStore_9( +class _FakeWKWebsiteDataStore_10 extends _i1.SmartFake + implements _i2.WKWebsiteDataStore { + _FakeWKWebsiteDataStore_10( Object parent, Invocation parentInvocation, ) : super( @@ -141,8 +149,30 @@ class _FakeWKHttpCookieStore_9 extends _i1.SmartFake ); } -class _FakeWKUIDelegate_10 extends _i1.SmartFake implements _i4.WKUIDelegate { - _FakeWKUIDelegate_10( +class _FakeWKHTTPCookieStore_11 extends _i1.SmartFake + implements _i2.WKHTTPCookieStore { + _FakeWKHTTPCookieStore_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWKUIDelegate_12 extends _i1.SmartFake implements _i2.WKUIDelegate { + _FakeWKUIDelegate_12( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformWebView_13 extends _i1.SmartFake + implements _i3.PlatformWebView { + _FakePlatformWebView_13( Object parent, Invocation parentInvocation, ) : super( @@ -154,1170 +184,1314 @@ class _FakeWKUIDelegate_10 extends _i1.SmartFake implements _i4.WKUIDelegate { /// A class which mocks [UIScrollView]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockUIScrollView extends _i1.Mock implements _i3.UIScrollView { +class MockUIScrollView extends _i1.Mock implements _i2.UIScrollView { MockUIScrollView() { _i1.throwOnMissingStub(this); } @override - _i5.Future<_i2.Point> getContentOffset() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future> getContentOffset() => (super.noSuchMethod( Invocation.method( #getContentOffset, [], ), - returnValue: _i5.Future<_i2.Point>.value(_FakePoint_0( - this, - Invocation.method( - #getContentOffset, - [], - ), - )), - ) as _i5.Future<_i2.Point>); + returnValue: _i4.Future>.value([]), + ) as _i4.Future>); @override - _i5.Future scrollBy(_i2.Point? offset) => (super.noSuchMethod( + _i4.Future scrollBy( + double? x, + double? y, + ) => + (super.noSuchMethod( Invocation.method( #scrollBy, - [offset], + [ + x, + y, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setContentOffset(_i2.Point? offset) => + _i4.Future setContentOffset( + double? x, + double? y, + ) => (super.noSuchMethod( Invocation.method( #setContentOffset, - [offset], + [ + x, + y, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setDelegate(_i3.UIScrollViewDelegate? delegate) => + _i4.Future setDelegate(_i2.UIScrollViewDelegate? delegate) => (super.noSuchMethod( Invocation.method( #setDelegate, [delegate], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i3.UIScrollView copy() => (super.noSuchMethod( + _i2.UIScrollView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), returnValue: _FakeUIScrollView_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i3.UIScrollView); + ) as _i2.UIScrollView); @override - _i5.Future setBackgroundColor(_i6.Color? color) => (super.noSuchMethod( + _i4.Future setBackgroundColor(int? value) => (super.noSuchMethod( Invocation.method( #setBackgroundColor, - [color], + [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setOpaque(bool? opaque) => (super.noSuchMethod( + _i4.Future setOpaque(bool? opaque) => (super.noSuchMethod( Invocation.method( #setOpaque, [opaque], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } -/// A class which mocks [WKNavigationDelegate]. +/// A class which mocks [URLRequest]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKNavigationDelegate extends _i1.Mock - implements _i4.WKNavigationDelegate { - MockWKNavigationDelegate() { +class MockURLRequest extends _i1.Mock implements _i2.URLRequest { + MockURLRequest() { _i1.throwOnMissingStub(this); } @override - _i4.WKNavigationDelegate copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWKNavigationDelegate_2( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( this, - Invocation.method( - #copy, - [], - ), + Invocation.getter(#pigeon_instanceManager), ), - ) as _i4.WKNavigationDelegate); + ) as _i2.PigeonInstanceManager); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => - (super.noSuchMethod( + _i4.Future getUrl() => (super.noSuchMethod( Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + #getUrl, + [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => - (super.noSuchMethod( + _i4.Future setHttpMethod(String? method) => (super.noSuchMethod( Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, + #setHttpMethod, + [method], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); -} + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); -/// A class which mocks [WKPreferences]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKPreferences extends _i1.Mock implements _i4.WKPreferences { - MockWKPreferences() { - _i1.throwOnMissingStub(this); - } + @override + _i4.Future getHttpMethod() => (super.noSuchMethod( + Invocation.method( + #getHttpMethod, + [], + ), + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setJavaScriptEnabled(bool? enabled) => (super.noSuchMethod( + _i4.Future setHttpBody(_i5.Uint8List? body) => (super.noSuchMethod( Invocation.method( - #setJavaScriptEnabled, - [enabled], + #setHttpBody, + [body], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i4.WKPreferences copy() => (super.noSuchMethod( + _i4.Future<_i5.Uint8List?> getHttpBody() => (super.noSuchMethod( Invocation.method( - #copy, + #getHttpBody, [], ), - returnValue: _FakeWKPreferences_3( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i4.WKPreferences); + returnValue: _i4.Future<_i5.Uint8List?>.value(), + ) as _i4.Future<_i5.Uint8List?>); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future setAllHttpHeaderFields(Map? fields) => (super.noSuchMethod( Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + #setAllHttpHeaderFields, + [fields], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future?> getAllHttpHeaderFields() => (super.noSuchMethod( Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, + #getAllHttpHeaderFields, + [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); -} - -/// A class which mocks [WKScriptMessageHandler]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKScriptMessageHandler extends _i1.Mock - implements _i4.WKScriptMessageHandler { - MockWKScriptMessageHandler() { - _i1.throwOnMissingStub(this); - } + returnValue: _i4.Future?>.value(), + ) as _i4.Future?>); @override - void Function( - _i4.WKUserContentController, - _i4.WKScriptMessage, - ) get didReceiveScriptMessage => (super.noSuchMethod( - Invocation.getter(#didReceiveScriptMessage), - returnValue: ( - _i4.WKUserContentController userContentController, - _i4.WKScriptMessage message, - ) {}, - ) as void Function( - _i4.WKUserContentController, - _i4.WKScriptMessage, - )); - - @override - _i4.WKScriptMessageHandler copy() => (super.noSuchMethod( + _i2.URLRequest pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKScriptMessageHandler_4( + returnValue: _FakeURLRequest_2( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKScriptMessageHandler); + ) as _i2.URLRequest); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } -/// A class which mocks [WKWebViewIOS]. +/// A class which mocks [WKNavigationDelegate]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKWebViewIOS extends _i1.Mock implements _i4.WKWebViewIOS { - MockWKWebViewIOS() { +class MockWKNavigationDelegate extends _i1.Mock + implements _i2.WKNavigationDelegate { + MockWKNavigationDelegate() { _i1.throwOnMissingStub(this); } @override - _i3.UIScrollView get scrollView => (super.noSuchMethod( - Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_1( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( this, - Invocation.getter(#scrollView), + Invocation.getter(#pigeon_instanceManager), ), - ) as _i3.UIScrollView); + ) as _i2.PigeonInstanceManager); @override - _i4.WKWebViewConfiguration get configuration => (super.noSuchMethod( - Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_5( - this, - Invocation.getter(#configuration), - ), - ) as _i4.WKWebViewConfiguration); - - @override - _i4.WKWebView copy() => (super.noSuchMethod( + _i2.WKNavigationDelegate pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebView_6( + returnValue: _FakeWKNavigationDelegate_3( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKWebView); - - @override - _i5.Future setBackgroundColor(_i6.Color? color) => (super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [color], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.WKNavigationDelegate); @override - _i5.Future setOpaque(bool? opaque) => (super.noSuchMethod( + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( Invocation.method( - #setOpaque, - [opaque], + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setUIDelegate(_i4.WKUIDelegate? delegate) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( - #setUIDelegate, - [delegate], + #removeObserver, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); +} + +/// A class which mocks [WKPreferences]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKPreferences extends _i1.Mock implements _i2.WKPreferences { + MockWKPreferences() { + _i1.throwOnMissingStub(this); + } @override - _i5.Future setNavigationDelegate(_i4.WKNavigationDelegate? delegate) => - (super.noSuchMethod( - Invocation.method( - #setNavigationDelegate, - [delegate], + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.PigeonInstanceManager); @override - _i5.Future getUrl() => (super.noSuchMethod( + _i4.Future setJavaScriptEnabled(bool? enabled) => (super.noSuchMethod( Invocation.method( - #getUrl, - [], + #setJavaScriptEnabled, + [enabled], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getEstimatedProgress() => (super.noSuchMethod( + _i2.WKPreferences pigeon_copy() => (super.noSuchMethod( Invocation.method( - #getEstimatedProgress, + #pigeon_copy, [], ), - returnValue: _i5.Future.value(0.0), - ) as _i5.Future); - - @override - _i5.Future loadRequest(_i7.NSUrlRequest? request) => - (super.noSuchMethod( - Invocation.method( - #loadRequest, - [request], + returnValue: _FakeWKPreferences_4( + this, + Invocation.method( + #pigeon_copy, + [], + ), ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.WKPreferences); @override - _i5.Future loadHtmlString( - String? string, { - String? baseUrl, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( - #loadHtmlString, - [string], - {#baseUrl: baseUrl}, + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadFileUrl( - String? url, { - required String? readAccessUrl, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( - #loadFileUrl, - [url], - {#readAccessUrl: readAccessUrl}, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future loadFlutterAsset(String? key) => (super.noSuchMethod( - Invocation.method( - #loadFlutterAsset, - [key], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future canGoBack() => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [], + #removeObserver, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); +} - @override - _i5.Future canGoForward() => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [], - ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); +/// A class which mocks [WKScriptMessageHandler]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKScriptMessageHandler extends _i1.Mock + implements _i2.WKScriptMessageHandler { + MockWKScriptMessageHandler() { + _i1.throwOnMissingStub(this); + } @override - _i5.Future goBack() => (super.noSuchMethod( - Invocation.method( - #goBack, - [], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + void Function( + _i2.WKScriptMessageHandler, + _i2.WKUserContentController, + _i2.WKScriptMessage, + ) get didReceiveScriptMessage => (super.noSuchMethod( + Invocation.getter(#didReceiveScriptMessage), + returnValue: ( + _i2.WKScriptMessageHandler pigeon_instance, + _i2.WKUserContentController controller, + _i2.WKScriptMessage message, + ) {}, + ) as void Function( + _i2.WKScriptMessageHandler, + _i2.WKUserContentController, + _i2.WKScriptMessage, + )); @override - _i5.Future goForward() => (super.noSuchMethod( - Invocation.method( - #goForward, - [], + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.PigeonInstanceManager); @override - _i5.Future reload() => (super.noSuchMethod( + _i2.WKScriptMessageHandler pigeon_copy() => (super.noSuchMethod( Invocation.method( - #reload, + #pigeon_copy, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future getTitle() => (super.noSuchMethod( - Invocation.method( - #getTitle, - [], + returnValue: _FakeWKScriptMessageHandler_5( + this, + Invocation.method( + #pigeon_copy, + [], + ), ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.WKScriptMessageHandler); @override - _i5.Future getCustomUserAgent() => (super.noSuchMethod( + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( Invocation.method( - #getCustomUserAgent, - [], + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setAllowsBackForwardNavigationGestures(bool? allow) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( - #setAllowsBackForwardNavigationGestures, - [allow], + #removeObserver, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); +} - @override - _i5.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( - Invocation.method( - #setCustomUserAgent, - [userAgent], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); +/// A class which mocks [WKWebView]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKWebView extends _i1.Mock implements _i2.WKWebView { + MockWKWebView() { + _i1.throwOnMissingStub(this); + } @override - _i5.Future evaluateJavaScript(String? javaScriptString) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavaScript, - [javaScriptString], + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + ) as _i2.PigeonInstanceManager); @override - _i5.Future setInspectable(bool? inspectable) => (super.noSuchMethod( + _i2.WKWebView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #setInspectable, - [inspectable], + #pigeon_copy, + [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _FakeWKWebView_6( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WKWebView); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } -/// A class which mocks [WKWebViewMacOS]. +/// A class which mocks [UIViewWKWebView]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKWebViewMacOS extends _i1.Mock implements _i4.WKWebViewMacOS { - MockWKWebViewMacOS() { +class MockUIViewWKWebView extends _i1.Mock implements _i2.UIViewWKWebView { + MockUIViewWKWebView() { _i1.throwOnMissingStub(this); } @override - _i4.WKWebViewConfiguration get configuration => (super.noSuchMethod( + _i2.WKWebViewConfiguration get configuration => (super.noSuchMethod( Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_5( + returnValue: _FakeWKWebViewConfiguration_7( this, Invocation.getter(#configuration), ), - ) as _i4.WKWebViewConfiguration); + ) as _i2.WKWebViewConfiguration); + + @override + _i2.UIScrollView get scrollView => (super.noSuchMethod( + Invocation.getter(#scrollView), + returnValue: _FakeUIScrollView_1( + this, + Invocation.getter(#scrollView), + ), + ) as _i2.UIScrollView); @override - _i4.WKWebView copy() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKWebViewConfiguration pigeonVar_configuration() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeonVar_configuration, [], ), - returnValue: _FakeWKWebView_6( + returnValue: _FakeWKWebViewConfiguration_7( + this, + Invocation.method( + #pigeonVar_configuration, + [], + ), + ), + ) as _i2.WKWebViewConfiguration); + + @override + _i2.UIScrollView pigeonVar_scrollView() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_scrollView, + [], + ), + returnValue: _FakeUIScrollView_1( this, Invocation.method( - #copy, + #pigeonVar_scrollView, [], ), ), - ) as _i4.WKWebView); + ) as _i2.UIScrollView); @override - _i5.Future setUIDelegate(_i4.WKUIDelegate? delegate) => + _i4.Future setUIDelegate(_i2.WKUIDelegate? delegate) => (super.noSuchMethod( Invocation.method( #setUIDelegate, [delegate], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setNavigationDelegate(_i4.WKNavigationDelegate? delegate) => + _i4.Future setNavigationDelegate(_i2.WKNavigationDelegate? delegate) => (super.noSuchMethod( Invocation.method( #setNavigationDelegate, [delegate], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getUrl() => (super.noSuchMethod( + _i4.Future getUrl() => (super.noSuchMethod( Invocation.method( #getUrl, [], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getEstimatedProgress() => (super.noSuchMethod( + _i4.Future getEstimatedProgress() => (super.noSuchMethod( Invocation.method( #getEstimatedProgress, [], ), - returnValue: _i5.Future.value(0.0), - ) as _i5.Future); + returnValue: _i4.Future.value(0.0), + ) as _i4.Future); @override - _i5.Future loadRequest(_i7.NSUrlRequest? request) => - (super.noSuchMethod( + _i4.Future load(_i2.URLRequest? request) => (super.noSuchMethod( Invocation.method( - #loadRequest, + #load, [request], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadHtmlString( - String? string, { + _i4.Future loadHtmlString( + String? string, String? baseUrl, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadHtmlString, - [string], - {#baseUrl: baseUrl}, + [ + string, + baseUrl, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadFileUrl( - String? url, { - required String? readAccessUrl, - }) => + _i4.Future loadFileUrl( + String? url, + String? readAccessUrl, + ) => (super.noSuchMethod( Invocation.method( #loadFileUrl, - [url], - {#readAccessUrl: readAccessUrl}, + [ + url, + readAccessUrl, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadFlutterAsset(String? key) => (super.noSuchMethod( + _i4.Future loadFlutterAsset(String? key) => (super.noSuchMethod( Invocation.method( #loadFlutterAsset, [key], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future canGoBack() => (super.noSuchMethod( + _i4.Future canGoBack() => (super.noSuchMethod( Invocation.method( #canGoBack, [], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(false), + ) as _i4.Future); @override - _i5.Future canGoForward() => (super.noSuchMethod( + _i4.Future canGoForward() => (super.noSuchMethod( Invocation.method( #canGoForward, [], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(false), + ) as _i4.Future); @override - _i5.Future goBack() => (super.noSuchMethod( + _i4.Future goBack() => (super.noSuchMethod( Invocation.method( #goBack, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future goForward() => (super.noSuchMethod( + _i4.Future goForward() => (super.noSuchMethod( Invocation.method( #goForward, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future reload() => (super.noSuchMethod( + _i4.Future reload() => (super.noSuchMethod( Invocation.method( #reload, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getTitle() => (super.noSuchMethod( + _i4.Future getTitle() => (super.noSuchMethod( Invocation.method( #getTitle, [], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getCustomUserAgent() => (super.noSuchMethod( - Invocation.method( - #getCustomUserAgent, - [], - ), - returnValue: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setAllowsBackForwardNavigationGestures(bool? allow) => + _i4.Future setAllowsBackForwardNavigationGestures(bool? allow) => (super.noSuchMethod( Invocation.method( #setAllowsBackForwardNavigationGestures, [allow], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( + _i4.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( Invocation.method( #setCustomUserAgent, [userAgent], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future evaluateJavaScript(String? javaScriptString) => + _i4.Future evaluateJavaScript(String? javaScriptString) => (super.noSuchMethod( Invocation.method( #evaluateJavaScript, [javaScriptString], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setInspectable(bool? inspectable) => (super.noSuchMethod( + _i4.Future setInspectable(bool? inspectable) => (super.noSuchMethod( Invocation.method( #setInspectable, [inspectable], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future getCustomUserAgent() => (super.noSuchMethod( + Invocation.method( + #getCustomUserAgent, + [], + ), + returnValue: _i4.Future.value(), + ) as _i4.Future); + + @override + _i2.UIViewWKWebView pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeUIViewWKWebView_8( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.UIViewWKWebView); + + @override + _i4.Future setBackgroundColor(int? value) => (super.noSuchMethod( + Invocation.method( + #setBackgroundColor, + [value], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future setOpaque(bool? opaque) => (super.noSuchMethod( + Invocation.method( + #setOpaque, + [opaque], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } /// A class which mocks [WKWebViewConfiguration]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKWebViewConfiguration extends _i1.Mock - implements _i4.WKWebViewConfiguration { + implements _i2.WKWebViewConfiguration { MockWKWebViewConfiguration() { _i1.throwOnMissingStub(this); } @override - _i4.WKUserContentController get userContentController => (super.noSuchMethod( - Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_7( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( this, - Invocation.getter(#userContentController), + Invocation.getter(#pigeon_instanceManager), ), - ) as _i4.WKUserContentController); + ) as _i2.PigeonInstanceManager); @override - _i4.WKPreferences get preferences => (super.noSuchMethod( - Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_3( + _i4.Future setUserContentController( + _i2.WKUserContentController? controller) => + (super.noSuchMethod( + Invocation.method( + #setUserContentController, + [controller], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future<_i2.WKUserContentController> getUserContentController() => + (super.noSuchMethod( + Invocation.method( + #getUserContentController, + [], + ), + returnValue: _i4.Future<_i2.WKUserContentController>.value( + _FakeWKUserContentController_9( this, - Invocation.getter(#preferences), + Invocation.method( + #getUserContentController, + [], + ), + )), + ) as _i4.Future<_i2.WKUserContentController>); + + @override + _i4.Future setWebsiteDataStore(_i2.WKWebsiteDataStore? dataStore) => + (super.noSuchMethod( + Invocation.method( + #setWebsiteDataStore, + [dataStore], ), - ) as _i4.WKPreferences); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i4.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod( - Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_8( + _i4.Future<_i2.WKWebsiteDataStore> getWebsiteDataStore() => + (super.noSuchMethod( + Invocation.method( + #getWebsiteDataStore, + [], + ), + returnValue: + _i4.Future<_i2.WKWebsiteDataStore>.value(_FakeWKWebsiteDataStore_10( this, - Invocation.getter(#websiteDataStore), + Invocation.method( + #getWebsiteDataStore, + [], + ), + )), + ) as _i4.Future<_i2.WKWebsiteDataStore>); + + @override + _i4.Future setPreferences(_i2.WKPreferences? preferences) => + (super.noSuchMethod( + Invocation.method( + #setPreferences, + [preferences], ), - ) as _i4.WKWebsiteDataStore); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future<_i2.WKPreferences> getPreferences() => (super.noSuchMethod( + Invocation.method( + #getPreferences, + [], + ), + returnValue: _i4.Future<_i2.WKPreferences>.value(_FakeWKPreferences_4( + this, + Invocation.method( + #getPreferences, + [], + ), + )), + ) as _i4.Future<_i2.WKPreferences>); @override - _i5.Future setAllowsInlineMediaPlayback(bool? allow) => + _i4.Future setAllowsInlineMediaPlayback(bool? allow) => (super.noSuchMethod( Invocation.method( #setAllowsInlineMediaPlayback, [allow], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setLimitsNavigationsToAppBoundDomains(bool? limit) => + _i4.Future setLimitsNavigationsToAppBoundDomains(bool? limit) => (super.noSuchMethod( Invocation.method( #setLimitsNavigationsToAppBoundDomains, [limit], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setMediaTypesRequiringUserActionForPlayback( - Set<_i4.WKAudiovisualMediaType>? types) => + _i4.Future setMediaTypesRequiringUserActionForPlayback( + _i2.AudiovisualMediaType? type) => (super.noSuchMethod( Invocation.method( #setMediaTypesRequiringUserActionForPlayback, - [types], + [type], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i4.WKWebViewConfiguration copy() => (super.noSuchMethod( + _i2.WKWebViewConfiguration pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebViewConfiguration_5( + returnValue: _FakeWKWebViewConfiguration_7( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKWebViewConfiguration); + ) as _i2.WKWebViewConfiguration); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } /// A class which mocks [WKWebsiteDataStore]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKWebsiteDataStore extends _i1.Mock - implements _i4.WKWebsiteDataStore { + implements _i2.WKWebsiteDataStore { MockWKWebsiteDataStore() { _i1.throwOnMissingStub(this); } @override - _i4.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod( + _i2.WKHTTPCookieStore get httpCookieStore => (super.noSuchMethod( Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_9( + returnValue: _FakeWKHTTPCookieStore_11( this, Invocation.getter(#httpCookieStore), ), - ) as _i4.WKHttpCookieStore); + ) as _i2.WKHTTPCookieStore); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i5.Future removeDataOfTypes( - Set<_i4.WKWebsiteDataType>? dataTypes, - DateTime? since, + _i2.WKHTTPCookieStore pigeonVar_httpCookieStore() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + returnValue: _FakeWKHTTPCookieStore_11( + this, + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + ), + ) as _i2.WKHTTPCookieStore); + + @override + _i4.Future removeDataOfTypes( + List<_i2.WebsiteDataType>? dataTypes, + double? modificationTimeInSecondsSinceEpoch, ) => (super.noSuchMethod( Invocation.method( #removeDataOfTypes, [ dataTypes, - since, + modificationTimeInSecondsSinceEpoch, ], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(false), + ) as _i4.Future); @override - _i4.WKWebsiteDataStore copy() => (super.noSuchMethod( + _i2.WKWebsiteDataStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebsiteDataStore_8( + returnValue: _FakeWKWebsiteDataStore_10( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKWebsiteDataStore); + ) as _i2.WKWebsiteDataStore); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } /// A class which mocks [WKUIDelegate]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKUIDelegate extends _i1.Mock implements _i4.WKUIDelegate { +class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { MockWKUIDelegate() { _i1.throwOnMissingStub(this); } @override - _i4.WKUIDelegate copy() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKUIDelegate pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKUIDelegate_10( + returnValue: _FakeWKUIDelegate_12( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKUIDelegate); + ) as _i2.WKUIDelegate); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } /// A class which mocks [WKUserContentController]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKUserContentController extends _i1.Mock - implements _i4.WKUserContentController { + implements _i2.WKUserContentController { MockWKUserContentController() { _i1.throwOnMissingStub(this); } @override - _i5.Future addScriptMessageHandler( - _i4.WKScriptMessageHandler? handler, + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future addScriptMessageHandler( + _i2.WKScriptMessageHandler? handler, String? name, ) => (super.noSuchMethod( @@ -1328,116 +1502,118 @@ class MockWKUserContentController extends _i1.Mock name, ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeScriptMessageHandler(String? name) => + _i4.Future removeScriptMessageHandler(String? name) => (super.noSuchMethod( Invocation.method( #removeScriptMessageHandler, [name], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( + _i4.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( Invocation.method( #removeAllScriptMessageHandlers, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future addUserScript(_i4.WKUserScript? userScript) => + _i4.Future addUserScript(_i2.WKUserScript? userScript) => (super.noSuchMethod( Invocation.method( #addUserScript, [userScript], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeAllUserScripts() => (super.noSuchMethod( + _i4.Future removeAllUserScripts() => (super.noSuchMethod( Invocation.method( #removeAllUserScripts, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i4.WKUserContentController copy() => (super.noSuchMethod( + _i2.WKUserContentController pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKUserContentController_7( + returnValue: _FakeWKUserContentController_9( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.WKUserContentController); + ) as _i2.WKUserContentController); @override - _i5.Future addObserver( - _i7.NSObject? observer, { - required String? keyPath, - required Set<_i7.NSKeyValueObservingOptions>? options, - }) => + _i4.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeObserver( - _i7.NSObject? observer, { - required String? keyPath, - }) => + _i4.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } /// A class which mocks [JavascriptChannelRegistry]. /// /// See the documentation for Mockito's code generation for more information. class MockJavascriptChannelRegistry extends _i1.Mock - implements _i8.JavascriptChannelRegistry { + implements _i6.JavascriptChannelRegistry { MockJavascriptChannelRegistry() { _i1.throwOnMissingStub(this); } @override - Map get channels => (super.noSuchMethod( + Map get channels => (super.noSuchMethod( Invocation.getter(#channels), - returnValue: {}, - ) as Map); + returnValue: {}, + ) as Map); @override void onJavascriptChannelMessage( @@ -1456,7 +1632,7 @@ class MockJavascriptChannelRegistry extends _i1.Mock ); @override - void updateJavascriptChannelsFromSet(Set<_i9.JavascriptChannel>? channels) => + void updateJavascriptChannelsFromSet(Set<_i7.JavascriptChannel>? channels) => super.noSuchMethod( Invocation.method( #updateJavascriptChannelsFromSet, @@ -1470,13 +1646,13 @@ class MockJavascriptChannelRegistry extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i8.WebViewPlatformCallbacksHandler { + implements _i6.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i5.FutureOr onNavigationRequest({ + _i4.FutureOr onNavigationRequest({ required String? url, required bool? isForMainFrame, }) => @@ -1489,8 +1665,8 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock #isForMainFrame: isForMainFrame, }, ), - returnValue: _i5.Future.value(false), - ) as _i5.FutureOr); + returnValue: _i4.Future.value(false), + ) as _i4.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod( @@ -1520,7 +1696,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock ); @override - void onWebResourceError(_i10.WebResourceError? error) => super.noSuchMethod( + void onWebResourceError(_i8.WebResourceError? error) => super.noSuchMethod( Invocation.method( #onWebResourceError, [error], @@ -1533,18 +1709,18 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewWidgetProxy extends _i1.Mock - implements _i11.WebViewWidgetProxy { + implements _i9.WebViewWidgetProxy { MockWebViewWidgetProxy() { _i1.throwOnMissingStub(this); } @override - _i4.WKWebView createWebView( - _i4.WKWebViewConfiguration? configuration, { + _i3.PlatformWebView createWebView( + _i2.WKWebViewConfiguration? configuration, { void Function( String, - _i7.NSObject, - Map<_i7.NSKeyValueChangeKey, Object?>, + _i2.NSObject, + Map<_i2.KeyValueChangeKey, Object?>, )? observeValue, }) => (super.noSuchMethod( @@ -1553,7 +1729,7 @@ class MockWebViewWidgetProxy extends _i1.Mock [configuration], {#observeValue: observeValue}, ), - returnValue: _FakeWKWebView_6( + returnValue: _FakePlatformWebView_13( this, Invocation.method( #createWebView, @@ -1561,13 +1737,31 @@ class MockWebViewWidgetProxy extends _i1.Mock {#observeValue: observeValue}, ), ), - ) as _i4.WKWebView); + ) as _i3.PlatformWebView); @override - _i4.WKScriptMessageHandler createScriptMessageHandler( + _i2.URLRequest createRequest({required String? url}) => (super.noSuchMethod( + Invocation.method( + #createRequest, + [], + {#url: url}, + ), + returnValue: _FakeURLRequest_2( + this, + Invocation.method( + #createRequest, + [], + {#url: url}, + ), + ), + ) as _i2.URLRequest); + + @override + _i2.WKScriptMessageHandler createScriptMessageHandler( {required void Function( - _i4.WKUserContentController, - _i4.WKScriptMessage, + _i2.WKScriptMessageHandler, + _i2.WKUserContentController, + _i2.WKScriptMessage, )? didReceiveScriptMessage}) => (super.noSuchMethod( Invocation.method( @@ -1575,7 +1769,7 @@ class MockWebViewWidgetProxy extends _i1.Mock [], {#didReceiveScriptMessage: didReceiveScriptMessage}, ), - returnValue: _FakeWKScriptMessageHandler_4( + returnValue: _FakeWKScriptMessageHandler_5( this, Invocation.method( #createScriptMessageHandler, @@ -1583,14 +1777,15 @@ class MockWebViewWidgetProxy extends _i1.Mock {#didReceiveScriptMessage: didReceiveScriptMessage}, ), ), - ) as _i4.WKScriptMessageHandler); + ) as _i2.WKScriptMessageHandler); @override - _i4.WKUIDelegate createUIDelgate( + _i2.WKUIDelegate createUIDelgate( {void Function( - _i4.WKWebView, - _i4.WKWebViewConfiguration, - _i4.WKNavigationAction, + _i2.WKUIDelegate, + _i2.WKWebView, + _i2.WKWebViewConfiguration, + _i2.WKNavigationAction, )? onCreateWebView}) => (super.noSuchMethod( Invocation.method( @@ -1598,7 +1793,7 @@ class MockWebViewWidgetProxy extends _i1.Mock [], {#onCreateWebView: onCreateWebView}, ), - returnValue: _FakeWKUIDelegate_10( + returnValue: _FakeWKUIDelegate_12( this, Invocation.method( #createUIDelgate, @@ -1606,31 +1801,49 @@ class MockWebViewWidgetProxy extends _i1.Mock {#onCreateWebView: onCreateWebView}, ), ), - ) as _i4.WKUIDelegate); + ) as _i2.WKUIDelegate); @override - _i4.WKNavigationDelegate createNavigationDelegate({ + _i2.WKNavigationDelegate createNavigationDelegate({ void Function( - _i4.WKWebView, + _i2.WKNavigationDelegate, + _i2.WKWebView, String?, )? didFinishNavigation, void Function( - _i4.WKWebView, + _i2.WKNavigationDelegate, + _i2.WKWebView, String?, )? didStartProvisionalNavigation, - _i5.Future<_i4.WKNavigationActionPolicy> Function( - _i4.WKWebView, - _i4.WKNavigationAction, + required _i4.Future<_i2.NavigationActionPolicy> Function( + _i2.WKNavigationDelegate, + _i2.WKWebView, + _i2.WKNavigationAction, )? decidePolicyForNavigationAction, void Function( - _i4.WKWebView, - _i7.NSError, + _i2.WKNavigationDelegate, + _i2.WKWebView, + _i2.NSError, )? didFailNavigation, void Function( - _i4.WKWebView, - _i7.NSError, + _i2.WKNavigationDelegate, + _i2.WKWebView, + _i2.NSError, )? didFailProvisionalNavigation, - void Function(_i4.WKWebView)? webViewWebContentProcessDidTerminate, + void Function( + _i2.WKNavigationDelegate, + _i2.WKWebView, + )? webViewWebContentProcessDidTerminate, + required _i4.Future<_i2.NavigationResponsePolicy> Function( + _i2.WKNavigationDelegate, + _i2.WKWebView, + _i2.WKNavigationResponse, + )? decidePolicyForNavigationResponse, + required _i4.Future<_i2.AuthenticationChallengeResponse> Function( + _i2.WKNavigationDelegate, + _i2.WKWebView, + _i2.URLAuthenticationChallenge, + )? didReceiveAuthenticationChallenge, }) => (super.noSuchMethod( Invocation.method( @@ -1644,9 +1857,13 @@ class MockWebViewWidgetProxy extends _i1.Mock #didFailProvisionalNavigation: didFailProvisionalNavigation, #webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate, + #decidePolicyForNavigationResponse: + decidePolicyForNavigationResponse, + #didReceiveAuthenticationChallenge: + didReceiveAuthenticationChallenge, }, ), - returnValue: _FakeWKNavigationDelegate_2( + returnValue: _FakeWKNavigationDelegate_3( this, Invocation.method( #createNavigationDelegate, @@ -1659,8 +1876,12 @@ class MockWebViewWidgetProxy extends _i1.Mock #didFailProvisionalNavigation: didFailProvisionalNavigation, #webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate, + #decidePolicyForNavigationResponse: + decidePolicyForNavigationResponse, + #didReceiveAuthenticationChallenge: + didReceiveAuthenticationChallenge, }, ), ), - ) as _i4.WKNavigationDelegate); + ) as _i2.WKNavigationDelegate); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/instance_manager_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/instance_manager_test.dart deleted file mode 100644 index 2fc68a489b6a..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/instance_manager_test.dart +++ /dev/null @@ -1,153 +0,0 @@ -// 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. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; - -void main() { - group('InstanceManager', () { - test('addHostCreatedInstance', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.getIdentifier(object), 0); - expect( - instanceManager.getInstanceWithWeakReference(0), - object, - ); - }); - - test('addHostCreatedInstance prevents already used objects and ids', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect( - () => instanceManager.addHostCreatedInstance(object, 0), - throwsAssertionError, - ); - - expect( - () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), - throwsAssertionError, - ); - }); - - test('addFlutterCreatedInstance', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addDartCreatedInstance(object); - - final int? instanceId = instanceManager.getIdentifier(object); - expect(instanceId, isNotNull); - expect( - instanceManager.getInstanceWithWeakReference(instanceId!), - object, - ); - }); - - test('removeWeakReference', () { - final CopyableObject object = CopyableObject(); - - int? weakInstanceId; - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (int instanceId) { - weakInstanceId = instanceId; - }); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.removeWeakReference(object), 0); - expect( - instanceManager.getInstanceWithWeakReference(0), - isA(), - ); - expect(weakInstanceId, 0); - }); - - test('removeWeakReference removes only weak reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.removeWeakReference(object), 0); - final CopyableObject copy = instanceManager.getInstanceWithWeakReference( - 0, - )!; - expect(identical(object, copy), isFalse); - }); - - test('removeStrongReference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - instanceManager.removeWeakReference(object); - expect(instanceManager.remove(0), isA()); - expect(instanceManager.containsIdentifier(0), isFalse); - }); - - test('removeStrongReference removes only strong reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - expect(instanceManager.remove(0), isA()); - expect( - instanceManager.getInstanceWithWeakReference(0), - object, - ); - }); - - test('getInstance can add a new weak reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - instanceManager.removeWeakReference(object); - - final CopyableObject newWeakCopy = - instanceManager.getInstanceWithWeakReference( - 0, - )!; - expect(identical(object, newWeakCopy), isFalse); - }); - }); -} - -class CopyableObject with Copyable { - @override - Copyable copy() { - return CopyableObject(); - } - - @override - int get hashCode { - return 0; - } - - @override - bool operator ==(Object other) { - return other is CopyableObject; - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.g.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.g.dart deleted file mode 100644 index 0a9e645fecd0..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/common/test_web_kit.g.dart +++ /dev/null @@ -1,2500 +0,0 @@ -// 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 (v18.0.0), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; - -class _TestWKWebsiteDataStoreHostApiCodec extends StandardMessageCodec { - const _TestWKWebsiteDataStoreHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKWebsiteDataTypeEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKWebsiteDataStore. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebsitedatastore?language=objc. -abstract class TestWKWebsiteDataStoreHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestWKWebsiteDataStoreHostApiCodec(); - - void createFromWebViewConfiguration( - int identifier, int configurationIdentifier); - - void createDefaultDataStore(int identifier); - - Future removeDataOfTypes( - int identifier, - List dataTypes, - double modificationTimeInSecondsSinceEpoch); - - static void setUp( - TestWKWebsiteDataStoreHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createFromWebViewConfiguration$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createFromWebViewConfiguration was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - final int? arg_configurationIdentifier = (args[1] as int?); - assert(arg_configurationIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - try { - api.createFromWebViewConfiguration( - arg_identifier!, arg_configurationIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createDefaultDataStore$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createDefaultDataStore was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.createDefaultDataStore was null, expected non-null int.'); - try { - api.createDefaultDataStore(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes was null, expected non-null int.'); - final List? arg_dataTypes = - (args[1] as List?)?.cast(); - assert(arg_dataTypes != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes was null, expected non-null List.'); - final double? arg_modificationTimeInSecondsSinceEpoch = - (args[2] as double?); - assert(arg_modificationTimeInSecondsSinceEpoch != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebsiteDataStoreHostApi.removeDataOfTypes was null, expected non-null double.'); - try { - final bool output = await api.removeDataOfTypes(arg_identifier!, - arg_dataTypes!, arg_modificationTimeInSecondsSinceEpoch!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of UIView. -/// -/// See https://developer.apple.com/documentation/uikit/uiview?language=objc. -abstract class TestUIViewHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void setBackgroundColor(int identifier, int? value); - - void setOpaque(int identifier, bool opaque); - - static void setUp( - TestUIViewHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setBackgroundColor$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setBackgroundColor was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setBackgroundColor was null, expected non-null int.'); - final int? arg_value = (args[1] as int?); - try { - api.setBackgroundColor(arg_identifier!, arg_value); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setOpaque$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setOpaque was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setOpaque was null, expected non-null int.'); - final bool? arg_opaque = (args[1] as bool?); - assert(arg_opaque != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIViewHostApi.setOpaque was null, expected non-null bool.'); - try { - api.setOpaque(arg_identifier!, arg_opaque!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of UIScrollView. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollview?language=objc. -abstract class TestUIScrollViewHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void createFromWebView(int identifier, int webViewIdentifier); - - List getContentOffset(int identifier); - - void scrollBy(int identifier, double x, double y); - - void setContentOffset(int identifier, double x, double y); - - void setDelegate(int identifier, int? uiScrollViewDelegateIdentifier); - - static void setUp( - TestUIScrollViewHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.createFromWebView$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.createFromWebView was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.createFromWebView was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.createFromWebView was null, expected non-null int.'); - try { - api.createFromWebView(arg_identifier!, arg_webViewIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.getContentOffset$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.getContentOffset was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.getContentOffset was null, expected non-null int.'); - try { - final List output = api.getContentOffset(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy was null, expected non-null int.'); - final double? arg_x = (args[1] as double?); - assert(arg_x != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy was null, expected non-null double.'); - final double? arg_y = (args[2] as double?); - assert(arg_y != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.scrollBy was null, expected non-null double.'); - try { - api.scrollBy(arg_identifier!, arg_x!, arg_y!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset was null, expected non-null int.'); - final double? arg_x = (args[1] as double?); - assert(arg_x != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset was null, expected non-null double.'); - final double? arg_y = (args[2] as double?); - assert(arg_y != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setContentOffset was null, expected non-null double.'); - try { - api.setContentOffset(arg_identifier!, arg_x!, arg_y!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setDelegate$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setDelegate was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewHostApi.setDelegate was null, expected non-null int.'); - final int? arg_uiScrollViewDelegateIdentifier = (args[1] as int?); - try { - api.setDelegate( - arg_identifier!, arg_uiScrollViewDelegateIdentifier); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -class _TestWKWebViewConfigurationHostApiCodec extends StandardMessageCodec { - const _TestWKWebViewConfigurationHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKAudiovisualMediaTypeEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKWebViewConfiguration. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebviewconfiguration?language=objc. -abstract class TestWKWebViewConfigurationHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestWKWebViewConfigurationHostApiCodec(); - - void create(int identifier); - - void createFromWebView(int identifier, int webViewIdentifier); - - void setAllowsInlineMediaPlayback(int identifier, bool allow); - - void setLimitsNavigationsToAppBoundDomains(int identifier, bool limit); - - void setMediaTypesRequiringUserActionForPlayback( - int identifier, List types); - - static void setUp( - TestWKWebViewConfigurationHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.createFromWebView$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.createFromWebView was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.createFromWebView was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.createFromWebView was null, expected non-null int.'); - try { - api.createFromWebView(arg_identifier!, arg_webViewIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback was null, expected non-null int.'); - final bool? arg_allow = (args[1] as bool?); - assert(arg_allow != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setAllowsInlineMediaPlayback was null, expected non-null bool.'); - try { - api.setAllowsInlineMediaPlayback(arg_identifier!, arg_allow!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setLimitsNavigationsToAppBoundDomains$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setLimitsNavigationsToAppBoundDomains was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setLimitsNavigationsToAppBoundDomains was null, expected non-null int.'); - final bool? arg_limit = (args[1] as bool?); - assert(arg_limit != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setLimitsNavigationsToAppBoundDomains was null, expected non-null bool.'); - try { - api.setLimitsNavigationsToAppBoundDomains( - arg_identifier!, arg_limit!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setMediaTypesRequiringUserActionForPlayback$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setMediaTypesRequiringUserActionForPlayback was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setMediaTypesRequiringUserActionForPlayback was null, expected non-null int.'); - final List? arg_types = - (args[1] as List?) - ?.cast(); - assert(arg_types != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewConfigurationHostApi.setMediaTypesRequiringUserActionForPlayback was null, expected non-null List.'); - try { - api.setMediaTypesRequiringUserActionForPlayback( - arg_identifier!, arg_types!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -class _TestWKUserContentControllerHostApiCodec extends StandardMessageCodec { - const _TestWKUserContentControllerHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WKUserScriptData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WKUserScriptData.decode(readValue(buffer)!); - case 129: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKUserContentController. -/// -/// See https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc. -abstract class TestWKUserContentControllerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestWKUserContentControllerHostApiCodec(); - - void createFromWebViewConfiguration( - int identifier, int configurationIdentifier); - - void addScriptMessageHandler( - int identifier, int handlerIdentifier, String name); - - void removeScriptMessageHandler(int identifier, String name); - - void removeAllScriptMessageHandlers(int identifier); - - void addUserScript(int identifier, WKUserScriptData userScript); - - void removeAllUserScripts(int identifier); - - static void setUp( - TestWKUserContentControllerHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.createFromWebViewConfiguration$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.createFromWebViewConfiguration was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - final int? arg_configurationIdentifier = (args[1] as int?); - assert(arg_configurationIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - try { - api.createFromWebViewConfiguration( - arg_identifier!, arg_configurationIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler was null, expected non-null int.'); - final int? arg_handlerIdentifier = (args[1] as int?); - assert(arg_handlerIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler was null, expected non-null int.'); - final String? arg_name = (args[2] as String?); - assert(arg_name != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addScriptMessageHandler was null, expected non-null String.'); - try { - api.addScriptMessageHandler( - arg_identifier!, arg_handlerIdentifier!, arg_name!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeScriptMessageHandler$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeScriptMessageHandler was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeScriptMessageHandler was null, expected non-null int.'); - final String? arg_name = (args[1] as String?); - assert(arg_name != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeScriptMessageHandler was null, expected non-null String.'); - try { - api.removeScriptMessageHandler(arg_identifier!, arg_name!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllScriptMessageHandlers$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllScriptMessageHandlers was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllScriptMessageHandlers was null, expected non-null int.'); - try { - api.removeAllScriptMessageHandlers(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addUserScript$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addUserScript was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addUserScript was null, expected non-null int.'); - final WKUserScriptData? arg_userScript = - (args[1] as WKUserScriptData?); - assert(arg_userScript != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.addUserScript was null, expected non-null WKUserScriptData.'); - try { - api.addUserScript(arg_identifier!, arg_userScript!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllUserScripts$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllUserScripts was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUserContentControllerHostApi.removeAllUserScripts was null, expected non-null int.'); - try { - api.removeAllUserScripts(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of WKUserPreferences. -/// -/// See https://developer.apple.com/documentation/webkit/wkpreferences?language=objc. -abstract class TestWKPreferencesHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void createFromWebViewConfiguration( - int identifier, int configurationIdentifier); - - void setJavaScriptEnabled(int identifier, bool enabled); - - static void setUp( - TestWKPreferencesHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.createFromWebViewConfiguration$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.createFromWebViewConfiguration was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - final int? arg_configurationIdentifier = (args[1] as int?); - assert(arg_configurationIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.createFromWebViewConfiguration was null, expected non-null int.'); - try { - api.createFromWebViewConfiguration( - arg_identifier!, arg_configurationIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.setJavaScriptEnabled$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.setJavaScriptEnabled was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.setJavaScriptEnabled was null, expected non-null int.'); - final bool? arg_enabled = (args[1] as bool?); - assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKPreferencesHostApi.setJavaScriptEnabled was null, expected non-null bool.'); - try { - api.setJavaScriptEnabled(arg_identifier!, arg_enabled!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of WKScriptMessageHandler. -/// -/// See https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?language=objc. -abstract class TestWKScriptMessageHandlerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); - - static void setUp( - TestWKScriptMessageHandlerHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKScriptMessageHandlerHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of WKNavigationDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wknavigationdelegate?language=objc. -abstract class TestWKNavigationDelegateHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); - - static void setUp( - TestWKNavigationDelegateHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKNavigationDelegateHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -class _TestNSObjectHostApiCodec extends StandardMessageCodec { - const _TestNSObjectHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSKeyValueObservingOptionsEnumData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of NSObject. -/// -/// See https://developer.apple.com/documentation/objectivec/nsobject. -abstract class TestNSObjectHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestNSObjectHostApiCodec(); - - void dispose(int identifier); - - void addObserver(int identifier, int observerIdentifier, String keyPath, - List options); - - void removeObserver(int identifier, int observerIdentifier, String keyPath); - - static void setUp( - TestNSObjectHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.dispose$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.dispose was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.dispose was null, expected non-null int.'); - try { - api.dispose(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver was null, expected non-null int.'); - final int? arg_observerIdentifier = (args[1] as int?); - assert(arg_observerIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver was null, expected non-null int.'); - final String? arg_keyPath = (args[2] as String?); - assert(arg_keyPath != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver was null, expected non-null String.'); - final List? arg_options = - (args[3] as List?) - ?.cast(); - assert(arg_options != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.addObserver was null, expected non-null List.'); - try { - api.addObserver(arg_identifier!, arg_observerIdentifier!, - arg_keyPath!, arg_options!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver was null, expected non-null int.'); - final int? arg_observerIdentifier = (args[1] as int?); - assert(arg_observerIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver was null, expected non-null int.'); - final String? arg_keyPath = (args[2] as String?); - assert(arg_keyPath != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSObjectHostApi.removeObserver was null, expected non-null String.'); - try { - api.removeObserver( - arg_identifier!, arg_observerIdentifier!, arg_keyPath!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -class _TestWKWebViewHostApiCodec extends StandardMessageCodec { - const _TestWKWebViewHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is AuthenticationChallengeResponse) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NSErrorData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookieData) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { - buffer.putUint8(131); - writeValue(buffer, value.encode()); - } else if (value is NSHttpUrlResponseData) { - buffer.putUint8(132); - writeValue(buffer, value.encode()); - } else if (value is NSKeyValueChangeKeyEnumData) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else if (value is NSKeyValueObservingOptionsEnumData) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is NSUrlRequestData) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else if (value is ObjectOrIdentifier) { - buffer.putUint8(136); - writeValue(buffer, value.encode()); - } else if (value is WKAudiovisualMediaTypeEnumData) { - buffer.putUint8(137); - writeValue(buffer, value.encode()); - } else if (value is WKFrameInfoData) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); - } else if (value is WKMediaCaptureTypeData) { - buffer.putUint8(139); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionData) { - buffer.putUint8(140); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationActionPolicyEnumData) { - buffer.putUint8(141); - writeValue(buffer, value.encode()); - } else if (value is WKNavigationResponseData) { - buffer.putUint8(142); - writeValue(buffer, value.encode()); - } else if (value is WKPermissionDecisionData) { - buffer.putUint8(143); - writeValue(buffer, value.encode()); - } else if (value is WKScriptMessageData) { - buffer.putUint8(144); - writeValue(buffer, value.encode()); - } else if (value is WKSecurityOriginData) { - buffer.putUint8(145); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptData) { - buffer.putUint8(146); - writeValue(buffer, value.encode()); - } else if (value is WKUserScriptInjectionTimeEnumData) { - buffer.putUint8(147); - writeValue(buffer, value.encode()); - } else if (value is WKWebsiteDataTypeEnumData) { - buffer.putUint8(148); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return AuthenticationChallengeResponse.decode(readValue(buffer)!); - case 129: - return NSErrorData.decode(readValue(buffer)!); - case 130: - return NSHttpCookieData.decode(readValue(buffer)!); - case 131: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); - case 132: - return NSHttpUrlResponseData.decode(readValue(buffer)!); - case 133: - return NSKeyValueChangeKeyEnumData.decode(readValue(buffer)!); - case 134: - return NSKeyValueObservingOptionsEnumData.decode(readValue(buffer)!); - case 135: - return NSUrlRequestData.decode(readValue(buffer)!); - case 136: - return ObjectOrIdentifier.decode(readValue(buffer)!); - case 137: - return WKAudiovisualMediaTypeEnumData.decode(readValue(buffer)!); - case 138: - return WKFrameInfoData.decode(readValue(buffer)!); - case 139: - return WKMediaCaptureTypeData.decode(readValue(buffer)!); - case 140: - return WKNavigationActionData.decode(readValue(buffer)!); - case 141: - return WKNavigationActionPolicyEnumData.decode(readValue(buffer)!); - case 142: - return WKNavigationResponseData.decode(readValue(buffer)!); - case 143: - return WKPermissionDecisionData.decode(readValue(buffer)!); - case 144: - return WKScriptMessageData.decode(readValue(buffer)!); - case 145: - return WKSecurityOriginData.decode(readValue(buffer)!); - case 146: - return WKUserScriptData.decode(readValue(buffer)!); - case 147: - return WKUserScriptInjectionTimeEnumData.decode(readValue(buffer)!); - case 148: - return WKWebsiteDataTypeEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKWebView. -/// -/// See https://developer.apple.com/documentation/webkit/wkwebview?language=objc. -abstract class TestWKWebViewHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestWKWebViewHostApiCodec(); - - void create(int identifier, int configurationIdentifier); - - void setUIDelegate(int identifier, int? uiDelegateIdentifier); - - void setNavigationDelegate(int identifier, int? navigationDelegateIdentifier); - - String? getUrl(int identifier); - - double getEstimatedProgress(int identifier); - - void loadRequest(int identifier, NSUrlRequestData request); - - void loadHtmlString(int identifier, String string, String? baseUrl); - - void loadFileUrl(int identifier, String url, String readAccessUrl); - - void loadFlutterAsset(int identifier, String key); - - bool canGoBack(int identifier); - - bool canGoForward(int identifier); - - void goBack(int identifier); - - void goForward(int identifier); - - void reload(int identifier); - - String? getTitle(int identifier); - - void setAllowsBackForwardNavigationGestures(int identifier, bool allow); - - void setCustomUserAgent(int identifier, String? userAgent); - - Future evaluateJavaScript(int identifier, String javaScriptString); - - void setInspectable(int identifier, bool inspectable); - - String? getCustomUserAgent(int identifier); - - static void setUp( - TestWKWebViewHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.create was null, expected non-null int.'); - final int? arg_configurationIdentifier = (args[1] as int?); - assert(arg_configurationIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!, arg_configurationIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setUIDelegate$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setUIDelegate was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setUIDelegate was null, expected non-null int.'); - final int? arg_uiDelegateIdentifier = (args[1] as int?); - try { - api.setUIDelegate(arg_identifier!, arg_uiDelegateIdentifier); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setNavigationDelegate$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setNavigationDelegate was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setNavigationDelegate was null, expected non-null int.'); - final int? arg_navigationDelegateIdentifier = (args[1] as int?); - try { - api.setNavigationDelegate( - arg_identifier!, arg_navigationDelegateIdentifier); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getUrl$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getUrl was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getUrl was null, expected non-null int.'); - try { - final String? output = api.getUrl(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getEstimatedProgress$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getEstimatedProgress was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getEstimatedProgress was null, expected non-null int.'); - try { - final double output = api.getEstimatedProgress(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadRequest$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadRequest was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadRequest was null, expected non-null int.'); - final NSUrlRequestData? arg_request = (args[1] as NSUrlRequestData?); - assert(arg_request != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadRequest was null, expected non-null NSUrlRequestData.'); - try { - api.loadRequest(arg_identifier!, arg_request!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadHtmlString$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadHtmlString was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadHtmlString was null, expected non-null int.'); - final String? arg_string = (args[1] as String?); - assert(arg_string != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadHtmlString was null, expected non-null String.'); - final String? arg_baseUrl = (args[2] as String?); - try { - api.loadHtmlString(arg_identifier!, arg_string!, arg_baseUrl); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl was null, expected non-null String.'); - final String? arg_readAccessUrl = (args[2] as String?); - assert(arg_readAccessUrl != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFileUrl was null, expected non-null String.'); - try { - api.loadFileUrl(arg_identifier!, arg_url!, arg_readAccessUrl!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFlutterAsset$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFlutterAsset was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFlutterAsset was null, expected non-null int.'); - final String? arg_key = (args[1] as String?); - assert(arg_key != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.loadFlutterAsset was null, expected non-null String.'); - try { - api.loadFlutterAsset(arg_identifier!, arg_key!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoBack$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoBack was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoBack was null, expected non-null int.'); - try { - final bool output = api.canGoBack(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoForward$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoForward was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.canGoForward was null, expected non-null int.'); - try { - final bool output = api.canGoForward(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goBack$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goBack was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goBack was null, expected non-null int.'); - try { - api.goBack(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goForward$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goForward was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.goForward was null, expected non-null int.'); - try { - api.goForward(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.reload$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.reload was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.reload was null, expected non-null int.'); - try { - api.reload(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getTitle$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getTitle was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getTitle was null, expected non-null int.'); - try { - final String? output = api.getTitle(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setAllowsBackForwardNavigationGestures$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setAllowsBackForwardNavigationGestures was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setAllowsBackForwardNavigationGestures was null, expected non-null int.'); - final bool? arg_allow = (args[1] as bool?); - assert(arg_allow != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setAllowsBackForwardNavigationGestures was null, expected non-null bool.'); - try { - api.setAllowsBackForwardNavigationGestures( - arg_identifier!, arg_allow!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setCustomUserAgent$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setCustomUserAgent was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setCustomUserAgent was null, expected non-null int.'); - final String? arg_userAgent = (args[1] as String?); - try { - api.setCustomUserAgent(arg_identifier!, arg_userAgent); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.evaluateJavaScript$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.evaluateJavaScript was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.evaluateJavaScript was null, expected non-null int.'); - final String? arg_javaScriptString = (args[1] as String?); - assert(arg_javaScriptString != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.evaluateJavaScript was null, expected non-null String.'); - try { - final Object? output = await api.evaluateJavaScript( - arg_identifier!, arg_javaScriptString!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setInspectable$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setInspectable was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setInspectable was null, expected non-null int.'); - final bool? arg_inspectable = (args[1] as bool?); - assert(arg_inspectable != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.setInspectable was null, expected non-null bool.'); - try { - api.setInspectable(arg_identifier!, arg_inspectable!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getCustomUserAgent$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getCustomUserAgent was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKWebViewHostApi.getCustomUserAgent was null, expected non-null int.'); - try { - final String? output = api.getCustomUserAgent(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Mirror of WKUIDelegate. -/// -/// See https://developer.apple.com/documentation/webkit/wkuidelegate?language=objc. -abstract class TestWKUIDelegateHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); - - static void setUp( - TestWKUIDelegateHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKUIDelegateHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -class _TestWKHttpCookieStoreHostApiCodec extends StandardMessageCodec { - const _TestWKHttpCookieStoreHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NSHttpCookieData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NSHttpCookiePropertyKeyEnumData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NSHttpCookieData.decode(readValue(buffer)!); - case 129: - return NSHttpCookiePropertyKeyEnumData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -/// Mirror of WKHttpCookieStore. -/// -/// See https://developer.apple.com/documentation/webkit/wkhttpcookiestore?language=objc. -abstract class TestWKHttpCookieStoreHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestWKHttpCookieStoreHostApiCodec(); - - void createFromWebsiteDataStore( - int identifier, int websiteDataStoreIdentifier); - - Future setCookie(int identifier, NSHttpCookieData cookie); - - static void setUp( - TestWKHttpCookieStoreHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.createFromWebsiteDataStore$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.createFromWebsiteDataStore was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.createFromWebsiteDataStore was null, expected non-null int.'); - final int? arg_websiteDataStoreIdentifier = (args[1] as int?); - assert(arg_websiteDataStoreIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.createFromWebsiteDataStore was null, expected non-null int.'); - try { - api.createFromWebsiteDataStore( - arg_identifier!, arg_websiteDataStoreIdentifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.setCookie$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.setCookie was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.setCookie was null, expected non-null int.'); - final NSHttpCookieData? arg_cookie = (args[1] as NSHttpCookieData?); - assert(arg_cookie != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.WKHttpCookieStoreHostApi.setCookie was null, expected non-null NSHttpCookieData.'); - try { - await api.setCookie(arg_identifier!, arg_cookie!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Host API for `NSUrl`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurl?language=objc. -abstract class TestNSUrlHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - String? getAbsoluteString(int identifier); - - static void setUp( - TestNSUrlHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlHostApi.getAbsoluteString$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlHostApi.getAbsoluteString was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlHostApi.getAbsoluteString was null, expected non-null int.'); - try { - final String? output = api.getAbsoluteString(arg_identifier!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Host API for `UIScrollViewDelegate`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or method calls on the associated native -/// class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/uikit/uiscrollviewdelegate?language=objc. -abstract class TestUIScrollViewDelegateHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - void create(int identifier); - - static void setUp( - TestUIScrollViewDelegateHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateHostApi.create$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.UIScrollViewDelegateHostApi.create was null, expected non-null int.'); - try { - api.create(arg_identifier!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} - -/// Host API for `NSUrlCredential`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc. -abstract class TestNSUrlCredentialHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - StandardMessageCodec(); - - /// Create a new native instance and add it to the `InstanceManager`. - void createWithUser(int identifier, String user, String password, - NSUrlCredentialPersistence persistence); - - static void setUp( - TestNSUrlCredentialHostApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = - messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser was null, expected non-null int.'); - final String? arg_user = (args[1] as String?); - assert(arg_user != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser was null, expected non-null String.'); - final String? arg_password = (args[2] as String?); - assert(arg_password != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser was null, expected non-null String.'); - final NSUrlCredentialPersistence? arg_persistence = args[3] == null - ? null - : NSUrlCredentialPersistence.values[args[3]! as int]; - assert(arg_persistence != null, - 'Argument for dev.flutter.pigeon.webview_flutter_wkwebview.NSUrlCredentialHostApi.createWithUser was null, expected non-null NSUrlCredentialPersistence.'); - try { - api.createWithUser( - arg_identifier!, arg_user!, arg_password!, arg_persistence!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); - } - }); - } - } - } -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart deleted file mode 100644 index 5eb821fdfcbc..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart +++ /dev/null @@ -1,389 +0,0 @@ -// 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. - -import 'dart:async'; - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation_api_impls.dart'; - -import '../common/test_web_kit.g.dart'; -import 'foundation_test.mocks.dart'; - -@GenerateMocks([ - TestNSObjectHostApi, - TestNSUrlCredentialHostApi, - TestNSUrlHostApi, -]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('Foundation', () { - late InstanceManager instanceManager; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - }); - - group('NSObject', () { - late MockTestNSObjectHostApi mockPlatformHostApi; - - late NSObject object; - - setUp(() { - mockPlatformHostApi = MockTestNSObjectHostApi(); - TestNSObjectHostApi.setUp(mockPlatformHostApi); - - object = NSObject.detached(instanceManager: instanceManager); - instanceManager.addDartCreatedInstance(object); - }); - - tearDown(() { - TestNSObjectHostApi.setUp(null); - }); - - test('addObserver', () async { - final NSObject observer = NSObject.detached( - instanceManager: instanceManager, - ); - instanceManager.addDartCreatedInstance(observer); - - await object.addObserver( - observer, - keyPath: 'aKeyPath', - options: { - NSKeyValueObservingOptions.initialValue, - NSKeyValueObservingOptions.priorNotification, - }, - ); - - final List optionsData = - verify(mockPlatformHostApi.addObserver( - instanceManager.getIdentifier(object), - instanceManager.getIdentifier(observer), - 'aKeyPath', - captureAny, - )).captured.single as List; - - expect(optionsData, hasLength(2)); - expect( - optionsData[0]!.value, - NSKeyValueObservingOptionsEnum.initialValue, - ); - expect( - optionsData[1]!.value, - NSKeyValueObservingOptionsEnum.priorNotification, - ); - }); - - test('removeObserver', () async { - final NSObject observer = NSObject.detached( - instanceManager: instanceManager, - ); - instanceManager.addDartCreatedInstance(observer); - - await object.removeObserver(observer, keyPath: 'aKeyPath'); - - verify(mockPlatformHostApi.removeObserver( - instanceManager.getIdentifier(object), - instanceManager.getIdentifier(observer), - 'aKeyPath', - )); - }); - - test('NSObjectHostApi.dispose', () async { - int? callbackIdentifier; - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (int identifier) { - callbackIdentifier = identifier; - }); - - final NSObject object = NSObject.detached( - instanceManager: instanceManager, - ); - final int identifier = instanceManager.addDartCreatedInstance(object); - - NSObject.dispose(object); - expect(callbackIdentifier, identifier); - }); - - test('observeValue', () async { - final Completer> argsCompleter = - Completer>(); - - FoundationFlutterApis.instance = FoundationFlutterApis( - instanceManager: instanceManager, - ); - - object = NSObject.detached( - instanceManager: instanceManager, - observeValue: ( - String keyPath, - NSObject object, - Map change, - ) { - argsCompleter.complete([keyPath, object, change]); - }, - ); - instanceManager.addHostCreatedInstance(object, 1); - - FoundationFlutterApis.instance.object.observeValue( - 1, - 'keyPath', - 1, - [ - NSKeyValueChangeKeyEnumData(value: NSKeyValueChangeKeyEnum.oldValue) - ], - [ - ObjectOrIdentifier(isIdentifier: false, value: 'value'), - ], - ); - - expect( - argsCompleter.future, - completion([ - 'keyPath', - object, - { - NSKeyValueChangeKey.oldValue: 'value', - }, - ]), - ); - }); - - test('observeValue returns object in an `InstanceManager`', () async { - final Completer> argsCompleter = - Completer>(); - - FoundationFlutterApis.instance = FoundationFlutterApis( - instanceManager: instanceManager, - ); - - object = NSObject.detached( - instanceManager: instanceManager, - observeValue: ( - String keyPath, - NSObject object, - Map change, - ) { - argsCompleter.complete([keyPath, object, change]); - }, - ); - instanceManager.addHostCreatedInstance(object, 1); - - final NSObject returnedObject = NSObject.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(returnedObject, 2); - - FoundationFlutterApis.instance.object.observeValue( - 1, - 'keyPath', - 1, - [ - NSKeyValueChangeKeyEnumData(value: NSKeyValueChangeKeyEnum.oldValue) - ], - [ - ObjectOrIdentifier(isIdentifier: true, value: 2), - ], - ); - - expect( - argsCompleter.future, - completion([ - 'keyPath', - object, - { - NSKeyValueChangeKey.oldValue: returnedObject, - }, - ]), - ); - }); - - test('NSObjectFlutterApi.dispose', () { - FoundationFlutterApis.instance = FoundationFlutterApis( - instanceManager: instanceManager, - ); - - object = NSObject.detached(instanceManager: instanceManager); - instanceManager.addHostCreatedInstance(object, 1); - - instanceManager.removeWeakReference(object); - FoundationFlutterApis.instance.object.dispose(1); - - expect(instanceManager.containsIdentifier(1), isFalse); - }); - }); - - group('NSUrl', () { - // Ensure the test host api is removed after each test run. - tearDown(() => TestNSUrlHostApi.setUp(null)); - - test('getAbsoluteString', () async { - final MockTestNSUrlHostApi mockApi = MockTestNSUrlHostApi(); - TestNSUrlHostApi.setUp(mockApi); - - final NSUrl url = NSUrl.detached(instanceManager: instanceManager); - instanceManager.addHostCreatedInstance(url, 0); - - when(mockApi.getAbsoluteString(0)).thenReturn('myString'); - - expect(await url.getAbsoluteString(), 'myString'); - }); - - test('Flutter API create', () { - final NSUrlFlutterApi flutterApi = NSUrlFlutterApiImpl( - instanceManager: instanceManager, - ); - - flutterApi.create(0); - - expect(instanceManager.getInstanceWithWeakReference(0), isA()); - }); - }); - - group('NSUrlCredential', () { - tearDown(() { - TestNSUrlCredentialHostApi.setUp(null); - }); - - test('HostApi createWithUser', () { - final MockTestNSUrlCredentialHostApi mockApi = - MockTestNSUrlCredentialHostApi(); - TestNSUrlCredentialHostApi.setUp(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const String user = 'testString'; - const String password = 'testString2'; - - const NSUrlCredentialPersistence persistence = - NSUrlCredentialPersistence.permanent; - - final NSUrlCredential instance = NSUrlCredential.withUser( - user: user, - password: password, - persistence: persistence, - instanceManager: instanceManager, - ); - - verify(mockApi.createWithUser( - instanceManager.getIdentifier(instance), - user, - password, - persistence, - )); - }); - }); - - group('NSUrlProtectionSpace', () { - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final NSUrlProtectionSpaceFlutterApiImpl api = - NSUrlProtectionSpaceFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - - api.create( - instanceIdentifier, - 'testString', - 'testString', - 'testAuthenticationMethod', - ); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - }); - - group('NSUrlAuthenticationChallenge', () { - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final NSUrlAuthenticationChallengeFlutterApiImpl api = - NSUrlAuthenticationChallengeFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - - const int protectionSpaceIdentifier = 1; - instanceManager.addHostCreatedInstance( - NSUrlProtectionSpace.detached( - host: null, - realm: null, - authenticationMethod: null, - instanceManager: instanceManager, - ), - protectionSpaceIdentifier, - ); - - api.create(instanceIdentifier, protectionSpaceIdentifier); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - }); - }); - - test('NSError', () { - expect( - const NSError( - code: 0, - domain: 'domain', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: 'desc', - }, - ).toString(), - 'desc (domain:0:{NSLocalizedDescription: desc})', - ); - expect( - const NSError( - code: 0, - domain: 'domain', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: '', - }, - ).toString(), - 'Error domain:0:{NSLocalizedDescription: }', - ); - expect( - const NSError( - code: 255, - domain: 'bar', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: 'baz', - }, - ).toString(), - 'baz (bar:255:{NSLocalizedDescription: baz})', - ); - expect( - const NSError( - code: 255, - domain: 'bar', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: '', - }, - ).toString(), - 'Error bar:255:{NSLocalizedDescription: }', - ); - }); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart deleted file mode 100644 index df4e12e6082f..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart +++ /dev/null @@ -1,125 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_wkwebview/test/src/foundation/foundation_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i3; - -import '../common/test_web_kit.g.dart' as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -/// A class which mocks [TestNSObjectHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestNSObjectHostApi extends _i1.Mock - implements _i2.TestNSObjectHostApi { - MockTestNSObjectHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void dispose(int? identifier) => super.noSuchMethod( - Invocation.method( - #dispose, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void addObserver( - int? identifier, - int? observerIdentifier, - String? keyPath, - List<_i3.NSKeyValueObservingOptionsEnumData?>? options, - ) => - super.noSuchMethod( - Invocation.method( - #addObserver, - [ - identifier, - observerIdentifier, - keyPath, - options, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeObserver( - int? identifier, - int? observerIdentifier, - String? keyPath, - ) => - super.noSuchMethod( - Invocation.method( - #removeObserver, - [ - identifier, - observerIdentifier, - keyPath, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestNSUrlCredentialHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestNSUrlCredentialHostApi extends _i1.Mock - implements _i2.TestNSUrlCredentialHostApi { - MockTestNSUrlCredentialHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createWithUser( - int? identifier, - String? user, - String? password, - _i3.NSUrlCredentialPersistence? persistence, - ) => - super.noSuchMethod( - Invocation.method( - #createWithUser, - [ - identifier, - user, - password, - persistence, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestNSUrlHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestNSUrlHostApi extends _i1.Mock implements _i2.TestNSUrlHostApi { - MockTestNSUrlHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - String? getAbsoluteString(int? identifier) => - (super.noSuchMethod(Invocation.method( - #getAbsoluteString, - [identifier], - )) as String?); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart deleted file mode 100644 index c6458b9d9335..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart +++ /dev/null @@ -1,177 +0,0 @@ -// 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. - -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart'; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit_api_impls.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; - -import '../common/test_web_kit.g.dart'; -import 'ui_kit_test.mocks.dart'; - -@GenerateMocks([ - TestWKWebViewConfigurationHostApi, - TestWKWebViewHostApi, - TestUIScrollViewHostApi, - TestUIScrollViewDelegateHostApi, - TestUIViewHostApi, -]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('UIKit', () { - late InstanceManager instanceManager; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - }); - - group('UIScrollView', () { - late MockTestUIScrollViewHostApi mockPlatformHostApi; - - late UIScrollView scrollView; - late int scrollViewInstanceId; - - setUp(() { - mockPlatformHostApi = MockTestUIScrollViewHostApi(); - TestUIScrollViewHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - TestWKWebViewHostApi.setUp(MockTestWKWebViewHostApi()); - final WKWebView webView = WKWebViewIOS( - WKWebViewConfiguration(instanceManager: instanceManager), - instanceManager: instanceManager, - ); - - scrollView = UIScrollView.fromWebView( - webView, - instanceManager: instanceManager, - ); - scrollViewInstanceId = instanceManager.getIdentifier(scrollView)!; - }); - - tearDown(() { - TestUIScrollViewHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - TestWKWebViewHostApi.setUp(null); - }); - - test('getContentOffset', () async { - when(mockPlatformHostApi.getContentOffset(scrollViewInstanceId)) - .thenReturn([4.0, 10.0]); - expect( - scrollView.getContentOffset(), - completion(const Point(4.0, 10.0)), - ); - }); - - test('scrollBy', () async { - await scrollView.scrollBy(const Point(4.0, 10.0)); - verify(mockPlatformHostApi.scrollBy(scrollViewInstanceId, 4.0, 10.0)); - }); - - test('setContentOffset', () async { - await scrollView.setContentOffset(const Point(4.0, 10.0)); - verify(mockPlatformHostApi.setContentOffset( - scrollViewInstanceId, - 4.0, - 10.0, - )); - }); - - test('setDelegate', () async { - final UIScrollViewDelegate delegate = UIScrollViewDelegate.detached( - instanceManager: instanceManager, - ); - const int delegateIdentifier = 10; - instanceManager.addHostCreatedInstance(delegate, delegateIdentifier); - await scrollView.setDelegate(delegate); - verify(mockPlatformHostApi.setDelegate( - scrollViewInstanceId, - delegateIdentifier, - )); - }); - }); - - group('UIScrollViewDelegate', () { - // Ensure the test host api is removed after each test run. - tearDown(() => TestUIScrollViewDelegateHostApi.setUp(null)); - - test('Host API create', () { - final MockTestUIScrollViewDelegateHostApi mockApi = - MockTestUIScrollViewDelegateHostApi(); - TestUIScrollViewDelegateHostApi.setUp(mockApi); - - UIScrollViewDelegate(instanceManager: instanceManager); - verify(mockApi.create(0)); - }); - - test('scrollViewDidScroll', () { - final UIScrollViewDelegateFlutterApi flutterApi = - UIScrollViewDelegateFlutterApiImpl( - instanceManager: instanceManager, - ); - - final UIScrollView scrollView = UIScrollView.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(scrollView, 0); - - List? args; - final UIScrollViewDelegate scrollViewDelegate = - UIScrollViewDelegate.detached( - scrollViewDidScroll: (UIScrollView scrollView, double x, double y) { - args = [scrollView, x, y]; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(scrollViewDelegate, 1); - - flutterApi.scrollViewDidScroll(1, 0, 5, 6); - expect(args, [scrollView, 5, 6]); - }); - }); - - group('UIView', () { - late MockTestUIViewHostApi mockPlatformHostApi; - - late UIView view; - late int viewInstanceId; - - setUp(() { - mockPlatformHostApi = MockTestUIViewHostApi(); - TestUIViewHostApi.setUp(mockPlatformHostApi); - - view = UIViewBase.detached(instanceManager: instanceManager); - viewInstanceId = instanceManager.addDartCreatedInstance(view); - }); - - tearDown(() { - TestUIViewHostApi.setUp(null); - }); - - test('setBackgroundColor', () async { - await view.setBackgroundColor(Colors.red); - verify(mockPlatformHostApi.setBackgroundColor( - viewInstanceId, - Colors.red.value, - )); - }); - - test('setOpaque', () async { - await view.setOpaque(false); - verify(mockPlatformHostApi.setOpaque(viewInstanceId, false)); - }); - }); - }); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart deleted file mode 100644 index 66bbc7275e69..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart +++ /dev/null @@ -1,517 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i3; - -import '../common/test_web_kit.g.dart' as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -/// A class which mocks [TestWKWebViewConfigurationHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKWebViewConfigurationHostApi extends _i1.Mock - implements _i2.TestWKWebViewConfigurationHostApi { - MockTestWKWebViewConfigurationHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void createFromWebView( - int? identifier, - int? webViewIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebView, - [ - identifier, - webViewIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setAllowsInlineMediaPlayback( - int? identifier, - bool? allow, - ) => - super.noSuchMethod( - Invocation.method( - #setAllowsInlineMediaPlayback, - [ - identifier, - allow, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setLimitsNavigationsToAppBoundDomains( - int? identifier, - bool? limit, - ) => - super.noSuchMethod( - Invocation.method( - #setLimitsNavigationsToAppBoundDomains, - [ - identifier, - limit, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setMediaTypesRequiringUserActionForPlayback( - int? identifier, - List<_i3.WKAudiovisualMediaTypeEnumData?>? types, - ) => - super.noSuchMethod( - Invocation.method( - #setMediaTypesRequiringUserActionForPlayback, - [ - identifier, - types, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKWebViewHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKWebViewHostApi extends _i1.Mock - implements _i2.TestWKWebViewHostApi { - MockTestWKWebViewHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create( - int? identifier, - int? configurationIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #create, - [ - identifier, - configurationIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setUIDelegate( - int? identifier, - int? uiDelegateIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #setUIDelegate, - [ - identifier, - uiDelegateIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setNavigationDelegate( - int? identifier, - int? navigationDelegateIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #setNavigationDelegate, - [ - identifier, - navigationDelegateIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String? getUrl(int? identifier) => (super.noSuchMethod(Invocation.method( - #getUrl, - [identifier], - )) as String?); - - @override - double getEstimatedProgress(int? identifier) => (super.noSuchMethod( - Invocation.method( - #getEstimatedProgress, - [identifier], - ), - returnValue: 0.0, - ) as double); - - @override - void loadRequest( - int? identifier, - _i3.NSUrlRequestData? request, - ) => - super.noSuchMethod( - Invocation.method( - #loadRequest, - [ - identifier, - request, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadHtmlString( - int? identifier, - String? string, - String? baseUrl, - ) => - super.noSuchMethod( - Invocation.method( - #loadHtmlString, - [ - identifier, - string, - baseUrl, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadFileUrl( - int? identifier, - String? url, - String? readAccessUrl, - ) => - super.noSuchMethod( - Invocation.method( - #loadFileUrl, - [ - identifier, - url, - readAccessUrl, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadFlutterAsset( - int? identifier, - String? key, - ) => - super.noSuchMethod( - Invocation.method( - #loadFlutterAsset, - [ - identifier, - key, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool canGoBack(int? identifier) => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [identifier], - ), - returnValue: false, - ) as bool); - - @override - bool canGoForward(int? identifier) => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [identifier], - ), - returnValue: false, - ) as bool); - - @override - void goBack(int? identifier) => super.noSuchMethod( - Invocation.method( - #goBack, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void goForward(int? identifier) => super.noSuchMethod( - Invocation.method( - #goForward, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void reload(int? identifier) => super.noSuchMethod( - Invocation.method( - #reload, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - String? getTitle(int? identifier) => (super.noSuchMethod(Invocation.method( - #getTitle, - [identifier], - )) as String?); - - @override - void setAllowsBackForwardNavigationGestures( - int? identifier, - bool? allow, - ) => - super.noSuchMethod( - Invocation.method( - #setAllowsBackForwardNavigationGestures, - [ - identifier, - allow, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setCustomUserAgent( - int? identifier, - String? userAgent, - ) => - super.noSuchMethod( - Invocation.method( - #setCustomUserAgent, - [ - identifier, - userAgent, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i4.Future evaluateJavaScript( - int? identifier, - String? javaScriptString, - ) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavaScript, - [ - identifier, - javaScriptString, - ], - ), - returnValue: _i4.Future.value(), - ) as _i4.Future); - - @override - void setInspectable( - int? identifier, - bool? inspectable, - ) => - super.noSuchMethod( - Invocation.method( - #setInspectable, - [ - identifier, - inspectable, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String? getCustomUserAgent(int? identifier) => - (super.noSuchMethod(Invocation.method( - #getCustomUserAgent, - [identifier], - )) as String?); -} - -/// A class which mocks [TestUIScrollViewHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestUIScrollViewHostApi extends _i1.Mock - implements _i2.TestUIScrollViewHostApi { - MockTestUIScrollViewHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createFromWebView( - int? identifier, - int? webViewIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebView, - [ - identifier, - webViewIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - List getContentOffset(int? identifier) => (super.noSuchMethod( - Invocation.method( - #getContentOffset, - [identifier], - ), - returnValue: [], - ) as List); - - @override - void scrollBy( - int? identifier, - double? x, - double? y, - ) => - super.noSuchMethod( - Invocation.method( - #scrollBy, - [ - identifier, - x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setContentOffset( - int? identifier, - double? x, - double? y, - ) => - super.noSuchMethod( - Invocation.method( - #setContentOffset, - [ - identifier, - x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setDelegate( - int? identifier, - int? uiScrollViewDelegateIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #setDelegate, - [ - identifier, - uiScrollViewDelegateIdentifier, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestUIScrollViewDelegateHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestUIScrollViewDelegateHostApi extends _i1.Mock - implements _i2.TestUIScrollViewDelegateHostApi { - MockTestUIScrollViewDelegateHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestUIViewHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestUIViewHostApi extends _i1.Mock implements _i2.TestUIViewHostApi { - MockTestUIViewHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void setBackgroundColor( - int? identifier, - int? value, - ) => - super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [ - identifier, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setOpaque( - int? identifier, - bool? opaque, - ) => - super.noSuchMethod( - Invocation.method( - #setOpaque, - [ - identifier, - opaque, - ], - ), - returnValueForMissingStub: null, - ); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart deleted file mode 100644 index 2f89e32e181d..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart +++ /dev/null @@ -1,1133 +0,0 @@ -// 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. - -import 'dart:async'; - -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit_api_impls.dart'; - -import '../common/test_web_kit.g.dart'; -import 'web_kit_test.mocks.dart'; - -@GenerateMocks([ - TestWKHttpCookieStoreHostApi, - TestWKNavigationDelegateHostApi, - TestWKPreferencesHostApi, - TestWKScriptMessageHandlerHostApi, - TestWKUIDelegateHostApi, - TestWKUserContentControllerHostApi, - TestWKWebViewConfigurationHostApi, - TestWKWebViewHostApi, - TestWKWebsiteDataStoreHostApi, -]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('WebKit', () { - late InstanceManager instanceManager; - late WebKitFlutterApis flutterApis; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - flutterApis = WebKitFlutterApis(instanceManager: instanceManager); - WebKitFlutterApis.instance = flutterApis; - }); - - group('WKWebsiteDataStore', () { - late MockTestWKWebsiteDataStoreHostApi mockPlatformHostApi; - - late WKWebsiteDataStore websiteDataStore; - - late WKWebViewConfiguration webViewConfiguration; - - setUp(() { - mockPlatformHostApi = MockTestWKWebsiteDataStoreHostApi(); - TestWKWebsiteDataStoreHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - webViewConfiguration = WKWebViewConfiguration( - instanceManager: instanceManager, - ); - - websiteDataStore = WKWebsiteDataStore.fromWebViewConfiguration( - webViewConfiguration, - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKWebsiteDataStoreHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('WKWebViewConfigurationFlutterApi.create', () { - final WebKitFlutterApis flutterApis = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - flutterApis.webViewConfiguration.create(2); - - expect(instanceManager.containsIdentifier(2), isTrue); - expect( - instanceManager.getInstanceWithWeakReference(2), - isA(), - ); - }); - - test('createFromWebViewConfiguration', () { - verify(mockPlatformHostApi.createFromWebViewConfiguration( - instanceManager.getIdentifier(websiteDataStore), - instanceManager.getIdentifier(webViewConfiguration), - )); - }); - - test('createDefaultDataStore', () { - final WKWebsiteDataStore defaultDataStore = - WKWebsiteDataStore.defaultDataStore; - verify( - mockPlatformHostApi.createDefaultDataStore( - NSObject.globalInstanceManager.getIdentifier(defaultDataStore), - ), - ); - }); - - test('removeDataOfTypes', () { - when(mockPlatformHostApi.removeDataOfTypes( - any, - any, - any, - )).thenAnswer((_) => Future.value(true)); - - expect( - websiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, - DateTime.fromMillisecondsSinceEpoch(5000), - ), - completion(true), - ); - - final List capturedArgs = - verify(mockPlatformHostApi.removeDataOfTypes( - instanceManager.getIdentifier(websiteDataStore), - captureAny, - 5.0, - )).captured; - final List typeData = - (capturedArgs.single as List) - .cast(); - - expect(typeData.single.value, WKWebsiteDataTypeEnum.cookies); - }); - }); - - group('WKHttpCookieStore', () { - late MockTestWKHttpCookieStoreHostApi mockPlatformHostApi; - - late WKHttpCookieStore httpCookieStore; - - late WKWebsiteDataStore websiteDataStore; - - setUp(() { - mockPlatformHostApi = MockTestWKHttpCookieStoreHostApi(); - TestWKHttpCookieStoreHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - TestWKWebsiteDataStoreHostApi.setUp( - MockTestWKWebsiteDataStoreHostApi(), - ); - - websiteDataStore = WKWebsiteDataStore.fromWebViewConfiguration( - WKWebViewConfiguration(instanceManager: instanceManager), - instanceManager: instanceManager, - ); - - httpCookieStore = WKHttpCookieStore.fromWebsiteDataStore( - websiteDataStore, - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKHttpCookieStoreHostApi.setUp(null); - TestWKWebsiteDataStoreHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('createFromWebsiteDataStore', () { - verify(mockPlatformHostApi.createFromWebsiteDataStore( - instanceManager.getIdentifier(httpCookieStore), - instanceManager.getIdentifier(websiteDataStore), - )); - }); - - test('setCookie', () async { - await httpCookieStore.setCookie( - const NSHttpCookie.withProperties({ - NSHttpCookiePropertyKey.comment: 'aComment', - })); - - final NSHttpCookieData cookie = verify( - mockPlatformHostApi.setCookie( - instanceManager.getIdentifier(httpCookieStore), - captureAny, - ), - ).captured.single as NSHttpCookieData; - - expect( - cookie.propertyKeys.single!.value, - NSHttpCookiePropertyKeyEnum.comment, - ); - expect(cookie.propertyValues.single, 'aComment'); - }); - }); - - group('WKScriptMessageHandler', () { - late MockTestWKScriptMessageHandlerHostApi mockPlatformHostApi; - - late WKScriptMessageHandler scriptMessageHandler; - - setUp(() async { - mockPlatformHostApi = MockTestWKScriptMessageHandlerHostApi(); - TestWKScriptMessageHandlerHostApi.setUp(mockPlatformHostApi); - - scriptMessageHandler = WKScriptMessageHandler( - didReceiveScriptMessage: (_, __) {}, - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKScriptMessageHandlerHostApi.setUp(null); - }); - - test('create', () async { - verify(mockPlatformHostApi.create( - instanceManager.getIdentifier(scriptMessageHandler), - )); - }); - - test('didReceiveScriptMessage', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - scriptMessageHandler = WKScriptMessageHandler( - instanceManager: instanceManager, - didReceiveScriptMessage: ( - WKUserContentController userContentController, - WKScriptMessage message, - ) { - argsCompleter.complete([userContentController, message]); - }, - ); - - final WKUserContentController userContentController = - WKUserContentController.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(userContentController, 2); - - WebKitFlutterApis.instance.scriptMessageHandler.didReceiveScriptMessage( - instanceManager.getIdentifier(scriptMessageHandler)!, - 2, - WKScriptMessageData(name: 'name'), - ); - - expect( - argsCompleter.future, - completion([userContentController, isA()]), - ); - }); - }); - - group('WKPreferences', () { - late MockTestWKPreferencesHostApi mockPlatformHostApi; - - late WKPreferences preferences; - - late WKWebViewConfiguration webViewConfiguration; - - setUp(() { - mockPlatformHostApi = MockTestWKPreferencesHostApi(); - TestWKPreferencesHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - webViewConfiguration = WKWebViewConfiguration( - instanceManager: instanceManager, - ); - - preferences = WKPreferences.fromWebViewConfiguration( - webViewConfiguration, - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKPreferencesHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('createFromWebViewConfiguration', () async { - verify(mockPlatformHostApi.createFromWebViewConfiguration( - instanceManager.getIdentifier(preferences), - instanceManager.getIdentifier(webViewConfiguration), - )); - }); - - test('setJavaScriptEnabled', () async { - await preferences.setJavaScriptEnabled(true); - verify(mockPlatformHostApi.setJavaScriptEnabled( - instanceManager.getIdentifier(preferences), - true, - )); - }); - }); - - group('WKUserContentController', () { - late MockTestWKUserContentControllerHostApi mockPlatformHostApi; - - late WKUserContentController userContentController; - - late WKWebViewConfiguration webViewConfiguration; - - setUp(() { - mockPlatformHostApi = MockTestWKUserContentControllerHostApi(); - TestWKUserContentControllerHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - webViewConfiguration = WKWebViewConfiguration( - instanceManager: instanceManager, - ); - - userContentController = - WKUserContentController.fromWebViewConfiguration( - webViewConfiguration, - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKUserContentControllerHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('createFromWebViewConfiguration', () async { - verify(mockPlatformHostApi.createFromWebViewConfiguration( - instanceManager.getIdentifier(userContentController), - instanceManager.getIdentifier(webViewConfiguration), - )); - }); - - test('addScriptMessageHandler', () async { - TestWKScriptMessageHandlerHostApi.setUp( - MockTestWKScriptMessageHandlerHostApi(), - ); - final WKScriptMessageHandler handler = WKScriptMessageHandler( - didReceiveScriptMessage: (_, __) {}, - instanceManager: instanceManager, - ); - - await userContentController.addScriptMessageHandler( - handler, 'handlerName'); - verify(mockPlatformHostApi.addScriptMessageHandler( - instanceManager.getIdentifier(userContentController), - instanceManager.getIdentifier(handler), - 'handlerName', - )); - }); - - test('removeScriptMessageHandler', () async { - await userContentController.removeScriptMessageHandler('handlerName'); - verify(mockPlatformHostApi.removeScriptMessageHandler( - instanceManager.getIdentifier(userContentController), - 'handlerName', - )); - }); - - test('removeAllScriptMessageHandlers', () async { - await userContentController.removeAllScriptMessageHandlers(); - verify(mockPlatformHostApi.removeAllScriptMessageHandlers( - instanceManager.getIdentifier(userContentController), - )); - }); - - test('addUserScript', () { - userContentController.addUserScript(const WKUserScript( - 'aScript', - WKUserScriptInjectionTime.atDocumentEnd, - isMainFrameOnly: false, - )); - verify(mockPlatformHostApi.addUserScript( - instanceManager.getIdentifier(userContentController), - argThat(isA()), - )); - }); - - test('removeAllUserScripts', () { - userContentController.removeAllUserScripts(); - verify(mockPlatformHostApi.removeAllUserScripts( - instanceManager.getIdentifier(userContentController), - )); - }); - }); - - group('WKWebViewConfiguration', () { - late MockTestWKWebViewConfigurationHostApi mockPlatformHostApi; - - late WKWebViewConfiguration webViewConfiguration; - - setUp(() async { - mockPlatformHostApi = MockTestWKWebViewConfigurationHostApi(); - TestWKWebViewConfigurationHostApi.setUp(mockPlatformHostApi); - - webViewConfiguration = WKWebViewConfiguration( - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('create', () async { - verify( - mockPlatformHostApi.create(instanceManager.getIdentifier( - webViewConfiguration, - )), - ); - }); - - test('createFromWebView', () async { - TestWKWebViewHostApi.setUp(MockTestWKWebViewHostApi()); - final WKWebView webView = WKWebViewIOS( - webViewConfiguration, - instanceManager: instanceManager, - ); - - final WKWebViewConfiguration configurationFromWebView = - WKWebViewConfiguration.fromWebView( - webView, - instanceManager: instanceManager, - ); - verify(mockPlatformHostApi.createFromWebView( - instanceManager.getIdentifier(configurationFromWebView), - instanceManager.getIdentifier(webView), - )); - }); - - test('allowsInlineMediaPlayback', () { - webViewConfiguration.setAllowsInlineMediaPlayback(true); - verify(mockPlatformHostApi.setAllowsInlineMediaPlayback( - instanceManager.getIdentifier(webViewConfiguration), - true, - )); - }); - - test('limitsNavigationsToAppBoundDomains', () { - webViewConfiguration.setLimitsNavigationsToAppBoundDomains(true); - verify(mockPlatformHostApi.setLimitsNavigationsToAppBoundDomains( - instanceManager.getIdentifier(webViewConfiguration), - true, - )); - }); - - test('mediaTypesRequiringUserActionForPlayback', () { - webViewConfiguration.setMediaTypesRequiringUserActionForPlayback( - { - WKAudiovisualMediaType.audio, - WKAudiovisualMediaType.video, - }, - ); - - final List typeData = verify( - mockPlatformHostApi.setMediaTypesRequiringUserActionForPlayback( - instanceManager.getIdentifier(webViewConfiguration), - captureAny, - )).captured.single as List; - - expect(typeData, hasLength(2)); - expect(typeData[0]!.value, WKAudiovisualMediaTypeEnum.audio); - expect(typeData[1]!.value, WKAudiovisualMediaTypeEnum.video); - }); - }); - - group('WKNavigationDelegate', () { - late MockTestWKNavigationDelegateHostApi mockPlatformHostApi; - - late WKWebView webView; - - late WKNavigationDelegate navigationDelegate; - - setUp(() async { - mockPlatformHostApi = MockTestWKNavigationDelegateHostApi(); - TestWKNavigationDelegateHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi(), - ); - TestWKWebViewHostApi.setUp(MockTestWKWebViewHostApi()); - webView = WKWebViewIOS( - WKWebViewConfiguration(instanceManager: instanceManager), - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - ); - }); - - tearDown(() { - TestWKNavigationDelegateHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - TestWKWebViewHostApi.setUp(null); - }); - - test('create', () async { - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - ); - - verify(mockPlatformHostApi.create( - instanceManager.getIdentifier(navigationDelegate), - )); - }); - - test('didFinishNavigation', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - didFinishNavigation: (WKWebView webView, String? url) { - argsCompleter.complete([webView, url]); - }, - ); - - WebKitFlutterApis.instance.navigationDelegate.didFinishNavigation( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - 'url', - ); - - expect(argsCompleter.future, completion([webView, 'url'])); - }); - - test('didStartProvisionalNavigation', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - didStartProvisionalNavigation: (WKWebView webView, String? url) { - argsCompleter.complete([webView, url]); - }, - ); - - WebKitFlutterApis.instance.navigationDelegate - .didStartProvisionalNavigation( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - 'url', - ); - - expect(argsCompleter.future, completion([webView, 'url'])); - }); - - test('decidePolicyForNavigationAction', () async { - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - decidePolicyForNavigationAction: ( - WKWebView webView, - WKNavigationAction navigationAction, - ) async { - return WKNavigationActionPolicy.cancel; - }, - ); - - final WKNavigationActionPolicyEnumData policyData = - await WebKitFlutterApis.instance.navigationDelegate - .decidePolicyForNavigationAction( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - WKNavigationActionData( - request: NSUrlRequestData( - url: 'url', - allHttpHeaderFields: {}, - ), - targetFrame: WKFrameInfoData( - isMainFrame: false, - request: NSUrlRequestData( - url: 'url', - allHttpHeaderFields: {}, - )), - navigationType: WKNavigationType.linkActivated, - ), - ); - - expect(policyData.value, WKNavigationActionPolicyEnum.cancel); - }); - - test('decidePolicyForNavigationResponse', () async { - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - decidePolicyForNavigationResponse: ( - WKWebView webView, - WKNavigationResponse navigationAction, - ) async { - return WKNavigationResponsePolicy.cancel; - }, - ); - - final WKNavigationResponsePolicyEnum policy = await WebKitFlutterApis - .instance.navigationDelegate - .decidePolicyForNavigationResponse( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - WKNavigationResponseData( - response: NSHttpUrlResponseData(statusCode: 401), - forMainFrame: true), - ); - - expect(policy, WKNavigationResponsePolicyEnum.cancel); - }); - - test('didFailNavigation', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - didFailNavigation: (WKWebView webView, NSError error) { - argsCompleter.complete([webView, error]); - }, - ); - - WebKitFlutterApis.instance.navigationDelegate.didFailNavigation( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - NSErrorData( - code: 23, - domain: 'Hello', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', - }, - ), - ); - - expect( - argsCompleter.future, - completion([webView, isA()]), - ); - }); - - test('didFailProvisionalNavigation', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - didFailProvisionalNavigation: (WKWebView webView, NSError error) { - argsCompleter.complete([webView, error]); - }, - ); - - WebKitFlutterApis.instance.navigationDelegate - .didFailProvisionalNavigation( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - NSErrorData( - code: 23, - domain: 'Hello', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', - }, - ), - ); - - expect( - argsCompleter.future, - completion([webView, isA()]), - ); - }); - - test('webViewWebContentProcessDidTerminate', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - webViewWebContentProcessDidTerminate: (WKWebView webView) { - argsCompleter.complete([webView]); - }, - ); - - WebKitFlutterApis.instance.navigationDelegate - .webViewWebContentProcessDidTerminate( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - ); - - expect(argsCompleter.future, completion([webView])); - }); - - test('didReceiveAuthenticationChallenge', () async { - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - const int credentialIdentifier = 3; - final NSUrlCredential credential = NSUrlCredential.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance( - credential, - credentialIdentifier, - ); - - navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - didReceiveAuthenticationChallenge: ( - WKWebView webView, - NSUrlAuthenticationChallenge challenge, - void Function( - NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential, - ) completionHandler, - ) { - completionHandler( - NSUrlSessionAuthChallengeDisposition.useCredential, - credential, - ); - }, - ); - - const int challengeIdentifier = 27; - instanceManager.addHostCreatedInstance( - NSUrlAuthenticationChallenge.detached( - protectionSpace: NSUrlProtectionSpace.detached( - host: null, - realm: null, - authenticationMethod: null, - ), - instanceManager: instanceManager, - ), - challengeIdentifier, - ); - - final AuthenticationChallengeResponse response = await WebKitFlutterApis - .instance.navigationDelegate - .didReceiveAuthenticationChallenge( - instanceManager.getIdentifier(navigationDelegate)!, - instanceManager.getIdentifier(webView)!, - challengeIdentifier, - ); - - expect(response.disposition, - NSUrlSessionAuthChallengeDisposition.useCredential); - expect(response.credentialIdentifier, credentialIdentifier); - }); - }); - - group('WKWebView', () { - late MockTestWKWebViewHostApi mockPlatformHostApi; - - late WKWebViewConfiguration webViewConfiguration; - - late WKWebView webView; - late int webViewInstanceId; - - setUp(() { - mockPlatformHostApi = MockTestWKWebViewHostApi(); - TestWKWebViewHostApi.setUp(mockPlatformHostApi); - - TestWKWebViewConfigurationHostApi.setUp( - MockTestWKWebViewConfigurationHostApi()); - webViewConfiguration = WKWebViewConfiguration( - instanceManager: instanceManager, - ); - - webView = WKWebViewIOS( - webViewConfiguration, - instanceManager: instanceManager, - ); - webViewInstanceId = instanceManager.getIdentifier(webView)!; - }); - - tearDown(() { - TestWKWebViewHostApi.setUp(null); - TestWKWebViewConfigurationHostApi.setUp(null); - }); - - test('create', () async { - verify(mockPlatformHostApi.create( - instanceManager.getIdentifier(webView), - instanceManager.getIdentifier( - webViewConfiguration, - ), - )); - }); - - test('setUIDelegate', () async { - TestWKUIDelegateHostApi.setUp(MockTestWKUIDelegateHostApi()); - final WKUIDelegate uiDelegate = WKUIDelegate( - instanceManager: instanceManager, - ); - - await webView.setUIDelegate(uiDelegate); - verify(mockPlatformHostApi.setUIDelegate( - webViewInstanceId, - instanceManager.getIdentifier(uiDelegate), - )); - - TestWKUIDelegateHostApi.setUp(null); - }); - - test('setNavigationDelegate', () async { - TestWKNavigationDelegateHostApi.setUp( - MockTestWKNavigationDelegateHostApi(), - ); - final WKNavigationDelegate navigationDelegate = WKNavigationDelegate( - instanceManager: instanceManager, - ); - - await webView.setNavigationDelegate(navigationDelegate); - verify(mockPlatformHostApi.setNavigationDelegate( - webViewInstanceId, - instanceManager.getIdentifier(navigationDelegate), - )); - - TestWKNavigationDelegateHostApi.setUp(null); - }); - - test('getUrl', () { - when( - mockPlatformHostApi.getUrl(webViewInstanceId), - ).thenReturn('www.flutter.dev'); - expect(webView.getUrl(), completion('www.flutter.dev')); - }); - - test('getEstimatedProgress', () { - when( - mockPlatformHostApi.getEstimatedProgress(webViewInstanceId), - ).thenReturn(54.5); - expect(webView.getEstimatedProgress(), completion(54.5)); - }); - - test('loadRequest', () { - webView.loadRequest(const NSUrlRequest(url: 'www.flutter.dev')); - verify(mockPlatformHostApi.loadRequest( - webViewInstanceId, - argThat(isA()), - )); - }); - - test('loadHtmlString', () { - webView.loadHtmlString('a', baseUrl: 'b'); - verify(mockPlatformHostApi.loadHtmlString(webViewInstanceId, 'a', 'b')); - }); - - test('loadFileUrl', () { - webView.loadFileUrl('a', readAccessUrl: 'b'); - verify(mockPlatformHostApi.loadFileUrl(webViewInstanceId, 'a', 'b')); - }); - - test('loadFlutterAsset', () { - webView.loadFlutterAsset('a'); - verify(mockPlatformHostApi.loadFlutterAsset(webViewInstanceId, 'a')); - }); - - test('canGoBack', () { - when(mockPlatformHostApi.canGoBack(webViewInstanceId)).thenReturn(true); - expect(webView.canGoBack(), completion(isTrue)); - }); - - test('canGoForward', () { - when(mockPlatformHostApi.canGoForward(webViewInstanceId)) - .thenReturn(false); - expect(webView.canGoForward(), completion(isFalse)); - }); - - test('goBack', () { - webView.goBack(); - verify(mockPlatformHostApi.goBack(webViewInstanceId)); - }); - - test('goForward', () { - webView.goForward(); - verify(mockPlatformHostApi.goForward(webViewInstanceId)); - }); - - test('reload', () { - webView.reload(); - verify(mockPlatformHostApi.reload(webViewInstanceId)); - }); - - test('getTitle', () { - when(mockPlatformHostApi.getTitle(webViewInstanceId)) - .thenReturn('MyTitle'); - expect(webView.getTitle(), completion('MyTitle')); - }); - - test('setAllowsBackForwardNavigationGestures', () { - webView.setAllowsBackForwardNavigationGestures(false); - verify(mockPlatformHostApi.setAllowsBackForwardNavigationGestures( - webViewInstanceId, - false, - )); - }); - - test('setCustomUserAgent', () { - webView.setCustomUserAgent('hello'); - verify(mockPlatformHostApi.setCustomUserAgent( - webViewInstanceId, - 'hello', - )); - }); - - test('getCustomUserAgent', () { - const String userAgent = 'str'; - when( - mockPlatformHostApi.getCustomUserAgent(webViewInstanceId), - ).thenReturn(userAgent); - expect(webView.getCustomUserAgent(), completion(userAgent)); - }); - - test('evaluateJavaScript', () { - when(mockPlatformHostApi.evaluateJavaScript(webViewInstanceId, 'gogo')) - .thenAnswer((_) => Future.value('stopstop')); - expect(webView.evaluateJavaScript('gogo'), completion('stopstop')); - }); - - test('evaluateJavaScript returns NSError', () { - when(mockPlatformHostApi.evaluateJavaScript(webViewInstanceId, 'gogo')) - .thenThrow( - PlatformException( - code: '', - details: NSErrorData( - code: 0, - domain: 'domain', - userInfo: { - NSErrorUserInfoKey.NSLocalizedDescription: 'desc', - }, - ), - ), - ); - expect( - webView.evaluateJavaScript('gogo'), - throwsA( - isA().having( - (PlatformException exception) => exception.details, - 'details', - isA(), - ), - ), - ); - }); - }); - - group('WKUIDelegate', () { - late MockTestWKUIDelegateHostApi mockPlatformHostApi; - - late WKUIDelegate uiDelegate; - - setUp(() async { - mockPlatformHostApi = MockTestWKUIDelegateHostApi(); - TestWKUIDelegateHostApi.setUp(mockPlatformHostApi); - - uiDelegate = WKUIDelegate(instanceManager: instanceManager); - }); - - tearDown(() { - TestWKUIDelegateHostApi.setUp(null); - }); - - test('create', () async { - verify(mockPlatformHostApi.create( - instanceManager.getIdentifier(uiDelegate), - )); - }); - - test('onCreateWebView', () async { - final Completer> argsCompleter = - Completer>(); - - WebKitFlutterApis.instance = WebKitFlutterApis( - instanceManager: instanceManager, - ); - - uiDelegate = WKUIDelegate( - instanceManager: instanceManager, - onCreateWebView: ( - WKWebView webView, - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, - ) { - argsCompleter.complete([ - webView, - configuration, - navigationAction, - ]); - }, - ); - - final WKWebView webView = WKWebViewIOS.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(webView, 2); - - final WKWebViewConfiguration configuration = - WKWebViewConfiguration.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(configuration, 3); - - WebKitFlutterApis.instance.uiDelegate.onCreateWebView( - instanceManager.getIdentifier(uiDelegate)!, - 2, - 3, - WKNavigationActionData( - request: NSUrlRequestData( - url: 'url', - allHttpHeaderFields: {}, - ), - targetFrame: WKFrameInfoData( - isMainFrame: false, - request: NSUrlRequestData( - url: 'url', - allHttpHeaderFields: {}, - )), - navigationType: WKNavigationType.linkActivated, - ), - ); - - expect( - argsCompleter.future, - completion([ - webView, - configuration, - isA(), - ]), - ); - }); - - test('requestMediaCapturePermission', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const int instanceIdentifier = 0; - late final List callbackParameters; - final WKUIDelegate instance = WKUIDelegate.detached( - requestMediaCapturePermission: ( - WKUIDelegate instance, - WKWebView webView, - WKSecurityOrigin origin, - WKFrameInfo frame, - WKMediaCaptureType type, - ) async { - callbackParameters = [ - instance, - webView, - origin, - frame, - type, - ]; - return WKPermissionDecision.grant; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WKUIDelegateFlutterApiImpl flutterApi = - WKUIDelegateFlutterApiImpl( - instanceManager: instanceManager, - ); - - final WKWebView webView = WKWebViewIOS.detached( - instanceManager: instanceManager, - ); - const int webViewIdentifier = 42; - instanceManager.addHostCreatedInstance( - webView, - webViewIdentifier, - ); - - const WKSecurityOrigin origin = - WKSecurityOrigin(host: 'host', port: 12, protocol: 'protocol'); - const WKFrameInfo frame = - WKFrameInfo(isMainFrame: false, request: NSUrlRequest(url: 'url')); - const WKMediaCaptureType type = WKMediaCaptureType.microphone; - - flutterApi.requestMediaCapturePermission( - instanceIdentifier, - webViewIdentifier, - WKSecurityOriginData( - host: origin.host, - port: origin.port, - protocol: origin.protocol, - ), - WKFrameInfoData( - isMainFrame: frame.isMainFrame, - request: NSUrlRequestData( - url: 'url', allHttpHeaderFields: {})), - WKMediaCaptureTypeData(value: type), - ); - - expect(callbackParameters, [ - instance, - webView, - isA(), - isA(), - type, - ]); - }); - }); - }); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart deleted file mode 100644 index d9a0ed01d50d..000000000000 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart +++ /dev/null @@ -1,659 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i3; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i4; - -import '../common/test_web_kit.g.dart' as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -/// A class which mocks [TestWKHttpCookieStoreHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKHttpCookieStoreHostApi extends _i1.Mock - implements _i2.TestWKHttpCookieStoreHostApi { - MockTestWKHttpCookieStoreHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createFromWebsiteDataStore( - int? identifier, - int? websiteDataStoreIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebsiteDataStore, - [ - identifier, - websiteDataStoreIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i3.Future setCookie( - int? identifier, - _i4.NSHttpCookieData? cookie, - ) => - (super.noSuchMethod( - Invocation.method( - #setCookie, - [ - identifier, - cookie, - ], - ), - returnValue: _i3.Future.value(), - returnValueForMissingStub: _i3.Future.value(), - ) as _i3.Future); -} - -/// A class which mocks [TestWKNavigationDelegateHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKNavigationDelegateHostApi extends _i1.Mock - implements _i2.TestWKNavigationDelegateHostApi { - MockTestWKNavigationDelegateHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKPreferencesHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKPreferencesHostApi extends _i1.Mock - implements _i2.TestWKPreferencesHostApi { - MockTestWKPreferencesHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createFromWebViewConfiguration( - int? identifier, - int? configurationIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebViewConfiguration, - [ - identifier, - configurationIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setJavaScriptEnabled( - int? identifier, - bool? enabled, - ) => - super.noSuchMethod( - Invocation.method( - #setJavaScriptEnabled, - [ - identifier, - enabled, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKScriptMessageHandlerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKScriptMessageHandlerHostApi extends _i1.Mock - implements _i2.TestWKScriptMessageHandlerHostApi { - MockTestWKScriptMessageHandlerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKUIDelegateHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKUIDelegateHostApi extends _i1.Mock - implements _i2.TestWKUIDelegateHostApi { - MockTestWKUIDelegateHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKUserContentControllerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKUserContentControllerHostApi extends _i1.Mock - implements _i2.TestWKUserContentControllerHostApi { - MockTestWKUserContentControllerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createFromWebViewConfiguration( - int? identifier, - int? configurationIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebViewConfiguration, - [ - identifier, - configurationIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void addScriptMessageHandler( - int? identifier, - int? handlerIdentifier, - String? name, - ) => - super.noSuchMethod( - Invocation.method( - #addScriptMessageHandler, - [ - identifier, - handlerIdentifier, - name, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeScriptMessageHandler( - int? identifier, - String? name, - ) => - super.noSuchMethod( - Invocation.method( - #removeScriptMessageHandler, - [ - identifier, - name, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeAllScriptMessageHandlers(int? identifier) => super.noSuchMethod( - Invocation.method( - #removeAllScriptMessageHandlers, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void addUserScript( - int? identifier, - _i4.WKUserScriptData? userScript, - ) => - super.noSuchMethod( - Invocation.method( - #addUserScript, - [ - identifier, - userScript, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeAllUserScripts(int? identifier) => super.noSuchMethod( - Invocation.method( - #removeAllUserScripts, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKWebViewConfigurationHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKWebViewConfigurationHostApi extends _i1.Mock - implements _i2.TestWKWebViewConfigurationHostApi { - MockTestWKWebViewConfigurationHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? identifier) => super.noSuchMethod( - Invocation.method( - #create, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void createFromWebView( - int? identifier, - int? webViewIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebView, - [ - identifier, - webViewIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setAllowsInlineMediaPlayback( - int? identifier, - bool? allow, - ) => - super.noSuchMethod( - Invocation.method( - #setAllowsInlineMediaPlayback, - [ - identifier, - allow, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setLimitsNavigationsToAppBoundDomains( - int? identifier, - bool? limit, - ) => - super.noSuchMethod( - Invocation.method( - #setLimitsNavigationsToAppBoundDomains, - [ - identifier, - limit, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setMediaTypesRequiringUserActionForPlayback( - int? identifier, - List<_i4.WKAudiovisualMediaTypeEnumData?>? types, - ) => - super.noSuchMethod( - Invocation.method( - #setMediaTypesRequiringUserActionForPlayback, - [ - identifier, - types, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWKWebViewHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKWebViewHostApi extends _i1.Mock - implements _i2.TestWKWebViewHostApi { - MockTestWKWebViewHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create( - int? identifier, - int? configurationIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #create, - [ - identifier, - configurationIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setUIDelegate( - int? identifier, - int? uiDelegateIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #setUIDelegate, - [ - identifier, - uiDelegateIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setNavigationDelegate( - int? identifier, - int? navigationDelegateIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #setNavigationDelegate, - [ - identifier, - navigationDelegateIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String? getUrl(int? identifier) => (super.noSuchMethod(Invocation.method( - #getUrl, - [identifier], - )) as String?); - - @override - double getEstimatedProgress(int? identifier) => (super.noSuchMethod( - Invocation.method( - #getEstimatedProgress, - [identifier], - ), - returnValue: 0.0, - ) as double); - - @override - void loadRequest( - int? identifier, - _i4.NSUrlRequestData? request, - ) => - super.noSuchMethod( - Invocation.method( - #loadRequest, - [ - identifier, - request, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadHtmlString( - int? identifier, - String? string, - String? baseUrl, - ) => - super.noSuchMethod( - Invocation.method( - #loadHtmlString, - [ - identifier, - string, - baseUrl, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadFileUrl( - int? identifier, - String? url, - String? readAccessUrl, - ) => - super.noSuchMethod( - Invocation.method( - #loadFileUrl, - [ - identifier, - url, - readAccessUrl, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadFlutterAsset( - int? identifier, - String? key, - ) => - super.noSuchMethod( - Invocation.method( - #loadFlutterAsset, - [ - identifier, - key, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool canGoBack(int? identifier) => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [identifier], - ), - returnValue: false, - ) as bool); - - @override - bool canGoForward(int? identifier) => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [identifier], - ), - returnValue: false, - ) as bool); - - @override - void goBack(int? identifier) => super.noSuchMethod( - Invocation.method( - #goBack, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void goForward(int? identifier) => super.noSuchMethod( - Invocation.method( - #goForward, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - void reload(int? identifier) => super.noSuchMethod( - Invocation.method( - #reload, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - String? getTitle(int? identifier) => (super.noSuchMethod(Invocation.method( - #getTitle, - [identifier], - )) as String?); - - @override - void setAllowsBackForwardNavigationGestures( - int? identifier, - bool? allow, - ) => - super.noSuchMethod( - Invocation.method( - #setAllowsBackForwardNavigationGestures, - [ - identifier, - allow, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setCustomUserAgent( - int? identifier, - String? userAgent, - ) => - super.noSuchMethod( - Invocation.method( - #setCustomUserAgent, - [ - identifier, - userAgent, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i3.Future evaluateJavaScript( - int? identifier, - String? javaScriptString, - ) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavaScript, - [ - identifier, - javaScriptString, - ], - ), - returnValue: _i3.Future.value(), - ) as _i3.Future); - - @override - void setInspectable( - int? identifier, - bool? inspectable, - ) => - super.noSuchMethod( - Invocation.method( - #setInspectable, - [ - identifier, - inspectable, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String? getCustomUserAgent(int? identifier) => - (super.noSuchMethod(Invocation.method( - #getCustomUserAgent, - [identifier], - )) as String?); -} - -/// A class which mocks [TestWKWebsiteDataStoreHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWKWebsiteDataStoreHostApi extends _i1.Mock - implements _i2.TestWKWebsiteDataStoreHostApi { - MockTestWKWebsiteDataStoreHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void createFromWebViewConfiguration( - int? identifier, - int? configurationIdentifier, - ) => - super.noSuchMethod( - Invocation.method( - #createFromWebViewConfiguration, - [ - identifier, - configurationIdentifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void createDefaultDataStore(int? identifier) => super.noSuchMethod( - Invocation.method( - #createDefaultDataStore, - [identifier], - ), - returnValueForMissingStub: null, - ); - - @override - _i3.Future removeDataOfTypes( - int? identifier, - List<_i4.WKWebsiteDataTypeEnumData?>? dataTypes, - double? modificationTimeInSecondsSinceEpoch, - ) => - (super.noSuchMethod( - Invocation.method( - #removeDataOfTypes, - [ - identifier, - dataTypes, - modificationTimeInSecondsSinceEpoch, - ], - ), - returnValue: _i3.Future.value(false), - ) as _i3.Future); -} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart index 8a1ba88ee26d..05cf5dd78832 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart @@ -6,13 +6,17 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/common/webkit_constants.dart'; import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; +import 'webkit_navigation_delegate_test.mocks.dart'; + +@GenerateMocks([URLAuthenticationChallenge, URLRequest, URL]) void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -28,55 +32,62 @@ void main() { ); }); - test('setOnPageFinished', () { + test('setOnPageFinished', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); late final String callbackUrl; - webKitDelegate.setOnPageFinished((String url) => callbackUrl = url); + await webKitDelegate.setOnPageFinished((String url) => callbackUrl = url); CapturingNavigationDelegate.lastCreatedDelegate.didFinishNavigation!( - WKWebViewIOS.detached(), + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), 'https://www.google.com', ); expect(callbackUrl, 'https://www.google.com'); }); - test('setOnPageStarted', () { + test('setOnPageStarted', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); late final String callbackUrl; - webKitDelegate.setOnPageStarted((String url) => callbackUrl = url); + await webKitDelegate.setOnPageStarted((String url) => callbackUrl = url); CapturingNavigationDelegate .lastCreatedDelegate.didStartProvisionalNavigation!( - WKWebViewIOS.detached(), + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), 'https://www.google.com', ); expect(callbackUrl, 'https://www.google.com'); }); - test('setOnHttpError from decidePolicyForNavigationResponse', () { + test('setOnHttpError from decidePolicyForNavigationResponse', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -86,24 +97,34 @@ void main() { callbackError = error; } - webKitDelegate.setOnHttpError(onHttpError); + await webKitDelegate.setOnHttpError(onHttpError); - CapturingNavigationDelegate + await CapturingNavigationDelegate .lastCreatedDelegate.decidePolicyForNavigationResponse!( - WKWebViewIOS.detached(), - const WKNavigationResponse( - response: NSHttpUrlResponse(statusCode: 401), forMainFrame: true), + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKNavigationResponse.pigeon_detached( + response: HTTPURLResponse.pigeon_detached( + statusCode: 401, + pigeon_instanceManager: TestInstanceManager(), + ), + isForMainFrame: true, + pigeon_instanceManager: TestInstanceManager(), + ), ); expect(callbackError.response?.statusCode, 401); }); - test('setOnHttpError is not called for error codes < 400', () { + test('setOnHttpError is not called for error codes < 400', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -113,24 +134,34 @@ void main() { callbackError = error; } - webKitDelegate.setOnHttpError(onHttpError); + await webKitDelegate.setOnHttpError(onHttpError); - CapturingNavigationDelegate + await CapturingNavigationDelegate .lastCreatedDelegate.decidePolicyForNavigationResponse!( - WKWebViewIOS.detached(), - const WKNavigationResponse( - response: NSHttpUrlResponse(statusCode: 399), forMainFrame: true), + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKNavigationResponse.pigeon_detached( + response: HTTPURLResponse.pigeon_detached( + statusCode: 399, + pigeon_instanceManager: TestInstanceManager(), + ), + isForMainFrame: true, + pigeon_instanceManager: TestInstanceManager(), + ), ); expect(callbackError, isNull); }); - test('onWebResourceError from didFailNavigation', () { + test('onWebResourceError from didFailNavigation', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -140,14 +171,19 @@ void main() { callbackError = error as WebKitWebResourceError; } - webKitDelegate.setOnWebResourceError(onWebResourceError); + await webKitDelegate.setOnWebResourceError(onWebResourceError); CapturingNavigationDelegate.lastCreatedDelegate.didFailNavigation!( - WKWebViewIOS.detached(), - const NSError( + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + NSError.pigeon_detached( code: WKErrorCode.webViewInvalidated, domain: 'domain', - userInfo: { + userInfo: const { NSErrorUserInfoKey.NSURLErrorFailingURLStringError: 'www.flutter.dev', NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', @@ -163,12 +199,11 @@ void main() { expect(callbackError.isForMainFrame, true); }); - test('onWebResourceError from didFailProvisionalNavigation', () { + test('onWebResourceError from didFailProvisionalNavigation', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -178,15 +213,20 @@ void main() { callbackError = error as WebKitWebResourceError; } - webKitDelegate.setOnWebResourceError(onWebResourceError); + await webKitDelegate.setOnWebResourceError(onWebResourceError); CapturingNavigationDelegate .lastCreatedDelegate.didFailProvisionalNavigation!( - WKWebViewIOS.detached(), - const NSError( + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + NSError.pigeon_detached( code: WKErrorCode.webViewInvalidated, domain: 'domain', - userInfo: { + userInfo: const { NSErrorUserInfoKey.NSURLErrorFailingURLStringError: 'www.flutter.dev', NSErrorUserInfoKey.NSLocalizedDescription: 'my desc', @@ -202,12 +242,12 @@ void main() { expect(callbackError.isForMainFrame, true); }); - test('onWebResourceError from webViewWebContentProcessDidTerminate', () { + test('onWebResourceError from webViewWebContentProcessDidTerminate', + () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -217,11 +257,16 @@ void main() { callbackError = error as WebKitWebResourceError; } - webKitDelegate.setOnWebResourceError(onWebResourceError); + await webKitDelegate.setOnWebResourceError(onWebResourceError); CapturingNavigationDelegate .lastCreatedDelegate.webViewWebContentProcessDidTerminate!( - WKWebViewIOS.detached(), + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), ); expect(callbackError.description, ''); @@ -234,50 +279,74 @@ void main() { expect(callbackError.isForMainFrame, true); }); - test('onNavigationRequest from decidePolicyForNavigationAction', () { + test('onNavigationRequest from decidePolicyForNavigationAction', () async { final WebKitNavigationDelegate webKitDelegate = WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); late final NavigationRequest callbackRequest; FutureOr onNavigationRequest( - NavigationRequest request) { + NavigationRequest request, + ) { callbackRequest = request; return NavigationDecision.navigate; } - webKitDelegate.setOnNavigationRequest(onNavigationRequest); + await webKitDelegate.setOnNavigationRequest(onNavigationRequest); + + final MockURLRequest mockRequest = MockURLRequest(); + when(mockRequest.getUrl()).thenAnswer( + (_) => Future.value('https://www.google.com'), + ); expect( - CapturingNavigationDelegate + await CapturingNavigationDelegate .lastCreatedDelegate.decidePolicyForNavigationAction!( - WKWebViewIOS.detached(), - const WKNavigationAction( - request: NSUrlRequest(url: 'https://www.google.com'), - targetFrame: WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com')), - navigationType: WKNavigationType.linkActivated, + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKNavigationAction.pigeon_detached( + request: mockRequest, + targetFrame: WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: URLRequest.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + ), + navigationType: NavigationType.linkActivated, + pigeon_instanceManager: TestInstanceManager(), ), ), - completion(WKNavigationActionPolicy.allow), + NavigationActionPolicy.allow, ); expect(callbackRequest.url, 'https://www.google.com'); expect(callbackRequest.isMainFrame, isFalse); }); - test('onHttpBasicAuthRequest emits host and realm', () { + test('onHttpBasicAuthRequest emits host and realm', () async { final WebKitNavigationDelegate iosNavigationDelegate = WebKitNavigationDelegate( - const WebKitNavigationDelegateCreationParams( + WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, + newAuthenticationChallengeResponse: ({ + required UrlSessionAuthChallengeDisposition disposition, + URLCredential? credential, + }) { + return AuthenticationChallengeResponse.pigeon_detached( + disposition: UrlSessionAuthChallengeDisposition + .cancelAuthenticationChallenge, + pigeon_instanceManager: TestInstanceManager(), + ); + }, ), ), ); @@ -285,37 +354,64 @@ void main() { String? callbackHost; String? callbackRealm; - iosNavigationDelegate.setOnHttpAuthRequest((HttpAuthRequest request) { - callbackHost = request.host; - callbackRealm = request.realm; - }); + await iosNavigationDelegate.setOnHttpAuthRequest( + (HttpAuthRequest request) { + callbackHost = request.host; + callbackRealm = request.realm; + request.onCancel(); + }, + ); const String expectedHost = 'expectedHost'; const String expectedRealm = 'expectedRealm'; - CapturingNavigationDelegate - .lastCreatedDelegate.didReceiveAuthenticationChallenge!( - WKWebViewIOS.detached(), - NSUrlAuthenticationChallenge.detached( - protectionSpace: NSUrlProtectionSpace.detached( + final MockURLAuthenticationChallenge mockChallenge = + MockURLAuthenticationChallenge(); + when(mockChallenge.getProtectionSpace()).thenAnswer( + (_) { + return Future.value( + URLProtectionSpace.pigeon_detached( + port: 0, host: expectedHost, realm: expectedRealm, authenticationMethod: NSUrlAuthenticationMethod.httpBasic, + pigeon_instanceManager: TestInstanceManager(), ), - ), - (NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential) {}); + ); + }, + ); + + await CapturingNavigationDelegate + .lastCreatedDelegate.didReceiveAuthenticationChallenge!( + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + mockChallenge, + ); expect(callbackHost, expectedHost); expect(callbackRealm, expectedRealm); }); - test('onHttpNtlmAuthRequest emits host and realm', () { + test('onHttpNtlmAuthRequest emits host and realm', () async { final WebKitNavigationDelegate iosNavigationDelegate = WebKitNavigationDelegate( - const WebKitNavigationDelegateCreationParams( + WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, + newAuthenticationChallengeResponse: ({ + required UrlSessionAuthChallengeDisposition disposition, + URLCredential? credential, + }) { + return AuthenticationChallengeResponse.pigeon_detached( + disposition: UrlSessionAuthChallengeDisposition + .cancelAuthenticationChallenge, + pigeon_instanceManager: TestInstanceManager(), + ); + }, ), ), ); @@ -323,26 +419,43 @@ void main() { String? callbackHost; String? callbackRealm; - iosNavigationDelegate.setOnHttpAuthRequest((HttpAuthRequest request) { - callbackHost = request.host; - callbackRealm = request.realm; - }); + await iosNavigationDelegate.setOnHttpAuthRequest( + (HttpAuthRequest request) { + callbackHost = request.host; + callbackRealm = request.realm; + request.onCancel(); + }, + ); const String expectedHost = 'expectedHost'; const String expectedRealm = 'expectedRealm'; - CapturingNavigationDelegate - .lastCreatedDelegate.didReceiveAuthenticationChallenge!( - WKWebViewIOS.detached(), - NSUrlAuthenticationChallenge.detached( - protectionSpace: NSUrlProtectionSpace.detached( + final MockURLAuthenticationChallenge mockChallenge = + MockURLAuthenticationChallenge(); + when(mockChallenge.getProtectionSpace()).thenAnswer( + (_) { + return Future.value( + URLProtectionSpace.pigeon_detached( + port: 0, host: expectedHost, realm: expectedRealm, authenticationMethod: NSUrlAuthenticationMethod.httpNtlm, + pigeon_instanceManager: TestInstanceManager(), ), - ), - (NSUrlSessionAuthChallengeDisposition disposition, - NSUrlCredential? credential) {}); + ); + }, + ); + + await CapturingNavigationDelegate + .lastCreatedDelegate.didReceiveAuthenticationChallenge!( + WKNavigationDelegate.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + WKWebView.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), + mockChallenge, + ); expect(callbackHost, expectedHost); expect(callbackRealm, expectedRealm); @@ -361,24 +474,14 @@ class CapturingNavigationDelegate extends WKNavigationDelegate { super.decidePolicyForNavigationAction, super.webViewWebContentProcessDidTerminate, super.didReceiveAuthenticationChallenge, - }) : super.detached() { + }) : super.pigeon_detached(pigeon_instanceManager: TestInstanceManager()) { lastCreatedDelegate = this; } static CapturingNavigationDelegate lastCreatedDelegate = CapturingNavigationDelegate(); } -// Records the last created instance of itself. -class CapturingUIDelegate extends WKUIDelegate { - CapturingUIDelegate({ - super.onCreateWebView, - super.requestMediaCapturePermission, - super.runJavaScriptAlertDialog, - super.runJavaScriptConfirmDialog, - super.runJavaScriptTextInputDialog, - super.instanceManager, - }) : super.detached() { - lastCreatedDelegate = this; - } - static CapturingUIDelegate lastCreatedDelegate = CapturingUIDelegate(); +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart new file mode 100644 index 000000000000..d30c175724e9 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_navigation_delegate_test.mocks.dart @@ -0,0 +1,385 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in webview_flutter_wkwebview/test/webkit_navigation_delegate_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; +import 'dart:typed_data' as _i4; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i5; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeURLProtectionSpace_1 extends _i1.SmartFake + implements _i2.URLProtectionSpace { + _FakeURLProtectionSpace_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeURLAuthenticationChallenge_2 extends _i1.SmartFake + implements _i2.URLAuthenticationChallenge { + _FakeURLAuthenticationChallenge_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeURLRequest_3 extends _i1.SmartFake implements _i2.URLRequest { + _FakeURLRequest_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeURL_4 extends _i1.SmartFake implements _i2.URL { + _FakeURL_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [URLAuthenticationChallenge]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockURLAuthenticationChallenge extends _i1.Mock + implements _i2.URLAuthenticationChallenge { + MockURLAuthenticationChallenge() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future<_i2.URLProtectionSpace> getProtectionSpace() => + (super.noSuchMethod( + Invocation.method( + #getProtectionSpace, + [], + ), + returnValue: + _i3.Future<_i2.URLProtectionSpace>.value(_FakeURLProtectionSpace_1( + this, + Invocation.method( + #getProtectionSpace, + [], + ), + )), + ) as _i3.Future<_i2.URLProtectionSpace>); + + @override + _i2.URLAuthenticationChallenge pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeURLAuthenticationChallenge_2( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.URLAuthenticationChallenge); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [URLRequest]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockURLRequest extends _i1.Mock implements _i2.URLRequest { + MockURLRequest() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future getUrl() => (super.noSuchMethod( + Invocation.method( + #getUrl, + [], + ), + returnValue: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setHttpMethod(String? method) => (super.noSuchMethod( + Invocation.method( + #setHttpMethod, + [method], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future getHttpMethod() => (super.noSuchMethod( + Invocation.method( + #getHttpMethod, + [], + ), + returnValue: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setHttpBody(_i4.Uint8List? body) => (super.noSuchMethod( + Invocation.method( + #setHttpBody, + [body], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future<_i4.Uint8List?> getHttpBody() => (super.noSuchMethod( + Invocation.method( + #getHttpBody, + [], + ), + returnValue: _i3.Future<_i4.Uint8List?>.value(), + ) as _i3.Future<_i4.Uint8List?>); + + @override + _i3.Future setAllHttpHeaderFields(Map? fields) => + (super.noSuchMethod( + Invocation.method( + #setAllHttpHeaderFields, + [fields], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future?> getAllHttpHeaderFields() => + (super.noSuchMethod( + Invocation.method( + #getAllHttpHeaderFields, + [], + ), + returnValue: _i3.Future?>.value(), + ) as _i3.Future?>); + + @override + _i2.URLRequest pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeURLRequest_3( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.URLRequest); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [URL]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockURL extends _i1.Mock implements _i2.URL { + MockURL() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future getAbsoluteString() => (super.noSuchMethod( + Invocation.method( + #getAbsoluteString, + [], + ), + returnValue: _i3.Future.value(_i5.dummyValue( + this, + Invocation.method( + #getAbsoluteString, + [], + ), + )), + ) as _i3.Future); + + @override + _i2.URL pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeURL_4( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.URL); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart index 4e1208641e85..bb09de31ac88 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart @@ -3,33 +3,35 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/common/platform_webview.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; +import 'package:webview_flutter_wkwebview/src/common/webkit_constants.dart'; import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; import 'webkit_webview_controller_test.mocks.dart'; -@GenerateMocks([ - NSUrl, - UIScrollView, - UIScrollViewDelegate, - WKPreferences, - WKUserContentController, - WKWebsiteDataStore, - WKWebViewIOS, - WKWebViewConfiguration, - WKScriptMessageHandler, +@GenerateNiceMocks(>[ + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), ]) void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -42,92 +44,131 @@ void main() { WKUIDelegate? uiDelegate, MockWKUserContentController? mockUserContentController, MockWKWebsiteDataStore? mockWebsiteDataStore, - MockWKWebViewIOS Function( + MockUIViewWKWebView Function( WKWebViewConfiguration configuration, { void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, )? observeValue, })? createMockWebView, MockWKWebViewConfiguration? mockWebViewConfiguration, - InstanceManager? instanceManager, + MockURLRequest Function({required String url})? createURLRequest, + PigeonInstanceManager? instanceManager, }) { final MockWKWebViewConfiguration nonNullMockWebViewConfiguration = mockWebViewConfiguration ?? MockWKWebViewConfiguration(); - late final MockWKWebViewIOS nonNullMockWebView; + late final MockUIViewWKWebView nonNullMockWebView; final PlatformWebViewControllerCreationParams controllerCreationParams = WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: ( + {PigeonInstanceManager? instanceManager}) { return nonNullMockWebViewConfiguration; }, - createWebView: ( - _, { + newPlatformWebView: ({ + required WKWebViewConfiguration initialConfiguration, void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String?, + NSObject?, + Map?, )? observeValue, - InstanceManager? instanceManager, }) { nonNullMockWebView = createMockWebView == null - ? MockWKWebViewIOS() + ? MockUIViewWKWebView() : createMockWebView( nonNullMockWebViewConfiguration, observeValue: observeValue, ); - return nonNullMockWebView; + return PlatformWebView.fromNativeWebView(nonNullMockWebView); }, - createUIDelegate: ({ + newWKUIDelegate: ({ void Function( - WKWebView webView, - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, + WKUIDelegate, + WKWebView, + WKWebViewConfiguration, + WKNavigationAction, )? onCreateWebView, - Future Function( - WKUIDelegate instance, - WKWebView webView, - WKSecurityOrigin origin, - WKFrameInfo frame, - WKMediaCaptureType type, + Future Function( + WKUIDelegate, + WKWebView, + WKSecurityOrigin, + WKFrameInfo, + MediaCaptureType, )? requestMediaCapturePermission, Future Function( - String message, - WKFrameInfo frame, - )? runJavaScriptAlertDialog, + WKUIDelegate, + WKWebView, + String, + WKFrameInfo, + )? runJavaScriptAlertPanel, Future Function( - String message, - WKFrameInfo frame, - )? runJavaScriptConfirmDialog, - Future Function( - String prompt, - String defaultText, - WKFrameInfo frame, - )? runJavaScriptTextInputDialog, - InstanceManager? instanceManager, + WKUIDelegate, + WKWebView, + String, + WKFrameInfo, + )? runJavaScriptConfirmPanel, + Future Function( + WKUIDelegate, + WKWebView, + String, + String?, + WKFrameInfo, + )? runJavaScriptTextInputPanel, }) { return uiDelegate ?? CapturingUIDelegate( onCreateWebView: onCreateWebView, requestMediaCapturePermission: requestMediaCapturePermission, - runJavaScriptAlertDialog: runJavaScriptAlertDialog, - runJavaScriptConfirmDialog: runJavaScriptConfirmDialog, - runJavaScriptTextInputDialog: runJavaScriptTextInputDialog); + runJavaScriptAlertPanel: runJavaScriptAlertPanel, + runJavaScriptConfirmPanel: runJavaScriptConfirmPanel, + runJavaScriptTextInputPanel: runJavaScriptTextInputPanel); }, - createScriptMessageHandler: WKScriptMessageHandler.detached, - createUIScrollViewDelegate: ({ - void Function(UIScrollView, double, double)? scrollViewDidScroll, + newWKScriptMessageHandler: ({ + required void Function( + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, + ) didReceiveScriptMessage, + }) { + return WKScriptMessageHandler.pigeon_detached( + didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), + ); + }, + newUIScrollViewDelegate: ({ + void Function( + UIScrollViewDelegate, + UIScrollView, + double, + double, + )? scrollViewDidScroll, }) { return scrollViewDelegate ?? CapturingUIScrollViewDelegate( scrollViewDidScroll: scrollViewDidScroll, ); }, + newURLRequest: + createURLRequest ?? ({required String url}) => MockURLRequest(), + newWKUserScript: ({ + required String source, + required UserScriptInjectionTime injectionTime, + required bool isForMainFrameOnly, + }) { + return WKUserScript.pigeon_detached( + source: source, + injectionTime: injectionTime, + isForMainFrameOnly: isForMainFrameOnly, + pigeon_instanceManager: TestInstanceManager(), + ); + }, ), - instanceManager: instanceManager, + instanceManager: instanceManager ?? TestInstanceManager(), ); final WebKitWebViewController controller = WebKitWebViewController( @@ -139,12 +180,22 @@ void main() { when(nonNullMockWebView.configuration) .thenReturn(nonNullMockWebViewConfiguration); - when(nonNullMockWebViewConfiguration.preferences) - .thenReturn(mockPreferences ?? MockWKPreferences()); - when(nonNullMockWebViewConfiguration.userContentController).thenReturn( - mockUserContentController ?? MockWKUserContentController()); - when(nonNullMockWebViewConfiguration.websiteDataStore) - .thenReturn(mockWebsiteDataStore ?? MockWKWebsiteDataStore()); + when(nonNullMockWebViewConfiguration.getPreferences()).thenAnswer( + (_) => Future.value( + mockPreferences ?? MockWKPreferences(), + ), + ); + when(nonNullMockWebViewConfiguration.getUserContentController()) + .thenAnswer( + (_) => Future.value( + mockUserContentController ?? MockWKUserContentController(), + ), + ); + when(nonNullMockWebViewConfiguration.getWebsiteDataStore()).thenAnswer( + (_) => Future.value( + mockWebsiteDataStore ?? MockWKWebsiteDataStore(), + ), + ); return controller; } @@ -156,10 +207,9 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { - return mockConfiguration; - }, + newWKWebViewConfiguration: () => mockConfiguration, ), + instanceManager: TestInstanceManager(), allowsInlineMediaPlayback: true, ); @@ -174,10 +224,11 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: () { return mockConfiguration; }, ), + instanceManager: TestInstanceManager(), limitsNavigationsToAppBoundDomains: true, ); @@ -194,10 +245,11 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: () { return mockConfiguration; }, ), + instanceManager: TestInstanceManager(), ); verifyNever( @@ -211,10 +263,11 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: () { return mockConfiguration; }, ), + instanceManager: TestInstanceManager(), mediaTypesRequiringUserAction: const { PlaybackMediaTypes.video, }, @@ -222,9 +275,7 @@ void main() { verify( mockConfiguration.setMediaTypesRequiringUserActionForPlayback( - { - WKAudiovisualMediaType.video, - }, + AudiovisualMediaType.video, ), ); }); @@ -236,18 +287,16 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: () { return mockConfiguration; }, ), + instanceManager: TestInstanceManager(), ); verify( mockConfiguration.setMediaTypesRequiringUserActionForPlayback( - { - WKAudiovisualMediaType.audio, - WKAudiovisualMediaType.video, - }, + AudiovisualMediaType.all, ), ); }); @@ -259,37 +308,35 @@ void main() { WebKitWebViewControllerCreationParams( webKitProxy: WebKitProxy( - createWebViewConfiguration: ({InstanceManager? instanceManager}) { + newWKWebViewConfiguration: () { return mockConfiguration; }, ), + instanceManager: TestInstanceManager(), mediaTypesRequiringUserAction: const {}, ); verify( mockConfiguration.setMediaTypesRequiringUserActionForPlayback( - {WKAudiovisualMediaType.none}, + AudiovisualMediaType.none, ), ); }); }); test('loadFile', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, ); await controller.loadFile('/path/to/file.html'); - verify(mockWebView.loadFileUrl( - '/path/to/file.html', - readAccessUrl: '/path/to', - )); + verify(mockWebView.loadFileUrl('/path/to/file.html', '/path/to')); }); test('loadFlutterAsset', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -300,24 +347,24 @@ void main() { }); test('loadHtmlString', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, ); - const String htmlString = 'Test data.'; + const String htmlString = 'Test data.'; await controller.loadHtmlString(htmlString, baseUrl: 'baseUrl'); verify(mockWebView.loadHtmlString( - 'Test data.', - baseUrl: 'baseUrl', + 'Test data.', + 'baseUrl', )); }); group('loadRequest', () { test('Throws ArgumentError for empty scheme', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -332,26 +379,28 @@ void main() { }); test('GET without headers', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); + final MockURLRequest mockRequest = MockURLRequest(); final WebKitWebViewController controller = createControllerWithMocks( - createMockWebView: (_, {dynamic observeValue}) => mockWebView, - ); + createMockWebView: (_, {dynamic observeValue}) => mockWebView, + createURLRequest: ({required String url}) { + expect(url, 'https://www.google.com'); + return mockRequest; + }); await controller.loadRequest( LoadRequestParams(uri: Uri.parse('https://www.google.com')), ); - final NSUrlRequest request = verify(mockWebView.loadRequest(captureAny)) - .captured - .single as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.allHttpHeaderFields, {}); - expect(request.httpMethod, 'get'); + final URLRequest request = + verify(mockWebView.load(captureAny)).captured.single as URLRequest; + verify(request.setAllHttpHeaderFields({})); + verify(request.setHttpMethod('get')); }); test('GET with headers', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -364,16 +413,14 @@ void main() { ), ); - final NSUrlRequest request = verify(mockWebView.loadRequest(captureAny)) - .captured - .single as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.allHttpHeaderFields, {'a': 'header'}); - expect(request.httpMethod, 'get'); + final URLRequest request = + verify(mockWebView.load(captureAny)).captured.single as URLRequest; + verify(request.setAllHttpHeaderFields({'a': 'header'})); + verify(request.setHttpMethod('get')); }); test('POST without body', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -384,15 +431,13 @@ void main() { method: LoadRequestMethod.post, )); - final NSUrlRequest request = verify(mockWebView.loadRequest(captureAny)) - .captured - .single as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.httpMethod, 'post'); + final URLRequest request = + verify(mockWebView.load(captureAny)).captured.single as URLRequest; + verify(request.setHttpMethod('post')); }); test('POST with body', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -404,20 +449,15 @@ void main() { body: Uint8List.fromList('Test Body'.codeUnits), )); - final NSUrlRequest request = verify(mockWebView.loadRequest(captureAny)) - .captured - .single as NSUrlRequest; - expect(request.url, 'https://www.google.com'); - expect(request.httpMethod, 'post'); - expect( - request.httpBody, - Uint8List.fromList('Test Body'.codeUnits), - ); + final URLRequest request = + verify(mockWebView.load(captureAny)).captured.single as URLRequest; + verify(request.setHttpMethod('post')); + verify(request.setHttpBody(Uint8List.fromList('Test Body'.codeUnits))); }); }); test('canGoBack', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -430,7 +470,7 @@ void main() { }); test('canGoForward', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -443,7 +483,7 @@ void main() { }); test('goBack', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -454,7 +494,7 @@ void main() { }); test('goForward', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -465,7 +505,7 @@ void main() { }); test('reload', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -476,7 +516,7 @@ void main() { }); test('setAllowsBackForwardNavigationGestures', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -487,7 +527,7 @@ void main() { }); test('runJavaScriptReturningResult', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -504,7 +544,7 @@ void main() { }); test('runJavaScriptReturningResult throws error on null return value', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -520,7 +560,7 @@ void main() { }); test('runJavaScript', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -537,7 +577,7 @@ void main() { test('runJavaScript ignores exception with unsupported javaScript type', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -546,9 +586,11 @@ void main() { when(mockWebView.evaluateJavaScript('runJavaScript')) .thenThrow(PlatformException( code: '', - details: const NSError( + details: NSError.pigeon_detached( code: WKErrorCode.javaScriptResultTypeIsUnsupported, domain: '', + userInfo: const {}, + pigeon_instanceManager: TestInstanceManager(), ), )); expect( @@ -558,7 +600,7 @@ void main() { }); test('getTitle', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -570,7 +612,7 @@ void main() { }); test('currentUrl', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -588,8 +630,12 @@ void main() { mockScrollView: mockScrollView, ); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await controller.scrollTo(2, 4); - verify(mockScrollView.setContentOffset(const Point(2.0, 4.0))); + verify(mockScrollView.setContentOffset(2.0, 4.0)); + + debugDefaultTargetPlatformOverride = null; }); test('scrollBy', () async { @@ -599,8 +645,12 @@ void main() { mockScrollView: mockScrollView, ); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await controller.scrollBy(2, 4); - verify(mockScrollView.scrollBy(const Point(2.0, 4.0))); + verify(mockScrollView.scrollBy(2.0, 4.0)); + + debugDefaultTargetPlatformOverride = null; }); test('getScrollPosition', () { @@ -610,13 +660,17 @@ void main() { mockScrollView: mockScrollView, ); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + when(mockScrollView.getContentOffset()).thenAnswer( - (_) => Future>.value(const Point(8.0, 16.0)), + (_) => Future>.value([8.0, 16.0]), ); expect( controller.getScrollPosition(), completion(const Offset(8.0, 16.0)), ); + + debugDefaultTargetPlatformOverride = null; }); test('disable zoom', () async { @@ -633,8 +687,8 @@ void main() { verify(mockUserContentController.addUserScript(captureAny)) .captured .first as WKUserScript; - expect(zoomScript.isMainFrameOnly, isTrue); - expect(zoomScript.injectionTime, WKUserScriptInjectionTime.atDocumentEnd); + expect(zoomScript.isForMainFrameOnly, isTrue); + expect(zoomScript.injectionTime, UserScriptInjectionTime.atDocumentEnd); expect( zoomScript.source, "var meta = document.createElement('meta');\n" @@ -646,7 +700,8 @@ void main() { }); test('setBackgroundColor', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); + //when(mockWebView) final MockUIScrollView mockScrollView = MockUIScrollView(); final WebKitWebViewController controller = createControllerWithMocks( @@ -654,18 +709,22 @@ void main() { mockScrollView: mockScrollView, ); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + await controller.setBackgroundColor(Colors.red); // UIScrollView.setBackgroundColor must be called last. verifyInOrder([ mockWebView.setOpaque(false), - mockWebView.setBackgroundColor(Colors.transparent), - mockScrollView.setBackgroundColor(Colors.red), + mockWebView.setBackgroundColor(Colors.transparent.value), + mockScrollView.setBackgroundColor(Colors.red.value), ]); + + debugDefaultTargetPlatformOverride = null; }); test('userAgent', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -708,12 +767,12 @@ void main() { ); when( mockWebsiteDataStore.removeDataOfTypes( - { - WKWebsiteDataType.memoryCache, - WKWebsiteDataType.diskCache, - WKWebsiteDataType.offlineWebApplicationCache, - }, - DateTime.fromMillisecondsSinceEpoch(0), + [ + WebsiteDataType.memoryCache, + WebsiteDataType.diskCache, + WebsiteDataType.offlineWebApplicationCache, + ], + 0, ), ).thenAnswer((_) => Future.value(false)); @@ -729,8 +788,8 @@ void main() { ); when( mockWebsiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.localStorage}, - DateTime.fromMillisecondsSinceEpoch(0), + [WebsiteDataType.localStorage], + 0, ), ).thenAnswer((_) => Future.value(false)); @@ -739,14 +798,16 @@ void main() { test('addJavaScriptChannel', () async { final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, }) { - return WKScriptMessageHandler.detached( + return WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); }, ); @@ -778,20 +839,22 @@ void main() { expect(userScript.source, 'window.name = webkit.messageHandlers.name;'); expect( userScript.injectionTime, - WKUserScriptInjectionTime.atDocumentStart, + UserScriptInjectionTime.atDocumentStart, ); }); test('addJavaScriptChannel requires channel with a unique name', () async { final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, }) { - return WKScriptMessageHandler.detached( + return WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); }, ); @@ -823,14 +886,16 @@ void main() { test('removeJavaScriptChannel', () async { final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, }) { - return WKScriptMessageHandler.detached( + return WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); }, ); @@ -862,14 +927,16 @@ void main() { test('removeJavaScriptChannel multiple times', () async { final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, }) { - return WKScriptMessageHandler.detached( + return WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); }, ); @@ -917,7 +984,7 @@ void main() { expect(userScript.source, 'window.name2 = webkit.messageHandlers.name2;'); expect( userScript.injectionTime, - WKUserScriptInjectionTime.atDocumentStart, + UserScriptInjectionTime.atDocumentStart, ); await controller.removeJavaScriptChannel('name2'); @@ -928,14 +995,16 @@ void main() { test('removeJavaScriptChannel with zoom disabled', () async { final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( - WKUserContentController userContentController, - WKScriptMessage message, + WKScriptMessageHandler, + WKUserContentController, + WKScriptMessage, ) didReceiveScriptMessage, }) { - return WKScriptMessageHandler.detached( + return WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); }, ); @@ -963,8 +1032,8 @@ void main() { verify(mockUserContentController.addUserScript(captureAny)) .captured .first as WKUserScript; - expect(zoomScript.isMainFrameOnly, isTrue); - expect(zoomScript.injectionTime, WKUserScriptInjectionTime.atDocumentEnd); + expect(zoomScript.isForMainFrameOnly, isTrue); + expect(zoomScript.injectionTime, UserScriptInjectionTime.atDocumentEnd); expect( zoomScript.source, "var meta = document.createElement('meta');\n" @@ -976,7 +1045,7 @@ void main() { }); test('getUserAgent', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -991,7 +1060,7 @@ void main() { }); test('setPlatformNavigationDelegate', () { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -1001,8 +1070,8 @@ void main() { WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: CapturingUIDelegate.new, + newWKNavigationDelegate: CapturingNavigationDelegate.new, + newWKUIDelegate: CapturingUIDelegate.new, ), ), ); @@ -1017,21 +1086,23 @@ void main() { }); test('setPlatformNavigationDelegate onProgress', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); late final void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, ) webViewObserveValue; final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: ( - _, { + WKWebViewConfiguration configuration, { void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, )? observeValue, }) { webViewObserveValue = observeValue!; @@ -1042,10 +1113,8 @@ void main() { verify( mockWebView.addObserver( mockWebView, - keyPath: 'estimatedProgress', - options: { - NSKeyValueObservingOptions.newValue, - }, + 'estimatedProgress', + [KeyValueObservingOptions.newValue], ), ); @@ -1053,8 +1122,7 @@ void main() { WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: WKUIDelegate.detached, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -1067,9 +1135,10 @@ void main() { await controller.setPlatformNavigationDelegate(navigationDelegate); webViewObserveValue( + mockWebView, 'estimatedProgress', mockWebView, - {NSKeyValueChangeKey.newValue: 0.0}, + {KeyValueChangeKey.newValue: 0.0}, ); expect(callbackProgress, 0); @@ -1083,42 +1152,48 @@ void main() { // CapturingUIDelegate.lastCreatedDelegate. createControllerWithMocks(); - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); - const NSUrlRequest request = NSUrlRequest(url: 'https://www.google.com'); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); + final MockURLRequest mockRequest = MockURLRequest(); CapturingUIDelegate.lastCreatedDelegate.onCreateWebView!( + CapturingUIDelegate.lastCreatedDelegate, mockWebView, - WKWebViewConfiguration.detached(), - const WKNavigationAction( - request: request, - targetFrame: WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com')), - navigationType: WKNavigationType.linkActivated, + MockWKWebViewConfiguration(), + WKNavigationAction.pigeon_detached( + request: mockRequest, + targetFrame: WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: MockURLRequest(), + pigeon_instanceManager: TestInstanceManager(), + ), + navigationType: NavigationType.linkActivated, + pigeon_instanceManager: TestInstanceManager(), ), ); - verify(mockWebView.loadRequest(request)); + verify(mockWebView.load(mockRequest)); }); test( 'setPlatformNavigationDelegate onProgress can be changed by the WebKitNavigationDelegate', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); late final void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, ) webViewObserveValue; final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: ( - _, { + WKWebViewConfiguration configuration, { void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, )? observeValue, }) { webViewObserveValue = observeValue!; @@ -1130,8 +1205,7 @@ void main() { WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: WKUIDelegate.detached, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -1147,30 +1221,33 @@ void main() { ); webViewObserveValue( + mockWebView, 'estimatedProgress', mockWebView, - {NSKeyValueChangeKey.newValue: 0.0}, + {KeyValueChangeKey.newValue: 0.0}, ); expect(callbackProgress, 0); }); test('setPlatformNavigationDelegate onUrlChange', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); late final void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, ) webViewObserveValue; final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: ( - _, { + WKWebViewConfiguration configuration, { void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, )? observeValue, }) { webViewObserveValue = observeValue!; @@ -1181,10 +1258,10 @@ void main() { verify( mockWebView.addObserver( mockWebView, - keyPath: 'URL', - options: { - NSKeyValueObservingOptions.newValue, - }, + 'URL', + [ + KeyValueObservingOptions.newValue, + ], ), ); @@ -1192,8 +1269,7 @@ void main() { WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: WKUIDelegate.detached, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -1205,14 +1281,15 @@ void main() { await controller.setPlatformNavigationDelegate(navigationDelegate); - final MockNSUrl mockNSUrl = MockNSUrl(); - when(mockNSUrl.getAbsoluteString()).thenAnswer((_) { + final MockURL mockUrl = MockURL(); + when(mockUrl.getAbsoluteString()).thenAnswer((_) { return Future.value('https://www.google.com'); }); webViewObserveValue( + mockWebView, 'URL', mockWebView, - {NSKeyValueChangeKey.newValue: mockNSUrl}, + {KeyValueChangeKey.newValue: mockUrl}, ); final UrlChange urlChange = await urlChangeCompleter.future; @@ -1220,21 +1297,23 @@ void main() { }); test('setPlatformNavigationDelegate onUrlChange to null NSUrl', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); late final void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, ) webViewObserveValue; final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: ( - _, { + WKWebViewConfiguration configuration, { void Function( - String keyPath, - NSObject object, - Map change, + NSObject, + String? keyPath, + NSObject? object, + Map? change, )? observeValue, }) { webViewObserveValue = observeValue!; @@ -1246,8 +1325,7 @@ void main() { WebKitNavigationDelegate( const WebKitNavigationDelegateCreationParams( webKitProxy: WebKitProxy( - createNavigationDelegate: CapturingNavigationDelegate.new, - createUIDelegate: WKUIDelegate.detached, + newWKNavigationDelegate: CapturingNavigationDelegate.new, ), ), ); @@ -1260,21 +1338,21 @@ void main() { await controller.setPlatformNavigationDelegate(navigationDelegate); webViewObserveValue( + mockWebView, 'URL', mockWebView, - {NSKeyValueChangeKey.newValue: null}, + {KeyValueChangeKey.newValue: null}, ); final UrlChange urlChange = await urlChangeCompleter.future; - expect(urlChange.url, isNull); + expect(urlChange.url, null); }); test('webViewIdentifier', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); - when(mockWebView.copy()).thenReturn(MockWKWebViewIOS()); + final PigeonInstanceManager instanceManager = TestInstanceManager(); + + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); + when(mockWebView.pigeon_copy()).thenReturn(MockUIViewWKWebView()); instanceManager.addHostCreatedInstance(mockWebView, 0); final WebKitWebViewController controller = createControllerWithMocks( @@ -1299,33 +1377,40 @@ void main() { }, ); - final Future Function( + final Future Function( WKUIDelegate instance, WKWebView webView, WKSecurityOrigin origin, WKFrameInfo frame, - WKMediaCaptureType type, + MediaCaptureType type, ) onPermissionRequestCallback = CapturingUIDelegate .lastCreatedDelegate.requestMediaCapturePermission!; - final WKPermissionDecision decision = await onPermissionRequestCallback( + final PermissionDecision decision = await onPermissionRequestCallback( CapturingUIDelegate.lastCreatedDelegate, - WKWebViewIOS.detached(), - const WKSecurityOrigin(host: '', port: 0, protocol: ''), - const WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com')), - WKMediaCaptureType.microphone, + MockWKWebView(), + WKSecurityOrigin.pigeon_detached( + host: '', + port: 0, + securityProtocol: '', + pigeon_instanceManager: TestInstanceManager(), + ), + WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: MockURLRequest(), + pigeon_instanceManager: TestInstanceManager(), + ), + MediaCaptureType.microphone, ); expect(permissionRequest.types, [ WebViewPermissionResourceType.microphone, ]); - expect(decision, WKPermissionDecision.grant); + expect(decision, PermissionDecision.grant); }); group('JavaScript Dialog', () { - test('setOnJavaScriptAlertDialog', () async { + test('setOnJavaScriptAlertPanel', () async { final WebKitWebViewController controller = createControllerWithMocks(); late final String message; await controller.setOnJavaScriptAlertDialog( @@ -1335,19 +1420,34 @@ void main() { }); const String callbackMessage = 'Message'; - final Future Function(String message, WKFrameInfo frame) - onJavaScriptAlertDialog = - CapturingUIDelegate.lastCreatedDelegate.runJavaScriptAlertDialog!; - await onJavaScriptAlertDialog( - callbackMessage, - const WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com'))); + final Future Function( + WKUIDelegate, + WKWebView, + String message, + WKFrameInfo frame, + ) onJavaScriptAlertPanel = + CapturingUIDelegate.lastCreatedDelegate.runJavaScriptAlertPanel!; + + final MockURLRequest mockRequest = MockURLRequest(); + when(mockRequest.getUrl()).thenAnswer( + (_) => Future.value('https://google.com'), + ); + + await onJavaScriptAlertPanel( + CapturingUIDelegate.lastCreatedDelegate, + MockWKWebView(), + callbackMessage, + WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: mockRequest, + pigeon_instanceManager: TestInstanceManager(), + ), + ); expect(message, callbackMessage); }); - test('setOnJavaScriptConfirmDialog', () async { + test('setOnJavaScriptConfirmPanel', () async { final WebKitWebViewController controller = createControllerWithMocks(); late final String message; const bool callbackReturnValue = true; @@ -1358,20 +1458,35 @@ void main() { }); const String callbackMessage = 'Message'; - final Future Function(String message, WKFrameInfo frame) - onJavaScriptConfirmDialog = - CapturingUIDelegate.lastCreatedDelegate.runJavaScriptConfirmDialog!; - final bool returnValue = await onJavaScriptConfirmDialog( - callbackMessage, - const WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com'))); + final Future Function( + WKUIDelegate, + WKWebView, + String message, + WKFrameInfo frame, + ) onJavaScriptConfirmPanel = + CapturingUIDelegate.lastCreatedDelegate.runJavaScriptConfirmPanel!; + + final MockURLRequest mockRequest = MockURLRequest(); + when(mockRequest.getUrl()).thenAnswer( + (_) => Future.value('https://google.com'), + ); + + final bool returnValue = await onJavaScriptConfirmPanel( + CapturingUIDelegate.lastCreatedDelegate, + MockWKWebView(), + callbackMessage, + WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: mockRequest, + pigeon_instanceManager: TestInstanceManager(), + ), + ); expect(message, callbackMessage); expect(returnValue, callbackReturnValue); }); - test('setOnJavaScriptTextInputDialog', () async { + test('setOnJavaScriptTextInputPanel', () async { final WebKitWebViewController controller = createControllerWithMocks(); late final String message; late final String? defaultText; @@ -1385,16 +1500,31 @@ void main() { const String callbackMessage = 'Message'; const String callbackDefaultText = 'Default Text'; - final Future Function( - String prompt, String defaultText, WKFrameInfo frame) - onJavaScriptTextInputDialog = CapturingUIDelegate - .lastCreatedDelegate.runJavaScriptTextInputDialog!; - final String returnValue = await onJavaScriptTextInputDialog( - callbackMessage, - callbackDefaultText, - const WKFrameInfo( - isMainFrame: false, - request: NSUrlRequest(url: 'https://google.com'))); + final Future Function( + WKUIDelegate, + WKWebView, + String prompt, + String? defaultText, + WKFrameInfo frame, + ) onJavaScriptTextInputPanel = CapturingUIDelegate + .lastCreatedDelegate.runJavaScriptTextInputPanel!; + + final MockURLRequest mockRequest = MockURLRequest(); + when(mockRequest.getUrl()).thenAnswer( + (_) => Future.value('https://google.com'), + ); + + final String? returnValue = await onJavaScriptTextInputPanel( + CapturingUIDelegate.lastCreatedDelegate, + MockWKWebView(), + callbackMessage, + callbackDefaultText, + WKFrameInfo.pigeon_detached( + isMainFrame: false, + request: mockRequest, + pigeon_instanceManager: TestInstanceManager(), + ), + ); expect(message, callbackMessage); expect(defaultText, callbackDefaultText); @@ -1403,7 +1533,7 @@ void main() { }); test('inspectable', () async { - final MockWKWebViewIOS mockWebView = MockWKWebViewIOS(); + final MockUIViewWKWebView mockWebView = MockUIViewWKWebView(); final WebKitWebViewController controller = createControllerWithMocks( createMockWebView: (_, {dynamic observeValue}) => mockWebView, @@ -1434,15 +1564,15 @@ void main() { final WKUserScript overrideConsoleScript = capturedScripts[1] as WKUserScript; - expect(messageHandlerScript.isMainFrameOnly, isFalse); + expect(messageHandlerScript.isForMainFrameOnly, isFalse); expect(messageHandlerScript.injectionTime, - WKUserScriptInjectionTime.atDocumentStart); + UserScriptInjectionTime.atDocumentStart); expect(messageHandlerScript.source, 'window.fltConsoleMessage = webkit.messageHandlers.fltConsoleMessage;'); - expect(overrideConsoleScript.isMainFrameOnly, isTrue); + expect(overrideConsoleScript.isForMainFrameOnly, isTrue); expect(overrideConsoleScript.injectionTime, - WKUserScriptInjectionTime.atDocumentStart); + UserScriptInjectionTime.atDocumentStart); expect(overrideConsoleScript.source, ''' var _flutter_webview_plugin_overrides = _flutter_webview_plugin_overrides || { removeCyclicObject: function() { @@ -1516,30 +1646,50 @@ window.addEventListener("error", function(e) { capturedParameters[0] as WKScriptMessageHandler; scriptMessageHandler.didReceiveScriptMessage( - mockUserContentController, - const WKScriptMessage( - name: 'test', - body: '{"level": "debug", "message": "Debug message"}')); + scriptMessageHandler, + mockUserContentController, + WKScriptMessage.pigeon_detached( + name: 'test', + body: '{"level": "debug", "message": "Debug message"}', + pigeon_instanceManager: TestInstanceManager(), + ), + ); scriptMessageHandler.didReceiveScriptMessage( - mockUserContentController, - const WKScriptMessage( - name: 'test', - body: '{"level": "error", "message": "Error message"}')); + scriptMessageHandler, + mockUserContentController, + WKScriptMessage.pigeon_detached( + name: 'test', + body: '{"level": "error", "message": "Error message"}', + pigeon_instanceManager: TestInstanceManager(), + ), + ); scriptMessageHandler.didReceiveScriptMessage( - mockUserContentController, - const WKScriptMessage( - name: 'test', - body: '{"level": "info", "message": "Info message"}')); + scriptMessageHandler, + mockUserContentController, + WKScriptMessage.pigeon_detached( + name: 'test', + body: '{"level": "info", "message": "Info message"}', + pigeon_instanceManager: TestInstanceManager(), + ), + ); scriptMessageHandler.didReceiveScriptMessage( - mockUserContentController, - const WKScriptMessage( - name: 'test', - body: '{"level": "log", "message": "Log message"}')); + scriptMessageHandler, + mockUserContentController, + WKScriptMessage.pigeon_detached( + name: 'test', + body: '{"level": "log", "message": "Log message"}', + pigeon_instanceManager: TestInstanceManager(), + ), + ); scriptMessageHandler.didReceiveScriptMessage( - mockUserContentController, - const WKScriptMessage( - name: 'test', - body: '{"level": "warning", "message": "Warning message"}')); + scriptMessageHandler, + mockUserContentController, + WKScriptMessage.pigeon_detached( + name: 'test', + body: '{"level": "warning", "message": "Warning message"}', + pigeon_instanceManager: TestInstanceManager(), + ), + ); expect(logs.length, 5); expect(logs[JavaScriptLogLevel.debug], 'Debug message'); @@ -1553,6 +1703,8 @@ window.addEventListener("error", function(e) { test('setOnScrollPositionChange', () async { final WebKitWebViewController controller = createControllerWithMocks(); + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + final Completer changeCompleter = Completer(); await controller.setOnScrollPositionChange( @@ -1562,6 +1714,7 @@ window.addEventListener("error", function(e) { ); final void Function( + UIScrollViewDelegate, UIScrollView scrollView, double, double, @@ -1569,11 +1722,18 @@ window.addEventListener("error", function(e) { .lastCreatedDelegate.scrollViewDidScroll!; final MockUIScrollView mockUIScrollView = MockUIScrollView(); - onScrollViewDidScroll(mockUIScrollView, 1.0, 2.0); + onScrollViewDidScroll( + CapturingUIScrollViewDelegate.lastCreatedDelegate, + mockUIScrollView, + 1.0, + 2.0, + ); final ScrollPositionChange change = await changeCompleter.future; expect(change.x, 1.0); expect(change.y, 2.0); + + debugDefaultTargetPlatformOverride = null; }); }); @@ -1582,14 +1742,16 @@ window.addEventListener("error", function(e) { late final WKScriptMessageHandler messageHandler; final WebKitProxy webKitProxy = WebKitProxy( - createScriptMessageHandler: ({ + newWKScriptMessageHandler: ({ required void Function( + WKScriptMessageHandler, WKUserContentController userContentController, WKScriptMessage message, ) didReceiveScriptMessage, }) { - messageHandler = WKScriptMessageHandler.detached( + messageHandler = WKScriptMessageHandler.pigeon_detached( didReceiveScriptMessage: didReceiveScriptMessage, + pigeon_instanceManager: TestInstanceManager(), ); return messageHandler; }, @@ -1605,8 +1767,13 @@ window.addEventListener("error", function(e) { ); messageHandler.didReceiveScriptMessage( + messageHandler, MockWKUserContentController(), - const WKScriptMessage(name: 'name', body: 'myMessage'), + WKScriptMessage.pigeon_detached( + name: 'name', + body: 'myMessage', + pigeon_instanceManager: TestInstanceManager(), + ), ); expect(callbackMessage, 'myMessage'); @@ -1619,16 +1786,15 @@ class CapturingNavigationDelegate extends WKNavigationDelegate { CapturingNavigationDelegate({ super.didFinishNavigation, super.didStartProvisionalNavigation, + super.decidePolicyForNavigationResponse, super.didFailNavigation, super.didFailProvisionalNavigation, super.decidePolicyForNavigationAction, - super.decidePolicyForNavigationResponse, super.webViewWebContentProcessDidTerminate, super.didReceiveAuthenticationChallenge, - }) : super.detached() { + }) : super.pigeon_detached(pigeon_instanceManager: TestInstanceManager()) { lastCreatedDelegate = this; } - static CapturingNavigationDelegate lastCreatedDelegate = CapturingNavigationDelegate(); } @@ -1638,25 +1804,27 @@ class CapturingUIDelegate extends WKUIDelegate { CapturingUIDelegate({ super.onCreateWebView, super.requestMediaCapturePermission, - super.runJavaScriptAlertDialog, - super.runJavaScriptConfirmDialog, - super.runJavaScriptTextInputDialog, - super.instanceManager, - }) : super.detached() { + super.runJavaScriptAlertPanel, + super.runJavaScriptConfirmPanel, + super.runJavaScriptTextInputPanel, + }) : super.pigeon_detached(pigeon_instanceManager: TestInstanceManager()) { lastCreatedDelegate = this; } - static CapturingUIDelegate lastCreatedDelegate = CapturingUIDelegate(); } class CapturingUIScrollViewDelegate extends UIScrollViewDelegate { CapturingUIScrollViewDelegate({ super.scrollViewDidScroll, - super.instanceManager, - }) : super.detached() { + }) : super.pigeon_detached(pigeon_instanceManager: TestInstanceManager()) { lastCreatedDelegate = this; } static CapturingUIScrollViewDelegate lastCreatedDelegate = CapturingUIScrollViewDelegate(); } + +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.mocks.dart index 0c4924df62dc..51b9e2ae9e48 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.mocks.dart @@ -3,15 +3,12 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i6; -import 'dart:math' as _i3; -import 'dart:ui' as _i7; +import 'dart:async' as _i3; +import 'dart:typed_data' as _i5; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i2; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart' as _i4; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i5; +import 'package:mockito/src/dummies.dart' as _i4; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -26,8 +23,9 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i5; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeNSObject_0 extends _i1.SmartFake implements _i2.NSObject { - _FakeNSObject_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -36,9 +34,8 @@ class _FakeNSObject_0 extends _i1.SmartFake implements _i2.NSObject { ); } -class _FakePoint_1 extends _i1.SmartFake - implements _i3.Point { - _FakePoint_1( +class _FakeUIScrollView_1 extends _i1.SmartFake implements _i2.UIScrollView { + _FakeUIScrollView_1( Object parent, Invocation parentInvocation, ) : super( @@ -47,8 +44,9 @@ class _FakePoint_1 extends _i1.SmartFake ); } -class _FakeUIScrollView_2 extends _i1.SmartFake implements _i4.UIScrollView { - _FakeUIScrollView_2( +class _FakeUIScrollViewDelegate_2 extends _i1.SmartFake + implements _i2.UIScrollViewDelegate { + _FakeUIScrollViewDelegate_2( Object parent, Invocation parentInvocation, ) : super( @@ -57,9 +55,8 @@ class _FakeUIScrollView_2 extends _i1.SmartFake implements _i4.UIScrollView { ); } -class _FakeUIScrollViewDelegate_3 extends _i1.SmartFake - implements _i4.UIScrollViewDelegate { - _FakeUIScrollViewDelegate_3( +class _FakeURL_3 extends _i1.SmartFake implements _i2.URL { + _FakeURL_3( Object parent, Invocation parentInvocation, ) : super( @@ -68,8 +65,8 @@ class _FakeUIScrollViewDelegate_3 extends _i1.SmartFake ); } -class _FakeWKPreferences_4 extends _i1.SmartFake implements _i5.WKPreferences { - _FakeWKPreferences_4( +class _FakeURLRequest_4 extends _i1.SmartFake implements _i2.URLRequest { + _FakeURLRequest_4( Object parent, Invocation parentInvocation, ) : super( @@ -78,9 +75,8 @@ class _FakeWKPreferences_4 extends _i1.SmartFake implements _i5.WKPreferences { ); } -class _FakeWKUserContentController_5 extends _i1.SmartFake - implements _i5.WKUserContentController { - _FakeWKUserContentController_5( +class _FakeWKPreferences_5 extends _i1.SmartFake implements _i2.WKPreferences { + _FakeWKPreferences_5( Object parent, Invocation parentInvocation, ) : super( @@ -89,9 +85,9 @@ class _FakeWKUserContentController_5 extends _i1.SmartFake ); } -class _FakeWKHttpCookieStore_6 extends _i1.SmartFake - implements _i5.WKHttpCookieStore { - _FakeWKHttpCookieStore_6( +class _FakeWKScriptMessageHandler_6 extends _i1.SmartFake + implements _i2.WKScriptMessageHandler { + _FakeWKScriptMessageHandler_6( Object parent, Invocation parentInvocation, ) : super( @@ -100,9 +96,9 @@ class _FakeWKHttpCookieStore_6 extends _i1.SmartFake ); } -class _FakeWKWebsiteDataStore_7 extends _i1.SmartFake - implements _i5.WKWebsiteDataStore { - _FakeWKWebsiteDataStore_7( +class _FakeWKUserContentController_7 extends _i1.SmartFake + implements _i2.WKUserContentController { + _FakeWKUserContentController_7( Object parent, Invocation parentInvocation, ) : super( @@ -111,9 +107,8 @@ class _FakeWKWebsiteDataStore_7 extends _i1.SmartFake ); } -class _FakeWKWebViewConfiguration_8 extends _i1.SmartFake - implements _i5.WKWebViewConfiguration { - _FakeWKWebViewConfiguration_8( +class _FakeWKUserScript_8 extends _i1.SmartFake implements _i2.WKUserScript { + _FakeWKUserScript_8( Object parent, Invocation parentInvocation, ) : super( @@ -122,7 +117,7 @@ class _FakeWKWebViewConfiguration_8 extends _i1.SmartFake ); } -class _FakeWKWebView_9 extends _i1.SmartFake implements _i5.WKWebView { +class _FakeWKWebView_9 extends _i1.SmartFake implements _i2.WKWebView { _FakeWKWebView_9( Object parent, Invocation parentInvocation, @@ -132,9 +127,9 @@ class _FakeWKWebView_9 extends _i1.SmartFake implements _i5.WKWebView { ); } -class _FakeWKScriptMessageHandler_10 extends _i1.SmartFake - implements _i5.WKScriptMessageHandler { - _FakeWKScriptMessageHandler_10( +class _FakeWKWebsiteDataStore_10 extends _i1.SmartFake + implements _i2.WKWebsiteDataStore { + _FakeWKWebsiteDataStore_10( Object parent, Invocation parentInvocation, ) : super( @@ -143,1018 +138,1733 @@ class _FakeWKScriptMessageHandler_10 extends _i1.SmartFake ); } -/// A class which mocks [NSUrl]. +class _FakeWKWebViewConfiguration_11 extends _i1.SmartFake + implements _i2.WKWebViewConfiguration { + _FakeWKWebViewConfiguration_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUIViewWKWebView_12 extends _i1.SmartFake + implements _i2.UIViewWKWebView { + _FakeUIViewWKWebView_12( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWKHTTPCookieStore_13 extends _i1.SmartFake + implements _i2.WKHTTPCookieStore { + _FakeWKHTTPCookieStore_13( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [UIScrollView]. /// /// See the documentation for Mockito's code generation for more information. -class MockNSUrl extends _i1.Mock implements _i2.NSUrl { - MockNSUrl() { - _i1.throwOnMissingStub(this); - } +class MockUIScrollView extends _i1.Mock implements _i2.UIScrollView { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i6.Future getAbsoluteString() => (super.noSuchMethod( + _i3.Future> getContentOffset() => (super.noSuchMethod( Invocation.method( - #getAbsoluteString, + #getContentOffset, [], ), - returnValue: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future>.value([]), + returnValueForMissingStub: _i3.Future>.value([]), + ) as _i3.Future>); @override - _i2.NSObject copy() => (super.noSuchMethod( + _i3.Future scrollBy( + double? x, + double? y, + ) => + (super.noSuchMethod( Invocation.method( - #copy, + #scrollBy, + [ + x, + y, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setContentOffset( + double? x, + double? y, + ) => + (super.noSuchMethod( + Invocation.method( + #setContentOffset, + [ + x, + y, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setDelegate(_i2.UIScrollViewDelegate? delegate) => + (super.noSuchMethod( + Invocation.method( + #setDelegate, + [delegate], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i2.UIScrollView pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, [], ), - returnValue: _FakeNSObject_0( + returnValue: _FakeUIScrollView_1( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeUIScrollView_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i2.NSObject); + ) as _i2.UIScrollView); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future setBackgroundColor(int? value) => (super.noSuchMethod( + Invocation.method( + #setBackgroundColor, + [value], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setOpaque(bool? opaque) => (super.noSuchMethod( + Invocation.method( + #setOpaque, + [opaque], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } -/// A class which mocks [UIScrollView]. +/// A class which mocks [UIScrollViewDelegate]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockUIScrollView extends _i1.Mock implements _i4.UIScrollView { - MockUIScrollView() { - _i1.throwOnMissingStub(this); - } +class MockUIScrollViewDelegate extends _i1.Mock + implements _i2.UIScrollViewDelegate { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i6.Future<_i3.Point> getContentOffset() => (super.noSuchMethod( + _i2.UIScrollViewDelegate pigeon_copy() => (super.noSuchMethod( Invocation.method( - #getContentOffset, + #pigeon_copy, [], ), - returnValue: _i6.Future<_i3.Point>.value(_FakePoint_1( + returnValue: _FakeUIScrollViewDelegate_2( this, Invocation.method( - #getContentOffset, + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeUIScrollViewDelegate_2( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.UIScrollViewDelegate); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [URL]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockURL extends _i1.Mock implements _i2.URL { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future getAbsoluteString() => (super.noSuchMethod( + Invocation.method( + #getAbsoluteString, + [], + ), + returnValue: _i3.Future.value(_i4.dummyValue( + this, + Invocation.method( + #getAbsoluteString, [], ), )), - ) as _i6.Future<_i3.Point>); + returnValueForMissingStub: + _i3.Future.value(_i4.dummyValue( + this, + Invocation.method( + #getAbsoluteString, + [], + ), + )), + ) as _i3.Future); @override - _i6.Future scrollBy(_i3.Point? offset) => (super.noSuchMethod( + _i2.URL pigeon_copy() => (super.noSuchMethod( Invocation.method( - #scrollBy, - [offset], + #pigeon_copy, + [], + ), + returnValue: _FakeURL_3( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeURL_3( + this, + Invocation.method( + #pigeon_copy, + [], + ), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.URL); @override - _i6.Future setContentOffset(_i3.Point? offset) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( - #setContentOffset, - [offset], + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setDelegate(_i4.UIScrollViewDelegate? delegate) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( - #setDelegate, - [delegate], + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [URLRequest]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockURLRequest extends _i1.Mock implements _i2.URLRequest { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future getUrl() => (super.noSuchMethod( + Invocation.method( + #getUrl, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setHttpMethod(String? method) => (super.noSuchMethod( + Invocation.method( + #setHttpMethod, + [method], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future getHttpMethod() => (super.noSuchMethod( + Invocation.method( + #getHttpMethod, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future setHttpBody(_i5.Uint8List? body) => (super.noSuchMethod( + Invocation.method( + #setHttpBody, + [body], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i4.UIScrollView copy() => (super.noSuchMethod( + _i3.Future<_i5.Uint8List?> getHttpBody() => (super.noSuchMethod( Invocation.method( - #copy, + #getHttpBody, [], ), - returnValue: _FakeUIScrollView_2( + returnValue: _i3.Future<_i5.Uint8List?>.value(), + returnValueForMissingStub: _i3.Future<_i5.Uint8List?>.value(), + ) as _i3.Future<_i5.Uint8List?>); + + @override + _i3.Future setAllHttpHeaderFields(Map? fields) => + (super.noSuchMethod( + Invocation.method( + #setAllHttpHeaderFields, + [fields], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future?> getAllHttpHeaderFields() => + (super.noSuchMethod( + Invocation.method( + #getAllHttpHeaderFields, + [], + ), + returnValue: _i3.Future?>.value(), + returnValueForMissingStub: _i3.Future?>.value(), + ) as _i3.Future?>); + + @override + _i2.URLRequest pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeURLRequest_4( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.UIScrollView); + returnValueForMissingStub: _FakeURLRequest_4( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.URLRequest); @override - _i6.Future setBackgroundColor(_i7.Color? color) => (super.noSuchMethod( + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( Invocation.method( - #setBackgroundColor, - [color], + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setOpaque(bool? opaque) => (super.noSuchMethod( + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( Invocation.method( - #setOpaque, - [opaque], + #removeObserver, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} +/// A class which mocks [WKPreferences]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKPreferences extends _i1.Mock implements _i2.WKPreferences { @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future setJavaScriptEnabled(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setJavaScriptEnabled, + [enabled], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i2.WKPreferences pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeWKPreferences_5( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKPreferences_5( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WKPreferences); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } -/// A class which mocks [UIScrollViewDelegate]. +/// A class which mocks [WKScriptMessageHandler]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockUIScrollViewDelegate extends _i1.Mock - implements _i4.UIScrollViewDelegate { - MockUIScrollViewDelegate() { - _i1.throwOnMissingStub(this); - } +class MockWKScriptMessageHandler extends _i1.Mock + implements _i2.WKScriptMessageHandler { + @override + void Function( + _i2.WKScriptMessageHandler, + _i2.WKUserContentController, + _i2.WKScriptMessage, + ) get didReceiveScriptMessage => (super.noSuchMethod( + Invocation.getter(#didReceiveScriptMessage), + returnValue: ( + _i2.WKScriptMessageHandler pigeon_instance, + _i2.WKUserContentController controller, + _i2.WKScriptMessage message, + ) {}, + returnValueForMissingStub: ( + _i2.WKScriptMessageHandler pigeon_instance, + _i2.WKUserContentController controller, + _i2.WKScriptMessage message, + ) {}, + ) as void Function( + _i2.WKScriptMessageHandler, + _i2.WKUserContentController, + _i2.WKScriptMessage, + )); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i4.UIScrollViewDelegate copy() => (super.noSuchMethod( + _i2.WKScriptMessageHandler pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeUIScrollViewDelegate_3( + returnValue: _FakeWKScriptMessageHandler_6( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i4.UIScrollViewDelegate); + returnValueForMissingStub: _FakeWKScriptMessageHandler_6( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WKScriptMessageHandler); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } -/// A class which mocks [WKPreferences]. +/// A class which mocks [WKUserContentController]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKPreferences extends _i1.Mock implements _i5.WKPreferences { - MockWKPreferences() { - _i1.throwOnMissingStub(this); - } +class MockWKUserContentController extends _i1.Mock + implements _i2.WKUserContentController { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i6.Future setJavaScriptEnabled(bool? enabled) => (super.noSuchMethod( + _i3.Future addScriptMessageHandler( + _i2.WKScriptMessageHandler? handler, + String? name, + ) => + (super.noSuchMethod( Invocation.method( - #setJavaScriptEnabled, - [enabled], + #addScriptMessageHandler, + [ + handler, + name, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeScriptMessageHandler(String? name) => + (super.noSuchMethod( + Invocation.method( + #removeScriptMessageHandler, + [name], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( + Invocation.method( + #removeAllScriptMessageHandlers, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future addUserScript(_i2.WKUserScript? userScript) => + (super.noSuchMethod( + Invocation.method( + #addUserScript, + [userScript], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeAllUserScripts() => (super.noSuchMethod( + Invocation.method( + #removeAllUserScripts, + [], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i2.WKUserContentController pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeWKUserContentController_7( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKUserContentController_7( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WKUserContentController); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [WKUserScript]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKUserScript extends _i1.Mock implements _i2.WKUserScript { + @override + String get source => (super.noSuchMethod( + Invocation.getter(#source), + returnValue: _i4.dummyValue( + this, + Invocation.getter(#source), + ), + returnValueForMissingStub: _i4.dummyValue( + this, + Invocation.getter(#source), + ), + ) as String); + + @override + _i2.UserScriptInjectionTime get injectionTime => (super.noSuchMethod( + Invocation.getter(#injectionTime), + returnValue: _i2.UserScriptInjectionTime.atDocumentStart, + returnValueForMissingStub: _i2.UserScriptInjectionTime.atDocumentStart, + ) as _i2.UserScriptInjectionTime); + + @override + bool get isForMainFrameOnly => (super.noSuchMethod( + Invocation.getter(#isForMainFrameOnly), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKUserScript pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeWKUserScript_8( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKUserScript_8( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WKUserScript); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [WKWebView]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKWebView extends _i1.Mock implements _i2.WKWebView { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.PigeonInstanceManager); @override - _i5.WKPreferences copy() => (super.noSuchMethod( + _i2.WKWebView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKPreferences_4( + returnValue: _FakeWKWebView_9( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKWebView_9( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i5.WKPreferences); + ) as _i2.WKWebView); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } -/// A class which mocks [WKUserContentController]. +/// A class which mocks [WKWebViewConfiguration]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKUserContentController extends _i1.Mock - implements _i5.WKUserContentController { - MockWKUserContentController() { - _i1.throwOnMissingStub(this); - } +class MockWKWebViewConfiguration extends _i1.Mock + implements _i2.WKWebViewConfiguration { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i6.Future addScriptMessageHandler( - _i5.WKScriptMessageHandler? handler, - String? name, - ) => + _i3.Future setUserContentController( + _i2.WKUserContentController? controller) => (super.noSuchMethod( Invocation.method( - #addScriptMessageHandler, - [ - handler, - name, - ], + #setUserContentController, + [controller], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeScriptMessageHandler(String? name) => + _i3.Future<_i2.WKUserContentController> getUserContentController() => (super.noSuchMethod( Invocation.method( - #removeScriptMessageHandler, - [name], + #getUserContentController, + [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future<_i2.WKUserContentController>.value( + _FakeWKUserContentController_7( + this, + Invocation.method( + #getUserContentController, + [], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.WKUserContentController>.value( + _FakeWKUserContentController_7( + this, + Invocation.method( + #getUserContentController, + [], + ), + )), + ) as _i3.Future<_i2.WKUserContentController>); @override - _i6.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( + _i3.Future setWebsiteDataStore(_i2.WKWebsiteDataStore? dataStore) => + (super.noSuchMethod( Invocation.method( - #removeAllScriptMessageHandlers, - [], + #setWebsiteDataStore, + [dataStore], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future addUserScript(_i5.WKUserScript? userScript) => + _i3.Future<_i2.WKWebsiteDataStore> getWebsiteDataStore() => (super.noSuchMethod( Invocation.method( - #addUserScript, - [userScript], + #getWebsiteDataStore, + [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: + _i3.Future<_i2.WKWebsiteDataStore>.value(_FakeWKWebsiteDataStore_10( + this, + Invocation.method( + #getWebsiteDataStore, + [], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.WKWebsiteDataStore>.value(_FakeWKWebsiteDataStore_10( + this, + Invocation.method( + #getWebsiteDataStore, + [], + ), + )), + ) as _i3.Future<_i2.WKWebsiteDataStore>); @override - _i6.Future removeAllUserScripts() => (super.noSuchMethod( + _i3.Future setPreferences(_i2.WKPreferences? preferences) => + (super.noSuchMethod( Invocation.method( - #removeAllUserScripts, - [], + #setPreferences, + [preferences], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i5.WKUserContentController copy() => (super.noSuchMethod( + _i3.Future<_i2.WKPreferences> getPreferences() => (super.noSuchMethod( Invocation.method( - #copy, + #getPreferences, [], ), - returnValue: _FakeWKUserContentController_5( + returnValue: _i3.Future<_i2.WKPreferences>.value(_FakeWKPreferences_5( this, Invocation.method( - #copy, + #getPreferences, [], ), - ), - ) as _i5.WKUserContentController); + )), + returnValueForMissingStub: + _i3.Future<_i2.WKPreferences>.value(_FakeWKPreferences_5( + this, + Invocation.method( + #getPreferences, + [], + ), + )), + ) as _i3.Future<_i2.WKPreferences>); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future setAllowsInlineMediaPlayback(bool? allow) => (super.noSuchMethod( Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + #setAllowsInlineMediaPlayback, + [allow], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future setLimitsNavigationsToAppBoundDomains(bool? limit) => (super.noSuchMethod( Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); -} - -/// A class which mocks [WKWebsiteDataStore]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKWebsiteDataStore extends _i1.Mock - implements _i5.WKWebsiteDataStore { - MockWKWebsiteDataStore() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod( - Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_6( - this, - Invocation.getter(#httpCookieStore), + #setLimitsNavigationsToAppBoundDomains, + [limit], ), - ) as _i5.WKHttpCookieStore); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeDataOfTypes( - Set<_i5.WKWebsiteDataType>? dataTypes, - DateTime? since, - ) => + _i3.Future setMediaTypesRequiringUserActionForPlayback( + _i2.AudiovisualMediaType? type) => (super.noSuchMethod( Invocation.method( - #removeDataOfTypes, - [ - dataTypes, - since, - ], + #setMediaTypesRequiringUserActionForPlayback, + [type], ), - returnValue: _i6.Future.value(false), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i5.WKWebsiteDataStore copy() => (super.noSuchMethod( + _i2.WKWebViewConfiguration pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebsiteDataStore_7( + returnValue: _FakeWKWebViewConfiguration_11( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKWebViewConfiguration_11( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i5.WKWebsiteDataStore); + ) as _i2.WKWebViewConfiguration); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } -/// A class which mocks [WKWebViewIOS]. +/// A class which mocks [UIViewWKWebView]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKWebViewIOS extends _i1.Mock implements _i5.WKWebViewIOS { - MockWKWebViewIOS() { - _i1.throwOnMissingStub(this); - } +class MockUIViewWKWebView extends _i1.Mock implements _i2.UIViewWKWebView { + @override + _i2.WKWebViewConfiguration get configuration => (super.noSuchMethod( + Invocation.getter(#configuration), + returnValue: _FakeWKWebViewConfiguration_11( + this, + Invocation.getter(#configuration), + ), + returnValueForMissingStub: _FakeWKWebViewConfiguration_11( + this, + Invocation.getter(#configuration), + ), + ) as _i2.WKWebViewConfiguration); @override - _i4.UIScrollView get scrollView => (super.noSuchMethod( + _i2.UIScrollView get scrollView => (super.noSuchMethod( Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_2( + returnValue: _FakeUIScrollView_1( + this, + Invocation.getter(#scrollView), + ), + returnValueForMissingStub: _FakeUIScrollView_1( this, Invocation.getter(#scrollView), ), - ) as _i4.UIScrollView); + ) as _i2.UIScrollView); @override - _i5.WKWebViewConfiguration get configuration => (super.noSuchMethod( - Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_8( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( this, - Invocation.getter(#configuration), + Invocation.getter(#pigeon_instanceManager), ), - ) as _i5.WKWebViewConfiguration); + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i5.WKWebView copy() => (super.noSuchMethod( + _i2.WKWebViewConfiguration pigeonVar_configuration() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeonVar_configuration, [], ), - returnValue: _FakeWKWebView_9( + returnValue: _FakeWKWebViewConfiguration_11( this, Invocation.method( - #copy, + #pigeonVar_configuration, [], ), ), - ) as _i5.WKWebView); - - @override - _i6.Future setBackgroundColor(_i7.Color? color) => (super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [color], + returnValueForMissingStub: _FakeWKWebViewConfiguration_11( + this, + Invocation.method( + #pigeonVar_configuration, + [], + ), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.WKWebViewConfiguration); @override - _i6.Future setOpaque(bool? opaque) => (super.noSuchMethod( + _i2.UIScrollView pigeonVar_scrollView() => (super.noSuchMethod( Invocation.method( - #setOpaque, - [opaque], + #pigeonVar_scrollView, + [], + ), + returnValue: _FakeUIScrollView_1( + this, + Invocation.method( + #pigeonVar_scrollView, + [], + ), + ), + returnValueForMissingStub: _FakeUIScrollView_1( + this, + Invocation.method( + #pigeonVar_scrollView, + [], + ), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.UIScrollView); @override - _i6.Future setUIDelegate(_i5.WKUIDelegate? delegate) => + _i3.Future setUIDelegate(_i2.WKUIDelegate? delegate) => (super.noSuchMethod( Invocation.method( #setUIDelegate, [delegate], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setNavigationDelegate(_i5.WKNavigationDelegate? delegate) => + _i3.Future setNavigationDelegate(_i2.WKNavigationDelegate? delegate) => (super.noSuchMethod( Invocation.method( #setNavigationDelegate, [delegate], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future getUrl() => (super.noSuchMethod( + _i3.Future getUrl() => (super.noSuchMethod( Invocation.method( #getUrl, [], ), - returnValue: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future getEstimatedProgress() => (super.noSuchMethod( + _i3.Future getEstimatedProgress() => (super.noSuchMethod( Invocation.method( #getEstimatedProgress, [], ), - returnValue: _i6.Future.value(0.0), - ) as _i6.Future); + returnValue: _i3.Future.value(0.0), + returnValueForMissingStub: _i3.Future.value(0.0), + ) as _i3.Future); @override - _i6.Future loadRequest(_i2.NSUrlRequest? request) => - (super.noSuchMethod( + _i3.Future load(_i2.URLRequest? request) => (super.noSuchMethod( Invocation.method( - #loadRequest, + #load, [request], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future loadHtmlString( - String? string, { + _i3.Future loadHtmlString( + String? string, String? baseUrl, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadHtmlString, - [string], - {#baseUrl: baseUrl}, + [ + string, + baseUrl, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future loadFileUrl( - String? url, { - required String? readAccessUrl, - }) => + _i3.Future loadFileUrl( + String? url, + String? readAccessUrl, + ) => (super.noSuchMethod( Invocation.method( #loadFileUrl, - [url], - {#readAccessUrl: readAccessUrl}, + [ + url, + readAccessUrl, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future loadFlutterAsset(String? key) => (super.noSuchMethod( + _i3.Future loadFlutterAsset(String? key) => (super.noSuchMethod( Invocation.method( #loadFlutterAsset, [key], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future canGoBack() => (super.noSuchMethod( + _i3.Future canGoBack() => (super.noSuchMethod( Invocation.method( #canGoBack, [], ), - returnValue: _i6.Future.value(false), - ) as _i6.Future); + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) as _i3.Future); @override - _i6.Future canGoForward() => (super.noSuchMethod( + _i3.Future canGoForward() => (super.noSuchMethod( Invocation.method( #canGoForward, [], ), - returnValue: _i6.Future.value(false), - ) as _i6.Future); + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) as _i3.Future); @override - _i6.Future goBack() => (super.noSuchMethod( + _i3.Future goBack() => (super.noSuchMethod( Invocation.method( #goBack, [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future goForward() => (super.noSuchMethod( + _i3.Future goForward() => (super.noSuchMethod( Invocation.method( #goForward, [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future reload() => (super.noSuchMethod( + _i3.Future reload() => (super.noSuchMethod( Invocation.method( #reload, [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future getTitle() => (super.noSuchMethod( + _i3.Future getTitle() => (super.noSuchMethod( Invocation.method( #getTitle, [], ), - returnValue: _i6.Future.value(), - ) as _i6.Future); - - @override - _i6.Future getCustomUserAgent() => (super.noSuchMethod( - Invocation.method( - #getCustomUserAgent, - [], - ), - returnValue: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setAllowsBackForwardNavigationGestures(bool? allow) => + _i3.Future setAllowsBackForwardNavigationGestures(bool? allow) => (super.noSuchMethod( Invocation.method( #setAllowsBackForwardNavigationGestures, [allow], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( + _i3.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod( Invocation.method( #setCustomUserAgent, [userAgent], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future evaluateJavaScript(String? javaScriptString) => + _i3.Future evaluateJavaScript(String? javaScriptString) => (super.noSuchMethod( Invocation.method( #evaluateJavaScript, [javaScriptString], ), - returnValue: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setInspectable(bool? inspectable) => (super.noSuchMethod( + _i3.Future setInspectable(bool? inspectable) => (super.noSuchMethod( Invocation.method( #setInspectable, [inspectable], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => - (super.noSuchMethod( + _i3.Future getCustomUserAgent() => (super.noSuchMethod( Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + #getCustomUserAgent, + [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => - (super.noSuchMethod( + _i2.UIViewWKWebView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, + #pigeon_copy, + [], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); -} - -/// A class which mocks [WKWebViewConfiguration]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKWebViewConfiguration extends _i1.Mock - implements _i5.WKWebViewConfiguration { - MockWKWebViewConfiguration() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.WKUserContentController get userContentController => (super.noSuchMethod( - Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_5( + returnValue: _FakeUIViewWKWebView_12( this, - Invocation.getter(#userContentController), + Invocation.method( + #pigeon_copy, + [], + ), ), - ) as _i5.WKUserContentController); - - @override - _i5.WKPreferences get preferences => (super.noSuchMethod( - Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_4( + returnValueForMissingStub: _FakeUIViewWKWebView_12( this, - Invocation.getter(#preferences), + Invocation.method( + #pigeon_copy, + [], + ), ), - ) as _i5.WKPreferences); + ) as _i2.UIViewWKWebView); @override - _i5.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod( - Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_7( - this, - Invocation.getter(#websiteDataStore), + _i3.Future setBackgroundColor(int? value) => (super.noSuchMethod( + Invocation.method( + #setBackgroundColor, + [value], ), - ) as _i5.WKWebsiteDataStore); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setAllowsInlineMediaPlayback(bool? allow) => - (super.noSuchMethod( + _i3.Future setOpaque(bool? opaque) => (super.noSuchMethod( Invocation.method( - #setAllowsInlineMediaPlayback, - [allow], + #setOpaque, + [opaque], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setLimitsNavigationsToAppBoundDomains(bool? limit) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( - #setLimitsNavigationsToAppBoundDomains, - [limit], + #addObserver, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future setMediaTypesRequiringUserActionForPlayback( - Set<_i5.WKAudiovisualMediaType>? types) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( - #setMediaTypesRequiringUserActionForPlayback, - [types], + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [WKWebsiteDataStore]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWKWebsiteDataStore extends _i1.Mock + implements _i2.WKWebsiteDataStore { + @override + _i2.WKHTTPCookieStore get httpCookieStore => (super.noSuchMethod( + Invocation.getter(#httpCookieStore), + returnValue: _FakeWKHTTPCookieStore_13( + this, + Invocation.getter(#httpCookieStore), + ), + returnValueForMissingStub: _FakeWKHTTPCookieStore_13( + this, + Invocation.getter(#httpCookieStore), + ), + ) as _i2.WKHTTPCookieStore); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.PigeonInstanceManager); @override - _i5.WKWebViewConfiguration copy() => (super.noSuchMethod( + _i2.WKHTTPCookieStore pigeonVar_httpCookieStore() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeonVar_httpCookieStore, [], ), - returnValue: _FakeWKWebViewConfiguration_8( + returnValue: _FakeWKHTTPCookieStore_13( this, Invocation.method( - #copy, + #pigeonVar_httpCookieStore, [], ), ), - ) as _i5.WKWebViewConfiguration); - - @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => - (super.noSuchMethod( - Invocation.method( - #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + returnValueForMissingStub: _FakeWKHTTPCookieStore_13( + this, + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + ) as _i2.WKHTTPCookieStore); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeDataOfTypes( + List<_i2.WebsiteDataType>? dataTypes, + double? modificationTimeInSecondsSinceEpoch, + ) => (super.noSuchMethod( Invocation.method( - #removeObserver, - [observer], - {#keyPath: keyPath}, + #removeDataOfTypes, + [ + dataTypes, + modificationTimeInSecondsSinceEpoch, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); -} - -/// A class which mocks [WKScriptMessageHandler]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKScriptMessageHandler extends _i1.Mock - implements _i5.WKScriptMessageHandler { - MockWKScriptMessageHandler() { - _i1.throwOnMissingStub(this); - } - - @override - void Function( - _i5.WKUserContentController, - _i5.WKScriptMessage, - ) get didReceiveScriptMessage => (super.noSuchMethod( - Invocation.getter(#didReceiveScriptMessage), - returnValue: ( - _i5.WKUserContentController userContentController, - _i5.WKScriptMessage message, - ) {}, - ) as void Function( - _i5.WKUserContentController, - _i5.WKScriptMessage, - )); + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) as _i3.Future); @override - _i5.WKScriptMessageHandler copy() => (super.noSuchMethod( + _i2.WKWebsiteDataStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKScriptMessageHandler_10( + returnValue: _FakeWKWebsiteDataStore_10( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWKWebsiteDataStore_10( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i5.WKScriptMessageHandler); + ) as _i2.WKWebsiteDataStore); @override - _i6.Future addObserver( - _i2.NSObject? observer, { - required String? keyPath, - required Set<_i2.NSKeyValueObservingOptions>? options, - }) => + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i6.Future removeObserver( - _i2.NSObject? observer, { - required String? keyPath, - }) => + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.dart index a9dd742bd670..429ac1988821 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.dart @@ -7,14 +7,13 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; import 'webkit_webview_cookie_manager_test.mocks.dart'; -@GenerateMocks([WKWebsiteDataStore, WKHttpCookieStore]) +@GenerateMocks([WKWebsiteDataStore, WKHTTPCookieStore]) void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -26,23 +25,23 @@ void main() { final WebKitWebViewCookieManager manager = WebKitWebViewCookieManager( WebKitWebViewCookieManagerCreationParams( webKitProxy: WebKitProxy( - defaultWebsiteDataStore: () => mockWKWebsiteDataStore, + defaultDataStoreWKWebsiteDataStore: () => mockWKWebsiteDataStore, ), ), ); when( mockWKWebsiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, - any, + [WebsiteDataType.cookies], + 0.0, ), ).thenAnswer((_) => Future.value(true)); expect(manager.clearCookies(), completion(true)); when( mockWKWebsiteDataStore.removeDataOfTypes( - {WKWebsiteDataType.cookies}, - any, + [WebsiteDataType.cookies], + 0.0, ), ).thenAnswer((_) => Future.value(false)); expect(manager.clearCookies(), completion(false)); @@ -52,13 +51,23 @@ void main() { final MockWKWebsiteDataStore mockWKWebsiteDataStore = MockWKWebsiteDataStore(); - final MockWKHttpCookieStore mockCookieStore = MockWKHttpCookieStore(); + final MockWKHTTPCookieStore mockCookieStore = MockWKHTTPCookieStore(); when(mockWKWebsiteDataStore.httpCookieStore).thenReturn(mockCookieStore); + Map? cookieProperties; + final HTTPCookie cookie = HTTPCookie.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ); final WebKitWebViewCookieManager manager = WebKitWebViewCookieManager( WebKitWebViewCookieManagerCreationParams( webKitProxy: WebKitProxy( - defaultWebsiteDataStore: () => mockWKWebsiteDataStore, + defaultDataStoreWKWebsiteDataStore: () => mockWKWebsiteDataStore, + newHTTPCookie: ({ + required Map properties, + }) { + cookieProperties = properties; + return cookie; + }, ), ), ); @@ -67,16 +76,14 @@ void main() { const WebViewCookie(name: 'a', value: 'b', domain: 'c', path: 'd'), ); - final NSHttpCookie cookie = verify(mockCookieStore.setCookie(captureAny)) - .captured - .single as NSHttpCookie; + verify(mockCookieStore.setCookie(cookie)); expect( - cookie.properties, - { - NSHttpCookiePropertyKey.name: 'a', - NSHttpCookiePropertyKey.value: 'b', - NSHttpCookiePropertyKey.domain: 'c', - NSHttpCookiePropertyKey.path: 'd', + cookieProperties, + { + HttpCookiePropertyKey.name: 'a', + HttpCookiePropertyKey.value: 'b', + HttpCookiePropertyKey.domain: 'c', + HttpCookiePropertyKey.path: 'd', }, ); }); @@ -85,13 +92,13 @@ void main() { final MockWKWebsiteDataStore mockWKWebsiteDataStore = MockWKWebsiteDataStore(); - final MockWKHttpCookieStore mockCookieStore = MockWKHttpCookieStore(); + final MockWKHTTPCookieStore mockCookieStore = MockWKHTTPCookieStore(); when(mockWKWebsiteDataStore.httpCookieStore).thenReturn(mockCookieStore); final WebKitWebViewCookieManager manager = WebKitWebViewCookieManager( WebKitWebViewCookieManagerCreationParams( webKitProxy: WebKitProxy( - defaultWebsiteDataStore: () => mockWKWebsiteDataStore, + defaultDataStoreWKWebsiteDataStore: () => mockWKWebsiteDataStore, ), ), ); @@ -110,3 +117,8 @@ void main() { }); }); } + +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.mocks.dart index bda15f7cec78..ce95b63531d7 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_cookie_manager_test.mocks.dart @@ -6,9 +6,7 @@ import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i4; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -23,9 +21,9 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeWKHttpCookieStore_0 extends _i1.SmartFake - implements _i2.WKHttpCookieStore { - _FakeWKHttpCookieStore_0( +class _FakeWKHTTPCookieStore_0 extends _i1.SmartFake + implements _i2.WKHTTPCookieStore { + _FakeWKHTTPCookieStore_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,9 +32,20 @@ class _FakeWKHttpCookieStore_0 extends _i1.SmartFake ); } -class _FakeWKWebsiteDataStore_1 extends _i1.SmartFake +class _FakePigeonInstanceManager_1 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWKWebsiteDataStore_2 extends _i1.SmartFake implements _i2.WKWebsiteDataStore { - _FakeWKWebsiteDataStore_1( + _FakeWKWebsiteDataStore_2( Object parent, Invocation parentInvocation, ) : super( @@ -48,7 +57,6 @@ class _FakeWKWebsiteDataStore_1 extends _i1.SmartFake /// A class which mocks [WKWebsiteDataStore]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKWebsiteDataStore extends _i1.Mock implements _i2.WKWebsiteDataStore { MockWKWebsiteDataStore() { @@ -56,40 +64,64 @@ class MockWKWebsiteDataStore extends _i1.Mock } @override - _i2.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod( + _i2.WKHTTPCookieStore get httpCookieStore => (super.noSuchMethod( Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_0( + returnValue: _FakeWKHTTPCookieStore_0( this, Invocation.getter(#httpCookieStore), ), - ) as _i2.WKHttpCookieStore); + ) as _i2.WKHTTPCookieStore); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_1( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKHTTPCookieStore pigeonVar_httpCookieStore() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + returnValue: _FakeWKHTTPCookieStore_0( + this, + Invocation.method( + #pigeonVar_httpCookieStore, + [], + ), + ), + ) as _i2.WKHTTPCookieStore); @override _i3.Future removeDataOfTypes( - Set<_i2.WKWebsiteDataType>? dataTypes, - DateTime? since, + List<_i2.WebsiteDataType>? dataTypes, + double? modificationTimeInSecondsSinceEpoch, ) => (super.noSuchMethod( Invocation.method( #removeDataOfTypes, [ dataTypes, - since, + modificationTimeInSecondsSinceEpoch, ], ), returnValue: _i3.Future.value(false), ) as _i3.Future); @override - _i2.WKWebsiteDataStore copy() => (super.noSuchMethod( + _i2.WKWebsiteDataStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebsiteDataStore_1( + returnValue: _FakeWKWebsiteDataStore_2( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -97,18 +129,18 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -116,31 +148,41 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), ) as _i3.Future); } -/// A class which mocks [WKHttpCookieStore]. +/// A class which mocks [WKHTTPCookieStore]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { - MockWKHttpCookieStore() { +class MockWKHTTPCookieStore extends _i1.Mock implements _i2.WKHTTPCookieStore { + MockWKHTTPCookieStore() { _i1.throwOnMissingStub(this); } @override - _i3.Future setCookie(_i4.NSHttpCookie? cookie) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_1( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future setCookie(_i2.HTTPCookie? cookie) => (super.noSuchMethod( Invocation.method( #setCookie, [cookie], @@ -150,34 +192,34 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { ) as _i3.Future); @override - _i2.WKHttpCookieStore copy() => (super.noSuchMethod( + _i2.WKHTTPCookieStore pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKHttpCookieStore_0( + returnValue: _FakeWKHTTPCookieStore_0( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i2.WKHttpCookieStore); + ) as _i2.WKHTTPCookieStore); @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -185,14 +227,16 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.dart index 3a17047c3edb..3ddfa7dd0984 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.dart @@ -2,31 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io'; - +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart'; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart'; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; +import 'package:webview_flutter_wkwebview/src/common/platform_webview.dart'; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart'; import 'package:webview_flutter_wkwebview/src/webkit_proxy.dart'; import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart'; -import 'webkit_webview_controller_test.mocks.dart' - show MockUIScrollViewDelegate; + import 'webkit_webview_widget_test.mocks.dart'; -@GenerateMocks([WKUIDelegate, WKWebViewConfiguration]) +@GenerateMocks([ + WKUIDelegate, + WKWebViewConfiguration, + UIScrollViewDelegate, +]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('WebKitWebViewWidget', () { testWidgets('build', (WidgetTester tester) async { - final InstanceManager testInstanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); + final PigeonInstanceManager testInstanceManager = TestInstanceManager(); final WebKitWebViewController controller = createTestWebViewController(testInstanceManager); @@ -43,16 +41,20 @@ void main() { Builder(builder: (BuildContext context) => widget.build(context)), ); - expect(find.byType(Platform.isMacOS ? AppKitView : UiKitView), - findsOneWidget); + expect( + find.byType( + defaultTargetPlatform == TargetPlatform.macOS + ? AppKitView + : UiKitView, + ), + findsOneWidget, + ); expect(find.byKey(const Key('keyValue')), findsOneWidget); }); testWidgets('Key of the PlatformView changes when the controller changes', (WidgetTester tester) async { - final InstanceManager testInstanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); + final PigeonInstanceManager testInstanceManager = TestInstanceManager(); // Pump WebViewWidget with first controller. final WebKitWebViewController controller1 = @@ -119,9 +121,7 @@ void main() { testWidgets( 'Key of the PlatformView is the same when the creation params are equal', (WidgetTester tester) async { - final InstanceManager testInstanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); + final PigeonInstanceManager testInstanceManager = TestInstanceManager(); final WebKitWebViewController controller = createTestWebViewController(testInstanceManager); @@ -177,50 +177,59 @@ void main() { } WebKitWebViewController createTestWebViewController( - InstanceManager testInstanceManager, + PigeonInstanceManager testInstanceManager, ) { return WebKitWebViewController( WebKitWebViewControllerCreationParams( - webKitProxy: WebKitProxy(createWebView: ( - WKWebViewConfiguration configuration, { - void Function( - String keyPath, - NSObject object, - Map change, - )? observeValue, - InstanceManager? instanceManager, - }) { - final WKWebView webView = WKWebViewIOS.detached( - instanceManager: testInstanceManager, - ); - testInstanceManager.addDartCreatedInstance(webView); - return webView; - }, createWebViewConfiguration: ({InstanceManager? instanceManager}) { - return MockWKWebViewConfiguration(); - }, createUIDelegate: ({ - dynamic onCreateWebView, - dynamic requestMediaCapturePermission, - dynamic runJavaScriptAlertDialog, - dynamic runJavaScriptConfirmDialog, - dynamic runJavaScriptTextInputDialog, - InstanceManager? instanceManager, - }) { - final MockWKUIDelegate mockWKUIDelegate = MockWKUIDelegate(); - when(mockWKUIDelegate.copy()).thenReturn(MockWKUIDelegate()); - - testInstanceManager.addDartCreatedInstance(mockWKUIDelegate); - return mockWKUIDelegate; - }, createUIScrollViewDelegate: ({ - void Function(UIScrollView, double, double)? scrollViewDidScroll, - }) { - final MockUIScrollViewDelegate mockScrollViewDelegate = - MockUIScrollViewDelegate(); - when(mockScrollViewDelegate.copy()) - .thenReturn(MockUIScrollViewDelegate()); - - testInstanceManager.addDartCreatedInstance(mockScrollViewDelegate); - return mockScrollViewDelegate; - }), + webKitProxy: WebKitProxy( + newPlatformWebView: ({ + required WKWebViewConfiguration initialConfiguration, + void Function( + NSObject, + String?, + NSObject?, + Map?, + )? observeValue, + }) { + final UIViewWKWebView webView = UIViewWKWebView.pigeon_detached( + pigeon_instanceManager: testInstanceManager, + ); + testInstanceManager.addDartCreatedInstance(webView); + return PlatformWebView.fromNativeWebView(webView); + }, + newWKWebViewConfiguration: () { + return MockWKWebViewConfiguration(); + }, + newWKUIDelegate: ({ + dynamic onCreateWebView, + dynamic requestMediaCapturePermission, + dynamic runJavaScriptAlertPanel, + dynamic runJavaScriptConfirmPanel, + dynamic runJavaScriptTextInputPanel, + }) { + final MockWKUIDelegate mockWKUIDelegate = MockWKUIDelegate(); + when(mockWKUIDelegate.pigeon_copy()).thenReturn(MockWKUIDelegate()); + + testInstanceManager.addDartCreatedInstance(mockWKUIDelegate); + return mockWKUIDelegate; + }, + newUIScrollViewDelegate: ({ + dynamic scrollViewDidScroll, + }) { + final MockUIScrollViewDelegate mockScrollViewDelegate = + MockUIScrollViewDelegate(); + when(mockScrollViewDelegate.pigeon_copy()) + .thenReturn(MockUIScrollViewDelegate()); + + testInstanceManager.addDartCreatedInstance(mockScrollViewDelegate); + return mockScrollViewDelegate; + }, + ), ), ); } + +// Test InstanceManager that sets `onWeakReferenceRemoved` as a noop. +class TestInstanceManager extends PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.mocks.dart index 2aff8e964b60..b99d333513dd 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.mocks.dart @@ -6,9 +6,7 @@ import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i4; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; +import 'package:webview_flutter_wkwebview/src/common/web_kit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -23,8 +21,9 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeWKUIDelegate_0 extends _i1.SmartFake implements _i2.WKUIDelegate { - _FakeWKUIDelegate_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -33,9 +32,8 @@ class _FakeWKUIDelegate_0 extends _i1.SmartFake implements _i2.WKUIDelegate { ); } -class _FakeWKUserContentController_1 extends _i1.SmartFake - implements _i2.WKUserContentController { - _FakeWKUserContentController_1( +class _FakeWKUIDelegate_1 extends _i1.SmartFake implements _i2.WKUIDelegate { + _FakeWKUIDelegate_1( Object parent, Invocation parentInvocation, ) : super( @@ -44,8 +42,9 @@ class _FakeWKUserContentController_1 extends _i1.SmartFake ); } -class _FakeWKPreferences_2 extends _i1.SmartFake implements _i2.WKPreferences { - _FakeWKPreferences_2( +class _FakeWKUserContentController_2 extends _i1.SmartFake + implements _i2.WKUserContentController { + _FakeWKUserContentController_2( Object parent, Invocation parentInvocation, ) : super( @@ -65,9 +64,30 @@ class _FakeWKWebsiteDataStore_3 extends _i1.SmartFake ); } -class _FakeWKWebViewConfiguration_4 extends _i1.SmartFake +class _FakeWKPreferences_4 extends _i1.SmartFake implements _i2.WKPreferences { + _FakeWKPreferences_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWKWebViewConfiguration_5 extends _i1.SmartFake implements _i2.WKWebViewConfiguration { - _FakeWKWebViewConfiguration_4( + _FakeWKWebViewConfiguration_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUIScrollViewDelegate_6 extends _i1.SmartFake + implements _i2.UIScrollViewDelegate { + _FakeUIScrollViewDelegate_6( Object parent, Invocation parentInvocation, ) : super( @@ -79,22 +99,30 @@ class _FakeWKWebViewConfiguration_4 extends _i1.SmartFake /// A class which mocks [WKUIDelegate]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { MockWKUIDelegate() { _i1.throwOnMissingStub(this); } @override - _i2.WKUIDelegate copy() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WKUIDelegate pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKUIDelegate_0( + returnValue: _FakeWKUIDelegate_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -102,18 +130,18 @@ class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -121,14 +149,16 @@ class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -138,7 +168,6 @@ class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { /// A class which mocks [WKWebViewConfiguration]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWKWebViewConfiguration extends _i1.Mock implements _i2.WKWebViewConfiguration { MockWKWebViewConfiguration() { @@ -146,31 +175,96 @@ class MockWKWebViewConfiguration extends _i1.Mock } @override - _i2.WKUserContentController get userContentController => (super.noSuchMethod( - Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_1( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( this, - Invocation.getter(#userContentController), + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future setUserContentController( + _i2.WKUserContentController? controller) => + (super.noSuchMethod( + Invocation.method( + #setUserContentController, + [controller], ), - ) as _i2.WKUserContentController); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i2.WKPreferences get preferences => (super.noSuchMethod( - Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_2( + _i3.Future<_i2.WKUserContentController> getUserContentController() => + (super.noSuchMethod( + Invocation.method( + #getUserContentController, + [], + ), + returnValue: _i3.Future<_i2.WKUserContentController>.value( + _FakeWKUserContentController_2( this, - Invocation.getter(#preferences), + Invocation.method( + #getUserContentController, + [], + ), + )), + ) as _i3.Future<_i2.WKUserContentController>); + + @override + _i3.Future setWebsiteDataStore(_i2.WKWebsiteDataStore? dataStore) => + (super.noSuchMethod( + Invocation.method( + #setWebsiteDataStore, + [dataStore], ), - ) as _i2.WKPreferences); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i2.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod( - Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_3( + _i3.Future<_i2.WKWebsiteDataStore> getWebsiteDataStore() => + (super.noSuchMethod( + Invocation.method( + #getWebsiteDataStore, + [], + ), + returnValue: + _i3.Future<_i2.WKWebsiteDataStore>.value(_FakeWKWebsiteDataStore_3( this, - Invocation.getter(#websiteDataStore), + Invocation.method( + #getWebsiteDataStore, + [], + ), + )), + ) as _i3.Future<_i2.WKWebsiteDataStore>); + + @override + _i3.Future setPreferences(_i2.WKPreferences? preferences) => + (super.noSuchMethod( + Invocation.method( + #setPreferences, + [preferences], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future<_i2.WKPreferences> getPreferences() => (super.noSuchMethod( + Invocation.method( + #getPreferences, + [], ), - ) as _i2.WKWebsiteDataStore); + returnValue: _i3.Future<_i2.WKPreferences>.value(_FakeWKPreferences_4( + this, + Invocation.method( + #getPreferences, + [], + ), + )), + ) as _i3.Future<_i2.WKPreferences>); @override _i3.Future setAllowsInlineMediaPlayback(bool? allow) => @@ -196,26 +290,26 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i3.Future setMediaTypesRequiringUserActionForPlayback( - Set<_i2.WKAudiovisualMediaType>? types) => + _i2.AudiovisualMediaType? type) => (super.noSuchMethod( Invocation.method( #setMediaTypesRequiringUserActionForPlayback, - [types], + [type], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), ) as _i3.Future); @override - _i2.WKWebViewConfiguration copy() => (super.noSuchMethod( + _i2.WKWebViewConfiguration pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWKWebViewConfiguration_4( + returnValue: _FakeWKWebViewConfiguration_5( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -223,18 +317,88 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i3.Future addObserver( - _i4.NSObject? observer, { - required String? keyPath, - required Set<_i4.NSKeyValueObservingOptions>? options, - }) => + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => + (super.noSuchMethod( + Invocation.method( + #addObserver, + [ + observer, + keyPath, + options, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); + + @override + _i3.Future removeObserver( + _i2.NSObject? observer, + String? keyPath, + ) => + (super.noSuchMethod( + Invocation.method( + #removeObserver, + [ + observer, + keyPath, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} + +/// A class which mocks [UIScrollViewDelegate]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockUIScrollViewDelegate extends _i1.Mock + implements _i2.UIScrollViewDelegate { + MockUIScrollViewDelegate() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.UIScrollViewDelegate pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeUIScrollViewDelegate_6( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.UIScrollViewDelegate); + + @override + _i3.Future addObserver( + _i2.NSObject? observer, + String? keyPath, + List<_i2.KeyValueObservingOptions>? options, + ) => (super.noSuchMethod( Invocation.method( #addObserver, - [observer], - { - #keyPath: keyPath, - #options: options, - }, + [ + observer, + keyPath, + options, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), @@ -242,14 +406,16 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i3.Future removeObserver( - _i4.NSObject? observer, { - required String? keyPath, - }) => + _i2.NSObject? observer, + String? keyPath, + ) => (super.noSuchMethod( Invocation.method( #removeObserver, - [observer], - {#keyPath: keyPath}, + [ + observer, + keyPath, + ], ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(),