- Revision
- 242027
- Author
- [email protected]
- Date
- 2019-02-24 20:47:23 -0800 (Sun, 24 Feb 2019)
Log Message
Cherry-pick r241950. rdar://problem/48317455
REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
https://bugs.webkit.org/show_bug.cgi?id=194924
<rdar://problem/48216125>
Reviewed by Geoffrey Garen.
Source/WebKit:
When process-swapping, we would create a new WebPage in the new process, which would
call restoreSessionInternal() to restore the HistoryItems based on the UIProcess's
backforward list. The issue is that this session restoring would send HistoryItem
updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.
With PSON though, this may end up overwriting values set by the previous process,
such as the scroll position.
Address the issue by temporarily disabling the HistoryItem update notifications to
the UIProcess while restoring a session.
* UIProcess/API/Cocoa/WKBackForwardListItem.mm:
(-[WKBackForwardListItem _scrollPosition]):
* UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::restoreSessionInternal):
Tools:
Add API test coverage.
* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241950 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-607-branch/Source/WebKit/ChangeLog (242026 => 242027)
--- branches/safari-607-branch/Source/WebKit/ChangeLog 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Source/WebKit/ChangeLog 2019-02-25 04:47:23 UTC (rev 242027)
@@ -1,5 +1,65 @@
2019-02-24 Babak Shafiei <[email protected]>
+ Cherry-pick r241950. rdar://problem/48317455
+
+ REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
+ https://bugs.webkit.org/show_bug.cgi?id=194924
+ <rdar://problem/48216125>
+
+ Reviewed by Geoffrey Garen.
+
+ Source/WebKit:
+
+ When process-swapping, we would create a new WebPage in the new process, which would
+ call restoreSessionInternal() to restore the HistoryItems based on the UIProcess's
+ backforward list. The issue is that this session restoring would send HistoryItem
+ updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.
+ With PSON though, this may end up overwriting values set by the previous process,
+ such as the scroll position.
+
+ Address the issue by temporarily disabling the HistoryItem update notifications to
+ the UIProcess while restoring a session.
+
+ * UIProcess/API/Cocoa/WKBackForwardListItem.mm:
+ (-[WKBackForwardListItem _scrollPosition]):
+ * UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::restoreSessionInternal):
+
+ Tools:
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241950 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-02-22 Chris Dumez <[email protected]>
+
+ REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
+ https://bugs.webkit.org/show_bug.cgi?id=194924
+ <rdar://problem/48216125>
+
+ Reviewed by Geoffrey Garen.
+
+ When process-swapping, we would create a new WebPage in the new process, which would
+ call restoreSessionInternal() to restore the HistoryItems based on the UIProcess's
+ backforward list. The issue is that this session restoring would send HistoryItem
+ updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.
+ With PSON though, this may end up overwriting values set by the previous process,
+ such as the scroll position.
+
+ Address the issue by temporarily disabling the HistoryItem update notifications to
+ the UIProcess while restoring a session.
+
+ * UIProcess/API/Cocoa/WKBackForwardListItem.mm:
+ (-[WKBackForwardListItem _scrollPosition]):
+ * UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::restoreSessionInternal):
+
+2019-02-24 Babak Shafiei <[email protected]>
+
Cherry-pick r241928. rdar://problem/48317429
Discard cached processes when clearing website data store
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItem.mm (242026 => 242027)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItem.mm 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItem.mm 2019-02-25 04:47:23 UTC (rev 242027)
@@ -71,6 +71,11 @@
return nullptr;
}
+- (CGPoint) _scrollPosition
+{
+ return CGPointMake(_item->pageState().mainFrameState.scrollPosition.x(), _item->pageState().mainFrameState.scrollPosition.y());
+}
+
#pragma mark WKObject protocol implementation
- (API::Object&)_apiObject
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h (242026 => 242027)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h 2019-02-25 04:47:23 UTC (rev 242027)
@@ -32,6 +32,8 @@
// For testing only.
- (CGImageRef)_copySnapshotForTesting WK_API_AVAILABLE(macosx(10.12.3), ios(10.3));
+@property (nonatomic) CGPoint _scrollPosition WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
@end
#endif
Modified: branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (242026 => 242027)
--- branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-02-25 04:47:23 UTC (rev 242027)
@@ -2692,6 +2692,9 @@
void WebPage::restoreSessionInternal(const Vector<BackForwardListItemState>& itemStates, WasRestoredByAPIRequest restoredByAPIRequest, WebBackForwardListProxy::OverwriteExistingItem overwrite)
{
+ // Since we're merely restoring HistoryItems from the UIProcess, there is no need to send HistoryItem update notifications back to the UIProcess.
+ // Also, with process-swap on navigation, these updates may actually overwrite important state in the UIProcess such as the scroll position.
+ SetForScope<void (*)(WebCore::HistoryItem&)> bypassHistoryItemUpdateNotifications(WebCore::notifyHistoryItemChanged, [](WebCore::HistoryItem&){});
for (const auto& itemState : itemStates) {
auto historyItem = toHistoryItem(itemState);
historyItem->setWasRestoredFromSession(restoredByAPIRequest == WasRestoredByAPIRequest::Yes);
Modified: branches/safari-607-branch/Tools/ChangeLog (242026 => 242027)
--- branches/safari-607-branch/Tools/ChangeLog 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Tools/ChangeLog 2019-02-25 04:47:23 UTC (rev 242027)
@@ -1,5 +1,53 @@
2019-02-24 Babak Shafiei <[email protected]>
+ Cherry-pick r241950. rdar://problem/48317455
+
+ REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
+ https://bugs.webkit.org/show_bug.cgi?id=194924
+ <rdar://problem/48216125>
+
+ Reviewed by Geoffrey Garen.
+
+ Source/WebKit:
+
+ When process-swapping, we would create a new WebPage in the new process, which would
+ call restoreSessionInternal() to restore the HistoryItems based on the UIProcess's
+ backforward list. The issue is that this session restoring would send HistoryItem
+ updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.
+ With PSON though, this may end up overwriting values set by the previous process,
+ such as the scroll position.
+
+ Address the issue by temporarily disabling the HistoryItem update notifications to
+ the UIProcess while restoring a session.
+
+ * UIProcess/API/Cocoa/WKBackForwardListItem.mm:
+ (-[WKBackForwardListItem _scrollPosition]):
+ * UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::restoreSessionInternal):
+
+ Tools:
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241950 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-02-22 Chris Dumez <[email protected]>
+
+ REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
+ https://bugs.webkit.org/show_bug.cgi?id=194924
+ <rdar://problem/48216125>
+
+ Reviewed by Geoffrey Garen.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
+2019-02-24 Babak Shafiei <[email protected]>
+
Cherry-pick r241948. rdar://problem/48317429
Unreviewed, disable API test added in r241928 on iOS.
Modified: branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (242026 => 242027)
--- branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-02-25 04:47:20 UTC (rev 242026)
+++ branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-02-25 04:47:23 UTC (rev 242027)
@@ -29,6 +29,7 @@
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
+#import <WebKit/WKBackForwardListItemPrivate.h>
#import <WebKit/WKContentRuleListStore.h>
#import <WebKit/WKNavigationDelegatePrivate.h>
#import <WebKit/WKNavigationPrivate.h>
@@ -4853,6 +4854,8 @@
EXPECT_EQ(pid1, pid5);
}
+#endif // PLATFORM(MAC)
+
static const char* tallPageBytes = R"PSONRESOURCE(
<!DOCTYPE html>
<html>
@@ -4867,11 +4870,30 @@
</style>
</head>
<body>
+<script>
+// Pages with dedicated workers do not go into page cache.
+var myWorker = new Worker('worker.js');
+</script>
<a id="testLink" href=""
</body>
</html>
)PSONRESOURCE";
+static unsigned waitUntilScrollPositionIsRestored(WKWebView *webView)
+{
+ unsigned scrollPosition = 0;
+ do {
+ [webView evaluateJavaScript:@"window.scrollY" completionHandler: [&] (id result, NSError *error) {
+ scrollPosition = [result integerValue];
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+ } while (!scrollPosition);
+
+ return scrollPosition;
+}
+
TEST(ProcessSwap, ScrollPositionRestoration)
{
auto processPoolConfiguration = psonProcessPoolConfiguration();
@@ -4883,8 +4905,6 @@
[handler addMappingFromURLString:@"pson://www.webkit.org/main.html" toData:tallPageBytes];
[webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
- [[webViewConfiguration preferences] _setUsesPageCache:NO];
-
auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
[webView setNavigationDelegate:delegate.get()];
@@ -4900,6 +4920,10 @@
TestWebKitAPI::Util::run(&done);
done = false;
+ do {
+ TestWebKitAPI::Util::sleep(0.05);
+ } while (lroundf([[[webView backForwardList] currentItem] _scrollPosition].y) != 5000);
+
[webView evaluateJavaScript:@"testLink.click()" completionHandler: nil];
TestWebKitAPI::Util::run(&done);
@@ -4916,16 +4940,39 @@
TestWebKitAPI::Util::run(&done);
done = false;
+ auto scrollPosition = waitUntilScrollPositionIsRestored(webView.get());
+ EXPECT_EQ(5000U, scrollPosition);
+
+ [webView evaluateJavaScript:@"scroll(0, 4000)" completionHandler: [&] (id result, NSError *error) {
+ done = true;
+ }];
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ do {
+ TestWebKitAPI::Util::sleep(0.05);
+ } while (lroundf([[[webView backForwardList] currentItem] _scrollPosition].y) != 4000);
+
+ [webView evaluateJavaScript:@"testLink.click()" completionHandler: nil];
+
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
[webView evaluateJavaScript:@"window.scrollY" completionHandler: [&] (id result, NSError *error) {
- EXPECT_EQ(5000, [result integerValue]);
+ EXPECT_EQ(0, [result integerValue]);
done = true;
}];
TestWebKitAPI::Util::run(&done);
done = false;
+
+ [webView goBack];
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ scrollPosition = waitUntilScrollPositionIsRestored(webView.get());
+ EXPECT_EQ(4000U, scrollPosition);
}
-#endif // PLATFORM(MAC)
-
static NSString *blockmeFilter = @"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*blockme.html\"}}]";
static const char* contentBlockingAfterProcessSwapTestBytes = R"PSONRESOURCE(