Commit e3b8ece1 authored by Andrea Diamantini's avatar Andrea Diamantini
Browse files

"Workaround" cookie management in private browsing mode

From the note in webpage file:
I'm sorry I really cannot let KIO work as needed in private browsing
mode. The problem is basically cookie related. This way we lose some
features in private browsing mode, but we ensure PRIVACY!

This change cannot be reverted until a proper fix for KIO
(or the right workaround for rekonq) will be found.

BUG: 303552
parent 12b3217f
......@@ -217,10 +217,7 @@ WebWindow *TabWindow::webWindow(int index) const
WebWindow *TabWindow::prepareNewTab(WebPage *page)
{
WebWindow *tab = new WebWindow(this, page);
if (_isPrivateBrowsing)
tab->setPrivateBrowsing(true);
WebWindow *tab = new WebWindow(this, _isPrivateBrowsing, page);
connect(tab, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString)));
......
......@@ -124,7 +124,7 @@ static void extractMimeType(const QNetworkReply* reply, QString& mimeType)
// ---------------------------------------------------------------------------------
WebPage::WebPage(QWidget *parent)
WebPage::WebPage(QWidget *parent, bool isPrivateBrowsing)
: KWebPage(parent, KWalletIntegration)
, _networkAnalyzer(false)
, _isOnRekonqPage(false)
......@@ -133,26 +133,44 @@ WebPage::WebPage(QWidget *parent)
setForwardUnsupportedContent(true);
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
// rekonq Network Manager
NetworkAccessManager *manager = new NetworkAccessManager(this);
if (isPrivateBrowsing)
{
// NOTE:
// I'm sorry I really cannot let KIO work as needed in private browsing mode.
// The problem is basically cookie related. This way we lose some features in private
// browsing mode, but we ensure PRIVACY! This change cannot be reverted until a proper
// fix for KIO (or the right workaround for rekonq) will be found.
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
setNetworkAccessManager(manager);
// ----- last stuffs
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*)));
settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
}
else
{
// rekonq Network Manager
NetworkAccessManager *manager = new NetworkAccessManager(this);
// set network reply object to emit readyRead when it receives meta data
manager->setEmitReadyReadOnMetaDataChange(true);
// set network reply object to emit readyRead when it receives meta data
manager->setEmitReadyReadOnMetaDataChange(true);
// disable QtWebKit cache to just use KIO one..
manager->setCache(0);
// disable QtWebKit cache to just use KIO one..
manager->setCache(0);
setNetworkAccessManager(manager);
setNetworkAccessManager(manager);
// activate ssl warnings
setSessionMetaData(QL1S("ssl_activate_warnings"), QL1S("TRUE"));
// activate ssl warnings
setSessionMetaData(QL1S("ssl_activate_warnings"), QL1S("TRUE"));
// ----- last stuffs
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*)));
}
// ----- Web Plugin Factory
setPluginFactory(new WebPluginFactory(this));
// ----- last stuffs
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*)));
connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequest(QNetworkRequest)));
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
......@@ -177,10 +195,13 @@ WebPage::~WebPage()
void WebPage::setWindow(QWidget *w)
{
// set cookieJar window..
NetworkAccessManager *manager = qobject_cast<NetworkAccessManager *>(networkAccessManager());
manager->setWindow(w);
if (!settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
{
// set cookieJar window..
NetworkAccessManager *manager = qobject_cast<NetworkAccessManager *>(networkAccessManager());
manager->setWindow(w);
}
_protHandler.setWindow(w);
}
......@@ -269,56 +290,32 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r
}
}
// Get the SSL information sent, if any...
KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager());
KIO::MetaData metaData = manager->requestMetaData();
if (metaData.contains(QL1S("ssl_in_use")))
{
WebSslInfo info;
info.restoreFrom(metaData.toVariant(), request.url());
info.setUrl(request.url());
_sslInfo = info;
}
if (isMainFrameRequest)
// Make sure nothing is cached when private browsing mode is enabled...
if (!settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
{
setRequestMetaData(QL1S("main_frame_request"), QL1S("TRUE"));
if (_sslInfo.isValid() && !domainSchemeMatch(request.url(), _sslInfo.url()))
// Get the SSL information sent, if any...
KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager());
KIO::MetaData metaData = manager->requestMetaData();
if (metaData.contains(QL1S("ssl_in_use")))
{
_sslInfo = WebSslInfo();
WebSslInfo info;
info.restoreFrom(metaData.toVariant(), request.url());
info.setUrl(request.url());
_sslInfo = info;
}
}
else
{
setRequestMetaData(QL1S("main_frame_request"), QL1S("FALSE"));
}
// Make sure nothing is cached when private browsing mode is enabled...
if (settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
{
if (manager)
if (isMainFrameRequest)
{
KIO::Integration::CookieJar *cookieJar = manager ? qobject_cast<KIO::Integration::CookieJar*>(manager->cookieJar()) : 0;
if (cookieJar)
setRequestMetaData(QL1S("main_frame_request"), QL1S("TRUE"));
if (_sslInfo.isValid() && !domainSchemeMatch(request.url(), _sslInfo.url()))
{
cookieJar->setDisableCookieStorage(true);
kDebug() << "COOKIE DISABLED -------------------------------------------------------------";
_sslInfo = WebSslInfo();
}
}
setSessionMetaData(QL1S("no-cache"), QL1S("true"));
}
else
{
if (manager)
else
{
KIO::Integration::CookieJar *cookieJar = manager ? qobject_cast<KIO::Integration::CookieJar*>(manager->cookieJar()) : 0;
if (cookieJar)
{
cookieJar->setDisableCookieStorage(false);
}
setRequestMetaData(QL1S("main_frame_request"), QL1S("FALSE"));
}
removeSessionMetaData(QL1S("no-cache"));
}
return KWebPage::acceptNavigationRequest(frame, request, type);
......
......@@ -49,7 +49,7 @@ class REKONQ_TESTS_EXPORT WebPage : public KWebPage
Q_OBJECT
public:
explicit WebPage(QWidget *parent = 0);
explicit WebPage(QWidget *parent = 0, bool isPrivateBrowsing = false);
~WebPage();
void setWindow(QWidget *);
......
......@@ -67,12 +67,13 @@
#include <QWebSettings>
WebTab::WebTab(QWidget *parent)
WebTab::WebTab(QWidget *parent, bool isPrivateBrowsing)
: QWidget(parent)
, m_webView(0)
, m_progress(0)
, m_part(0)
, m_zoomFactor(10)
, m_isPrivateBrowsing(isPrivateBrowsing)
, m_splitter(new QSplitter(this))
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......@@ -136,7 +137,7 @@ WebView *WebTab::view()
{
if (!m_webView)
{
m_webView = new WebView(this);
m_webView = new WebView(this, m_isPrivateBrowsing);
}
return m_webView;
}
......
......@@ -58,7 +58,7 @@ class REKONQ_TESTS_EXPORT WebTab : public QWidget
Q_OBJECT
public:
explicit WebTab(QWidget *parent = 0);
explicit WebTab(QWidget *parent = 0, bool isPrivateBrowsing = false);
~WebTab();
WebView *view();
......@@ -127,6 +127,8 @@ private:
int m_zoomFactor;
bool m_isPrivateBrowsing;
QSplitter *m_splitter;
};
......
......@@ -86,7 +86,7 @@ static QVariant execJScript(QWebHitTestResult result, const QString& script)
// --------------------------------------------------------------------------------------------------
WebView::WebView(QWidget* parent)
WebView::WebView(QWidget* parent, bool isPrivateBrowsing)
: KWebView(parent, false)
, m_autoScrollTimer(new QTimer(this))
, m_verticalAutoScrollSpeed(0)
......@@ -100,6 +100,7 @@ WebView::WebView(QWidget* parent)
, m_accessKeysPressed(false)
, m_accessKeysActive(false)
, m_parentTab(qobject_cast<WebTab *>(parent))
, m_isPrivateBrowsing(isPrivateBrowsing)
{
// loadUrl signal
connect(this, SIGNAL(loadUrl(KUrl, Rekonq::OpenType)), rApp, SLOT(loadUrl(KUrl, Rekonq::OpenType)));
......@@ -153,7 +154,7 @@ WebPage *WebView::page()
WebPage *p = qobject_cast<WebPage *>(KWebView::page());
if (!p)
{
p = new WebPage(this);
p = new WebPage(this, m_isPrivateBrowsing);
setPage(p);
}
return p;
......
......@@ -63,7 +63,7 @@ public:
TextSelection = 0x00000100
};
explicit WebView(QWidget *parent);
explicit WebView(QWidget *parent, bool isPrivateBrowsing);
~WebView();
WebPage *page();
......@@ -170,6 +170,8 @@ private:
bool m_accessKeysActive;
WebTab *m_parentTab;
bool m_isPrivateBrowsing;
};
#endif
......@@ -70,9 +70,9 @@
#include <QVBoxLayout>
WebWindow::WebWindow(QWidget *parent, WebPage *pg)
WebWindow::WebWindow(QWidget *parent, bool isPrivateBrowsing, WebPage *pg)
: QWidget(parent)
, _tab(new WebTab(this))
, _tab(new WebTab(this, isPrivateBrowsing))
, _bar(new UrlBar(_tab))
, _mainToolBar(0)
, m_findBar(new FindBar(this))
......@@ -81,7 +81,6 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg)
, m_popup(new QLabel(this))
, m_hidePopupTimer(new QTimer(this))
, _ac(new KActionCollection(this))
, _isPrivateBrowsing(false)
{
if (pg)
{
......@@ -897,19 +896,6 @@ void WebWindow::toggleBookmarksToolbar(bool b)
}
bool WebWindow::isPrivateBrowsing()
{
return _isPrivateBrowsing;
}
void WebWindow::setPrivateBrowsing(bool on)
{
_tab->page()->settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, on);
_isPrivateBrowsing = on;
}
void WebWindow::showCrashMessageBar()
{
_tab->showCrashMessageBar();
......
......@@ -62,7 +62,7 @@ class WebWindow : public QWidget
Q_OBJECT
public:
WebWindow(QWidget *parent = 0, WebPage *pg = 0);
WebWindow(QWidget *parent = 0, bool isPrivateBrowsing = false, WebPage *pg = 0);
~WebWindow();
void load(const QUrl &);
......@@ -82,8 +82,6 @@ public:
virtual KActionCollection *actionCollection() const;
QAction *actionByName(const QString &name);
bool isPrivateBrowsing();
void checkFocus();
private:
......@@ -92,7 +90,6 @@ private:
public Q_SLOTS:
void setWidgetsHidden(bool hide);
void setPrivateBrowsing(bool);
private Q_SLOTS:
void webLoadProgress(int);
......@@ -177,8 +174,6 @@ private:
QTimer *m_hidePopupTimer;
KActionCollection *_ac;
bool _isPrivateBrowsing;
};
#endif // WEB_WINDOW
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment