summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_delegate_qt.cpp
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2021-01-25 14:59:55 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2021-02-05 08:19:49 +0100
commitc43c3c3ae46735e3d23e0ed70c31143d2556a579 (patch)
treef24808bc3dd12c862510a994b3da8e004749b837 /src/core/web_contents_delegate_qt.cpp
parentf9885840ef2840179f589dd1f71a776df5fd34f3 (diff)
Fix loadFinished signal if page has content but server sends HTTP error
For triggering an error page 3 conditions should be fulfilled: - main frame navigation - the page's document is empty - the HTTP status code indicates an error This fix adds check for the empty document and sends loadFinished signal without expecting an error page if the document is not empty. Fixes: QTBUG-90517 Change-Id: I6463d75fb5e682932feca64b0f059f9aa475795c Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r--src/core/web_contents_delegate_qt.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index e594f648e..1e92a46f8 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -341,6 +341,7 @@ void WebContentsDelegateQt::RenderViewHostChanged(content::RenderViewHost *, con
void WebContentsDelegateQt::EmitLoadStarted(const QUrl &url, bool isErrorPage)
{
+ m_isDocumentEmpty = true;
m_viewClient->loadStarted(url, isErrorPage);
m_viewClient->updateNavigationActions();
@@ -383,9 +384,10 @@ void WebContentsDelegateQt::DidStartNavigation(content::NavigationHandle *naviga
EmitLoadStarted(toQt(navigation_handle->GetURL()));
}
-void WebContentsDelegateQt::EmitLoadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription)
+void WebContentsDelegateQt::EmitLoadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription, bool triggersErrorPage)
{
Q_ASSERT(!isErrorPage || webEngineSettings()->testAttribute(WebEngineSettings::ErrorPageEnabled));
+ Q_ASSERT((triggersErrorPage && webEngineSettings()->testAttribute(WebEngineSettings::ErrorPageEnabled)) || !triggersErrorPage);
// When error page enabled we don't need to send the error page load finished signal
if (m_loadProgressMap[url] == 100)
@@ -396,7 +398,7 @@ void WebContentsDelegateQt::EmitLoadFinished(bool success, const QUrl &url, bool
m_isNavigationCommitted = false;
m_viewClient->loadProgressChanged(100);
- m_viewClient->loadFinished(success, url, isErrorPage, errorCode, errorDescription);
+ m_viewClient->loadFinished(success, url, isErrorPage, errorCode, errorDescription, triggersErrorPage);
m_viewClient->updateNavigationActions();
}
@@ -489,7 +491,11 @@ void WebContentsDelegateQt::DidStopLoading()
void WebContentsDelegateQt::didFailLoad(const QUrl &url, int errorCode, const QString &errorDescription)
{
m_viewClient->iconChanged(QUrl());
- EmitLoadFinished(false /* success */ , url, false /* isErrorPage */, errorCode, errorDescription);
+ bool errorPageEnabled = webEngineSettings()->testAttribute(WebEngineSettings::ErrorPageEnabled);
+ // Delay notifying failure until the error-page is done loading.
+ // Error-pages are not loaded on failures due to abort.
+ bool aborted = (errorCode == -3 /* ERR_ABORTED*/ );
+ EmitLoadFinished(false /* success */ , url, false /* isErrorPage */, errorCode, errorDescription, errorPageEnabled && !aborted);
}
void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code)
@@ -542,7 +548,9 @@ void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame
content::NavigationEntry *entry = web_contents()->GetController().GetActiveEntry();
int http_statuscode = entry ? entry->GetHttpStatusCode() : 0;
- EmitLoadFinished(http_statuscode < 400, toQt(validated_url), false /* isErrorPage */, http_statuscode);
+ bool errorPageEnabled = webEngineSettings()->testAttribute(WebEngineSettings::ErrorPageEnabled);
+ bool triggersErrorPage = errorPageEnabled && (http_statuscode >= 400) && m_isDocumentEmpty;
+ EmitLoadFinished(http_statuscode < 400, toQt(validated_url), false /* isErrorPage */, http_statuscode, QString(), triggersErrorPage);
}
void WebContentsDelegateQt::DidUpdateFaviconURL(content::RenderFrameHost *render_frame_host, const std::vector<blink::mojom::FaviconURLPtr> &candidates)
@@ -856,6 +864,18 @@ bool WebContentsDelegateQt::ShouldNavigateOnBackForwardMouseButtons()
#endif
}
+void WebContentsDelegateQt::ResourceLoadComplete(content::RenderFrameHost* render_frame_host,
+ const content::GlobalRequestID& request_id,
+ const blink::mojom::ResourceLoadInfo& resource_load_info)
+{
+ Q_UNUSED(render_frame_host);
+ Q_UNUSED(request_id);
+
+ if (resource_load_info.request_destination == network::mojom::RequestDestination::kDocument) {
+ m_isDocumentEmpty = (resource_load_info.raw_body_bytes == 0);
+ }
+}
+
FaviconManager *WebContentsDelegateQt::faviconManager()
{
return m_faviconManager.data();