Title: [133664] trunk/Source/WebCore
Revision
133664
Author
a...@apple.com
Date
2012-11-06 13:24:37 -0800 (Tue, 06 Nov 2012)

Log Message

Some cookie code cleanup
https://bugs.webkit.org/show_bug.cgi?id=101375

Reviewed by Dan Bernstein.

* platform/CookieJar.h: Fixed style. Grouped functions by which storage they operate
on in Mac port, but didn't add explanatory comments yet, because this is different
in some ports.

* platform/mac/CookieJar.mm:
(WebCore): Removed special code for isHTTPOnly, it's present in Foundation in all
supported OS X versions.
(WebCore::filterCookies): Use -isHTTPOnly directly.
(WebCore::cookies): Get rid of a variable for URL, implicit conversion works just as well.
(WebCore::cookieRequestHeaderFieldValue): Ditto.
(WebCore::setCookies): Assert that no more than one cookie was created from one
Set-Cookie header, document.cookie can only be used to set one cookie at a time.
(WebCore::getRawCookies): Removed useless local variables.

* platform/network/CookieStorage.h: Removed an unneeded include, clarified a comment.

* platform/network/HTTPHeaderMap.h: Added a FIXME.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133663 => 133664)


--- trunk/Source/WebCore/ChangeLog	2012-11-06 21:19:59 UTC (rev 133663)
+++ trunk/Source/WebCore/ChangeLog	2012-11-06 21:24:37 UTC (rev 133664)
@@ -1,3 +1,28 @@
+2012-11-06  Alexey Proskuryakov  <a...@apple.com>
+
+        Some cookie code cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=101375
+
+        Reviewed by Dan Bernstein.
+
+        * platform/CookieJar.h: Fixed style. Grouped functions by which storage they operate
+        on in Mac port, but didn't add explanatory comments yet, because this is different
+        in some ports.
+
+        * platform/mac/CookieJar.mm:
+        (WebCore): Removed special code for isHTTPOnly, it's present in Foundation in all
+        supported OS X versions.
+        (WebCore::filterCookies): Use -isHTTPOnly directly.
+        (WebCore::cookies): Get rid of a variable for URL, implicit conversion works just as well.
+        (WebCore::cookieRequestHeaderFieldValue): Ditto.
+        (WebCore::setCookies): Assert that no more than one cookie was created from one
+        Set-Cookie header, document.cookie can only be used to set one cookie at a time.
+        (WebCore::getRawCookies): Removed useless local variables.
+
+        * platform/network/CookieStorage.h: Removed an unneeded include, clarified a comment.
+
+        * platform/network/HTTPHeaderMap.h: Added a FIXME.
+
 2012-11-06  John Griggs  <jgri...@rim.com>
 
         Implement MediaPlayerPrivate::didLoadingProgress for BlackBerry platform

Modified: trunk/Source/WebCore/platform/CookieJar.h (133663 => 133664)


--- trunk/Source/WebCore/platform/CookieJar.h	2012-11-06 21:19:59 UTC (rev 133663)
+++ trunk/Source/WebCore/platform/CookieJar.h	2012-11-06 21:24:37 UTC (rev 133664)
@@ -33,22 +33,22 @@
 
 namespace WebCore {
 
-    class Document;
-    class KURL;
+class Document;
+class KURL;
+struct Cookie;
 
-    struct Cookie;
+// These two functions implement document.cookie API, with special rules for HttpOnly cookies.
+String cookies(const Document*, const KURL&);
+void setCookies(Document*, const KURL&, const String&);
 
-    // cookies omits HttpOnly cookies.
-    String cookies(const Document*, const KURL&);
-    String cookieRequestHeaderFieldValue(const Document*, const KURL&);
-    void setCookies(Document*, const KURL&, const String&);
-    bool cookiesEnabled(const Document*);
-    bool getRawCookies(const Document*, const KURL&, Vector<Cookie>&);
-    void deleteCookie(const Document*, const KURL&, const String&);
+bool cookiesEnabled(const Document*);
+String cookieRequestHeaderFieldValue(const Document*, const KURL&);
+bool getRawCookies(const Document*, const KURL&, Vector<Cookie>&);
+void deleteCookie(const Document*, const KURL&, const String&);
 
-    void getHostnamesWithCookies(HashSet<String>& hostnames);
-    void deleteCookiesForHostname(const String& hostname);
-    void deleteAllCookies();
+void getHostnamesWithCookies(HashSet<String>& hostnames);
+void deleteCookiesForHostname(const String& hostname);
+void deleteAllCookies();
 
 }
 

Modified: trunk/Source/WebCore/platform/mac/CookieJar.mm (133663 => 133664)


--- trunk/Source/WebCore/platform/mac/CookieJar.mm	2012-11-06 21:19:59 UTC (rev 133663)
+++ trunk/Source/WebCore/platform/mac/CookieJar.mm	2012-11-06 21:24:37 UTC (rev 133664)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2006, 2008, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -33,25 +33,10 @@
 #import "CookieStorage.h"
 #import "CookieStorageCFNet.h"
 #import "Document.h"
-#import "KURL.h"
 #import "WebCoreSystemInterface.h"
-#import <wtf/RetainPtr.h>
 
-
-@interface NSHTTPCookie (WebCoreHTTPOnlyCookies)
-- (BOOL)isHTTPOnly;
-@end
-
 namespace WebCore {
 
-static bool isHTTPOnly(NSHTTPCookie *cookie)
-{
-    // Once we require a newer version of Foundation with the isHTTPOnly method,
-    // we can eliminate the instancesRespondToSelector: check.
-    static bool supportsHTTPOnlyCookies = [NSHTTPCookie instancesRespondToSelector:@selector(isHTTPOnly)];
-    return supportsHTTPOnlyCookies && [cookie isHTTPOnly];
-}
-
 static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies)
 {
     NSUInteger count = [unfilteredCookies count];
@@ -67,7 +52,7 @@
         if (![[cookie name] length])
             continue;
 
-        if (isHTTPOnly(cookie))
+        if ([cookie isHTTPOnly])
             continue;
 
         [filteredCookies.get() addObject:cookie];
@@ -80,12 +65,11 @@
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSURL *cookieURL = url;
     NSArray *cookies;
     if (RetainPtr<CFHTTPCookieStorageRef> cfCookieStorage = currentCFHTTPCookieStorage())
-        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), cookieURL);
+        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), url);
     else
-        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
 
     return [[NSHTTPCookie requestHeaderFieldsWithCookies:filterCookies(cookies).get()] objectForKey:@"Cookie"];
 
@@ -97,12 +81,11 @@
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSURL *cookieURL = url;
     NSArray *cookies;
     if (RetainPtr<CFHTTPCookieStorageRef> cfCookieStorage = currentCFHTTPCookieStorage())
-        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), cookieURL);
+        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), url);
     else
-        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
 
     return [[NSHTTPCookie requestHeaderFieldsWithCookies:cookies] objectForKey:@"Cookie"];
 
@@ -123,8 +106,9 @@
     // cookiesWithResponseHeaderFields doesn't parse cookies without a value
     String cookieString = cookieStr.contains('=') ? cookieStr : cookieStr + "=";
 
-    NSURL *cookieURL = url;    
+    NSURL *cookieURL = url;
     RetainPtr<NSArray> filteredCookies = filterCookies([NSHTTPCookie cookiesWithResponseHeaderFields:[NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"] forURL:cookieURL]);
+    ASSERT([filteredCookies.get() count] <= 1);
 
     if (RetainPtr<CFHTTPCookieStorageRef> cfCookieStorage = currentCFHTTPCookieStorage())
         wkSetHTTPCookiesForURL(cfCookieStorage.get(), filteredCookies.get(), cookieURL, document->firstPartyForCookies());
@@ -155,26 +139,19 @@
     rawCookies.clear();
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSURL *cookieURL = url;
     NSArray *cookies;
     if (RetainPtr<CFHTTPCookieStorageRef> cfCookieStorage = currentCFHTTPCookieStorage())
-        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), cookieURL);
+        cookies = wkHTTPCookiesForURL(cfCookieStorage.get(), url);
     else
-        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
 
     NSUInteger count = [cookies count];
     rawCookies.reserveCapacity(count);
     for (NSUInteger i = 0; i < count; ++i) {
         NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
-        NSString *name = [cookie name];
-        NSString *value = [cookie value];
-        NSString *domain = [cookie domain];
-        NSString *path = [cookie path];
         NSTimeInterval expires = [[cookie expiresDate] timeIntervalSince1970] * 1000;
-        bool httpOnly = [cookie isHTTPOnly];
-        bool secure = [cookie isSecure];
-        bool session = [cookie isSessionOnly];
-        rawCookies.uncheckedAppend(Cookie(name, value, domain, path, expires, httpOnly, secure, session));
+        rawCookies.uncheckedAppend(Cookie([cookie name], [cookie value], [cookie domain], [cookie path], expires,
+            [cookie isHTTPOnly], [cookie isSecure], [cookie isSessionOnly]));
     }
 
     END_BLOCK_OBJC_EXCEPTIONS;

Modified: trunk/Source/WebCore/platform/network/CookieStorage.h (133663 => 133664)


--- trunk/Source/WebCore/platform/network/CookieStorage.h	2012-11-06 21:19:59 UTC (rev 133663)
+++ trunk/Source/WebCore/platform/network/CookieStorage.h	2012-11-06 21:24:37 UTC (rev 133664)
@@ -26,11 +26,9 @@
 #ifndef CookieStorage_h
 #define CookieStorage_h
 
-#include <wtf/RetainPtr.h>
-
 namespace WebCore {
 
-// These are always observing the main cookie storage, even when in private browsing mode.
+// These are always observing the shared cookie storage, even when in private browsing mode.
 void startObservingCookieChanges();
 void stopObservingCookieChanges();
 

Modified: trunk/Source/WebCore/platform/network/HTTPHeaderMap.h (133663 => 133664)


--- trunk/Source/WebCore/platform/network/HTTPHeaderMap.h	2012-11-06 21:19:59 UTC (rev 133663)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderMap.h	2012-11-06 21:24:37 UTC (rev 133664)
@@ -39,6 +39,7 @@
 
     typedef Vector<std::pair<String, String> > CrossThreadHTTPHeaderMapData;
 
+    // FIXME: Not every header fits into a map. Notably, multiple Set-Cookie header fields are needed to set multiple cookies.
     class HTTPHeaderMap : public HashMap<AtomicString, String, CaseFoldingHash> {
     public:
         HTTPHeaderMap();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to