Remove all uses of deprecatedCharacters from WebKit2
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Mar 2014 06:22:02 +0000 (06:22 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Mar 2014 06:22:02 +0000 (06:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130197

Reviewed by Andreas Kling.

Source/WebKit2:

* Shared/APIString.h: Rewrote getCharacters to use StringView,
substring, and getCharactersWithUpconvert. Added an 8-bit case
to getUTF8CString.

* Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp:
(WebKit::writeByte): Added.
(WebKit::writeCharacter): Added.
(WebKit::writeLine): Added. Uses operator[] instead of characters16 to get
the UTF-16 characters out of the string.
(WebKit::NetscapePluginModule::scanPlugin): Replaced code that writes out
text to stdout with much simpler version using the functions above.

* UIProcess/TextChecker.h: Changed text arguments to use StringView instead
of UChar/int pairs.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::internalShowContextMenu): Updated to pass StringView.

* UIProcess/efl/TextCheckerEfl.cpp:
(WebKit::nextWordOffset): Changed function to use StringView and unsigned.
(WebKit::TextChecker::checkTextOfParagraph): Changed to use StringView and
substring.
(WebKit::TextChecker::checkSpellingOfString): Ditto.
(WebKit::TextChecker::checkGrammarOfString): Ditto.
(WebKit::TextChecker::requestCheckingOfString): Pass in a StringView, so no
need to call deprecatedCharacters.

* UIProcess/ios/TextCheckerIOS.mm:
(WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView.
(WebKit::TextChecker::checkSpellingOfString): Ditto.
(WebKit::TextChecker::checkGrammarOfString): Ditto.

* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView and
use StringView::createNSStringWithoutCopying.
(WebKit::TextChecker::checkSpellingOfString): CHanged to take StringView.
(WebKit::TextChecker::checkGrammarOfString): Ditto.

* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
(WebKit::convertStringToKeyCodes): Changed to take StringView and use
upconvertedCharacters instead of deprecatedCharacters. Also use move instead
of swap.
(WebKit::NetscapePlugin::sendComplexTextInput): Updated to new style for loop.

* WebProcess/WebPage/EncoderAdapter.cpp:
(WebKit::EncoderAdapter::encodeString): Use StringView::upconvertedCharacters
instead of String::deprecatedCharacters.

Source/WTF:

* wtf/text/StringView.h: Added new getCharactersWithUpconvert and upconvertedCharacters
functions. These are useful for callers that need UTF-16.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165692 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringView.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/APIString.h
Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp
Source/WebKit2/UIProcess/TextChecker.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/efl/TextCheckerEfl.cpp
Source/WebKit2/UIProcess/ios/TextCheckerIOS.mm
Source/WebKit2/UIProcess/mac/TextCheckerMac.mm
Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
Source/WebKit2/WebProcess/WebPage/EncoderAdapter.cpp

index 5193b4f..d77b772 100644 (file)
@@ -1,5 +1,15 @@
 2014-03-15  Darin Adler  <darin@apple.com>
 
+        Remove all uses of deprecatedCharacters from WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=130197
+
+        Reviewed by Andreas Kling.
+
+        * wtf/text/StringView.h: Added new getCharactersWithUpconvert and upconvertedCharacters
+        functions. These are useful for callers that need UTF-16.
+
+2014-03-15  Darin Adler  <darin@apple.com>
+
         Try to fix EFL build.
 
         * wtf/ThreadingPthreads.cpp: (WTF::changeThreadPriority): Code in this function
index 525339a..7fb3552 100644 (file)
@@ -85,6 +85,20 @@ public:
         return static_cast<const UChar*>(m_characters);
     }
 
+    void getCharactersWithUpconvert(LChar*) const;
+    void getCharactersWithUpconvert(UChar*) const;
+
+    class UpconvertedCharacters {
+    public:
+        explicit UpconvertedCharacters(const StringView&);
+        operator const UChar*() const { return m_characters; }
+        const UChar* get() const { return m_characters; }
+    private:
+        Vector<UChar, 32> m_upconvertedCharacters;
+        const UChar* m_characters;
+    };
+    UpconvertedCharacters upconvertedCharacters() const { return UpconvertedCharacters(*this); }
+
     bool isNull() const { return !m_characters; }
     bool isEmpty() const { return !length(); }
     unsigned length() const { return m_length & ~is16BitStringFlag; }
@@ -176,6 +190,38 @@ private:
     unsigned m_length;
 };
 
+inline void StringView::getCharactersWithUpconvert(LChar* destination) const
+{
+    ASSERT(is8Bit());
+    memcpy(destination, characters8(), length());
+}
+
+inline void StringView::getCharactersWithUpconvert(UChar* destination) const
+{
+    if (is8Bit()) {
+        const LChar* characters8 = this->characters8();
+        unsigned length = this->length();
+        for (unsigned i = 0; i < length; ++i)
+            destination[i] = characters8[i];
+        return;
+    }
+    memcpy(destination, characters16(), length() * sizeof(UChar));
+}
+
+inline StringView::UpconvertedCharacters::UpconvertedCharacters(const StringView& string)
+{
+    if (!string.is8Bit()) {
+        m_characters = string.characters16();
+        return;
+    }
+    const LChar* characters8 = string.characters8();
+    unsigned length = string.length();
+    m_upconvertedCharacters.reserveInitialCapacity(length);
+    for (unsigned i = 0; i < length; ++i)
+        m_upconvertedCharacters.uncheckedAppend(characters8[i]);
+    m_characters = m_upconvertedCharacters.data();
+}
+
 } // namespace WTF
 
 using WTF::StringView;
index 05be9d3..2095071 100644 (file)
@@ -1,3 +1,58 @@
+2014-03-15  Darin Adler  <darin@apple.com>
+
+        Remove all uses of deprecatedCharacters from WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=130197
+
+        Reviewed by Andreas Kling.
+
+        * Shared/APIString.h: Rewrote getCharacters to use StringView,
+        substring, and getCharactersWithUpconvert. Added an 8-bit case
+        to getUTF8CString.
+
+        * Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp:
+        (WebKit::writeByte): Added.
+        (WebKit::writeCharacter): Added.
+        (WebKit::writeLine): Added. Uses operator[] instead of characters16 to get
+        the UTF-16 characters out of the string.
+        (WebKit::NetscapePluginModule::scanPlugin): Replaced code that writes out
+        text to stdout with much simpler version using the functions above.
+
+        * UIProcess/TextChecker.h: Changed text arguments to use StringView instead
+        of UChar/int pairs.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::internalShowContextMenu): Updated to pass StringView.
+
+        * UIProcess/efl/TextCheckerEfl.cpp:
+        (WebKit::nextWordOffset): Changed function to use StringView and unsigned.
+        (WebKit::TextChecker::checkTextOfParagraph): Changed to use StringView and
+        substring.
+        (WebKit::TextChecker::checkSpellingOfString): Ditto.
+        (WebKit::TextChecker::checkGrammarOfString): Ditto.
+        (WebKit::TextChecker::requestCheckingOfString): Pass in a StringView, so no
+        need to call deprecatedCharacters.
+
+        * UIProcess/ios/TextCheckerIOS.mm:
+        (WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView.
+        (WebKit::TextChecker::checkSpellingOfString): Ditto.
+        (WebKit::TextChecker::checkGrammarOfString): Ditto.
+
+        * UIProcess/mac/TextCheckerMac.mm:
+        (WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView and
+        use StringView::createNSStringWithoutCopying.
+        (WebKit::TextChecker::checkSpellingOfString): CHanged to take StringView.
+        (WebKit::TextChecker::checkGrammarOfString): Ditto.
+
+        * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
+        (WebKit::convertStringToKeyCodes): Changed to take StringView and use
+        upconvertedCharacters instead of deprecatedCharacters. Also use move instead
+        of swap.
+        (WebKit::NetscapePlugin::sendComplexTextInput): Updated to new style for loop.
+
+        * WebProcess/WebPage/EncoderAdapter.cpp:
+        (WebKit::EncoderAdapter::encodeString): Use StringView::upconvertedCharacters
+        instead of String::deprecatedCharacters.
+
 2014-03-15  David Kilzer  <ddkilzer@apple.com>
 
         [iOS] Define SYSTEM_VERSION_PREFIX consistently
index 767f162..5fe603b 100644 (file)
@@ -31,6 +31,7 @@
 #include <JavaScriptCore/JSStringRef.h>
 #include <JavaScriptCore/OpaqueJSString.h>
 #include <wtf/PassRefPtr.h>
+#include <wtf/text/StringView.h>
 #include <wtf/text/WTFString.h>
 #include <wtf/unicode/UTF8.h>
 
@@ -68,11 +69,10 @@ public:
     size_t length() const { return m_string.length(); }
     size_t getCharacters(UChar* buffer, size_t bufferLength) const
     {
-        if (!bufferLength)
-            return 0;
-        bufferLength = std::min(bufferLength, static_cast<size_t>(m_string.length()));
-        memcpy(buffer, m_string.deprecatedCharacters(), bufferLength * sizeof(UChar));
-        return bufferLength;
+        unsigned unsignedBufferLength = std::min<size_t>(bufferLength, std::numeric_limits<unsigned>::max());
+        StringView substring = StringView(m_string).substring(0, unsignedBufferLength);
+        substring.getCharactersWithUpconvert(buffer);
+        return substring.length();
     }
 
     size_t maximumUTF8CStringSize() const { return m_string.length() * 3 + 1; }
@@ -81,11 +81,17 @@ public:
         if (!bufferSize)
             return 0;
         char* p = buffer;
-        const UChar* d = m_string.deprecatedCharacters();
-        WTF::Unicode::ConversionResult result = WTF::Unicode::convertUTF16ToUTF8(&d, d + m_string.length(), &p, p + bufferSize - 1, /* strict */ true);
-        *p++ = '\0';
+        WTF::Unicode::ConversionResult result;
+        if (m_string.is8Bit()) {
+            const LChar* characters = m_string.characters8();
+            result = WTF::Unicode::convertLatin1ToUTF8(&characters, characters + m_string.length(), &p, p + bufferSize - 1);
+        } else {
+            const UChar* characters = m_string.characters16();
+            result = WTF::Unicode::convertUTF16ToUTF8(&characters, characters + m_string.length(), &p, p + bufferSize - 1, /* strict */ true);
+        }
         if (result != WTF::Unicode::conversionOK && result != WTF::Unicode::targetExhausted)
             return 0;
+        *p++ = '\0';
         return p - buffer;
     }
 
index d4a003a..6d3405a 100644 (file)
@@ -185,23 +185,28 @@ void NetscapePluginModule::determineQuirks()
 #endif
 }
 
-static String truncateToSingleLine(const String& string)
+static void writeByte(char byte)
 {
-    unsigned oldLength = string.length();
-    UChar* buffer;
-    String stringBuffer(StringImpl::createUninitialized(oldLength + 1, buffer));
-
-    unsigned newLength = 0;
-    const UChar* start = string.deprecatedCharacters();
-    for (const UChar* c = start; c < start + oldLength; ++c) {
-        if (*c != UChar('\n'))
-            buffer[newLength++] = *c;
-    }
-    buffer[newLength++] = UChar('\n');
+    int result;
+    while ((result = fputc(byte, stdout)) == EOF && errno == EINTR) { }
+    ASSERT(result != EOF);
+}
 
-    String result = (newLength == oldLength + 1) ? stringBuffer : String(stringBuffer.characters16(), newLength);
-    ASSERT(result.endsWith(UChar('\n')));
-    return result;
+static void writeCharacter(UChar character)
+{
+    writeByte(reinterpret_cast<const char*>(&character)[0]);
+    writeByte(reinterpret_cast<const char*>(&character)[1]);
+}
+
+static void writeLine(const String& line)
+{
+    unsigned length = line.length();
+    for (unsigned i = 0; i < length; ++i) {
+        UChar character = line[i];
+        if (character != '\n')
+            writeCharacter(character);
+    }
+    writeCharacter('\n');
 }
 
 bool NetscapePluginModule::scanPlugin(const String& pluginPath)
@@ -227,22 +232,9 @@ bool NetscapePluginModule::scanPlugin(const String& pluginPath)
     }
 
     // Write data to standard output for the UI process.
-    String output[3] = {
-        truncateToSingleLine(metaData.name),
-        truncateToSingleLine(metaData.description),
-        truncateToSingleLine(metaData.mimeDescription)
-    };
-    for (unsigned i = 0; i < 3; ++i) {
-        const String& line = output[i];
-        const char* current = reinterpret_cast<const char*>(line.characters16());
-        const char* end = reinterpret_cast<const char*>(line.characters16()) + (line.length() * sizeof(UChar));
-        while (current < end) {
-            int result;
-            while ((result = fputc(*current, stdout)) == EOF && errno == EINTR) { }
-            ASSERT(result != EOF);
-            ++current;
-        }
-    }
+    writeLine(metaData.name);
+    writeLine(metaData.description);
+    writeLine(metaData.mimeDescription);
 
     fflush(stdout);
 
index 3b8626b..411928a 100644 (file)
@@ -67,10 +67,10 @@ public:
     static int64_t uniqueSpellDocumentTag(WebPageProxy*);
     static void closeSpellDocumentWithTag(int64_t);
 #if USE(UNIFIED_TEXT_CHECKING)
-    static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes);
+    static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes);
 #endif
-    static void checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength);
-    static void checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
+    static void checkSpellingOfString(int64_t spellDocumentTag, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength);
+    static void checkGrammarOfString(int64_t spellDocumentTag, StringView text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
     static bool spellingUIIsShowing();
     static void toggleSpellingUIIsShowing();
     static void updateSpellingUIWithMisspelledWord(int64_t spellDocumentTag, const String& misspelledWord);
index a76bad0..8d6b2f1 100644 (file)
@@ -3469,18 +3469,18 @@ int64_t WebPageProxy::spellDocumentTag()
 #if USE(UNIFIED_TEXT_CHECKING)
 void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results)
 {
-    results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text.deprecatedCharacters(), text.length(), checkingTypes);
+    results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text, checkingTypes);
 }
 #endif
 
 void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength)
 {
-    TextChecker::checkSpellingOfString(spellDocumentTag(), text.deprecatedCharacters(), text.length(), misspellingLocation, misspellingLength);
+    TextChecker::checkSpellingOfString(spellDocumentTag(), text, misspellingLocation, misspellingLength);
 }
 
 void WebPageProxy::checkGrammarOfString(const String& text, Vector<GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
 {
-    TextChecker::checkGrammarOfString(spellDocumentTag(), text.deprecatedCharacters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);
+    TextChecker::checkGrammarOfString(spellDocumentTag(), text, grammarDetails, badGrammarLocation, badGrammarLength);
 }
 
 void WebPageProxy::spellingUIIsShowing(bool& isShowing)
index da1290d..b37d09a 100644 (file)
@@ -120,19 +120,19 @@ void TextChecker::closeSpellDocumentWithTag(int64_t tag)
 }
 
 #if ENABLE(SPELLCHECK)
-static int nextWordOffset(const UChar* text, int length, int currentOffset)
+static unsigned nextWordOffset(StringView text, unsigned currentOffset)
 {
     // FIXME: avoid creating textIterator object here, it could be passed as a parameter.
     //        isTextBreak() leaves the iterator pointing to the first boundary position at
     //        or after "offset" (ubrk_isBoundary side effect).
     //        For many word separators, the method doesn't properly determine the boundaries
     //        without resetting the iterator.
-    TextBreakIterator* textIterator = wordBreakIterator(StringView(text, length));
+    TextBreakIterator* textIterator = wordBreakIterator(text);
     if (!textIterator)
         return currentOffset;
 
-    int wordOffset = currentOffset;
-    while (wordOffset < length && isTextBreak(textIterator, wordOffset))
+    unsigned wordOffset = currentOffset;
+    while (wordOffset < text.length() && isTextBreak(textIterator, wordOffset))
         ++wordOffset;
 
     // Do not treat the word's boundary as a separator.
@@ -148,26 +148,26 @@ static int nextWordOffset(const UChar* text, int length, int currentOffset)
 #endif // ENABLE(SPELLCHECK)
 
 #if USE(UNIFIED_TEXT_CHECKING)
-Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes)
+Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes)
 {
     Vector<TextCheckingResult> paragraphCheckingResult;
 #if ENABLE(SPELLCHECK)
     if (checkingTypes & TextCheckingTypeSpelling) {
-        TextBreakIterator* textIterator = wordBreakIterator(StringView(text, length));
+        TextBreakIterator* textIterator = wordBreakIterator(text);
         if (!textIterator)
             return paragraphCheckingResult;
 
         // Omit the word separators at the beginning/end of the text to don't unnecessarily
         // involve the client to check spelling for them.
-        int offset = nextWordOffset(text, length, 0);
-        int lengthStrip = length;
+        unsigned offset = nextWordOffset(text, 0);
+        unsigned lengthStrip = text.length();
         while (lengthStrip > 0 && isTextBreak(textIterator, lengthStrip - 1))
             --lengthStrip;
 
-        while (offset >= 0 && offset < lengthStrip) {
+        while (offset < lengthStrip) {
             int32_t misspellingLocation = -1;
             int32_t misspellingLength = 0;
-            checkSpellingOfString(spellDocumentTag, text + offset, lengthStrip - offset, misspellingLocation, misspellingLength);
+            checkSpellingOfString(spellDocumentTag, text.substring(offset, lengthStrip - offset), misspellingLocation, misspellingLength);
             if (!misspellingLength)
                 break;
 
@@ -178,7 +178,7 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
             paragraphCheckingResult.append(misspellingResult);
             offset += misspellingLocation + misspellingLength;
             // Generally, we end up checking at the word separator, move to the adjacent word.
-            offset = nextWordOffset(text, lengthStrip, offset);
+            offset = nextWordOffset(text.substring(0, lengthStrip), offset);
         }
     }
 #else
@@ -191,10 +191,10 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
 }
 #endif
 
-void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength)
+void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength)
 {
 #if ENABLE(SPELLCHECK)
-    WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, String(text, length), misspellingLocation, misspellingLength);
+    WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, text.toStringWithoutCopying(), misspellingLocation, misspellingLength);
 #else
     UNUSED_PARAM(spellDocumentTag);
     UNUSED_PARAM(text);
@@ -204,7 +204,7 @@ void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* t
 #endif
 }
 
-void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<GrammarDetail>&, int32_t&, int32_t&)
+void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<GrammarDetail>&, int32_t&, int32_t&)
 {
     notImplemented();
 }
@@ -271,10 +271,7 @@ void TextChecker::requestCheckingOfString(PassRefPtr<TextCheckerCompletion> comp
     ASSERT(request.sequence() != unrequestedTextCheckingSequence);
     ASSERT(request.mask() != TextCheckingTypeNone);
 
-    String text = request.text();
-    Vector<TextCheckingResult> result = checkTextOfParagraph(completion->spellDocumentTag(), text.deprecatedCharacters(), text.length(), request.mask());
-
-    completion->didFinishCheckingText(result);
+    completion->didFinishCheckingText(checkTextOfParagraph(completion->spellDocumentTag(), request.text(), request.mask()));
 #else
     UNUSED_PARAM(completion);
 #endif
index 8712056..d2369d5 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "TextCheckerState.h"
 #import <WebCore/NotImplemented.h>
+#import <wtf/text/StringView.h>
 
 using namespace WebCore;
 
@@ -131,7 +132,7 @@ void TextChecker::closeSpellDocumentWithTag(int64_t)
 
 #if USE(UNIFIED_TEXT_CHECKING)
 
-Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t, const UChar*, int, uint64_t)
+Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t, StringView, uint64_t)
 {
     notImplemented();
     return Vector<TextCheckingResult>();
@@ -139,15 +140,13 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t, const UCha
 
 #endif
 
-void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&)
+void TextChecker::checkSpellingOfString(int64_t, StringView, int32_t&, int32_t&)
 {
-    // Mac uses checkTextOfParagraph instead.
     notImplemented();
 }
 
-void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
+void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
 {
-    // Mac uses checkTextOfParagraph instead.
     notImplemented();
 }
 
index c2ce378..dd8b72f 100644 (file)
@@ -31,6 +31,7 @@
 #import "TextCheckerState.h"
 #import <WebCore/NotImplemented.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/text/StringView.h>
 
 @interface NSSpellChecker (WebNSSpellCheckerDetails)
 - (NSString *)languageForWordRange:(NSRange)range inString:(NSString *)string orthography:(NSOrthography *)orthography;
@@ -295,13 +296,13 @@ void TextChecker::closeSpellDocumentWithTag(int64_t tag)
 
 #if USE(UNIFIED_TEXT_CHECKING)
 
-Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes)
+Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes)
 {
     Vector<TextCheckingResult> results;
 
-    RetainPtr<NSString> textString = adoptNS([[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO]);
-    NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString .get()
-                                                                          range:NSMakeRange(0, length)
+    RetainPtr<NSString> textString = text.createNSStringWithoutCopying();
+    NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString.get()
+                                                                          range:NSMakeRange(0, text.length())
                                                                           types:checkingTypes | NSTextCheckingTypeOrthography
                                                                         options:nil
                                                          inSpellDocumentWithTag:spellDocumentTag 
@@ -384,13 +385,13 @@ Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocume
 
 #endif
 
-void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&)
+void TextChecker::checkSpellingOfString(int64_t, StringView, int32_t&, int32_t&)
 {
     // Mac uses checkTextOfParagraph instead.
     notImplemented();
 }
 
-void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
+void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)
 {
     // Mac uses checkTextOfParagraph instead.
     notImplemented();
index 725f22b..8eb17c6 100644 (file)
@@ -963,7 +963,7 @@ uint64_t NetscapePlugin::pluginComplexTextInputIdentifier() const
 
 
 #ifndef NP_NO_CARBON
-static bool convertStringToKeyCodes(const String& string, ScriptCode scriptCode, Vector<UInt8>& keyCodes)
+static bool convertStringToKeyCodes(StringView string, ScriptCode scriptCode, Vector<UInt8>& keyCodes)
 {
     // Create the mapping.
     UnicodeMapping mapping;
@@ -973,27 +973,27 @@ static bool convertStringToKeyCodes(const String& string, ScriptCode scriptCode,
 
     mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kTextEncodingDefaultVariant, kTextEncodingDefaultFormat);
     mapping.mappingVersion = kUnicodeUseLatestMapping;
-    
+
     // Create the converter
     UnicodeToTextInfo textInfo;
-    
+
     if (CreateUnicodeToTextInfo(&mapping, &textInfo) != noErr)
         return false;
-    
+
     ByteCount inputLength = string.length() * sizeof(UniChar);
     ByteCount inputRead;
     ByteCount outputLength;
     ByteCount maxOutputLength = string.length() * sizeof(UniChar);
 
     Vector<UInt8> outputData(maxOutputLength);
-    OSStatus status = ConvertFromUnicodeToText(textInfo, inputLength, string.deprecatedCharacters(), kNilOptions, 0, 0, 0, 0, maxOutputLength, &inputRead, &outputLength, outputData.data());
+    OSStatus status = ConvertFromUnicodeToText(textInfo, inputLength, string.upconvertedCharacters(), kNilOptions, 0, 0, 0, 0, maxOutputLength, &inputRead, &outputLength, outputData.data());
     
     DisposeUnicodeToTextInfo(&textInfo);
     
     if (status != noErr)
         return false;
 
-    outputData.swap(keyCodes);
+    keyCodes = std::move(outputData);
     return true;
 }
 #endif
@@ -1034,8 +1034,8 @@ void NetscapePlugin::sendComplexTextInput(const String& textInput)
         EventRecord event = initializeEventRecord(keyDown);
         event.modifiers = 0;
 
-        for (size_t i = 0; i < keyCodes.size(); i++) {
-            event.message = keyCodes[i];
+        for (auto& keyCode : keyCodes) {
+            event.message = keyCode;
             NPP_HandleEvent(&event);
         }
         break;
index 38ec1dc..bdc074e 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "DataReference.h"
 #include "WebCoreArgumentCoders.h"
-#include <wtf/text/WTFString.h>
+#include <wtf/text/StringView.h>
 
 namespace WebKit {
 
@@ -108,7 +108,7 @@ void EncoderAdapter::encodeString(const String& value)
 
     uint64_t lengthInBytes = length * sizeof(UChar);
     m_encoder << lengthInBytes;
-    m_encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(value.deprecatedCharacters()), length * sizeof(UChar), alignof(UChar));
+    m_encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(StringView(value).upconvertedCharacters().get()), length * sizeof(UChar), alignof(UChar));
 }
 
 }