Commit 6d9d01c2 authored by Waldo Bastian's avatar Waldo Bastian

Accpept cookies via HTTP-EQUIV. (Fixes BR35012)

svn path=/trunk/kdelibs/; revision=127883
parent 4b5c545d
......@@ -21,9 +21,6 @@
* $Id$
*/
// --------------------------------------------------------------------------
#include <dcopclient.h>
#include <kapplication.h>
#include <kdebug.h>
#include "html_document.h"
......@@ -189,51 +186,15 @@ HTMLCollection HTMLDocument::all() const
DOMString HTMLDocument::cookie() const
{
QCString replyType;
QByteArray params, reply;
QDataStream stream(params, IO_WriteOnly);
stream << URL().string();
if (!kapp->dcopClient()->call("kcookiejar", "kcookiejar",
"findDOMCookies(QString)", params, replyType, reply)) {
// Maybe it wasn't running (e.g. we're opening local html files)
KApplication::startServiceByDesktopName( "kcookiejar");
if (!kapp->dcopClient()->call("kcookiejar", "kcookiejar",
"findDOMCookies(QString)", params, replyType, reply)) {
kdWarning(6010) << "Can't communicate with cookiejar!" << endl;
return DOMString();
}
}
QDataStream stream2(reply, IO_ReadOnly);
if(replyType != "QString") {
kdError(6010) << "DCOP function findDOMCookies(...) returns "
<< replyType << ", expected QString" << endl;
return DOMString();
}
QString result;
stream2 >> result;
return DOMString(result);
if (!impl) return DOMString();
return ((HTMLDocumentImpl *)impl)->cookie();
}
void HTMLDocument::setCookie( const DOMString & value )
{
long windowId = view()->winId();
QByteArray params;
QDataStream stream(params, IO_WriteOnly);
QString fake_header("Set-Cookie: ");
fake_header.append(value.string());
fake_header.append("\n");
stream << URL().string() << fake_header.utf8() << windowId;
if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar",
"addCookies(QString,QCString,long int)", params))
{
// Maybe it wasn't running (e.g. we're opening local html files)
KApplication::startServiceByDesktopName( "kcookiejar");
if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar",
"addCookies(QString,QCString,long int)", params))
kdWarning(6010) << "Can't communicate with cookiejar!" << endl;
}
if (impl)
((HTMLDocumentImpl *)impl)->setCookie(value);
}
void HTMLDocument::open( )
......
......@@ -40,6 +40,8 @@
#include "html_miscimpl.h"
#include "rendering/render_object.h"
#include <dcopclient.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kurl.h>
#include <kglobal.h>
......@@ -120,6 +122,57 @@ DOMString HTMLDocumentImpl::lastModified() const
return DOMString();
}
DOMString HTMLDocumentImpl::cookie() const
{
QCString replyType;
QByteArray params, reply;
QDataStream stream(params, IO_WriteOnly);
stream << URL();
if (!kapp->dcopClient()->call("kcookiejar", "kcookiejar",
"findDOMCookies(QString)", params, replyType, reply)) {
// Maybe it wasn't running (e.g. we're opening local html files)
KApplication::startServiceByDesktopName( "kcookiejar");
if (!kapp->dcopClient()->call("kcookiejar", "kcookiejar",
"findDOMCookies(QString)", params, replyType, reply)) {
kdWarning(6010) << "Can't communicate with cookiejar!" << endl;
return DOMString();
}
}
QDataStream stream2(reply, IO_ReadOnly);
if(replyType != "QString") {
kdError(6010) << "DCOP function findDOMCookies(...) returns "
<< replyType << ", expected QString" << endl;
return DOMString();
}
QString result;
stream2 >> result;
return DOMString(result);
}
void HTMLDocumentImpl::setCookie( const DOMString & value )
{
long windowId = view() ? view()->winId() : 0;
QByteArray params;
QDataStream stream(params, IO_WriteOnly);
QString fake_header("Set-Cookie: ");
fake_header.append(value.string());
fake_header.append("\n");
stream << URL() << fake_header.utf8() << windowId;
if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar",
"addCookies(QString,QCString,long int)", params))
{
// Maybe it wasn't running (e.g. we're opening local html files)
KApplication::startServiceByDesktopName( "kcookiejar");
if (!kapp->dcopClient()->send("kcookiejar", "kcookiejar",
"addCookies(QString,QCString,long int)", params))
kdWarning(6010) << "Can't communicate with cookiejar!" << endl;
}
}
HTMLElementImpl *HTMLDocumentImpl::body()
{
NodeImpl *de = documentElement();
......
......@@ -57,6 +57,8 @@ public:
DOMString domain() const;
void setDomain( const DOMString &newDomain ); // not part of the DOM
DOMString lastModified() const;
DOMString cookie() const;
void setCookie( const DOMString &);
HTMLElementImpl *body();
void setBody(HTMLElementImpl *_body);
......@@ -74,6 +76,7 @@ public:
virtual void determineParseMode( const QString &str );
virtual void close();
protected:
HTMLElementImpl *bodyElement;
......
......@@ -299,6 +299,11 @@ void HTMLMetaElementImpl::attach()
KIO::http_update_cache(url, true, 0);
}
}
else if( (strcasecmp(_equiv, "set-cookie") == 0) && !_content.isNull())
{
HTMLDocumentImpl *d = static_cast<HTMLDocumentImpl *>(ownerDocument());
d->setCookie(_content);
}
HTMLElementImpl::attach();
}
......
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