From a4376f3760fae97b3ae45c9ae7b62ed505bfa05d Mon Sep 17 00:00:00 2001 From: kh1 Date: Wed, 16 Jun 2010 12:29:53 +0200 Subject: Fix some kind of race condition while using remote commands. Because of async content loading, we have to cache the url to load. A combination of SetSource and SyncContents would have lead to sync to the old url till loading was finished. So return the cached during loading. Task-number: QTBUG-11342 Reviewed-by: ck --- tools/assistant/tools/assistant/helpviewer.cpp | 7 ++++++- tools/assistant/tools/assistant/helpviewer.h | 2 ++ tools/assistant/tools/assistant/helpviewer_p.h | 4 ++++ tools/assistant/tools/assistant/helpviewer_qtb.cpp | 1 + tools/assistant/tools/assistant/helpviewer_qwv.cpp | 12 ++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index a448dd4..2e4b60c 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -189,9 +189,14 @@ void HelpViewer::home() // -- private slots +void HelpViewer::setLoadStarted() +{ + d->m_loadFinished = false; +} + void HelpViewer::setLoadFinished(bool ok) { - Q_UNUSED(ok) + d->m_loadFinished = ok; emit sourceChanged(source()); } diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h index 847b0ca..939096d 100644 --- a/tools/assistant/tools/assistant/helpviewer.h +++ b/tools/assistant/tools/assistant/helpviewer.h @@ -127,6 +127,7 @@ signals: void highlighted(const QString &link); void printRequested(); #else + void loadStarted(); void loadFinished(bool finished); #endif @@ -138,6 +139,7 @@ protected: private slots: void actionChanged(); + void setLoadStarted(); void setLoadFinished(bool ok); private: diff --git a/tools/assistant/tools/assistant/helpviewer_p.h b/tools/assistant/tools/assistant/helpviewer_p.h index 2772905..d65bab5 100644 --- a/tools/assistant/tools/assistant/helpviewer_p.h +++ b/tools/assistant/tools/assistant/helpviewer_p.h @@ -67,6 +67,7 @@ public: HelpViewerPrivate() #endif { + m_loadFinished = false; } #ifdef QT_NO_WEBKIT @@ -112,6 +113,9 @@ public: bool forceFont; QString lastAnchor; #endif // QT_NO_WEBKIT + +public: + bool m_loadFinished; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp index f6b5022..af744b7 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp @@ -160,6 +160,7 @@ void HelpViewer::setSource(const QUrl &url) if (launchWithExternalApp(url)) return; + emit loadStarted(); QString string = url.toString(); const HelpEngineWrapper &engine = HelpEngineWrapper::instance(); const QUrl &resolvedUrl = (string == QLatin1String("help") ? LocalHelpFile : diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp index f61d6d4..8993ac9 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp @@ -180,6 +180,7 @@ private: bool closeNewTabIfNeeded; friend class HelpViewer; + QUrl m_loadingUrl; Qt::MouseButtons m_pressedButtons; Qt::KeyboardModifiers m_keyboardModifiers; }; @@ -237,6 +238,11 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, return false; } + m_loadingUrl = url; // because of async page loading, we will hit some kind + // of race condition while using a remote command, like a combination of + // SetSource; SyncContent. SetSource would be called and SyncContents shortly + // afterwards, but the page might not have finished loading and the old url + // would be returned. return true; } @@ -270,6 +276,7 @@ HelpViewer::HelpViewer(qreal zoom, QWidget *parent) connect(page(), SIGNAL(linkHovered(QString, QString, QString)), this, SIGNAL(highlighted(QString))); connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl))); + connect(this, SIGNAL(loadStarted()), this, SLOT(setLoadStarted())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool))); connect(this, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged())); connect(page(), SIGNAL(printRequested(QWebFrame*)), this, SIGNAL(printRequested())); @@ -336,6 +343,11 @@ void HelpViewer::setTitle(const QString &title) QUrl HelpViewer::source() const { TRACE_OBJ + HelpPage *currentPage = static_cast (page()); + if (currentPage && !d->m_loadFinished) { + // see HelpPage::acceptNavigationRequest(...) + return currentPage->m_loadingUrl; + } return url(); } -- cgit v0.12