<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[170856] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/170856">170856</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-07-07 13:52:49 -0700 (Mon, 07 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add SPI for saving and restoring a WKWebView's _WKSessionState
https://bugs.webkit.org/show_bug.cgi?id=134693

Reviewed by Dan Bernstein.

* UIProcess/API/C/WKPage.cpp:
(WKPageRestoreFromSessionState):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _sessionState]):
(-[WKWebView _restoreFromSessionStateData:]):
(-[WKWebView _restoreFromSessionState:]):
(-[WKWebView _restoreSessionState:andNavigate:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/_WKSessionState.mm:
(-[_WKSessionState _initWithSessionState:]):
* UIProcess/API/Cocoa/_WKSessionStateInternal.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::restoreFromSessionState):
* UIProcess/WebPageProxy.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKSessionStatemm">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionState.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKSessionStateInternalh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionStateInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/ChangeLog        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2014-07-07  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Add SPI for saving and restoring a WKWebView's _WKSessionState
+        https://bugs.webkit.org/show_bug.cgi?id=134693
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageRestoreFromSessionState):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _sessionState]):
+        (-[WKWebView _restoreFromSessionStateData:]):
+        (-[WKWebView _restoreFromSessionState:]):
+        (-[WKWebView _restoreSessionState:andNavigate:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/_WKSessionState.mm:
+        (-[_WKSessionState _initWithSessionState:]):
+        * UIProcess/API/Cocoa/_WKSessionStateInternal.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::restoreFromSessionState):
+        * UIProcess/WebPageProxy.h:
+
+2014-07-07  Anders Carlsson  &lt;andersca@apple.com&gt;
+
</ins><span class="cx">         Add a stubbed out _WKSessionState class
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=134690
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -389,7 +389,7 @@
</span><span class="cx">         sessionState = toImpl(static_cast&lt;WKSessionStateRef&gt;(sessionStateRef))-&gt;sessionState();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    toImpl(pageRef)-&gt;restoreFromSessionState(WTF::move(sessionState));
</del><ins>+    toImpl(pageRef)-&gt;restoreFromSessionState(WTF::move(sessionState), true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> double WKPageGetTextZoomFactor(WKPageRef pageRef)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -67,6 +67,7 @@
</span><span class="cx"> #import &quot;_WKFindDelegate.h&quot;
</span><span class="cx"> #import &quot;_WKFormDelegate.h&quot;
</span><span class="cx"> #import &quot;_WKRemoteObjectRegistryInternal.h&quot;
</span><ins>+#import &quot;_WKSessionStateInternal.h&quot;
</ins><span class="cx"> #import &quot;_WKVisitedLinkProviderInternal.h&quot;
</span><span class="cx"> #import &quot;_WKWebsiteDataStoreInternal.h&quot;
</span><span class="cx"> #import &lt;JavaScriptCore/JSContext.h&gt;
</span><span class="lines">@@ -1591,9 +1592,9 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // FIXME: This should return a _WKSessionState object.
</span><del>-- (NSData *)_sessionState
</del><ins>+- (id)_sessionState
</ins><span class="cx"> {
</span><del>-    return [self _sessionStateData];
</del><ins>+    return adoptNS([[_WKSessionState alloc] _initWithSessionState:_page-&gt;sessionState()]).autorelease();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_restoreFromSessionStateData:(NSData *)sessionStateData
</span><span class="lines">@@ -1603,19 +1604,28 @@
</span><span class="cx">     if (!WebKit::decodeLegacySessionState(static_cast&lt;const uint8_t*&gt;(sessionStateData.bytes), sessionStateData.length, sessionState))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    uint64_t navigationID = _page-&gt;restoreFromSessionState(WTF::move(sessionState));
-    if (navigationID) {
</del><ins>+    if (uint64_t navigationID = _page-&gt;restoreFromSessionState(WTF::move(sessionState), true)) {
</ins><span class="cx">         // FIXME: This is not necessarily always a reload navigation.
</span><span class="cx">         _navigationState-&gt;createReloadNavigation(navigationID);
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// FIXME: This should take a _WKSessionState object.
-- (void)_restoreFromSessionState:(NSData *)sessionStateData
</del><ins>+// FIXME: Remove this once nobody is using it.
+- (void)_restoreFromSessionState:(id)sessionState
</ins><span class="cx"> {
</span><del>-    [self _restoreFromSessionStateData:sessionStateData];
</del><ins>+    [self _restoreSessionState:sessionState andNavigate:YES];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (WKNavigation *)_restoreSessionState:(_WKSessionState *)sessionState andNavigate:(BOOL)navigate
+{
+    if (uint64_t navigationID = _page-&gt;restoreFromSessionState(sessionState-&gt;_sessionState, navigate)) {
+        // FIXME: This is not necessarily always a reload navigation.
+        return _navigationState-&gt;createReloadNavigation(navigationID).autorelease();
+    }
+
+    return nil;
+}
+
</ins><span class="cx"> - (void)_close
</span><span class="cx"> {
</span><span class="cx">     _page-&gt;close();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> 
</span><span class="cx"> @class WKBrowsingContextHandle;
</span><span class="cx"> @class _WKRemoteObjectRegistry;
</span><ins>+@class _WKSessionState;
</ins><span class="cx"> @class _WKWebViewPrintFormatter;
</span><span class="cx"> 
</span><span class="cx"> @protocol WKHistoryDelegatePrivate;
</span><span class="lines">@@ -83,13 +84,17 @@
</span><span class="cx"> 
</span><span class="cx"> @property (nonatomic, readonly) pid_t _webProcessIdentifier;
</span><span class="cx"> 
</span><ins>+// FIXME: Remove these once nobody is using them.
</ins><span class="cx"> @property (nonatomic, readonly) NSData *_sessionStateData;
</span><span class="cx"> - (void)_restoreFromSessionStateData:(NSData *)sessionStateData;
</span><span class="cx"> 
</span><del>-// FIXME: Remove these once nobody is using them.
-@property (nonatomic, readonly) NSData *_sessionState;
-- (void)_restoreFromSessionState:(NSData *)sessionState;
</del><ins>+// FIXME: This should return a _WKSessionState object, not an id.
+@property (nonatomic, readonly) id _sessionState;
+- (WKNavigation *)_restoreSessionState:(_WKSessionState *)sessionState andNavigate:(BOOL)navigate;
</ins><span class="cx"> 
</span><ins>+// FIXME: Remove this once nobody is using it.
+- (void)_restoreFromSessionState:(id)sessionState;
+
</ins><span class="cx"> @property (nonatomic, setter=_setAllowsRemoteInspection:) BOOL _allowsRemoteInspection;
</span><span class="cx"> 
</span><span class="cx"> @property (nonatomic, setter=_setAddsVisitedLinks:) BOOL _addsVisitedLinks;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKSessionStatemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionState.mm (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionState.mm        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionState.mm        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -45,6 +45,16 @@
</span><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (instancetype)_initWithSessionState:(WebKit::SessionState)sessionState
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _sessionState = std::move(sessionState);
+
+    return self;
+}
+
</ins><span class="cx"> - (NSData *)data
</span><span class="cx"> {
</span><span class="cx">     return WebKit::encodeSessionState(_sessionState).autorelease();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKSessionStateInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionStateInternal.h (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionStateInternal.h        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSessionStateInternal.h        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -30,9 +30,12 @@
</span><span class="cx"> #import &quot;SessionState.h&quot;
</span><span class="cx"> 
</span><span class="cx"> @interface _WKSessionState () {
</span><ins>+@package
</ins><span class="cx">     WebKit::SessionState _sessionState;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (instancetype)_initWithSessionState:(WebKit::SessionState)sessionState;
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -1859,7 +1859,7 @@
</span><span class="cx">     return sessionState;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-uint64_t WebPageProxy::restoreFromSessionState(SessionState sessionState)
</del><ins>+uint64_t WebPageProxy::restoreFromSessionState(SessionState sessionState, bool navigate)
</ins><span class="cx"> {
</span><span class="cx">     bool hasBackForwardList = !!sessionState.backForwardListState.currentIndex;
</span><span class="cx"> 
</span><span class="lines">@@ -1872,15 +1872,17 @@
</span><span class="cx">         process().send(Messages::WebPage::RestoreSession(m_backForwardList-&gt;itemStates()), m_pageID);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // FIXME: Navigating should be separate from state restoration.
</del><ins>+    if (navigate) {
+        // FIXME: Navigating should be separate from state restoration.
</ins><span class="cx"> 
</span><del>-    if (!sessionState.provisionalURL.isNull())
-        return loadRequest(sessionState.provisionalURL);
</del><ins>+        if (!sessionState.provisionalURL.isNull())
+            return loadRequest(sessionState.provisionalURL);
</ins><span class="cx"> 
</span><del>-    if (hasBackForwardList) {
-        // FIXME: Do we have to null check the back forward list item here?
-        if (WebBackForwardListItem* item = m_backForwardList-&gt;currentItem())
-            return goToBackForwardItem(item);
</del><ins>+        if (hasBackForwardList) {
+            // FIXME: Do we have to null check the back forward list item here?
+            if (WebBackForwardListItem* item = m_backForwardList-&gt;currentItem())
+                return goToBackForwardItem(item);
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (170855 => 170856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-07-07 20:39:36 UTC (rev 170855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-07-07 20:52:49 UTC (rev 170856)
</span><span class="lines">@@ -550,7 +550,7 @@
</span><span class="cx">     void terminateProcess();
</span><span class="cx"> 
</span><span class="cx">     SessionState sessionState(const std::function&lt;bool (WebBackForwardListItem&amp;)&gt;&amp; = nullptr) const;
</span><del>-    uint64_t restoreFromSessionState(SessionState);
</del><ins>+    uint64_t restoreFromSessionState(SessionState, bool navigate);
</ins><span class="cx"> 
</span><span class="cx">     bool supportsTextZoom() const;
</span><span class="cx">     double textZoomFactor() const { return m_textZoomFactor; }
</span></span></pre>
</div>
</div>

</body>
</html>