Skip to content

Commit

Permalink
fix(ios): cookies updated while reloading webview (#11415)
Browse files Browse the repository at this point in the history
* fix(ios): cookies updated in reloading webview

* fix(ios): cookies updated while reloading webview

Co-authored-by: ssekhri <ssekhri@axway.com>
  • Loading branch information
vijaysingh-axway and ssekhri committed Jan 9, 2020
1 parent 9bf5364 commit fc11337
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
UIActivityIndicatorView *_loadingIndicator;
BOOL _isViewDetached;
BOOL _tiCookieHandlerAdded;
BOOL ignoreNextRequest;
SEL reloadMethod;
}

@property (nonatomic, retain) id reloadData;

// Used from the proxy
- (void)setHtml_:(id)args;
- (void)viewDidClose;

- (void)reload;
- (WKWebView *)webView;

- (void)fireEvent:(id)listener withObject:(id)obj remove:(BOOL)yn thisObject:(id)thisObject_;
Expand Down
36 changes: 36 additions & 0 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (void)dealloc
{
RELEASE_TO_NIL(_pageToken);
RELEASE_TO_NIL(_loadingIndicator);
RELEASE_TO_NIL(self.reloadData);
[super dealloc];
}

Expand Down Expand Up @@ -172,6 +173,10 @@ - (void)setWillHandleTouches_:(id)value

- (void)setUrl_:(id)value
{
ignoreNextRequest = YES;
self.reloadData = value;
reloadMethod = @selector(setUrl_:);

ENSURE_TYPE(value, NSString);
[[self proxy] replaceValue:value forKey:@"url" notification:NO];

Expand Down Expand Up @@ -201,6 +206,10 @@ - (void)setBackgroundColor_:(id)value

- (void)setData_:(id)value
{
ignoreNextRequest = YES;
self.reloadData = value;
reloadMethod = @selector(setData_:);

[[self proxy] replaceValue:value forKey:@"data" notification:NO];

if ([[self webView] isLoading]) {
Expand Down Expand Up @@ -241,6 +250,10 @@ - (void)setBlacklistedURLs_:(id)blacklistedURLs

- (void)setHtml_:(id)args
{
ignoreNextRequest = YES;
self.reloadData = args;
reloadMethod = @selector(setHtml_:);

NSString *content = nil;
NSDictionary *options = nil;

Expand Down Expand Up @@ -349,6 +362,18 @@ - (void)setKeyboardDisplayRequiresUserAction_:(id)value
[[self proxy] replaceValue:value forKey:@"keyboardDisplayRequiresUserAction" notification:NO];
}

- (void)reload
{
if (_webView == nil) {
return;
}
if (self.reloadData != nil) {
[self performSelector:reloadMethod withObject:self.reloadData];
return;
}
[[self webView] reload];
}

#pragma mark Utilities

- (void)loadRequestWithURL:(NSURL *)url
Expand Down Expand Up @@ -892,6 +917,7 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
if ([[self proxy] _hasListeners:@"load"]) {
[[self proxy] fireEvent:@"load" withObject:@{ @"url" : webView.URL.absoluteString, @"title" : webView.title }];
}
ignoreNextRequest = NO;
}

- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
Expand Down Expand Up @@ -1063,6 +1089,16 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WK
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
BOOL valid = !ignoreNextRequest;
if ([scheme hasPrefix:@"http"]) {
//UIWebViewNavigationTypeOther means we are either in a META redirect
//or it is a js request from within the page
valid = valid && (navigationAction.navigationType != WKNavigationTypeOther);
}
if (valid) {
self.reloadData = navigationAction.request.URL.absoluteString;
reloadMethod = @selector(setUrl_:);
}
decisionHandler(WKNavigationActionPolicyAllow);
}
}
Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIWebViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ - (void)stopLoading:(id)unused

- (void)reload:(id)unused
{
[[[self webView] webView] reload];
TiThreadPerformOnMainThread(
^{
[[self webView] reload];
},
NO);
}

- (void)repaint:(id)unused
Expand Down

0 comments on commit fc11337

Please sign in to comment.