Platform font class gets needlessly initialized in the Networking process
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jun 2019 03:44:50 +0000 (03:44 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jun 2019 03:44:50 +0000 (03:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199140

Reviewed by Tim Horton.

* NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in: Revert a change that was made in
  r246702, which is not needed anymore.
* Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb: Ditto.

* Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::platformColorClass): Added getter that uses NSClassFromString, thereby avoiding
  initializing the class.
(IPC::platformFontClass): Ditto.
(IPC::typeFromObject): Changed to use the above getters instead of +class.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246726 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in
Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb
Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm

index 9971623..56d196e 100644 (file)
@@ -1,3 +1,20 @@
+2019-06-23  Dan Bernstein  <mitz@apple.com>
+
+        Platform font class gets needlessly initialized in the Networking process
+        https://bugs.webkit.org/show_bug.cgi?id=199140
+
+        Reviewed by Tim Horton.
+
+        * NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in: Revert a change that was made in
+          r246702, which is not needed anymore.
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb: Ditto.
+
+        * Shared/Cocoa/ArgumentCodersCocoa.mm:
+        (IPC::platformColorClass): Added getter that uses NSClassFromString, thereby avoiding
+          initializing the class.
+        (IPC::platformFontClass): Ditto.
+        (IPC::typeFromObject): Changed to use the above getters instead of +class.
+
 2019-06-23  Simon Fraser  <simon.fraser@apple.com>
 
         [Async overflow scroll] Clipped composited layers inside overflow scroll jitter and get incorrectly clipped
index 15e02fd..42ee294 100644 (file)
@@ -95,7 +95,6 @@
 
 (allow file-read*
     ;; Basic system paths
-    (subpath "/Library/Fonts") ;; Needed to serialize font data types <rdar://problem/50164879>
     (subpath "/Library/Frameworks")
     (subpath "/Library/Managed Preferences")
 
index 5e7e908..80716ec 100644 (file)
     (literal "/usr/local/lib/log") ; <rdar://problem/36629495>
 )
 
-;; Read-only preferences and data
-(allow file-read*
-    ;; Basic system paths
-    (subpath "/Library/Fonts") ;; Needed to serialize font data types <rdar://problem/50164879>
-)
-
 ;; Security framework
 (allow mach-lookup
     (global-name "com.apple.ocspd")
index 221737d..a1cd863 100644 (file)
@@ -77,6 +77,34 @@ enum class NSType {
 
 #pragma mark - Helpers
 
+static Class platformColorClass()
+{
+    static Class colorClass;
+    static std::once_flag flag;
+    std::call_once(flag, [] {
+#if USE(APPKIT)
+        colorClass = NSClassFromString(@"NSColor");
+#else
+        colorClass = NSClassFromString(@"UIColor");
+#endif
+    });
+    return colorClass;
+}
+
+static Class platformFontClass()
+{
+    static Class fontClass;
+    static std::once_flag flag;
+    std::call_once(flag, [] {
+#if USE(APPKIT)
+        fontClass = NSClassFromString(@"NSFont");
+#else
+        fontClass = NSClassFromString(@"UIFont");
+#endif
+    });
+    return fontClass;
+}
+
 static NSType typeFromObject(id object)
 {
     ASSERT(object);
@@ -84,7 +112,7 @@ static NSType typeFromObject(id object)
     // Specific classes handled.
     if ([object isKindOfClass:[NSArray class]])
         return NSType::Array;
-    if ([object isKindOfClass:[PlatformColor class]])
+    if ([object isKindOfClass:platformColorClass()])
         return NSType::Color;
     if ([object isKindOfClass:[NSData class]])
         return NSType::Data;
@@ -92,7 +120,7 @@ static NSType typeFromObject(id object)
         return NSType::Date;
     if ([object isKindOfClass:[NSDictionary class]])
         return NSType::Dictionary;
-    if ([object isKindOfClass:[PlatformFont class]])
+    if ([object isKindOfClass:platformFontClass()])
         return NSType::Font;
     if ([object isKindOfClass:[NSNumber class]])
         return NSType::Number;