Diff
Modified: trunk/Source/WebCore/ChangeLog (213777 => 213778)
--- trunk/Source/WebCore/ChangeLog 2017-03-13 01:37:36 UTC (rev 213777)
+++ trunk/Source/WebCore/ChangeLog 2017-03-13 01:54:16 UTC (rev 213778)
@@ -1,3 +1,26 @@
+2017-03-12 Brady Eidson <[email protected]>
+
+ Add full NSHTTPCookie fidelity to WebCore::Cookie.
+ https://bugs.webkit.org/show_bug.cgi?id=169514
+
+ Reviewed by Dean Jackson.
+
+ No new tests (Refactor, no testable behavior change for now).
+
+ * platform/Cookie.h:
+ (WebCore::Cookie::Cookie):
+ (WebCore::Cookie::encode):
+ (WebCore::Cookie::decode):
+
+ * platform/network/cocoa/CookieCocoa.mm:
+ (WebCore::portVectorFromList):
+ (WebCore::portStringFromVector):
+ (WebCore::Cookie::Cookie):
+ (WebCore::Cookie::operator NSHTTPCookie *):
+
+ * platform/network/mac/CookieJarMac.mm:
+ (WebCore::getRawCookies):
+
2017-03-12 Said Abou-Hallawa <[email protected]>
REGRESSION (r213764): Async image decoding is disabled for animated images
Modified: trunk/Source/WebCore/platform/Cookie.h (213777 => 213778)
--- trunk/Source/WebCore/platform/Cookie.h 2017-03-13 01:37:36 UTC (rev 213777)
+++ trunk/Source/WebCore/platform/Cookie.h 2017-03-13 01:54:16 UTC (rev 213778)
@@ -23,9 +23,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef Cookie_h
-#define Cookie_h
+#pragma once
+#include "URL.h"
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
@@ -38,7 +38,7 @@
struct Cookie {
Cookie() { }
- Cookie(const String& name, const String& value, const String& domain, const String& path, double expires, bool httpOnly, bool secure, bool session)
+ Cookie(const String& name, const String& value, const String& domain, const String& path, double expires, bool httpOnly, bool secure, bool session, const String& comment, const URL& commentURL, const Vector<uint16_t> ports)
: name(name)
, value(value)
, domain(domain)
@@ -47,6 +47,9 @@
, httpOnly(httpOnly)
, secure(secure)
, session(session)
+ , comment(comment)
+ , commentURL(commentURL)
+ , ports(ports)
{
}
@@ -54,6 +57,7 @@
template<class Decoder> static bool decode(Decoder&, Cookie&);
#ifdef __OBJC__
+ WEBCORE_EXPORT Cookie(NSHTTPCookie *);
operator NSHTTPCookie *() const;
#endif
@@ -66,6 +70,10 @@
bool httpOnly;
bool secure;
bool session;
+ String comment;
+ URL commentURL;
+ Vector<uint16_t> ports;
+
};
struct CookieHash {
@@ -83,14 +91,7 @@
template<class Encoder>
void Cookie::encode(Encoder& encoder) const
{
- encoder << name;
- encoder << value;
- encoder << domain;
- encoder << path;
- encoder << expires;
- encoder << httpOnly;
- encoder << secure;
- encoder << session;
+ encoder << name << value << domain << path << expires << httpOnly << secure << session << comment << commentURL << ports;
}
template<class Decoder>
@@ -112,6 +113,12 @@
return false;
if (!decoder.decode(cookie.session))
return false;
+ if (!decoder.decode(cookie.comment))
+ return false;
+ if (!decoder.decode(cookie.commentURL))
+ return false;
+ if (!decoder.decode(cookie.ports))
+ return false;
return true;
}
@@ -124,5 +131,3 @@
typedef WebCore::CookieHash Hash;
};
}
-
-#endif
Modified: trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm (213777 => 213778)
--- trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm 2017-03-13 01:37:36 UTC (rev 213777)
+++ trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm 2017-03-13 01:54:16 UTC (rev 213778)
@@ -26,28 +26,80 @@
#import "config.h"
#import "Cookie.h"
-#import <wtf/BlockObjCExceptions.h>
+#import <wtf/text/StringBuilder.h>
namespace WebCore {
+static Vector<uint16_t> portVectorFromList(NSArray<NSNumber *> *portList)
+{
+ Vector<uint16_t> ports;
+ ports.reserveInitialCapacity(portList.count);
+
+ for (NSNumber *port : portList)
+ ports.uncheckedAppend(port.unsignedShortValue);
+
+ return ports;
+}
+
+static NSString *portStringFromVector(const Vector<uint16_t>& ports)
+{
+ if (ports.isEmpty())
+ return nil;
+
+ auto *string = [NSMutableString stringWithCapacity:ports.size() * 5];
+
+ for (size_t i = 0; i < ports.size() - 1; ++i)
+ [string appendFormat:@"%" PRIu16 ", ", ports[i]];
+
+ [string appendFormat:@"%" PRIu16, ports.last()];
+
+ return string;
+}
+
+Cookie::Cookie(NSHTTPCookie *cookie)
+ : Cookie(cookie.name, cookie.value, cookie.domain, cookie.path, [cookie.expiresDate timeIntervalSince1970] * 1000.0,
+ cookie.HTTPOnly, cookie.secure, cookie.sessionOnly, cookie.comment, cookie.commentURL, portVectorFromList(cookie.portList))
+{
+}
+
Cookie::operator NSHTTPCookie *() const
{
// FIXME: existing APIs do not provide a way to set httpOnly without parsing headers from scratch.
- BEGIN_BLOCK_OBJC_EXCEPTIONS
+ NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:11];
- return [NSHTTPCookie cookieWithProperties:@{
- NSHTTPCookieName: name,
- NSHTTPCookieValue: value,
- NSHTTPCookieDomain: domain,
- NSHTTPCookiePath: path,
- NSHTTPCookieDomain: domain,
- NSHTTPCookieSecure: @(secure),
- NSHTTPCookieDiscard: @(session),
- NSHTTPCookieExpires: [NSDate dateWithTimeIntervalSince1970:expires / 1000.0],
- }];
+ if (!comment.isNull())
+ [properties setObject:(NSString *)comment forKey:NSHTTPCookieComment];
- END_BLOCK_OBJC_EXCEPTIONS
+ if (!commentURL.isNull())
+ [properties setObject:(NSURL *)commentURL forKey:NSHTTPCookieCommentURL];
+
+ if (!domain.isNull())
+ [properties setObject:(NSString *)domain forKey:NSHTTPCookieDomain];
+
+ if (!name.isNull())
+ [properties setObject:(NSString *)name forKey:NSHTTPCookieName];
+
+ if (!path.isNull())
+ [properties setObject:(NSString *)path forKey:NSHTTPCookiePath];
+
+ if (!value.isNull())
+ [properties setObject:(NSString *)value forKey:NSHTTPCookieValue];
+
+ NSDate *expirationDate = [NSDate dateWithTimeIntervalSince1970:expires / 1000.0];
+ auto maxAge = [expirationDate timeIntervalSinceNow];
+ if (maxAge > 0)
+ [properties setObject:[NSString stringWithFormat:@"%f", maxAge] forKey:NSHTTPCookieMaximumAge];
+
+ auto* portString = portStringFromVector(ports);
+ if (portString)
+ [properties setObject:portString forKey:NSHTTPCookiePort];
+
+ [properties setObject:@(secure) forKey:NSHTTPCookieSecure];
+ [properties setObject:(session ? @"TRUE" : @"FALSE") forKey:NSHTTPCookieDiscard];
+ [properties setObject:@"1" forKey:NSHTTPCookieVersion];
+
+ return [NSHTTPCookie cookieWithProperties:properties];
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm (213777 => 213778)
--- trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm 2017-03-13 01:37:36 UTC (rev 213777)
+++ trunk/Source/WebCore/platform/network/mac/CookieJarMac.mm 2017-03-13 01:54:16 UTC (rev 213778)
@@ -228,9 +228,7 @@
rawCookies.reserveCapacity(count);
for (NSUInteger i = 0; i < count; ++i) {
NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
- NSTimeInterval expires = [[cookie expiresDate] timeIntervalSince1970] * 1000;
- rawCookies.uncheckedAppend(Cookie([cookie name], [cookie value], [cookie domain], [cookie path], expires,
- [cookie isHTTPOnly], [cookie isSecure], [cookie isSessionOnly]));
+ rawCookies.uncheckedAppend({ cookie });
}
END_BLOCK_OBJC_EXCEPTIONS;