[haiku-webkit-commits] r301 - in webkit/trunk/WebKit: . haiku/API

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Tue, 09 Mar 2010 00:35:40 +0000

Author: stippi
Date: Tue Mar  9 00:35:39 2010
New Revision: 301
URL: http://mmlr.dyndns.org/changeset/301

Log:
Some work towards a persistent cookie jar implementation. Since it will be
browser specific, there needs to be a way to influence the cookie jar behavior
from within the browser. Nothing is wired, yet.

Added:
   webkit/trunk/WebKit/haiku/API/NetworkCookie.cpp
   webkit/trunk/WebKit/haiku/API/NetworkCookie.h
   webkit/trunk/WebKit/haiku/API/NetworkCookieJar.cpp
   webkit/trunk/WebKit/haiku/API/NetworkCookieJar.h
Modified:
   webkit/trunk/WebKit/Jamfile
   webkit/trunk/WebKit/haiku/API/WebPage.cpp
   webkit/trunk/WebKit/haiku/API/WebPage.h

Modified: webkit/trunk/WebKit/Jamfile
==============================================================================
--- webkit/trunk/WebKit/Jamfile Tue Mar  9 00:34:18 2010        (r300)
+++ webkit/trunk/WebKit/Jamfile Tue Mar  9 00:35:39 2010        (r301)
@@ -65,12 +65,16 @@
 SEARCH_SOURCE += [ FDirName $(TOP) WebKit haiku WebCoreSupport ] ;
 
 SharedLibrary libwebkit.so :
+       # WebCoreSupport
        ChromeClientHaiku.cpp
        ContextMenuClientHaiku.cpp
        DragClientHaiku.cpp
        EditorClientHaiku.cpp
        FrameLoaderClientHaiku.cpp
        InspectorClientHaiku.cpp
+       # API
+       NetworkCookie.cpp
+       NetworkCookieJar.cpp
        WebDownload.cpp
        WebDownloadPrivate.cpp
        WebFrame.cpp

Added: webkit/trunk/WebKit/haiku/API/NetworkCookie.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ webkit/trunk/WebKit/haiku/API/NetworkCookie.cpp     Tue Mar  9 00:35:39 
2010        (r301)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "NetworkCookie.h"
+
+#include <Message.h>
+#include <stdio.h>
+
+BNetworkCookie::BNetworkCookie(const BString& rawValue)
+    : fExpirationDate()
+    , fRawValue()
+{
+       _ParseRawValue(rawValue);
+}
+
+BNetworkCookie::BNetworkCookie(const BMessage& archive)
+    : fExpirationDate()
+    , fRawValue()
+{
+       BString rawValue;
+       if (archive.FindString("raw value", &rawValue) == B_OK)
+               _ParseRawValue(rawValue);
+}
+
+BNetworkCookie::~BNetworkCookie()
+{
+}
+
+status_t BNetworkCookie::Archive(BMessage* into, bool deep) const
+{
+       if (!into)
+               return B_BAD_VALUE;
+
+       return into->AddString("raw value", AsRawValue().String());
+}
+
+BString BNetworkCookie::AsRawValue() const
+{
+       // TODO: Recompose the raw value, once parsing into individual fields
+       // is implemented.
+       return fRawValue;
+}
+
+const BDateTime& BNetworkCookie::ExpirationDate() const
+{
+       return fExpirationDate;
+}
+
+// #pragma mark - private
+
+void BNetworkCookie::_ParseRawValue(const BString& rawValue)
+{
+       // TODO: Parse into individual fields. Most important is the
+       // expiration date, but also stuff like Domain, for security reasons.
+       fRawValue = rawValue;
+}

Added: webkit/trunk/WebKit/haiku/API/NetworkCookie.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ webkit/trunk/WebKit/haiku/API/NetworkCookie.h       Tue Mar  9 00:35:39 
2010        (r301)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _NETWORK_COOKIE_H_
+#define _NETWORK_COOKIE_H_
+
+#include <DateTime.h>
+#include <String.h>
+
+class BMessage;
+
+
+class BNetworkCookie {
+public:
+                                                               
BNetworkCookie(const BString& rawValue);
+                                                               
BNetworkCookie(const BMessage& archive);
+       virtual                                         ~BNetworkCookie();
+
+       virtual status_t                        Archive(BMessage* into,
+                                                                       bool 
deep = true) const;
+
+                       BString                         AsRawValue() const;
+                       const BDateTime&        ExpirationDate() const;
+
+private:
+                       void                            _ParseRawValue(const 
BString& rawValue);
+
+private:
+                       BDateTime                       fExpirationDate;
+                       BString                         fRawValue;
+};
+
+
+#endif // _NETWORK_COOKIE_H_

Added: webkit/trunk/WebKit/haiku/API/NetworkCookieJar.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ webkit/trunk/WebKit/haiku/API/NetworkCookieJar.cpp  Tue Mar  9 00:35:39 
2010        (r301)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "NetworkCookieJar.h"
+
+#include "PlatformString.h"
+#include "StringHash.h"
+#include <Message.h>
+#include <wtf/HashMap.h>
+#include <stdio.h>
+
+using namespace WebCore;
+
+class BNetworkCookieJar::Private {
+public:
+       typedef HashMap<String, String> URLCookiesMap;
+       URLCookiesMap cookies;
+};
+
+BNetworkCookieJar::BNetworkCookieJar()
+       : fData(new Private())
+       , fCookiesEnabled(true)
+{
+}
+
+BNetworkCookieJar::BNetworkCookieJar(const BMessage& archive)
+       : fData(new Private())
+{
+       BMessage cookiesArchive;
+       for (int32 i = 0; archive.FindMessage("cookies", i, &cookiesArchive) == 
B_OK; i++) {
+               BString url;
+               if (cookiesArchive.FindString("url", &url) != B_OK)
+                       continue;
+               BString cookies;
+               if (cookiesArchive.FindString("cookies", &cookies) != B_OK)
+                       continue;
+               fData->cookies.set(url, cookies);
+       }
+       if (archive.FindBool("cookies enabled", &fCookiesEnabled) != B_OK)
+               fCookiesEnabled = true;
+}
+
+BNetworkCookieJar::~BNetworkCookieJar()
+{
+       delete fData;
+}
+
+status_t BNetworkCookieJar::Archive(BMessage* into, bool deep) const
+{
+       if (!into)
+               return B_BAD_VALUE;
+
+       Private::URLCookiesMap::iterator it = fData->cookies.begin();
+
+       while (it != fData->cookies.end()) {
+               BMessage cookiesArchive;
+               status_t ret = cookiesArchive.AddString("url", it.get()->first);
+               if (ret != B_OK)
+                       return ret;
+               ret = cookiesArchive.AddString("cookies", it.get()->second);
+               if (ret != B_OK)
+                       return ret;
+               ret = into->AddMessage("cookies", &cookiesArchive);
+               if (ret != B_OK)
+                       return ret;
+
+               ++it;
+       }
+
+       return into->AddBool("cookies enabled", fCookiesEnabled);
+}
+
+void BNetworkCookieJar::SetCookiesFor(const BString& url, const BString& value)
+{
+       fData->cookies.set(url, value);
+}
+
+BString BNetworkCookieJar::CookiesFor(const BString& url) const
+{
+       return fData->cookies.get(url);
+}
+
+BString BNetworkCookieJar::CookieRequestHeaderFieldValue(const BString& url) 
const
+{
+       // TODO: Return just HTMLOnly cookies here.
+       return CookiesFor(url);
+}
+
+void BNetworkCookieJar::SetCookiesEnabled(bool enabled)
+{
+       fCookiesEnabled = enabled;
+}
+
+bool BNetworkCookieJar::CookiesEnabled() const
+{
+       return fCookiesEnabled;
+}

Added: webkit/trunk/WebKit/haiku/API/NetworkCookieJar.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ webkit/trunk/WebKit/haiku/API/NetworkCookieJar.h    Tue Mar  9 00:35:39 
2010        (r301)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _NETWORK_COOKIE_H_
+#define _NETWORK_COOKIE_H_
+
+#include <String.h>
+
+class BMessage;
+
+
+class BNetworkCookieJar {
+public:
+                                                               
BNetworkCookieJar();
+                                                               
BNetworkCookieJar(const BMessage& archive);
+       virtual                                         ~BNetworkCookieJar();
+
+       virtual status_t                        Archive(BMessage* into,
+                                                                       bool 
deep = true) const;
+
+                       void                            SetCookiesFor(const 
BString& url,
+                                                                       const 
BString& value);
+                       BString                         CookiesFor(const 
BString& url) const;
+                       BString                         
CookieRequestHeaderFieldValue(
+                                                                       const 
BString& url) const;
+
+                       void                            SetCookiesEnabled(bool 
enabled);
+                       bool                            CookiesEnabled() const;
+
+private:
+                       class Private;
+
+                       Private*                        fData;
+                       bool                            fCookiesEnabled;
+};
+
+
+#endif // _NETWORK_COOKIE_H_

Modified: webkit/trunk/WebKit/haiku/API/WebPage.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.cpp   Tue Mar  9 00:34:18 2010        
(r300)
+++ webkit/trunk/WebKit/haiku/API/WebPage.cpp   Tue Mar  9 00:35:39 2010        
(r301)
@@ -164,6 +164,7 @@
     , m_mainFrame(0)
     , m_settings(0)
     , m_page(0)
+    , m_cookieJar(0)
     , m_pageVisible(true)
     , m_pageDirty(false)
     , m_toolbarsVisible(true)
@@ -232,6 +233,11 @@
     m_downloadListener = listener;
 }
 
+void BWebPage::SetCookieJar(BNetworkCookieJar* cookieJar)
+{
+    m_cookieJar = cookieJar;
+}
+
 void BWebPage::LoadURL(const char* urlString)
 {
     BMessage message(HANDLE_LOAD_URL);

Modified: webkit/trunk/WebKit/haiku/API/WebPage.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.h     Tue Mar  9 00:34:18 2010        
(r300)
+++ webkit/trunk/WebKit/haiku/API/WebPage.h     Tue Mar  9 00:35:39 2010        
(r301)
@@ -34,6 +34,7 @@
 #include <Rect.h>
 #include <String.h>
 
+class BNetworkCookieJar;
 class BRegion;
 class BView;
 class BWebDownload;
@@ -80,6 +81,7 @@
 
                        void                            SetListener(const 
BMessenger& listener);
                        void                            
SetDownloadListener(const BMessenger& listener);
+                       void                            
SetCookieJar(BNetworkCookieJar* cookieJar);
 
                        BWebFrame*                      MainFrame() const;
                        BWebSettings*           Settings() const;
@@ -204,6 +206,7 @@
        BWebFrame* m_mainFrame;
        BWebSettings* m_settings;
        WebCore::Page* m_page;
+       BNetworkCookieJar* m_cookieJar;
 
     bool m_pageVisible;
     bool m_pageDirty;

Other related posts:

  • » [haiku-webkit-commits] r301 - in webkit/trunk/WebKit: . haiku/API - webkit