diff --git a/plugins/Mac/Sources/WebView.mm b/plugins/Mac/Sources/WebView.mm index 80ebee84..77015ef1 100644 --- a/plugins/Mac/Sources/WebView.mm +++ b/plugins/Mac/Sources/WebView.mm @@ -166,6 +166,7 @@ - (id)initWithGameObject:(const char *)gameObject_ transparent:(BOOL)transparent // [webView setPolicyDelegate:(id)self]; webView.UIDelegate = self; webView.navigationDelegate = self; + [webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil]; gameObject = [NSString stringWithUTF8String:gameObject_]; if (ua != NULL && strcmp(ua, "") != 0) { [webView setCustomUserAgent:[NSString stringWithUTF8String:ua]]; @@ -186,12 +187,14 @@ - (void)dispose { @synchronized(self) { if (webView != nil) { + WKWebView *webView0 = webView; + webView = nil; // [webView setFrameLoadDelegate:nil]; // [webView setPolicyDelegate:nil]; - webView.UIDelegate = nil; - webView.navigationDelegate = nil; - [webView stopLoading:nil]; - webView = nil; + webView0.UIDelegate = nil; + webView0.navigationDelegate = nil; + [webView0 stopLoading]; + [webView0 removeObserver:self forKeyPath:@"loading"]; } if (window != nil) { [window close]; @@ -218,11 +221,6 @@ - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigatio [self addMessage:[NSString stringWithFormat:@"E%@",[error description]]]; } -- (void)webView:(WKWebView*)wkWebView didCommitNavigation:(null_unspecified WKNavigation *)navigation -{ - [self addMessage:[NSString stringWithFormat:@"L%s","Unknown URL"]]; -} - - (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { if (webView == nil) { @@ -297,6 +295,19 @@ - (void)userContentController:(WKUserContentController *)userContentController */ } +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + if (webView == nil) + return; + + if ([keyPath isEqualToString:@"loading"] && [[change objectForKey:NSKeyValueChangeNewKey] intValue] == 0 + && [webView URL] != nil) { + [self addMessage:[NSString stringWithFormat:@"L%s",[[[webView URL] absoluteString] UTF8String]]]; + } +} + - (void)addMessage:(NSString*)msg { @synchronized(messages)