Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.09 KB | None | 0 0
  1. diff --git a/Source/WebCore/WebCore.pri b/Source/WebCore/WebCore.pri
  2. index 0ff4763..0dbd829 100644
  3. --- a/Source/WebCore/WebCore.pri
  4. +++ b/Source/WebCore/WebCore.pri
  5. @@ -6,7 +6,7 @@ include(features.pri)
  6. # We enable TextureMapper by default; remove this line to enable GraphicsLayerQt.
  7. CONFIG += texmap
  8.  
  9. -QT *= network
  10. +QT *= network sql
  11.  
  12. SOURCE_DIR = $$replace(PWD, /WebCore, "")
  13.  
  14. diff --git a/Source/WebCore/WebCore.pro b/Source/WebCore/WebCore.pro
  15. index 300ecc7..db2a89b 100644
  16. --- a/Source/WebCore/WebCore.pro
  17. +++ b/Source/WebCore/WebCore.pro
  18. @@ -1939,6 +1939,7 @@ HEADERS += \
  19. platform/AsyncFileStream.h \
  20. platform/ContentType.h \
  21. platform/ContextMenu.h \
  22. + platform/Cookie.h \
  23. platform/CrossThreadCopier.h \
  24. platform/DateComponents.h \
  25. platform/DefaultLocalizationStrategy.h \
  26. @@ -2083,6 +2084,7 @@ HEADERS += \
  27. platform/PlatformTouchPoint.h \
  28. platform/PopupMenu.h \
  29. platform/qt/ClipboardQt.h \
  30. + platform/qt/CookieJarQt.h \
  31. platform/qt/QWebPageClient.h \
  32. platform/qt/QtStyleOptionWebComboBox.h \
  33. platform/qt/RenderThemeQt.h \
  34. diff --git a/Source/WebCore/platform/Cookie.h b/Source/WebCore/platform/Cookie.h
  35. index 4eea7d2..257a2fa 100644
  36. --- a/Source/WebCore/platform/Cookie.h
  37. +++ b/Source/WebCore/platform/Cookie.h
  38. @@ -29,12 +29,23 @@
  39. #include "PlatformString.h"
  40. #include <wtf/text/StringHash.h>
  41.  
  42. -namespace WebCore {
  43. +#if PLATFORM(QT)
  44. +QT_BEGIN_NAMESPACE
  45. +class QNetworkCookie;
  46. +QT_END_NAMESPACE
  47. +#endif
  48.  
  49. - // This struct is currently only used to provide more cookies information
  50. - // to the Web Inspector.
  51. +namespace WebCore {
  52.  
  53. struct Cookie {
  54. + Cookie()
  55. + : expires(0)
  56. + , httpOnly(false)
  57. + , secure(false)
  58. + , session(false)
  59. + {
  60. + }
  61. +
  62. Cookie(const String& name, const String& value, const String& domain,
  63. const String& path, double expires, bool httpOnly, bool secure,
  64. bool session)
  65. @@ -57,6 +68,11 @@ namespace WebCore {
  66. bool httpOnly;
  67. bool secure;
  68. bool session;
  69. +
  70. +#if PLATFORM(QT)
  71. + Cookie(const QNetworkCookie&);
  72. + operator QNetworkCookie() const;
  73. +#endif
  74. };
  75.  
  76. struct CookieHash {
  77. diff --git a/Source/WebCore/platform/qt/CookieJarQt.cpp b/Source/WebCore/platform/qt/CookieJarQt.cpp
  78. index 6dcd66b..a4f9a7c 100644
  79. --- a/Source/WebCore/platform/qt/CookieJarQt.cpp
  80. +++ b/Source/WebCore/platform/qt/CookieJarQt.cpp
  81. @@ -26,6 +26,8 @@
  82. */
  83.  
  84. #include "config.h"
  85. +#include "CookieJarQt.h"
  86. +
  87. #include "CookieJar.h"
  88.  
  89. #include "Cookie.h"
  90. @@ -38,12 +40,17 @@
  91. #include "qwebframe.h"
  92. #include "qwebpage.h"
  93. #include "qwebsettings.h"
  94. +#include <QDateTime>
  95. +#include <QDir>
  96. #include <QNetworkAccessManager>
  97. #include <QNetworkCookie>
  98. +#include <QSqlQuery>
  99. #include <QStringList>
  100.  
  101. namespace WebCore {
  102.  
  103. +static WebKit2SharedCookieJar* webKit2SharedCookieJar = 0;
  104. +
  105. static QNetworkCookieJar *cookieJar(const Document *document)
  106. {
  107. if (!document)
  108. @@ -144,19 +151,164 @@ void deleteCookie(const Document*, const KURL&, const String&)
  109.  
  110. void getHostnamesWithCookies(HashSet<String>& hostnames)
  111. {
  112. - // FIXME: Not yet implemented
  113. + WebKit2SharedCookieJar::shared()->getHostnamesWithCookies(hostnames);
  114. }
  115.  
  116. void deleteCookiesForHostname(const String& hostname)
  117. {
  118. - // FIXME: Not yet implemented
  119. + WebKit2SharedCookieJar::shared()->deleteCookiesForHostname(hostname);
  120. }
  121.  
  122. void deleteAllCookies()
  123. {
  124. - // FIXME: Not yet implemented
  125. + WebKit2SharedCookieJar::shared()->deleteAllCookies();
  126. +}
  127. +
  128. +Cookie::Cookie(const QNetworkCookie& cookie)
  129. + : name(cookie.name().constData())
  130. + , value(cookie.value().constData())
  131. + , domain(cookie.domain())
  132. + , path(cookie.path())
  133. + , expires(cookie.expirationDate().toMSecsSinceEpoch())
  134. + , httpOnly(cookie.isHttpOnly())
  135. + , secure(cookie.isSecure())
  136. + , session(cookie.isSessionCookie())
  137. +{
  138. +}
  139. +
  140. +Cookie::operator QNetworkCookie() const
  141. +{
  142. + QNetworkCookie result(QString(name).toAscii(), QString(value).toAscii());
  143. + result.setDomain(domain);
  144. + result.setPath(path);
  145. + if (session) {
  146. + QDateTime expirationDate;
  147. + expirationDate.setMSecsSinceEpoch(expires);
  148. + result.setExpirationDate(expirationDate);
  149. + }
  150. + result.setHttpOnly(httpOnly);
  151. + result.setSecure(secure);
  152. + return result;
  153. +}
  154. +
  155. +WebKit2SharedCookieJar* sharedCookieJar()
  156. +{
  157. + return WebKit2SharedCookieJar::shared();
  158. }
  159.  
  160. +WebKit2SharedCookieJar* WebKit2SharedCookieJar::shared()
  161. +{
  162. + if (!webKit2SharedCookieJar)
  163. + webKit2SharedCookieJar = new WebKit2SharedCookieJar();
  164. + return webKit2SharedCookieJar;
  165. +}
  166. +
  167. +void WebKit2SharedCookieJar::destroy()
  168. +{
  169. + delete webKit2SharedCookieJar;
  170. + webKit2SharedCookieJar = 0;
  171. +}
  172. +
  173. +void WebKit2SharedCookieJar::getHostnamesWithCookies(HashSet<String>& hostnames)
  174. +{
  175. + QList<QNetworkCookie> cookies = allCookies();
  176. + foreach (QNetworkCookie networkCookie, cookies)
  177. + hostnames.add(networkCookie.domain());
  178. +}
  179. +
  180. +void WebKit2SharedCookieJar::deleteCookiesForHostname(const QString& hostname)
  181. +{
  182. + QList<QNetworkCookie> cookies = allCookies();
  183. + QList<QNetworkCookie>::Iterator it = cookies.begin();
  184. + QList<QNetworkCookie>::Iterator end = cookies.end();
  185. + const QLatin1String deletionQuery("DELETE FROM cookies WHERE domain=:domainvalue");
  186. + QSqlQuery sqlQuery(m_database);
  187. + sqlQuery.prepare(deletionQuery);
  188. + sqlQuery.bindValue(QLatin1String(":domainvalue"), hostname);
  189. + sqlQuery.exec();
  190. + while (it != end) {
  191. + if (it->domain() == hostname)
  192. + it = cookies.erase(it);
  193. + else
  194. + it++;
  195. + }
  196. + setAllCookies(cookies);
  197. +}
  198. +
  199. +void WebKit2SharedCookieJar::deleteAllCookies()
  200. +{
  201. + QSqlQuery sqlQuery(m_database);
  202. + const QLatin1String deletionQuery("DELETE * FROM cookies");
  203. + sqlQuery.prepare(deletionQuery);
  204. + sqlQuery.exec();
  205. + setAllCookies(QList<QNetworkCookie>());
  206. +}
  207. +
  208. +WebKit2SharedCookieJar::WebKit2SharedCookieJar()
  209. +{
  210. + m_database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
  211. +}
  212. +
  213. +WebKit2SharedCookieJar::~WebKit2SharedCookieJar()
  214. +{
  215. +}
  216. +
  217. +bool WebKit2SharedCookieJar::setCookiesFromUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url)
  218. +{
  219. + bool status = QNetworkCookieJar::setCookiesFromUrl(cookieList, url);
  220. + QSqlQuery sqlQuery(m_database);
  221. + // Delete old cookies for this domain.
  222. + sqlQuery.prepare(QLatin1String("DELETE FROM cookies WHERE domain=:domainvalue"));
  223. + sqlQuery.bindValue(QLatin1String(":domainvalue"), url.host());
  224. + sqlQuery.exec();
  225. +
  226. + sqlQuery.prepare(QLatin1String("INSERT INTO cookies (cookie, domain) VALUES (:cookievalue, :domainvalue)"));
  227. + foreach (const QNetworkCookie &cookie, cookiesForUrl(url)) {
  228. + if (!cookie.isSessionCookie()) {
  229. + sqlQuery.bindValue(QLatin1String(":cookievalue"), cookie.toRawForm());
  230. + sqlQuery.bindValue(QLatin1String(":domainvalue"), url.host());
  231. + sqlQuery.exec();
  232. + }
  233. + }
  234. + return status;
  235. +}
  236. +
  237. +void WebKit2SharedCookieJar::ensureDatabaseTable()
  238. +{
  239. + if (!m_database.open()) {
  240. + qWarning("Can't open cookie database");
  241. + return;
  242. + }
  243. +
  244. + const QLatin1String creationQuery("CREATE TABLE IF NOT EXISTS cookies (id INTEGER PRIMARY KEY AUTOINCREMENT,"
  245. + "cookie BLOB, domain VARCHAR);");
  246. + QSqlQuery sqlQuery(creationQuery);
  247. + sqlQuery.exec();
  248. +}
  249. +
  250. +void WebKit2SharedCookieJar::setStoragePath(const String& path)
  251. +{
  252. + m_path = path;
  253. + QDir().mkpath(m_path + QLatin1String(".QtWebKit/"));
  254. + const QString dataBaseName = m_path + QLatin1String(".QtWebKit/cookies.db");
  255. + m_database.setDatabaseName(dataBaseName);
  256. + ensureDatabaseTable();
  257. + loadCookies();
  258. +}
  259. +
  260. +void WebKit2SharedCookieJar::loadCookies()
  261. +{
  262. + QList<QNetworkCookie> cookies;
  263. + QSqlQuery sqlQuery(m_database);
  264. + sqlQuery.prepare(QLatin1String("SELECT cookie FROM cookies"));
  265. + sqlQuery.exec();
  266. + while (sqlQuery.next())
  267. + cookies.append(QNetworkCookie::parseCookies(sqlQuery.value(0).toByteArray()));
  268. + setAllCookies(cookies);
  269. +}
  270. +
  271. +#include "moc_CookieJarQt.cpp"
  272. +
  273. }
  274.  
  275. // vim: ts=4 sw=4 et
  276. diff --git a/Source/WebCore/platform/qt/CookieJarQt.h b/Source/WebCore/platform/qt/CookieJarQt.h
  277. new file mode 100644
  278. index 0000000..1b474dc
  279. --- /dev/null
  280. +++ b/Source/WebCore/platform/qt/CookieJarQt.h
  281. @@ -0,0 +1,61 @@
  282. +/*
  283. + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  284. + *
  285. + * This library is free software; you can redistribute it and/or
  286. + * modify it under the terms of the GNU Library General Public
  287. + * License as published by the Free Software Foundation; either
  288. + * version 2 of the License, or (at your option) any later version.
  289. + *
  290. + * This library is distributed in the hope that it will be useful,
  291. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  292. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  293. + * Library General Public License for more details.
  294. + *
  295. + * You should have received a copy of the GNU Library General Public License
  296. + * along with this library; see the file COPYING.LIB. If not, write to
  297. + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  298. + * Boston, MA 02110-1301, USA.
  299. + *
  300. + */
  301. +
  302. +#ifndef CookieJarQt_h
  303. +#define CookieJarQt_h
  304. +
  305. +#include <QtCore/QFile>
  306. +#include <QtCore/QObject>
  307. +#include <QtCore/QTimer>
  308. +#include <QtCore/QTimerEvent>
  309. +#include <QtNetwork/QNetworkCookieJar>
  310. +#include <QtSql/QSqlDatabase>
  311. +
  312. +#include <wtf/HashSet.h>
  313. +#include <wtf/text/WTFString.h>
  314. +
  315. +namespace WebCore {
  316. +
  317. +class WebKit2SharedCookieJar : public QNetworkCookieJar {
  318. + Q_OBJECT
  319. +public:
  320. + static WebKit2SharedCookieJar* shared();
  321. + void destroy();
  322. +
  323. + void getHostnamesWithCookies(HashSet<String>& hostnames);
  324. + void deleteCookiesForHostname(const QString& hostname);
  325. + void deleteAllCookies();
  326. + void setStoragePath(const String&);
  327. + bool setCookiesFromUrl(const QList<QNetworkCookie>&, const QUrl&);
  328. + void loadCookies();
  329. +
  330. +private:
  331. + WebKit2SharedCookieJar();
  332. + ~WebKit2SharedCookieJar();
  333. + void ensureDatabaseTable();
  334. +
  335. + QSqlDatabase m_database;
  336. + QString m_path;
  337. +};
  338. +
  339. +WebKit2SharedCookieJar* sharedCookieJar();
  340. +}
  341. +
  342. +#endif
  343. diff --git a/Source/WebKit2/Shared/WebProcessCreationParameters.cpp b/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
  344. index de52716..5d2374b 100644
  345. --- a/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
  346. +++ b/Source/WebKit2/Shared/WebProcessCreationParameters.cpp
  347. @@ -53,6 +53,9 @@ void WebProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) con
  348. encoder->encode(applicationCacheDirectory);
  349. encoder->encode(databaseDirectory);
  350. encoder->encode(localStorageDirectory);
  351. +#if PLATFORM(QT)
  352. + encoder->encode(cookieStorageDirectory);
  353. +#endif
  354. encoder->encode(urlSchemesRegistererdAsEmptyDocument);
  355. encoder->encode(urlSchemesRegisteredAsSecure);
  356. encoder->encode(urlSchemesForWhichDomainRelaxationIsForbidden);
  357. @@ -105,6 +108,10 @@ bool WebProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, Web
  358. return false;
  359. if (!decoder->decode(parameters.localStorageDirectory))
  360. return false;
  361. +#if PLATFORM(QT)
  362. + if (!decoder->decode(parameters.cookieStorageDirectory))
  363. + return false;
  364. +#endif
  365. if (!decoder->decode(parameters.urlSchemesRegistererdAsEmptyDocument))
  366. return false;
  367. if (!decoder->decode(parameters.urlSchemesRegisteredAsSecure))
  368. diff --git a/Source/WebKit2/Shared/WebProcessCreationParameters.h b/Source/WebKit2/Shared/WebProcessCreationParameters.h
  369. index 0396cfb..16ac6b2 100644
  370. --- a/Source/WebKit2/Shared/WebProcessCreationParameters.h
  371. +++ b/Source/WebKit2/Shared/WebProcessCreationParameters.h
  372. @@ -56,6 +56,9 @@ struct WebProcessCreationParameters {
  373. String applicationCacheDirectory;
  374. String databaseDirectory;
  375. String localStorageDirectory;
  376. +#if PLATFORM(QT)
  377. + String cookieStorageDirectory;
  378. +#endif
  379. Vector<String> urlSchemesRegistererdAsEmptyDocument;
  380. Vector<String> urlSchemesRegisteredAsSecure;
  381. Vector<String> urlSchemesForWhichDomainRelaxationIsForbidden;
  382. diff --git a/Source/WebKit2/UIProcess/qt/WebContextQt.cpp b/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
  383. index b46587e..5c6bdad 100644
  384. --- a/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
  385. +++ b/Source/WebKit2/UIProcess/qt/WebContextQt.cpp
  386. @@ -29,6 +29,7 @@
  387.  
  388. #include "ApplicationCacheStorage.h"
  389. #include "WebProcessCreationParameters.h"
  390. +#include <QDesktopServices>
  391. #include <QProcess>
  392.  
  393. namespace WebKit {
  394. @@ -42,9 +43,10 @@ String WebContext::applicationCacheDirectory()
  395. #endif
  396. }
  397.  
  398. -void WebContext::platformInitializeWebProcess(WebProcessCreationParameters&)
  399. +void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
  400. {
  401. qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
  402. + parameters.cookieStorageDirectory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
  403. }
  404.  
  405. void WebContext::platformInvalidateContext()
  406. diff --git a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
  407. index 919044e..917794e 100644
  408. --- a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
  409. +++ b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp
  410. @@ -29,6 +29,8 @@
  411. #include "WebProcessCreationParameters.h"
  412. #include <WebCore/RuntimeEnabledFeatures.h>
  413. #include <QNetworkAccessManager>
  414. +#include <QNetworkCookieJar>
  415. +#include <WebCore/CookieJarQt.h>
  416.  
  417. namespace WebKit {
  418.  
  419. @@ -44,6 +46,10 @@ void WebProcess::platformClearResourceCaches(ResourceCachesToClear)
  420. void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder* arguments)
  421. {
  422. m_networkAccessManager = new QNetworkAccessManager;
  423. + WebCore::WebKit2SharedCookieJar* jar = WebCore::sharedCookieJar();
  424. + jar->setStoragePath(parameters.cookieStorageDirectory);
  425. + m_networkAccessManager->setCookieJar(jar);
  426. + jar->setParent(0);
  427.  
  428. // Disable runtime enabled features that have no WebKit2 implementation yet.
  429. #if ENABLE(DEVICE_ORIENTATION)
  430. @@ -57,6 +63,7 @@ void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters
  431.  
  432. void WebProcess::platformTerminate()
  433. {
  434. + WebCore::sharedCookieJar()->destroy();
  435. delete m_networkAccessManager;
  436. m_networkAccessManager = 0;
  437. }
Add Comment
Please, Sign In to add comment