@@ -44,6 +44,7 @@ - (void)dealloc
44
44
{
45
45
RELEASE_TO_NIL (_pageToken);
46
46
RELEASE_TO_NIL (_loadingIndicator);
47
+ RELEASE_TO_NIL (self.reloadData );
47
48
[super dealloc ];
48
49
}
49
50
@@ -174,6 +175,10 @@ - (void)setWillHandleTouches_:(id)value
174
175
175
176
- (void )setUrl_ : (id )value
176
177
{
178
+ ignoreNextRequest = YES ;
179
+ self.reloadData = value;
180
+ reloadMethod = @selector (setUrl_: );
181
+
177
182
ENSURE_TYPE (value, NSString );
178
183
[[self proxy ] replaceValue: value forKey: @" url" notification: NO ];
179
184
@@ -203,6 +208,10 @@ - (void)setBackgroundColor_:(id)value
203
208
204
209
- (void )setData_ : (id )value
205
210
{
211
+ ignoreNextRequest = YES ;
212
+ self.reloadData = value;
213
+ reloadMethod = @selector (setData_: );
214
+
206
215
[[self proxy ] replaceValue: value forKey: @" data" notification: NO ];
207
216
208
217
if ([[self webView ] isLoading ]) {
@@ -243,6 +252,10 @@ - (void)setBlacklistedURLs_:(id)blacklistedURLs
243
252
244
253
- (void )setHtml_ : (id )args
245
254
{
255
+ ignoreNextRequest = YES ;
256
+ self.reloadData = args;
257
+ reloadMethod = @selector (setHtml_: );
258
+
246
259
NSString *content = nil ;
247
260
NSDictionary *options = nil ;
248
261
@@ -351,6 +364,18 @@ - (void)setKeyboardDisplayRequiresUserAction_:(id)value
351
364
[[self proxy ] replaceValue: value forKey: @" keyboardDisplayRequiresUserAction" notification: NO ];
352
365
}
353
366
367
+ - (void )reload
368
+ {
369
+ if (_webView == nil ) {
370
+ return ;
371
+ }
372
+ if (self.reloadData != nil ) {
373
+ [self performSelector: reloadMethod withObject: self .reloadData];
374
+ return ;
375
+ }
376
+ [[self webView ] reload ];
377
+ }
378
+
354
379
#pragma mark Utilities
355
380
356
381
- (void )loadRequestWithURL : (NSURL *)url
@@ -894,6 +919,7 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
894
919
if ([[self proxy ] _hasListeners: @" load" ]) {
895
920
[[self proxy ] fireEvent: @" load" withObject: @{ @" url" : webView.URL .absoluteString , @" title" : webView.title }];
896
921
}
922
+ ignoreNextRequest = NO ;
897
923
}
898
924
899
925
- (void )webView : (WKWebView *)webView didFailNavigation : (WKNavigation *)navigation withError : (NSError *)error
@@ -1058,27 +1084,20 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WK
1058
1084
[[UIApplication sharedApplication ] openURL: navigationAction.request.URL];
1059
1085
decisionHandler (WKNavigationActionPolicyCancel );
1060
1086
} else {
1087
+ BOOL valid = !ignoreNextRequest;
1088
+ if ([scheme hasPrefix: @" http" ]) {
1089
+ // UIWebViewNavigationTypeOther means we are either in a META redirect
1090
+ // or it is a js request from within the page
1091
+ valid = valid && (navigationAction.navigationType != WKNavigationTypeOther );
1092
+ }
1093
+ if (valid) {
1094
+ self.reloadData = navigationAction.request .URL .absoluteString ;
1095
+ reloadMethod = @selector (setUrl_: );
1096
+ }
1061
1097
decisionHandler (WKNavigationActionPolicyAllow );
1062
1098
}
1063
1099
}
1064
1100
1065
- - (void )webView : (WKWebView *)webView decidePolicyForNavigationResponse : (WKNavigationResponse *)navigationResponse decisionHandler : (void (^)(WKNavigationResponsePolicy ))decisionHandler
1066
- {
1067
- NSDictionary <NSString *, id > *requestHeaders = [[self proxy ] valueForKey: @" requestHeaders" ];
1068
- NSURL *requestedURL = navigationResponse.response .URL ;
1069
-
1070
- // If we have request headers set, we do a little hack to persist them across different URL's,
1071
- // which is not officially supported by iOS.
1072
- if (requestHeaders != nil && requestedURL != nil && ![requestedURL.absoluteString isEqualToString: _currentURL.absoluteString]) {
1073
- _currentURL = requestedURL;
1074
- decisionHandler (WKNavigationResponsePolicyCancel );
1075
- [self loadRequestWithURL: _currentURL];
1076
- return ;
1077
- }
1078
-
1079
- decisionHandler (WKNavigationResponsePolicyAllow );
1080
- }
1081
-
1082
1101
- (WKWebView *)webView : (WKWebView *)webView createWebViewWithConfiguration : (WKWebViewConfiguration *)configuration forNavigationAction : (WKNavigationAction *)navigationAction windowFeatures : (WKWindowFeatures *)windowFeatures
1083
1102
{
1084
1103
if (!navigationAction.targetFrame .isMainFrame ) {
0 commit comments