From 5b5785bc564ccea9f6868d02be3d1080cb5039b9 Mon Sep 17 00:00:00 2001 From: kh1 Date: Wed, 16 Jun 2010 12:24:12 +0200 Subject: Fix some kind of race condition while using remote commands. Please do not merge to master, we had to fix it different there. 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_qwv.cpp | 23 +++++++++++++++++++++- tools/assistant/tools/assistant/helpviewer_qwv.h | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp index 244d091..dcbbf2c 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp @@ -172,6 +172,7 @@ private: bool closeNewTabIfNeeded; friend class HelpViewer; + QUrl m_loadingUrl; Qt::MouseButtons m_pressedButtons; Qt::KeyboardModifiers m_keyboardModifiers; }; @@ -232,6 +233,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; } @@ -268,6 +274,7 @@ HelpViewer::HelpViewer(CentralWidget *parent, qreal zoom) 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(page(), SIGNAL(printRequested(QWebFrame*)), this, SIGNAL(printRequested())); @@ -333,10 +340,19 @@ bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *e) return false; } +QUrl HelpViewer::source() const +{ + HelpPage *currentPage = static_cast (page()); + if (currentPage && !hasLoadFinished()) { + // see HelpPage::acceptNavigationRequest(...) + return currentPage->m_loadingUrl; + } + return url(); +} + void HelpViewer::setSource(const QUrl &url) { TRACE_OBJ - loadFinished = false; load(url.toString() == QLatin1String("help") ? LocalHelpFile : url); } @@ -396,6 +412,11 @@ void HelpViewer::mousePressEvent(QMouseEvent *event) QWebView::mousePressEvent(event); } +void HelpViewer::setLoadStarted() +{ + loadFinished = false; +} + void HelpViewer::setLoadFinished(bool ok) { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.h b/tools/assistant/tools/assistant/helpviewer_qwv.h index 2577828..1897e3e 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.h +++ b/tools/assistant/tools/assistant/helpviewer_qwv.h @@ -71,8 +71,8 @@ public: bool handleForwardBackwardMouseButtons(QMouseEvent *e); + QUrl source() const; void setSource(const QUrl &url); - inline QUrl source() const { return url(); } inline QString documentTitle() const { return title(); } @@ -109,6 +109,7 @@ protected: private Q_SLOTS: void actionChanged(); + void setLoadStarted(); void setLoadFinished(bool ok); private: -- cgit v0.12