summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/api/core_api.pro10
-rw-r--r--src/core/api/dummy.cpp1
-rw-r--r--src/core/api/qwebenginecallback_p.h8
-rw-r--r--src/core/api/qwebenginecookiestoreclient.cpp151
-rw-r--r--src/core/api/qwebenginecookiestoreclient.h83
-rw-r--r--src/core/api/qwebenginecookiestoreclient_p.h94
-rw-r--r--src/core/browser_context_adapter.cpp12
-rw-r--r--src/core/browser_context_adapter.h7
-rw-r--r--src/core/cookie_monster_delegate_qt.cpp138
-rw-r--r--src/core/cookie_monster_delegate_qt.h79
-rw-r--r--src/core/core_gyp_generator.pro2
-rw-r--r--src/core/type_conversion.h13
-rw-r--r--src/core/url_request_context_getter_qt.cpp18
-rw-r--r--src/core/url_request_context_getter_qt.h4
-rw-r--r--src/core/web_contents_adapter.cpp3
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp13
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h4
17 files changed, 633 insertions, 7 deletions
diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro
index e0a6c2de4..605a6dc3b 100644
--- a/src/core/api/core_api.pro
+++ b/src/core/api/core_api.pro
@@ -4,6 +4,7 @@ DESTDIR = $$OUT_PWD/$$getConfigDir()
TEMPLATE = lib
CONFIG += staticlib c++11
+QT += network
# Don't create .prl file for this intermediate library because
# their contents get used when linking against them, breaking
@@ -17,7 +18,9 @@ CONFIG -= create_prl
contains(QT_CONFIG, build_all):CONFIG += build_all
}
-DEFINES += BUILDING_CHROMIUM
+DEFINES += \
+ BUILDING_CHROMIUM \
+ NOMINMAX
CHROMIUM_SRC_DIR = $$QTWEBENGINE_ROOT/$$getChromiumSrcDir()
INCLUDEPATH += $$QTWEBENGINE_ROOT/src/core \
@@ -30,5 +33,8 @@ HEADERS = \
qwebenginecallback_p.h \
qtwebenginecoreglobal.h \
qtwebenginecoreglobal_p.h \
+ qwebenginecookiestoreclient.h \
+ qwebenginecookiestoreclient_p.h \
-SOURCES = dummy.cpp \
+SOURCES = \
+ qwebenginecookiestoreclient.cpp \
diff --git a/src/core/api/dummy.cpp b/src/core/api/dummy.cpp
deleted file mode 100644
index 3c2a8e265..000000000
--- a/src/core/api/dummy.cpp
+++ /dev/null
@@ -1 +0,0 @@
-// Used when we need to compile with no source code
diff --git a/src/core/api/qwebenginecallback_p.h b/src/core/api/qwebenginecallback_p.h
index 9c798acbe..9eb627ad3 100644
--- a/src/core/api/qwebenginecallback_p.h
+++ b/src/core/api/qwebenginecallback_p.h
@@ -72,6 +72,14 @@ public:
}
}
+ enum ReservedCallbackIds {
+ NoCallbackId = 0,
+ DeleteCookieCallbackId,
+
+ // Place reserved id's before this.
+ ReservedCallbackIdsEnd
+ };
+
template<typename T>
void registerCallback(quint64 callbackId, const QWebEngineCallback<T> &callback);
diff --git a/src/core/api/qwebenginecookiestoreclient.cpp b/src/core/api/qwebenginecookiestoreclient.cpp
new file mode 100644
index 000000000..c8b314be9
--- /dev/null
+++ b/src/core/api/qwebenginecookiestoreclient.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.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 "qwebenginecookiestoreclient.h"
+#include "qwebenginecookiestoreclient_p.h"
+
+#include <QByteArray>
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+
+using namespace QtWebEngineCore;
+
+QWebEngineCookieStoreClientPrivate::QWebEngineCookieStoreClientPrivate(QWebEngineCookieStoreClient* q)
+ : m_nextCallbackId(CallbackDirectory::ReservedCallbackIdsEnd)
+ , delegate(0)
+ , q_ptr(q)
+{
+}
+
+QWebEngineCookieStoreClientPrivate::~QWebEngineCookieStoreClientPrivate()
+{
+
+}
+
+void QWebEngineCookieStoreClientPrivate::processPendingUserCookies()
+{
+ Q_ASSERT(delegate);
+ Q_ASSERT(delegate->hasCookieMonster());
+
+ if (m_pendingUserCookies.isEmpty())
+ return;
+
+ Q_FOREACH (const auto &cookieData, m_pendingUserCookies) {
+ if (cookieData.callbackId == CallbackDirectory::DeleteCookieCallbackId)
+ delegate->deleteCookie(cookieData.cookie, cookieData.origin);
+ else
+ delegate->setCookie(cookieData.callbackId, cookieData.cookie, cookieData.origin);
+ }
+
+ m_pendingUserCookies.clear();
+}
+
+void QWebEngineCookieStoreClientPrivate::setCookie(const QWebEngineCallback<bool> &callback, const QNetworkCookie &cookie, const QUrl &origin)
+{
+ const quint64 currentCallbackId = callback ? m_nextCallbackId++ : static_cast<quint64>(CallbackDirectory::NoCallbackId);
+
+ if (currentCallbackId != CallbackDirectory::NoCallbackId)
+ callbackDirectory.registerCallback(currentCallbackId, callback);
+
+ if (!delegate || !delegate->hasCookieMonster()) {
+ m_pendingUserCookies.append(CookieData{ currentCallbackId, cookie, origin });
+ return;
+ }
+
+ delegate->setCookie(currentCallbackId, cookie, origin);
+}
+
+void QWebEngineCookieStoreClientPrivate::deleteCookie(const QNetworkCookie &cookie, const QUrl &url)
+{
+ if (!delegate || !delegate->hasCookieMonster()) {
+ m_pendingUserCookies.append(CookieData{ CallbackDirectory::DeleteCookieCallbackId, cookie, url });
+ return;
+ }
+
+ delegate->deleteCookie(cookie, url);
+}
+
+void QWebEngineCookieStoreClientPrivate::onSetCallbackResult(qint64 callbackId, bool success)
+{
+ callbackDirectory.invoke(callbackId, success);
+}
+
+void QWebEngineCookieStoreClientPrivate::onCookieChanged(const QNetworkCookie &cookie, bool removed)
+{
+ Q_Q(QWebEngineCookieStoreClient);
+ if (removed)
+ Q_EMIT q->cookieRemoved(cookie);
+ else
+ Q_EMIT q->cookieAdded(cookie);
+}
+
+void QWebEngineCookieStoreClientPrivate::onCookieStoreLoaded()
+{
+ Q_Q(QWebEngineCookieStoreClient);
+ Q_EMIT q->cookieStoreLoaded();
+}
+
+QWebEngineCookieStoreClient::QWebEngineCookieStoreClient(QObject *parent)
+ : QObject(parent)
+ , d_ptr(new QWebEngineCookieStoreClientPrivate(this))
+{
+
+}
+
+QWebEngineCookieStoreClient::~QWebEngineCookieStoreClient()
+{
+
+}
+
+void QWebEngineCookieStoreClient::setCookieWithCallback(const QNetworkCookie &cookie, const QWebEngineCallback<bool> &resultCallback, const QUrl &origin)
+{
+ Q_D(QWebEngineCookieStoreClient);
+ d->setCookie(resultCallback, cookie, origin);
+}
+
+void QWebEngineCookieStoreClient::setCookie(const QNetworkCookie &cookie, const QUrl &origin)
+{
+ setCookieWithCallback(cookie, QWebEngineCallback<bool>(), origin);
+}
+
+void QWebEngineCookieStoreClient::deleteCookie(const QNetworkCookie &cookie, const QUrl &origin)
+{
+ Q_D(QWebEngineCookieStoreClient);
+ d->deleteCookie(cookie, origin);
+}
+
+QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginecookiestoreclient.h b/src/core/api/qwebenginecookiestoreclient.h
new file mode 100644
index 000000000..3ab7df14f
--- /dev/null
+++ b/src/core/api/qwebenginecookiestoreclient.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.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 QWEBENGINECOOKIESTORECLIENT_H
+#define QWEBENGINECOOKIESTORECLIENT_H
+
+#include "qtwebenginecoreglobal.h"
+#include "qwebenginecallback.h"
+
+#include <QObject>
+#include <QScopedPointer>
+#include <QNetworkCookie>
+#include <QUrl>
+
+namespace QtWebEngineCore {
+class CookieMonsterDelegateQt;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QWebEngineCookieStoreClientPrivate;
+class QWEBENGINE_EXPORT QWebEngineCookieStoreClient : public QObject {
+ Q_OBJECT
+public:
+ explicit QWebEngineCookieStoreClient(QObject *parent = 0);
+ virtual ~QWebEngineCookieStoreClient();
+
+#ifdef Q_QDOC
+ void setCookieWithCallback(const QNetworkCookie &cookie, FunctorOrLambda resultCallback, const QUrl &origin = QUrl());
+#else
+ void setCookieWithCallback(const QNetworkCookie &cookie, const QWebEngineCallback<bool> &resultCallback, const QUrl &origin = QUrl());
+#endif
+ void setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
+ void deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
+
+Q_SIGNALS:
+ void cookieAdded(const QNetworkCookie &cookie);
+ void cookieRemoved(const QNetworkCookie &cookie);
+ void cookieStoreLoaded();
+
+private:
+ friend class QtWebEngineCore::CookieMonsterDelegateQt;
+
+ Q_DECLARE_PRIVATE(QWebEngineCookieStoreClient)
+ QScopedPointer<QWebEngineCookieStoreClientPrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINECOOKIESTORECLIENT_H
diff --git a/src/core/api/qwebenginecookiestoreclient_p.h b/src/core/api/qwebenginecookiestoreclient_p.h
new file mode 100644
index 000000000..aedb473cd
--- /dev/null
+++ b/src/core/api/qwebenginecookiestoreclient_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.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 QWEBENGINECOOKIESTORECLIENT_P_H
+#define QWEBENGINECOOKIESTORECLIENT_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 "cookie_monster_delegate_qt.h"
+#include "qwebenginecallback_p.h"
+#include "qwebenginecookiestoreclient.h"
+
+#include <QList>
+#include <QMap>
+#include <QNetworkCookie>
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+
+class QWEBENGINE_PRIVATE_EXPORT QWebEngineCookieStoreClientPrivate {
+ struct CookieData {
+ quint64 callbackId;
+ QNetworkCookie cookie;
+ QUrl origin;
+ };
+
+public:
+ Q_DECLARE_PUBLIC(QWebEngineCookieStoreClient)
+ QtWebEngineCore::CallbackDirectory callbackDirectory;
+ QList<CookieData> m_pendingUserCookies;
+ quint64 m_nextCallbackId;
+
+ QtWebEngineCore::CookieMonsterDelegateQt *delegate;
+ QWebEngineCookieStoreClient *q_ptr;
+
+ QWebEngineCookieStoreClientPrivate(QWebEngineCookieStoreClient *q);
+ ~QWebEngineCookieStoreClientPrivate();
+
+ void processPendingUserCookies();
+ void setCookie(const QWebEngineCallback<bool> &callback, const QNetworkCookie &cookie, const QUrl &origin);
+ void deleteCookie(const QNetworkCookie &cookie, const QUrl &url);
+
+ void onSetCallbackResult(qint64 callbackId, bool success);
+ void onCookieChanged(const QNetworkCookie &cookie, bool removed);
+ void onCookieStoreLoaded();
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINECOOKIESTORECLIENT_P_H
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index fa51575e3..a01f7a4b8 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -132,6 +132,18 @@ DownloadManagerDelegateQt *BrowserContextAdapter::downloadManagerDelegate()
return m_downloadManagerDelegate.data();
}
+QWebEngineCookieStoreClient *BrowserContextAdapter::cookieStoreClient()
+{
+ return m_cookieStoreClient.data();
+}
+
+void BrowserContextAdapter::setCookieStoreClient(QWebEngineCookieStoreClient *client)
+{
+ m_cookieStoreClient = client;
+ if (m_browserContext->url_request_getter_.get())
+ m_browserContext->url_request_getter_->updateStorageSettings();
+}
+
void BrowserContextAdapter::addClient(BrowserContextAdapterClient *adapterClient)
{
m_clients.append(adapterClient);
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index 42787bc23..1a973c026 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -40,11 +40,14 @@
#include "qtwebenginecoreglobal.h"
#include <QList>
+#include <QPointer>
#include <QScopedPointer>
#include <QSharedData>
#include <QString>
#include <QVector>
+#include "api/qwebenginecookiestoreclient.h"
+
QT_FORWARD_DECLARE_CLASS(QObject)
namespace QtWebEngineCore {
@@ -69,6 +72,9 @@ public:
WebEngineVisitedLinksManager *visitedLinksManager();
DownloadManagerDelegateQt *downloadManagerDelegate();
+ QWebEngineCookieStoreClient *cookieStoreClient();
+ void setCookieStoreClient(QWebEngineCookieStoreClient *client);
+
QList<BrowserContextAdapterClient*> clients() { return m_clients; }
void addClient(BrowserContextAdapterClient *adapterClient);
void removeClient(BrowserContextAdapterClient *adapterClient);
@@ -139,6 +145,7 @@ private:
QScopedPointer<WebEngineVisitedLinksManager> m_visitedLinksManager;
QScopedPointer<DownloadManagerDelegateQt> m_downloadManagerDelegate;
QScopedPointer<UserScriptControllerHost> m_userScriptController;
+ QPointer<QWebEngineCookieStoreClient> m_cookieStoreClient;
QString m_dataPath;
QString m_cachePath;
diff --git a/src/core/cookie_monster_delegate_qt.cpp b/src/core/cookie_monster_delegate_qt.cpp
new file mode 100644
index 000000000..f42768901
--- /dev/null
+++ b/src/core/cookie_monster_delegate_qt.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.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 "cookie_monster_delegate_qt.h"
+
+#include "base/bind.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/cookies/cookie_util.h"
+
+#include "api/qwebenginecookiestoreclient.h"
+#include "api/qwebenginecookiestoreclient_p.h"
+#include "type_conversion.h"
+
+namespace QtWebEngineCore {
+
+static GURL sourceUrlForCookie(const QNetworkCookie &cookie) {
+ QString urlFragment = QString("%1%2").arg(cookie.domain()).arg(cookie.path());
+ return net::cookie_util::CookieOriginToURL(urlFragment.toStdString(), /* is_https */ cookie.isSecure());
+}
+
+static void onSetCookieCallback(QWebEngineCookieStoreClientPrivate *client, qint64 callbackId, bool success) {
+ client->onSetCallbackResult(callbackId, success);
+}
+
+CookieMonsterDelegateQt::CookieMonsterDelegateQt()
+ : m_client(0)
+ , m_cookieMonster(0)
+{
+
+}
+
+CookieMonsterDelegateQt::~CookieMonsterDelegateQt()
+{
+
+}
+
+bool CookieMonsterDelegateQt::hasCookieMonster()
+{
+ return m_cookieMonster.get();
+}
+
+void CookieMonsterDelegateQt::setCookie(quint64 callbackId, const QNetworkCookie &cookie, const QUrl &origin)
+{
+ Q_ASSERT(hasCookieMonster());
+ Q_ASSERT(m_client);
+
+ net::CookieStore::SetCookiesCallback callback;
+ if (callbackId != CallbackDirectory::NoCallbackId)
+ callback = base::Bind(&onSetCookieCallback, m_client->d_func(), callbackId);
+
+ net::CookieOptions options;
+ options.set_include_httponly();
+
+ GURL gurl = origin.isEmpty() ? sourceUrlForCookie(cookie) : toGurl(origin);
+
+ m_cookieMonster->SetCookieWithOptionsAsync(gurl, cookie.toRawForm().toStdString(), options, callback);
+}
+
+void CookieMonsterDelegateQt::deleteCookie(const QNetworkCookie &cookie, const QUrl &origin)
+{
+ Q_ASSERT(hasCookieMonster());
+ Q_ASSERT(m_client);
+
+ GURL gurl = origin.isEmpty() ? sourceUrlForCookie(cookie) : toGurl(origin);
+
+ m_cookieMonster->DeleteCookieAsync(gurl, cookie.name().toStdString(), base::Closure());
+}
+
+void CookieMonsterDelegateQt::setCookieMonster(net::CookieMonster* monster)
+{
+ m_cookieMonster = monster;
+
+ if (m_client)
+ m_client->d_func()->processPendingUserCookies();
+}
+
+void CookieMonsterDelegateQt::setClient(QWebEngineCookieStoreClient *client)
+{
+ m_client = client;
+
+ if (!m_client)
+ return;
+
+ m_client->d_ptr->delegate = this;
+
+ if (hasCookieMonster())
+ m_client->d_func()->processPendingUserCookies();
+}
+
+void CookieMonsterDelegateQt::OnCookieChanged(const net::CanonicalCookie& cookie, bool removed, ChangeCause cause)
+{
+ if (!m_client)
+ return;
+ m_client->d_ptr->onCookieChanged(toQt(cookie), removed);
+}
+
+void CookieMonsterDelegateQt::OnLoaded()
+{
+ if (!m_client)
+ return;
+
+ m_client->d_ptr->onCookieStoreLoaded();
+}
+
+}
diff --git a/src/core/cookie_monster_delegate_qt.h b/src/core/cookie_monster_delegate_qt.h
new file mode 100644
index 000000000..05ab24e9f
--- /dev/null
+++ b/src/core/cookie_monster_delegate_qt.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.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 COOKIE_MONSTER_DELEGATE_QT_H
+#define COOKIE_MONSTER_DELEGATE_QT_H
+
+#include "qtwebenginecoreglobal.h"
+
+QT_WARNING_PUSH
+// For some reason adding -Wno-unused-parameter to QMAKE_CXXFLAGS has no
+// effect with clang, so use a pragma for these dirty chromium headers
+QT_WARNING_DISABLE_CLANG("-Wunused-parameter")
+#include "base/memory/ref_counted.h"
+#include "net/cookies/cookie_monster.h"
+QT_WARNING_POP
+
+#include <QList>
+#include <QNetworkCookie>
+#include <QPointer>
+
+QT_FORWARD_DECLARE_CLASS(QWebEngineCookieStoreClient)
+
+namespace QtWebEngineCore {
+
+class QWEBENGINE_EXPORT CookieMonsterDelegateQt: public net::CookieMonsterDelegate {
+ QPointer<QWebEngineCookieStoreClient> m_client;
+ scoped_refptr<net::CookieMonster> m_cookieMonster;
+public:
+ CookieMonsterDelegateQt();
+ ~CookieMonsterDelegateQt();
+
+ bool hasCookieMonster();
+
+ void setCookie(quint64 callbackId, const QNetworkCookie &cookie, const QUrl &origin);
+ void deleteCookie(const QNetworkCookie &cookie, const QUrl &origin);
+
+ void setCookieMonster(net::CookieMonster* monster);
+ void setClient(QWebEngineCookieStoreClient *client);
+
+ void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed, ChangeCause cause) override;
+ void OnLoaded() override;
+};
+
+}
+
+#endif // COOKIE_MONSTER_DELEGATE_QT_H
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro
index 494924054..4ab1b7b98 100644
--- a/src/core/core_gyp_generator.pro
+++ b/src/core/core_gyp_generator.pro
@@ -42,6 +42,7 @@ SOURCES = \
content_client_qt.cpp \
content_browser_client_qt.cpp \
content_main_delegate_qt.cpp \
+ cookie_monster_delegate_qt.cpp \
custom_protocol_handler.cpp \
custom_url_scheme_handler.cpp \
delegated_frame_node.cpp \
@@ -111,6 +112,7 @@ HEADERS = \
content_client_qt.h \
content_browser_client_qt.h \
content_main_delegate_qt.h \
+ cookie_monster_delegate_qt.h \
custom_protocol_handler.h \
custom_url_scheme_handler.h \
delegated_frame_node.h \
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index 3f5575a47..a711e7235 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -41,12 +41,14 @@
#include <QDateTime>
#include <QDir>
#include <QMatrix4x4>
+#include <QNetworkCookie>
#include <QRect>
#include <QString>
#include <QUrl>
#include "base/files/file_path.h"
#include "base/time/time.h"
#include "content/public/common/file_chooser_file_info.h"
+#include "net/cookies/canonical_cookie.h"
#include "third_party/skia/include/utils/SkMatrix44.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/rect.h"
@@ -147,6 +149,17 @@ inline base::Time toTime(const QDateTime &dateTime) {
return base::Time::FromInternalValue(dateTime.toMSecsSinceEpoch());
}
+inline QNetworkCookie toQt(const net::CanonicalCookie & cookie)
+{
+ QNetworkCookie qCookie = QNetworkCookie(QByteArray::fromStdString(cookie.Name()), QByteArray::fromStdString(cookie.Value()));
+ qCookie.setDomain(toQt(cookie.Domain()));
+ qCookie.setExpirationDate(toQt(cookie.ExpiryDate()));
+ qCookie.setHttpOnly(cookie.IsHttpOnly());
+ qCookie.setPath(toQt(cookie.Path()));
+ qCookie.setSecure(cookie.IsSecure());
+ return qCookie;
+}
+
inline base::FilePath::StringType toFilePathString(const QString &str)
{
#if defined(OS_WIN)
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index da0dd8ab3..d829666b7 100644
--- a/src/core/url_request_context_getter_qt.cpp
+++ b/src/core/url_request_context_getter_qt.cpp
@@ -64,11 +64,14 @@
#include "browser_context_adapter.h"
#include "custom_protocol_handler.h"
#include "custom_url_scheme_handler.h"
+#include "cookie_monster_delegate_qt.h"
#include "content_client_qt.h"
#include "network_delegate_qt.h"
#include "proxy_config_service_qt.h"
#include "proxy_resolver_qt.h"
#include "qrc_protocol_handler_qt.h"
+#include "qwebenginecookiestoreclient.h"
+#include "qwebenginecookiestoreclient_p.h"
#include "type_conversion.h"
namespace QtWebEngineCore {
@@ -80,6 +83,7 @@ using content::BrowserThread;
URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextAdapter *browserContext, content::ProtocolHandlerMap *protocolHandlers)
: m_ignoreCertificateErrors(false)
, m_browserContext(browserContext)
+ , m_cookieDelegate(new CookieMonsterDelegateQt())
{
std::swap(m_protocolHandlers, *protocolHandlers);
@@ -186,6 +190,8 @@ void URLRequestContextGetterQt::generateCookieStore()
// Unset it first to get a chance to destroy and flush the old cookie store before before opening a new on possibly the same file.
m_storage->set_cookie_store(0);
+ m_cookieDelegate->setCookieMonster(0);
+ m_cookieDelegate->setClient(m_browserContext->cookieStoreClient());
net::CookieStore* cookieStore = 0;
switch (m_browserContext->persistentCookiesPolicy()) {
@@ -194,7 +200,8 @@ void URLRequestContextGetterQt::generateCookieStore()
content::CreateCookieStore(content::CookieStoreConfig(
base::FilePath(),
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
- NULL, NULL)
+ NULL,
+ m_cookieDelegate.get())
);
break;
case BrowserContextAdapter::AllowPersistentCookies:
@@ -202,7 +209,8 @@ void URLRequestContextGetterQt::generateCookieStore()
content::CreateCookieStore(content::CookieStoreConfig(
toFilePath(m_browserContext->cookiesPath()),
content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES,
- NULL, NULL)
+ NULL,
+ m_cookieDelegate.get())
);
break;
case BrowserContextAdapter::ForcePersistentCookies:
@@ -210,11 +218,15 @@ void URLRequestContextGetterQt::generateCookieStore()
content::CreateCookieStore(content::CookieStoreConfig(
toFilePath(m_browserContext->cookiesPath()),
content::CookieStoreConfig::RESTORED_SESSION_COOKIES,
- NULL, NULL)
+ NULL,
+ m_cookieDelegate.get())
);
break;
}
m_storage->set_cookie_store(cookieStore);
+
+ net::CookieMonster * const cookieMonster = cookieStore->GetCookieMonster();
+ m_cookieDelegate->setCookieMonster(cookieMonster);
}
void URLRequestContextGetterQt::updateUserAgent()
diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h
index d08836714..78fb5a1ab 100644
--- a/src/core/url_request_context_getter_qt.h
+++ b/src/core/url_request_context_getter_qt.h
@@ -48,6 +48,8 @@
#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_job_factory_impl.h"
+#include "cookie_monster_delegate_qt.h"
+
#include "qglobal.h"
#include <qatomic.h>
@@ -95,6 +97,8 @@ private:
scoped_ptr<net::NetworkDelegate> m_networkDelegate;
scoped_ptr<net::URLRequestContextStorage> m_storage;
scoped_ptr<net::URLRequestJobFactoryImpl> m_jobFactory;
+
+ scoped_refptr<CookieMonsterDelegateQt> m_cookieDelegate;
};
} // namespace QtWebEngineCore
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index ec7928c71..ac1bf968d 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -46,6 +46,7 @@
#include "browser_context_qt.h"
#include "media_capture_devices_dispatcher.h"
#include "qt_render_view_observer_host.h"
+#include "qwebenginecallback_p.h"
#include "type_conversion.h"
#include "web_channel_ipc_transport_host.h"
#include "web_contents_adapter_client.h"
@@ -309,7 +310,7 @@ WebContentsAdapterPrivate::WebContentsAdapterPrivate()
: engineContext(WebEngineContext::current())
, webChannel(0)
, adapterClient(0)
- , nextRequestId(1)
+ , nextRequestId(CallbackDirectory::ReservedCallbackIdsEnd)
, lastFindRequestId(0)
{
}
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index adccfca2a..eda242102 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -36,6 +36,7 @@
#include "qwebengineprofile.h"
+#include "qwebenginecookiestoreclient.h"
#include "qwebenginedownloaditem.h"
#include "qwebenginedownloaditem_p.h"
#include "qwebenginepage.h"
@@ -403,6 +404,18 @@ void QWebEngineProfile::setHttpCacheMaximumSize(int maxSize)
d->browserContext()->setHttpCacheMaxSize(maxSize);
}
+QWebEngineCookieStoreClient* QWebEngineProfile::cookieStoreClient()
+{
+ Q_D(QWebEngineProfile);
+ return d->browserContext()->cookieStoreClient();
+}
+
+void QWebEngineProfile::setCookieStoreClient(QWebEngineCookieStoreClient *client)
+{
+ Q_D(QWebEngineProfile);
+ d->browserContext()->setCookieStoreClient(client);
+}
+
/*!
Clears all links from the visited links database.
diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h
index d65db24ab..ab36a7b16 100644
--- a/src/webenginewidgets/api/qwebengineprofile.h
+++ b/src/webenginewidgets/api/qwebengineprofile.h
@@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE
class QObject;
class QUrl;
+class QWebEngineCookieStoreClient;
class QWebEngineDownloadItem;
class QWebEnginePage;
class QWebEnginePagePrivate;
@@ -93,6 +94,9 @@ public:
int httpCacheMaximumSize() const;
void setHttpCacheMaximumSize(int maxSize);
+ QWebEngineCookieStoreClient* cookieStoreClient();
+ void setCookieStoreClient(QWebEngineCookieStoreClient *client);
+
void clearAllVisitedLinks();
void clearVisitedLinks(const QList<QUrl> &urls);
bool visitedLinksContainsUrl(const QUrl &url) const;