OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 if (quoteMark && (end == length)) | 392 if (quoteMark && (end == length)) |
393 break; // Close quote not found. | 393 break; // Close quote not found. |
394 | 394 |
395 return value.substring(pos, end - pos); | 395 return value.substring(pos, end - pos); |
396 } | 396 } |
397 | 397 |
398 return ""; | 398 return ""; |
399 } | 399 } |
400 | 400 |
401 enum Mode { | 401 enum class MetaAttribute { |
402 None, | 402 None, |
403 Charset, | 403 Charset, |
404 Pragma, | 404 Pragma, |
405 }; | 405 }; |
406 | 406 |
407 WTF::TextEncoding encodingFromMetaAttributes( | 407 WTF::TextEncoding encodingFromMetaAttributes( |
408 const HTMLAttributeList& attributes) { | 408 const HTMLAttributeList& attributes) { |
409 bool gotPragma = false; | 409 bool gotPragma = false; |
410 Mode mode = None; | 410 MetaAttribute mode = MetaAttribute::None; |
411 String charset; | 411 String charset; |
412 | 412 |
413 for (const auto& htmlAttribute : attributes) { | 413 for (const auto& htmlAttribute : attributes) { |
414 const String& attributeName = htmlAttribute.first; | 414 const String& attributeName = htmlAttribute.first; |
415 const String& attributeValue = AtomicString(htmlAttribute.second); | 415 const String& attributeValue = AtomicString(htmlAttribute.second); |
416 | 416 |
417 if (threadSafeMatch(attributeName, http_equivAttr)) { | 417 if (threadSafeMatch(attributeName, http_equivAttr)) { |
418 if (equalIgnoringCase(attributeValue, "content-type")) | 418 if (equalIgnoringCase(attributeValue, "content-type")) |
419 gotPragma = true; | 419 gotPragma = true; |
420 } else if (charset.isEmpty()) { | 420 } else if (charset.isEmpty()) { |
421 if (threadSafeMatch(attributeName, charsetAttr)) { | 421 if (threadSafeMatch(attributeName, charsetAttr)) { |
422 charset = attributeValue; | 422 charset = attributeValue; |
423 mode = Charset; | 423 mode = MetaAttribute::Charset; |
424 } else if (threadSafeMatch(attributeName, contentAttr)) { | 424 } else if (threadSafeMatch(attributeName, contentAttr)) { |
425 charset = extractCharset(attributeValue); | 425 charset = extractCharset(attributeValue); |
426 if (charset.length()) | 426 if (charset.length()) |
427 mode = Pragma; | 427 mode = MetaAttribute::Pragma; |
428 } | 428 } |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 if (mode == Charset || (mode == Pragma && gotPragma)) | 432 if (mode == MetaAttribute::Charset || |
| 433 (mode == MetaAttribute::Pragma && gotPragma)) |
433 return WTF::TextEncoding(stripLeadingAndTrailingHTMLSpaces(charset)); | 434 return WTF::TextEncoding(stripLeadingAndTrailingHTMLSpaces(charset)); |
434 | 435 |
435 return WTF::TextEncoding(); | 436 return WTF::TextEncoding(); |
436 } | 437 } |
437 | 438 |
438 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b) { | 439 static bool threadSafeEqual(const StringImpl* a, const StringImpl* b) { |
439 if (a == b) | 440 if (a == b) |
440 return true; | 441 return true; |
441 if (a->hash() != b->hash()) | 442 if (a->hash() != b->hash()) |
442 return false; | 443 return false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 string = StringImpl::create8BitIfPossible(characters, size); | 492 string = StringImpl::create8BitIfPossible(characters, size); |
492 else if (width == Force8Bit) | 493 else if (width == Force8Bit) |
493 string = String::make8BitFrom16BitSource(characters, size); | 494 string = String::make8BitFrom16BitSource(characters, size); |
494 else | 495 else |
495 string = String(characters, size); | 496 string = String(characters, size); |
496 | 497 |
497 return string; | 498 return string; |
498 } | 499 } |
499 | 500 |
500 } // namespace blink | 501 } // namespace blink |
OLD | NEW |