Title: [207603] branches/safari-602-branch

Diff

Modified: branches/safari-602-branch/Source/WebKit2/ChangeLog (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/ChangeLog	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/ChangeLog	2016-10-20 09:59:53 UTC (rev 207603)
@@ -1,5 +1,51 @@
 2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r206833. rdar://problem/28634858
+
+    2016-10-05  Tim Horton  <timothy_hor...@apple.com>
+
+            Avoid automatically re-taking snapshots for back-forward items that were never loaded into the view
+            https://bugs.webkit.org/show_bug.cgi?id=162955
+            <rdar://problem/27659173>
+
+            Reviewed by Simon Fraser.
+
+            Make it possible for clients to control the snapshot for back-forward
+            items that are restored from session state without navigating to them,
+            by ensuring that we won't stomp on the snapshot that they explicitly take,
+            until a load occurs.
+
+            * UIProcess/WebBackForwardList.cpp:
+            (WebKit::WebBackForwardList::addItem):
+            (WebKit::WebBackForwardList::goToItem):
+            * UIProcess/ios/ViewGestureControllerIOS.mm:
+            (WebKit::ViewGestureController::beginSwipeGesture):
+            * UIProcess/mac/ViewGestureControllerMac.mm:
+            (WebKit::ViewGestureController::trackSwipeGesture):
+            Disambiguate explicit API-driven snapshot recording from automatic,
+            navigation-driven snapshot recording.
+
+            * UIProcess/Cocoa/WebViewImpl.mm:
+            (WebKit::WebViewImpl::saveBackForwardSnapshotForCurrentItem):
+            Get rid of the version of recordNavigationSnapshot() that doesn't take a
+            back-forward list item, and grab the current item at the one remaining caller.
+
+            * UIProcess/WebPageProxy.cpp:
+            (WebKit::WebPageProxy::recordAutomaticNavigationSnapshot):
+            (WebKit::WebPageProxy::recordNavigationSnapshot):
+            (WebKit::WebPageProxy::restoreFromSessionState):
+            (WebKit::WebPageProxy::didCommitLoadForFrame):
+            * UIProcess/WebPageProxy.h:
+            Rename m_suppressNavigationSnapshotting to m_suppressAutomaticNavigationSnapshotting,
+            and make it be only about automatic (navigation-driven) snapshots; it won't have
+            any impact on explicit snapshots forced by clients.
+
+            Set m_suppressAutomaticNavigationSnapshotting unconditionally when restoring
+            from session state, so that we won't start automatically snapshotting until
+            something has loaded in the view.
+
+2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r206829. rdar://problem/28634858
 
     2016-10-05  Tim Horton  <timothy_hor...@apple.com>

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-10-20 09:59:53 UTC (rev 207603)
@@ -3177,7 +3177,8 @@
 
 void WebViewImpl::saveBackForwardSnapshotForCurrentItem()
 {
-    m_page->recordNavigationSnapshot();
+    if (WebBackForwardListItem* item = m_page->backForwardList().currentItem())
+        m_page->recordNavigationSnapshot(*item);
 }
 
 void WebViewImpl::saveBackForwardSnapshotForItem(WebBackForwardListItem& item)

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebBackForwardList.cpp (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebBackForwardList.cpp	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebBackForwardList.cpp	2016-10-20 09:59:53 UTC (rev 207603)
@@ -93,7 +93,7 @@
     Vector<RefPtr<WebBackForwardListItem>> removedItems;
     
     if (m_hasCurrentIndex) {
-        m_page->recordNavigationSnapshot();
+        m_page->recordAutomaticNavigationSnapshot();
 
         // Toss everything in the forward list.
         unsigned targetSize = m_currentIndex + 1;
@@ -187,7 +187,7 @@
     WebBackForwardListItem* currentItem = m_entries[m_currentIndex].get();
     bool shouldKeepCurrentItem = true;
     if (currentItem != item) {
-        m_page->recordNavigationSnapshot();
+        m_page->recordAutomaticNavigationSnapshot();
         shouldKeepCurrentItem = m_page->shouldKeepCurrentBackForwardListItemInList(m_entries[m_currentIndex].get());
     }
 

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-20 09:59:53 UTC (rev 207603)
@@ -1183,8 +1183,11 @@
     return WTFMove(navigation);
 }
 
-void WebPageProxy::recordNavigationSnapshot()
+void WebPageProxy::recordAutomaticNavigationSnapshot()
 {
+    if (m_suppressAutomaticNavigationSnapshotting)
+        return;
+
     if (WebBackForwardListItem* item = m_backForwardList->currentItem())
         recordNavigationSnapshot(*item);
 }
@@ -1191,7 +1194,7 @@
 
 void WebPageProxy::recordNavigationSnapshot(WebBackForwardListItem& item)
 {
-    if (!m_shouldRecordNavigationSnapshots || m_suppressNavigationSnapshotting)
+    if (!m_shouldRecordNavigationSnapshots)
         return;
 
 #if PLATFORM(COCOA)
@@ -2388,11 +2391,9 @@
 
         process().send(Messages::WebPage::RestoreSession(m_backForwardList->itemStates()), m_pageID);
 
-        if (navigate) {
-            // The back / forward list was restored from a sessionState so we don't want to snapshot the current
-            // page when navigating away. Suppress navigation snapshotting until the next load has committed
-            m_suppressNavigationSnapshotting = true;
-        }
+        // The back / forward list was restored from a sessionState so we don't want to snapshot the current
+        // page when navigating away. Suppress navigation snapshotting until the next load has committed
+        m_suppressAutomaticNavigationSnapshotting = true;
     }
 
     // FIXME: Navigating should be separate from state restoration.
@@ -3246,7 +3247,7 @@
 
     if (frame->isMainFrame()) {
         m_pageLoadState.didCommitLoad(transaction, webCertificateInfo, markPageInsecure);
-        m_suppressNavigationSnapshotting = false;
+        m_suppressAutomaticNavigationSnapshotting = false;
     } else if (markPageInsecure)
         m_pageLoadState.didDisplayOrRunInsecureContent(transaction);
 

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-20 09:59:53 UTC (rev 207603)
@@ -1002,7 +1002,7 @@
 
     bool shouldRecordNavigationSnapshots() const { return m_shouldRecordNavigationSnapshots; }
     void setShouldRecordNavigationSnapshots(bool shouldRecordSnapshots) { m_shouldRecordNavigationSnapshots = shouldRecordSnapshots; }
-    void recordNavigationSnapshot();
+    void recordAutomaticNavigationSnapshot();
     void recordNavigationSnapshot(WebBackForwardListItem&);
 
 #if PLATFORM(COCOA)
@@ -1828,7 +1828,7 @@
     bool m_waitingForDidUpdateViewState;
 
     bool m_shouldScaleViewToFitDocument { false };
-    bool m_suppressNavigationSnapshotting { false };
+    bool m_suppressAutomaticNavigationSnapshotting { false };
 
 #if PLATFORM(COCOA)
     HashMap<String, String> m_temporaryPDFFiles;

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2016-10-20 09:59:53 UTC (rev 207603)
@@ -158,7 +158,7 @@
     if (m_activeGestureType != ViewGestureType::None)
         return;
 
-    m_webPageProxy.recordNavigationSnapshot();
+    m_webPageProxy.recordAutomaticNavigationSnapshot();
 
     m_webPageProxyForBackForwardListForCurrentSwipe = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page : &m_webPageProxy;
     m_webPageProxyForBackForwardListForCurrentSwipe->navigationGestureDidBegin();

Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (207602 => 207603)


--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-20 09:59:53 UTC (rev 207603)
@@ -399,7 +399,7 @@
 
     m_pendingSwipeTracker.reset("starting to track swipe");
 
-    m_webPageProxy.recordNavigationSnapshot();
+    m_webPageProxy.recordAutomaticNavigationSnapshot();
 
     BOOL swipingLeft = isPhysicallySwipingLeft(direction);
     CGFloat maxProgress = swipingLeft ? 1 : 0;

Modified: branches/safari-602-branch/Tools/ChangeLog (207602 => 207603)


--- branches/safari-602-branch/Tools/ChangeLog	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Tools/ChangeLog	2016-10-20 09:59:53 UTC (rev 207603)
@@ -1,5 +1,40 @@
 2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r206833. rdar://problem/28634858
+
+    2016-10-05  Tim Horton  <timothy_hor...@apple.com>
+
+            Avoid automatically re-taking snapshots for back-forward items that were never loaded into the view
+            https://bugs.webkit.org/show_bug.cgi?id=162955
+            <rdar://problem/27659173>
+
+            Reviewed by Simon Fraser.
+
+            * TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm:
+            (-[SnapshotTestWKWebView init]):
+            (forceRepaintCallback):
+            (-[SnapshotTestWKWebView synchronouslyForceRepaint]):
+            (-[SnapshotTestWKWebView synchronouslyLoadTestPageAndForceRepaint:]):
+            (TEST):
+            (makeRedSquareView):
+            Add a test that restoring session state into a web view without navigating,
+            then explicitly snapshotting and navigating away, leaves the original snapshot alone.
+
+            Adjust the existing test, as well, to ensure that it will reliably fail
+            if the feature is broken. Use an explicitly added and removed red square
+            instead of scrolling, because we can't scroll in the restore-without-navigating case.
+
+            Stop trying to override the window scale, because it's not working (we're getting partial snapshots)
+            and isn't necessary; instead just multiply the expected value by the page scale.
+
+            (-[SnapshotTestWKWebView loadPageNamed:]): Deleted.
+            * TestWebKitAPI/mac/TestWKWebViewMac.h:
+            * TestWebKitAPI/mac/TestWKWebViewMac.mm:
+            (-[TestWKWebView synchronouslyLoadTestPageNamed:]):
+            Reorganize to reduce duplication.
+
+2016-10-20  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r206829. rdar://problem/28634858
 
     2016-10-05  Tim Horton  <timothy_hor...@apple.com>

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm (207602 => 207603)


--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm	2016-10-20 09:59:53 UTC (rev 207603)
@@ -28,22 +28,21 @@
 
 #if WK_API_ENABLED && PLATFORM(MAC)
 
-#import "_javascript_Test.h"
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import "TestNavigationDelegate.h"
 #import "TestWKWebViewMac.h"
 #import <WebKit/WKBackForwardListItemPrivate.h>
+#import <WebKit/WKPage.h>
+#import <WebKit/WKPagePrivate.h>
 #import <WebKit/WKWebView.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
+static bool didForceRepaint;
+
 using namespace TestWebKitAPI;
 
-@interface NSWindow ()
-- (void)_setWindowResolution:(CGFloat)resolution displayIfChanged:(BOOL)displayIfChanged;
-@end
-
 @interface WKWebView ()
 - (WKPageRef)_pageForTesting;
 @end
@@ -58,23 +57,35 @@
 {
     self = [super initWithFrame:NSMakeRect(0, 0, 800, 600)];
     if (self) {
-        [self _setOverrideDeviceScaleFactor:1];
         [self _disableBackForwardSnapshotVolatilityForTesting];
         [self setAllowsBackForwardNavigationGestures:YES];
         [self _setWindowOcclusionDetectionEnabled:NO];
 
-        [self.window _setWindowResolution:1 displayIfChanged:YES];
         [self.window orderBack:nil];
     }
     return self;
 }
 
-- (void)loadPageNamed:(NSString *)pageName
+static void forceRepaintCallback(WKErrorRef error, void*)
 {
-    [self loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:pageName withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
-    [self _test_waitForDidFinishNavigation];
+    EXPECT_NULL(error);
+    didForceRepaint = true;
 }
 
+- (void)synchronouslyForceRepaint
+{
+    didForceRepaint = false;
+    WKPageForceRepaint([self _pageForTesting], 0, forceRepaintCallback);
+    TestWebKitAPI::Util::run(&didForceRepaint);
+}
+
+- (void)synchronouslyLoadTestPageAndForceRepaint:(NSString *)testPageName
+{
+    [self synchronouslyLoadTestPageNamed:testPageName];
+    [self synchronouslyForceRepaint];
+    [[self window] display];
+}
+
 @end
 
 static bool imagesAreEqual(CGImageRef first, CGImageRef second)
@@ -89,7 +100,7 @@
 {
     RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
 
-    [webView loadPageNamed:@"simple"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
 
     RetainPtr<WKBackForwardListItem> firstItem = [[webView backForwardList] currentItem];
 
@@ -96,12 +107,12 @@
     RetainPtr<CGImageRef> imageBeforeNavigation = adoptCF([firstItem _copySnapshotForTesting]);
     EXPECT_NULL(imageBeforeNavigation.get());
 
-    [webView loadPageNamed:@"lots-of-text"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"lots-of-text"];
 
     // After navigating, the first item should have a valid back-forward snapshot.
     RetainPtr<CGImageRef> imageAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
     EXPECT_NOT_NULL(imageAfterNavigation.get());
-    EXPECT_EQ(CGImageGetWidth(imageAfterNavigation.get()), (unsigned long)800);
+    EXPECT_EQ(CGImageGetWidth(imageAfterNavigation.get()), (unsigned long)(800 * [webView window].backingScaleFactor));
 }
 
 TEST(SnapshotStore, SnapshotClearedWhenItemIsRemoved)
@@ -108,12 +119,12 @@
 {
     RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
 
-    [webView loadPageNamed:@"simple"];
-    [webView loadPageNamed:@"lots-of-text"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"lots-of-text"];
 
     RetainPtr<WKBackForwardListItem> item = [[webView backForwardList] currentItem];
 
-    [webView loadPageNamed:@"simple"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
 
     EXPECT_NOT_NULL(adoptCF([item _copySnapshotForTesting]).get());
 
@@ -125,7 +136,7 @@
     // The original second item is still in the forward list, and should still have a snapshot.
     EXPECT_NOT_NULL(adoptCF([item _copySnapshotForTesting]).get());
 
-    [webView loadPageNamed:@"lots-of-text"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"lots-of-text"];
 
     // The original second item shouldn't have an image anymore, because it was invalidated
     // by navigating back past it and then doing another load.
@@ -132,20 +143,31 @@
     EXPECT_NULL(adoptCF([item _copySnapshotForTesting]).get());
 }
 
+static RetainPtr<NSView> makeRedSquareView()
+{
+    RetainPtr<NSBox> redSquare = adoptNS([[NSBox alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]);
+    [redSquare setBoxType:NSBoxCustom];
+    [redSquare setFillColor:[NSColor redColor]];
+    return redSquare;
+}
+
 TEST(SnapshotStore, ExplicitSnapshotsChangeUponNavigation)
 {
     RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
 
-    [webView loadPageNamed:@"lots-of-text"];
+    RetainPtr<NSView> redSquare = makeRedSquareView();
+    [[webView superview] addSubview:redSquare.get()];
 
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"lots-of-text"];
+
     RetainPtr<WKBackForwardListItem> firstItem = [[webView backForwardList] currentItem];
     [webView _saveBackForwardSnapshotForItem:firstItem.get()];
+    [redSquare removeFromSuperview];
 
     RetainPtr<CGImageRef> initialSnapshot = adoptCF([firstItem _copySnapshotForTesting]);
     EXPECT_NOT_NULL(initialSnapshot);
 
-    EXPECT_JS_EQ([webView _pageForTesting], "window.scrollTo(0,100)", "undefined");
-    [webView loadPageNamed:@"simple"];
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
 
     // After navigating, the first item's snapshot should change.
     RetainPtr<CGImageRef> snapshotAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
@@ -153,4 +175,34 @@
     EXPECT_FALSE(imagesAreEqual(initialSnapshot.get(), snapshotAfterNavigation.get()));
 }
 
+TEST(SnapshotStore, SnapshotsForNeverLoadedPagesDoNotChangeUponNavigation)
+{
+    RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    RetainPtr<NSView> redSquare = makeRedSquareView();
+    [[webView superview] addSubview:redSquare.get()];
+
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
+
+    WKRetainPtr<WKSessionStateRef> sessionState = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState([webView _pageForTesting], nullptr, nullptr)));
+    WKPageRestoreFromSessionStateWithoutNavigation([webView _pageForTesting], sessionState.get());
+
+    RetainPtr<WKBackForwardListItem> firstItem = [[webView backForwardList] currentItem];
+    [webView _saveBackForwardSnapshotForItem:firstItem.get()];
+    [redSquare removeFromSuperview];
+
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"lots-of-text"];
+
+    RetainPtr<CGImageRef> initialSnapshot = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(initialSnapshot);
+
+    [webView synchronouslyLoadTestPageAndForceRepaint:@"simple"];
+
+    // After navigating, the first item's snapshot should not change, because it was
+    // never loaded into the view.
+    RetainPtr<CGImageRef> snapshotAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(snapshotAfterNavigation.get());
+    EXPECT_TRUE(imagesAreEqual(initialSnapshot.get(), snapshotAfterNavigation.get()));
+}
+
 #endif // WK_API_ENABLED && PLATFORM(MAC)

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h (207602 => 207603)


--- branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h	2016-10-20 09:59:53 UTC (rev 207603)
@@ -42,6 +42,7 @@
 - (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure;
 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
 - (void)loadTestPageNamed:(NSString *)pageName;
+- (void)synchronouslyLoadTestPageNamed:(NSString *)pageName;
 - (void)typeCharacter:(char)character;
 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script;
 - (void)waitForMessage:(NSString *)message;

Modified: branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm (207602 => 207603)


--- branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm	2016-10-20 09:59:48 UTC (rev 207602)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm	2016-10-20 09:59:53 UTC (rev 207603)
@@ -28,6 +28,7 @@
 
 #if WK_API_ENABLED && PLATFORM(MAC)
 
+#import "TestNavigationDelegate.h"
 #import "Utilities.h"
 
 #import <AppKit/AppKit.h>
@@ -180,6 +181,12 @@
     [self loadRequest:request];
 }
 
+- (void)synchronouslyLoadTestPageNamed:(NSString *)pageName
+{
+    [self loadTestPageNamed:pageName];
+    [self _test_waitForDidFinishNavigation];
+}
+
 - (void)typeCharacter:(char)character {
     NSString *characterAsString = [NSString stringWithFormat:@"%c" , character];
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to