summaryrefslogtreecommitdiffstats
path: root/src/core/browser_context_adapter.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-11-24 18:03:17 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2014-12-12 12:29:12 +0100
commit6ec3268a30a63d5c15258ea6f4f792e21930b093 (patch)
treeb2a122f94eed67546a7ee1d0f118a7e72ec18c8f /src/core/browser_context_adapter.cpp
parentb93a478d60e90073870aad22febd519adc4a4a3b (diff)
Introduce QWebEngineProfile API
Introduces initial widgets API for the Chromium BrowserContext. Adds API for controlling cookie jar policy, user-agent string and cache and persistent data paths. Similar QML API will follow in another patch. [ChangeLog][QtWebEngineWidgets][QWebEngineProfile] New API for profiles applying to groups of QWebEnginePages. Change-Id: I3c4ef4053fde7564af29178c91a0aca8a2b61a5f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src/core/browser_context_adapter.cpp')
-rw-r--r--src/core/browser_context_adapter.cpp161
1 files changed, 155 insertions, 6 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index ccb6a385d..133dd688a 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -37,8 +37,12 @@
#include "browser_context_adapter.h"
#include "browser_context_qt.h"
+#include "content_client_qt.h"
#include "web_engine_context.h"
#include "web_engine_visited_links_manager.h"
+#include "url_request_context_getter_qt.h"
+
+#include "net/proxy/proxy_service.h"
#include <QCoreApplication>
#include <QDir>
@@ -57,11 +61,22 @@ inline QString buildLocationFromStandardPath(const QString &standardPath, const
}
}
-BrowserContextAdapter::BrowserContextAdapter(const QString &name, bool offTheRecord)
- : m_name(name)
- , m_offTheRecord(offTheRecord)
+BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord)
+ : m_offTheRecord(offTheRecord)
+ , m_browserContext(new BrowserContextQt(this))
+ , m_httpCacheType(DiskHttpCache)
+ , m_persistentCookiesPolicy(AllowPersistentCookies)
+ , m_httpCacheMaxSize(0)
+{
+}
+
+BrowserContextAdapter::BrowserContextAdapter(const QString &storageName)
+ : m_name(storageName)
+ , m_offTheRecord(false)
, m_browserContext(new BrowserContextQt(this))
- , m_visitedLinksManager(new WebEngineVisitedLinksManager(this))
+ , m_httpCacheType(DiskHttpCache)
+ , m_persistentCookiesPolicy(AllowPersistentCookies)
+ , m_httpCacheMaxSize(0)
{
}
@@ -69,6 +84,24 @@ BrowserContextAdapter::~BrowserContextAdapter()
{
}
+void BrowserContextAdapter::setStorageName(const QString &storageName)
+{
+ if (storageName == m_name)
+ return;
+ m_name = storageName;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateStorageSettings();
+}
+
+void BrowserContextAdapter::setOffTheRecord(bool offTheRecord)
+{
+ if (offTheRecord == m_offTheRecord)
+ return;
+ m_offTheRecord = offTheRecord;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateStorageSettings();
+}
+
BrowserContextQt *BrowserContextAdapter::browserContext()
{
return m_browserContext.data();
@@ -76,6 +109,8 @@ BrowserContextQt *BrowserContextAdapter::browserContext()
WebEngineVisitedLinksManager *BrowserContextAdapter::visitedLinksManager()
{
+ if (!m_visitedLinksManager)
+ m_visitedLinksManager.reset(new WebEngineVisitedLinksManager(this));
return m_visitedLinksManager.data();
}
@@ -91,10 +126,124 @@ BrowserContextAdapter* BrowserContextAdapter::offTheRecordContext()
QString BrowserContextAdapter::dataPath() const
{
- return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation), m_name);
+ if (m_offTheRecord)
+ return QString();
+ if (!m_dataPath.isEmpty())
+ return m_dataPath;
+ if (!m_name.isNull())
+ return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation), m_name);
+ return QString();
+}
+
+void BrowserContextAdapter::setDataPath(const QString &path)
+{
+ if (m_dataPath == path)
+ return;
+ m_dataPath = path;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateStorageSettings();
}
QString BrowserContextAdapter::cachePath() const
{
- return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), m_name);
+ if (m_offTheRecord)
+ return QString();
+ if (!m_cachePath.isEmpty())
+ return m_cachePath;
+ if (!m_name.isNull())
+ return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), m_name);
+ return QString();
+}
+
+void BrowserContextAdapter::setCachePath(const QString &path)
+{
+ if (m_cachePath == path)
+ return;
+ m_cachePath = path;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateHttpCache();
+}
+
+QString BrowserContextAdapter::cookiesPath() const
+{
+ if (m_offTheRecord)
+ return QString();
+ QString basePath = dataPath();
+ if (!basePath.isEmpty())
+ return basePath % QDir::separator() % QLatin1String("Coookies");
+ return QString();
+}
+
+QString BrowserContextAdapter::httpCachePath() const
+{
+ if (m_offTheRecord)
+ return QString();
+ QString basePath = cachePath();
+ if (!basePath.isEmpty())
+ return basePath % QDir::separator() % QLatin1String("Cache");
+ return QString();
+}
+
+QString BrowserContextAdapter::httpUserAgent() const
+{
+ if (m_httpUserAgent.isNull())
+ return QString::fromStdString(ContentClientQt::getUserAgent());
+ return m_httpUserAgent;
+}
+
+void BrowserContextAdapter::setHttpUserAgent(const QString &userAgent)
+{
+ if (m_httpUserAgent == userAgent)
+ return;
+ m_httpUserAgent = userAgent;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateUserAgent();
+}
+
+BrowserContextAdapter::HttpCacheType BrowserContextAdapter::httpCacheType() const
+{
+ if (isOffTheRecord() || httpCachePath().isEmpty())
+ return MemoryHttpCache;
+ return m_httpCacheType;
+}
+
+void BrowserContextAdapter::setHttpCacheType(BrowserContextAdapter::HttpCacheType newhttpCacheType)
+{
+ BrowserContextAdapter::HttpCacheType oldCacheType = httpCacheType();
+ m_httpCacheType = newhttpCacheType;
+ if (oldCacheType == httpCacheType())
+ return;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateHttpCache();
+}
+
+BrowserContextAdapter::PersistentCookiesPolicy BrowserContextAdapter::persistentCookiesPolicy() const
+{
+ if (isOffTheRecord() || cookiesPath().isEmpty())
+ return NoPersistentCookies;
+ return m_persistentCookiesPolicy;
+}
+
+void BrowserContextAdapter::setPersistentCookiesPolicy(BrowserContextAdapter::PersistentCookiesPolicy newPersistentCookiesPolicy)
+{
+ BrowserContextAdapter::PersistentCookiesPolicy oldPolicy = persistentCookiesPolicy();
+ m_persistentCookiesPolicy = newPersistentCookiesPolicy;
+ if (oldPolicy == persistentCookiesPolicy())
+ return;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateCookieStore();
+}
+
+int BrowserContextAdapter::httpCacheMaxSize() const
+{
+ return m_httpCacheMaxSize;
+}
+
+void BrowserContextAdapter::setHttpCacheMaxSize(int maxSize)
+{
+ if (m_httpCacheMaxSize == maxSize)
+ return;
+ m_httpCacheMaxSize = maxSize;
+ if (m_browserContext->url_request_getter_)
+ m_browserContext->url_request_getter_->updateHttpCache();
}