Diff
Modified: trunk/Source/WebKit2/ChangeLog (170224 => 170225)
--- trunk/Source/WebKit2/ChangeLog 2014-06-20 23:44:01 UTC (rev 170224)
+++ trunk/Source/WebKit2/ChangeLog 2014-06-20 23:48:37 UTC (rev 170225)
@@ -1,3 +1,23 @@
+2014-06-20 Anders Carlsson <[email protected]>
+
+ Implement more of LegacySessionStateDecoder
+ https://bugs.webkit.org/show_bug.cgi?id=134144
+
+ Reviewed by Sam Weinig.
+
+ * Shared/SessionState.cpp:
+ (WebKit::BackForwardListState::encode):
+ (WebKit::SessionState::encode): Deleted.
+ * Shared/SessionState.h:
+ * UIProcess/mac/LegacySessionStateCoding.cpp:
+ (WebKit::LegacySessionStateDecoder::decodeSessionState):
+ (WebKit::LegacySessionStateDecoder::decodeSessionHistory):
+ (WebKit::LegacySessionStateDecoder::decodeV0SessionHistory):
+ (WebKit::LegacySessionStateDecoder::decodeV1SessionHistory):
+ (WebKit::LegacySessionStateDecoder::decodeSessionHistoryEntries):
+ (WebKit::LegacySessionStateDecoder::decodeSessionHistoryEntry):
+ * UIProcess/mac/LegacySessionStateCoding.h:
+
2014-06-20 Ryuan Choi <[email protected]>
Unreviewed. build fix for the cmake based ports since r170188
Modified: trunk/Source/WebKit2/Shared/SessionState.cpp (170224 => 170225)
--- trunk/Source/WebKit2/Shared/SessionState.cpp 2014-06-20 23:44:01 UTC (rev 170224)
+++ trunk/Source/WebKit2/Shared/SessionState.cpp 2014-06-20 23:48:37 UTC (rev 170225)
@@ -73,9 +73,9 @@
encoder << mainFrameState;
}
-void SessionState::encode(IPC::ArgumentEncoder& encoder) const
+void BackForwardListState::encode(IPC::ArgumentEncoder& encoder) const
{
- encoder << backForwardListItems;
+ encoder << items;
encoder << currentIndex;
}
Modified: trunk/Source/WebKit2/Shared/SessionState.h (170224 => 170225)
--- trunk/Source/WebKit2/Shared/SessionState.h 2014-06-20 23:44:01 UTC (rev 170224)
+++ trunk/Source/WebKit2/Shared/SessionState.h 2014-06-20 23:48:37 UTC (rev 170225)
@@ -27,6 +27,7 @@
#define SessionState_h
#include <WebCore/IntPoint.h>
+#include <WebCore/URL.h>
#include <wtf/Optional.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -97,13 +98,18 @@
FrameState mainFrameState;
};
-struct SessionState {
+struct BackForwardListState {
void encode(IPC::ArgumentEncoder&) const;
- Vector<PageState> backForwardListItems;
+ Vector<PageState> items;
uint32_t currentIndex;
};
+struct SessionState {
+ BackForwardListState backForwardListState;
+ WebCore::URL provisionalURL;
+};
+
} // namespace WebKit
#endif // SessionState_h
Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp (170224 => 170225)
--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp 2014-06-20 23:44:01 UTC (rev 170224)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp 2014-06-20 23:48:37 UTC (rev 170225)
@@ -26,8 +26,23 @@
#include "config.h"
#include "LegacySessionStateCoding.h"
+#include "APIData.h"
+#include "SessionState.h"
+#include <wtf/cf/TypeCasts.h>
+
namespace WebKit {
+// Session state keys.
+static const uint32_t sessionStateDataVersion = 2;
+
+static const CFStringRef sessionHistoryKey = CFSTR("SessionHistory");
+static const CFStringRef provisionalURLKey = CFSTR("ProvisionalURL");
+
+// Session history keys.
+static const CFStringRef sessionHistoryVersionKey = CFSTR("SessionHistoryVersion");
+static const CFStringRef sessionHistoryCurrentIndexKey = CFSTR("SessionHistoryCurrentIndex");
+static const CFStringRef sessionHistoryEntriesKey = CFSTR("SessionHistoryEntries");
+
LegacySessionStateDecoder::LegacySessionStateDecoder(API::Data* data)
: m_data(data)
{
@@ -39,10 +54,117 @@
bool LegacySessionStateDecoder::decodeSessionState(SessionState& sessionState) const
{
- // FIXME: Implement this.
- (void)m_data;
+ if (!m_data)
+ return false;
+ size_t size = m_data->size();
+ const uint8_t* bytes = m_data->bytes();
+
+ if (size < sizeof(uint32_t))
+ return false;
+
+ uint32_t versionNumber = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
+
+ if (versionNumber != sessionStateDataVersion)
+ return false;
+
+ auto data = "" bytes + sizeof(uint32_t), size - sizeof(uint32_t)));
+
+ auto sessionStateDictionary = adoptCF(dynamic_cf_cast<CFDictionaryRef>(CFPropertyListCreateWithData(kCFAllocatorDefault, data.get(), kCFPropertyListImmutable, nullptr, nullptr)));
+ if (!sessionStateDictionary)
+ return false;
+
+ if (auto backForwardListDictionary = dynamic_cf_cast<CFDictionaryRef>(CFDictionaryGetValue(sessionStateDictionary.get(), sessionHistoryKey))) {
+ if (!decodeSessionHistory(backForwardListDictionary, sessionState.backForwardListState))
+ return false;
+ }
+
+ if (auto provisionalURLString = dynamic_cf_cast<CFStringRef>(CFDictionaryGetValue(sessionStateDictionary.get(), provisionalURLKey))) {
+ sessionState.provisionalURL = WebCore::URL(WebCore::URL(), provisionalURLString);
+ if (!sessionState.provisionalURL.isValid())
+ return false;
+ }
+
+ return true;
+}
+
+bool LegacySessionStateDecoder::decodeSessionHistory(CFDictionaryRef backForwardListDictionary, BackForwardListState& backForwardListState) const
+{
+ auto sessionHistoryVersionNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(backForwardListDictionary, sessionHistoryVersionKey));
+ if (!sessionHistoryVersionNumber) {
+ // Version 0 session history dictionaries did not contain a version number.
+ return decodeV0SessionHistory(backForwardListDictionary, backForwardListState);
+ }
+
+ CFIndex sessionHistoryVersion;
+ if (!CFNumberGetValue(sessionHistoryVersionNumber, kCFNumberCFIndexType, &sessionHistoryVersion))
+ return false;
+
+ if (sessionHistoryVersion == 1)
+ return decodeV1SessionHistory(backForwardListDictionary, backForwardListState);
+
return false;
}
+bool LegacySessionStateDecoder::decodeV0SessionHistory(CFDictionaryRef sessionHistoryDictionary, BackForwardListState& backForwardListState) const
+{
+ // FIXME: Implement.
+ return false;
+}
+
+bool LegacySessionStateDecoder::decodeV1SessionHistory(CFDictionaryRef sessionHistoryDictionary, BackForwardListState& backForwardListState) const
+{
+ auto currentIndexNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(sessionHistoryDictionary, sessionHistoryCurrentIndexKey));
+ if (!currentIndexNumber) {
+ // No current index means the dictionary represents an empty session.
+ backForwardListState.currentIndex = 0;
+ backForwardListState.items = { };
+ return true;
+ }
+
+ CFIndex currentIndex;
+ if (!CFNumberGetValue(currentIndexNumber, kCFNumberCFIndexType, ¤tIndex))
+ return false;
+
+ if (currentIndex < 0)
+ return false;
+
+ auto historyEntries = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(sessionHistoryDictionary, sessionHistoryEntriesKey));
+ if (!historyEntries)
+ return false;
+
+ if (!decodeSessionHistoryEntries(historyEntries, backForwardListState.items))
+ return false;
+
+ backForwardListState.currentIndex = static_cast<uint32_t>(currentIndex);
+ if (backForwardListState.currentIndex >= backForwardListState.items.size())
+ return false;
+
+ return true;
+}
+
+bool LegacySessionStateDecoder::decodeSessionHistoryEntries(CFArrayRef entriesArray, Vector<PageState>& entries) const
+{
+ for (CFIndex i = 0, size = CFArrayGetCount(entriesArray); i < size; ++i) {
+ auto entryDictionary = dynamic_cf_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(entriesArray, i));
+ if (!entryDictionary)
+ return false;
+
+ PageState entry;
+ if (!decodeSessionHistoryEntry(entryDictionary, entry))
+ return false;
+
+ entries.append(std::move(entry));
+ }
+
+ return false;
+}
+
+bool LegacySessionStateDecoder::decodeSessionHistoryEntry(CFDictionaryRef entryDictionary, PageState& pageState) const
+{
+ // FIXME: Implement this.
+ return false;
+}
+
+
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h (170224 => 170225)
--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h 2014-06-20 23:44:01 UTC (rev 170224)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.h 2014-06-20 23:48:37 UTC (rev 170225)
@@ -26,13 +26,17 @@
#ifndef LegacySessionStateCoding_h
#define LegacySessionStateCoding_h
+#include <wtf/Vector.h>
+
namespace API {
class Data;
}
namespace WebKit {
+struct BackForwardListState;
struct SessionState;
+struct PageState;
class LegacySessionStateDecoder {
public:
@@ -42,6 +46,13 @@
bool decodeSessionState(SessionState&) const;
private:
+ bool decodeSessionHistory(CFDictionaryRef, BackForwardListState&) const;
+ bool decodeV0SessionHistory(CFDictionaryRef, BackForwardListState&) const;
+ bool decodeV1SessionHistory(CFDictionaryRef, BackForwardListState&) const;
+
+ bool decodeSessionHistoryEntries(CFArrayRef, Vector<PageState>&) const;
+ bool decodeSessionHistoryEntry(CFDictionaryRef, PageState&) const;
+
API::Data* m_data;
};