summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2022-03-24 09:10:15 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2022-04-07 21:46:20 +0200
commita4e32eac5cb858ffa5668b01cef10cc42854713b (patch)
tree0190ecc4bd9be5b74d0be69dbb4d40186f825283 /src/core
parentef685c981d4245b7c704a9d566b05db064756c1f (diff)
Resolve status code for http response with failure
All non-default https status codes are hidden under net::ERR_HTTP_RESPONSE_CODE_FAILURE error of network stack. Handle successful load case and set the real http status code for error. Also set localized load error description only for http codes. Pick-to: 6.2 6.3 Fixes: QTBUG-46860 Fixes: QTBUG-61100 Task-number: QTBUG-94963 Change-Id: I81e083441d1814fb530f39ea3da1c4ef52b7da59 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/web_contents_delegate_qt.cpp20
-rw-r--r--src/core/web_engine_error.cpp19
-rw-r--r--src/core/web_engine_error.h2
3 files changed, 28 insertions, 13 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 7173d05fc..edd7df452 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -64,8 +64,6 @@
#include "certificate_error_controller.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "components/custom_handlers/protocol_handler_registry.h"
-#include "components/error_page/common/error.h"
-#include "components/error_page/common/localized_error.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
@@ -430,9 +428,11 @@ void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navig
return;
// WebContentsObserver::DidFailLoad is not called any longer so we have to report the failure here.
- const net::Error error_code = navigation_handle->GetNetErrorCode();
- const std::string error_description = net::ErrorToString(error_code);
- didFailLoad(toQt(navigation_handle->GetURL()), error_code, toQt(error_description));
+ int error_code = navigation_handle->GetNetErrorCode();
+ if (error_code == net::ERR_HTTP_RESPONSE_CODE_FAILURE)
+ if (auto entry = web_contents()->GetController().GetActiveEntry())
+ error_code = entry->GetHttpStatusCode();
+ didFailLoad(toQt(navigation_handle->GetURL()), error_code, WebEngineError::toQtErrorDescription(error_code));
// The load will succede as an error-page load later, and we reported the original error above
if (navigation_handle->IsErrorPage()) {
@@ -498,12 +498,7 @@ void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_h
emitLoadFinished(/* isErrorPage = */true);
return;
}
- // Qt6: Consider getting rid of the error_description (Chromium already has)
- std::u16string error_description;
- error_description = error_page::LocalizedError::GetErrorDetails(
- error_code <= 0 ? error_page::Error::kNetErrorDomain : error_page::Error::kHttpErrorDomain,
- error_code, false, false);
- didFailLoad(toQt(validated_url), error_code, toQt(error_description));
+ didFailLoad(toQt(validated_url), error_code, WebEngineError::toQtErrorDescription(error_code));
}
void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url)
@@ -532,6 +527,7 @@ void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame
m_loadingInfo.success = http_statuscode < 400;
m_loadingInfo.url = toQt(validated_url);
m_loadingInfo.errorCode = http_statuscode;
+ m_loadingInfo.errorDescription = WebEngineError::toQtErrorDescription(http_statuscode);
m_loadingInfo.triggersErrorPage = triggersErrorPage;
}
@@ -735,7 +731,7 @@ void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransitio
if (!navigationAllowedByPolicy)
errorDescription = QStringLiteral("Launching external protocol forbidden by WebEngineSettings::UnknownUrlSchemePolicy");
else
- errorDescription = QStringLiteral("Launching external protocol suppressed by WebContentsAdapterClient::navigationRequested");
+ errorDescription = QStringLiteral("Launching external protocol suppressed by 'navigationRequested' API");
didFailLoad(url, net::Error::ERR_ABORTED, errorDescription);
}
}
diff --git a/src/core/web_engine_error.cpp b/src/core/web_engine_error.cpp
index 52a84494c..a6580d76b 100644
--- a/src/core/web_engine_error.cpp
+++ b/src/core/web_engine_error.cpp
@@ -38,8 +38,17 @@
****************************************************************************/
#include "web_engine_error.h"
+
+#include "components/error_page/common/error.h"
+#include "components/error_page/common/localized_error.h"
#include "net/base/net_errors.h"
+#include "type_conversion.h"
+
+#include <QString>
+
+using namespace QtWebEngineCore;
+
const int WebEngineError::UserAbortedError = net::ERR_ABORTED;
namespace {
@@ -84,3 +93,13 @@ WebEngineError::ErrorDomain WebEngineError::toQtErrorDomain(int error_code)
else
return WebEngineError::InternalErrorDomain;
}
+
+QString WebEngineError::toQtErrorDescription(int errorCode)
+{
+ if (errorCode < 0)
+ return toQt(net::ErrorToString(errorCode));
+ else if (errorCode > 0)
+ return toQt(error_page::LocalizedError::GetErrorDetails(
+ error_page::Error::kHttpErrorDomain, errorCode, false, false));
+ return QString();
+}
diff --git a/src/core/web_engine_error.h b/src/core/web_engine_error.h
index 7277ffa9d..0ef0950ae 100644
--- a/src/core/web_engine_error.h
+++ b/src/core/web_engine_error.h
@@ -70,7 +70,7 @@ public:
static const int UserAbortedError;
static ErrorDomain toQtErrorDomain(int error_code);
-
+ static QString toQtErrorDescription(int errorCode);
};
#endif // WEB_ENGINE_ERROR_H