Title: [170654] trunk/Source/WebKit2
Revision
170654
Author
[email protected]
Date
2014-07-01 12:04:54 -0700 (Tue, 01 Jul 2014)

Log Message

Add a encodeLegacySessionState function
https://bugs.webkit.org/show_bug.cgi?id=134502

Reviewed by Tim Horton.

* UIProcess/LegacySessionStateCoding.h:
* UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::encodeSessionHistoryEntryData):
(WebKit::encodeLegacySessionHistoryEntryData):
(WebKit::createDictionary):
(WebKit::encodeSessionHistory):
(WebKit::encodeLegacySessionState):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (170653 => 170654)


--- trunk/Source/WebKit2/ChangeLog	2014-07-01 18:41:27 UTC (rev 170653)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-01 19:04:54 UTC (rev 170654)
@@ -1,3 +1,18 @@
+2014-07-01  Anders Carlsson  <[email protected]>
+
+        Add a encodeLegacySessionState function
+        https://bugs.webkit.org/show_bug.cgi?id=134502
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/LegacySessionStateCoding.h:
+        * UIProcess/mac/LegacySessionStateCoding.cpp:
+        (WebKit::encodeSessionHistoryEntryData):
+        (WebKit::encodeLegacySessionHistoryEntryData):
+        (WebKit::createDictionary):
+        (WebKit::encodeSessionHistory):
+        (WebKit::encodeLegacySessionState):
+
 2014-07-01  Alexey Proskuryakov  <[email protected]>
 
         [Cocoa] WebProcess doesn't follow localization of UI process when run as a service

Modified: trunk/Source/WebKit2/UIProcess/LegacySessionStateCoding.h (170653 => 170654)


--- trunk/Source/WebKit2/UIProcess/LegacySessionStateCoding.h	2014-07-01 18:41:27 UTC (rev 170653)
+++ trunk/Source/WebKit2/UIProcess/LegacySessionStateCoding.h	2014-07-01 19:04:54 UTC (rev 170654)
@@ -37,6 +37,7 @@
 struct FrameState;
 struct SessionState;
 
+RefPtr<API::Data> encodeLegacySessionState(const SessionState&);
 RefPtr<API::Data> encodeLegacySessionHistoryEntryData(const FrameState&);
 
 bool decodeLegacySessionState(const API::Data&, SessionState&);

Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp (170653 => 170654)


--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp	2014-07-01 18:41:27 UTC (rev 170653)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp	2014-07-01 19:04:54 UTC (rev 170654)
@@ -41,6 +41,8 @@
 static const CFStringRef provisionalURLKey = CFSTR("ProvisionalURL");
 
 // Session history keys.
+static const uint32_t sessionHistoryVersion = 1;
+
 static const CFStringRef sessionHistoryVersionKey = CFSTR("SessionHistoryVersion");
 static const CFStringRef sessionHistoryCurrentIndexKey = CFSTR("SessionHistoryCurrentIndex");
 static const CFStringRef sessionHistoryEntriesKey = CFSTR("SessionHistoryEntries");
@@ -353,7 +355,7 @@
 #endif
 }
 
-static MallocPtr<uint8_t> encodeLegacySessionHistoryEntryData(const FrameState& frameState, size_t& bufferSize)
+static MallocPtr<uint8_t> encodeSessionHistoryEntryData(const FrameState& frameState, size_t& bufferSize)
 {
     HistoryEntryDataEncoder encoder;
 
@@ -366,13 +368,105 @@
 RefPtr<API::Data> encodeLegacySessionHistoryEntryData(const FrameState& frameState)
 {
     size_t bufferSize;
-    auto buffer = encodeLegacySessionHistoryEntryData(frameState, bufferSize);
+    auto buffer = encodeSessionHistoryEntryData(frameState, bufferSize);
 
     return API::Data::createWithoutCopying(buffer.leakPtr(), bufferSize, [] (unsigned char* buffer, const void* context) {
         fastFree(buffer);
     }, nullptr);
 }
 
+static RetainPtr<CFDataRef> encodeSessionHistoryEntryData(const FrameState& frameState)
+{
+
+    return nullptr;
+}
+
+static RetainPtr<CFDictionaryRef> createDictionary(std::initializer_list<std::pair<CFStringRef, CFTypeRef>> keyValuePairs)
+{
+    Vector<CFTypeRef> keys;
+    Vector<CFTypeRef> values;
+
+    keys.reserveInitialCapacity(keyValuePairs.size());
+    values.reserveInitialCapacity(keyValuePairs.size());
+
+    for (const auto& keyValuePair : keyValuePairs) {
+        keys.uncheckedAppend(keyValuePair.first);
+        keys.uncheckedAppend(keyValuePair.second);
+    }
+
+    return adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys.data(), values.data(), keyValuePairs.size(), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+}
+
+static RetainPtr<CFDictionaryRef> encodeSessionHistory(const BackForwardListState& backForwardListState)
+{
+    ASSERT(!backForwardListState.currentIndex || backForwardListState.currentIndex.value() < backForwardListState.items.size());
+
+    auto sessionHistoryVersionNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &sessionHistoryVersion));
+
+    if (!backForwardListState.currentIndex)
+        return createDictionary({ { sessionHistoryVersionKey, sessionHistoryVersionNumber.get() } });
+
+    auto entries = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, backForwardListState.items.size(), &kCFTypeArrayCallBacks));
+
+    for (const auto& item : backForwardListState.items) {
+        auto url = ""
+        auto title = item.pageState.title.createCFString();
+        auto originalURL = item.pageState.mainFrameState.originalURLString.createCFString();
+        auto data = ""
+
+        auto entryDictionary = createDictionary({ { sessionHistoryEntryURLKey, url.get() }, { sessionHistoryEntryTitleKey, title.get() }, { sessionHistoryEntryDataKey, data.get() }});
+
+        CFArrayAppendValue(entries.get(), entryDictionary.get());
+    }
+
+    uint32_t currentIndex = backForwardListState.currentIndex.value();
+    auto currentIndexNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &currentIndex));
+
+    return createDictionary({ { sessionHistoryVersionKey, sessionHistoryVersionNumber.get() }, { sessionHistoryCurrentIndexKey, currentIndexNumber.get() }, { sessionHistoryEntriesKey, entries.get() } });
+}
+
+RefPtr<API::Data> encodeLegacySessionState(const SessionState& sessionState)
+{
+    auto sessionHistoryDictionary = encodeSessionHistory(sessionState.backForwardListState);
+    auto provisionalURLString = sessionState.provisionalURL.string().createCFString();
+
+    RetainPtr<CFDictionaryRef> stateDictionary;
+    if (provisionalURLString)
+        stateDictionary = createDictionary({ { sessionHistoryKey, sessionHistoryDictionary.get() }, { provisionalURLKey, provisionalURLString.get() } });
+    else
+        stateDictionary = createDictionary({ { sessionHistoryKey, sessionHistoryDictionary.get() } });
+
+    auto writeStream = adoptCF(CFWriteStreamCreateWithAllocatedBuffers(kCFAllocatorDefault, nullptr));
+    if (!writeStream)
+        return nullptr;
+
+    if (!CFWriteStreamOpen(writeStream.get()))
+        return nullptr;
+
+    if (!CFPropertyListWrite(stateDictionary.get(), writeStream.get(), kCFPropertyListBinaryFormat_v1_0, 0, nullptr))
+        return nullptr;
+
+    auto data = "" kCFStreamPropertyDataWritten)));
+
+    CFIndex length = CFDataGetLength(data.get());
+
+    size_t bufferSize = length + sizeof(uint32_t);
+    auto buffer = MallocPtr<uint8_t>::malloc(bufferSize);
+
+    // Put the session state version number at the start of the buffer
+    buffer.get()[0] = (sessionStateDataVersion & 0xff000000) >> 24;
+    buffer.get()[1] = (sessionStateDataVersion & 0x00ff0000) >> 16;
+    buffer.get()[2] = (sessionStateDataVersion & 0x0000ff00) >> 8;
+    buffer.get()[3] = (sessionStateDataVersion & 0x000000ff);
+
+    // Copy in the actual session state data
+    CFDataGetBytes(data.get(), CFRangeMake(0, length), buffer.get() + sizeof(uint32_t));
+
+    return API::Data::createWithoutCopying(buffer.leakPtr(), bufferSize, [] (unsigned char* buffer, const void* context) {
+        fastFree(buffer);
+    }, nullptr);
+}
+
 class HistoryEntryDataDecoder {
 public:
     HistoryEntryDataDecoder(const uint8_t* buffer, size_t bufferSize)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to