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

Changeset 236973 in webkit


Ignore:
Timestamp:
Oct 9, 2018, 12:04:44 PM (8 years ago)
Author:
Chris Dumez
Message:

PSON: Doing a cross-site navigation via the URL bar does not swap process on iOS
https://bugs.webkit.org/show_bug.cgi?id=190378
<rdar://problem/45059466>

Reviewed by Geoffrey Garen.

Source/WebKit:

Process swapping was sometimes not happening via URL bar navigation on iOS due to top-hit preloading,
which would use a new WKWebView for the speculative load and rely on the _relatedWebView SPI to use
the same WebContent process as the view currently on screen.

To address the issue, if the source URL is empty and the page has a related page, use the related
page's URL as source URL when doing the process-swap decision.

  • UIProcess/API/APIPageConfiguration.cpp:

(API::PageConfiguration::relatedPage const):
(API::PageConfiguration::relatedPage): Deleted.

  • UIProcess/API/APIPageConfiguration.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::processForNavigationInternal):

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r236968 r236973  
     12018-10-09  Chris Dumez  <cdumez@apple.com>
     2
     3        PSON: Doing a cross-site navigation via the URL bar does not swap process on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=190378
     5        <rdar://problem/45059466>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Process swapping was sometimes not happening via URL bar navigation on iOS due to top-hit preloading,
     10        which would use a new WKWebView for the speculative load and rely on the _relatedWebView SPI to use
     11        the same WebContent process as the view currently on screen.
     12
     13        To address the issue, if the source URL is empty and the page has a related page, use the related
     14        page's URL as source URL when doing the process-swap decision.
     15
     16        * UIProcess/API/APIPageConfiguration.cpp:
     17        (API::PageConfiguration::relatedPage const):
     18        (API::PageConfiguration::relatedPage): Deleted.
     19        * UIProcess/API/APIPageConfiguration.h:
     20        * UIProcess/WebProcessPool.cpp:
     21        (WebKit::WebProcessPool::processForNavigationInternal):
     22
    1232018-10-09  Andy Estes  <aestes@apple.com>
    224
  • trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp

    r234946 r236973  
    130130}
    131131
    132 WebPageProxy* PageConfiguration::relatedPage()
     132WebPageProxy* PageConfiguration::relatedPage() const
    133133{
    134134    return m_relatedPage.get();
  • trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h

    r234946 r236973  
    7373    WebKit::WebPreferencesStore::ValueMap& preferenceValues() { return m_preferenceValues; }
    7474
    75     WebKit::WebPageProxy* relatedPage();
     75    WebKit::WebPageProxy* relatedPage() const;
    7676    void setRelatedPage(WebKit::WebPageProxy*);
    7777
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r236959 r236973  
    21392139
    21402140        bool isInitialLoadInNewWindowOpenedByDOM = page.openedByDOM() && !page.hasCommittedAnyProvisionalLoads();
    2141         URL url;
     2141        URL sourceURL;
    21422142        if (isInitialLoadInNewWindowOpenedByDOM && !navigation.requesterOrigin().isEmpty())
    2143             url = URL { URL(), navigation.requesterOrigin().toString() };
     2143            sourceURL = URL { URL(), navigation.requesterOrigin().toString() };
    21442144        else
    2145             url = URL { { }, page.pageLoadState().url() };
    2146         if (!url.isValid() || !targetURL.isValid() || url.isEmpty() || url.isBlankURL() || registrableDomainsAreEqual(url, targetURL)) {
     2145            sourceURL = URL { { }, page.pageLoadState().url() };
     2146
     2147        if (sourceURL.isEmpty() && page.configuration().relatedPage()) {
     2148            sourceURL = URL { { }, page.configuration().relatedPage()->pageLoadState().url() };
     2149            RELEASE_LOG(ProcessSwapping, "Using related page %p's URL as source URL for process swap decision", page.configuration().relatedPage());
     2150        }
     2151
     2152        if (!sourceURL.isValid() || !targetURL.isValid() || sourceURL.isEmpty() || sourceURL.isBlankURL() || registrableDomainsAreEqual(sourceURL, targetURL)) {
    21472153            reason = "Navigation is same-site"_s;
    21482154            return page.process();
  • trunk/Tools/ChangeLog

    r236964 r236973  
     12018-10-09  Chris Dumez  <cdumez@apple.com>
     2
     3        PSON: Doing a cross-site navigation via the URL bar does not swap process on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=190378
     5        <rdar://problem/45059466>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add API test coverage.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     12
    1132018-10-09  Jer Noble  <jer.noble@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r236226 r236973  
    18041804}
    18051805
     1806enum class ExpectSwap { No, Yes };
     1807static void runProcessSwapDueToRelatedWebViewTest(NSURL* relatedViewURL, NSURL* targetURL, ExpectSwap expectSwap)
     1808{
     1809    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     1810    processPoolConfiguration.get().processSwapsOnNavigation = YES;
     1811    processPoolConfiguration.get().prewarmsProcessesAutomatically = YES;
     1812    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     1813
     1814    auto webView1Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1815    [webView1Configuration setProcessPool:processPool.get()];
     1816    auto handler = adoptNS([[PSONScheme alloc] init]);
     1817    [webView1Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     1818
     1819    auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView1Configuration.get()]);
     1820    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
     1821    [webView1 setNavigationDelegate:delegate.get()];
     1822
     1823    numberOfDecidePolicyCalls = 0;
     1824    NSURLRequest *request = [NSURLRequest requestWithURL:relatedViewURL];
     1825    [webView1 loadRequest:request];
     1826
     1827    TestWebKitAPI::Util::run(&done);
     1828    done = false;
     1829
     1830    auto pid1 = [webView1 _webProcessIdentifier];
     1831
     1832    auto webView2Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1833    [webView2Configuration setProcessPool:processPool.get()];
     1834    [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     1835    webView2Configuration.get()._relatedWebView = webView1.get(); // webView2 will be related to webView1 and webView1's URL will be used for process swap decision.
     1836    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView2Configuration.get()]);
     1837    [webView2 setNavigationDelegate:delegate.get()];
     1838
     1839    request = [NSURLRequest requestWithURL:targetURL];
     1840    [webView2 loadRequest:request];
     1841
     1842    TestWebKitAPI::Util::run(&done);
     1843    done = false;
     1844
     1845    auto pid2 = [webView2 _webProcessIdentifier];
     1846
     1847    if (expectSwap == ExpectSwap::No)
     1848        EXPECT_TRUE(pid1 == pid2);
     1849    else
     1850        EXPECT_FALSE(pid1 == pid2);
     1851
     1852    EXPECT_EQ(2, numberOfDecidePolicyCalls);
     1853}
     1854
     1855TEST(ProcessSwap, ProcessSwapDueToRelatedView)
     1856{
     1857    runProcessSwapDueToRelatedWebViewTest([NSURL URLWithString:@"pson://www.webkit.org/main1.html"], [NSURL URLWithString:@"pson://www.apple.com/main2.html"], ExpectSwap::Yes);
     1858}
     1859
     1860TEST(ProcessSwap, NoProcessSwapDueToRelatedView)
     1861{
     1862    runProcessSwapDueToRelatedWebViewTest([NSURL URLWithString:@"pson://www.webkit.org/main1.html"], [NSURL URLWithString:@"pson://www.webkit.org/main2.html"], ExpectSwap::No);
     1863}
     1864
    18061865TEST(ProcessSwap, TerminatedSuspendedPageProcess)
    18071866{
Note: See TracChangeset for help on using the changeset viewer.