Changeset 71069 in webkit


Ignore:
Timestamp:
Nov 1, 2010 4:12:55 PM (13 years ago)
Author:
andersca@apple.com
Message:

Add ArgumentCoder specialization for WTF::CString
https://bugs.webkit.org/show_bug.cgi?id=48796

Reviewed by Sam Weinig.

  • Platform/CoreIPC/ArgumentCoders.h:
Location:
trunk/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r71060 r71069  
     12010-11-01  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Add ArgumentCoder specialization for WTF::CString
     6        https://bugs.webkit.org/show_bug.cgi?id=48796
     7
     8        * Platform/CoreIPC/ArgumentCoders.h:
     9
    1102010-11-01  Anders Carlsson  <andersca@apple.com>
    211
  • trunk/WebKit2/Platform/CoreIPC/ArgumentCoders.h

    r68677 r71069  
    3434#include <wtf/Vector.h>
    3535#include <wtf/text/AtomicString.h>
     36#include <wtf/text/CString.h>
    3637#include <wtf/text/WTFString.h>
    3738
     
    195196};
    196197
    197 template<> struct ArgumentCoder<String> {
    198     static void encode(ArgumentEncoder* encoder, const String& string)
     198template<> struct ArgumentCoder<CString> {
     199    static void encode(ArgumentEncoder* encoder, const CString& string)
    199200    {
    200201        // Special case the null string.
     
    206207        uint32_t length = string.length();
    207208        encoder->encode(length);
    208         encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.characters()), length * sizeof(UChar));
    209     }
    210    
    211     static bool decode(ArgumentDecoder* decoder, String& s)
     209        encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.data()), length);
     210    }
     211
     212    static bool decode(ArgumentDecoder* decoder, CString& result)
    212213    {
    213214        uint32_t length;
     
    217218        if (length == std::numeric_limits<uint32_t>::max()) {
    218219            // This is the null string.
    219             s = String();
     220            result = CString();
     221            return true;
     222        }
     223
     224        // Before allocating the string, make sure that the decoder buffer is big enough.
     225        if (!decoder->bufferIsLargeEnoughToContain<char>(length)) {
     226            decoder->markInvalid();
     227            return false;
     228        }
     229
     230        char* buffer;
     231        CString string = CString::newUninitialized(length, buffer);
     232        if (!decoder->decodeBytes(reinterpret_cast<uint8_t*>(buffer), length))
     233            return false;
     234
     235        result = string;
     236        return true;
     237    }
     238};
     239
     240template<> struct ArgumentCoder<String> {
     241    static void encode(ArgumentEncoder* encoder, const String& string)
     242    {
     243        // Special case the null string.
     244        if (string.isNull()) {
     245            encoder->encodeUInt32(std::numeric_limits<uint32_t>::max());
     246            return;
     247        }
     248
     249        uint32_t length = string.length();
     250        encoder->encode(length);
     251        encoder->encodeBytes(reinterpret_cast<const uint8_t*>(string.characters()), length * sizeof(UChar));
     252    }
     253   
     254    static bool decode(ArgumentDecoder* decoder, String& result)
     255    {
     256        uint32_t length;
     257        if (!decoder->decode(length))
     258            return false;
     259
     260        if (length == std::numeric_limits<uint32_t>::max()) {
     261            // This is the null string.
     262            result = String();
    220263            return true;
    221264        }
     
    232275            return false;
    233276       
    234         s = string;
     277        result = string;
    235278        return true;
    236279    }
Note: See TracChangeset for help on using the changeset viewer.