62 // First attribute should be <cookiename>=<cookievalue>
63 String cookieName, cookieValue;
64 Vector<String>::iterator attribute = attributes.begin();
65 if (attribute->contains('=')) {
66 Vector<String> nameValuePair;
67 attribute->split('=', true, nameValuePair);
68 cookieName = nameValuePair[0];
69 cookieValue = nameValuePair[1];
70 } else {
71 // According to RFC6265 we should ignore the entire
72 // set-cookie string now, but other browsers appear
73 // to treat this as <cookiename>=<empty>
74 cookieName = *attribute;
75 }
76
77 int expires = 0;
78 String secure = "FALSE";
79 String path = url.baseAsString().substring(url.pathStart());
80 if (path.length() > 1 && path.endsWith('/'))
81 path.remove(path.length() - 1);
82 String domain = url.host();
83
84 // Iterate through remaining attributes
85 for (++attribute; attribute != attributes.end(); ++attribute) {
86 if (attribute->contains('=')) {
87 Vector<String> keyValuePair;
88 attribute->split('=', true, keyValuePair);
89 String key = keyValuePair[0].stripWhiteSpace().lower();
90 String val = keyValuePair[1].stripWhiteSpace();
91 if (key == "expires") {
92 CString dateStr(reinterpret_cast<const char*>(val.characters8()), val.length());
93 expires = WTF::parseDateFromNullTerminatedCharacters(dateStr.data()) / WTF::msPerSecond;
94 } else if (key == "max-age")
95 expires = time(0) + val.toInt();
96 else if (key == "domain")
97 domain = val;
98 else if (key == "path")
99 path = val;
100 } else {
101 String key = attribute->stripWhiteSpace().lower();
102 if (key == "secure")
103 secure = "TRUE";
104 }
105 }
106
107 StringBuilder cookieStr;
108 cookieStr.reserveCapacity(domain.length() + path.length() + cookieName.length() + cookieValue.length() + 26);
109 cookieStr.append(domain + "\t");
110 cookieStr.append(domain.startsWith('.') ? "TRUE\t" : "FALSE\t");
111 cookieStr.append(path + "\t");
112 cookieStr.append(secure + "\t");
113 cookieStr.append(String::number(expires) + "\t");
114 cookieStr.append(cookieName + "\t");
115 cookieStr.append(cookieValue);
116
117 if (expired)
118 *expired = isExpired(expires);
119
120 return cookieStr.toString();
121}
122
123void setCookiesFromDOM(const NetworkStorageSession&, const KURL&, const KURL& url, const String& value)
124{