Changeset 158978 in webkit


Ignore:
Timestamp:
Nov 8, 2013 4:51:54 PM (10 years ago)
Author:
andersca@apple.com
Message:

KeyedEncoder should be able to encoder objects
https://bugs.webkit.org/show_bug.cgi?id=124085

Reviewed by Sam Weinig.

Source/WebCore:

  • history/HistoryItem.cpp:

(WebCore::HistoryItem::encodeBackForwardTree):
Encode the root object.

(WebCore::HistoryItem::encodeBackForwardTreeNode):
Encode the target.

  • history/HistoryItem.h:

Add new members.

  • platform/KeyedCoding.h:

(WebCore::KeyedEncoder::encodeObject):
Call beginObject, call the functor and then call endObject().

Source/WebKit2:

Add a dictionary stack to KeyedEncoder that's pushed and popped by
beginObject/endObject.

  • Shared/cf/KeyedEncoder.cpp:

(WebKit::KeyedEncoder::KeyedEncoder):
(WebKit::KeyedEncoder::~KeyedEncoder):
(WebKit::KeyedEncoder::encodeUInt32):
(WebKit::KeyedEncoder::encodeString):
(WebKit::KeyedEncoder::beginObject):
(WebKit::KeyedEncoder::endObject):

  • Shared/cf/KeyedEncoder.h:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r158972 r158978  
     12013-11-08  Anders Carlsson  <andersca@apple.com>
     2
     3        KeyedEncoder should be able to encoder objects
     4        https://bugs.webkit.org/show_bug.cgi?id=124085
     5
     6        Reviewed by Sam Weinig.
     7
     8        * history/HistoryItem.cpp:
     9        (WebCore::HistoryItem::encodeBackForwardTree):
     10        Encode the root object.
     11
     12        (WebCore::HistoryItem::encodeBackForwardTreeNode):
     13        Encode the target.
     14
     15        * history/HistoryItem.h:
     16        Add new members.
     17
     18        * platform/KeyedCoding.h:
     19        (WebCore::KeyedEncoder::encodeObject):
     20        Call beginObject, call the functor and then call endObject().
     21
    1222013-11-08  Sam Weinig  <sam@webkit.org>
    223
  • trunk/Source/WebCore/history/HistoryItem.cpp

    r158971 r158978  
    688688    encoder.encodeUInt32("version", backForwardTreeEncodingVersion);
    689689
    690     // FIXME: Encode the tree.
     690    encoder.encodeObject("root", *this, [](KeyedEncoder& encoder, const HistoryItem& item) {
     691        item.encodeBackForwardTreeNode(encoder);
     692    });
    691693}
    692694
     
    732734
    733735    encoder.encodeString(m_target);
     736}
     737
     738void HistoryItem::encodeBackForwardTreeNode(KeyedEncoder& encoder) const
     739{
     740    // FIXME: Implement.
     741
     742    encoder.encodeString("target", m_target);
    734743}
    735744
  • trunk/Source/WebCore/history/HistoryItem.h

    r158971 r158978  
    224224
    225225    void encodeBackForwardTreeNode(Encoder&) const;
    226 
    227     /* When adding new member variables to this class, please notify the Qt team.
    228      * qt/HistoryItemQt.cpp contains code to serialize history items.
    229      */
     226    void encodeBackForwardTreeNode(KeyedEncoder&) const;
    230227
    231228    String m_urlString;
  • trunk/Source/WebCore/platform/KeyedCoding.h

    r158971 r158978  
    3737public:
    3838    virtual void encodeUInt32(const String& key, uint32_t) = 0;
     39
     40    virtual void encodeString(const String& key, const String&) = 0;
     41
     42    template<typename T, typename F>
     43    void encodeObject(const String& key, const T& object, F function)
     44    {
     45        this->beginObject(key);
     46        function(*this, object);
     47        this->endObject();
     48    }
     49
     50private:
     51    virtual void beginObject(const String& key) = 0;
     52    virtual void endObject() = 0;
    3953};
    4054
  • trunk/Source/WebKit2/ChangeLog

    r158976 r158978  
     12013-11-08  Anders Carlsson  <andersca@apple.com>
     2
     3        KeyedEncoder should be able to encoder objects
     4        https://bugs.webkit.org/show_bug.cgi?id=124085
     5
     6        Reviewed by Sam Weinig.
     7
     8        Add a dictionary stack to KeyedEncoder that's pushed and popped by
     9        beginObject/endObject.
     10
     11        * Shared/cf/KeyedEncoder.cpp:
     12        (WebKit::KeyedEncoder::KeyedEncoder):
     13        (WebKit::KeyedEncoder::~KeyedEncoder):
     14        (WebKit::KeyedEncoder::encodeUInt32):
     15        (WebKit::KeyedEncoder::encodeString):
     16        (WebKit::KeyedEncoder::beginObject):
     17        (WebKit::KeyedEncoder::endObject):
     18        * Shared/cf/KeyedEncoder.h:
     19
    1202013-11-08  Alexandru Chiculita  <achicu@adobe.com>
    221
  • trunk/Source/WebKit2/Shared/cf/KeyedEncoder.cpp

    r158971 r158978  
    4040    : m_rootDictionary(createDictionary())
    4141{
     42    m_dictionaryStack.append(m_rootDictionary.get());
    4243}
    4344   
    4445KeyedEncoder::~KeyedEncoder()
    4546{
     47    ASSERT(m_dictionaryStack.size() == 1);
     48    ASSERT(m_dictionaryStack.last() == m_rootDictionary);
    4649}
    4750
     
    4952{
    5053    RetainPtr<CFNumberRef> number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
    51     CFDictionarySetValue(m_rootDictionary.get(), key.createCFString().get(), number.get());
     54    CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), number.get());
     55}
     56
     57void KeyedEncoder::encodeString(const String& key, const String& value)
     58{
     59    CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), value.createCFString().get());
     60}
     61
     62void KeyedEncoder::beginObject(const String& key)
     63{
     64    auto dictionary = createDictionary();
     65    CFDictionarySetValue(m_dictionaryStack.last(), key.createCFString().get(), dictionary.get());
     66
     67    m_dictionaryStack.append(dictionary.get());
     68}
     69
     70void KeyedEncoder::endObject()
     71{
     72    m_dictionaryStack.removeLast();
    5273}
    5374
  • trunk/Source/WebKit2/Shared/cf/KeyedEncoder.h

    r158971 r158978  
    2929#include <WebCore/KeyedCoding.h>
    3030#include <wtf/RetainPtr.h>
     31#include <wtf/Vector.h>
    3132
    3233namespace WebKit {
     
    3940private:
    4041    virtual void encodeUInt32(const String& key, uint32_t) OVERRIDE;
     42    virtual void encodeString(const String& key, const String&) OVERRIDE;
     43
     44    virtual void beginObject(const String& key) OVERRIDE;
     45    virtual void endObject() OVERRIDE;
    4146
    4247    RetainPtr<CFMutableDictionaryRef> m_rootDictionary;
     48    Vector<CFMutableDictionaryRef, 16> m_dictionaryStack;
    4349};
    4450
Note: See TracChangeset for help on using the changeset viewer.