Changeset 66693 in webkit


Ignore:
Timestamp:
Sep 2, 2010 4:57:22 PM (14 years ago)
Author:
weinig@apple.com
Message:

Add ability to send WKDictionaryRefs via post message.
https://bugs.webkit.org/show_bug.cgi?id=45151

Reviewed by Anders Carlsson.

  • Shared/ImmutableDictionary.cpp:

(WebKit::ImmutableDictionary::ImmutableDictionary):

  • Shared/ImmutableDictionary.h:

(WebKit::ImmutableDictionary::adopt): Remove tag, it wasn't doing anything.
(WebKit::ImmutableDictionary::isMutable):
(WebKit::ImmutableDictionary::map): Add accessor of internal
map for encoder.

  • Shared/UserMessageCoders.h:

(WebKit::UserMessageEncoder::baseEncode):
(WebKit::UserMessageDecoder::baseDecode):
Add encoder/decoder.

Location:
trunk/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r66688 r66693  
     12010-09-02  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        Add ability to send WKDictionaryRefs via post message.
     6        https://bugs.webkit.org/show_bug.cgi?id=45151
     7
     8        * Shared/ImmutableDictionary.cpp:
     9        (WebKit::ImmutableDictionary::ImmutableDictionary):
     10        * Shared/ImmutableDictionary.h:
     11        (WebKit::ImmutableDictionary::adopt): Remove tag, it wasn't doing anything.
     12        (WebKit::ImmutableDictionary::isMutable):
     13        (WebKit::ImmutableDictionary::map): Add accessor of internal
     14        map for encoder.
     15
     16        * Shared/UserMessageCoders.h:
     17        (WebKit::UserMessageEncoder::baseEncode):
     18        (WebKit::UserMessageDecoder::baseDecode):
     19        Add encoder/decoder.
     20
    1212010-09-02  Sam Weinig  <sam@webkit.org>
    222
  • trunk/WebKit2/Shared/ImmutableDictionary.cpp

    r66679 r66693  
    3535}
    3636
    37 ImmutableDictionary::ImmutableDictionary(MapType& map, AdoptTag)
     37ImmutableDictionary::ImmutableDictionary(MapType& map)
    3838{
    3939    m_map.swap(map);
  • trunk/WebKit2/Shared/ImmutableDictionary.h

    r66676 r66693  
    5151    static PassRefPtr<ImmutableDictionary> adopt(MapType& map)
    5252    {
    53         return adoptRef(new ImmutableDictionary(map, Adopt));
     53        return adoptRef(new ImmutableDictionary(map));
    5454    }
    5555    ~ImmutableDictionary();
     56
     57    virtual bool isMutable() { return false; }
    5658
    5759    template<typename T>
     
    7779    size_t size() { return m_map.size(); }
    7880
    79     virtual bool isMutable() { return false; }
     81    const MapType& map() { return m_map; }
    8082
    8183protected:
    8284    ImmutableDictionary();
    83     enum AdoptTag { Adopt };
    84     ImmutableDictionary(MapType& map, AdoptTag);
     85    ImmutableDictionary(MapType& map);
    8586
    8687    virtual Type type() const { return APIType; }
  • trunk/WebKit2/Shared/UserMessageCoders.h

    r66688 r66693  
    2424 */
    2525
     26#include "ArgumentDecoder.h"
    2627#include "ArgumentEncoder.h"
    27 #include "ArgumentDecoder.h"
    2828#include "ImmutableArray.h"
     29#include "ImmutableDictionary.h"
     30#include "WebCoreArgumentCoders.h"
    2931#include "WebString.h"
    3032
     
    3234
    3335//   - Array -> Array
     36//   - Dictionary -> Dictionary
    3437//   - String -> String
    3538
     
    4548            for (size_t i = 0; i < array->size(); ++i)
    4649                encoder->encode(Owner(array->at(i)));
     50            return true;
     51        }
     52        case APIObject::TypeDictionary: {
     53            ImmutableDictionary* dictionary = static_cast<ImmutableDictionary*>(m_root);
     54            const ImmutableDictionary::MapType& map = dictionary->map();
     55            encoder->encode(static_cast<uint64_t>(map.size()));
     56
     57            ImmutableDictionary::MapType::const_iterator it = map.begin();
     58            ImmutableDictionary::MapType::const_iterator end = map.end();
     59            for (; it != end; ++it) {
     60                encoder->encode(it->first);
     61                encoder->encode(Owner(it->second.get()));
     62            }
    4763            return true;
    4864        }
     
    7187// Handles
    7288//   - Array -> Array
     89//   - Dictionary -> Dictionary
    7390//   - String -> String
    7491
     
    94111
    95112            coder.m_root = ImmutableArray::adopt(vector);
     113            break;
     114        }
     115        case APIObject::TypeDictionary: {
     116            uint64_t size;
     117            if (!decoder->decode(size))
     118                return false;
     119
     120            ImmutableDictionary::MapType map;
     121            for (size_t i = 0; i < size; ++i) {
     122                String key;
     123                if (!decoder->decode(key))
     124                    return false;
     125
     126                RefPtr<APIObject> element;
     127                Owner messageCoder(coder, element);
     128                if (!decoder->decode(messageCoder))
     129                    return false;
     130
     131                std::pair<ImmutableDictionary::MapType::iterator, bool> result = map.set(key, element.release());
     132                if (!result.second)
     133                    return false;
     134            }
     135
     136            coder.m_root = ImmutableDictionary::adopt(map);
    96137            break;
    97138        }
Note: See TracChangeset for help on using the changeset viewer.