Title: [225288] trunk
Revision
225288
Author
simon.fra...@apple.com
Date
2017-11-29 12:41:47 -0800 (Wed, 29 Nov 2017)

Log Message

REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
https://bugs.webkit.org/show_bug.cgi?id=180155
rdar://problem/34220827

Reviewed by Zalan Bujtas.
Source/WebCore:

When content is loaded in a UIWebView or WKWebView via an HTML string, history().currentItem()
is null so itemAllowsScrollRestoration() would return false, preventing scrolling to anchors.

Fix by allowing scroll restoration if the the history item is null.

Tested by WebKit.NoHistoryItemScrollToFragment API test.

* loader/FrameLoader.cpp:
(WebCore::itemAllowsScrollRestoration):

Tools:

API test that loads a page with a relative anchor, and simulates a click to scroll to it.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm: Added.
(-[DidScrollToFragmentDelegate _webViewDidScroll:]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225287 => 225288)


--- trunk/Source/WebCore/ChangeLog	2017-11-29 20:30:37 UTC (rev 225287)
+++ trunk/Source/WebCore/ChangeLog	2017-11-29 20:41:47 UTC (rev 225288)
@@ -1,3 +1,21 @@
+2017-11-29  Simon Fraser  <simon.fra...@apple.com>
+
+        REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
+        https://bugs.webkit.org/show_bug.cgi?id=180155
+        rdar://problem/34220827
+
+        Reviewed by Zalan Bujtas.
+        
+        When content is loaded in a UIWebView or WKWebView via an HTML string, history().currentItem()
+        is null so itemAllowsScrollRestoration() would return false, preventing scrolling to anchors.
+
+        Fix by allowing scroll restoration if the the history item is null.
+
+        Tested by WebKit.NoHistoryItemScrollToFragment API test.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::itemAllowsScrollRestoration):
+
 2017-11-29  Chris Dumez  <cdu...@apple.com>
 
         Introduce ServiceWorkerContainer::ensureSWClientConnection()

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (225287 => 225288)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2017-11-29 20:30:37 UTC (rev 225287)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2017-11-29 20:41:47 UTC (rev 225288)
@@ -2889,7 +2889,7 @@
 
 static bool itemAllowsScrollRestoration(HistoryItem* historyItem)
 {
-    return historyItem && historyItem->shouldRestoreScrollPosition();
+    return !historyItem || historyItem->shouldRestoreScrollPosition();
 }
 
 static bool isSameDocumentReload(bool isNewNavigation, FrameLoadType loadType)

Modified: trunk/Tools/ChangeLog (225287 => 225288)


--- trunk/Tools/ChangeLog	2017-11-29 20:30:37 UTC (rev 225287)
+++ trunk/Tools/ChangeLog	2017-11-29 20:41:47 UTC (rev 225288)
@@ -1,3 +1,21 @@
+2017-11-29  Simon Fraser  <simon.fra...@apple.com>
+
+        REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
+        https://bugs.webkit.org/show_bug.cgi?id=180155
+        rdar://problem/34220827
+
+        Reviewed by Zalan Bujtas.
+
+        API test that loads a page with a relative anchor, and simulates a click to scroll to it.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm: Added.
+        (-[DidScrollToFragmentDelegate _webViewDidScroll:]):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html: Added.
+
 2017-11-29  Ryan Haddad  <ryanhad...@apple.com>
 
         webkitpy EWS should be present on the dashboard.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (225287 => 225288)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-11-29 20:30:37 UTC (rev 225287)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-11-29 20:41:47 UTC (rev 225288)
@@ -37,6 +37,8 @@
 		0F2C20B81DCD545000542D9E /* Time.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F2C20B71DCD544800542D9E /* Time.cpp */; };
 		0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */; };
 		0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */; };
+		0F5651F71FCE4DDC00310FBC /* NoHistoryItemScrollToFragment.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */; };
+		0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */; };
 		115EB3431EE0BA03003C2C0A /* ViewportSizeForViewportUnits.mm in Sources */ = {isa = PBXBuildFile; fileRef = 115EB3421EE0B720003C2C0A /* ViewportSizeForViewportUnits.mm */; };
 		1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
 		1A3524AE1D63A4FB0031729B /* Scope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3524AC1D63A4FB0031729B /* Scope.cpp */; };
@@ -1002,6 +1004,7 @@
 				F6FDDDD614241C6F004F1729 /* push-state.html in Copy Resources */,
 				A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */,
 				F46849C01EEF5EF300B937FE /* rich-and-plain-text.html in Copy Resources */,
+				0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */,
 				F4D65DA81F5E4704009D8C27 /* selected-text-image-link-and-editable.html in Copy Resources */,
 				7A66BDB81EAF18D500CCC924 /* set-long-title.html in Copy Resources */,
 				52B8CF9815868D9100281053 /* SetDocumentURI.html in Copy Resources */,
@@ -1071,6 +1074,8 @@
 		0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEvaluateJavaScript.mm; sourceTree = "<group>"; };
 		0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SnapshotViaRenderInContext.mm; sourceTree = "<group>"; };
 		0F4FFAA01ED3D0DE00F7111F /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
+		0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NoHistoryItemScrollToFragment.mm; sourceTree = "<group>"; };
+		0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "scroll-to-anchor.html"; sourceTree = "<group>"; };
 		0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RedBlackTree.cpp; sourceTree = "<group>"; };
 		0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MetaAllocator.cpp; sourceTree = "<group>"; };
 		0FE447971B76F1E3009498EB /* ParkingLot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParkingLot.cpp; sourceTree = "<group>"; };
@@ -2519,6 +2524,7 @@
 				93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */,
 				93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */,
 				93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */,
+				0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */,
 				7CCB4DA71C83AE7300CC6918 /* PageGroup.cpp */,
 				BC909779125571AB00083756 /* PageLoadBasic.cpp */,
 				BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */,
@@ -2707,6 +2713,7 @@
 				C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */,
 				CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
 				F6FDDDD514241C48004F1729 /* push-state.html */,
+				0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */,
 				7A66BDB71EAF150100CCC924 /* set-long-title.html */,
 				CEBABD481B71687C0051210A /* should-open-external-schemes.html */,
 				1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */,
@@ -3410,6 +3417,7 @@
 				7CCE7F031A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
 				7CCE7F041A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
 				7CCE7F051A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
+				0F5651F71FCE4DDC00310FBC /* NoHistoryItemScrollToFragment.mm in Sources */,
 				2ECFF5551D9B12F800B55394 /* NowPlayingControlsTests.mm in Sources */,
 				A10F047E1E3AD29C00C95E19 /* NSFileManagerExtras.mm in Sources */,
 				37A22AA71DCAA27200AFBFC4 /* ObservedRenderingProgressEventsAfterCrash.mm in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm (225287 => 225288)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm	2017-11-29 20:30:37 UTC (rev 225287)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm	2017-11-29 20:41:47 UTC (rev 225288)
@@ -80,8 +80,6 @@
     [webView loadTestPageNamed:@"mediastreamtrack-detached"];
 
     TestWebKitAPI::Util::run(&hasRecievedCorrectCaptureState);
-
-
 }
 
 } // namespace TestWebKitAPI

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm (0 => 225288)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm	2017-11-29 20:41:47 UTC (rev 225288)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKUIDelegatePrivate.h>
+#import <WebKit/WKWebViewConfiguration.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
+
+static bool testDone;
+
+@interface DidScrollToFragmentDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation DidScrollToFragmentDelegate
+
+- (void)_webViewDidScroll:(WKWebView *)webView
+{
+    testDone = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, NoHistoryItemScrollToFragment)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto processPoolConfig = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get() processPoolConfiguration:processPoolConfig.get()]);
+    auto delegate = adoptNS([[DidScrollToFragmentDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+
+    NSURL* resourceURL = [[NSBundle mainBundle] URLForResource:@"scroll-to-anchor" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    NSString *testFileContents = [NSString stringWithContentsOfURL:resourceURL encoding:NSUTF8StringEncoding error:nil];
+    [webView synchronouslyLoadHTMLString:testFileContents];
+
+    TestWebKitAPI::Util::run(&testDone);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html (0 => 225288)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html	2017-11-29 20:41:47 UTC (rev 225288)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+    .spacer {
+        height: 500px;
+        background-color: silver;
+        margin: 10px;
+    }
+    </style>
+    <script>
+        function doTest()
+        {
+            setTimeout(function() {
+                var link = document.getElementById('test-link');
+                link.click();
+            }, 0);
+        }
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+<ul>
+    <li><a id="test-link" href="" to target</a></li>
+</ul>
+
+<div class="spacer"></div>
+<div class="spacer"></div>
+<div class="spacer"></div>
+
+<h2 id="target">Target link</h2>
+
+<div class="spacer"></div>
+<div class="spacer"></div>
+
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to