@@ -74,26 +74,26 @@ - (instancetype)initWithFrame:(CGRect)frame
7474 binaryMessenger : (NSObject <FlutterBinaryMessenger>*)messenger {
7575 if (self = [super init ]) {
7676 _viewId = viewId;
77-
77+
7878 NSString * channelName = [NSString stringWithFormat: @" plugins.flutter.io/webview_%lld " , viewId];
7979 _channel = [FlutterMethodChannel methodChannelWithName: channelName binaryMessenger: messenger];
8080 _javaScriptChannelNames = [[NSMutableSet alloc ] init ];
81-
81+
8282 WKUserContentController * userContentController = [[WKUserContentController alloc ] init ];
8383 if ([args[@" javascriptChannelNames" ] isKindOfClass: [NSArray class ]]) {
8484 NSArray * javaScriptChannelNames = args[@" javascriptChannelNames" ];
8585 [_javaScriptChannelNames addObjectsFromArray: javaScriptChannelNames];
8686 [self registerJavaScriptChannels: _javaScriptChannelNames controller: userContentController];
8787 }
88-
88+
8989 NSDictionary <NSString *, id >* settings = args[@" settings" ];
90-
90+
9191 WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc ] init ];
9292 [self applyConfigurationSettings: settings toConfiguration: configuration];
9393 configuration.userContentController = userContentController;
9494 [self updateAutoMediaPlaybackPolicy: args[@" autoMediaPlaybackPolicy" ]
9595 inConfiguration: configuration];
96-
96+
9797 _webView = [[FLTWKWebView alloc ] initWithFrame: frame configuration: configuration];
9898 _navigationDelegate = [[FLTWKNavigationDelegate alloc ] initWithChannel: _channel];
9999 _webView.UIDelegate = self;
@@ -102,18 +102,18 @@ - (instancetype)initWithFrame:(CGRect)frame
102102 [_channel setMethodCallHandler: ^(FlutterMethodCall* call, FlutterResult result) {
103103 [weakSelf onMethodCall: call result: result];
104104 }];
105-
105+
106106 if (@available (iOS 11.0 , *)) {
107107 _webView.scrollView .contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
108108 if (@available (iOS 13.0 , *)) {
109109 _webView.scrollView .automaticallyAdjustsScrollIndicatorInsets = NO ;
110110 }
111111 }
112-
112+
113113 [self applySettings: settings];
114114 // TODO(amirh): return an error if apply settings failed once it's possible to do so.
115115 // https://github.com/flutter/flutter/issues/36228
116-
116+
117117 NSString * initialUrl = args[@" initialUrl" ];
118118 if ([initialUrl isKindOfClass: [NSString class ]]) {
119119 [self loadUrl: initialUrl];
@@ -188,9 +188,9 @@ - (void)onUpdateSettings:(FlutterMethodCall*)call result:(FlutterResult)result {
188188- (void )onLoadUrl : (FlutterMethodCall*)call result : (FlutterResult)result {
189189 if (![self loadRequest: [call arguments ]]) {
190190 result ([FlutterError
191- errorWithCode: @" loadUrl_failed"
192- message: @" Failed parsing the URL"
193- details: [NSString stringWithFormat: @" Request was: '%@ '" , [call arguments ]]]);
191+ errorWithCode: @" loadUrl_failed"
192+ message: @" Failed parsing the URL"
193+ details: [NSString stringWithFormat: @" Request was: '%@ '" , [call arguments ]]]);
194194 } else {
195195 result (nil );
196196 }
@@ -236,16 +236,16 @@ - (void)onEvaluateJavaScript:(FlutterMethodCall*)call result:(FlutterResult)resu
236236 }
237237 [_webView evaluateJavaScript: jsString
238238 completionHandler: ^(_Nullable id evaluateResult, NSError * _Nullable error) {
239- if (error) {
240- result ([FlutterError
241- errorWithCode: @" evaluateJavaScript_failed"
242- message: @" Failed evaluating JavaScript"
243- details: [NSString stringWithFormat: @" JavaScript string was: '%@ '\n %@ " ,
244- jsString, error]]);
245- } else {
246- result ([NSString stringWithFormat: @" %@ " , evaluateResult]);
247- }
248- }];
239+ if (error) {
240+ result ([FlutterError
241+ errorWithCode: @" evaluateJavaScript_failed"
242+ message: @" Failed evaluating JavaScript"
243+ details: [NSString stringWithFormat: @" JavaScript string was: '%@ '\n %@ " ,
244+ jsString, error]]);
245+ } else {
246+ result ([NSString stringWithFormat: @" %@ " , evaluateResult]);
247+ }
248+ }];
249249}
250250
251251- (void )onRunJavaScript : (FlutterMethodCall*)call
@@ -259,27 +259,27 @@ - (void)onRunJavaScript:(FlutterMethodCall*)call
259259 return ;
260260 }
261261 [_webView
262- evaluateJavaScript: jsString
263- completionHandler: ^(_Nullable id evaluateResult, NSError * _Nullable error) {
264- if (error) {
265- // WebKit will throw an error (WKErrorJavaScriptResultTypeIsUnsupported) when the
266- // type of the evaluated value is unsupported. This also goes for
267- // `null` and `undefined` on iOS 14+, for example when running a void function.
268- // For ease of use this specific error is ignored when no return value is expected.
269- BOOL sendError = sendReturnValue || error.code != WKErrorJavaScriptResultTypeIsUnsupported ;
270- result (
271- sendError
272- ? [FlutterError
273- errorWithCode: (sendReturnValue ? @" runJavascriptReturningResult_failed"
274- : @" runJavascript_failed" )
275- message: @" Failed running JavaScript"
276- details: [NSString stringWithFormat: @" JavaScript string was: '%@ '\n %@ " ,
277- jsString, error]]
278- : nil );
279- return ;
280- }
281- result (sendReturnValue ? [NSString stringWithFormat: @" %@ " , evaluateResult] : nil );
282- }];
262+ evaluateJavaScript: jsString
263+ completionHandler: ^(_Nullable id evaluateResult, NSError * _Nullable error) {
264+ if (error) {
265+ // WebKit will throw an error (WKErrorJavaScriptResultTypeIsUnsupported) when the
266+ // type of the evaluated value is unsupported. This also goes for
267+ // `null` and `undefined` on iOS 14+, for example when running a void function.
268+ // For ease of use this specific error is ignored when no return value is expected.
269+ BOOL sendError = sendReturnValue || error.code != WKErrorJavaScriptResultTypeIsUnsupported ;
270+ result (
271+ sendError
272+ ? [FlutterError
273+ errorWithCode: (sendReturnValue ? @" runJavascriptReturningResult_failed"
274+ : @" runJavascript_failed" )
275+ message: @" Failed running JavaScript"
276+ details: [NSString stringWithFormat: @" JavaScript string was: '%@ '\n %@ " ,
277+ jsString, error]]
278+ : nil );
279+ return ;
280+ }
281+ result (sendReturnValue ? [NSString stringWithFormat: @" %@ " , evaluateResult] : nil );
282+ }];
283283}
284284
285285- (void )onAddJavaScriptChannels : (FlutterMethodCall*)call result : (FlutterResult)result {
@@ -298,12 +298,12 @@ - (void)onRemoveJavaScriptChannels:(FlutterMethodCall*)call result:(FlutterResul
298298 for (NSString * channelName in _javaScriptChannelNames) {
299299 [_webView.configuration.userContentController removeScriptMessageHandlerForName: channelName];
300300 }
301-
301+
302302 NSArray * channelNamesToRemove = [call arguments ];
303303 for (NSString * channelName in channelNamesToRemove) {
304304 [_javaScriptChannelNames removeObject: channelName];
305305 }
306-
306+
307307 [self registerJavaScriptChannels: _javaScriptChannelNames
308308 controller: _webView.configuration.userContentController];
309309 result (nil );
@@ -317,8 +317,8 @@ - (void)clearCache:(FlutterResult)result {
317317 [dataStore removeDataOfTypes: cacheDataTypes
318318 modifiedSince: dateFrom
319319 completionHandler: ^{
320- result (nil );
321- }];
320+ result (nil );
321+ }];
322322 } else {
323323 // support for iOS8 tracked in https://github.com/flutter/flutter/issues/27624.
324324 NSLog (@" Clearing cache is not supported for Flutter WebViews prior to iOS 9." );
@@ -334,18 +334,18 @@ - (void)onScrollTo:(FlutterMethodCall*)call result:(FlutterResult)result {
334334 NSDictionary * arguments = [call arguments ];
335335 int x = [arguments[@" x" ] intValue ];
336336 int y = [arguments[@" y" ] intValue ];
337-
337+
338338 _webView.scrollView .contentOffset = CGPointMake (x, y);
339339 result (nil );
340340}
341341
342342- (void )onScrollBy : (FlutterMethodCall*)call result : (FlutterResult)result {
343343 CGPoint contentOffset = _webView.scrollView .contentOffset ;
344-
344+
345345 NSDictionary * arguments = [call arguments ];
346346 int x = [arguments[@" x" ] intValue ] + contentOffset.x ;
347347 int y = [arguments[@" y" ] intValue ] + contentOffset.y ;
348-
348+
349349 _webView.scrollView .contentOffset = CGPointMake (x, y);
350350 result (nil );
351351}
@@ -382,7 +382,7 @@ - (NSString*)applySettings:(NSDictionary<NSString*, id>*)settings {
382382 } else if ([key isEqualToString: @" gestureNavigationEnabled" ]) {
383383 NSNumber * allowsBackForwardNavigationGestures = settings[key];
384384 _webView.allowsBackForwardNavigationGestures =
385- [allowsBackForwardNavigationGestures boolValue ];
385+ [allowsBackForwardNavigationGestures boolValue ];
386386 } else if ([key isEqualToString: @" userAgent" ]) {
387387 NSString * userAgent = settings[key];
388388 [self updateUserAgent: [userAgent isEqual: [NSNull null ]] ? nil : userAgent];
@@ -397,7 +397,7 @@ - (NSString*)applySettings:(NSDictionary<NSString*, id>*)settings {
397397 return nil ;
398398 }
399399 return [NSString stringWithFormat: @" webview_flutter: unknown setting keys: {%@ }" ,
400- [unknownKeys componentsJoinedByString: @" , " ]];
400+ [unknownKeys componentsJoinedByString: @" , " ]];
401401}
402402
403403- (void )applyConfigurationSettings : (NSDictionary <NSString*, id>*)settings
@@ -462,7 +462,7 @@ - (bool)loadRequest:(NSDictionary<NSString*, id>*)request {
462462 if (!request) {
463463 return false ;
464464 }
465-
465+
466466 NSString * url = request[@" url" ];
467467 if ([url isKindOfClass: [NSString class ]]) {
468468 id headers = request[@" headers" ];
@@ -472,7 +472,7 @@ - (bool)loadRequest:(NSDictionary<NSString*, id>*)request {
472472 return [self loadUrl: url];
473473 }
474474 }
475-
475+
476476 return false ;
477477}
478478
@@ -495,15 +495,15 @@ - (void)registerJavaScriptChannels:(NSSet*)channelNames
495495 controller : (WKUserContentController *)userContentController {
496496 for (NSString * channelName in channelNames) {
497497 FLTJavaScriptChannel* channel =
498- [[FLTJavaScriptChannel alloc ] initWithMethodChannel: _channel
499- javaScriptChannelName: channelName];
498+ [[FLTJavaScriptChannel alloc ] initWithMethodChannel: _channel
499+ javaScriptChannelName: channelName];
500500 [userContentController addScriptMessageHandler: channel name: channelName];
501501 NSString * wrapperSource = [NSString
502- stringWithFormat: @" window.%@ = webkit.messageHandlers.%@ ;" , channelName, channelName];
502+ stringWithFormat: @" window.%@ = webkit.messageHandlers.%@ ;" , channelName, channelName];
503503 WKUserScript * wrapperScript =
504- [[WKUserScript alloc ] initWithSource: wrapperSource
505- injectionTime: WKUserScriptInjectionTimeAtDocumentStart
506- forMainFrameOnly: NO ];
504+ [[WKUserScript alloc ] initWithSource: wrapperSource
505+ injectionTime: WKUserScriptInjectionTimeAtDocumentStart
506+ forMainFrameOnly: NO ];
507507 [userContentController addUserScript: wrapperScript];
508508 }
509509}
@@ -519,13 +519,13 @@ - (void)updateUserAgent:(NSString*)userAgent {
519519#pragma mark WKUIDelegate
520520
521521- (WKWebView *)webView : (WKWebView *)webView
522- createWebViewWithConfiguration : (WKWebViewConfiguration *)configuration
523- forNavigationAction : (WKNavigationAction *)navigationAction
524- windowFeatures : (WKWindowFeatures *)windowFeatures {
522+ createWebViewWithConfiguration : (WKWebViewConfiguration *)configuration
523+ forNavigationAction : (WKNavigationAction *)navigationAction
524+ windowFeatures : (WKWindowFeatures *)windowFeatures {
525525 if (!navigationAction.targetFrame .isMainFrame ) {
526526 [webView loadRequest: navigationAction.request];
527527 }
528-
528+
529529 return nil ;
530530}
531531
0 commit comments