summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2018-11-28 07:13:08 +0100
committerAndy Shaw <andy.shaw@qt.io>2018-11-29 10:30:56 +0000
commitd53e316480889660e1668ef4b46a122dc333c499 (patch)
tree84a1516b50d44d3038e1630a739ae0ea8f8d7f80
parentdade6ce5d75b48573980308f2f8b487620a232e6 (diff)
iOS: Keep the navigation object passed into didStart for finishing
Instead of relying on the different frames to fail or finish as this is not reliable in iOS 12 we check if the navigation object passed into didFinish is the last one we got in didStart. At that point we can assume that the page has in fact finished loading. Change-Id: I06c20863b27a384d3532c06a18723ad5d3347363 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r--src/plugins/darwin/qdarwinwebview.mm49
-rw-r--r--src/plugins/darwin/qdarwinwebview_p.h3
2 files changed, 26 insertions, 26 deletions
diff --git a/src/plugins/darwin/qdarwinwebview.mm b/src/plugins/darwin/qdarwinwebview.mm
index 66bb61f..e82771f 100644
--- a/src/plugins/darwin/qdarwinwebview.mm
+++ b/src/plugins/darwin/qdarwinwebview.mm
@@ -160,49 +160,50 @@ QT_END_NAMESPACE
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
Q_UNUSED(webView);
- Q_UNUSED(navigation);
// WKNavigationDelegate gives us per-frame notifications while the QWebView API
- // should provide per-page notifications. Keep track of started frame loads
- // and emit notifications when the final frame completes.
- if (++qDarwinWebViewPrivate->requestFrameCount == 1) {
- Q_EMIT qDarwinWebViewPrivate->loadingChanged(
- QWebViewLoadRequestPrivate(qDarwinWebViewPrivate->url(),
- QWebView::LoadStartedStatus,
- QString()));
- }
+ // should provide per-page notifications. Therefore we keep track of the last frame
+ // to be started, if that finishes or fails then we indicate that it has loaded.
+ if (qDarwinWebViewPrivate->wkNavigation != navigation)
+ qDarwinWebViewPrivate->wkNavigation = navigation;
+ else
+ return;
+ Q_EMIT qDarwinWebViewPrivate->loadingChanged(
+ QWebViewLoadRequestPrivate(qDarwinWebViewPrivate->url(),
+ QWebView::LoadStartedStatus,
+ QString()));
Q_EMIT qDarwinWebViewPrivate->loadProgressChanged(qDarwinWebViewPrivate->loadProgress());
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
Q_UNUSED(webView);
- Q_UNUSED(navigation);
- if (--qDarwinWebViewPrivate->requestFrameCount == 0) {
- [self pageDone];
- Q_EMIT qDarwinWebViewPrivate->loadingChanged(
- QWebViewLoadRequestPrivate(qDarwinWebViewPrivate->url(),
- QWebView::LoadSucceededStatus,
- QString()));
- }
+ if (qDarwinWebViewPrivate->wkNavigation != navigation)
+ return;
+
+ [self pageDone];
+ Q_EMIT qDarwinWebViewPrivate->loadingChanged(
+ QWebViewLoadRequestPrivate(qDarwinWebViewPrivate->url(),
+ QWebView::LoadSucceededStatus,
+ QString()));
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation
withError:(NSError *)error
{
Q_UNUSED(webView);
- Q_UNUSED(navigation);
- if (--qDarwinWebViewPrivate->requestFrameCount == 0)
- [self handleError:error];
+ if (qDarwinWebViewPrivate->wkNavigation != navigation)
+ return;
+ [self handleError:error];
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation
withError:(NSError *)error
{
Q_UNUSED(webView);
- Q_UNUSED(navigation);
- if (--qDarwinWebViewPrivate->requestFrameCount == 0)
- [self handleError:error];
+ if (qDarwinWebViewPrivate->wkNavigation != navigation)
+ return;
+ [self handleError:error];
}
- (void)webView:(WKWebView *)webView
@@ -304,8 +305,6 @@ QUrl QDarwinWebViewPrivate::url() const
void QDarwinWebViewPrivate::setUrl(const QUrl &url)
{
if (url.isValid()) {
- requestFrameCount = 0;
-
if (url.isLocalFile()) {
// We need to pass local files via loadFileURL and the read access should cover
// the directory that the file is in, to facilitate loading referenced images etc
diff --git a/src/plugins/darwin/qdarwinwebview_p.h b/src/plugins/darwin/qdarwinwebview_p.h
index 8bc9c13..96fb09e 100644
--- a/src/plugins/darwin/qdarwinwebview_p.h
+++ b/src/plugins/darwin/qdarwinwebview_p.h
@@ -67,6 +67,7 @@
#endif
Q_FORWARD_DECLARE_OBJC_CLASS(WKWebView);
+Q_FORWARD_DECLARE_OBJC_CLASS(WKNavigation);
#ifdef Q_OS_IOS
Q_FORWARD_DECLARE_OBJC_CLASS(UIGestureRecognizer);
@@ -109,10 +110,10 @@ protected:
public:
WKWebView *wkWebView;
+ WKNavigation *wkNavigation;
#ifdef Q_OS_IOS
UIGestureRecognizer *m_recognizer;
#endif
- int requestFrameCount;
QPointer<QObject> m_parentView;
};