Add support for v0 legacy decoding
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jun 2014 22:32:33 +0000 (22:32 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jun 2014 22:32:33 +0000 (22:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134275

Reviewed by Andreas Kling.

* Shared/SessionState.h:
* UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::LegacySessionStateDecoder::decodeV0SessionHistory):
(WebKit::LegacySessionStateDecoder::decodeV1SessionHistory):

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/SessionState.h
Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp

index 53de5a7..622bb65 100644 (file)
@@ -1,5 +1,17 @@
 2014-06-24  Anders Carlsson  <andersca@apple.com>
 
+        Add support for v0 legacy decoding
+        https://bugs.webkit.org/show_bug.cgi?id=134275
+
+        Reviewed by Andreas Kling.
+
+        * Shared/SessionState.h:
+        * UIProcess/mac/LegacySessionStateCoding.cpp:
+        (WebKit::LegacySessionStateDecoder::decodeV0SessionHistory):
+        (WebKit::LegacySessionStateDecoder::decodeV1SessionHistory):
+
+2014-06-24  Anders Carlsson  <andersca@apple.com>
+
         Add SPI for clearing an entire back-forward list
         https://bugs.webkit.org/show_bug.cgi?id=134274
 
index 2ee5130..3115132 100644 (file)
@@ -118,7 +118,7 @@ struct BackForwardListState {
     static bool decode(IPC::ArgumentDecoder&, BackForwardListState&);
 
     Vector<PageState> items;
-    uint32_t currentIndex;
+    Optional<uint32_t> currentIndex;
 };
 
 struct SessionState {
index ff97e17..66b72a0 100644 (file)
@@ -118,8 +118,38 @@ bool LegacySessionStateDecoder::decodeSessionHistory(CFDictionaryRef backForward
 
 bool LegacySessionStateDecoder::decodeV0SessionHistory(CFDictionaryRef sessionHistoryDictionary, BackForwardListState& backForwardListState) const
 {
-    // FIXME: Implement.
-    return false;
+    auto currentIndexNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(sessionHistoryDictionary, sessionHistoryCurrentIndexKey));
+    if (!currentIndexNumber)
+        return false;
+
+    CFIndex currentIndex;
+    if (!CFNumberGetValue(currentIndexNumber, kCFNumberCFIndexType, &currentIndex))
+        return false;
+
+    if (currentIndex < -1)
+        return false;
+
+    auto historyEntries = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(sessionHistoryDictionary, sessionHistoryEntriesKey));
+    if (!historyEntries)
+        return false;
+
+    // Version 0 session history relied on currentIndex == -1 to represent the same thing as not having a current index.
+    bool hasCurrentIndex = currentIndex != -1;
+
+    if (!decodeSessionHistoryEntries(historyEntries, backForwardListState.items))
+        return false;
+
+    if (!hasCurrentIndex && CFArrayGetCount(historyEntries))
+        return false;
+
+    if (hasCurrentIndex) {
+        if (static_cast<uint32_t>(currentIndex) >= backForwardListState.items.size())
+            return false;
+
+        backForwardListState.currentIndex = static_cast<uint32_t>(currentIndex);
+    }
+
+    return true;
 }
 
 bool LegacySessionStateDecoder::decodeV1SessionHistory(CFDictionaryRef sessionHistoryDictionary, BackForwardListState& backForwardListState) const
@@ -147,7 +177,7 @@ bool LegacySessionStateDecoder::decodeV1SessionHistory(CFDictionaryRef sessionHi
         return false;
 
     backForwardListState.currentIndex = static_cast<uint32_t>(currentIndex);
-    if (backForwardListState.currentIndex >= backForwardListState.items.size())
+    if (static_cast<uint32_t>(currentIndex) >= backForwardListState.items.size())
         return false;
 
     return true;