diff options
Diffstat (limited to 'src')
23 files changed, 359 insertions, 73 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp new file mode 100644 index 000000000..b06515c2f --- /dev/null +++ b/src/core/browser_context_adapter.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "browser_context_adapter.h" + +#include "browser_context_qt.h" +#include "web_engine_context.h" +#include "web_engine_visited_links_manager.h" + +#include <QCoreApplication> +#include <QDir> +#include <QString> +#include <QStringBuilder> +#include <QStandardPaths> + + +BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord) + : m_offTheRecord(offTheRecord) + , m_browserContext(new BrowserContextQt(this)) + , m_visitedLinksManager(new WebEngineVisitedLinksManager(this)) +{ +} + +BrowserContextAdapter::~BrowserContextAdapter() +{ +} + +BrowserContextQt *BrowserContextAdapter::browserContext() +{ + return m_browserContext.data(); +} + +WebEngineVisitedLinksManager *BrowserContextAdapter::visitedLinksManager() +{ + return m_visitedLinksManager.data(); +} + +BrowserContextAdapter* BrowserContextAdapter::defaultContext() +{ + return WebEngineContext::current()->defaultBrowserContext(); +} + +BrowserContextAdapter* BrowserContextAdapter::offTheRecordContext() +{ + return WebEngineContext::current()->offTheRecordBrowserContext(); +} + +QString BrowserContextAdapter::dataPath() const +{ + QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + if (dataLocation.isEmpty()) + dataLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); + + dataLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); + dataLocation.append(QDir::separator() % QLatin1String("Default")); + return dataLocation; +} + +QString BrowserContextAdapter::cachePath() const +{ + QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + if (cacheLocation.isEmpty()) + cacheLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); + + cacheLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); + cacheLocation.append(QDir::separator() % QLatin1String("Default")); + return cacheLocation; +} diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h new file mode 100644 index 000000000..362ab79ee --- /dev/null +++ b/src/core/browser_context_adapter.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSER_CONTEXT_ADAPTER_H +#define BROWSER_CONTEXT_ADAPTER_H + +#include "qtwebenginecoreglobal.h" + +#include <QScopedPointer> +#include <QSharedData> + +class BrowserContextQt; +class WebEngineVisitedLinksManager; + +// Make a QSharedData if we need to open arbitrary BrowserContextAdapter beyond the defaults. +class QWEBENGINE_EXPORT BrowserContextAdapter // : public QSharedData +{ +public: + virtual ~BrowserContextAdapter(); + + static BrowserContextAdapter* defaultContext(); + static BrowserContextAdapter* offTheRecordContext(); + + WebEngineVisitedLinksManager *visitedLinksManager(); + + BrowserContextQt *browserContext(); + bool isOffTheRecord() const { return m_offTheRecord; } + QString dataPath() const; + QString cachePath() const; + +protected: + explicit BrowserContextAdapter(bool offTheRecord = false); + +private: + bool m_offTheRecord; + QScopedPointer<BrowserContextQt> m_browserContext; + QScopedPointer<WebEngineVisitedLinksManager> m_visitedLinksManager; + friend class WebEngineContext; + + Q_DISABLE_COPY(BrowserContextAdapter) +}; + +#endif // BROWSER_CONTEXT_ADAPTER_H diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp index 44b6ca4ef..8dc4a3da2 100644 --- a/src/core/browser_context_qt.cpp +++ b/src/core/browser_context_qt.cpp @@ -36,6 +36,7 @@ #include "browser_context_qt.h" +#include "browser_context_adapter.h" #include "type_conversion.h" #include "qtwebenginecoreglobal.h" #include "resource_context_qt.h" @@ -47,14 +48,8 @@ #include "content/public/browser/storage_partition.h" #include "net/proxy/proxy_config_service.h" -#include <QByteArray> -#include <QCoreApplication> -#include <QDir> -#include <QStandardPaths> -#include <QString> -#include <QStringBuilder> - -BrowserContextQt::BrowserContextQt() +BrowserContextQt::BrowserContextQt(BrowserContextAdapter *adapter) + : m_adapter(adapter) { resourceContext.reset(new ResourceContextQt(this)); } @@ -67,29 +62,17 @@ BrowserContextQt::~BrowserContextQt() base::FilePath BrowserContextQt::GetPath() const { - QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - if (dataLocation.isEmpty()) - dataLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); - - dataLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); - dataLocation.append(QDir::separator() % QLatin1String("Default")); - return base::FilePath(toFilePathString(dataLocation)); + return base::FilePath(toFilePathString(m_adapter->dataPath())); } base::FilePath BrowserContextQt::GetCachePath() const { - QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - if (cacheLocation.isEmpty()) - cacheLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); - - cacheLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); - cacheLocation.append(QDir::separator() % QLatin1String("Default")); - return base::FilePath(toFilePathString(cacheLocation)); + return base::FilePath(toFilePathString(m_adapter->cachePath())); } bool BrowserContextQt::IsOffTheRecord() const { - return false; + return m_adapter->isOffTheRecord(); } net::URLRequestContextGetter *BrowserContextQt::GetRequestContext() diff --git a/src/core/browser_context_qt.h b/src/core/browser_context_qt.h index 125c0fc46..634db6f3f 100644 --- a/src/core/browser_context_qt.h +++ b/src/core/browser_context_qt.h @@ -43,10 +43,12 @@ #include "net/url_request/url_request_context.h" #include "download_manager_delegate_qt.h" +class BrowserContextAdapter; + class BrowserContextQt : public content::BrowserContext { public: - explicit BrowserContextQt(); + explicit BrowserContextQt(BrowserContextAdapter *); virtual ~BrowserContextQt(); @@ -70,6 +72,7 @@ private: scoped_ptr<content::ResourceContext> resourceContext; scoped_refptr<net::URLRequestContextGetter> url_request_getter_; scoped_ptr<DownloadManagerDelegateQt> downloadManagerDelegate; + BrowserContextAdapter *m_adapter; DISALLOW_COPY_AND_ASSIGN(BrowserContextQt); }; diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 3ead5314f..2aca88d6a 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -201,12 +201,10 @@ public: void PreMainMessageLoopRun() Q_DECL_OVERRIDE { - m_browserContext.reset(new BrowserContextQt()); } void PostMainMessageLoopRun() { - m_browserContext.reset(); } int PreCreateThreads() Q_DECL_OVERRIDE @@ -217,13 +215,7 @@ public: return 0; } - BrowserContextQt* browser_context() const { - return m_browserContext.get(); - } - private: - scoped_ptr<BrowserContextQt> m_browserContext; - DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsQt); }; @@ -347,22 +339,15 @@ void ContentBrowserClientQt::OverrideWebkitPrefs(content::RenderViewHost *rvh, c static_cast<WebContentsDelegateQt*>(webContents->GetDelegate())->overrideWebPreferences(webContents, web_prefs); } -BrowserContextQt* ContentBrowserClientQt::browser_context() { - Q_ASSERT(m_browserMainParts); - return static_cast<BrowserMainPartsQt*>(m_browserMainParts)->browser_context(); -} - -net::URLRequestContextGetter* ContentBrowserClientQt::CreateRequestContext(content::BrowserContext* content_browser_context, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) +net::URLRequestContextGetter* ContentBrowserClientQt::CreateRequestContext(content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) { - if (content_browser_context != browser_context()) - fprintf(stderr, "Warning: off the record browser context not implemented !\n"); - return static_cast<BrowserContextQt*>(browser_context())->CreateRequestContext(protocol_handlers); + return static_cast<BrowserContextQt*>(browser_context)->CreateRequestContext(protocol_handlers); } -void ContentBrowserClientQt::enableInspector(bool enable) +void ContentBrowserClientQt::enableInspector(bool enable, content::BrowserContext* browser_context) { if (enable && !m_devtools) { - m_devtools.reset(new DevToolsHttpHandlerDelegateQt(browser_context())); + m_devtools.reset(new DevToolsHttpHandlerDelegateQt(browser_context)); } else if (!enable && m_devtools) { m_devtools.reset(); } diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h index dd5d9f3a1..ed328d1bf 100644 --- a/src/core/content_browser_client_qt.h +++ b/src/core/content_browser_client_qt.h @@ -98,11 +98,9 @@ public: base::Callback<void(bool)> result_callback, base::Closure *cancel_callback) Q_DECL_OVERRIDE; - BrowserContextQt* browser_context(); - virtual net::URLRequestContextGetter *CreateRequestContext(content::BrowserContext *content_browser_context, content::ProtocolHandlerMap *protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptorss) Q_DECL_OVERRIDE; - void enableInspector(bool); + void enableInspector(bool enable, content::BrowserContext *browser_context); private: BrowserMainPartsQt* m_browserMainParts; diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index c50d56df4..c6144b344 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -35,6 +35,7 @@ INCLUDEPATH += $$[QT_INSTALL_HEADERS] $$PWD SOURCES = \ browser_accessibility_manager_qt.cpp \ browser_accessibility_qt.cpp \ + browser_context_adapter.cpp \ browser_context_qt.cpp \ certificate_error_controller.cpp \ chromium_gpu_helper.cpp \ @@ -82,6 +83,7 @@ SOURCES = \ HEADERS = \ browser_accessibility_manager_qt.h \ browser_accessibility_qt.h \ + browser_context_adapter.h \ browser_context_qt.h \ certificate_error_controller_p.h \ certificate_error_controller.h \ diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 1a393a0c7..b086cd4f3 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -55,6 +55,7 @@ #include "base/bind.h" #include "cc/output/delegated_frame_data.h" #include "cc/quads/checkerboard_draw_quad.h" +#include "cc/quads/debug_border_draw_quad.h" #include "cc/quads/draw_quad.h" #include "cc/quads/render_pass_draw_quad.h" #include "cc/quads/solid_color_draw_quad.h" @@ -601,6 +602,30 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour rectangleNode->setColor(toQt(scquad->color)); currentLayerChain->appendChildNode(rectangleNode); break; + } case cc::DrawQuad::DEBUG_BORDER: { + const cc::DebugBorderDrawQuad *dbquad = cc::DebugBorderDrawQuad::MaterialCast(quad); + QSGGeometryNode *geometryNode = new QSGGeometryNode; + + QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 4); + geometry->setDrawingMode(GL_LINE_LOOP); + geometry->setLineWidth(dbquad->width); + // QSGGeometry::updateRectGeometry would actually set the corners in the following order: + // top-left, bottom-left, top-right, bottom-right, leading to a nice criss cross, instead + // of having a closed loop. + const gfx::Rect &r(dbquad->rect); + geometry->vertexDataAsPoint2D()[0].set(r.x(), r.y()); + geometry->vertexDataAsPoint2D()[1].set(r.x() + r.width(), r.y()); + geometry->vertexDataAsPoint2D()[2].set(r.x() + r.width(), r.y() + r.height()); + geometry->vertexDataAsPoint2D()[3].set(r.x(), r.y() + r.height()); + geometryNode->setGeometry(geometry); + + QSGFlatColorMaterial *material = new QSGFlatColorMaterial; + material->setColor(toQt(dbquad->color)); + geometryNode->setMaterial(material); + + geometryNode->setFlags(QSGNode::OwnsGeometry | QSGNode::OwnsMaterial); + currentLayerChain->appendChildNode(geometryNode); + break; } case cc::DrawQuad::TILED_CONTENT: { const cc::TileDrawQuad *tquad = cc::TileDrawQuad::MaterialCast(quad); QSharedPointer<MailboxTexture> &texture = findMailboxTexture(tquad->resource_id, m_data->mailboxTextures, mailboxTextureCandidates); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 3f223f733..dd9f800db 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -41,6 +41,7 @@ #include "web_contents_adapter.h" #include "web_contents_adapter_p.h" +#include "browser_context_adapter.h" #include "browser_context_qt.h" #include "content_browser_client_qt.h" #include "javascript_dialog_manager_qt.h" @@ -175,9 +176,8 @@ static QStringList listRecursively(const QDir& dir) { return ret; } -static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient) +static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient, content::BrowserContext *browserContext) { - content::BrowserContext* browserContext = ContentBrowserClientQt::Get()->browser_context(); content::WebContents::CreateParams create_params(browserContext, NULL); create_params.routing_id = MSG_ROUTING_NONE; create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight); @@ -222,7 +222,7 @@ static void serializeNavigationHistory(const content::NavigationController &cont } } -void deserializeNavigationHistory(QDataStream &input, int *currentIndex, std::vector<content::NavigationEntry*> *entries) +void deserializeNavigationHistory(QDataStream &input, int *currentIndex, std::vector<content::NavigationEntry*> *entries, content::BrowserContext *browserContext) { int version; input >> version; @@ -278,7 +278,7 @@ void deserializeNavigationHistory(QDataStream &input, int *currentIndex, std::ve false, // The extra headers are not sync'ed across sessions. std::string(), - ContentBrowserClientQt::Get()->browser_context()); + browserContext); entry->SetTitle(toString16(title)); entry->SetPageState(content::PageState::CreateFromEncodedData(std::string(pageState.data(), pageState.size()))); @@ -308,13 +308,13 @@ QExplicitlySharedDataPointer<WebContentsAdapter> WebContentsAdapter::createFromS { int currentIndex; std::vector<content::NavigationEntry*> entries; - deserializeNavigationHistory(input, ¤tIndex, &entries); + deserializeNavigationHistory(input, ¤tIndex, &entries, adapterClient->browserContextAdapter()->browserContext()); if (currentIndex == -1) return QExplicitlySharedDataPointer<WebContentsAdapter>(); // Unlike WebCore, Chromium only supports Restoring to a new WebContents instance. - content::WebContents* newWebContents = createBlankWebContents(adapterClient); + content::WebContents* newWebContents = createBlankWebContents(adapterClient, adapterClient->browserContextAdapter()->browserContext()); content::NavigationController &controller = newWebContents->GetController(); controller.Restore(currentIndex, content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); @@ -350,7 +350,7 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient) // Create our own if a WebContents wasn't provided at construction. if (!d->webContents) - d->webContents.reset(createBlankWebContents(adapterClient)); + d->webContents.reset(createBlankWebContents(adapterClient, adapterClient->browserContextAdapter()->browserContext())); // This might replace any adapter that has been initialized with this WebEngineSettings. adapterClient->webEngineSettings()->setWebContentsAdapter(this); @@ -625,7 +625,13 @@ qreal WebContentsAdapter::currentZoomFactor() const void WebContentsAdapter::enableInspector(bool enable) { - ContentBrowserClientQt::Get()->enableInspector(enable); + ContentBrowserClientQt::Get()->enableInspector(enable, browserContext()); +} + +BrowserContextQt* WebContentsAdapter::browserContext() +{ + Q_D(WebContentsAdapter); + return static_cast<BrowserContextQt*>(d->webContents->GetBrowserContext()); } QAccessibleInterface *WebContentsAdapter::browserAccessible() diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index 6bec50316..6e17fc2f5 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -48,6 +48,7 @@ namespace content { class WebContents; } +class BrowserContextQt; class WebContentsAdapterPrivate; struct WebPreferences; @@ -111,11 +112,13 @@ public: void dpiScaleChanged(); QAccessibleInterface *browserAccessible(); + BrowserContextQt* browserContext(); private: Q_DISABLE_COPY(WebContentsAdapter); Q_DECLARE_PRIVATE(WebContentsAdapter); QScopedPointer<WebContentsAdapterPrivate> d_ptr; + friend class WebContentsDelegateQt; }; #endif // WEB_CONTENTS_ADAPTER_H diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 8fd401fe4..8fd988c7e 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -48,6 +48,7 @@ QT_FORWARD_DECLARE_CLASS(QVariant) +class BrowserContextAdapter; class CertificateErrorController; class JavaScriptDialogController; class RenderWidgetHostViewQt; @@ -176,6 +177,8 @@ public: virtual void allowCertificateError(const QExplicitlySharedDataPointer<CertificateErrorController> &errorController) = 0; + virtual BrowserContextAdapter* browserContextAdapter() = 0; + }; #endif // WEB_CONTENTS_ADAPTER_CLIENT_H diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index c2cccfedb..f9dba67fe 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -40,6 +40,7 @@ #include "web_contents_delegate_qt.h" +#include "browser_context_adapter.h" #include "media_capture_devices_dispatcher.h" #include "type_conversion.h" #include "web_contents_adapter_client.h" @@ -270,7 +271,7 @@ void WebContentsDelegateQt::DidNavigateAnyFrame(const content::LoadCommittedDeta { if (!params.should_update_history) return; - WebEngineContext::current()->visitedLinksManager()->addUrl(params.url); + m_viewClient->browserContextAdapter()->visitedLinksManager()->addUrl(params.url); } diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 20bf3e051..d4659f0be 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -65,6 +65,7 @@ #include "content/public/app/startup_helper_win.h" #endif // OS_WIN +#include "browser_context_adapter.h" #include "content_browser_client_qt.h" #include "content_client_qt.h" #include "content_main_delegate_qt.h" @@ -73,7 +74,6 @@ #include "type_conversion.h" #include "surface_factory_qt.h" #include "web_engine_library_info.h" -#include "web_engine_visited_links_manager.h" #include <QGuiApplication> #include <QOpenGLContext> #include <QStringList> @@ -107,9 +107,18 @@ scoped_refptr<WebEngineContext> WebEngineContext::current() return sContext; } -WebEngineVisitedLinksManager *WebEngineContext::visitedLinksManager() +BrowserContextAdapter* WebEngineContext::defaultBrowserContext() { - return m_visitedLinksManager.get(); + if (!m_defaultBrowserContext) + m_defaultBrowserContext.reset(new BrowserContextAdapter()); + return m_defaultBrowserContext.get(); +} + +BrowserContextAdapter* WebEngineContext::offTheRecordBrowserContext() +{ + if (!m_offTheRecordBrowserContext) + m_offTheRecordBrowserContext.reset(new BrowserContextAdapter(true)); + return m_offTheRecordBrowserContext.get(); } #ifndef CHROMIUM_VERSION @@ -204,7 +213,4 @@ WebEngineContext::WebEngineContext() // thread to avoid a thread check assertion in its constructor when it // first gets referenced on the IO thread. MediaCaptureDevicesDispatcher::GetInstance(); - - // Ensure we have a VisitedLinksMaster instance up and running - m_visitedLinksManager.reset(new WebEngineVisitedLinksManager); } diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h index d1cd9a7a5..0b3ad8678 100644 --- a/src/core/web_engine_context.h +++ b/src/core/web_engine_context.h @@ -49,15 +49,16 @@ class BrowserMainRunner; class ContentMainRunner; } +class BrowserContextAdapter; class ContentMainDelegateQt; class SurfaceFactoryQt; -class WebEngineVisitedLinksManager; class WebEngineContext : public base::RefCounted<WebEngineContext> { public: static scoped_refptr<WebEngineContext> current(); - WebEngineVisitedLinksManager *visitedLinksManager(); + BrowserContextAdapter *defaultBrowserContext(); + BrowserContextAdapter *offTheRecordBrowserContext(); private: friend class base::RefCounted<WebEngineContext>; @@ -71,7 +72,8 @@ private: #if defined(OS_ANDROID) scoped_ptr<SurfaceFactoryQt> m_surfaceFactory; #endif - scoped_ptr<WebEngineVisitedLinksManager> m_visitedLinksManager; + scoped_ptr<BrowserContextAdapter> m_defaultBrowserContext; + scoped_ptr<BrowserContextAdapter> m_offTheRecordBrowserContext; }; #endif // WEB_ENGINE_CONTEXT_H diff --git a/src/core/web_engine_visited_links_manager.cpp b/src/core/web_engine_visited_links_manager.cpp index 36467ca21..a2f6dbf9f 100644 --- a/src/core/web_engine_visited_links_manager.cpp +++ b/src/core/web_engine_visited_links_manager.cpp @@ -36,8 +36,9 @@ #include "web_engine_visited_links_manager.h" -#include "content_browser_client_qt.h" +#include "browser_context_adapter.h" #include "browser_context_qt.h" +#include "content_browser_client_qt.h" #include "type_conversion.h" #include "base/memory/scoped_ptr.h" @@ -80,11 +81,11 @@ void WebEngineVisitedLinksManager::deleteVisitedLinkDataForUrls(const QList<QUrl m_visitedLinkMaster->DeleteURLs(&iterator); } -WebEngineVisitedLinksManager::WebEngineVisitedLinksManager() +WebEngineVisitedLinksManager::WebEngineVisitedLinksManager(BrowserContextAdapter *adapter) : m_delegate(new VisitedLinkDelegateQt) { - Q_ASSERT(ContentBrowserClientQt::Get() && ContentBrowserClientQt::Get()->browser_context()); - BrowserContextQt *browserContext = ContentBrowserClientQt::Get()->browser_context(); + Q_ASSERT(adapter && adapter->browserContext()); + BrowserContextQt *browserContext = adapter->browserContext(); m_visitedLinkMaster.reset(new visitedlink::VisitedLinkMaster(browserContext, m_delegate.data(), /* persist to disk = */true)); m_visitedLinkMaster->Init(); } diff --git a/src/core/web_engine_visited_links_manager.h b/src/core/web_engine_visited_links_manager.h index aa44dd9cf..5b0286c51 100644 --- a/src/core/web_engine_visited_links_manager.h +++ b/src/core/web_engine_visited_links_manager.h @@ -49,6 +49,7 @@ namespace visitedlink { class VisitedLinkMaster; } +class BrowserContextAdapter; class VisitedLinkDelegateQt; class GURL; @@ -57,7 +58,7 @@ class QWEBENGINE_EXPORT WebEngineVisitedLinksManager { public: virtual~WebEngineVisitedLinksManager(); - WebEngineVisitedLinksManager(); + WebEngineVisitedLinksManager(BrowserContextAdapter*); void deleteAllVisitedLinkData(); void deleteVisitedLinkDataForUrls(const QList<QUrl> &); diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index ad850e84e..3a6b8cb21 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -37,6 +37,7 @@ #include "qquickwebengineview_p.h" #include "qquickwebengineview_p_p.h" +#include "browser_context_adapter.h" #include "certificate_error_controller.h" #include "javascript_dialog_controller.h" #include "qquickwebenginehistory_p.h" @@ -343,9 +344,11 @@ void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebConten switch (disposition) { case WebContentsAdapterClient::NewForegroundTabDisposition: - case WebContentsAdapterClient::NewBackgroundTabDisposition: request.m_destination = QQuickWebEngineView::NewViewInTab; break; + case WebContentsAdapterClient::NewBackgroundTabDisposition: + request.m_destination = QQuickWebEngineView::NewViewInBackgroundTab; + break; case WebContentsAdapterClient::NewPopupDisposition: request.m_destination = QQuickWebEngineView::NewViewInDialog; break; @@ -356,7 +359,7 @@ void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebConten Q_UNREACHABLE(); } - emit e->newViewRequested(&request); + Q_EMIT e->newViewRequested(&request); } void QQuickWebEngineViewPrivate::close() @@ -401,6 +404,11 @@ QObject *QQuickWebEngineViewPrivate::accessibilityParentObject() return q; } +BrowserContextAdapter *QQuickWebEngineViewPrivate::browserContextAdapter() +{ + return BrowserContextAdapter::defaultContext(); +} + WebEngineSettings *QQuickWebEngineViewPrivate::webEngineSettings() const { return m_settings->d_func()->coreSettings.data(); @@ -557,6 +565,17 @@ void QQuickWebEngineView::stop() d->adapter->stop(); } +void QQuickWebEngineView::setZoomFactor(qreal arg) +{ + Q_D(QQuickWebEngineView); + qreal oldFactor = d->adapter->currentZoomFactor(); + d->adapter->setZoomFactor(arg); + if (qFuzzyCompare(oldFactor, d->adapter->currentZoomFactor())) + return; + + emit zoomFactorChanged(arg); +} + void QQuickWebEngineViewPrivate::didRunJavaScript(quint64 requestId, const QVariant &result) { Q_Q(QQuickWebEngineView); @@ -620,6 +639,12 @@ QQuickWebEngineViewExperimental *QQuickWebEngineView::experimental() const return d->e.data(); } +qreal QQuickWebEngineView::zoomFactor() const +{ + Q_D(const QQuickWebEngineView); + return d->adapter->currentZoomFactor(); +} + bool QQuickWebEngineViewExperimental::inspectable() const { Q_D(const QQuickWebEngineView); diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index 22713ee22..9f6493022 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -56,6 +56,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY urlChanged) Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY urlChanged) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) Q_ENUMS(NavigationRequestAction); Q_ENUMS(NavigationType); Q_ENUMS(LoadStatus); @@ -75,6 +76,7 @@ public: QString title() const; bool canGoBack() const; bool canGoForward() const; + qreal zoomFactor() const; QQuickWebEngineViewExperimental *experimental() const; @@ -116,7 +118,8 @@ public: enum NewViewDestination { NewViewInWindow, NewViewInTab, - NewViewInDialog + NewViewInDialog, + NewViewInBackgroundTab }; // must match WebContentsAdapterClient::JavaScriptConsoleMessageLevel @@ -133,6 +136,7 @@ public Q_SLOTS: void goForward(); void reload(); void stop(); + void setZoomFactor(qreal arg); Q_SIGNALS: void titleChanged(); @@ -143,6 +147,7 @@ Q_SIGNALS: void linkHovered(const QUrl &hoveredUrl); void navigationRequested(QQuickWebEngineNavigationRequest *request); void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID); + void zoomFactorChanged(qreal arg); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 6662f1f02..c7ea6575e 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -179,6 +179,8 @@ public: virtual WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; virtual void allowCertificateError(const QExplicitlySharedDataPointer<CertificateErrorController> &errorController); + virtual BrowserContextAdapter *browserContextAdapter() Q_DECL_OVERRIDE; + void setDevicePixelRatio(qreal); void adoptWebContents(WebContentsAdapter *webContents); diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 72b16f28b..e3ab2ec0d 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -23,6 +23,7 @@ #include "qwebenginepage.h" #include "qwebenginepage_p.h" +#include "browser_context_adapter.h" #include "certificate_error_controller.h" #include "javascript_dialog_controller.h" #include "qwebenginehistory.h" @@ -410,6 +411,11 @@ void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input) } } +BrowserContextAdapter *QWebEnginePagePrivate::browserContextAdapter() +{ + return BrowserContextAdapter::defaultContext(); +} + QWebEnginePage::QWebEnginePage(QObject* parent) : QObject(parent) , d_ptr(new QWebEnginePagePrivate) @@ -624,6 +630,13 @@ bool QWebEnginePagePrivate::contextMenuRequested(const WebEngineContextMenuData return true; } +void QWebEnginePagePrivate::navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) +{ + Q_Q(QWebEnginePage); + bool accepted = q->acceptNavigationRequest(url, static_cast<QWebEnginePage::NavigationType>(navigationType), isMainFrame); + navigationRequestAction = accepted ? WebContentsAdapterClient::AcceptRequest : WebContentsAdapterClient::IgnoreRequest; +} + void QWebEnginePagePrivate::javascriptDialog(QSharedPointer<JavaScriptDialogController> controller) { Q_Q(QWebEnginePage); @@ -945,6 +958,14 @@ bool QWebEnginePage::certificateError(const QWebEngineCertificateError &) return false; } +bool QWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) +{ + Q_UNUSED(url); + Q_UNUSED(type); + Q_UNUSED(isMainFrame); + return true; +} + QT_END_NAMESPACE #include "moc_qwebenginepage.cpp" diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 7856b8243..afb62ceda 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -136,6 +136,16 @@ public: PermissionDeniedByUser }; + // must match WebContentsAdapterClient::NavigationType + enum NavigationType { + NavigationTypeLinkClicked, + NavigationTypeTyped, + NavigationTypeFormSubmitted, + NavigationTypeBackForward, + NavigationTypeReload, + NavigationTypeOther + }; + enum Feature { #ifndef Q_QDOC Notifications = 0, @@ -248,6 +258,7 @@ protected: virtual bool javaScriptPrompt(const QUrl &securityOrigin, const QString& msg, const QString& defaultValue, QString* result); virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID); virtual bool certificateError(const QWebEngineCertificateError &certificateError); + virtual bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame); private: Q_DECLARE_PRIVATE(QWebEnginePage); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 54129229f..6424c3b0b 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -122,7 +122,7 @@ public: virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry) Q_DECL_OVERRIDE; virtual void close() Q_DECL_OVERRIDE; virtual bool contextMenuRequested(const WebEngineContextMenuData &data) Q_DECL_OVERRIDE; - virtual void navigationRequested(int, const QUrl &, int &, bool) Q_DECL_OVERRIDE { } + virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) Q_DECL_OVERRIDE; virtual void requestFullScreen(bool) Q_DECL_OVERRIDE { } virtual bool isFullScreen() const Q_DECL_OVERRIDE { return false; } virtual void javascriptDialog(QSharedPointer<JavaScriptDialogController>) Q_DECL_OVERRIDE; @@ -139,6 +139,8 @@ public: virtual WebEngineSettings *webEngineSettings() const Q_DECL_OVERRIDE; virtual void allowCertificateError(const QExplicitlySharedDataPointer<CertificateErrorController> &controller) Q_DECL_OVERRIDE; + virtual BrowserContextAdapter *browserContextAdapter() Q_DECL_OVERRIDE; + void updateAction(QWebEnginePage::WebAction) const; void updateNavigationActions(); void _q_webActionTriggered(bool checked); diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc index e89b10ab8..af435d170 100644 --- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc +++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc @@ -147,6 +147,21 @@ */ /*! + \enum QWebEnginePage::NavigationType + + This enum describes the type of a navigation request. + + \value NavigationTypeLinkClicked The navigation request resulted from a clicked link. + \value NavigationTypeTyped The navigation request resulted from an explicitly loaded url. + \value NavigationTypeFormSubmitted The navigation request resulted from a form submission. + \value NavigationTypeBackForward The navigation request resulted from a back/forward action. + \value NavigationTypeReload The navigation request resulted from a reload action. + \value NavigationTypeOther The navigation request was triggered by other means not covered by the above. + + \sa acceptNavigationRequest() +*/ + +/*! \enum QWebEnginePage::Feature This enum describes the platform feature access categories that the user may be asked to grant or deny access to. @@ -209,6 +224,15 @@ */ /*! + \fn bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) + This function is called whenever there is a request to navigate to a specified \a url by means of the specified navigation type \atype. + The \a isMainFrame argument marks if the request corresponds to the main frame, or a sub frame. + If the request is accepted Chromium will continue to load the page, else the request will be ignored. + The default implementation accepts the navigation request. +*/ + + +/*! \fn void QWebEnginePage::javaScriptAlert(const QUrl &securityOrigin, const QString& msg) This function is called whenever a JavaScript program running in a frame affiliated with \a securityOrigin calls the alert() function with the message \a msg. |