Title: [249230] trunk
Revision
249230
Author
timothy_hor...@apple.com
Date
2019-08-28 19:07:35 -0700 (Wed, 28 Aug 2019)

Log Message

Reloading a web view with a fixed-width viewport and variable content width restores the previous page scale, shouldn't
https://bugs.webkit.org/show_bug.cgi?id=201256
<rdar://problem/54809509>

Reviewed by Simon Fraser.

Source/WebKit:

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::restorePageState):
When restoring page state from a history item, if the saved scale was equal to the
initial scale at the time it was saved, ignore the saved scale and use the current
initial scale instead.

Normally this doesn't matter because a given page's initial scale doesn't usually change
between loads, but it totally can! See the test for one example of a way an API client
might cause this; you could also imagine something similar happening if the actual
page content changed.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/long-email-viewport.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/ReloadWithDifferingInitialScale.mm: Added.
(TestWebKitAPI::TEST):
Add a test. I left many comments because I had a great deal of trouble
writing this test and wanted to document my findings.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (249229 => 249230)


--- trunk/Source/WebKit/ChangeLog	2019-08-29 02:06:24 UTC (rev 249229)
+++ trunk/Source/WebKit/ChangeLog	2019-08-29 02:07:35 UTC (rev 249230)
@@ -1,3 +1,22 @@
+2019-08-28  Tim Horton  <timothy_hor...@apple.com>
+
+        Reloading a web view with a fixed-width viewport and variable content width restores the previous page scale, shouldn't
+        https://bugs.webkit.org/show_bug.cgi?id=201256
+        <rdar://problem/54809509>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::restorePageState):
+        When restoring page state from a history item, if the saved scale was equal to the
+        initial scale at the time it was saved, ignore the saved scale and use the current
+        initial scale instead.
+
+        Normally this doesn't matter because a given page's initial scale doesn't usually change
+        between loads, but it totally can! See the test for one example of a way an API client
+        might cause this; you could also imagine something similar happening if the actual
+        page content changed.
+
 2019-08-28  Megan Gardner  <megan_gard...@apple.com>
 
         Null check webFrame when creating a print preview to prevent a crash.

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (249229 => 249230)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-08-29 02:06:24 UTC (rev 249229)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-08-29 02:07:35 UTC (rev 249230)
@@ -379,7 +379,8 @@
 
     FloatSize currentMinimumLayoutSizeInScrollViewCoordinates = m_viewportConfiguration.minimumLayoutSize();
     if (historyItem.minimumLayoutSizeInScrollViewCoordinates() == currentMinimumLayoutSizeInScrollViewCoordinates) {
-        float boundedScale = std::min<float>(m_viewportConfiguration.maximumScale(), std::max<float>(m_viewportConfiguration.minimumScale(), historyItem.pageScaleFactor()));
+        float boundedScale = historyItem.scaleIsInitial() ? m_viewportConfiguration.initialScale() : historyItem.pageScaleFactor();
+        boundedScale = std::min<float>(m_viewportConfiguration.maximumScale(), std::max<float>(m_viewportConfiguration.minimumScale(), boundedScale));
         scalePage(boundedScale, IntPoint());
 
         Optional<FloatPoint> scrollPosition;

Modified: trunk/Tools/ChangeLog (249229 => 249230)


--- trunk/Tools/ChangeLog	2019-08-29 02:06:24 UTC (rev 249229)
+++ trunk/Tools/ChangeLog	2019-08-29 02:07:35 UTC (rev 249230)
@@ -1,3 +1,18 @@
+2019-08-28  Tim Horton  <timothy_hor...@apple.com>
+
+        Reloading a web view with a fixed-width viewport and variable content width restores the previous page scale, shouldn't
+        https://bugs.webkit.org/show_bug.cgi?id=201256
+        <rdar://problem/54809509>
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/long-email-viewport.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/ReloadWithDifferingInitialScale.mm: Added.
+        (TestWebKitAPI::TEST):
+        Add a test. I left many comments because I had a great deal of trouble
+        writing this test and wanted to document my findings.
+
 2019-08-28  Jonathan Bedard  <jbed...@apple.com>
 
         results.webkit.org: Do not display branch selector if only one branches available

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249229 => 249230)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-08-29 02:06:24 UTC (rev 249229)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-08-29 02:07:35 UTC (rev 249230)
@@ -126,6 +126,8 @@
 		2D21FE591F04642900B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */; };
 		2D2BEB2D22324E5F005544CA /* RequestTextInputContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D2BEB2C22324E5F005544CA /* RequestTextInputContext.mm */; };
 		2D2D13B3229F408B005068AF /* DeviceManagementRestrictions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D2D13B2229F408B005068AF /* DeviceManagementRestrictions.mm */; };
+		2D2FE8D82315F06E00B2E9C9 /* ReloadWithDifferingInitialScale.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D2FE8D72315F06D00B2E9C9 /* ReloadWithDifferingInitialScale.mm */; };
+		2D2FE8DA231745C900B2E9C9 /* long-email-viewport.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2D2FE8D9231745AB00B2E9C9 /* long-email-viewport.html */; };
 		2D3CA3A8221DF4B40088E803 /* PageOverlayPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D3CA3A4221DF2390088E803 /* PageOverlayPlugin.mm */; };
 		2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */; };
 		2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
@@ -1321,6 +1323,7 @@
 				46C519E71D3563FD00DAA51A /* LocalStorageNullEntries.localstorage in Copy Resources */,
 				46C519E81D3563FD00DAA51A /* LocalStorageNullEntries.localstorage-shm in Copy Resources */,
 				7A6A2C721DCCFB5200C0D085 /* LocalStorageQuirkEnabled.html in Copy Resources */,
+				2D2FE8DA231745C900B2E9C9 /* long-email-viewport.html in Copy Resources */,
 				C9E8EE7521DED94300797765 /* long-test.mp4 in Copy Resources */,
 				9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */,
 				93AF4ED11506F130007FD57E /* lots-of-images.html in Copy Resources */,
@@ -1568,6 +1571,8 @@
 		2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewStablePresentationUpdateCallback.mm; sourceTree = "<group>"; };
 		2D2BEB2C22324E5F005544CA /* RequestTextInputContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequestTextInputContext.mm; sourceTree = "<group>"; };
 		2D2D13B2229F408B005068AF /* DeviceManagementRestrictions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceManagementRestrictions.mm; sourceTree = "<group>"; };
+		2D2FE8D72315F06D00B2E9C9 /* ReloadWithDifferingInitialScale.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ReloadWithDifferingInitialScale.mm; sourceTree = "<group>"; };
+		2D2FE8D9231745AB00B2E9C9 /* long-email-viewport.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "long-email-viewport.html"; sourceTree = "<group>"; };
 		2D3CA3A4221DF2390088E803 /* PageOverlayPlugin.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageOverlayPlugin.mm; sourceTree = "<group>"; };
 		2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKThumbnailView.mm; path = WebKit/WKThumbnailView.mm; sourceTree = "<group>"; };
 		2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
@@ -2830,6 +2835,7 @@
 				5798E2AF1CAF5C2800C5CBA0 /* ProvisionalURLNotChange.mm */,
 				5CFACF64226FD1FB0056C7D0 /* Proxy.mm */,
 				A1C4FB6C1BACCE50003742D0 /* QuickLook.mm */,
+				2D2FE8D72315F06D00B2E9C9 /* ReloadWithDifferingInitialScale.mm */,
 				1A4F81D01BDFFDCF004E672E /* RemoteObjectRegistry.h */,
 				1A4F81C81BDFFD18004E672E /* RemoteObjectRegistry.mm */,
 				1A4F81CD1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm */,
@@ -3695,6 +3701,7 @@
 				8361F1771E610B2100759B25 /* link-with-download-attribute-with-slashes.html */,
 				8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */,
 				378E647816326FDF00B6C676 /* link-with-title.html */,
+				2D2FE8D9231745AB00B2E9C9 /* long-email-viewport.html */,
 				C9E8EE7421DED91E00797765 /* long-test.mp4 */,
 				9361002814DC957B0061379D /* lots-of-iframes.html */,
 				93AF4ECF1506F123007FD57E /* lots-of-images.html */,
@@ -4644,6 +4651,7 @@
 				7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
 				6B4E861C2220A5520022F389 /* RegistrableDomain.cpp in Sources */,
 				7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
+				2D2FE8D82315F06E00B2E9C9 /* ReloadWithDifferingInitialScale.mm in Sources */,
 				7C83E0C31D0A653A00FEBCF3 /* RemoteObjectRegistry.mm in Sources */,
 				7CCE7EC91A411A7E00447C4C /* RenderedImageFromDOMNode.mm in Sources */,
 				7CCE7ECA1A411A7E00447C4C /* RenderedImageFromDOMRange.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/long-email-viewport.html (0 => 249230)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/long-email-viewport.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/long-email-viewport.html	2019-08-29 02:07:35 UTC (rev 249230)
@@ -0,0 +1,10 @@
+<html>
+    <head>
+        <!-- This matches the default MobileMail viewport on iOS -->
+        <meta name='viewport' content='width=375, initial-scale=-1'>
+    </head>
+    <!-- We need a large height so that WebKit doesn't inflate the scale
+         to ensure that the web view is vertically covered by content.  -->
+    <body style="height: 10000px;">
+    </body>
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ReloadWithDifferingInitialScale.mm (0 => 249230)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ReloadWithDifferingInitialScale.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ReloadWithDifferingInitialScale.mm	2019-08-29 02:07:35 UTC (rev 249230)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2019 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 "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "_javascript_Test.h"
+#import "PlatformUtilities.h"
+#import "PlatformWebView.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, ReloadWithDifferingInitialScale)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 375, 375) configuration:configuration.get()]);
+
+    // It is important that we load from a file, not a HTML string, otherwise we don't
+    // get a back-forward list item, and thus don't try to restore state.
+    [webView synchronouslyLoadTestPageNamed:@"long-email-viewport"];
+
+    [webView waitForNextPresentationUpdate];
+
+    // "fixed-width-viewport" requests a width=375 viewport and has no overflowing
+    // content, so we should end up with an initial scale of 1.
+    EXPECT_EQ([webView scrollView].zoomScale, 1);
+
+    // Unparenting the view will cause the current state
+    // (including isInitialScale=YES and pageScaleFactor=1)
+    // to be saved to the back-forward item.
+    [webView removeFromSuperview];
+    [webView waitForNextPresentationUpdate];
+
+    [webView addToTestWindow];
+
+    // Install the user script, so that the next time we load the page,
+    // the document lays out very wide, causing the initial scale to be small.
+    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"document.body.style.width = '2000px'; setTimeout(function () { window.webkit.messageHandlers.testHandler.postMessage('ranUserScript'); }, 0)" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
+    [[webView configuration].userContentController addUserScript:userScript.get()];
+
+    // Reload, causing both the user script and the page state restoration code to run.
+    [webView reload];
+
+    [webView waitForMessage:@"ranUserScript"];
+    [webView waitForNextPresentationUpdate];
+
+    // Ensure that we did *not* restore pageScaleFactor to 1.
+    EXPECT_EQ([webView scrollView].zoomScale, 0.25);
+}
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to