Allow WebString.utf8() to take UTF8ConversionMode

Currently WebString.utf8() always converts the internal string to UTF-8
with LenientUTF8Conversion mode (if the string is not ascii), but
WebString::fromUTF8() only takes valid, strict UTF-8 string.

therefore
the same string may not be able to be converted back to WebString.

This has been causing a few issues:
- UTF16 (WTFString) -> UTF8 -> UTF16 (WTFString) round trip doesn't work
- Works differently from base::UTF16ToUTF8, and some code explicitly
  calls base version via .utf16() to avoid any problems while it could
  be more costly than .utf8() if the internal string is ascii/latin.

Similar but opposite attempt has been made in the past in
https://codereview.chromium.org/1768063002/
but hadn't landed as leniently converted UTF8 is not valid and probably
should not be accepted.

BUG=667131

Review-Url: https://codereview.chromium.org/2629573002
Cr-Original-Commit-Position: refs/heads/master@{#444008}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: d280d3b7b888a5f8964e916cdc2360ebc7858418
1 file changed
tree: d8bfc743b7057bd1ea3131b119d1b0b512f638c6
  1. allocator/
  2. debug/
  3. dtoa/
  4. testing/
  5. text/
  6. typed_arrays/
  7. .gitignore
  8. AddressSanitizer.h
  9. Alignment.h
  10. Allocator.h
  11. Allocator.md
  12. ASCIICType.cpp
  13. ASCIICType.h
  14. ASCIICTypeTest.cpp
  15. Assertions.cpp
  16. Assertions.h
  17. AssertionsTest.cpp
  18. Atomics.h
  19. AutoReset.h
  20. BitVector.cpp
  21. BitVector.h
  22. BitwiseOperations.h
  23. BloomFilter.h
  24. BUILD.gn
  25. build_config.h
  26. ByteOrder.h
  27. ByteSwap.h
  28. CheckedNumeric.h
  29. Compiler.h
  30. ConditionalDestructor.h
  31. ContainerAnnotations.h
  32. CONTRIBUTORS.pthreads-win32
  33. CPU.h
  34. CryptographicallyRandomNumber.cpp
  35. CryptographicallyRandomNumber.h
  36. CurrentTime.cpp
  37. CurrentTime.h
  38. DataLog.cpp
  39. DataLog.h
  40. DateMath.cpp
  41. DateMath.h
  42. DEPS
  43. Deque.h
  44. DequeTest.cpp
  45. DoublyLinkedList.h
  46. dtoa.cpp
  47. dtoa.h
  48. dtoa_test.cpp
  49. DynamicAnnotations.cpp
  50. DynamicAnnotations.h
  51. FilePrintStream.cpp
  52. FilePrintStream.h
  53. Forward.h
  54. Functional.h
  55. FunctionalTest.cpp
  56. GetPtr.h
  57. HashCountedSet.h
  58. HashFunctions.h
  59. HashIterators.h
  60. HashMap.h
  61. HashMapTest.cpp
  62. HashSet.h
  63. HashSetTest.cpp
  64. HashTable.cpp
  65. HashTable.h
  66. HashTableDeletedValueType.h
  67. HashTraits.h
  68. HexNumber.h
  69. InstanceCounter.cpp
  70. InstanceCounter.h
  71. LeakAnnotations.h
  72. LinkedHashSet.h
  73. LinkedStack.h
  74. ListHashSet.h
  75. ListHashSetTest.cpp
  76. Locker.h
  77. MathExtras.h
  78. MathExtrasTest.cpp
  79. Noncopyable.h
  80. NonCopyingSort.h
  81. NotFound.h
  82. Optional.h
  83. OptionalTest.cpp
  84. OWNERS
  85. PassRefPtr.h
  86. PassRefPtrTest.cpp
  87. PrintStream.cpp
  88. PrintStream.h
  89. PtrUtil.h
  90. RefCounted.h
  91. RefPtr.h
  92. RefPtrTest.cpp
  93. RefVector.h
  94. RetainPtr.h
  95. SaturatedArithmetic.h
  96. ScopedLogger.md
  97. SizeAssertions.h
  98. SizeLimits.cpp
  99. SpinLock.h
  100. StaticConstructors.h
  101. StdLibExtras.h
  102. StringExtras.h
  103. StringExtrasTest.cpp
  104. StringHasher.h
  105. StringHasherTest.cpp
  106. TerminatedArray.h
  107. TerminatedArrayBuilder.h
  108. Threading.h
  109. ThreadingPrimitives.h
  110. ThreadingPthreads.cpp
  111. ThreadingWin.cpp
  112. ThreadRestrictionVerifier.h
  113. ThreadSafeRefCounted.h
  114. ThreadSpecific.h
  115. ThreadSpecificWin.cpp
  116. Time.h
  117. TimeTest.cpp
  118. TreeNode.h
  119. TreeNodeTest.cpp
  120. TriState.h
  121. TypeTraits.h
  122. TypeTraitsTest.cpp
  123. UniquePtrTransitionGuide.md
  124. Vector.h
  125. VectorTest.cpp
  126. VectorTraits.h
  127. WeakPtr.h
  128. WTF.cpp
  129. WTF.h
  130. WTFExport.h
  131. WTFThreadData.cpp
  132. WTFThreadData.h