WebCore::screenSupportsExtendedColor improperly calls NSScreen functions in the WebCo...
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 22:54:37 +0000 (22:54 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 22:54:37 +0000 (22:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184364
<rdar://problem/39246314>

Reviewed by Per Arne Vollan.

The WebContent process is interacting directly with NSScreen to determine if the current screen
has extended color support. This should be brokered from the UIProcess.

Tested by fast/media/mq-color-gamut.html.

* platform/ScreenProperties.h:
(WebCore::ScreenProperties::encode const): Add screenSupportsExtendedColor.
(WebCore::ScreenProperties::decode): Ditto.
* platform/mac/PlatformScreenMac.mm:
(WebCore::getScreenProperties): Retrieve extended color support.
(WebCore::screenSupportsExtendedColor): Retrieve cached version when in the WebContent
process. Assert that NSScreen is not accessed in the WebContent process.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/ScreenProperties.h
Source/WebCore/platform/mac/PlatformScreenMac.mm

index 81b9ecf..65d0507 100644 (file)
@@ -1,3 +1,24 @@
+2018-04-06  Brent Fulgham  <bfulgham@apple.com>
+
+        WebCore::screenSupportsExtendedColor improperly calls NSScreen functions in the WebContent process
+        https://bugs.webkit.org/show_bug.cgi?id=184364
+        <rdar://problem/39246314>
+
+        Reviewed by Per Arne Vollan.
+
+        The WebContent process is interacting directly with NSScreen to determine if the current screen
+        has extended color support. This should be brokered from the UIProcess.
+        
+        Tested by fast/media/mq-color-gamut.html.
+
+        * platform/ScreenProperties.h:
+        (WebCore::ScreenProperties::encode const): Add screenSupportsExtendedColor.
+        (WebCore::ScreenProperties::decode): Ditto.
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::getScreenProperties): Retrieve extended color support.
+        (WebCore::screenSupportsExtendedColor): Retrieve cached version when in the WebContent
+        process. Assert that NSScreen is not accessed in the WebContent process.
+
 2018-04-06  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win][WebCore] Expose a constant for scrollbar pixels per line (cScrollbarPixelsPerLine)
index fc96d1b..f92f552 100644 (file)
@@ -41,6 +41,7 @@ struct ScreenProperties {
     RetainPtr<CGColorSpaceRef> colorSpace;
     int screenDepth { 0 };
     int screenDepthPerComponent { 0 };
+    bool screenSupportsExtendedColor { false };
     bool screenHasInvertedColors { false };
     bool screenIsMonochrome { false };
 
@@ -57,7 +58,7 @@ struct ScreenProperties {
 template<class Encoder>
 void ScreenProperties::encode(Encoder& encoder) const
 {
-    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenHasInvertedColors << screenIsMonochrome;
+    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenSupportsExtendedColor << screenHasInvertedColors << screenIsMonochrome;
 
     if (colorSpace) {
         // Try to encode the name.
@@ -106,6 +107,11 @@ std::optional<ScreenProperties> ScreenProperties::decode(Decoder& decoder)
     if (!screenDepthPerComponent)
         return std::nullopt;
 
+    std::optional<bool> screenSupportsExtendedColor;
+    decoder >> screenSupportsExtendedColor;
+    if (!screenSupportsExtendedColor)
+        return std::nullopt;
+
     std::optional<bool> screenHasInvertedColors;
     decoder >> screenHasInvertedColors;
     if (!screenHasInvertedColors)
@@ -151,7 +157,7 @@ std::optional<ScreenProperties> ScreenProperties::decode(Decoder& decoder)
     }
     }
 
-    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
+    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenSupportsExtendedColor), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome) } };
 }
 
 } // namespace WebCore
index f9fe575..27a435d 100644 (file)
@@ -48,7 +48,7 @@ namespace WebCore {
 
 static PlatformDisplayID displayID(NSScreen *screen)
 {
-    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
+    // FIXME: <https://webkit.org/b/184344> We should assert here if in WebContent process.
     return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
 }
 
@@ -71,7 +71,7 @@ static PlatformDisplayID displayID(Widget* widget)
 // Screen containing the menubar.
 static NSScreen *firstScreen()
 {
-    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
+    // FIXME: <https://webkit.org/b/184344> We should assert here if in WebContent process.
     NSArray *screens = [NSScreen screens];
     if (![screens count])
         return nil;
@@ -112,10 +112,11 @@ void getScreenProperties(HashMap<PlatformDisplayID, ScreenProperties>& screenPro
 
         int screenDepth = NSBitsPerPixelFromDepth(screen.depth);
         int screenDepthPerComponent = NSBitsPerSampleFromDepth(screen.depth);
+        bool screenSupportsExtendedColor = [screen canRepresentDisplayGamut:NSDisplayGamutP3];
         bool screenHasInvertedColors = CGDisplayUsesInvertedPolarity();
         bool screenIsMonochrome = CGDisplayUsesForceToGray();
 
-        screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenHasInvertedColors, screenIsMonochrome });
+        screenProperties.set(WebCore::displayID(screen), ScreenProperties { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenIsMonochrome });
     }
 }
 
@@ -229,7 +230,10 @@ bool screenSupportsExtendedColor(Widget* widget)
     if (!widget)
         return false;
 
-    // FIXME: <https://webkit.org/b/184364> We should assert here if in WebContent process.
+    if (!screenProperties().isEmpty())
+        return getScreenProperties(widget).screenSupportsExtendedColor;
+
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     return [screen(widget) canRepresentDisplayGamut:NSDisplayGamutP3];
 }