OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 static bool isOriginSeparator(UChar ch) | 136 static bool isOriginSeparator(UChar ch) |
137 { | 137 { |
138 return isASCIISpace(ch) || ch == ','; | 138 return isASCIISpace(ch) || ch == ','; |
139 } | 139 } |
140 | 140 |
141 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription) | 141 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription) |
142 { | 142 { |
143 AtomicallyInitializedStatic(AtomicString&, accessControlAllowOrigin = *new A
tomicString("access-control-allow-origin", AtomicString::ConstructFromLiteral)); | 143 AtomicallyInitializedStatic(AtomicString&, accessControlAllowOrigin = *new A
tomicString("access-control-allow-origin", AtomicString::ConstructFromLiteral)); |
144 AtomicallyInitializedStatic(AtomicString&, accessControlAllowCredentials = *
new AtomicString("access-control-allow-credentials", AtomicString::ConstructFrom
Literal)); | 144 AtomicallyInitializedStatic(AtomicString&, accessControlAllowCredentials = *
new AtomicString("access-control-allow-credentials", AtomicString::ConstructFrom
Literal)); |
145 | 145 |
| 146 if (!response.httpStatusCode()) { |
| 147 errorDescription = "Received an invalid response. Origin '" + securityOr
igin->toString() + "' is therefore not allowed access."; |
| 148 return false; |
| 149 } |
| 150 |
146 // A wildcard Access-Control-Allow-Origin can not be used if credentials are
to be sent, | 151 // A wildcard Access-Control-Allow-Origin can not be used if credentials are
to be sent, |
147 // even with Access-Control-Allow-Credentials set to true. | 152 // even with Access-Control-Allow-Credentials set to true. |
148 const AtomicString& accessControlOriginString = response.httpHeaderField(acc
essControlAllowOrigin); | 153 const AtomicString& accessControlOriginString = response.httpHeaderField(acc
essControlAllowOrigin); |
149 if (accessControlOriginString == starAtom && includeCredentials == DoNotAllo
wStoredCredentials) | 154 if (accessControlOriginString == starAtom && includeCredentials == DoNotAllo
wStoredCredentials) |
150 return true; | 155 return true; |
151 | 156 |
152 if (accessControlOriginString != securityOrigin->toAtomicString()) { | 157 if (accessControlOriginString != securityOrigin->toAtomicString()) { |
153 if (accessControlOriginString == starAtom) { | 158 if (accessControlOriginString == starAtom) { |
154 errorDescription = "A wildcard '*' cannot be used in the 'Access-Con
trol-Allow-Origin' header when the credentials flag is true. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; | 159 errorDescription = "A wildcard '*' cannot be used in the 'Access-Con
trol-Allow-Origin' header when the credentials flag is true. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; |
155 } else if (accessControlOriginString.isEmpty()) { | 160 } else if (accessControlOriginString.isEmpty()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 Vector<String> headers; | 197 Vector<String> headers; |
193 headerValue.split(',', false, headers); | 198 headerValue.split(',', false, headers); |
194 for (unsigned headerCount = 0; headerCount < headers.size(); headerCount++)
{ | 199 for (unsigned headerCount = 0; headerCount < headers.size(); headerCount++)
{ |
195 String strippedHeader = headers[headerCount].stripWhiteSpace(); | 200 String strippedHeader = headers[headerCount].stripWhiteSpace(); |
196 if (!strippedHeader.isEmpty()) | 201 if (!strippedHeader.isEmpty()) |
197 headerSet.add(strippedHeader); | 202 headerSet.add(strippedHeader); |
198 } | 203 } |
199 } | 204 } |
200 | 205 |
201 } // namespace WebCore | 206 } // namespace WebCore |
OLD | NEW |