From ad8bc45732eeb2efa6e885d564c10761e7154889 Mon Sep 17 00:00:00 2001 From: Michael Bruning Date: Wed, 18 May 2016 15:35:42 +0200 Subject: Let setContent / setHtml fail when content is too big to load. Chromium fails silently - except for a log entry - when the size of the content is larger than 2 MB. This was causing trouble because the user was not informed about the failed load at all. Task-number: QTBUG-53414 Change-Id: I80f3f36b5eac72f3809538c19ff314068b75b61d Reviewed-by: Joerg Bornemann --- src/core/web_contents_adapter.cpp | 8 +++++++- src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 66d133f60..c450768fa 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -68,6 +68,7 @@ #include "content/public/common/page_zoom.h" #include "content/public/common/renderer_preferences.h" #include "content/public/common/url_constants.h" +#include "content/public/common/url_utils.h" #include "content/public/common/web_preferences.h" #include "third_party/WebKit/public/web/WebFindOptions.h" @@ -485,7 +486,12 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT urlString.append(","); urlString.append(encodedData.constData(), encodedData.length()); - content::NavigationController::LoadURLParams params((GURL(urlString))); + GURL dataUrlToLoad(urlString); + if (dataUrlToLoad.spec().size() > content::GetMaxURLChars()) { + d->adapterClient->loadFinished(false, baseUrl, false, net::ERR_ABORTED); + return; + } + content::NavigationController::LoadURLParams params((dataUrlToLoad)); params.load_type = content::NavigationController::LOAD_TYPE_DATA; params.base_url_for_data_url = toGurl(baseUrl); params.virtual_url_for_data_url = baseUrl.isEmpty() ? GURL(url::kAboutBlankURL) : toGurl(baseUrl); diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc index 50578a0e7..0900765fc 100644 --- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc +++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc @@ -607,6 +607,10 @@ \warning This function works only for HTML, for other mime types (such as XHTML and SVG) setContent() should be used instead. + \warning The content will be percent encoded before being sent to the renderer via IPC. + This may increase its size. The maximum size of the percent encoded content is + 2 megabytes minus 30 bytes. + \sa toHtml(), setContent(), load() */ @@ -622,6 +626,10 @@ \note This method will not affect session or global history for the page. + \warning The content will be percent encoded before being sent to the renderer via IPC. + This may increase its size. The maximum size of the percent encoded content is + 2 megabytes minus 6 bytes plus the length of the mime type string. + \sa toHtml(), setHtml() */ -- cgit v1.2.3