diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-17 12:20:46 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2018-01-17 15:56:28 +0000 |
commit | 71d6dc0c326523103dff867d7184e7bc7e49c71d (patch) | |
tree | f28f83359516f688313632b33b218185733746fa /src/core | |
parent | 51ac6916f600eac67486ff272e48360c751237c9 (diff) | |
parent | 2c6e6b86ef0a6c63297f9d5daa41c294aaf31a9b (diff) |
Merge "Merge remote-tracking branch 'origin/5.10' into dev" into refs/staging/dev
Diffstat (limited to 'src/core')
22 files changed, 306 insertions, 59 deletions
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 <qtwebenginecoreglobal.h> + +QT_BEGIN_NAMESPACE + +QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> 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 <QObject> +#include <QSharedPointer> + +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<QtWebEngineCore::BrowserContextAdapter> browserContext, QtWebEngineCore::BrowserContextAdapterClient *profile); + ~QWebEngineBrowserContext(); + + void shutdown(); + + QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef; + +private: + QtWebEngineCore::BrowserContextAdapterClient *m_profile; +}; + +QT_END_NAMESPACE + +#endif // QWEBENGINEBROWSERCONTEXT_P_H diff --git a/src/core/api/qwebenginecookiestore.cpp b/src/core/api/qwebenginecookiestore.cpp index 8adf46bea..031eb8d3d 100644 --- a/src/core/api/qwebenginecookiestore.cpp +++ b/src/core/api/qwebenginecookiestore.cpp @@ -230,7 +230,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. diff --git a/src/core/api/qwebengineurlrequestjob.cpp b/src/core/api/qwebengineurlrequestjob.cpp index a071adbd5..47aab48a0 100644 --- a/src/core/api/qwebengineurlrequestjob.cpp +++ b/src/core/api/qwebengineurlrequestjob.cpp @@ -115,12 +115,20 @@ QByteArray QWebEngineUrlRequestJob::requestMethod() const /*! Replies to the request with \a device and the MIME type \a contentType. + The user has to be aware that \a device will be used on another thread until the job is deleted. In case simultaneous access from the main thread is desired, the user is reponsible for making access to \a device thread-safe for example by using QMutex. Note that the \a device object is not owned by the web engine. Therefore, the signal QObject::destroyed() of QWebEngineUrlRequestJob must be monitored. + + 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) { diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index 0f392f9f8..3f8397752 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -42,6 +42,7 @@ #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/browsing_data_remover.h" +#include "content/public/browser/download_manager.h" #include "browser_context_qt.h" #include "content_client_qt.h" @@ -102,9 +103,16 @@ 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()); } @@ -178,6 +186,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 5960014b9..b647bc30c 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -73,6 +73,8 @@ public: static QSharedPointer<BrowserContextAdapter> defaultContext(); static QObject* globalQObjectRoot(); + void shutdown(); + VisitedLinksManagerQt *visitedLinksManager(); DownloadManagerDelegateQt *downloadManagerDelegate(); diff --git a/src/core/config/common.pri b/src/core/config/common.pri index d8a4fa181..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 @@ -62,3 +63,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/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 328dcd38d..d0019e4f3 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -105,6 +105,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" @@ -295,8 +299,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; } 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 diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 6f4a4e8db..de39300c9 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -739,6 +739,7 @@ void DelegatedFrameNode::preprocess() if (!mailboxesToFetch.isEmpty()) fetchAndSyncMailboxes(mailboxesToFetch); +#endif // Then render any intermediate RenderPass in order. typedef QPair<int, QSharedPointer<QSGLayer> > Pair; @@ -748,7 +749,6 @@ void DelegatedFrameNode::preprocess() // Proceed with the actual update. pair.second->updateTexture(); } -#endif } static YUVVideoMaterial::ColorSpace toQt(cc::YUVVideoDrawQuad::ColorSpace color_space) diff --git a/src/core/pdfium_document_wrapper_qt.cpp b/src/core/pdfium_document_wrapper_qt.cpp index df829a426..ca1e8cd07 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. @@ -129,7 +129,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); @@ -153,21 +155,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<int, PdfiumPageWrapperQt*> m_cachedPages; }; } // namespace QtWebEngineCore 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<ProxyConfigService> baseService) diff --git a/src/core/renderer/user_resource_controller.cpp b/src/core/renderer/user_resource_controller.cpp index b4375dfdb..f85879053 100644 --- a/src/core/renderer/user_resource_controller.cpp +++ b/src/core/renderer/user_resource_controller.cpp @@ -148,9 +148,14 @@ void UserResourceController::RenderFrameObserverHelper::runScripts(UserScriptDat void UserResourceController::runScripts(UserScriptData::InjectionPoint p, blink::WebLocalFrame *frame) { content::RenderFrame *renderFrame = content::RenderFrame::FromWebFrame(frame); - content::RenderView *renderView = renderFrame->GetRenderView(); + if (!renderFrame) + return; const bool isMainFrame = renderFrame->IsMainFrame(); + content::RenderView *renderView = renderFrame->GetRenderView(); + if (!renderView) + return; + QList<uint64_t> scriptsToRun = m_viewUserScriptMap.value(0).toList(); scriptsToRun.append(m_viewUserScriptMap.value(renderView).toList()); @@ -233,7 +238,8 @@ void UserResourceController::RenderFrameObserverHelper::OnDestruct() void UserResourceController::RenderViewObserverHelper::OnDestruct() { // Remove all scripts associated with the render view. - UserResourceController::instance()->renderViewDestroyed(render_view()); + if (content::RenderView *view = render_view()) + UserResourceController::instance()->renderViewDestroyed(view); delete this; } @@ -251,20 +257,23 @@ bool UserResourceController::RenderFrameObserverHelper::OnMessageReceived(const void UserResourceController::RenderFrameObserverHelper::onUserScriptAdded(const UserScriptData &script) { - content::RenderView *view = render_frame()->GetRenderView(); - UserResourceController::instance()->addScriptForView(script, view); + if (content::RenderFrame *frame = render_frame()) + if (content::RenderView *view = frame->GetRenderView()) + UserResourceController::instance()->addScriptForView(script, view); } void UserResourceController::RenderFrameObserverHelper::onUserScriptRemoved(const UserScriptData &script) { - content::RenderView *view = render_frame()->GetRenderView(); - UserResourceController::instance()->removeScriptForView(script, view); + if (content::RenderFrame *frame = render_frame()) + if (content::RenderView *view = frame->GetRenderView()) + UserResourceController::instance()->removeScriptForView(script, view); } void UserResourceController::RenderFrameObserverHelper::onScriptsCleared() { - content::RenderView *view = render_frame()->GetRenderView(); - UserResourceController::instance()->clearScriptsForView(view); + if (content::RenderFrame *frame = render_frame()) + if (content::RenderView *view = frame->GetRenderView()) + UserResourceController::instance()->clearScriptsForView(view); } UserResourceController *UserResourceController::instance() 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() diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 0b6a44d8d..668e791c1 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -632,9 +632,11 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT CHECK_VALID_RENDER_WIDGET_HOST_VIEW(d->webContents->GetRenderViewHost()); 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); @@ -1359,7 +1361,11 @@ bool WebContentsAdapter::handleDropDataFileContents(const content::DropData &dro const auto maybeFilename = dropData.GetSafeFilenameForImageFileContents(); const QString fileName = maybeFilename ? toQt(maybeFilename->AsUTF16Unsafe()) : QString(); +#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)); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 6416ab6af..d6de9dfe6 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -390,7 +390,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; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 2086bea4b..7b765d99b 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -80,6 +80,16 @@ namespace QtWebEngineCore { +static gfx::Rect rootViewToScreenRect(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view) +{ + RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt *>(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) @@ -336,6 +346,9 @@ void WebContentsDelegateQt::DidUpdateFaviconURL(const std::vector<content::Favic faviconCandidates.append(toFaviconInfo(candidate)); } + // Favicon URL can be changed from JavaScript too. Thus we need to reset + // the current candidate icon list to not handle previous icon as a candidate. + m_faviconManager->resetCandidates(); m_faviconManager->update(faviconCandidates); } @@ -552,8 +565,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) @@ -564,8 +579,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) diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index e7bbbb9c7..84f6ce738 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -123,7 +123,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; } @@ -199,20 +203,27 @@ void WebEngineContext::destroy() { if (m_devtoolsServer) m_devtoolsServer->stop(); - delete m_globalQObject; - m_globalQObject = 0; base::MessagePump::Delegate *delegate = static_cast<base::MessageLoop *>(m_runLoop->delegate_); // 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<WebEngineContext> { public: static scoped_refptr<WebEngineContext> current(); - QSharedPointer<QtWebEngineCore::BrowserContextAdapter> defaultBrowserContext(); + QSharedPointer<BrowserContextAdapter> defaultBrowserContext(); QObject *globalQObject(); #if BUILDFLAG(ENABLE_BASIC_PRINTING) printing::PrintJobManager* getPrintJobManager(); @@ -90,6 +90,7 @@ public: private: friend class base::RefCounted<WebEngineContext>; + friend class BrowserContextAdapter; WebEngineContext(); ~WebEngineContext(); @@ -98,7 +99,7 @@ private: std::unique_ptr<content::ContentMainRunner> m_contentRunner; std::unique_ptr<content::BrowserMainRunner> m_browserRunner; QObject* m_globalQObject; - QSharedPointer<QtWebEngineCore::BrowserContextAdapter> m_defaultBrowserContext; + QSharedPointer<BrowserContextAdapter> m_defaultBrowserContext; std::unique_ptr<DevToolsServerQt> m_devtoolsServer; #if BUILDFLAG(ENABLE_BASIC_PRINTING) std::unique_ptr<printing::PrintJobManager> m_printJobManager; diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index 4241a11c2..4fb89d4e6 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1024,7 +1024,8 @@ static inline double currentTimeForEvent(const QEvent *event) { Q_ASSERT(event); - if (const QInputEvent *inputEvent = static_cast<const QInputEvent *>(event)) { + if (event->type() != QEvent::Leave) { + const QInputEvent *inputEvent = static_cast<const QInputEvent *>(event); if (inputEvent->timestamp()) return static_cast<double>(inputEvent->timestamp()) / 1000; } |