Diff
Modified: trunk/Source/WebKit2/ChangeLog (170682 => 170683)
--- trunk/Source/WebKit2/ChangeLog 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/ChangeLog 2014-07-02 00:47:19 UTC (rev 170683)
@@ -1,5 +1,30 @@
2014-07-01 Anders Carlsson <ander...@apple.com>
+ Add ABI hacks to allow WKPageRef to use WKSessionStateRef
+ https://bugs.webkit.org/show_bug.cgi?id=134529
+
+ Reviewed by Sam Weinig.
+
+ * UIProcess/API/APISessionState.h:
+ Add a sessionState() getter.
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageCopySessionState):
+ Add a hack where we return a WKSessionStateRef if the least significant bit of the context pointer
+ is 1, and a WKDataRef otherwise.
+
+ (WKPageRestoreFromSessionState):
+ Handle both WKDataRef and WKSessionStateref.
+
+ * UIProcess/API/C/WKPage.h:
+ Use WKTypeRefs for state saving and restoration.
+
+ * UIProcess/API/C/WKSessionStateRef.cpp:
+ (WKSessionStateCopyData):
+ Add helper function.
+
+2014-07-01 Anders Carlsson <ander...@apple.com>
+
WKPageRestoreFromSessionState should use the new session state restore code path
https://bugs.webkit.org/show_bug.cgi?id=134526
Modified: trunk/Source/WebKit2/UIProcess/API/APISessionState.h (170682 => 170683)
--- trunk/Source/WebKit2/UIProcess/API/APISessionState.h 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/UIProcess/API/APISessionState.h 2014-07-02 00:47:19 UTC (rev 170683)
@@ -36,6 +36,8 @@
static PassRefPtr<SessionState> create(WebKit::SessionState);
virtual ~SessionState();
+ const WebKit::SessionState& sessionState() const { return m_sessionState; }
+
private:
explicit SessionState(WebKit::SessionState);
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (170682 => 170683)
--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp 2014-07-02 00:47:19 UTC (rev 170683)
@@ -32,6 +32,7 @@
#include "APIFindClient.h"
#include "APILoaderClient.h"
#include "APIPolicyClient.h"
+#include "APISessionState.h"
#include "APIUIClient.h"
#include "ImmutableDictionary.h"
#include "LegacySessionStateCoding.h"
@@ -350,8 +351,12 @@
return toAPI(sessionBackForwardListValueType);
}
-WKDataRef WKPageCopySessionState(WKPageRef pageRef, void *context, WKPageSessionStateFilterCallback filter)
+WKTypeRef WKPageCopySessionState(WKPageRef pageRef, void* context, WKPageSessionStateFilterCallback filter)
{
+ // FIXME: This is a hack to make sure we return a WKDataRef to maintain compatibility with older versions of Safari.
+ bool shouldReturnData = !(reinterpret_cast<uintptr_t>(context) & 1);
+ context = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(context) & ~1);
+
auto sessionState = toImpl(pageRef)->sessionState([pageRef, context, filter](WebBackForwardListItem& item) {
if (filter) {
if (!filter(pageRef, WKPageGetSessionBackForwardListItemValueType(), toAPI(&item), context))
@@ -364,15 +369,26 @@
return true;
});
- return toAPI(encodeLegacySessionState(sessionState).release().leakRef());
+ if (shouldReturnData)
+ toAPI(encodeLegacySessionState(sessionState).release().leakRef());
+
+ return toAPI(API::SessionState::create(std::move(sessionState)).leakRef());
}
-void WKPageRestoreFromSessionState(WKPageRef pageRef, WKDataRef sessionStateData)
+void WKPageRestoreFromSessionState(WKPageRef pageRef, WKTypeRef sessionStateRef)
{
SessionState sessionState;
- if (!decodeLegacySessionState(*toImpl(sessionStateData), sessionState))
- return;
+ // FIXME: This is for backwards compatibility with Safari. Remove it once Safari no longer depends on it.
+ if (toImpl(sessionStateRef)->type() == API::Object::Type::Data) {
+ if (!decodeLegacySessionState(*toImpl(static_cast<WKDataRef>(sessionStateRef)), sessionState))
+ return;
+ } else {
+ ASSERT(toImpl(sessionStateRef)->type() == API::Object::Type::SessionState);
+
+ sessionState = toImpl(static_cast<WKSessionStateRef>(sessionStateRef))->sessionState();
+ }
+
toImpl(pageRef)->restoreFromState(std::move(sessionState));
}
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.h (170682 => 170683)
--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.h 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.h 2014-07-02 00:47:19 UTC (rev 170683)
@@ -130,9 +130,15 @@
WK_EXPORT WKStringRef WKPageGetSessionBackForwardListItemValueType(void);
typedef bool (*WKPageSessionStateFilterCallback)(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context);
-WK_EXPORT WKDataRef WKPageCopySessionState(WKPageRef page, void* context, WKPageSessionStateFilterCallback urlAllowedCallback);
-WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKDataRef sessionStateData);
+// FIXME: This should return a WKSessionStateRef object, not a WKTypeRef.
+// It currently returns a WKTypeRef for backwards compatibility with Safari.
+WK_EXPORT WKTypeRef WKPageCopySessionState(WKPageRef page, void* context, WKPageSessionStateFilterCallback urlAllowedCallback);
+
+// FIXME: This should take a WKSessionStateRef object, not a WKTypeRef.
+// It currently takes a WKTypeRef for backwards compatibility with Safari.
+WK_EXPORT void WKPageRestoreFromSessionState(WKPageRef page, WKTypeRef sessionState);
+
WK_EXPORT double WKPageGetBackingScaleFactor(WKPageRef page);
WK_EXPORT void WKPageSetCustomBackingScaleFactor(WKPageRef page, double customScaleFactor);
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.cpp (170682 => 170683)
--- trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.cpp 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.cpp 2014-07-02 00:47:19 UTC (rev 170683)
@@ -26,6 +26,7 @@
#include "config.h"
#include "WKSessionStateRef.h"
+#include "APIData.h"
#include "APISessionState.h"
#include "LegacySessionStateCoding.h"
#include "SessionState.h"
@@ -44,3 +45,8 @@
return WebKit::toAPI(API::SessionState::create(std::move(sessionState)).leakRef());
}
+
+WKDataRef WKSessionStateCopyData(WKSessionStateRef sessionState)
+{
+ return WebKit::toAPI(WebKit::encodeLegacySessionState(WebKit::toImpl(sessionState)->sessionState()).release().leakRef());
+}
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.h (170682 => 170683)
--- trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.h 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKSessionStateRef.h 2014-07-02 00:47:19 UTC (rev 170683)
@@ -36,6 +36,8 @@
WK_EXPORT WKSessionStateRef WKSessionStateCreateFromData(WKDataRef data);
+WK_EXPORT WKDataRef WKSessionStateCopyData(WKSessionStateRef sessionState);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp (170682 => 170683)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/RestoreSessionStateContainingFormData.cpp 2014-07-02 00:47:19 UTC (rev 170683)
@@ -28,6 +28,7 @@
#include "PlatformUtilities.h"
#include "PlatformWebView.h"
#include "Test.h"
+#include <WebKit2/WKSessionStateRef.h>
namespace TestWebKitAPI {
@@ -49,7 +50,7 @@
WKPageSetPageLoaderClient(page, &loaderClient.base);
}
-static WKRetainPtr<WKDataRef> createSessionStateContainingFormData(WKContextRef context)
+static WKRetainPtr<WKDataRef> createSessionStateDataContainingFormData(WKContextRef context)
{
PlatformWebView webView(context);
setPageLoaderClient(webView.page());
@@ -62,7 +63,8 @@
Util::run(&didFinishLoad);
didFinishLoad = false;
- return adoptWK(WKPageCopySessionState(webView.page(), 0, 0));
+ auto sessionState = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), nullptr)));
+ return adoptWK(WKSessionStateCopyData(sessionState.get()));
}
TEST(WebKit2, RestoreSessionStateContainingFormData)
@@ -75,10 +77,12 @@
PlatformWebView webView(context.get());
setPageLoaderClient(webView.page());
- WKRetainPtr<WKDataRef> data = ""
+ WKRetainPtr<WKDataRef> data = ""
EXPECT_NOT_NULL(data);
- WKPageRestoreFromSessionState(webView.page(), data.get());
+ auto sessionState = adoptWK(WKSessionStateCreateFromData(data.get()));
+ WKPageRestoreFromSessionState(webView.page(), sessionState.get());
+
Util::run(&didFinishLoad);
EXPECT_TRUE(WKPageCanGoBack(webView.page()));
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp (170682 => 170683)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp 2014-07-02 00:43:42 UTC (rev 170682)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp 2014-07-02 00:47:19 UTC (rev 170683)
@@ -48,7 +48,7 @@
WKPageSetPageLoaderClient(page, &loaderClient.base);
}
-static WKRetainPtr<WKDataRef> createSessionState(WKContextRef context)
+static WKRetainPtr<WKSessionStateRef> createSessionState(WKContextRef context)
{
PlatformWebView webView(context);
setPageLoaderClient(webView.page());
@@ -57,7 +57,7 @@
Util::run(&didFinishLoad);
didFinishLoad = false;
- return adoptWK(WKPageCopySessionState(webView.page(), 0, 0));
+ return adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), nullptr)));
}
TEST(WebKit2, WKPageGetScaleFactorNotZero)
@@ -67,10 +67,10 @@
PlatformWebView webView(context.get());
setPageLoaderClient(webView.page());
- WKRetainPtr<WKDataRef> data = ""
- EXPECT_NOT_NULL(data);
+ auto sessionState = createSessionState(context.get());
+ EXPECT_NOT_NULL(sessionState);
- WKPageRestoreFromSessionState(webView.page(), data.get());
+ WKPageRestoreFromSessionState(webView.page(), sessionState.get());
Util::run(&didFinishLoad);
EXPECT_TRUE(WKPageGetScaleFactor(webView.page()) == 1.0);