diff options
author | Jonathan Bauer | 2012-05-08 18:33:51 +0200 |
---|---|---|
committer | Jonathan Bauer | 2012-05-08 18:33:51 +0200 |
commit | cac39bd88a396b885f59bc23506ba1a8b2bfca5e (patch) | |
tree | 7524575a1066f528223a9ed8988031dc11c2ce9c /src/fbgui | |
parent | foo (diff) | |
download | fbgui-cac39bd88a396b885f59bc23506ba1a8b2bfca5e.tar.gz fbgui-cac39bd88a396b885f59bc23506ba1a8b2bfca5e.tar.xz fbgui-cac39bd88a396b885f59bc23506ba1a8b2bfca5e.zip |
pbs2 clear cookies extension (tofix: multiple loaded URLs messages)
Diffstat (limited to 'src/fbgui')
-rw-r--r-- | src/fbgui/fbgui.cpp | 81 | ||||
-rw-r--r-- | src/fbgui/fbgui.h | 5 | ||||
-rw-r--r-- | src/fbgui/javascriptinterface.cpp | 10 | ||||
-rw-r--r-- | src/fbgui/javascriptinterface.h | 8 |
4 files changed, 102 insertions, 2 deletions
diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index 48e776b..c4f5f22 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -49,6 +49,12 @@ void fbgui::init() { QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); QObject::connect(jsi, SIGNAL(shutDownClient()), this, SLOT(shutdownSystem())); + QObject::connect(jsi, SIGNAL(deleteCookies()), this, + SLOT(clearAllCookies())); + QObject::connect(jsi, SIGNAL(showCookies()), this, + SLOT(printCookies())); + QObject::connect(jsi, SIGNAL(showHistory()), this, + SLOT(printHistory())); QObject::connect(_webView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM())); @@ -124,7 +130,6 @@ void fbgui::loadURL() { QObject::connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadURLDone(bool))); _webView->load(req, QNetworkAccessManager::PostOperation, postData); - } // TODO: error page if no host. } @@ -140,6 +145,80 @@ void fbgui::loadURLDone(bool success) { LOG4CXX_DEBUG(coreLogger, "Loaded URL: " << _webView->url().toString()); } } +//------------------------------------------------------------------------------------------- +/** + * This method clears all cookies aside from the ones sent by baseURL. + * + */ + +void fbgui::clearAllCookies() { + + LOG4CXX_DEBUG(coreLogger, "Clearing cookies..."); + + // persist pbs cookies and delete the rest. + QUrl currentURL(_webView->page()->mainFrame()->url()); + QNetworkCookieJar* cookieJar = new QNetworkCookieJar(); + QList<QNetworkCookie> cookieList = _webView->page()->networkAccessManager()->cookieJar()->cookiesForUrl(currentURL); + _webView->page()->networkAccessManager()->setCookieJar(cookieJar); + + // restart the session with pbs + loadURL(); +} + +void fbgui::printCookies() { + + QList<QNetworkCookie> cookieList = _webView->page()->networkAccessManager()->cookieJar()->cookiesForUrl(_webView->page()->mainFrame()->url()); + + if (cookieList.isEmpty()) { + LOG4CXX_DEBUG(coreLogger, "No cookies saved!"); + } + else { + QList<QNetworkCookie>::iterator i; + for (i = cookieList.begin(); i != cookieList.end(); ++i) { + if (i->domain() == baseURL.host() || i->domain() == "." + baseURL.host()) { + LOG4CXX_DEBUG(coreLogger, "Keeping cookie from domain '" << i->domain() << "': " << i->toRawForm()); + } + else { + LOG4CXX_DEBUG(coreLogger, "Deleting cookie from domain '" << i->domain() << "': " << i->toRawForm()); + } + } + } + +} +void fbgui::printHistory() { + LOG4CXX_DEBUG(coreLogger, "--------------------------------------------------"); + QList<QUrl> urls; + QList<QWebHistoryItem> history = _webView->history()->backItems(10); + QList<QWebHistoryItem>::iterator n; + for (n = history.begin(); n != history.end(); ++n) { + LOG4CXX_DEBUG(coreLogger, "History item: " << n->url().toString()); + if (!(urls.contains(n->url()))) { + urls.append(n->url()); + LOG4CXX_DEBUG(coreLogger, "Appended: " << n->url().toString()); + } + } + + QList<QUrl>::iterator u; + for (u = urls.begin(); u != urls.end(); ++u) { + LOG4CXX_DEBUG(coreLogger, "Cookie from URL " << u->toString()); + QList<QNetworkCookie> cookieList = _webView->page()->networkAccessManager()->cookieJar()->cookiesForUrl(*u); + if (cookieList.isEmpty()) { + LOG4CXX_DEBUG(coreLogger, "No cookies saved!"); + } + else { + QList<QNetworkCookie>::iterator i; + for (i = cookieList.begin(); i != cookieList.end(); ++i) { + if (i->domain() == baseURL.host()) { + LOG4CXX_DEBUG(coreLogger, "Keeping cookie from domain '" << i->domain() << "': " << i->toRawForm()); + } + else { + LOG4CXX_DEBUG(coreLogger, "Deleting cookie from domain '" << i->domain() << "': " << i->toRawForm()); + } + } + } + } + LOG4CXX_DEBUG(coreLogger, "--------------------------------------------------"); +} //------------------------------------------------------------------------------------------- /** diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h index c300387..3eb4bcd 100644 --- a/src/fbgui/fbgui.h +++ b/src/fbgui/fbgui.h @@ -45,9 +45,12 @@ private: // QNetworkRequest for the Network Request QNetworkRequest* _qnr; + private slots: void loadURLDone(bool success); - + void clearAllCookies(); + void printCookies(); + void printHistory(); void loadSystem(); // prepares kexec by loading downloaded initramfs, kernel into kexec void prepareKexec(); diff --git a/src/fbgui/javascriptinterface.cpp b/src/fbgui/javascriptinterface.cpp index 8022797..c730dfb 100644 --- a/src/fbgui/javascriptinterface.cpp +++ b/src/fbgui/javascriptinterface.cpp @@ -80,6 +80,16 @@ void JavascriptInterface::loadJQuery() { } } +void JavascriptInterface::clearCookies() { + emit deleteCookies(); +} +void JavascriptInterface::dumpCookies() { + emit showCookies(); +} +void JavascriptInterface::dumpHistory() { + emit showHistory(); +} + //------------------------------------------------------------------------------------------------------- /** * This method quits the whole program. diff --git a/src/fbgui/javascriptinterface.h b/src/fbgui/javascriptinterface.h index 2b3c83f..e2885ce 100644 --- a/src/fbgui/javascriptinterface.h +++ b/src/fbgui/javascriptinterface.h @@ -34,6 +34,7 @@ protected: // loads jQuery code void loadJQuery(); + signals: // quit the application void quitFbgui(); @@ -41,11 +42,18 @@ signals: void shutDownClient(); // reboot the system. connected to fbgui::performReboot() void rebootClient(); + void deleteCookies(); + void showCookies(); + void showHistory(); public slots: // make sure the interface stays attached on webpage reload void attachToDOM(); + void clearCookies(); + void dumpCookies(); + void dumpHistory(); + void quit(); void shutDown(); void reboot(); |