⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243961 in webkit


Ignore:
Timestamp:
Apr 5, 2019, 8:41:26 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

We should pass minimumEffectiveDeviceWidth to web process on new page creation.
https://bugs.webkit.org/show_bug.cgi?id=196077
<rdar://problem/49108202>

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2019-04-05
Reviewed by Chris Dumez.

Source/WebCore:

If the page doesn't specify it requires to use the device width in viewport tag, we should try to scale down
the page to fit the window width.

Test: fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta.html

  • page/ViewportConfiguration.cpp:

(WebCore::ViewportConfiguration::updateDefaultConfiguration): Also update the minimum layout size

when the default configuration is changed.

(WebCore::ViewportConfiguration::nativeWebpageParametersWithShrinkToFit): Make sure we fit the content

to window width.

Source/WebKit:

When a new web view is created, it is possible we don't have the web content process till a load
is requested. This patch stashes minimumEffectiveDeviceWidth in WebPageProxy.cpp and passes that
value down to web process via WebPageCreationParameters when a new process is created, just like
we did for other values like viewportConfigurationLayoutSizeScaleFactor or viewportConfigurationViewLayoutSize.

  • Shared/WebPageCreationParameters.cpp:

(WebKit::WebPageCreationParameters::encode const): Encode viewportConfigurationMinimumEffectiveDeviceWidth value.
(WebKit::WebPageCreationParameters::decode): Decode viewportConfigurationMinimumEffectiveDeviceWidth value.

  • Shared/WebPageCreationParameters.h:
  • UIProcess/API/Cocoa/WKWebView.mm: Now that we stash the minimumEffectiveDeviceWidth value in WebPageProxy, we

don't need the iVar in WKWebView any more.

(-[WKWebView _dispatchSetViewLayoutSize:]): Use _page->minimumEffectiveDeviceWidth().
(-[WKWebView _setViewScale:]): Ditto.
(-[WKWebView _setMinimumEffectiveDeviceWidth:]): Ditto.
(-[WKWebView _minimumEffectiveDeviceWidth]): Ditto.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::creationParameters): Also add viewportConfigurationMinimumEffectiveDeviceWidth to

web process creation parameter.

  • UIProcess/WebPageProxy.h:

(WebKit::WebPageProxy::minimumEffectiveDeviceWidth const): Returns m_viewportConfigurationMinimumEffectiveDeviceWidth.

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::setViewportConfigurationViewLayoutSize): Pass parameters.viewportConfigurationMinimumEffectiveDeviceWidth

to web process.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::WebPage): Take viewportConfigurationMinimumEffectiveDeviceWidth value from the parameter and

set that to viewport configuration.

Tools:

Add an API test to verify the minimumEffectDeviceWidth is passed to web content process
on new web view.

  • TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

LayoutTests:

Add a layout test to verify the page shrinks to fit the window width when ignoreMetaViewport
flag is turned on.

  • fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta-expected.txt: Added.
  • fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta.html: Added.
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243958 r243961  
     12019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should pass minimumEffectiveDeviceWidth to web process on new page creation.
     4        https://bugs.webkit.org/show_bug.cgi?id=196077
     5        <rdar://problem/49108202>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add a layout test to verify the page shrinks to fit the window width when ignoreMetaViewport
     10        flag is turned on.
     11
     12        * fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta-expected.txt: Added.
     13        * fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta.html: Added.
     14
    1152019-04-05  Jer Noble  <jer.noble@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r243958 r243961  
     12019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should pass minimumEffectiveDeviceWidth to web process on new page creation.
     4        https://bugs.webkit.org/show_bug.cgi?id=196077
     5        <rdar://problem/49108202>
     6
     7        Reviewed by Chris Dumez.
     8
     9        If the page doesn't specify it requires to use the device width in viewport tag, we should try to scale down
     10        the page to fit the window width.
     11
     12        Test: fast/viewport/ios/shrink-to-fit-for-page-without-viewport-meta.html
     13
     14        * page/ViewportConfiguration.cpp:
     15        (WebCore::ViewportConfiguration::updateDefaultConfiguration): Also update the minimum layout size
     16            when the default configuration is changed.
     17        (WebCore::ViewportConfiguration::nativeWebpageParametersWithShrinkToFit): Make sure we fit the content
     18            to window width.
     19
    1202019-04-05  Jer Noble  <jer.noble@apple.com>
    221
  • trunk/Source/WebCore/page/ViewportConfiguration.cpp

    r242069 r243961  
    178178    m_canIgnoreScalingConstraints = canIgnoreScalingConstraints;
    179179    updateDefaultConfiguration();
     180    updateMinimumLayoutSize();
    180181    updateConfiguration();
    181182    return true;
     
    354355    parameters.allowsShrinkToFit = true;
    355356    parameters.minimumScale = 0.25;
     357    parameters.initialScaleIsSet = false;
    356358    return parameters;
    357359}
  • trunk/Source/WebKit/ChangeLog

    r243958 r243961  
     12019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should pass minimumEffectiveDeviceWidth to web process on new page creation.
     4        https://bugs.webkit.org/show_bug.cgi?id=196077
     5        <rdar://problem/49108202>
     6
     7        Reviewed by Chris Dumez.
     8
     9        When a new web view is created, it is possible we don't have the web content process till a load
     10        is requested. This patch stashes minimumEffectiveDeviceWidth in WebPageProxy.cpp and passes that
     11        value down to web process via WebPageCreationParameters when a new process is created, just like
     12        we did for other values like viewportConfigurationLayoutSizeScaleFactor or viewportConfigurationViewLayoutSize.
     13
     14        * Shared/WebPageCreationParameters.cpp:
     15        (WebKit::WebPageCreationParameters::encode const): Encode viewportConfigurationMinimumEffectiveDeviceWidth value.
     16        (WebKit::WebPageCreationParameters::decode): Decode viewportConfigurationMinimumEffectiveDeviceWidth value.
     17        * Shared/WebPageCreationParameters.h:
     18        * UIProcess/API/Cocoa/WKWebView.mm: Now that we stash the minimumEffectiveDeviceWidth value in WebPageProxy, we
     19            don't need the iVar in WKWebView any more.
     20        (-[WKWebView _dispatchSetViewLayoutSize:]): Use _page->minimumEffectiveDeviceWidth().
     21        (-[WKWebView _setViewScale:]): Ditto.
     22        (-[WKWebView _setMinimumEffectiveDeviceWidth:]): Ditto.
     23        (-[WKWebView _minimumEffectiveDeviceWidth]): Ditto.
     24        * UIProcess/WebPageProxy.cpp:
     25        (WebKit::WebPageProxy::creationParameters): Also add viewportConfigurationMinimumEffectiveDeviceWidth to
     26            web process creation parameter.
     27        * UIProcess/WebPageProxy.h:
     28        (WebKit::WebPageProxy::minimumEffectiveDeviceWidth const): Returns m_viewportConfigurationMinimumEffectiveDeviceWidth.
     29        * UIProcess/ios/WebPageProxyIOS.mm:
     30        (WebKit::WebPageProxy::setViewportConfigurationViewLayoutSize): Pass parameters.viewportConfigurationMinimumEffectiveDeviceWidth
     31            to web process.
     32        * WebProcess/WebPage/WebPage.cpp:
     33        (WebKit::WebPage::WebPage): Take viewportConfigurationMinimumEffectiveDeviceWidth value from the parameter and
     34            set that to viewport configuration.
     35
    1362019-04-05  Jer Noble  <jer.noble@apple.com>
    237
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp

    r243630 r243961  
    9191    encoder << viewportConfigurationViewLayoutSize;
    9292    encoder << viewportConfigurationLayoutSizeScaleFactor;
     93    encoder << viewportConfigurationMinimumEffectiveDeviceWidth;
    9394    encoder << viewportConfigurationViewSize;
    9495    encoder << maximumUnobscuredSize;
     
    269270    if (!decoder.decode(parameters.viewportConfigurationLayoutSizeScaleFactor))
    270271        return WTF::nullopt;
     272    if (!decoder.decode(parameters.viewportConfigurationMinimumEffectiveDeviceWidth))
     273        return WTF::nullopt;
    271274    if (!decoder.decode(parameters.viewportConfigurationViewSize))
    272275        return WTF::nullopt;
  • trunk/Source/WebKit/Shared/WebPageCreationParameters.h

    r243630 r243961  
    149149    WebCore::FloatSize viewportConfigurationViewLayoutSize;
    150150    double viewportConfigurationLayoutSizeScaleFactor;
     151    double viewportConfigurationMinimumEffectiveDeviceWidth;
    151152    WebCore::FloatSize viewportConfigurationViewSize;
    152153    WebCore::FloatSize maximumUnobscuredSize;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r243956 r243961  
    383383#endif
    384384    _WKSelectionAttributes _selectionAttributes;
    385     CGFloat _minimumEffectiveDeviceWidth;
    386385}
    387386
     
    28452844
    28462845    LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->pageID() << " _dispatchSetViewLayoutSize:] " << viewLayoutSize << " contentZoomScale " << contentZoomScale(self));
    2847     _page->setViewportConfigurationViewLayoutSize(viewLayoutSize, _page->layoutSizeScaleFactor(), _minimumEffectiveDeviceWidth);
     2846    _page->setViewportConfigurationViewLayoutSize(viewLayoutSize, _page->layoutSizeScaleFactor(), _page->minimumEffectiveDeviceWidth());
    28482847    _lastSentViewLayoutSize = viewLayoutSize;
    28492848}
     
    56895688        return;
    56905689
    5691     _page->setViewportConfigurationViewLayoutSize([self activeViewLayoutSize:self.bounds], viewScale, _minimumEffectiveDeviceWidth);
     5690    _page->setViewportConfigurationViewLayoutSize([self activeViewLayoutSize:self.bounds], viewScale, _page->minimumEffectiveDeviceWidth());
    56925691#endif
    56935692}
     
    56955694- (void)_setMinimumEffectiveDeviceWidth:(CGFloat)minimumEffectiveDeviceWidth
    56965695{
    5697     if (_minimumEffectiveDeviceWidth == minimumEffectiveDeviceWidth)
     5696#if PLATFORM(IOS_FAMILY)
     5697    if (_page->minimumEffectiveDeviceWidth() == minimumEffectiveDeviceWidth)
    56985698        return;
    56995699
    5700     _minimumEffectiveDeviceWidth = minimumEffectiveDeviceWidth;
     5700    _page->setViewportConfigurationViewLayoutSize([self activeViewLayoutSize:self.bounds], _page->layoutSizeScaleFactor(), minimumEffectiveDeviceWidth);
     5701#endif
     5702}
     5703
     5704- (CGFloat)_minimumEffectiveDeviceWidth
     5705{
    57015706#if PLATFORM(IOS_FAMILY)
    5702     _page->setViewportConfigurationViewLayoutSize([self activeViewLayoutSize:self.bounds], _page->layoutSizeScaleFactor(), _minimumEffectiveDeviceWidth);
    5703 #endif
    5704 }
    5705 
    5706 - (CGFloat)_minimumEffectiveDeviceWidth
    5707 {
    5708     return _minimumEffectiveDeviceWidth;
     5707    return _page->minimumEffectiveDeviceWidth();
     5708#else
     5709    return 0;
     5710#endif
    57095711}
    57105712
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r243899 r243961  
    70247024    parameters.viewportConfigurationViewLayoutSize = m_viewportConfigurationViewLayoutSize;
    70257025    parameters.viewportConfigurationLayoutSizeScaleFactor = m_viewportConfigurationLayoutSizeScaleFactor;
     7026    parameters.viewportConfigurationMinimumEffectiveDeviceWidth = m_viewportConfigurationMinimumEffectiveDeviceWidth;
    70267027    parameters.maximumUnobscuredSize = m_maximumUnobscuredSize;
    70277028    parameters.deviceOrientation = m_deviceOrientation;
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r243899 r243961  
    701701    bool forceAlwaysUserScalable() const { return m_forceAlwaysUserScalable; }
    702702    double layoutSizeScaleFactor() const { return m_viewportConfigurationLayoutSizeScaleFactor; }
     703    double minimumEffectiveDeviceWidth() const { return m_viewportConfigurationMinimumEffectiveDeviceWidth; }
    703704    void setIsScrollingOrZooming(bool);
    704705    void requestRectsForGranularityWithSelectionOffset(WebCore::TextGranularity, uint32_t offset, WTF::Function<void(const Vector<WebCore::SelectionRect>&, CallbackBase::Error)>&&);
     
    24212422    WebCore::FloatSize m_viewportConfigurationViewLayoutSize;
    24222423    double m_viewportConfigurationLayoutSizeScaleFactor { 1 };
     2424    double m_viewportConfigurationMinimumEffectiveDeviceWidth { 0 };
    24232425    WebCore::FloatSize m_maximumUnobscuredSize;
    24242426#endif
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r243797 r243961  
    330330    m_viewportConfigurationViewLayoutSize = size;
    331331    m_viewportConfigurationLayoutSizeScaleFactor = scaleFactor;
     332    m_viewportConfigurationMinimumEffectiveDeviceWidth = minimumEffectiveDeviceWidth;
    332333
    333334    if (hasRunningProcess())
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r243762 r243961  
    661661
    662662#if PLATFORM(IOS_FAMILY)
    663     setViewportConfigurationViewLayoutSize(parameters.viewportConfigurationViewLayoutSize, parameters.viewportConfigurationLayoutSizeScaleFactor, 0);
     663    setViewportConfigurationViewLayoutSize(parameters.viewportConfigurationViewLayoutSize, parameters.viewportConfigurationLayoutSizeScaleFactor, parameters.viewportConfigurationMinimumEffectiveDeviceWidth);
    664664    setMaximumUnobscuredSize(parameters.maximumUnobscuredSize);
    665665#endif
  • trunk/Tools/ChangeLog

    r243960 r243961  
     12019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should pass minimumEffectiveDeviceWidth to web process on new page creation.
     4        https://bugs.webkit.org/show_bug.cgi?id=196077
     5        <rdar://problem/49108202>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add an API test to verify the minimumEffectDeviceWidth is passed to web content process
     10        on new web view.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     13
    1142019-04-05  Saam Barati  <sbarati@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r243935 r243961  
    58875887}
    58885888
     5889static const char* minimumWidthPageBytes = R"PSONRESOURCE(
     5890<!DOCTYPE html>
     5891<html>
     5892<head>
     5893<style>
     5894div {
     5895    margin: 0;
     5896    width: 100%;
     5897    height: 10000px;
     5898}
     5899</style>
     5900</head>
     5901<body>
     5902<div>Test</a>
     5903</body>
     5904</html>
     5905)PSONRESOURCE";
     5906
     5907TEST(ProcessSwap, PassMinimumDeviceWidthOnNewWebView)
     5908{
     5909    auto processPoolConfiguration = psonProcessPoolConfiguration();
     5910    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     5911
     5912    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     5913    [webViewConfiguration setProcessPool:processPool.get()];
     5914    auto handler = adoptNS([[PSONScheme alloc] init]);
     5915    [handler addMappingFromURLString:@"pson://www.webkit.org/main.html" toData:minimumWidthPageBytes];
     5916    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     5917
     5918    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     5919
     5920    auto navigationDelegate = adoptNS([[PSONNavigationDelegate alloc] init]);
     5921    [webView setNavigationDelegate:navigationDelegate.get()];
     5922
     5923    auto preferences = [[webView configuration] preferences];
     5924    [preferences _setShouldIgnoreMetaViewport:YES];
     5925    [webView _setMinimumEffectiveDeviceWidth:1024];
     5926
     5927    auto* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main.html"]];
     5928    [webView loadRequest:request];
     5929
     5930    TestWebKitAPI::Util::run(&done);
     5931    done = false;
     5932
     5933    bool finishedRunningScript = false;
     5934    [webView evaluateJavaScript:@"window.innerWidth" completionHandler: [&] (id result, NSError *error) {
     5935        NSNumber *width = (NSNumber *)result;
     5936        EXPECT_EQ(1024, [width intValue]);
     5937        finishedRunningScript = true;
     5938    }];
     5939    TestWebKitAPI::Util::run(&finishedRunningScript);
     5940}
     5941
    58895942#endif
Note: See TracChangeset for help on using the changeset viewer.