| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 double parseDate(const String& value) | 334 double parseDate(const String& value) |
| 335 { | 335 { |
| 336 return parseDateFromNullTerminatedCharacters(value.utf8().data()); | 336 return parseDateFromNullTerminatedCharacters(value.utf8().data()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 AtomicString extractMIMETypeFromMediaType(const AtomicString& mediaType) | 339 AtomicString extractMIMETypeFromMediaType(const AtomicString& mediaType) |
| 340 { | 340 { |
| 341 StringBuilder mimeType; | |
| 342 unsigned length = mediaType.length(); | 341 unsigned length = mediaType.length(); |
| 343 mimeType.reserveCapacity(length); | |
| 344 for (unsigned i = 0; i < length; i++) { | |
| 345 UChar c = mediaType[i]; | |
| 346 | 342 |
| 347 if (c == ';') | 343 unsigned pos = 0; |
| 344 |
| 345 while (pos < length) { |
| 346 UChar c = mediaType[pos]; |
| 347 if (c != '\t' && c != ' ') |
| 348 break; | 348 break; |
| 349 ++pos; |
| 350 } |
| 351 |
| 352 if (pos == length) |
| 353 return mediaType; |
| 354 |
| 355 unsigned typeStart = pos; |
| 356 |
| 357 unsigned typeEnd = pos; |
| 358 while (pos < length) { |
| 359 UChar c = mediaType[pos]; |
| 349 | 360 |
| 350 // While RFC 2616 does not allow it, other browsers allow multiple value
s in the HTTP media | 361 // While RFC 2616 does not allow it, other browsers allow multiple value
s in the HTTP media |
| 351 // type header field, Content-Type. In such cases, the media type string
passed here may contain | 362 // type header field, Content-Type. In such cases, the media type string
passed here may contain |
| 352 // the multiple values separated by commas. For now, this code ignores t
ext after the first comma, | 363 // the multiple values separated by commas. For now, this code ignores t
ext after the first comma, |
| 353 // which prevents it from simply failing to parse such types altogether.
Later for better | 364 // which prevents it from simply failing to parse such types altogether.
Later for better |
| 354 // compatibility we could consider using the first or last valid MIME ty
pe instead. | 365 // compatibility we could consider using the first or last valid MIME ty
pe instead. |
| 355 // See https://bugs.webkit.org/show_bug.cgi?id=25352 for more discussion
. | 366 // See https://bugs.webkit.org/show_bug.cgi?id=25352 for more discussion
. |
| 356 if (c == ',') | 367 if (c == ',' || c == ';') |
| 357 break; | 368 break; |
| 358 | 369 |
| 359 // FIXME: The following is not correct. RFC 2616 allows linear white spa
ce before and | 370 if (c != '\t' && c != ' ') |
| 360 // after the MIME type, but not within the MIME type itself. And linear
white space | 371 typeEnd = pos + 1; |
| 361 // includes only a few specific ASCII characters; a small subset of isSp
aceOrNewline. | |
| 362 // See https://bugs.webkit.org/show_bug.cgi?id=8644 for a bug tracking p
art of this. | |
| 363 if (isSpaceOrNewline(c)) | |
| 364 continue; | |
| 365 | 372 |
| 366 mimeType.append(c); | 373 ++pos; |
| 367 } | 374 } |
| 368 | 375 |
| 369 if (mimeType.length() == length) | 376 return AtomicString(mediaType.getString().substring(typeStart, typeEnd - typ
eStart)); |
| 370 return mediaType; | |
| 371 return mimeType.toAtomicString(); | |
| 372 } | 377 } |
| 373 | 378 |
| 374 String extractCharsetFromMediaType(const String& mediaType) | 379 String extractCharsetFromMediaType(const String& mediaType) |
| 375 { | 380 { |
| 376 unsigned pos, len; | 381 unsigned pos, len; |
| 377 findCharsetInMediaType(mediaType, pos, len); | 382 findCharsetInMediaType(mediaType, pos, len); |
| 378 return mediaType.substring(pos, len); | 383 return mediaType.substring(pos, len); |
| 379 } | 384 } |
| 380 | 385 |
| 381 void findCharsetInMediaType(const String& mediaType, unsigned& charsetPos, unsig
ned& charsetLen, unsigned start) | 386 void findCharsetInMediaType(const String& mediaType, unsigned& charsetPos, unsig
ned& charsetLen, unsigned start) |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 if (option == Suborigin::SuboriginPolicyOptions::None) | 754 if (option == Suborigin::SuboriginPolicyOptions::None) |
| 750 messages.append("Ignoring unknown suborigin policy option " + option
Name + "."); | 755 messages.append("Ignoring unknown suborigin policy option " + option
Name + "."); |
| 751 else | 756 else |
| 752 suborigin->addPolicyOption(option); | 757 suborigin->addPolicyOption(option); |
| 753 } | 758 } |
| 754 | 759 |
| 755 return true; | 760 return true; |
| 756 } | 761 } |
| 757 | 762 |
| 758 } // namespace blink | 763 } // namespace blink |
| OLD | NEW |