Changeset 231859 in webkit
- Timestamp:
- May 16, 2018 11:54:39 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r231852 r231859 1 2018-05-16 Daniel Bates <dabates@apple.com> 2 3 Cleanup platform Cookie 4 https://bugs.webkit.org/show_bug.cgi?id=185654 5 6 Reviewed by Per Arne Vollan. 7 8 Remove unnecessary constructor and use =default for default constructor. 9 Simplify Cookie::decode() by having it decode directly into a stack-allocated 10 cookie. Remove some unnecessary local variables. Fix style nits. 11 12 * platform/Cookie.h: 13 (WebCore::Cookie::Cookie): 14 (WebCore::Cookie::isNull const): 15 (WebCore::Cookie::encode const): 16 (WebCore::Cookie::decode): 17 * platform/network/cf/CookieJarCFNet.cpp: 18 (WebCore::getRawCookies): 19 * platform/network/cocoa/CookieCocoa.mm: 20 (WebCore::cookieCreated): 21 (WebCore::Cookie::Cookie): 22 (WebCore::Cookie::operator== const): 23 (WebCore::Cookie::hash const): 24 * platform/network/soup/CookieJarSoup.cpp: 25 (WebCore::getRawCookies): 26 1 27 2018-05-14 Yusuke Suzuki <utatane.tea@gmail.com> 2 28 -
trunk/Source/WebCore/platform/Cookie.h
r226226 r231859 38 38 39 39 struct Cookie { 40 Cookie() { } 41 40 Cookie() = default; 42 41 Cookie(WTF::HashTableDeletedValueType) 43 42 : name(WTF::HashTableDeletedValue) 44 { }45 46 Cookie(const String& name, const String& value, const String& domain, const String& path, double created, double expires, bool httpOnly, bool secure, bool session, const String& comment, const URL& commentURL, const Vector<uint16_t> ports)47 : name(name)48 , value(value)49 , domain(domain)50 , path(path)51 , created(created)52 , expires(expires)53 , httpOnly(httpOnly)54 , secure(secure)55 , session(session)56 , comment(comment)57 , commentURL(commentURL)58 , ports(ports)59 43 { 60 44 } … … 77 61 { 78 62 return name.isNull() 79 && value.isNull()80 && domain.isNull()81 && path.isNull()82 && created == 083 && expires == 084 && !httpOnly85 && !secure86 && !session87 && comment.isNull()88 && commentURL.isNull();63 && value.isNull() 64 && domain.isNull() 65 && path.isNull() 66 && !created 67 && !expires 68 && !httpOnly 69 && !secure 70 && !session 71 && comment.isNull() 72 && commentURL.isNull(); 89 73 } 90 74 … … 120 104 void Cookie::encode(Encoder& encoder) const 121 105 { 122 encoder << name << value << domain << path << created << expires << httpOnly << secure << session << comment << commentURL << ports; 106 encoder << name; 107 encoder << value; 108 encoder << domain; 109 encoder << path; 110 encoder << created; 111 encoder << expires; 112 encoder << httpOnly; 113 encoder << secure; 114 encoder << session; 115 encoder << comment; 116 encoder << commentURL; 117 encoder << ports; 123 118 } 124 119 … … 126 121 std::optional<Cookie> Cookie::decode(Decoder& decoder) 127 122 { 128 std::optional<String> name; 129 decoder >> name; 130 if (!name) 123 Cookie cookie; 124 if (!decoder.decode(cookie.name)) 131 125 return std::nullopt; 132 133 std::optional<String> value; 134 decoder >> value; 135 if (!value) 126 if (!decoder.decode(cookie.value)) 136 127 return std::nullopt; 137 138 std::optional<String> domain; 139 decoder >> domain; 140 if (!domain) 128 if (!decoder.decode(cookie.domain)) 141 129 return std::nullopt; 142 143 std::optional<String> path; 144 decoder >> path; 145 if (!path) 130 if (!decoder.decode(cookie.path)) 146 131 return std::nullopt; 147 148 std::optional<double> created; 149 decoder >> created; 150 if (!created) 132 if (!decoder.decode(cookie.created)) 151 133 return std::nullopt; 152 153 std::optional<double> expires; 154 decoder >> expires; 155 if (!expires) 134 if (!decoder.decode(cookie.expires)) 156 135 return std::nullopt; 157 158 std::optional<bool> httpOnly; 159 decoder >> httpOnly; 160 if (!httpOnly) 136 if (!decoder.decode(cookie.httpOnly)) 161 137 return std::nullopt; 162 163 std::optional<bool> secure; 164 decoder >> secure; 165 if (!secure) 138 if (!decoder.decode(cookie.secure)) 166 139 return std::nullopt; 167 168 std::optional<bool> session; 169 decoder >> session; 170 if (!session) 140 if (!decoder.decode(cookie.session)) 171 141 return std::nullopt; 172 173 std::optional<String> comment; 174 decoder >> comment; 175 if (!comment) 142 if (!decoder.decode(cookie.comment)) 176 143 return std::nullopt; 177 178 URL commentURL; 179 if (!decoder.decode(commentURL)) 144 if (!decoder.decode(cookie.commentURL)) 180 145 return std::nullopt; 181 182 std::optional<Vector<uint16_t>> ports; 183 decoder >> ports; 184 if (!ports) 146 if (!decoder.decode(cookie.ports)) 185 147 return std::nullopt; 186 187 return {{ WTFMove(*name), WTFMove(*value), WTFMove(*domain), WTFMove(*path), WTFMove(*created), WTFMove(*expires), WTFMove(*httpOnly), WTFMove(*secure), WTFMove(*session), WTFMove(*comment), WTFMove(commentURL), WTFMove(*ports) }}; 148 return cookie; 188 149 } 189 150 -
trunk/Source/WebCore/platform/network/cf/CookieJarCFNet.cpp
r230944 r231859 258 258 259 259 for (CFIndex i = 0; i < count; i++) { 260 CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i)); 261 String name = cookieName(cookie).get(); 262 String value = cookieValue(cookie).get(); 263 String domain = cookieDomain(cookie).get(); 264 String path = cookiePath(cookie).get(); 265 266 double created = cookieCreatedTime(cookie); 267 double expires = cookieExpirationTime(cookie); 268 269 bool httpOnly = CFHTTPCookieIsHTTPOnly(cookie); 270 bool secure = CFHTTPCookieIsSecure(cookie); 271 bool session = false; // FIXME: Need API for if a cookie is a session cookie. 272 273 String comment; 274 URL commentURL; 275 Vector<uint16_t> ports; 276 277 rawCookies.uncheckedAppend(Cookie(name, value, domain, path, created, expires, httpOnly, secure, session, comment, commentURL, ports)); 260 CFHTTPCookieRef cfCookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i)); 261 Cookie cookie; 262 cookie.name = cookieName(cfCookie).get(); 263 cookie.value = cookieValue(cfCookie).get(); 264 cookie.domain = cookieDomain(cfCookie).get(); 265 cookie.path = cookiePath(cfCookie).get(); 266 cookie.created = cookieCreatedTime(cfCookie); 267 cookie.expires = cookieExpirationTime(cfCookie); 268 cookie.httpOnly = CFHTTPCookieIsHTTPOnly(cfCookie); 269 cookie.secure = CFHTTPCookieIsSecure(cfCookie); 270 cookie.session = false; // FIXME: Need API for if a cookie is a session cookie. 271 rawCookies.uncheckedAppend(WTFMove(cookie)); 278 272 } 279 273 -
trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm
r231495 r231859 1 1 /* 2 * Copyright (C) 2015 Apple, Inc. All rights reserved.2 * Copyright (C) 2015-2018 Apple, Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 69 69 return toCanonicalFormat(((NSString *)value).doubleValue); 70 70 71 return 0 .0;71 return 0; 72 72 } 73 73 74 74 Cookie::Cookie(NSHTTPCookie *cookie) 75 : Cookie(cookie.name, cookie.value, cookie.domain, cookie.path, cookieCreated(cookie), [cookie.expiresDate timeIntervalSince1970] * 1000.0, 76 cookie.HTTPOnly, cookie.secure, cookie.sessionOnly, cookie.comment, cookie.commentURL, portVectorFromList(cookie.portList)) 75 : name { cookie.name } 76 , value { cookie.value } 77 , domain { cookie.domain } 78 , path { cookie.path } 79 , created { cookieCreated(cookie) } 80 , expires { [cookie.expiresDate timeIntervalSince1970] * 1000.0 } 81 , httpOnly { static_cast<bool>(cookie.HTTPOnly) } 82 , secure { static_cast<bool>(cookie.secure) } 83 , session { static_cast<bool>(cookie.sessionOnly) } 84 , comment { cookie.comment } 85 , commentURL { cookie.commentURL } 86 , ports { portVectorFromList(cookie.portList) } 77 87 { 78 88 } … … 133 143 if (thisNull || otherNull) 134 144 return thisNull == otherNull; 135 136 NSHTTPCookie *nsCookie(*this); 137 return [nsCookie isEqual:other]; 145 return [static_cast<NSHTTPCookie *>(*this) isEqual:other]; 138 146 } 139 147 … … 142 150 ASSERT(!name.isHashTableDeletedValue()); 143 151 ASSERT(!isNull()); 144 NSHTTPCookie *nsCookie(*this); 145 return nsCookie.hash; 152 return static_cast<NSHTTPCookie *>(*this).hash; 146 153 } 147 154 -
trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp
r230944 r231859 160 160 161 161 for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) { 162 SoupCookie* cookie = static_cast<SoupCookie*>(iter->data); 163 rawCookies.append(Cookie(String::fromUTF8(cookie->name), String::fromUTF8(cookie->value), String::fromUTF8(cookie->domain), 164 String::fromUTF8(cookie->path), 0, cookie->expires ? static_cast<double>(soup_date_to_time_t(cookie->expires)) * 1000 : 0, 165 cookie->http_only, cookie->secure, !cookie->expires, String(), URL(), Vector<uint16_t>{ })); 166 soup_cookie_free(cookie); 162 SoupCookie* soupCookie = static_cast<SoupCookie*>(iter->data); 163 Cookie cookie; 164 cookie.name = String::fromUTF8(soupCookie->name); 165 cookie.value = String::fromUTF8(soupCookie->value); 166 cookie.domain = String::fromUTF8(soupCookie->domain); 167 cookie.path = String::fromUTF8(soupCookie->path); 168 cookie.created = 0; 169 cookie.expires = soupCookie->expires ? static_cast<double>(soup_date_to_time_t(soupCookie->expires)) * 1000 : 0; 170 cookie.httpOnly = soupCookie->http_only; 171 cookie.secure = soupCookie->secure; 172 cookie.session = !soupCookie->expires; 173 rawCookies.append(WTFMove(cookie)); 174 soup_cookie_free(soupCookie); 167 175 } 168 176
Note: See TracChangeset
for help on using the changeset viewer.