diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m index 5a51e7b980f8..84d31d1c543e 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFScriptMessageHandlerHostApiTests.m @@ -45,8 +45,9 @@ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFScriptMessageHandlerHostApiImpl *hostAPI = - [[FWFScriptMessageHandlerHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFScriptMessageHandlerHostApiImpl *hostAPI = [[FWFScriptMessageHandlerHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI createWithIdentifier:@0 error:&error]; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m index eec7a2b5a6dc..939c14873fa4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFUIDelegateHostApiTests.m @@ -45,8 +45,9 @@ - (id)mockFlutterApiWithManager:(FWFInstanceManager *)instanceManager { - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFUIDelegateHostApiImpl *hostAPI = - [[FWFUIDelegateHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFUIDelegateHostApiImpl *hostAPI = [[FWFUIDelegateHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI createWithIdentifier:@0 error:&error]; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewConfigurationHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewConfigurationHostApiTests.m index e09e16b62e45..2ec74d0522dd 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewConfigurationHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewConfigurationHostApiTests.m @@ -14,8 +14,9 @@ @interface FWFWebViewConfigurationHostApiTests : XCTestCase @implementation FWFWebViewConfigurationHostApiTests - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewConfigurationHostApiImpl *hostAPI = - [[FWFWebViewConfigurationHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI createWithIdentifier:@0 error:&error]; @@ -27,8 +28,9 @@ - (void)testCreateWithIdentifier { - (void)testCreateFromWebViewWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewConfigurationHostApiImpl *hostAPI = - [[FWFWebViewConfigurationHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; WKWebView *mockWebView = OCMClassMock([WKWebView class]); OCMStub([mockWebView configuration]).andReturn(OCMClassMock([WKWebViewConfiguration class])); @@ -48,8 +50,9 @@ - (void)testSetAllowsInlineMediaPlayback { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebViewConfiguration withIdentifier:0]; - FWFWebViewConfigurationHostApiImpl *hostAPI = - [[FWFWebViewConfigurationHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:@0 @@ -65,8 +68,9 @@ - (void)testSetMediaTypesRequiringUserActionForPlayback { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebViewConfiguration withIdentifier:0]; - FWFWebViewConfigurationHostApiImpl *hostAPI = - [[FWFWebViewConfigurationHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewConfigurationHostApiImpl *hostAPI = [[FWFWebViewConfigurationHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m index ca17cc212d31..1061abb78f45 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewHostApiTests.m @@ -14,8 +14,9 @@ @interface FWFWebViewHostApiTests : XCTestCase @implementation FWFWebViewHostApiTests - (void)testCreateWithIdentifier { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; [instanceManager addDartCreatedInstance:[[WKWebViewConfiguration alloc] init] withIdentifier:0]; @@ -32,8 +33,9 @@ - (void)testLoadRequest { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"https://www.flutter.dev" @@ -57,8 +59,9 @@ - (void)testLoadRequestWithInvalidUrl { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; FWFNSUrlRequestData *requestData = [FWFNSUrlRequestData makeWithUrl:@"%invalidUrl%" @@ -78,8 +81,9 @@ - (void)testSetCustomUserAgent { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI setUserAgentForWebViewWithIdentifier:@0 userAgent:@"userA" error:&error]; @@ -94,8 +98,9 @@ - (void)testURL { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; XCTAssertEqualObjects([hostAPI URLForWebViewWithIdentifier:@0 error:&error], @@ -110,8 +115,9 @@ - (void)testCanGoBack { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; XCTAssertEqualObjects([hostAPI canGoBackForWebViewWithIdentifier:@0 error:&error], @YES); @@ -124,8 +130,9 @@ - (void)testSetUIDelegate { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; id mockDelegate = OCMProtocolMock(@protocol(WKUIDelegate)); [instanceManager addDartCreatedInstance:mockDelegate withIdentifier:1]; @@ -142,8 +149,9 @@ - (void)testSetNavigationDelegate { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; id mockDelegate = OCMProtocolMock(@protocol(WKNavigationDelegate)); [instanceManager addDartCreatedInstance:mockDelegate withIdentifier:1]; @@ -161,8 +169,9 @@ - (void)testEstimatedProgress { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; XCTAssertEqualObjects([hostAPI estimatedProgressForWebViewWithIdentifier:@0 error:&error], @34.0); @@ -175,8 +184,9 @@ - (void)testloadHTMLString { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI loadHTMLForWebViewWithIdentifier:@0 @@ -193,8 +203,9 @@ - (void)testLoadFileURL { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI loadFileForWebViewWithIdentifier:@0 @@ -222,10 +233,11 @@ - (void)testLoadFlutterAsset { OCMStub([mockBundle URLForResource:@"myFolder/assets/index" withExtension:@"html"]) .andReturn([NSURL URLWithString:@"webview_flutter/myFolder/assets/index.html"]); - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager - bundle:mockBundle - assetManager:mockAssetManager]; + 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]; @@ -243,8 +255,9 @@ - (void)testCanGoForward { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; XCTAssertEqualObjects([hostAPI canGoForwardForWebViewWithIdentifier:@0 error:&error], @NO); @@ -257,8 +270,9 @@ - (void)testGoBack { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI goBackForWebViewWithIdentifier:@0 error:&error]; @@ -272,8 +286,9 @@ - (void)testGoForward { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI goForwardForWebViewWithIdentifier:@0 error:&error]; @@ -287,8 +302,9 @@ - (void)testReload { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI reloadWebViewWithIdentifier:@0 error:&error]; @@ -303,8 +319,9 @@ - (void)testTitle { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; XCTAssertEqualObjects([hostAPI titleForWebViewWithIdentifier:@0 error:&error], @"myTitle"); @@ -317,8 +334,9 @@ - (void)testSetAllowsBackForwardNavigationGestures { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; FlutterError *error; [hostAPI setAllowsBackForwardForWebViewWithIdentifier:@0 isAllowed:@YES error:&error]; @@ -336,8 +354,9 @@ - (void)testEvaluateJavaScript { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; NSString __block *returnValue; FlutterError __block *returnError; @@ -369,8 +388,9 @@ - (void)testEvaluateJavaScriptReturnsNSErrorData { FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; [instanceManager addDartCreatedInstance:mockWebView withIdentifier:0]; - FWFWebViewHostApiImpl *hostAPI = - [[FWFWebViewHostApiImpl alloc] initWithInstanceManager:instanceManager]; + FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc] + initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) + instanceManager:instanceManager]; NSString __block *returnValue; FlutterError __block *returnError; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFHTTPCookieStoreHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFHTTPCookieStoreHostApi.m index 3ad0a169b81f..79a3a684b805 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFHTTPCookieStoreHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFHTTPCookieStoreHostApi.m @@ -7,7 +7,8 @@ #import "FWFWebsiteDataStoreHostApi.h" @interface FWFHTTPCookieStoreHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFHTTPCookieStoreHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h index da5939a3abed..90e55417cd1b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.h @@ -27,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FWFNavigationDelegate : FWFObject @property(readonly, nonnull, nonatomic) FWFNavigationDelegateFlutterApiImpl *navigationDelegateAPI; + - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m index 6946783088d5..1132e02880b2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFNavigationDelegateHostApi.m @@ -7,7 +7,7 @@ #import "FWFWebViewConfigurationHostApi.h" @interface FWFNavigationDelegateFlutterApiImpl () -// This reference must be weak to prevent a circular reference with the objects it stores. +// InstanceManager must be weak to prevent a circular reference with the object it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @@ -183,8 +183,10 @@ - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView { @end @interface FWFNavigationDelegateHostApiImpl () -@property(weak) id binaryMessenger; -// This reference must be weak to prevent a circular reference with the objects it stores. +// 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 diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h index 1f7b2943974e..0b740a524cef 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.h @@ -17,6 +17,12 @@ NS_ASSUME_NONNULL_BEGIN @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 (^)(NSError *_Nullable))completion; @end /** @@ -24,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FWFObject : NSObject @property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; + - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m index f88b91750493..c88b2f4e56cb 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFObjectHostApi.m @@ -6,7 +6,7 @@ #import "FWFDataConverters.h" @interface FWFObjectFlutterApiImpl () -// This reference must be weak to prevent a circular reference with the objects it stores. +// InstanceManager must be weak to prevent a circular reference with the object it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @@ -74,7 +74,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath @end @interface FWFObjectHostApiImpl () -// This reference must be weak to prevent a circular reference with the objects it stores. +// InstanceManager must be weak to prevent a circular reference with the object it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFPreferencesHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFPreferencesHostApi.m index dbb04fccccd2..1a10c08eec4a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFPreferencesHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFPreferencesHostApi.m @@ -6,7 +6,8 @@ #import "FWFWebViewConfigurationHostApi.h" @interface FWFPreferencesHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFPreferencesHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h index 36f12feac3fe..9c5769e4658b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.h @@ -27,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN @interface FWFScriptMessageHandler : FWFObject @property(readonly, nonnull, nonatomic) FWFScriptMessageHandlerFlutterApiImpl *scriptMessageHandlerAPI; + - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end @@ -37,7 +38,8 @@ NS_ASSUME_NONNULL_BEGIN * Handles creating WKScriptMessageHandler that intercommunicate with a paired Dart object. */ @interface FWFScriptMessageHandlerHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m index 69ace0202824..d9e8b934a79a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScriptMessageHandlerHostApi.m @@ -6,7 +6,7 @@ #import "FWFDataConverters.h" @interface FWFScriptMessageHandlerFlutterApiImpl () -// This reference must be weak to prevent a circular reference with the objects it stores. +// InstanceManager must be weak to prevent a circular reference with the object it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @@ -62,13 +62,19 @@ - (void)userContentController:(nonnull WKUserContentController *)userContentCont @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)initWithInstanceManager:(FWFInstanceManager *)instanceManager { +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { self = [self init]; if (self) { + _binaryMessenger = binaryMessenger; _instanceManager = instanceManager; } return self; @@ -81,7 +87,9 @@ - (FWFScriptMessageHandler *)scriptMessageHandlerForIdentifier:(NSNumber *)ident - (void)createWithIdentifier:(nonnull NSNumber *)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFScriptMessageHandler *scriptMessageHandler = [[FWFScriptMessageHandler alloc] init]; + FWFScriptMessageHandler *scriptMessageHandler = + [[FWFScriptMessageHandler alloc] initWithBinaryMessenger:self.binaryMessenger + instanceManager:self.instanceManager]; [self.instanceManager addDartCreatedInstance:scriptMessageHandler withIdentifier:identifier.longValue]; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScrollViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScrollViewHostApi.m index fb77b717aa64..a32e9565b514 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScrollViewHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFScrollViewHostApi.m @@ -6,7 +6,8 @@ #import "FWFWebViewHostApi.h" @interface FWFScrollViewHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFScrollViewHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h index 1bb65914e097..7b6b4eec9b8e 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.h @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN @interface FWFUIDelegateFlutterApiImpl : FWFWKUIDelegateFlutterApi @property(readonly, nonatomic) FWFWebViewConfigurationFlutterApiImpl *webViewConfigurationFlutterApi; + - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end @@ -29,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FWFUIDelegate : FWFObject @property(readonly, nonnull, nonatomic) FWFUIDelegateFlutterApiImpl *UIDelegateAPI; + - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; @end @@ -39,7 +41,8 @@ NS_ASSUME_NONNULL_BEGIN * Handles creating WKUIDelegate that intercommunicate with a paired Dart object. */ @interface FWFUIDelegateHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m index 36c4b2feefe3..60e7ad11965c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIDelegateHostApi.m @@ -6,9 +6,10 @@ #import "FWFDataConverters.h" @interface FWFUIDelegateFlutterApiImpl () -// BinaryMessenger and InstanceManager must be weak to prevent a circular reference -// with the objects it stores. +// 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 @@ -84,13 +85,19 @@ - (WKWebView *)webView:(WKWebView *)webView @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)initWithInstanceManager:(FWFInstanceManager *)instanceManager { +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { self = [self init]; if (self) { + _binaryMessenger = binaryMessenger; _instanceManager = instanceManager; } return self; @@ -102,7 +109,8 @@ - (FWFUIDelegate *)delegateForIdentifier:(NSNumber *)identifier { - (void)createWithIdentifier:(nonnull NSNumber *)identifier error:(FlutterError *_Nullable *_Nonnull)error { - FWFUIDelegate *uIDelegate = [[FWFUIDelegate alloc] init]; + FWFUIDelegate *uIDelegate = [[FWFUIDelegate alloc] initWithBinaryMessenger:self.binaryMessenger + instanceManager:self.instanceManager]; [self.instanceManager addDartCreatedInstance:uIDelegate withIdentifier:identifier.longValue]; } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIViewHostApi.m index 465738b570cd..a990561c4fba 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIViewHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUIViewHostApi.m @@ -5,7 +5,8 @@ #import "FWFUIViewHostApi.h" @interface FWFUIViewHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFUIViewHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUserContentControllerHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUserContentControllerHostApi.m index d15341a7883d..08bbaa68c99c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUserContentControllerHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFUserContentControllerHostApi.m @@ -7,7 +7,8 @@ #import "FWFWebViewConfigurationHostApi.h" @interface FWFUserContentControllerHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFUserContentControllerHostApiImpl diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.h index e2279b48c409..f1e62cc0cba3 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.h @@ -7,6 +7,7 @@ #import "FWFGeneratedWebKitApis.h" #import "FWFInstanceManager.h" +#import "FWFObjectHostApi.h" NS_ASSUME_NONNULL_BEGIN @@ -18,17 +19,29 @@ NS_ASSUME_NONNULL_BEGIN @interface FWFWebViewConfigurationFlutterApiImpl : FWFWKWebViewConfigurationFlutterApi - (instancetype)initWithBinaryMessenger:(id)binaryMessenger instanceManager:(FWFInstanceManager *)instanceManager; + - (void)createWithConfiguration:(WKWebViewConfiguration *)configuration completion:(void (^)(NSError *_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)initWithInstanceManager:(FWFInstanceManager *)instanceManager; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.m index 2b7d1be86d37..a083a2a031ef 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewConfigurationHostApi.m @@ -7,8 +7,7 @@ #import "FWFWebViewConfigurationHostApi.h" @interface FWFWebViewConfigurationFlutterApiImpl () -// BinaryMessenger and InstanceManager must be weak to prevent a circular reference -// with the objects it stores. +// InstanceManager must be weak to prevent a circular reference with the object it stores. @property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @@ -29,14 +28,45 @@ - (void)createWithConfiguration:(WKWebViewConfiguration *)configuration } @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:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} +@end + @interface FWFWebViewConfigurationHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// 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)initWithInstanceManager:(FWFInstanceManager *)instanceManager { +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { self = [self init]; if (self) { + _binaryMessenger = binaryMessenger; _instanceManager = instanceManager; } return self; @@ -49,7 +79,9 @@ - (WKWebViewConfiguration *)webViewConfigurationForIdentifier:(NSNumber *)identi - (void)createWithIdentifier:(nonnull NSNumber *)identifier error:(FlutterError *_Nullable *_Nonnull)error { - WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init]; + FWFWebViewConfiguration *webViewConfiguration = + [[FWFWebViewConfiguration alloc] initWithBinaryMessenger:self.binaryMessenger + instanceManager:self.instanceManager]; [self.instanceManager addDartCreatedInstance:webViewConfiguration withIdentifier:identifier.longValue]; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.h index 968a9a85b2e7..f1bb59bcb9ae 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.h @@ -7,6 +7,7 @@ #import "FWFGeneratedWebKitApis.h" #import "FWFInstanceManager.h" +#import "FWFObjectHostApi.h" NS_ASSUME_NONNULL_BEGIN @@ -23,6 +24,12 @@ NS_ASSUME_NONNULL_BEGIN * Implementation of WKWebView that can be used as a FlutterPlatformView. */ @interface FWFWebView : WKWebView +@property(readonly, nonnull, nonatomic) FWFObjectFlutterApiImpl *objectApi; + +- (instancetype)initWithFrame:(CGRect)frame + configuration:(nonnull WKWebViewConfiguration *)configuration + binaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; @end /** @@ -31,8 +38,11 @@ NS_ASSUME_NONNULL_BEGIN * Handles creating WKWebViews that intercommunicate with a paired Dart object. */ @interface FWFWebViewHostApiImpl : NSObject -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager; -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager; + +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager bundle:(NSBundle *)bundle assetManager:(FWFAssetManager *)assetManager; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m index 2962aadd1647..9a8aedd1e646 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewHostApi.m @@ -12,6 +12,18 @@ - (NSString *)lookupKeyForAsset:(NSString *)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]; + } + return self; +} + - (void)setFrame:(CGRect)frame { [super setFrame:frame]; // Prevents the contentInsets from being adjusted by iOS and gives control to Flutter. @@ -28,29 +40,50 @@ - (void)setFrame:(CGRect)frame { } } +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + [self.objectApi observeValueForObject:self + keyPath:keyPath + object:object + change:change + completion:^(NSError *error) { + NSAssert(!error, @"%@", error); + }]; +} + - (nonnull UIView *)view { return self; } @end @interface FWFWebViewHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// 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)initWithInstanceManager:(FWFInstanceManager *)instanceManager { - return [self initWithInstanceManager:instanceManager +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger + instanceManager:(FWFInstanceManager *)instanceManager { + return [self initWithBinaryMessenger:binaryMessenger + instanceManager:instanceManager bundle:[NSBundle mainBundle] assetManager:[[FWFAssetManager alloc] init]]; } -- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager +- (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; @@ -77,7 +110,9 @@ - (void)createWithIdentifier:(nonnull NSNumber *)identifier WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager instanceForIdentifier:configurationIdentifier.longValue]; FWFWebView *webView = [[FWFWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) - configuration:configuration]; + configuration:configuration + binaryMessenger:self.binaryMessenger + instanceManager:self.instanceManager]; [self.instanceManager addDartCreatedInstance:webView withIdentifier:identifier.longValue]; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebsiteDataStoreHostApi.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebsiteDataStoreHostApi.m index 0fd85e010a0a..5398d14d4e8b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebsiteDataStoreHostApi.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebsiteDataStoreHostApi.m @@ -7,7 +7,8 @@ #import "FWFWebViewConfigurationHostApi.h" @interface FWFWebsiteDataStoreHostApiImpl () -@property(nonatomic) FWFInstanceManager *instanceManager; +// InstanceManager must be weak to prevent a circular reference with the object it stores. +@property(nonatomic, weak) FWFInstanceManager *instanceManager; @end @implementation FWFWebsiteDataStoreHostApiImpl 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 index c9c8c2324cc6..3cc100aebd46 100644 --- 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 @@ -179,8 +179,6 @@ class InstanceManager { final Copyable copy = instance.copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; - - assert(instance == copy); } /// Whether this manager contains the given [identifier]. 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 index 0a1dd347f8a2..f537a4454c4f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -237,13 +237,12 @@ class NSHttpCookie { /// The root class of most Objective-C class hierarchies. @immutable class NSObject with Copyable { - // TODO(bparrishMines): Change constructor name to `detached`. /// 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({ + NSObject.detached({ this.observeValue, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, @@ -255,6 +254,11 @@ class NSObject with Copyable { 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) { @@ -290,30 +294,12 @@ class NSObject with Copyable { return _api.removeObserverForInstances(this, observer, keyPath); } - /// Release the reference to the Objective-C object. - static void dispose(NSObject instance) { - instance._api.instanceManager.removeWeakReference(instance); - } - @override - Copyable copy() { - return NSObject( + NSObject copy() { + return NSObject.detached( observeValue: observeValue, binaryMessenger: _api.binaryMessenger, instanceManager: _api.instanceManager, ); } - - @override - int get hashCode { - return Object.hash(_api, _api.instanceManager.getIdentifier(this)); - } - - @override - bool operator ==(Object other) { - return other is NSObject && - _api == other._api && - _api.instanceManager.getIdentifier(this) == - other._api.instanceManager.getIdentifier(other); - } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart index de760ec5b36e..d2310e0a5df8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart @@ -89,7 +89,6 @@ class FoundationFlutterApis { } /// Host api implementation for [NSObject]. -@immutable class NSObjectHostApiImpl extends NSObjectHostApi { /// Constructs an [NSObjectHostApiImpl]. NSObjectHostApiImpl({ @@ -134,18 +133,6 @@ class NSObjectHostApiImpl extends NSObjectHostApi { keyPath, ); } - - @override - int get hashCode { - return Object.hash(binaryMessenger, instanceManager); - } - - @override - bool operator ==(Object other) { - return other is NSObjectHostApiImpl && - binaryMessenger == other.binaryMessenger && - instanceManager == other.instanceManager; - } } /// Flutter api implementation for [NSObject]. 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 index 88aefc18e454..33447091e5f9 100644 --- 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 @@ -4,6 +4,7 @@ import 'dart:math'; +import 'package:flutter/foundation.dart'; // TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316) // ignore: unnecessary_import import 'package:flutter/painting.dart' show Color; @@ -14,25 +15,42 @@ import '../foundation/foundation.dart'; import '../web_kit/web_kit.dart'; import 'ui_kit_api_impls.dart'; -// TODO(bparrishMines): All subclasses of NSObject need to pass their -// InstanceManager and BinaryMessenger to its parent. They also need to -// override copy(); - /// 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 UIView { /// Constructs a [UIScrollView] that is owned by [webView]. - UIScrollView.fromWebView( + factory UIScrollView.fromWebView( WKWebView webView, { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - }) : _scrollViewApi = UIScrollViewHostApiImpl( + }) { + 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, - ) { - _scrollViewApi.createFromWebViewForInstances(this, webView); - } + ), + super.detached(); final UIScrollViewHostApiImpl _scrollViewApi; @@ -59,21 +77,36 @@ class UIScrollView extends UIView { Future setContentOffset(Point offset) { return _scrollViewApi.setContentOffsetForInstances(this, offset); } + + @override + UIScrollView copy() { + return UIScrollView.detached( + observeValue: observeValue, + binaryMessenger: _viewApi.binaryMessenger, + instanceManager: _viewApi.instanceManager, + ); + } } /// Manages the content for a rectangular area on the screen. /// /// Wraps [UIView](https://developer.apple.com/documentation/uikit/uiview?language=objc). +@immutable class UIView extends NSObject { - /// Constructs an [NSObject]. - 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. + UIView.detached({ super.observeValue, - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _viewApi = UIViewHostApiImpl( + super.binaryMessenger, + super.instanceManager, + }) : _viewApi = UIViewHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ); + ), + super.detached(); final UIViewHostApiImpl _viewApi; @@ -92,4 +125,13 @@ class UIView extends NSObject { Future setOpaque(bool opaque) { return _viewApi.setOpaqueForInstances(this, opaque); } + + @override + UIView copy() { + return UIView.detached( + observeValue: observeValue, + binaryMessenger: _viewApi.binaryMessenger, + instanceManager: _viewApi.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 index e921c4bad15a..6a54166fbad8 100644 --- 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 @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:math'; import 'package:flutter/painting.dart' show Color; +import 'package:flutter/services.dart'; import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; @@ -18,9 +19,16 @@ import 'ui_kit.dart'; class UIScrollViewHostApiImpl extends UIScrollViewHostApi { /// Constructs a [UIScrollViewHostApiImpl]. UIScrollViewHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -75,9 +83,16 @@ class UIScrollViewHostApiImpl extends UIScrollViewHostApi { class UIViewHostApiImpl extends UIViewHostApi { /// Constructs a [UIViewHostApiImpl]. UIViewHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index b2945293e624..ffc6eb8c23bf 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -10,10 +10,6 @@ import '../foundation/foundation.dart'; import '../ui_kit/ui_kit.dart'; import 'web_kit_api_impls.dart'; -// TODO(bparrishMines): All subclasses of NSObject need to pass their -// InstanceManager and BinaryMessenger to its parent. They also need to -// override copy(): https://github.com/flutter/flutter/issues/105245 - /// Times at which to inject script content into a webpage. /// /// Wraps [WKUserScriptInjectionTime](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc). @@ -214,23 +210,40 @@ class WKScriptMessage { /// 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]. - @visibleForTesting - WKPreferences.fromWebViewConfiguration( + factory WKPreferences.fromWebViewConfiguration( WKWebViewConfiguration configuration, { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - }) : _preferencesApi = WKPreferencesHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ) { - _preferencesApi.createFromWebViewConfigurationForInstances( - this, + }) { + 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. @@ -240,22 +253,39 @@ class WKPreferences extends NSObject { 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 { - WKWebsiteDataStore._({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _websiteDataStoreApi = WKWebsiteDataStoreHostApiImpl( + /// 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._(); + final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore.detached(); websiteDataStore._websiteDataStoreApi.createDefaultDataStoreForInstances( websiteDataStore, ); @@ -263,13 +293,12 @@ class WKWebsiteDataStore extends NSObject { } /// Constructs a [WKWebsiteDataStore] that is owned by [configuration]. - @visibleForTesting factory WKWebsiteDataStore.fromWebViewConfiguration( WKWebViewConfiguration configuration, { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) { - final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore._( + final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); @@ -304,28 +333,44 @@ class WKWebsiteDataStore extends NSObject { 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 { - WKHttpCookieStore._({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _httpCookieStoreApi = WKHttpCookieStoreHostApiImpl( + /// 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]. - @visibleForTesting factory WKHttpCookieStore.fromWebsiteDataStore( WKWebsiteDataStore dataStore, { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) { - final WKHttpCookieStore cookieStore = WKHttpCookieStore._( + final WKHttpCookieStore cookieStore = WKHttpCookieStore.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); @@ -342,25 +387,54 @@ class WKHttpCookieStore extends NSObject { Future setCookie(NSHttpCookie cookie) { return _httpCookieStoreApi.setCookieForInsances(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) +/// 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, - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl( + 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. @@ -372,6 +446,16 @@ class WKScriptMessageHandler extends NSObject { 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. @@ -383,21 +467,25 @@ class WKScriptMessageHandler extends NSObject { /// 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]. - @visibleForTesting - WKUserContentController.fromWebViewConfiguration( + factory WKUserContentController.fromWebViewConfiguration( WKWebViewConfiguration configuration, { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - }) : _userContentControllerApi = WKUserContentControllerHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ) { - _userContentControllerApi.createFromWebViewConfigurationForInstances( - this, + }) { + final WKUserContentController userContentController = + WKUserContentController.detached( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ); + userContentController._userContentControllerApi + .createFromWebViewConfigurationForInstances( + userContentController, configuration, ); + return userContentController; } /// Constructs a [WKUserContentController] without creating the associated @@ -406,12 +494,14 @@ class WKUserContentController extends NSObject { /// This should only be used outside of tests by subclasses created by this /// library or to create a copy for an InstanceManager. WKUserContentController.detached({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _userContentControllerApi = WKUserContentControllerHostApiImpl( + super.observeValue, + super.binaryMessenger, + super.instanceManager, + }) : _userContentControllerApi = WKUserContentControllerHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ); + ), + super.detached(); final WKUserContentControllerHostApiImpl _userContentControllerApi; @@ -474,24 +564,35 @@ class WKUserContentController extends NSObject { 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]. - factory WKWebViewConfiguration({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) { - final WKWebViewConfiguration configuration = - WKWebViewConfiguration.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - configuration._webViewConfigurationApi.createForInstances(configuration); - return configuration; + 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. @@ -519,17 +620,14 @@ class WKWebViewConfiguration extends NSObject { /// This should only be used outside of tests by subclasses created by this /// library or to create a copy for an InstanceManager. WKWebViewConfiguration.detached({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _binaryMessenger = binaryMessenger, - _instanceManager = instanceManager, - _webViewConfigurationApi = WKWebViewConfigurationHostApiImpl( + super.observeValue, + super.binaryMessenger, + super.instanceManager, + }) : _webViewConfigurationApi = WKWebViewConfigurationHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ); - - final BinaryMessenger? _binaryMessenger; - final InstanceManager? _instanceManager; + ), + super.detached(); late final WKWebViewConfigurationHostApiImpl _webViewConfigurationApi; @@ -537,13 +635,16 @@ class WKWebViewConfiguration extends NSObject { late final WKUserContentController userContentController = WKUserContentController.fromWebViewConfiguration( this, - binaryMessenger: _binaryMessenger, - instanceManager: _instanceManager, + binaryMessenger: _webViewConfigurationApi.binaryMessenger, + instanceManager: _webViewConfigurationApi.instanceManager, ); /// Manages the preference-related settings for the web view. - late final WKPreferences preferences = - WKPreferences.fromWebViewConfiguration(this); + 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. /// @@ -551,8 +652,8 @@ class WKWebViewConfiguration extends NSObject { late final WKWebsiteDataStore websiteDataStore = WKWebsiteDataStore.fromWebViewConfiguration( this, - binaryMessenger: _binaryMessenger, - instanceManager: _instanceManager, + binaryMessenger: _webViewConfigurationApi.binaryMessenger, + instanceManager: _webViewConfigurationApi.instanceManager, ); /// Indicates whether HTML5 videos play inline or use the native full-screen controller. @@ -581,25 +682,54 @@ class WKWebViewConfiguration extends NSObject { 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, super.observeValue, - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _uiDelegateApi = WKUIDelegateHostApiImpl( + 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, + 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]. @@ -608,6 +738,16 @@ class WKUIDelegate extends NSObject { WKWebViewConfiguration configuration, WKNavigationAction navigationAction, )? onCreateWebView; + + @override + WKUIDelegate copy() { + return WKUIDelegate.detached( + onCreateWebView: onCreateWebView, + observeValue: observeValue, + binaryMessenger: _uiDelegateApi.binaryMessenger, + instanceManager: _uiDelegateApi.instanceManager, + ); + } } /// Methods for handling navigation changes and tracking navigation requests. @@ -629,10 +769,12 @@ class WKNavigationDelegate extends NSObject { super.observeValue, super.binaryMessenger, super.instanceManager, - }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( + }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ) { + ), + super.detached() { + // Ensures FlutterApis for the WebKit library are set up. WebKitFlutterApis.instance.ensureSetUp(); _navigationDelegateApi.createForInstances(this); } @@ -652,10 +794,11 @@ class WKNavigationDelegate extends NSObject { super.observeValue, super.binaryMessenger, super.instanceManager, - }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( + }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ); + ), + super.detached(); final WKNavigationDelegateHostApiImpl _navigationDelegateApi; @@ -683,7 +826,7 @@ class WKNavigationDelegate extends NSObject { final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate; @override - Copyable copy() { + WKNavigationDelegate copy() { return WKNavigationDelegate.detached( didFinishNavigation: didFinishNavigation, didStartProvisionalNavigation: didStartProvisionalNavigation, @@ -697,26 +840,12 @@ class WKNavigationDelegate extends NSObject { instanceManager: _navigationDelegateApi.instanceManager, ); } - - @override - int get hashCode { - return Object.hash(didFinishNavigation, _navigationDelegateApi, - _navigationDelegateApi.instanceManager.getIdentifier(this)); - } - - @override - bool operator ==(Object other) { - return other is WKNavigationDelegate && - didFinishNavigation == other.didFinishNavigation && - _navigationDelegateApi == other._navigationDelegateApi && - _navigationDelegateApi.instanceManager.getIdentifier(this) == - other._navigationDelegateApi.instanceManager.getIdentifier(other); - } } /// Object that displays interactive web content, such as for an in-app browser. /// /// Wraps [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview?language=objc). +@immutable class WKWebView extends UIView { /// Constructs a [WKWebView]. /// @@ -732,17 +861,18 @@ class WKWebView extends UIView { super.observeValue, super.binaryMessenger, super.instanceManager, - }) : _binaryMessenger = binaryMessenger, - _instanceManager = instanceManager, - _webViewApi = WKWebViewHostApiImpl( + }) : _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. + /// 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. @@ -750,15 +880,11 @@ class WKWebView extends UIView { super.observeValue, super.binaryMessenger, super.instanceManager, - }) : _binaryMessenger = binaryMessenger, - _instanceManager = instanceManager, - _webViewApi = WKWebViewHostApiImpl( + }) : _webViewApi = WKWebViewHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, - ); - - final BinaryMessenger? _binaryMessenger; - final InstanceManager? _instanceManager; + ), + super.detached(); final WKWebViewHostApiImpl _webViewApi; @@ -774,15 +900,15 @@ class WKWebView extends UIView { late final WKWebViewConfiguration configuration = WKWebViewConfiguration.fromWebView( this, - binaryMessenger: _binaryMessenger, - instanceManager: _instanceManager, + binaryMessenger: _webViewApi.binaryMessenger, + instanceManager: _webViewApi.instanceManager, ); /// The scrollable view associated with the web view. late final UIScrollView scrollView = UIScrollView.fromWebView( this, - binaryMessenger: _binaryMessenger, - instanceManager: _instanceManager, + binaryMessenger: _webViewApi.binaryMessenger, + instanceManager: _webViewApi.instanceManager, ); /// Used to integrate custom user interface elements into web view interactions. @@ -904,4 +1030,13 @@ class WKWebView extends UIView { javaScriptString, ); } + + @override + WKWebView copy() { + return WKWebView.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 index d0423b44df84..6a7fb6254889 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit_api_impls.dart @@ -296,6 +296,10 @@ class WebKitFlutterApis { uiDelegate, binaryMessenger: _binaryMessenger, ); + WKWebViewConfigurationFlutterApi.setup( + webViewConfiguration, + binaryMessenger: _binaryMessenger, + ); _hasBeenSetUp = true; } } @@ -305,9 +309,16 @@ class WebKitFlutterApis { class WKWebsiteDataStoreHostApiImpl extends WKWebsiteDataStoreHostApi { /// Constructs a [WebsiteDataStoreHostApiImpl]. WKWebsiteDataStoreHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -350,9 +361,16 @@ class WKWebsiteDataStoreHostApiImpl extends WKWebsiteDataStoreHostApi { class WKScriptMessageHandlerHostApiImpl extends WKScriptMessageHandlerHostApi { /// Constructs a [WKScriptMessageHandlerHostApiImpl]. WKScriptMessageHandlerHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -396,9 +414,16 @@ class WKScriptMessageHandlerFlutterApiImpl class WKPreferencesHostApiImpl extends WKPreferencesHostApi { /// Constructs a [WKPreferencesHostApiImpl]. WKPreferencesHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -430,9 +455,16 @@ class WKPreferencesHostApiImpl extends WKPreferencesHostApi { class WKHttpCookieStoreHostApiImpl extends WKHttpCookieStoreHostApi { /// Constructs a [WKHttpCookieStoreHostApiImpl]. WKHttpCookieStoreHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -465,9 +497,16 @@ class WKUserContentControllerHostApiImpl extends WKUserContentControllerHostApi { /// Constructs a [WKUserContentControllerHostApiImpl]. WKUserContentControllerHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -539,9 +578,16 @@ class WKUserContentControllerHostApiImpl class WKWebViewConfigurationHostApiImpl extends WKWebViewConfigurationHostApi { /// Constructs a [WKWebViewConfigurationHostApiImpl]. WKWebViewConfigurationHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -620,9 +666,16 @@ class WKWebViewConfigurationFlutterApiImpl class WKUIDelegateHostApiImpl extends WKUIDelegateHostApi { /// Constructs a [WKUIDelegateHostApiImpl]. WKUIDelegateHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; @@ -666,7 +719,6 @@ class WKUIDelegateFlutterApiImpl extends WKUIDelegateFlutterApi { } /// Host api implementation for [WKNavigationDelegate]. -@immutable class WKNavigationDelegateHostApiImpl extends WKNavigationDelegateHostApi { /// Constructs a [WKNavigationDelegateHostApiImpl]. WKNavigationDelegateHostApiImpl({ @@ -688,18 +740,6 @@ class WKNavigationDelegateHostApiImpl extends WKNavigationDelegateHostApi { Future createForInstances(WKNavigationDelegate instance) async { return create(instanceManager.addDartCreatedInstance(instance)); } - - @override - int get hashCode { - return Object.hash(binaryMessenger, instanceManager); - } - - @override - bool operator ==(Object other) { - return other is WKNavigationDelegateHostApiImpl && - binaryMessenger == other.binaryMessenger && - instanceManager == other.instanceManager; - } } /// Flutter api implementation for [WKNavigationDelegate]. @@ -819,9 +859,16 @@ class WKNavigationDelegateFlutterApiImpl class WKWebViewHostApiImpl extends WKWebViewHostApi { /// Constructs a [WKWebViewHostApiImpl]. WKWebViewHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? NSObject.globalInstanceManager; + }) : 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; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 99195fba4c33..ed1912ee7898 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -330,8 +330,6 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { // unsupported. This also goes for `null` and `undefined` on iOS 14+. For // example, when running a void function. For ease of use, this specific // error is ignored when no return value is expected. - // TODO(bparrishMines): Ensure the platform code includes the NSError in - // the FlutterError.details. if (exception.details is! NSError || exception.details.code != WKErrorCode.javaScriptResultTypeIsUnsupported) { diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart index d97d152739c4..87b659885b52 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart @@ -37,7 +37,7 @@ void main() { mockPlatformHostApi = MockTestNSObjectHostApi(); TestNSObjectHostApi.setup(mockPlatformHostApi); - object = NSObject(instanceManager: instanceManager); + object = NSObject.detached(instanceManager: instanceManager); instanceManager.addDartCreatedInstance(object); }); @@ -46,7 +46,9 @@ void main() { }); test('addObserver', () async { - final NSObject observer = NSObject(instanceManager: instanceManager); + final NSObject observer = NSObject.detached( + instanceManager: instanceManager, + ); instanceManager.addDartCreatedInstance(observer); await object.addObserver( @@ -78,7 +80,9 @@ void main() { }); test('removeObserver', () async { - final NSObject observer = NSObject(instanceManager: instanceManager); + final NSObject observer = NSObject.detached( + instanceManager: instanceManager, + ); instanceManager.addDartCreatedInstance(observer); await object.removeObserver(observer, keyPath: 'aKeyPath'); @@ -97,7 +101,9 @@ void main() { callbackIdentifier = identifier; }); - final NSObject object = NSObject(instanceManager: instanceManager); + final NSObject object = NSObject.detached( + instanceManager: instanceManager, + ); final int identifier = instanceManager.addDartCreatedInstance(object); NSObject.dispose(object); @@ -112,7 +118,7 @@ void main() { instanceManager: instanceManager, ); - object = NSObject( + object = NSObject.detached( instanceManager: instanceManager, observeValue: ( String keyPath, @@ -151,7 +157,7 @@ void main() { instanceManager: instanceManager, ); - object = NSObject(instanceManager: instanceManager); + object = NSObject.detached(instanceManager: instanceManager); instanceManager.addHostCreatedInstance(object, 1); instanceManager.removeWeakReference(object); 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 index aeb4e1cc54ce..f2250e1ac423 100644 --- 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 @@ -97,7 +97,7 @@ void main() { mockPlatformHostApi = MockTestUIViewHostApi(); TestUIViewHostApi.setup(mockPlatformHostApi); - view = UIView(instanceManager: instanceManager); + view = UIView.detached(instanceManager: instanceManager); viewInstanceId = instanceManager.addDartCreatedInstance(view); }); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart index b0c63b663066..e44e7b13a205 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart @@ -2,14 +2,12 @@ // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.dart. // Do not manually edit this file. -import 'dart:async' as _i4; +import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart' - as _i2; import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i5; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i3; + as _i4; +import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -21,77 +19,82 @@ import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i3; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -class _FakeCopyable_0 extends _i1.Fake implements _i2.Copyable {} +class _FakeWKHttpCookieStore_0 extends _i1.Fake + implements _i2.WKHttpCookieStore {} -class _FakeWKHttpCookieStore_1 extends _i1.Fake - implements _i3.WKHttpCookieStore {} +class _FakeWKWebsiteDataStore_1 extends _i1.Fake + implements _i2.WKWebsiteDataStore {} /// A class which mocks [WKHttpCookieStore]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKHttpCookieStore extends _i1.Mock implements _i3.WKHttpCookieStore { +// ignore: must_be_immutable +class MockWKHttpCookieStore extends _i1.Mock implements _i2.WKHttpCookieStore { MockWKHttpCookieStore() { _i1.throwOnMissingStub(this); } @override - _i4.Future setCookie(_i5.NSHttpCookie? cookie) => + _i3.Future setCookie(_i4.NSHttpCookie? cookie) => (super.noSuchMethod(Invocation.method(#setCookie, [cookie]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); + returnValueForMissingStub: Future.value()) as _i3.Future); @override - _i4.Future addObserver(_i5.NSObject? observer, - {String? keyPath, Set<_i5.NSKeyValueObservingOptions>? options}) => + _i2.WKHttpCookieStore copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKHttpCookieStore_0()) as _i2.WKHttpCookieStore); + @override + _i3.Future addObserver(_i4.NSObject? observer, + {String? keyPath, Set<_i4.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); + returnValueForMissingStub: Future.value()) as _i3.Future); @override - _i4.Future removeObserver(_i5.NSObject? observer, {String? keyPath}) => + _i3.Future removeObserver(_i4.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i2.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_0()) as _i2.Copyable); + returnValueForMissingStub: Future.value()) as _i3.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 _i3.WKWebsiteDataStore { + implements _i2.WKWebsiteDataStore { MockWKWebsiteDataStore() { _i1.throwOnMissingStub(this); } @override - _i3.WKHttpCookieStore get httpCookieStore => + _i2.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod(Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_1()) as _i3.WKHttpCookieStore); + returnValue: _FakeWKHttpCookieStore_0()) as _i2.WKHttpCookieStore); @override - _i4.Future removeDataOfTypes( - Set<_i3.WKWebsiteDataType>? dataTypes, DateTime? since) => + _i3.Future removeDataOfTypes( + Set<_i2.WKWebsiteDataType>? dataTypes, DateTime? since) => (super.noSuchMethod( Invocation.method(#removeDataOfTypes, [dataTypes, since]), - returnValue: Future.value(false)) as _i4.Future); + returnValue: Future.value(false)) as _i3.Future); @override - _i4.Future addObserver(_i5.NSObject? observer, - {String? keyPath, Set<_i5.NSKeyValueObservingOptions>? options}) => + _i2.WKWebsiteDataStore copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKWebsiteDataStore_1()) as _i2.WKWebsiteDataStore); + @override + _i3.Future addObserver(_i4.NSObject? observer, + {String? keyPath, Set<_i4.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); + returnValueForMissingStub: Future.value()) as _i3.Future); @override - _i4.Future removeObserver(_i5.NSObject? observer, {String? keyPath}) => + _i3.Future removeObserver(_i4.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i2.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_0()) as _i2.Copyable); + returnValueForMissingStub: Future.value()) as _i3.Future); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index 6161bd044435..f216711ca0b2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -2,25 +2,23 @@ // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart. // Do not manually edit this file. -import 'dart:async' as _i6; +import 'dart:async' as _i5; import 'dart:math' as _i2; -import 'dart:ui' as _i7; +import 'dart:ui' as _i6; import 'package:mockito/mockito.dart' as _i1; import 'package:webview_flutter_platform_interface/src/types/javascript_channel.dart' - as _i10; + as _i9; import 'package:webview_flutter_platform_interface/src/types/types.dart' - as _i11; + as _i10; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' - as _i9; -import 'package:webview_flutter_wkwebview/src/common/instance_manager.dart' - as _i3; -import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' as _i8; -import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart' as _i5; +import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' + as _i7; +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; import 'package:webview_flutter_wkwebview/src/web_kit_webview_widget.dart' - as _i12; + as _i11; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -34,84 +32,83 @@ import 'package:webview_flutter_wkwebview/src/web_kit_webview_widget.dart' class _FakePoint_0 extends _i1.Fake implements _i2.Point {} -class _FakeCopyable_1 extends _i1.Fake implements _i3.Copyable {} +class _FakeUIScrollView_1 extends _i1.Fake implements _i3.UIScrollView {} + +class _FakeWKNavigationDelegate_2 extends _i1.Fake + implements _i4.WKNavigationDelegate {} + +class _FakeWKPreferences_3 extends _i1.Fake implements _i4.WKPreferences {} -class _FakeWKWebViewConfiguration_2 extends _i1.Fake +class _FakeWKScriptMessageHandler_4 extends _i1.Fake + implements _i4.WKScriptMessageHandler {} + +class _FakeWKWebViewConfiguration_5 extends _i1.Fake implements _i4.WKWebViewConfiguration {} -class _FakeUIScrollView_3 extends _i1.Fake implements _i5.UIScrollView {} +class _FakeWKWebView_6 extends _i1.Fake implements _i4.WKWebView {} -class _FakeWKUserContentController_4 extends _i1.Fake +class _FakeWKUserContentController_7 extends _i1.Fake implements _i4.WKUserContentController {} -class _FakeWKPreferences_5 extends _i1.Fake implements _i4.WKPreferences {} - -class _FakeWKWebsiteDataStore_6 extends _i1.Fake +class _FakeWKWebsiteDataStore_8 extends _i1.Fake implements _i4.WKWebsiteDataStore {} -class _FakeWKHttpCookieStore_7 extends _i1.Fake +class _FakeWKHttpCookieStore_9 extends _i1.Fake implements _i4.WKHttpCookieStore {} -class _FakeWKWebView_8 extends _i1.Fake implements _i4.WKWebView {} - -class _FakeWKScriptMessageHandler_9 extends _i1.Fake - implements _i4.WKScriptMessageHandler {} - class _FakeWKUIDelegate_10 extends _i1.Fake implements _i4.WKUIDelegate {} -class _FakeWKNavigationDelegate_11 extends _i1.Fake - implements _i4.WKNavigationDelegate {} - /// A class which mocks [UIScrollView]. /// /// See the documentation for Mockito's code generation for more information. -class MockUIScrollView extends _i1.Mock implements _i5.UIScrollView { +// ignore: must_be_immutable +class MockUIScrollView extends _i1.Mock implements _i3.UIScrollView { MockUIScrollView() { _i1.throwOnMissingStub(this); } @override - _i6.Future<_i2.Point> getContentOffset() => (super.noSuchMethod( + _i5.Future<_i2.Point> getContentOffset() => (super.noSuchMethod( Invocation.method(#getContentOffset, []), returnValue: Future<_i2.Point>.value(_FakePoint_0())) - as _i6.Future<_i2.Point>); + as _i5.Future<_i2.Point>); @override - _i6.Future scrollBy(_i2.Point? offset) => + _i5.Future scrollBy(_i2.Point? offset) => (super.noSuchMethod(Invocation.method(#scrollBy, [offset]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setContentOffset(_i2.Point? offset) => + _i5.Future setContentOffset(_i2.Point? offset) => (super.noSuchMethod(Invocation.method(#setContentOffset, [offset]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i3.UIScrollView copy() => (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeUIScrollView_1()) as _i3.UIScrollView); @override - _i6.Future setBackgroundColor(_i7.Color? color) => + _i5.Future setBackgroundColor(_i6.Color? color) => (super.noSuchMethod(Invocation.method(#setBackgroundColor, [color]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setOpaque(bool? opaque) => + _i5.Future setOpaque(bool? opaque) => (super.noSuchMethod(Invocation.method(#setOpaque, [opaque]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.Future); } /// A class which mocks [WKNavigationDelegate]. @@ -125,59 +122,62 @@ class MockWKNavigationDelegate extends _i1.Mock } @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + _i4.WKNavigationDelegate copy() => (super.noSuchMethod( + Invocation.method(#copy, []), + returnValue: _FakeWKNavigationDelegate_2()) as _i4.WKNavigationDelegate); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.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 - _i6.Future setJavaScriptEnabled(bool? enabled) => + _i5.Future setJavaScriptEnabled(bool? enabled) => (super.noSuchMethod(Invocation.method(#setJavaScriptEnabled, [enabled]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i4.WKPreferences copy() => (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKPreferences_3()) as _i4.WKPreferences); + @override + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: 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() { @@ -192,27 +192,30 @@ class MockWKScriptMessageHandler extends _i1.Mock _i4.WKScriptMessage message) {}) as void Function( _i4.WKUserContentController, _i4.WKScriptMessage)); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i4.WKScriptMessageHandler copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKScriptMessageHandler_4()) + as _i4.WKScriptMessageHandler); + @override + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.Future); } /// A class which mocks [WKWebView]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWKWebView extends _i1.Mock implements _i4.WKWebView { MockWKWebView() { _i1.throwOnMissingStub(this); @@ -221,127 +224,128 @@ class MockWKWebView extends _i1.Mock implements _i4.WKWebView { @override _i4.WKWebViewConfiguration get configuration => (super.noSuchMethod(Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_2()) + returnValue: _FakeWKWebViewConfiguration_5()) as _i4.WKWebViewConfiguration); @override - _i5.UIScrollView get scrollView => + _i3.UIScrollView get scrollView => (super.noSuchMethod(Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_3()) as _i5.UIScrollView); + returnValue: _FakeUIScrollView_1()) as _i3.UIScrollView); @override - _i6.Future setUIDelegate(_i4.WKUIDelegate? delegate) => + _i5.Future setUIDelegate(_i4.WKUIDelegate? delegate) => (super.noSuchMethod(Invocation.method(#setUIDelegate, [delegate]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setNavigationDelegate(_i4.WKNavigationDelegate? delegate) => + _i5.Future setNavigationDelegate(_i4.WKNavigationDelegate? delegate) => (super.noSuchMethod(Invocation.method(#setNavigationDelegate, [delegate]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future getUrl() => + _i5.Future getUrl() => (super.noSuchMethod(Invocation.method(#getUrl, []), - returnValue: Future.value()) as _i6.Future); + returnValue: Future.value()) as _i5.Future); @override - _i6.Future getEstimatedProgress() => + _i5.Future getEstimatedProgress() => (super.noSuchMethod(Invocation.method(#getEstimatedProgress, []), - returnValue: Future.value(0.0)) as _i6.Future); + returnValue: Future.value(0.0)) as _i5.Future); @override - _i6.Future loadRequest(_i8.NSUrlRequest? request) => + _i5.Future loadRequest(_i7.NSUrlRequest? request) => (super.noSuchMethod(Invocation.method(#loadRequest, [request]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future loadHtmlString(String? string, {String? baseUrl}) => + _i5.Future loadHtmlString(String? string, {String? baseUrl}) => (super.noSuchMethod( Invocation.method(#loadHtmlString, [string], {#baseUrl: baseUrl}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future loadFileUrl(String? url, {String? readAccessUrl}) => + _i5.Future loadFileUrl(String? url, {String? readAccessUrl}) => (super.noSuchMethod( Invocation.method( #loadFileUrl, [url], {#readAccessUrl: readAccessUrl}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future loadFlutterAsset(String? key) => + _i5.Future loadFlutterAsset(String? key) => (super.noSuchMethod(Invocation.method(#loadFlutterAsset, [key]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future canGoBack() => + _i5.Future canGoBack() => (super.noSuchMethod(Invocation.method(#canGoBack, []), - returnValue: Future.value(false)) as _i6.Future); + returnValue: Future.value(false)) as _i5.Future); @override - _i6.Future canGoForward() => + _i5.Future canGoForward() => (super.noSuchMethod(Invocation.method(#canGoForward, []), - returnValue: Future.value(false)) as _i6.Future); + returnValue: Future.value(false)) as _i5.Future); @override - _i6.Future goBack() => + _i5.Future goBack() => (super.noSuchMethod(Invocation.method(#goBack, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future goForward() => + _i5.Future goForward() => (super.noSuchMethod(Invocation.method(#goForward, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future reload() => + _i5.Future reload() => (super.noSuchMethod(Invocation.method(#reload, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future getTitle() => + _i5.Future getTitle() => (super.noSuchMethod(Invocation.method(#getTitle, []), - returnValue: Future.value()) as _i6.Future); + returnValue: Future.value()) as _i5.Future); @override - _i6.Future setAllowsBackForwardNavigationGestures(bool? allow) => + _i5.Future setAllowsBackForwardNavigationGestures(bool? allow) => (super.noSuchMethod( Invocation.method(#setAllowsBackForwardNavigationGestures, [allow]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setCustomUserAgent(String? userAgent) => + _i5.Future setCustomUserAgent(String? userAgent) => (super.noSuchMethod(Invocation.method(#setCustomUserAgent, [userAgent]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future evaluateJavaScript(String? javaScriptString) => (super + _i5.Future evaluateJavaScript(String? javaScriptString) => (super .noSuchMethod(Invocation.method(#evaluateJavaScript, [javaScriptString]), - returnValue: Future.value()) as _i6.Future); + returnValue: Future.value()) as _i5.Future); + @override + _i4.WKWebView copy() => (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKWebView_6()) as _i4.WKWebView); @override - _i6.Future setBackgroundColor(_i7.Color? color) => + _i5.Future setBackgroundColor(_i6.Color? color) => (super.noSuchMethod(Invocation.method(#setBackgroundColor, [color]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setOpaque(bool? opaque) => + _i5.Future setOpaque(bool? opaque) => (super.noSuchMethod(Invocation.method(#setOpaque, [opaque]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.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 { MockWKWebViewConfiguration() { @@ -351,51 +355,54 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i4.WKUserContentController get userContentController => (super.noSuchMethod(Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_4()) + returnValue: _FakeWKUserContentController_7()) as _i4.WKUserContentController); @override _i4.WKPreferences get preferences => (super.noSuchMethod(Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_5()) as _i4.WKPreferences); + returnValue: _FakeWKPreferences_3()) as _i4.WKPreferences); @override _i4.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod(Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_6()) as _i4.WKWebsiteDataStore); + returnValue: _FakeWKWebsiteDataStore_8()) as _i4.WKWebsiteDataStore); @override - _i6.Future setAllowsInlineMediaPlayback(bool? allow) => (super + _i5.Future setAllowsInlineMediaPlayback(bool? allow) => (super .noSuchMethod(Invocation.method(#setAllowsInlineMediaPlayback, [allow]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future setMediaTypesRequiringUserActionForPlayback( + _i5.Future setMediaTypesRequiringUserActionForPlayback( Set<_i4.WKAudiovisualMediaType>? types) => (super.noSuchMethod( Invocation.method( #setMediaTypesRequiringUserActionForPlayback, [types]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i4.WKWebViewConfiguration copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKWebViewConfiguration_5()) + as _i4.WKWebViewConfiguration); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.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 { MockWKWebsiteDataStore() { @@ -405,62 +412,65 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i4.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod(Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_7()) as _i4.WKHttpCookieStore); + returnValue: _FakeWKHttpCookieStore_9()) as _i4.WKHttpCookieStore); @override - _i6.Future removeDataOfTypes( + _i5.Future removeDataOfTypes( Set<_i4.WKWebsiteDataType>? dataTypes, DateTime? since) => (super.noSuchMethod( Invocation.method(#removeDataOfTypes, [dataTypes, since]), - returnValue: Future.value(false)) as _i6.Future); + returnValue: Future.value(false)) as _i5.Future); + @override + _i4.WKWebsiteDataStore copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKWebsiteDataStore_8()) as _i4.WKWebsiteDataStore); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.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 { MockWKUIDelegate() { _i1.throwOnMissingStub(this); } @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i4.WKUIDelegate copy() => (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKUIDelegate_10()) as _i4.WKUIDelegate); + @override + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.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 { MockWKUserContentController() { @@ -468,72 +478,74 @@ class MockWKUserContentController extends _i1.Mock } @override - _i6.Future addScriptMessageHandler( + _i5.Future addScriptMessageHandler( _i4.WKScriptMessageHandler? handler, String? name) => (super.noSuchMethod( Invocation.method(#addScriptMessageHandler, [handler, name]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeScriptMessageHandler(String? name) => (super + _i5.Future removeScriptMessageHandler(String? name) => (super .noSuchMethod(Invocation.method(#removeScriptMessageHandler, [name]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( + _i5.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( Invocation.method(#removeAllScriptMessageHandlers, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future addUserScript(_i4.WKUserScript? userScript) => + _i5.Future addUserScript(_i4.WKUserScript? userScript) => (super.noSuchMethod(Invocation.method(#addUserScript, [userScript]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeAllUserScripts() => + _i5.Future removeAllUserScripts() => (super.noSuchMethod(Invocation.method(#removeAllUserScripts, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future addObserver(_i8.NSObject? observer, - {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => + _i4.WKUserContentController copy() => + (super.noSuchMethod(Invocation.method(#copy, []), + returnValue: _FakeWKUserContentController_7()) + as _i4.WKUserContentController); + @override + _i5.Future addObserver(_i7.NSObject? observer, + {String? keyPath, Set<_i7.NSKeyValueObservingOptions>? options}) => (super.noSuchMethod( Invocation.method( #addObserver, [observer], {#keyPath: keyPath, #options: options}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i6.Future removeObserver(_i8.NSObject? observer, {String? keyPath}) => + _i5.Future removeObserver(_i7.NSObject? observer, {String? keyPath}) => (super.noSuchMethod( Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + returnValueForMissingStub: Future.value()) as _i5.Future); } /// A class which mocks [JavascriptChannelRegistry]. /// /// See the documentation for Mockito's code generation for more information. class MockJavascriptChannelRegistry extends _i1.Mock - implements _i9.JavascriptChannelRegistry { + implements _i8.JavascriptChannelRegistry { MockJavascriptChannelRegistry() { _i1.throwOnMissingStub(this); } @override - Map get channels => + Map get channels => (super.noSuchMethod(Invocation.getter(#channels), - returnValue: {}) - as Map); + returnValue: {}) + as Map); @override void onJavascriptChannelMessage(String? channel, String? message) => super.noSuchMethod( Invocation.method(#onJavascriptChannelMessage, [channel, message]), returnValueForMissingStub: null); @override - void updateJavascriptChannelsFromSet(Set<_i10.JavascriptChannel>? channels) => + void updateJavascriptChannelsFromSet(Set<_i9.JavascriptChannel>? channels) => super.noSuchMethod( Invocation.method(#updateJavascriptChannelsFromSet, [channels]), returnValueForMissingStub: null); @@ -543,17 +555,17 @@ class MockJavascriptChannelRegistry extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i9.WebViewPlatformCallbacksHandler { + implements _i8.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i6.FutureOr onNavigationRequest({String? url, bool? isForMainFrame}) => + _i5.FutureOr onNavigationRequest({String? url, bool? isForMainFrame}) => (super.noSuchMethod( Invocation.method(#onNavigationRequest, [], {#url: url, #isForMainFrame: isForMainFrame}), - returnValue: Future.value(false)) as _i6.FutureOr); + returnValue: Future.value(false)) as _i5.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod(Invocation.method(#onPageStarted, [url]), @@ -567,7 +579,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock super.noSuchMethod(Invocation.method(#onProgress, [progress]), returnValueForMissingStub: null); @override - void onWebResourceError(_i11.WebResourceError? error) => + void onWebResourceError(_i10.WebResourceError? error) => super.noSuchMethod(Invocation.method(#onWebResourceError, [error]), returnValueForMissingStub: null); } @@ -576,7 +588,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewWidgetProxy extends _i1.Mock - implements _i12.WebViewWidgetProxy { + implements _i11.WebViewWidgetProxy { MockWebViewWidgetProxy() { _i1.throwOnMissingStub(this); } @@ -584,12 +596,12 @@ class MockWebViewWidgetProxy extends _i1.Mock @override _i4.WKWebView createWebView(_i4.WKWebViewConfiguration? configuration, {void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? + String, _i7.NSObject, Map<_i7.NSKeyValueChangeKey, Object?>)? observeValue}) => (super.noSuchMethod( Invocation.method( #createWebView, [configuration], {#observeValue: observeValue}), - returnValue: _FakeWKWebView_8()) as _i4.WKWebView); + returnValue: _FakeWKWebView_6()) as _i4.WKWebView); @override _i4.WKScriptMessageHandler createScriptMessageHandler( {void Function(_i4.WKUserContentController, _i4.WKScriptMessage)? @@ -597,7 +609,7 @@ class MockWebViewWidgetProxy extends _i1.Mock (super.noSuchMethod( Invocation.method(#createScriptMessageHandler, [], {#didReceiveScriptMessage: didReceiveScriptMessage}), - returnValue: _FakeWKScriptMessageHandler_9()) + returnValue: _FakeWKScriptMessageHandler_4()) as _i4.WKScriptMessageHandler); @override _i4.WKUIDelegate createUIDelgate( @@ -612,11 +624,11 @@ class MockWebViewWidgetProxy extends _i1.Mock _i4.WKNavigationDelegate createNavigationDelegate( {void Function(_i4.WKWebView, String?)? didFinishNavigation, void Function(_i4.WKWebView, String?)? didStartProvisionalNavigation, - _i6.Future<_i4.WKNavigationActionPolicy> Function( + _i5.Future<_i4.WKNavigationActionPolicy> Function( _i4.WKWebView, _i4.WKNavigationAction)? decidePolicyForNavigationAction, - void Function(_i4.WKWebView, _i8.NSError)? didFailNavigation, - void Function(_i4.WKWebView, _i8.NSError)? + void Function(_i4.WKWebView, _i7.NSError)? didFailNavigation, + void Function(_i4.WKWebView, _i7.NSError)? didFailProvisionalNavigation, void Function(_i4.WKWebView)? webViewWebContentProcessDidTerminate}) => @@ -631,6 +643,6 @@ class MockWebViewWidgetProxy extends _i1.Mock #webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate }), - returnValue: _FakeWKNavigationDelegate_11()) + returnValue: _FakeWKNavigationDelegate_2()) as _i4.WKNavigationDelegate); }