Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 3ed7f96

Browse files
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: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@236973 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a4a2ee3 commit 3ed7f96

File tree

6 files changed

+105
-6
lines changed

6 files changed

+105
-6
lines changed

Source/WebKit/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2018-10-09 Chris Dumez <[email protected]>
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+
123
2018-10-09 Andy Estes <[email protected]>
224

325
[iOS] Replace @"UIPreviewDataAttachmentListIsContentManaged" with a UIKit constant

Source/WebKit/UIProcess/API/APIPageConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void PageConfiguration::setPreferences(WebPreferences* preferences)
129129
m_preferences = preferences;
130130
}
131131

132-
WebPageProxy* PageConfiguration::relatedPage()
132+
WebPageProxy* PageConfiguration::relatedPage() const
133133
{
134134
return m_relatedPage.get();
135135
}

Source/WebKit/UIProcess/API/APIPageConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class PageConfiguration : public ObjectImpl<Object::Type::PageConfiguration> {
7272

7373
WebKit::WebPreferencesStore::ValueMap& preferenceValues() { return m_preferenceValues; }
7474

75-
WebKit::WebPageProxy* relatedPage();
75+
WebKit::WebPageProxy* relatedPage() const;
7676
void setRelatedPage(WebKit::WebPageProxy*);
7777

7878
WebKit::VisitedLinkStore* visitedLinkStore();

Source/WebKit/UIProcess/WebProcessPool.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,12 +2138,18 @@ Ref<WebProcessProxy> WebProcessPool::processForNavigationInternal(WebPageProxy&
21382138
}
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();
21492155
}

Tools/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2018-10-09 Chris Dumez <[email protected]>
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+
113
2018-10-09 Jer Noble <[email protected]>
214

315
ISOTrackEncryptionBox returns incorrect defaultKeyID

Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,65 @@ function loaded() {
18031803
EXPECT_NE(pid1, pid3);
18041804
}
18051805

1806+
enum class ExpectSwap { No, Yes };
1807+
static 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+
1855+
TEST(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+
1860+
TEST(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+
18061865
TEST(ProcessSwap, TerminatedSuspendedPageProcess)
18071866
{
18081867
auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);

0 commit comments

Comments
 (0)