Skip to content

Commit 6429724

Browse files
committed
Add support for history.scrollRestoration
https://bugs.webkit.org/show_bug.cgi?id=147782 rdar://problem/22614568 Reviewed by Sam Weinig. LayoutTests/imported/w3c: New passing baselines. * web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic-expected.txt: * web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin-expected.txt: * web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-cross-origin-expected.txt: * web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc-expected.txt: Source/WebCore: Add support for history.scrollRestoration, per spec: <https://html.spec.whatwg.org/multipage/browsers.html#dom-history-scroll-restoration> This is a new attribute on the History interface. On setting, sets the "shouldRestoreScrollPosition" state on the current history item, and the getter returns that state. pushState() inherits the state from the current item. HistoryController::restoreScrollPositionAndViewState() consults this state, and if set to "manual" ("don't restore) it just uses the current scroll position (we need something to pass to setPageScaleFactor() so can't just avoid the restoration). FrameLoader::scrollToFragmentWithParentBoundary() also needs to consult the historyItem to know if it's OK to scroll to a fragment, on back/forward same-document loads. Tests: fast/history/history-scroll-restoration-attribute.html fast/history/history-scroll-restoration.html * history/HistoryItem.cpp: (WebCore::HistoryItem::HistoryItem): (WebCore::HistoryItem::shouldRestoreScrollPosition): (WebCore::HistoryItem::setShouldRestoreScrollPosition): * history/HistoryItem.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::loadInSameDocument): (WebCore::itemAllowsScrollRestoration): (WebCore::isSameDocumentReload): (WebCore::FrameLoader::scrollToFragmentWithParentBoundary): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): * loader/FrameLoader.h: * loader/HistoryController.cpp: (WebCore::HistoryController::restoreScrollPositionAndViewState): (WebCore::HistoryController::goToItem): (WebCore::HistoryController::pushState): (WebCore::HistoryController::replaceState): * page/History.cpp: (WebCore::History::scrollRestoration): (WebCore::History::setScrollRestoration): * page/History.h: * page/History.idl: Source/WebKit2: Need to send shouldRestoreScrollPosition to the UI process in SessionState, WKWebView now stores _unobscuredCenterToRestore and _scrollOffsetToRestore as std::optionals, and they will be nullopt if scroll restoration should not happen. ViewGestureControllerIOS also needs knowledge of whether scroll restoration will happen, and compares UI-process scroll position vs. the position at snapshot time to know if the snapshot should be shown (this prevents showing a misleading snapshot when swiping back on a navigation where scroll restoration is disabled). * Shared/SessionState.cpp: (WebKit::FrameState::encode): (WebKit::FrameState::decode): * Shared/SessionState.h: * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::pageState): * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _processDidExit]): (-[WKWebView _didCommitLayerTree:]): (-[WKWebView _restorePageScrollPosition:scrollOrigin:previousObscuredInset:scale:]): (-[WKWebView _restorePageStateToUnobscuredCenter:scale:]): * UIProcess/API/Cocoa/WKWebViewInternal.h: * UIProcess/API/gtk/PageClientImpl.cpp: (WebKit::PageClientImpl::viewScrollPosition): * UIProcess/API/gtk/PageClientImpl.h: * UIProcess/PageClient.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::viewScrollPosition): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/ios/PageClientImplIOS.h: * UIProcess/ios/PageClientImplIOS.mm: (WebKit::PageClientImpl::viewScrollPosition): (WebKit::PageClientImpl::restorePageState): (WebKit::PageClientImpl::restorePageCenterAndScale): * UIProcess/ios/ViewGestureControllerIOS.mm: (WebKit::ViewGestureController::beginSwipeGesture): * UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::restorePageState): (WebKit::WebPageProxy::restorePageCenterAndScale): * UIProcess/mac/PageClientImpl.h: * UIProcess/mac/PageClientImpl.mm: (WebKit::PageClientImpl::viewScrollPosition): * UIProcess/mac/ViewSnapshotStore.h: (WebKit::ViewSnapshot::setViewScrollPosition): (WebKit::ViewSnapshot::viewScrollPosition): * UIProcess/mac/ViewSnapshotStore.mm: (WebKit::ViewSnapshotStore::recordSnapshot): * WebProcess/WebCoreSupport/SessionStateConversion.cpp: (WebKit::toFrameState): (WebKit::applyFrameState): * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: (WebKit::WebFrameLoaderClient::restoreViewState): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::restorePageState): LayoutTests: Sadly history-scroll-restoration.html needs to be cloned for iOS and to use uiController.doAfterPresentationUpdate() there, since restoration involves a trip to the UI process, and this same test did not work for Mac WK1 (dispatch_async() doesn't seem to give the right timing in DRT). * TestExpectations: * fast/dom/Window/window-appendages-cleared-expected.txt: * fast/history/history-scroll-restoration-attribute-expected.txt: Added. * fast/history/history-scroll-restoration-attribute.html: Added. * fast/history/history-scroll-restoration-expected.txt: Added. * fast/history/history-scroll-restoration.html: Added. * platform/ios-simulator-wk2/TestExpectations: * platform/ios-simulator/TestExpectations: Canonical link: https://commits.webkit.org/186349@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213590 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9583464 commit 6429724

48 files changed

Lines changed: 566 additions & 104 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LayoutTests/ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2017-03-08 Simon Fraser <simon.fraser@apple.com>
2+
3+
Add support for history.scrollRestoration
4+
https://bugs.webkit.org/show_bug.cgi?id=147782
5+
rdar://problem/22614568
6+
7+
Reviewed by Sam Weinig.
8+
9+
Sadly history-scroll-restoration.html needs to be cloned for iOS and to use uiController.doAfterPresentationUpdate()
10+
there, since restoration involves a trip to the UI process, and this same test did not work for Mac WK1 (dispatch_async()
11+
doesn't seem to give the right timing in DRT).
12+
13+
* TestExpectations:
14+
* fast/dom/Window/window-appendages-cleared-expected.txt:
15+
* fast/history/history-scroll-restoration-attribute-expected.txt: Added.
16+
* fast/history/history-scroll-restoration-attribute.html: Added.
17+
* fast/history/history-scroll-restoration-expected.txt: Added.
18+
* fast/history/history-scroll-restoration.html: Added.
19+
* platform/ios-simulator-wk2/TestExpectations:
20+
* platform/ios-simulator/TestExpectations:
21+
122
2017-03-08 Chris Dumez <cdumez@apple.com>
223

324
[iOS] Throttle DOM timers to 30fps in low power mode

LayoutTests/TestExpectations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fast/viewport/ios [ Skip ]
2525
fast/visual-viewport/ios/ [ Skip ]
2626
fast/events/ios [ Skip ]
2727
fast/events/touch/ios [ Skip ]
28+
fast/history/ios [ Skip ]
2829
fast/scrolling/ios [ Skip ]
2930
scrollingcoordinator/ios [ Skip ]
3031
fast/content-observation [ Skip ]
@@ -1058,6 +1059,7 @@ webkit.org/b/168175 imported/w3c/web-platform-tests/html/semantics/embedded-cont
10581059
webkit.org/b/168175 imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/same-url.html [ Pass Failure ]
10591060
webkit.org/b/168175 imported/w3c/web-platform-tests/html/browsers/offline/browser-state/navigator_online_online.html [ Pass Failure ]
10601061
webkit.org/b/168175 imported/w3c/web-platform-tests/html/semantics/text-level-semantics/the-a-element/a-download-click.html [ Timeout Pass ]
1062+
webkit.org/b/169264 imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html [ Failure ]
10611063

10621064
webkit.org/b/168066 performance-api/performance-now-api.html [ Pass Failure ]
10631065
webkit.org/b/168005 performance-api/performance-now-time-origin-in-worker.html [ Pass Failure ]

LayoutTests/fast/dom/Window/window-appendages-cleared-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PASS history.go == "LEFTOVER" is false
44
PASS history.length == "LEFTOVER" is false
55
PASS history.pushState == "LEFTOVER" is false
66
PASS history.replaceState == "LEFTOVER" is false
7+
PASS history.scrollRestoration == "LEFTOVER" is false
78
PASS history.state == "LEFTOVER" is false
89
PASS location.ancestorOrigins == "LEFTOVER" is false
910
PASS location.assign == "LEFTOVER" is false
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Tests the history.scrollRestoration attribute
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS 'scrollRestoration' in history is true
7+
PASS history.scrollRestoration is "auto"
8+
PASS history.scrollRestoration is "manual"
9+
PASS history.scrollRestoration is "manual"
10+
PASS history.scrollRestoration is "auto"
11+
PASS successfullyParsed is true
12+
13+
TEST COMPLETE
14+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<html>
2+
<head>
3+
<script src="../../resources/js-test-pre.js"></script>
4+
</head>
5+
<body>
6+
<script>
7+
description("Tests the history.scrollRestoration attribute");
8+
9+
if (window.testRunner)
10+
testRunner.clearBackForwardList();
11+
12+
shouldBeTrue("'scrollRestoration' in history");
13+
14+
history.scrollRestoration = 'auto';
15+
shouldBeEqualToString('history.scrollRestoration', 'auto');
16+
17+
history.scrollRestoration = 'manual';
18+
shouldBeEqualToString('history.scrollRestoration', 'manual');
19+
20+
history.scrollRestoration = 'bananas';
21+
shouldBeEqualToString('history.scrollRestoration', 'manual');
22+
23+
history.scrollRestoration = 'auto';
24+
shouldBeEqualToString('history.scrollRestoration', 'auto');
25+
26+
</script>
27+
<script src="../../resources/js-test-post.js"></script>
28+
</body>
29+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Tests that history.scrollRestoration works for same-document navigations
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS 'scrollRestoration' in history is true
7+
PASS history.scrollRestoration is "auto"
8+
PASS window.scrollX is 123
9+
PASS window.scrollY is 456
10+
PASS history.scrollRestoration is "manual"
11+
PASS window.scrollX is 333
12+
PASS window.scrollY is 555
13+
PASS successfullyParsed is true
14+
15+
TEST COMPLETE
16+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<html>
2+
<head>
3+
<script src="../../resources/js-test-pre.js"></script>
4+
<style>
5+
body {
6+
height: 2000px;
7+
width: 2000px;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
<script>
13+
var jsTestIsAsync = true;
14+
15+
description("Tests that history.scrollRestoration works for same-document navigations");
16+
17+
if (window.testRunner)
18+
testRunner.clearBackForwardList();
19+
20+
shouldBeTrue("'scrollRestoration' in history");
21+
22+
// Can't create history entries inside the onload handler.
23+
window.setTimeout(testAutoScrollRestoration, 0);
24+
25+
function testAutoScrollRestoration()
26+
{
27+
history.scrollRestoration = 'auto';
28+
shouldBeEqualToString('history.scrollRestoration', 'auto');
29+
30+
window.scrollTo(123, 456);
31+
history.pushState(null, '', '#1');
32+
window.scrollTo(0, 0);
33+
history.back();
34+
35+
window.setTimeout(function () {
36+
shouldBe('window.scrollX', '123');
37+
shouldBe('window.scrollY', '456');
38+
39+
testManualScrollRestoration();
40+
}, 0);
41+
}
42+
43+
function testManualScrollRestoration()
44+
{
45+
history.scrollRestoration = 'manual';
46+
shouldBeEqualToString('history.scrollRestoration', 'manual');
47+
48+
window.scrollTo(234, 567);
49+
history.pushState(null, '', '#2');
50+
window.scrollTo(333, 555);
51+
history.back();
52+
53+
window.setTimeout(function() {
54+
shouldBe('window.scrollX', '333');
55+
shouldBe('window.scrollY', '555');
56+
window.scrollTo(0, 0);
57+
finishJSTest();
58+
}, 0);
59+
}
60+
61+
</script>
62+
<script src="../../resources/js-test-post.js"></script>
63+
</body>
64+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Tests that history.scrollRestoration works for same-document navigations
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS 'scrollRestoration' in history is true
7+
PASS history.scrollRestoration is "auto"
8+
PASS window.scrollX is 123
9+
PASS window.scrollY is 456
10+
PASS history.scrollRestoration is "manual"
11+
PASS window.scrollX is 333
12+
PASS window.scrollY is 555
13+
PASS successfullyParsed is true
14+
15+
TEST COMPLETE
16+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<html>
2+
<head>
3+
<script src="../../../resources/js-test-pre.js"></script>
4+
<style>
5+
body {
6+
height: 2000px;
7+
width: 2000px;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
<script>
13+
var jsTestIsAsync = true;
14+
15+
description("Tests that history.scrollRestoration works for same-document navigations");
16+
17+
if (window.testRunner)
18+
testRunner.clearBackForwardList();
19+
20+
shouldBeTrue("'scrollRestoration' in history");
21+
22+
// Can't create history entries inside the onload handler.
23+
window.setTimeout(testAutoScrollRestoration, 0);
24+
25+
function waitForPresentationUpdateUIScript()
26+
{
27+
return `(function() {
28+
uiController.doAfterPresentationUpdate(function() {
29+
uiController.uiScriptComplete();
30+
});
31+
})()`;
32+
}
33+
34+
function testAutoScrollRestoration()
35+
{
36+
history.scrollRestoration = 'auto';
37+
shouldBeEqualToString('history.scrollRestoration', 'auto');
38+
39+
window.scrollTo(123, 456);
40+
history.pushState(null, '', '#1');
41+
window.scrollTo(0, 0);
42+
history.back();
43+
44+
testRunner.runUIScript(waitForPresentationUpdateUIScript(), function () {
45+
shouldBe('window.scrollX', '123');
46+
shouldBe('window.scrollY', '456');
47+
48+
testManualScrollRestoration();
49+
});
50+
}
51+
52+
function testManualScrollRestoration()
53+
{
54+
history.scrollRestoration = 'manual';
55+
shouldBeEqualToString('history.scrollRestoration', 'manual');
56+
57+
window.scrollTo(234, 567);
58+
history.pushState(null, '', '#2');
59+
window.scrollTo(333, 555);
60+
history.back();
61+
62+
testRunner.runUIScript(waitForPresentationUpdateUIScript(), function () {
63+
shouldBe('window.scrollX', '333');
64+
shouldBe('window.scrollY', '555');
65+
66+
window.scrollTo(0, 0);
67+
finishJSTest();
68+
});
69+
}
70+
71+
</script>
72+
<script src="../../../resources/js-test-post.js"></script>
73+
</body>
74+
</html>

LayoutTests/imported/w3c/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2017-03-08 Simon Fraser <simon.fraser@apple.com>
2+
3+
Add support for history.scrollRestoration
4+
https://bugs.webkit.org/show_bug.cgi?id=147782
5+
rdar://problem/22614568
6+
7+
Reviewed by Sam Weinig.
8+
9+
New passing baselines.
10+
11+
* web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic-expected.txt:
12+
* web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin-expected.txt:
13+
* web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-cross-origin-expected.txt:
14+
* web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc-expected.txt:
15+
116
2017-03-07 Jiewen Tan <jiewen_tan@apple.com>
217

318
[WebCrypto] Implement ECDH ImportKey/ExportKey operations

0 commit comments

Comments
 (0)