Title: [230351] trunk/Source/WebCore
Revision
230351
Author
bfulg...@apple.com
Date
2018-04-06 12:37:17 -0700 (Fri, 06 Apr 2018)

Log Message

WebCore::screenColorSpace is retrieving CGColorSpace from NSScreen directly
https://bugs.webkit.org/show_bug.cgi?id=184343
<rdar://problem/39224881>

Reviewed by Per Arne Vollan.

Revise ScreenProperties to serialize the screen's color space, and later
retrieve that in the WebContent process. This allows us to close off
the CGSWindowServer connection.

* platform/ScreenProperties.h:
(WebCore::ScreenProperties::encode const): Add CGColorSpaceRef support.
(WebCore::ScreenProperties::decode): Ditto.
* platform/mac/PlatformScreenMac.mm:
(WebCore::displayID): Add assertion to prevent use in WebContent process.
(WebCore::firstScreen): Ditto.
(WebCore::getScreenProperties): Add support for CGColorSpaceRef.
(WebCore::screenColorSpace): Retrieve cached version when in WebContent process.
Assert that NSScreen is not accessed in WebContent process.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (230350 => 230351)


--- trunk/Source/WebCore/ChangeLog	2018-04-06 19:33:32 UTC (rev 230350)
+++ trunk/Source/WebCore/ChangeLog	2018-04-06 19:37:17 UTC (rev 230351)
@@ -1,3 +1,25 @@
+2018-04-06  Brent Fulgham  <bfulg...@apple.com>
+
+        WebCore::screenColorSpace is retrieving CGColorSpace from NSScreen directly
+        https://bugs.webkit.org/show_bug.cgi?id=184343
+        <rdar://problem/39224881>
+
+        Reviewed by Per Arne Vollan.
+
+        Revise ScreenProperties to serialize the screen's color space, and later
+        retrieve that in the WebContent process. This allows us to close off
+        the CGSWindowServer connection.
+
+        * platform/ScreenProperties.h:
+        (WebCore::ScreenProperties::encode const): Add CGColorSpaceRef support.
+        (WebCore::ScreenProperties::decode): Ditto.
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::displayID): Add assertion to prevent use in WebContent process.
+        (WebCore::firstScreen): Ditto.
+        (WebCore::getScreenProperties): Add support for CGColorSpaceRef.
+        (WebCore::screenColorSpace): Retrieve cached version when in WebContent process.
+        Assert that NSScreen is not accessed in WebContent process.
+
 2018-04-06  Ms2ger  <ms2...@igalia.com>
 
         Implement createImageBitmap(Blob)

Modified: trunk/Source/WebCore/platform/ScreenProperties.h (230350 => 230351)


--- trunk/Source/WebCore/platform/ScreenProperties.h	2018-04-06 19:33:32 UTC (rev 230350)
+++ trunk/Source/WebCore/platform/ScreenProperties.h	2018-04-06 19:37:17 UTC (rev 230351)
@@ -25,18 +25,31 @@
 
 #pragma once
 
+#if PLATFORM(MAC)
+
 #include "FloatRect.h"
+#include <wtf/RetainPtr.h>
+#include <wtf/text/WTFString.h>
 
+typedef struct CGColorSpace *CGColorSpaceRef;
+
 namespace WebCore {
 
 struct ScreenProperties {
     FloatRect screenAvailableRect;
     FloatRect screenRect;
+    RetainPtr<CGColorSpaceRef> colorSpace;
     int screenDepth { 0 };
     int screenDepthPerComponent { 0 };
     bool screenHasInvertedColors { false };
     bool screenIsMonochrome { false };
 
+    enum EncodedColorSpaceDataType {
+        Null,
+        ColorSpaceName,
+        ColorSpaceData,
+    };
+
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<ScreenProperties> decode(Decoder&);
 };
@@ -45,6 +58,29 @@
 void ScreenProperties::encode(Encoder& encoder) const
 {
     encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenHasInvertedColors << screenIsMonochrome;
+
+    if (colorSpace) {
+        // Try to encode the name.
+        if (auto name = adoptCF(CGColorSpaceCopyName(colorSpace.get()))) {
+            encoder.encodeEnum(ColorSpaceName);
+            encoder << String(name.get());
+            return;
+        }
+
+        // Failing that, just encode the ICC data.
+        if (auto profileData = adoptCF(CGColorSpaceCopyICCData(colorSpace.get()))) {
+            encoder.encodeEnum(ColorSpaceData);
+
+            Vector<uint8_t> iccData;
+            iccData.append(CFDataGetBytePtr(profileData.get()), CFDataGetLength(profileData.get()));
+
+            encoder << iccData;
+            return;
+        }
+    }
+
+    // The color space was null or failed to be encoded.
+    encoder << Null;
 }
 
 template<class Decoder>
@@ -80,8 +116,44 @@
     if (!screenIsMonochrome)
         return std::nullopt;
 
-    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
+    EncodedColorSpaceDataType dataType;
+    if (!decoder.decodeEnum(dataType))
+        return std::nullopt;
+
+    RetainPtr<CGColorSpaceRef> cgColorSpace;
+    switch (dataType) {
+    case Null:
+        break;
+    case ColorSpaceName: {
+        std::optional<String> colorSpaceName;
+        decoder >> colorSpaceName;
+        ASSERT(colorSpaceName);
+        if (!colorSpaceName)
+            return std::nullopt;
+
+        cgColorSpace = adoptCF(CGColorSpaceCreateWithName(colorSpaceName->createCFString().get()));
+        break;
+    }
+    case ColorSpaceData: {
+        std::optional<Vector<uint8_t>> iccData;
+        decoder >> iccData;
+        ASSERT(iccData);
+        if (!iccData)
+            return std::nullopt;
+
+        auto colorSpaceData = adoptCF(CFDataCreate(kCFAllocatorDefault, iccData->data(), iccData->size()));
+        // FIXME: <http://webkit.org/b/184358> We should switch to CGColorSpaceCreateICCBased.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+        cgColorSpace = adoptCF(CGColorSpaceCreateWithICCProfile(colorSpaceData.get()));
+#pragma clang diagnostic pop
+        break;
+    }
+    }
+
+    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
 }
 
 } // namespace WebCore
 
+#endif // PLATFORM(MAC)

Modified: trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm (230350 => 230351)


--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2018-04-06 19:33:32 UTC (rev 230350)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2018-04-06 19:37:17 UTC (rev 230351)
@@ -48,7 +48,7 @@
 
 static PlatformDisplayID displayID(NSScreen *screen)
 {
-    // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
 }
 
@@ -71,7 +71,7 @@
 // Screen containing the menubar.
 static NSScreen *firstScreen()
 {
-    // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     NSArray *screens = [NSScreen screens];
     if (![screens count])
         return nil;
@@ -102,16 +102,20 @@
 
 void getScreenProperties(HashMap<PlatformDisplayID, ScreenProperties>& screenProperties)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     for (NSScreen *screen in [NSScreen screens]) {
-        FloatRect screenAvailableRect = [screen visibleFrame];
-        screenAvailableRect.setY(NSMaxY([screen frame]) - (screenAvailableRect.y() + screenAvailableRect.height())); // flip
-        FloatRect screenRect = [screen frame];
+        FloatRect screenAvailableRect = screen.visibleFrame;
+        screenAvailableRect.setY(NSMaxY(screen.frame) - (screenAvailableRect.y() + screenAvailableRect.height())); // flip
+        FloatRect screenRect = screen.frame;
+
+        RetainPtr<CGColorSpaceRef> colorSpace = screen.colorSpace.CGColorSpace;
+
         int screenDepth = NSBitsPerPixelFromDepth(screen.depth);
         int screenDepthPerComponent = NSBitsPerSampleFromDepth(screen.depth);
         bool screenHasInvertedColors = CGDisplayUsesInvertedPolarity();
         bool screenIsMonochrome = CGDisplayUsesForceToGray();
 
-        screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, screenDepth, screenDepthPerComponent, screenHasInvertedColors, screenIsMonochrome });
+        screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenHasInvertedColors, screenIsMonochrome });
     }
 }
 
@@ -213,7 +217,10 @@
 
 CGColorSpaceRef screenColorSpace(Widget* widget)
 {
-    // FIXME: <http://webkit.org/b/184343> We should assert here if in WebContent process.
+    if (!screenProperties().isEmpty())
+        return getScreenProperties(widget).colorSpace.get();
+
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return screen(widget).colorSpace.CGColorSpace;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to