Title: [275371] trunk
Revision
275371
Author
mmaxfi...@apple.com
Date
2021-04-01 11:50:22 -0700 (Thu, 01 Apr 2021)

Log Message

[Cocoa] REGRESSION(r272999): User-installed fonts no longer work in Mail
https://bugs.webkit.org/show_bug.cgi?id=223985
<rdar://problem/75975210>

Reviewed by Per Arne Vollan.

Source/WebKit:

The sandbox extension which allows user-installed fonts to work was part of the WebPage,
but XType may already have been initialized to use the static registry by the time the WebPage
has been created. Therefore, simply _having_ a sandbox extension isn't sufficient; instead,
WebPage's constructor needs to call CTFontManagerEnableAllUserFonts() to switch to using fontd
in addition to using the sandbox extension.

Test: WebKit.UserInstalledFontsWork

* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_lastNavigationWasAppBound):
(WebKit::WebPage::~WebPage):
* WebProcess/WebPage/WebPage.h:

Tools:

* TestWebKitAPI/Tests/WebKit/FontRegistrySandboxCheck.mm:
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275370 => 275371)


--- trunk/Source/WebKit/ChangeLog	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Source/WebKit/ChangeLog	2021-04-01 18:50:22 UTC (rev 275371)
@@ -1,3 +1,24 @@
+2021-04-01  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] REGRESSION(r272999): User-installed fonts no longer work in Mail
+        https://bugs.webkit.org/show_bug.cgi?id=223985
+        <rdar://problem/75975210>
+
+        Reviewed by Per Arne Vollan.
+
+        The sandbox extension which allows user-installed fonts to work was part of the WebPage,
+        but XType may already have been initialized to use the static registry by the time the WebPage
+        has been created. Therefore, simply _having_ a sandbox extension isn't sufficient; instead,
+        WebPage's constructor needs to call CTFontManagerEnableAllUserFonts() to switch to using fontd
+        in addition to using the sandbox extension.
+
+        Test: WebKit.UserInstalledFontsWork
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_lastNavigationWasAppBound):
+        (WebKit::WebPage::~WebPage):
+        * WebProcess/WebPage/WebPage.h:
+
 2021-03-31  Jiewen Tan  <jiewen_...@apple.com>
 
         Allow ASCWebKitSPISupport to be used on macOS

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (275370 => 275371)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-01 18:50:22 UTC (rev 275371)
@@ -629,12 +629,8 @@
 #endif
 
 #if HAVE(STATIC_FONT_REGISTRY)
-    if (parameters.fontMachExtensionHandle) {
-        if ((m_fontExtension = SandboxExtension::create(WTFMove(*parameters.fontMachExtensionHandle)))) {
-            bool ok = m_fontExtension->consume();
-            ASSERT_UNUSED(ok, ok);
-        }
-    }
+    if (parameters.fontMachExtensionHandle)
+        WebProcess::singleton().switchFromStaticFontRegistryToUserFontRegistry(WTFMove(*parameters.fontMachExtensionHandle));
 #endif
 
     m_page = makeUnique<Page>(WTFMove(pageConfiguration));
@@ -1019,11 +1015,6 @@
             completionHandler(WTF::nullopt);
     }
 #endif
-
-#if HAVE(STATIC_FONT_REGISTRY)
-    if (m_fontExtension)
-        m_fontExtension->revoke();
-#endif
 }
 
 IPC::Connection* WebPage::messageSenderConnection() const

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (275370 => 275371)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-01 18:50:22 UTC (rev 275371)
@@ -2269,10 +2269,6 @@
 #if ENABLE(IMAGE_EXTRACTION)
     WeakHashSet<WebCore::Element> m_elementsWithExtractedImages;
 #endif
-
-#if HAVE(STATIC_FONT_REGISTRY)
-    RefPtr<SandboxExtension> m_fontExtension;
-#endif
 };
 
 #if !PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/ChangeLog (275370 => 275371)


--- trunk/Tools/ChangeLog	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Tools/ChangeLog	2021-04-01 18:50:22 UTC (rev 275371)
@@ -1,3 +1,14 @@
+2021-04-01  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] REGRESSION(r272999): User-installed fonts no longer work in Mail
+        https://bugs.webkit.org/show_bug.cgi?id=223985
+        <rdar://problem/75975210>
+
+        Reviewed by Per Arne Vollan.
+
+        * TestWebKitAPI/Tests/WebKit/FontRegistrySandboxCheck.mm:
+        (TEST):
+
 2021-04-01  Jonathan Bedard  <jbed...@apple.com>
 
         [webkitscmpy] Improve git-svn-id regex

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (275370 => 275371)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-04-01 18:50:22 UTC (rev 275371)
@@ -108,6 +108,7 @@
 		1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */; };
 		1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
 		1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
+		1C51534C261596D700FBC4FE /* UserInstalledAhem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C51534B261596BD00FBC4FE /* UserInstalledAhem.html */; };
 		1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
 		1C79201C234BDD9B001EAF23 /* CopyRTF.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C79201B234BDD9B001EAF23 /* CopyRTF.mm */; };
 		1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
@@ -1688,6 +1689,7 @@
 				4952BE5F257816F800B0AEF1 /* try-text-select-with-disabled-text-interaction.html in Copy Resources */,
 				F4451C761EB8FD890020C5DA /* two-paragraph-contenteditable.html in Copy Resources */,
 				1D67BFDD2433EE66006B5047 /* two-videos.html in Copy Resources */,
+				1C51534C261596D700FBC4FE /* UserInstalledAhem.html in Copy Resources */,
 				C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */,
 				CD57779D211CE91F001B371E /* video-with-audio-and-web-audio.html in Copy Resources */,
 				CDC8E4941BC6F10800594FEC /* video-with-audio.html in Copy Resources */,
@@ -1833,6 +1835,7 @@
 		1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelFontSubresourcePlugIn.mm; sourceTree = "<group>"; };
 		1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
 		1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
+		1C51534B261596BD00FBC4FE /* UserInstalledAhem.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = UserInstalledAhem.html; sourceTree = "<group>"; };
 		1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
 		1C79201B234BDD9B001EAF23 /* CopyRTF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyRTF.mm; sourceTree = "<group>"; };
 		1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackgroundColor.mm; sourceTree = "<group>"; };
@@ -4538,6 +4541,7 @@
 				C95984F61E36BCD7002C0D45 /* test-without-audio-track.mp4 */,
 				524BBCA019E30C63002F1AF1 /* test.mp4 */,
 				7AE9E5081AE5AE8B00CF874B /* test.pdf */,
+				1C51534B261596BD00FBC4FE /* UserInstalledAhem.html */,
 				C9C9A91C21DED79400FDE96E /* video-with-play-button.html */,
 				07CD32F72065B72A0064A4BE /* video.html */,
 				1C2B81841C8924A200A5529F /* webfont.html */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/FontRegistrySandboxCheck.mm (275370 => 275371)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/FontRegistrySandboxCheck.mm	2021-04-01 18:09:13 UTC (rev 275370)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/FontRegistrySandboxCheck.mm	2021-04-01 18:50:22 UTC (rev 275371)
@@ -30,6 +30,7 @@
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 
 TEST(WebKit, FontdSandboxCheck)
@@ -53,4 +54,29 @@
     ASSERT_TRUE(sandboxAccess());
 }
 
+TEST(WebKit, UserInstalledFontsWork)
+{
+    NSURL *fontURL = [[NSBundle mainBundle] URLForResource:@"Ahem" withExtension:@"ttf" subdirectory:@"TestWebKitAPI.resources"];
+    CFErrorRef error = nil;
+    auto registrationSucceeded = CTFontManagerRegisterFontsForURL(static_cast<CFURLRef>(fontURL), kCTFontManagerScopeUser, &error);
+
+    auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    WKContextSetUsesSingleWebProcess(context.get(), true);
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().processPool = (WKProcessPool *)context.get();
+    [configuration.get().processPool _warmInitialProcess];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 600, 500) configuration:configuration.get() addToWindow:YES]);
+    [webView synchronouslyLoadTestPageNamed:@"UserInstalledAhem"];
+    auto result = [webView stringByEvaluatingJavaScript:@"document.getElementById('target').offsetWidth"].intValue;
+    ASSERT_EQ(result, 12 * 48);
+
+    if (registrationSucceeded) {
+        error = nil;
+        CTFontManagerUnregisterFontsForURL(static_cast<CFURLRef>(fontURL), kCTFontManagerScopeUser, &error);
+        ASSERT_FALSE(error);
+    }
+}
+
 #endif // WK_HAVE_C_SPI

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/UserInstalledAhem.html (0 => 275371)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/UserInstalledAhem.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/UserInstalledAhem.html	2021-04-01 18:50:22 UTC (rev 275371)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="font: 48px 'Ahem';"><span id="target">Hello World!</span></div>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to