<!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>[203508] trunk</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/203508">203508</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-21 10:01:10 -0700 (Thu, 21 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebBackForwardList's currentIndex could get out of bounds when filtering items.
https://bugs.webkit.org/show_bug.cgi?id=159986

Source/WebKit2:

When generating a new BackForwardListState object, if we filter out multiple items in the list, the currentIndex could get
out of bounds.

Patch by Yongjun Zhang &lt;yongjun_zhang@apple.com&gt; on 2016-07-21
Reviewed by Dan Bernstein.

* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::backForwardListState): Make currentIndex point to the last item if it is out of bounds.

Tools:

Add a test to verify filtering out 2 items from a 3-item list will set the currentIndex
to 0.

Patch by Yongjun Zhang &lt;yongjun_zhang@apple.com&gt; on 2016-07-21
Reviewed by Dan Bernstein.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm: Added.
(-[WKBackForwardListTestNavigationDelegate webView:didFinishNavigation:]):
(TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebBackForwardListcpp">trunk/Source/WebKit2/UIProcess/WebBackForwardList.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2WKBackForwardListmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (203507 => 203508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-07-21 16:59:33 UTC (rev 203507)
+++ trunk/Source/WebKit2/ChangeLog        2016-07-21 17:01:10 UTC (rev 203508)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-07-21  Yongjun Zhang  &lt;yongjun_zhang@apple.com&gt;
+
+        WebBackForwardList's currentIndex could get out of bounds when filtering items.
+        https://bugs.webkit.org/show_bug.cgi?id=159986
+
+        When generating a new BackForwardListState object, if we filter out multiple items in the list, the currentIndex could get
+        out of bounds.
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::backForwardListState): Make currentIndex point to the last item if it is out of bounds.
+
</ins><span class="cx"> 2016-07-21  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Automation: Allow JavaScript evaluation to return an InvalidElementState error
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebBackForwardListcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebBackForwardList.cpp (203507 => 203508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebBackForwardList.cpp        2016-07-21 16:59:33 UTC (rev 203507)
+++ trunk/Source/WebKit2/UIProcess/WebBackForwardList.cpp        2016-07-21 17:01:10 UTC (rev 203508)
</span><span class="lines">@@ -416,6 +416,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (backForwardListState.items.isEmpty())
</span><span class="cx">         backForwardListState.currentIndex = Nullopt;
</span><ins>+    else if (backForwardListState.items.size() &lt;= backForwardListState.currentIndex.value())
+        backForwardListState.currentIndex = backForwardListState.items.size() - 1;
</ins><span class="cx"> 
</span><span class="cx">     return backForwardListState;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (203507 => 203508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-07-21 16:59:33 UTC (rev 203507)
+++ trunk/Tools/ChangeLog        2016-07-21 17:01:10 UTC (rev 203508)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-07-21  Yongjun Zhang  &lt;yongjun_zhang@apple.com&gt;
+
+        WebBackForwardList's currentIndex could get out of bounds when filtering items.
+        https://bugs.webkit.org/show_bug.cgi?id=159986
+
+        Add a test to verify filtering out 2 items from a 3-item list will set the currentIndex
+        to 0.
+
+        Reviewed by Dan Bernstein.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm: Added.
+        (-[WKBackForwardListTestNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+
</ins><span class="cx"> 2016-07-21  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Web view background colors don't work in accelerated compositing mode
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (203507 => 203508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-07-21 16:59:33 UTC (rev 203507)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-07-21 17:01:10 UTC (rev 203508)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx">                 1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */; };
</span><span class="cx">                 1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
</span><span class="cx">                 1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
</span><ins>+                1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */; };
</ins><span class="cx">                 26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
</span><span class="cx">                 26F52EAD1828827B0023D412 /* geolocationGetCurrentPosition.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAC1828820E0023D412 /* geolocationGetCurrentPosition.html */; };
</span><span class="cx">                 26F52EAF18288C230023D412 /* geolocationGetCurrentPositionWithHighAccuracy.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAE18288C040023D412 /* geolocationGetCurrentPositionWithHighAccuracy.html */; };
</span><span class="lines">@@ -651,6 +652,7 @@
</span><span class="cx">                 1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRetainPtr.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKBackForwardList.mm; path = Tests/WebKit2/WKBackForwardList.mm; sourceTree = SOURCE_ROOT; };
</ins><span class="cx">                 260BA5781B1D2E7B004FA07C /* DFACombiner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DFACombiner.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 260BA57A1B1D2EE2004FA07C /* DFAHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DFAHelpers.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SetAndUpdateCacheModel.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1249,6 +1251,7 @@
</span><span class="cx">                                 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
</span><span class="cx">                                 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */,
</span><span class="cx">                                 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */,
</span><ins>+                                1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = &quot;WebKit2 Cocoa&quot;;
</span><span class="cx">                         path = WebKit2Cocoa;
</span><span class="lines">@@ -2211,6 +2214,7 @@
</span><span class="cx">                                 7CCE7F2C1A411B1000447C4C /* PreventImageLoadWithAutoResizing.mm in Sources */,
</span><span class="cx">                                 7CCE7F0C1A411AE600447C4C /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
</span><span class="cx">                                 7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
</span><ins>+                                1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */,
</ins><span class="cx">                                 7C83E0511D0A641800FEBCF3 /* ParsedContentRange.cpp in Sources */,
</span><span class="cx">                                 46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */,
</span><span class="cx">                                 7C3965061CDD74F90094DBB8 /* Color.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2WKBackForwardListmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm (0 => 203508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm        2016-07-21 17:01:10 UTC (rev 203508)
</span><span class="lines">@@ -0,0 +1,94 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;Test.h&quot;
+
+#import &lt;WebKit/WKBackForwardListPrivate.h&gt;
+#import &lt;WebKit/WKNavigationDelegate.h&gt;
+#import &lt;WebKit/WKNavigationPrivate.h&gt;
+#import &lt;WebKit/WKWebViewPrivate.h&gt;
+#import &lt;WebKit/_WKSessionState.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+#if WK_API_ENABLED
+
+static bool isDone;
+
+@interface WKBackForwardListTestNavigationDelegate : NSObject &lt;WKNavigationDelegate&gt;
+@end
+
+@implementation WKBackForwardListTestNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    isDone = true;
+}
+
+@end
+
+static NSString *loadableURL1 = @&quot;data:text/html,no%20error%20A&quot;;
+static NSString *loadableURL2 = @&quot;data:text/html,no%20error%20B&quot;;
+static NSString *loadableURL3 = @&quot;data:text/html,no%20error%20C&quot;;
+
+TEST(WKBackForwardList, RemoveCurrentItem)
+{
+    auto webView = adoptNS([[WKWebView alloc] init]);
+    auto controller = adoptNS([[WKBackForwardListTestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:controller.get()];
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]];
+    TestWebKitAPI::Util::run(&amp;isDone);
+    isDone = false;
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL2]]];
+    TestWebKitAPI::Util::run(&amp;isDone);
+    isDone = false;
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL3]]];
+    TestWebKitAPI::Util::run(&amp;isDone);
+    isDone = false;
+
+    WKBackForwardList *list = [webView backForwardList];
+    EXPECT_EQ((NSUInteger)2, list.backList.count);
+    EXPECT_EQ((NSUInteger)0, list.forwardList.count);
+    EXPECT_STREQ([[list.currentItem URL] absoluteString].UTF8String, loadableURL3.UTF8String);
+
+    _WKSessionState *sessionState = [webView _sessionStateWithFilter:^BOOL(WKBackForwardListItem *item)
+    {
+        return [item.URL isEqual:[NSURL URLWithString:loadableURL2]];
+    }];
+
+    [webView _restoreSessionState:sessionState andNavigate:NO];
+
+    WKBackForwardList *newList = [webView backForwardList];
+
+    EXPECT_EQ((NSUInteger)0, newList.backList.count);
+    EXPECT_EQ((NSUInteger)0, newList.forwardList.count);
+    EXPECT_STREQ([[newList.currentItem URL] absoluteString].UTF8String, loadableURL2.UTF8String);
+}
+
+#endif
</ins></span></pre>
</div>
</div>

</body>
</html>