From f7103bc5fd099dd0a0772ef28930dd368e9fcf47 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 4 Dec 2017 10:29:25 +0100 Subject: Fix Message Bubble position for High-DPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-64812 Change-Id: I9df71253cf6c541622e431b1ff444fc49269d0c3 Reviewed-by: Jüri Valdmann Reviewed-by: Allan Sandfeld Jensen --- src/core/web_contents_delegate_qt.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 7d4c671b0..26da6348a 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -79,6 +79,16 @@ namespace QtWebEngineCore { +static gfx::Rect rootViewToScreenRect(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view) +{ + RenderWidgetHostViewQt *rwhv = static_cast(web_contents->GetRenderWidgetHostView()); + if (!rwhv) + return gfx::Rect(); + content::ScreenInfo screenInfo; + rwhv->GetScreenInfo(&screenInfo); + return gfx::ScaleToEnclosingRect(anchor_in_root_view, 1 / screenInfo.device_scale_factor); +} + // Maps the LogSeverity defines in base/logging.h to the web engines message levels. static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptConsoleMessageLevel(int32_t messageLevel) { if (messageLevel < 1) @@ -457,8 +467,10 @@ void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransitio void WebContentsDelegateQt::ShowValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view, const base::string16 &main_text, const base::string16 &sub_text) { - Q_UNUSED(web_contents); - m_viewClient->showValidationMessage(toQt(anchor_in_root_view), toQt(main_text), toQt(sub_text)); + gfx::Rect anchor = rootViewToScreenRect(web_contents, anchor_in_root_view); + if (anchor.IsEmpty()) + return; + m_viewClient->showValidationMessage(toQt(anchor), toQt(main_text), toQt(sub_text)); } void WebContentsDelegateQt::HideValidationMessage(content::WebContents *web_contents) @@ -469,8 +481,10 @@ void WebContentsDelegateQt::HideValidationMessage(content::WebContents *web_cont void WebContentsDelegateQt::MoveValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view) { - Q_UNUSED(web_contents); - m_viewClient->moveValidationMessage(toQt(anchor_in_root_view)); + gfx::Rect anchor = rootViewToScreenRect(web_contents, anchor_in_root_view); + if (anchor.IsEmpty()) + return; + m_viewClient->moveValidationMessage(toQt(anchor)); } void WebContentsDelegateQt::BeforeUnloadFired(content::WebContents *tab, bool proceed, bool *proceed_to_fire_unload) -- cgit v1.2.3 From 2f7667ba5f58eefbc47ef8cbe319b12922bfafc9 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 7 Dec 2017 13:39:00 +0100 Subject: Check for null renderView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can according to documentation potentially be null, even if it might not happen in our cases. Task-number: QTBUG-63854 Change-Id: I76029c83fe32c163c2707568fe81b7590a79b4fe Reviewed-by: Alexandru Croitor Reviewed-by: Michael Brüning Reviewed-by: Viktor Engelmann --- src/core/renderer/user_resource_controller.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/renderer/user_resource_controller.cpp b/src/core/renderer/user_resource_controller.cpp index b172c762b..36125d189 100644 --- a/src/core/renderer/user_resource_controller.cpp +++ b/src/core/renderer/user_resource_controller.cpp @@ -129,6 +129,8 @@ void UserResourceController::RenderViewObserverHelper::runScripts(UserScriptData void UserResourceController::runScripts(UserScriptData::InjectionPoint p, blink::WebLocalFrame *frame) { content::RenderView *renderView = content::RenderView::FromWebView(frame->view()); + if (!renderView) + return; const bool isMainFrame = (frame == renderView->GetWebView()->mainFrame()); QList scriptsToRun = m_viewUserScriptMap.value(globalScriptsIndex).toList(); @@ -192,7 +194,8 @@ void UserResourceController::RenderViewObserverHelper::FrameDetached(blink::WebF void UserResourceController::RenderViewObserverHelper::OnDestruct() { - UserResourceController::instance()->renderViewDestroyed(render_view()); + if (content::RenderView *view = render_view()) + UserResourceController::instance()->renderViewDestroyed(view); } bool UserResourceController::RenderViewObserverHelper::OnMessageReceived(const IPC::Message &message) @@ -209,17 +212,20 @@ bool UserResourceController::RenderViewObserverHelper::OnMessageReceived(const I void UserResourceController::RenderViewObserverHelper::onUserScriptAdded(const UserScriptData &script) { - UserResourceController::instance()->addScriptForView(script, render_view()); + if (content::RenderView *view = render_view()) + UserResourceController::instance()->addScriptForView(script, view); } void UserResourceController::RenderViewObserverHelper::onUserScriptRemoved(const UserScriptData &script) { - UserResourceController::instance()->removeScriptForView(script, render_view()); + if (content::RenderView *view = render_view()) + UserResourceController::instance()->removeScriptForView(script, view); } void UserResourceController::RenderViewObserverHelper::onScriptsCleared() { - UserResourceController::instance()->clearScriptsForView(render_view()); + if (content::RenderView *view = render_view()) + UserResourceController::instance()->clearScriptsForView(view); } UserResourceController *UserResourceController::instance() -- cgit v1.2.3 From fda2f858bef4d25c711f02fbb0f2aa0127a6c3b5 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Thu, 7 Dec 2017 16:09:25 +0100 Subject: Fix favicon update from JavaScript Task-number: QTBUG-64967 Change-Id: Ida79d6cdb682d510e9a2e91e3e3ca263acf34a99 Reviewed-by: Viktor Engelmann --- src/core/web_contents_delegate_qt.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core') diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 26da6348a..4fe877e67 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -289,6 +289,9 @@ void WebContentsDelegateQt::DidUpdateFaviconURL(const std::vectorresetCandidates(); m_faviconManager->update(faviconCandidates); } -- cgit v1.2.3 From 8f7ae2efd14f837914512e2072ccf5d942a90b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Tue, 12 Dec 2017 10:02:01 +0100 Subject: Fix QSGSoftwareLayer rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Software layers (added in qtdeclarative 5.8) also need updating. Task-number: QTBUG-62867 Change-Id: If7a941d7e360871822e1776cde3845abcb1f7efa Reviewed-by: Michael Brüning --- src/core/delegated_frame_node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 7547e24f7..8ed88ea5d 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -753,6 +753,7 @@ void DelegatedFrameNode::preprocess() if (!mailboxesToFetch.isEmpty()) fetchAndSyncMailboxes(mailboxesToFetch); +#endif // Then render any intermediate RenderPass in order. typedef QPair > Pair; @@ -762,7 +763,6 @@ void DelegatedFrameNode::preprocess() // Proceed with the actual update. pair.second->updateTexture(); } -#endif } static YUVVideoMaterial::ColorSpace toQt(cc::YUVVideoDrawQuad::ColorSpace color_space) -- cgit v1.2.3 From aead0729aaab970b95220bd864520d7635d7a33f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 14 Dec 2017 11:21:31 +0100 Subject: Fix invalid access in currentTimeForEvent The method currentTimeForEvent() tried to access the timestamp() method for a QEvent::Leave event. Leave events are regular QEvents and not QInputEvents, and thus have no such method. Change-Id: Iecc20d239b0e2a5b39b995dabdd7ca8fb44491aa Reviewed-by: Allan Sandfeld Jensen --- src/core/web_event_factory.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index 919ba730f..7245e29e6 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1023,7 +1023,8 @@ static inline double currentTimeForEvent(const QEvent *event) { Q_ASSERT(event); - if (const QInputEvent *inputEvent = static_cast(event)) { + if (event->type() != QEvent::Leave) { + const QInputEvent *inputEvent = static_cast(event); if (inputEvent->timestamp()) return static_cast(inputEvent->timestamp()) / 1000; } -- cgit v1.2.3 From d4b3d9457bbe090c4ecc0d5a7d70e7bb08b22b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Thu, 14 Dec 2017 12:43:16 +0100 Subject: Turn off caching of images rendered for the printer When printing very large documents using the QPrinter-based API, it was possible to run out of memory because the images that pdfium has generated was cached for reuse when printing multiple copies of the document. Caching the images is now removed as printing multiple copies is not the default use case and is nowadays often also handled by the printer itself. Task-number: QTBUG-58400 Change-Id: I27bd17b33a839a845ca1b387b0c3bd0466b6592f Reviewed-by: Allan Sandfeld Jensen --- src/core/pdfium_document_wrapper_qt.cpp | 20 +++++++------------- src/core/pdfium_document_wrapper_qt.h | 6 +++--- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'src/core') diff --git a/src/core/pdfium_document_wrapper_qt.cpp b/src/core/pdfium_document_wrapper_qt.cpp index 7c43c77db..ccf8e15fe 100644 --- a/src/core/pdfium_document_wrapper_qt.cpp +++ b/src/core/pdfium_document_wrapper_qt.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -124,7 +124,9 @@ private: }; -PdfiumDocumentWrapperQt::PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize& imageSize, const char *password) +PdfiumDocumentWrapperQt::PdfiumDocumentWrapperQt(const void *pdfData, size_t size, + const QSize& imageSize, + const char *password) : m_imageSize(imageSize * 2.0) { Q_ASSERT(pdfData); @@ -148,21 +150,13 @@ QImage PdfiumDocumentWrapperQt::pageAsQImage(size_t index) return QImage(); } - PdfiumPageWrapperQt *pageWrapper = nullptr; - if (!m_cachedPages.contains(index)) { - pageWrapper = new PdfiumPageWrapperQt(m_documentHandle, index, - m_imageSize.width(), m_imageSize.height()); - m_cachedPages.insert(index, pageWrapper); - } else { - pageWrapper = m_cachedPages.value(index); - } - - return pageWrapper->image(); + PdfiumPageWrapperQt pageWrapper(m_documentHandle, index, + m_imageSize.width(), m_imageSize.height()); + return pageWrapper.image(); } PdfiumDocumentWrapperQt::~PdfiumDocumentWrapperQt() { - qDeleteAll(m_cachedPages); FPDF_CloseDocument(m_documentHandle); if (--m_libraryUsers == 0) FPDF_DestroyLibrary(); diff --git a/src/core/pdfium_document_wrapper_qt.h b/src/core/pdfium_document_wrapper_qt.h index 42ac94a28..28c490ae5 100644 --- a/src/core/pdfium_document_wrapper_qt.h +++ b/src/core/pdfium_document_wrapper_qt.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebEngine module of the Qt Toolkit. @@ -53,7 +53,8 @@ class PdfiumPageWrapperQt; class QWEBENGINE_EXPORT PdfiumDocumentWrapperQt { public: - PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize &imageSize, const char *password = nullptr); + PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize &imageSize, + const char *password = nullptr); virtual ~PdfiumDocumentWrapperQt(); QImage pageAsQImage(size_t index); int pageCount() const { return m_pageCount; } @@ -63,7 +64,6 @@ private: int m_pageCount; void *m_documentHandle; QSize m_imageSize; - QHash m_cachedPages; }; } // namespace QtWebEngineCore -- cgit v1.2.3 From b9a12f07441d345797787f7142a240a386e513b2 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 4 Dec 2017 11:27:03 +0100 Subject: Hardcode default argument for mimetype in ::setContent The docs were wrong in that the default is actually text/plain with US-ASCII encoding (see e.g. data_url_unittest.cc). Anyhow, saying it might change in the future does not help anyone, and is actually a potential security risk - see e.g. the discussion about 'magic' in QTextEdit::setText(). Because of this, it's unlikely that Chromium ever changes the default. Anyhow, we can as well hardcode the default, and document it then. Change-Id: I949111598a30fa69d152d3e98d76e9d96df92d54 Reviewed-by: Leena Miettinen Reviewed-by: Viktor Engelmann Reviewed-by: Allan Sandfeld Jensen --- src/core/web_contents_adapter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 1930e7a0e..53bb55b6a 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -591,9 +591,11 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT { Q_D(WebContentsAdapter); QByteArray encodedData = data.toPercentEncoding(); - std::string urlString("data:"); - urlString.append(mimeType.toStdString()); - urlString.append(","); + std::string urlString; + if (!mimeType.isEmpty()) + urlString = std::string("data:") + mimeType.toStdString() + std::string(","); + else + urlString = std::string("data:text/plain;charset=US-ASCII,"); urlString.append(encodedData.constData(), encodedData.length()); GURL dataUrlToLoad(urlString); -- cgit v1.2.3 From 17ecc4e7e0c88d891e1b18d5810a7ac2fd0b83ba Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 12 Mar 2017 22:59:59 +0100 Subject: Doc: QWebEngineUrlRequestJob: mention when to delete the device It's used from another thread, so it shouldn't be deleted immediately, and it's not deleted by the QtWebEngine code, so tell people to do it themselves at the right time. Change-Id: I54786be320f5fe82f144e7b1c2e6137260d9ceab Reviewed-by: Leena Miettinen Reviewed-by: Allan Sandfeld Jensen --- src/core/api/qwebengineurlrequestjob.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/core') diff --git a/src/core/api/qwebengineurlrequestjob.cpp b/src/core/api/qwebengineurlrequestjob.cpp index 1db23f6ab..e95f58863 100644 --- a/src/core/api/qwebengineurlrequestjob.cpp +++ b/src/core/api/qwebengineurlrequestjob.cpp @@ -114,6 +114,13 @@ QByteArray QWebEngineUrlRequestJob::requestMethod() const /*! Replies to the request with \a device and the MIME type \a contentType. + + The device should remain available at least as long as the job exists. + When calling this method with a newly constructed device, one solution is to + make the device delete itself when closed, like this: + \code + connect(device, &QIODevice::aboutToClose, device, &QObject::deleteLater); + \endcode */ void QWebEngineUrlRequestJob::reply(const QByteArray &contentType, QIODevice *device) { -- cgit v1.2.3 From 10491dfcc06a3b663bcd52cc04a26f36d91b9d59 Mon Sep 17 00:00:00 2001 From: Valentin Fokin Date: Tue, 21 Nov 2017 10:39:01 +0100 Subject: Clean up contextMenuRequested implementation - Get rid of the unused return value - Instantiate event only when used Change-Id: I01b93d133a53185c2c87f61ea688be3742511c38 Reviewed-by: Peter Varga Reviewed-by: Allan Sandfeld Jensen --- src/core/web_contents_adapter_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index bc45a90fb..f2f1d28d1 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -389,7 +389,7 @@ public: virtual bool isBeingAdopted() = 0; virtual void close() = 0; virtual void windowCloseRejected() = 0; - virtual bool contextMenuRequested(const WebEngineContextMenuData &) = 0; + virtual void contextMenuRequested(const WebEngineContextMenuData &) = 0; virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) = 0; virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) = 0; virtual bool isFullScreenMode() const = 0; -- cgit v1.2.3 From dfcd401333f96e8146ab81b919286f8bae187790 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 30 Nov 2017 17:59:57 +0100 Subject: Update setCookie documentation WebEngine prepends "." to domain if one is set explicitly to the cookie. Task-nmuber: QTBUG-64732 Change-Id: Ic54531281cf3a26f7a516118b8ecd78a2ac27e4a Reviewed-by: Leena Miettinen Reviewed-by: Kai Koehne --- src/core/api/qwebenginecookiestore.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/api/qwebenginecookiestore.cpp b/src/core/api/qwebenginecookiestore.cpp index 4617882ab..6b2d542ea 100644 --- a/src/core/api/qwebenginecookiestore.cpp +++ b/src/core/api/qwebenginecookiestore.cpp @@ -229,7 +229,10 @@ QWebEngineCookieStore::~QWebEngineCookieStore() /*! Adds \a cookie to the cookie store. - It is possible to provide an optional \a origin URL argument to limit the scope of the cookie. + \note If \a cookie specifies a QNetworkCookie::domain() that does not start with a dot, + a dot is automatically prepended. To limit the cookie to the exact server, + omit QNetworkCookie::domain() and set \a origin instead. + The provided URL should also include the scheme. \note This operation is asynchronous. -- cgit v1.2.3 From 196ae04aa7c9b274880409fb38a050db99197900 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 13 Dec 2017 12:10:39 +0100 Subject: Initialize ScreenWin singleton to fix dpi glitches on Windows Static function ScreenWin::GetSystemMetricsInDIP returned an incorrect (already scaled) size for the scrollbars. To take system scaling into account an instance of the ScreenWin singleton has to be created once. So let's use ScreenWin directly, instead of DesktopScreenQt, which is just a mock object anyway. [ChangeLog][Windows] Fixed issues with too large scrollbars on Hi-DPI monitors. Task-number: QTBUG-60705 Change-Id: I7cbc10e98b2a5217b0a0e78afb32818c1cb199d7 Reviewed-by: Alexandru Croitor Reviewed-by: Viktor Engelmann --- src/core/content_browser_client_qt.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index d446d8ff4..14ec42fb7 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -102,6 +102,10 @@ #include "web_engine_context.h" #include "web_engine_library_info.h" +#if defined(Q_OS_WIN) +#include "ui/display/win/screen_win.h" +#endif + #if defined(Q_OS_LINUX) #include "global_descriptors_qt.h" #include "ui/base/resource/resource_bundle.h" @@ -292,8 +296,11 @@ public: { base::ThreadRestrictions::SetIOAllowed(true); // Like ChromeBrowserMainExtraPartsViews::PreCreateThreads does. +#if defined(Q_OS_WIN) + display::Screen::SetScreenInstance(new display::win::ScreenWin); +#else display::Screen::SetScreenInstance(new DesktopScreenQt); - +#endif return 0; } -- cgit v1.2.3 From 9ef3a8263098c6a32db8b824aabf85587d1f1140 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 16 Nov 2017 14:36:33 +0100 Subject: Fix access after free on shutdown After we keep around the browser-context after the profile is deleted it was keeping pointers to deleted objects and would sometimes use them on shutdown. Change-Id: Ib67d0ee0b27cb1a1b64d9b8b4c348ed418b9bbc3 Reviewed-by: Peter Varga Reviewed-by: Michal Klocek --- src/core/browser_context_adapter.cpp | 14 ++++++++++++-- src/core/browser_context_adapter.h | 2 ++ src/core/web_engine_context.cpp | 21 ++++++++++++++++----- src/core/web_engine_context.h | 5 +++-- 4 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index bec76ad81..41b5b1932 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -41,6 +41,7 @@ #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/download_manager.h" #include "browser_context_qt.h" #include "content_client_qt.h" @@ -100,10 +101,17 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName) } BrowserContextAdapter::~BrowserContextAdapter() +{ + Q_ASSERT(!m_downloadManagerDelegate); +} + +void BrowserContextAdapter::shutdown() { m_browserContext->ShutdownStoragePartitions(); - if (m_downloadManagerDelegate) - content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE, m_downloadManagerDelegate.take()); + if (m_downloadManagerDelegate) { + m_browserContext->GetDownloadManager(m_browserContext.data())->Shutdown(); + m_downloadManagerDelegate.reset(); + } BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(m_browserContext.data()); } @@ -177,6 +185,8 @@ void BrowserContextAdapter::addClient(BrowserContextAdapterClient *adapterClient void BrowserContextAdapter::removeClient(BrowserContextAdapterClient *adapterClient) { m_clients.removeOne(adapterClient); + if (m_clients.isEmpty() && this != WebEngineContext::current()->m_defaultBrowserContext.data()) + shutdown(); } void BrowserContextAdapter::cancelDownload(quint32 downloadId) diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index f6ebfd51c..2e7b66a7e 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -73,6 +73,8 @@ public: static QSharedPointer defaultContext(); static QObject* globalQObjectRoot(); + void shutdown(); + VisitedLinksManagerQt *visitedLinksManager(); DownloadManagerDelegateQt *downloadManagerDelegate(); diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 900b82eb9..6a8c8ae73 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -117,7 +117,11 @@ void destroyContext() // Before destroying MessageLoop via destroying BrowserMainRunner destructor // WebEngineContext's pointer is used. sContext->destroy(); - sContext = 0; +#if !defined(NDEBUG) + if (!sContext->HasOneRef()) + qWarning("WebEngineContext leaked on exit, likely due to leaked WebEngine View or Page"); +#endif + sContext = nullptr; s_destroyed = true; } @@ -193,19 +197,26 @@ void WebEngineContext::destroy() { if (m_devtoolsServer) m_devtoolsServer->stop(); - delete m_globalQObject; - m_globalQObject = 0; base::MessagePump::Delegate *delegate = m_runLoop->loop_; // Flush the UI message loop before quitting. while (delegate->DoWork()) { } + + if (m_defaultBrowserContext) + m_defaultBrowserContext->shutdown(); + // Delete the global object and thus custom profiles + delete m_globalQObject; + m_globalQObject = nullptr; + // Handle any events posted by browser-context shutdown. + while (delegate->DoWork()) { } + GLContextHelper::destroy(); - m_devtoolsServer.reset(0); + m_devtoolsServer.reset(); m_runLoop->AfterRun(); // Force to destroy RenderProcessHostImpl by destroying BrowserMainRunner. // RenderProcessHostImpl should be destroyed before WebEngineContext since // default BrowserContext might be used by the RenderprocessHostImpl's destructor. - m_browserRunner.reset(0); + m_browserRunner.reset(); // Drop the false reference. sContext->Release(); diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h index 92c45e260..1b4be48b1 100644 --- a/src/core/web_engine_context.h +++ b/src/core/web_engine_context.h @@ -80,7 +80,7 @@ class WebEngineContext : public base::RefCounted { public: static scoped_refptr current(); - QSharedPointer defaultBrowserContext(); + QSharedPointer defaultBrowserContext(); QObject *globalQObject(); #if BUILDFLAG(ENABLE_BASIC_PRINTING) printing::PrintJobManager* getPrintJobManager(); @@ -90,6 +90,7 @@ public: private: friend class base::RefCounted; + friend class BrowserContextAdapter; WebEngineContext(); ~WebEngineContext(); @@ -98,7 +99,7 @@ private: std::unique_ptr m_contentRunner; std::unique_ptr m_browserRunner; QObject* m_globalQObject; - QSharedPointer m_defaultBrowserContext; + QSharedPointer m_defaultBrowserContext; std::unique_ptr m_devtoolsServer; #if BUILDFLAG(ENABLE_BASIC_PRINTING) std::unique_ptr m_printJobManager; -- cgit v1.2.3 From 56fd6e23f4900bb712bf3139232eadac5b6b7223 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 2 Jan 2018 16:24:05 +0100 Subject: Fix backward compatibility - Guard QTemporaryDir::filePath (5.9) usage in the drag and drop implementation. - Guard QQuickItem::mapToGlobal (5.7) usage in the Quick context menu implementation. Change-Id: If383fa55fbbd1b2a3fe4abd57373598a1703786c Reviewed-by: Allan Sandfeld Jensen --- src/core/web_contents_adapter.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core') diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 53bb55b6a..ff4f09f0e 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -1267,7 +1267,11 @@ bool WebContentsAdapter::handleDropDataFileContents(const content::DropData &dro } const QString &fileName = toQt(dropData.file_description_filename); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) const QString &filePath = d->dndTmpDir->filePath(fileName); +#else + const QString &filePath = d->dndTmpDir->path() + QLatin1Char('/') + fileName; +#endif QFile file(filePath); if (!file.open(QIODevice::WriteOnly)) { qWarning("Cannot write temporary file %s.", qUtf8Printable(filePath)); -- cgit v1.2.3 From 8ef9f9faf09b7bae9ba548443434eb84b07c883c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 14 Dec 2017 12:42:46 +0100 Subject: Fix crash on exit race in url_request_custom_job Fixes a race-condition crash the device is deleted when the job delegate dies. Happens for instance when the device has the job delegate as parent. Change-Id: I5041bbd5747dddb18022044a310ccb5a5985f098 Reviewed-by: Michal Klocek --- src/core/url_request_custom_job.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp index b49135f79..070414b4b 100644 --- a/src/core/url_request_custom_job.cpp +++ b/src/core/url_request_custom_job.cpp @@ -65,12 +65,12 @@ URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, URLRequestCustomJob::~URLRequestCustomJob() { m_proxy->m_job = nullptr; - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, - base::Bind(&URLRequestCustomJobProxy::release, - m_proxy)); if (m_device && m_device->isOpen()) m_device->close(); m_device = nullptr; + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&URLRequestCustomJobProxy::release, + m_proxy)); } void URLRequestCustomJob::Start() -- cgit v1.2.3 From 0b406584b711e5c6e12baeb15e10045f02914af4 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 14 Dec 2017 12:45:44 +0100 Subject: Fix sanitizer build Task-number: QTBUG-64726 Change-Id: Ic88eed62e85ad1d95afcbd154c6556509e42bd47 Reviewed-by: Michal Klocek --- src/core/config/common.pri | 12 ++++++++++++ src/core/core_module.pro | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/config/common.pri b/src/core/config/common.pri index d8a4fa181..d9dd7d7fd 100644 --- a/src/core/config/common.pri +++ b/src/core/config/common.pri @@ -62,3 +62,15 @@ CONFIG(debug, debug|release) { # Compiling with -Os makes a huge difference in binary size optimize_size: gn_args += optimize_for_size=true + +# We don't want to apply sanitizer options to the build tools (GN, dict convert, etc). +!host_build { + sanitizer: gn_args += sanitizer_keep_symbols=true + sanitize_address: gn_args += is_asan=true + sanitize_thread: gn_args += is_tsan=true + sanitize_memory: gn_args += is_msan=true + # rtti is required for a specific check of ubsan, -fsanitize=vptr, which uses the runtime + # type information to check that correct derived objects are assigned to base pointers. Without + # rtti, linking would fail at build time. + sanitize_undefined: gn_args += is_ubsan=true use_rtti=true +} diff --git a/src/core/core_module.pro b/src/core/core_module.pro index 2409ccb12..d21985e60 100644 --- a/src/core/core_module.pro +++ b/src/core/core_module.pro @@ -40,8 +40,17 @@ else: LIBS_PRIVATE += $$NINJA_ARCHIVES LIBS_PRIVATE += $$NINJA_LIB_DIRS $$NINJA_LIBS # GN's LFLAGS doesn't always work across all the Linux configurations we support. # The Windows and macOS ones from GN does provide a few useful flags however -linux: QMAKE_LFLAGS += -Wl,--gc-sections -Wl,-O1 -Wl,-z,now -Wl,-z,defs -else: QMAKE_LFLAGS += $$NINJA_LFLAGS + +linux { + QMAKE_LFLAGS += -Wl,--gc-sections -Wl,-O1 -Wl,-z,now + # Embedded address sanitizer symbols are undefined and are picked up by the dynamic link loader + # at runtime. Thus we do not to pass the linker flag below, because the linker would complain + # about the undefined sanitizer symbols. + !sanitizer: QMAKE_LFLAGS += -Wl,-z,defs +} else { + QMAKE_LFLAGS += $$NINJA_LFLAGS +} + POST_TARGETDEPS += $$NINJA_TARGETDEPS -- cgit v1.2.3 From ed3a0f052910b09edc393dfb6c6940f118b267ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 15 Dec 2017 15:19:28 +0100 Subject: ProxyConfigServiceQt: Use default HostPortPair for SCHEME_DIRECT Unlike QNetworkProxy, Chromium's net::ProxyServer expects the hostname and port to be at default values for special schemes (DIRECT and INVALID). Otherwise, a DCHECK is triggered at proxy_server.cc:73. Change-Id: I1ac6c425ea03fcbfe084d25c2fd05bf174c753d6 Reviewed-by: Viktor Engelmann --- src/core/proxy_config_service_qt.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/core') diff --git a/src/core/proxy_config_service_qt.cpp b/src/core/proxy_config_service_qt.cpp index cd8f4c0fe..7fca18eb6 100644 --- a/src/core/proxy_config_service_qt.cpp +++ b/src/core/proxy_config_service_qt.cpp @@ -52,22 +52,20 @@ using content::BrowserThread; net::ProxyServer ProxyConfigServiceQt::fromQNetworkProxy(const QNetworkProxy &qtProxy) { - net::ProxyServer::Scheme proxyScheme = net::ProxyServer::SCHEME_INVALID; + net::HostPortPair hostPortPair(qtProxy.hostName().toStdString(), qtProxy.port()); switch (qtProxy.type()) { case QNetworkProxy::Socks5Proxy: - proxyScheme = net::ProxyServer::SCHEME_SOCKS5; - break; + return net::ProxyServer(net::ProxyServer::SCHEME_SOCKS5, hostPortPair); case QNetworkProxy::HttpProxy: case QNetworkProxy::HttpCachingProxy: case QNetworkProxy::FtpCachingProxy: - proxyScheme = net::ProxyServer::SCHEME_HTTP; - break; + return net::ProxyServer(net::ProxyServer::SCHEME_HTTP, hostPortPair); case QNetworkProxy::NoProxy: case QNetworkProxy::DefaultProxy: - proxyScheme = net::ProxyServer::SCHEME_DIRECT; - break; + return net::ProxyServer(net::ProxyServer::SCHEME_DIRECT, net::HostPortPair()); + default: + return net::ProxyServer(net::ProxyServer::SCHEME_INVALID, net::HostPortPair()); } - return net::ProxyServer(proxyScheme, net::HostPortPair(qtProxy.hostName().toStdString(), qtProxy.port())); } ProxyConfigServiceQt::ProxyConfigServiceQt(std::unique_ptr baseService) -- cgit v1.2.3 From 9ed734bfdd7b70f4f7f8e78529ead40031607f99 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 15 Jan 2018 10:34:22 +0100 Subject: Reduce jumbo limit Reduces amount of memory used when compiling and is more friendly when compiling using icecream. Change-Id: I3ba3afcaa75ee79e02f2a8b2fa6d8f19e5f7b929 Reviewed-by: Alexandru Croitor --- src/core/config/common.pri | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/config/common.pri b/src/core/config/common.pri index d9dd7d7fd..886ebe83d 100644 --- a/src/core/config/common.pri +++ b/src/core/config/common.pri @@ -13,7 +13,8 @@ gn_args += \ treat_warnings_as_errors=false \ enable_swiftshader=false \ use_custom_libcxx=false \ - use_jumbo_build=true + use_jumbo_build=true \ + jumbo_file_merge_limit=50 qtConfig(webengine-printing-and-pdf) { gn_args += enable_basic_printing=true enable_print_preview=true -- cgit v1.2.3 From a3fe8bc7859a84bbdd91f3ce73108878798b3986 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Jan 2018 17:52:58 +0100 Subject: Protect QML profiles as well as core Moves QWebEngineBrowserContext to core and makes use of it from both widget and qml. Change-Id: I34748f302b0515b11b5831690d28478dfa6a852b Reviewed-by: Michal Klocek Reviewed-by: Alexandru Croitor --- src/core/api/core_api.pro | 2 + src/core/api/qwebenginebrowsercontext.cpp | 73 +++++++++++++++++++++++++++ src/core/api/qwebenginebrowsercontext_p.h | 83 +++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 src/core/api/qwebenginebrowsercontext.cpp create mode 100644 src/core/api/qwebenginebrowsercontext_p.h (limited to 'src/core') diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro index 270595378..93eebbc45 100644 --- a/src/core/api/core_api.pro +++ b/src/core/api/core_api.pro @@ -33,6 +33,7 @@ HEADERS = \ qwebenginecallback_p.h \ qtwebenginecoreglobal.h \ qtwebenginecoreglobal_p.h \ + qwebenginebrowsercontext_p.h \ qwebenginecookiestore.h \ qwebenginecookiestore_p.h \ qwebenginehttprequest.h \ @@ -44,6 +45,7 @@ HEADERS = \ SOURCES = \ qtwebenginecoreglobal.cpp \ + qwebenginebrowsercontext.cpp \ qwebenginecookiestore.cpp \ qwebenginehttprequest.cpp \ qwebengineurlrequestinfo.cpp \ diff --git a/src/core/api/qwebenginebrowsercontext.cpp b/src/core/api/qwebenginebrowsercontext.cpp new file mode 100644 index 000000000..c3ab16460 --- /dev/null +++ b/src/core/api/qwebenginebrowsercontext.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebenginebrowsercontext_p.h" + +#include "browser_context_adapter.h" +#include + +QT_BEGIN_NAMESPACE + +QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer browserContext, + QtWebEngineCore::BrowserContextAdapterClient *profile) + : QObject(QtWebEngineCore::BrowserContextAdapter::globalQObjectRoot()) + , browserContextRef(browserContext) + , m_profile(profile) +{ + browserContextRef->addClient(m_profile); +} + +QWebEngineBrowserContext::~QWebEngineBrowserContext() +{ + if (m_profile) + shutdown(); +} + +void QWebEngineBrowserContext::shutdown() +{ + Q_ASSERT(m_profile); + // In the case the user sets this profile as the parent of the interceptor + // it can be deleted before the browser-context still referencing it is. + browserContextRef->setRequestInterceptor(nullptr); + browserContextRef->removeClient(m_profile); + m_profile = 0; + deleteLater(); +} + +QT_END_NAMESPACE diff --git a/src/core/api/qwebenginebrowsercontext_p.h b/src/core/api/qwebenginebrowsercontext_p.h new file mode 100644 index 000000000..713ab730e --- /dev/null +++ b/src/core/api/qwebenginebrowsercontext_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINEBROWSERCONTEXT_P_H +#define QWEBENGINEBROWSERCONTEXT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// +#include "qtwebenginecoreglobal_p.h" + +#include +#include + +namespace QtWebEngineCore { +class BrowserContextAdapter; +class BrowserContextAdapterClient; +} + +QT_BEGIN_NAMESPACE + +// This is a wrapper class for BrowserContextAdapter. BrowserContextAdapter must be destructed before WebEngineContext +// is destructed. Therefore access it via the QWebEngineBrowserContext which parent is the WebEngineContext::globalQObject. +// This guarantees the destruction together with the WebEngineContext. +class QWEBENGINE_PRIVATE_EXPORT QWebEngineBrowserContext : public QObject { +public: + QWebEngineBrowserContext(QSharedPointer browserContext, QtWebEngineCore::BrowserContextAdapterClient *profile); + ~QWebEngineBrowserContext(); + + void shutdown(); + + QSharedPointer browserContextRef; + +private: + QtWebEngineCore::BrowserContextAdapterClient *m_profile; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEBROWSERCONTEXT_P_H -- cgit v1.2.3