Title: [247921] trunk/Source/WebKit
Revision
247921
Author
[email protected]
Date
2019-07-29 14:21:54 -0700 (Mon, 29 Jul 2019)

Log Message

ShareableBitmap::createGraphicsContext() should return nullptr when CGBitmapContextCreateWithData returns nil
https://bugs.webkit.org/show_bug.cgi?id=200185

Reviewed by Simon Fraser.

We should not be creating GraphicsContext with nil CGContextRef in ShareableBitmap::createGraphicsContext()
as such a GraphicsContext is only used for specific purposes.

This patch adds an early return to ShareableBitmap::createGraphicsContext() when CGBitmapContextCreateWithData
returns nil CGContextRef.

* PluginProcess/PluginControllerProxy.cpp:
(WebKit::PluginControllerProxy::paint):
* Shared/API/c/cg/WKImageCG.cpp:
(WKImageCreateFromCGImage):
* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::display):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::encodeImage):
* Shared/cg/ShareableBitmapCG.cpp:
(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::makeCGImageCopy):
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::imageForRect):
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::renderedImage):
* WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::image const):
* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::snapshot):
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::snapshot):
* WebProcess/Plugins/PluginProxy.cpp:
(WebKit::PluginProxy::paint):
(WebKit::PluginProxy::update):
* WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::convertCGImageToBitmap):
* WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::display):
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::createSelectionSnapshot const):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::snapshotAtSize):
(WebKit::WebPage::snapshotNode):
(WebKit::WebPage::drawRectToImage):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247920 => 247921)


--- trunk/Source/WebKit/ChangeLog	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/ChangeLog	2019-07-29 21:21:54 UTC (rev 247921)
@@ -1,3 +1,53 @@
+2019-07-26  Ryosuke Niwa  <[email protected]>
+
+        ShareableBitmap::createGraphicsContext() should return nullptr when CGBitmapContextCreateWithData returns nil
+        https://bugs.webkit.org/show_bug.cgi?id=200185
+
+        Reviewed by Simon Fraser.
+
+        We should not be creating GraphicsContext with nil CGContextRef in ShareableBitmap::createGraphicsContext()
+        as such a GraphicsContext is only used for specific purposes.
+
+        This patch adds an early return to ShareableBitmap::createGraphicsContext() when CGBitmapContextCreateWithData
+        returns nil CGContextRef.
+
+        * PluginProcess/PluginControllerProxy.cpp:
+        (WebKit::PluginControllerProxy::paint):
+        * Shared/API/c/cg/WKImageCG.cpp:
+        (WKImageCreateFromCGImage):
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::display):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::encodeImage):
+        * Shared/cg/ShareableBitmapCG.cpp:
+        (WebKit::ShareableBitmap::createGraphicsContext):
+        (WebKit::ShareableBitmap::makeCGImageCopy):
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::imageForRect):
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
+        (WebKit::InjectedBundleRangeHandle::renderedImage):
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+        (WebKit::InjectedBundleHitTestResult::image const):
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        (WebKit::NetscapePlugin::snapshot):
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::snapshot):
+        * WebProcess/Plugins/PluginProxy.cpp:
+        (WebKit::PluginProxy::paint):
+        (WebKit::PluginProxy::update):
+        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
+        (WebKit::convertCGImageToBitmap):
+        * WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
+        (WebKit::DrawingAreaCoordinatedGraphics::display):
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::createSelectionSnapshot const):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::snapshotAtSize):
+        (WebKit::WebPage::snapshotNode):
+        (WebKit::WebPage::drawRectToImage):
+
 2019-07-29  Dean Jackson  <[email protected]>
 
         Contextual menu does not present when holding an embedded photo but works with link and attachments

Modified: trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp (247920 => 247921)


--- trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -183,6 +183,8 @@
 
     // Create a graphics context.
     auto graphicsContext = m_backingStore->createGraphicsContext();
+    if (!graphicsContext)
+        return;
 
 #if PLATFORM(COCOA)
     // FIXME: We should really call applyDeviceScaleFactor instead of scale, but that ends up calling into WKSI

Modified: trunk/Source/WebKit/Shared/API/c/cg/WKImageCG.cpp (247920 => 247921)


--- trunk/Source/WebKit/Shared/API/c/cg/WKImageCG.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/Shared/API/c/cg/WKImageCG.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -50,6 +50,9 @@
     auto webImage = WebKit::WebImage::create(imageSize, WebKit::toImageOptions(options));
 
     auto graphicsContext = webImage->bitmap().createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     WebCore::FloatRect rect(WebCore::FloatPoint(0, 0), imageSize);
     graphicsContext->clearRect(rect);
     graphicsContext->drawNativeImage(imageRef, imageSize, rect, rect);

Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.cpp (247920 => 247921)


--- trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -65,7 +65,10 @@
 
     // FIXME: figure out the rounding strategy for ShareableBitmap.
     m_controlledImage = ShareableBitmap::createShareable(IntSize(image->size()), { });
-    m_controlledImage->createGraphicsContext()->drawImage(*image, IntPoint());
+    auto graphicsContext = m_controlledImage->createGraphicsContext();
+    if (!graphicsContext)
+        return;
+    graphicsContext->drawImage(*image, IntPoint());
 #endif
 }
 

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (247920 => 247921)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2019-07-29 21:21:54 UTC (rev 247921)
@@ -279,7 +279,8 @@
         if (m_backBuffer.bitmap && !willPaintEntireBackingStore)
             backImage = m_backBuffer.bitmap->makeCGImage();
 
-        drawInContext(*context, backImage.get());
+        if (context)
+            drawInContext(*context, backImage.get());
     }
     
     m_layer->owner()->platformCALayerLayerDidDisplay(m_layer);

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (247920 => 247921)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -1095,7 +1095,9 @@
 static void encodeImage(Encoder& encoder, Image& image)
 {
     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(IntSize(image.size()), { });
-    bitmap->createGraphicsContext()->drawImage(image, IntPoint());
+    auto graphicsContext = bitmap->createGraphicsContext();
+    if (graphicsContext)
+        graphicsContext->drawImage(image, IntPoint());
 
     ShareableBitmap::Handle handle;
     bitmap->createHandle(handle);

Modified: trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (247920 => 247921)


--- trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -91,7 +91,9 @@
 
     unsigned bytesPerPixel = calculateBytesPerPixel(m_configuration);
     RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), bytesPerPixel * 8 / 4, calculateBytesPerRow(m_size, m_configuration).unsafeGet(), colorSpace(m_configuration), bitmapInfo(m_configuration), releaseBitmapContextData, this));
-    
+    if (!bitmapContext)
+        return nullptr;
+
     ASSERT(bitmapContext.get());
 
     // We want the origin to be in the top left corner so we flip the backing store context.
@@ -114,6 +116,9 @@
 RetainPtr<CGImageRef> ShareableBitmap::makeCGImageCopy()
 {
     auto graphicsContext = createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     RetainPtr<CGImageRef> image = adoptCF(CGBitmapContextCreateImage(graphicsContext->platformContext()));
     return image;
 }

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -160,6 +160,9 @@
         return nullptr;
 
     auto graphicsContext = snapshot->bitmap().createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     graphicsContext->clearRect(IntRect(IntPoint(), bitmapSize));
     graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
     graphicsContext->scale(bitmapScaleFactor);

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -143,6 +143,9 @@
         return nullptr;
 
     auto graphicsContext = backingStore->createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     graphicsContext->scale(scaleFactor);
 
     paintRect.move(frameView->frameRect().x(), frameView->frameRect().y());

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -182,6 +182,9 @@
 
     // FIXME: need to handle EXIF rotation.
     auto graphicsContext = webImage->bitmap().createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     graphicsContext->drawImage(bitmapImage, {{ }, size});
 
     return webImage;

Modified: trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -749,6 +749,8 @@
 
     auto bitmap = ShareableBitmap::createShareable(backingStoreSize, { });
     auto context = bitmap->createGraphicsContext();
+    if (!context)
+        return nullptr;
 
     // FIXME: We should really call applyDeviceScaleFactor instead of scale, but that ends up calling into WKSI
     // which we currently don't have initiated in the plug-in process.

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2019-07-29 21:21:54 UTC (rev 247921)
@@ -1244,6 +1244,8 @@
 
     auto bitmap = ShareableBitmap::createShareable(backingStoreSize, { });
     auto context = bitmap->createGraphicsContext();
+    if (!context)
+        return nullptr;
 
     context->scale(FloatSize(contentsScaleFactor, -contentsScaleFactor));
     context->translate(-m_scrollOffset.width(), -m_pdfDocumentSize.height() + m_scrollOffset.height());

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -213,12 +213,14 @@
     
         // Blit the plug-in backing store into our own backing store.
         auto graphicsContext = m_backingStore->createGraphicsContext();
-        graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
-        graphicsContext->setCompositeOperation(CompositeCopy);
+        if (graphicsContext) {
+            graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
+            graphicsContext->setCompositeOperation(CompositeCopy);
 
-        m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), IntPoint(), pluginBounds());
+            m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), IntPoint(), pluginBounds());
 
-        m_pluginBackingStoreContainsValidData = true;
+            m_pluginBackingStoreContainsValidData = true;
+        }
     }
 
     m_backingStore->paint(graphicsContext, contentsScaleFactor(), dirtyRect.location(), dirtyRect);
@@ -723,9 +725,11 @@
     if (m_backingStore) {
         // Blit the plug-in backing store into our own backing store.
         auto graphicsContext = m_backingStore->createGraphicsContext();
-        graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
-        graphicsContext->setCompositeOperation(CompositeCopy);
-        m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), paintedRect.location(), paintedRect);
+        if (graphicsContext) {
+            graphicsContext->applyDeviceScaleFactor(contentsScaleFactor());
+            graphicsContext->setCompositeOperation(CompositeCopy);
+            m_pluginBackingStore->paint(*graphicsContext, contentsScaleFactor(), paintedRect.location(), paintedRect);
+        }
     }
 
     // Ask the controller to invalidate the rect for us.

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm	2019-07-29 21:21:54 UTC (rev 247921)
@@ -184,6 +184,9 @@
         return nullptr;
 
     auto graphicsContext = bitmap->createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     UIGraphicsPushContext(graphicsContext->platformContext());
     CGContextDrawImage(graphicsContext->platformContext(), CGRectMake(0, 0, size.width(), size.height()), image);
     UIGraphicsPopContext();

Modified: trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -731,14 +731,16 @@
     m_scrollOffset = IntSize();
 
     auto graphicsContext = bitmap->createGraphicsContext();
-    graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
+    if (graphicsContext) {
+        graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
+        graphicsContext->translate(-bounds.x(), -bounds.y());
+    }
 
     updateInfo.updateRectBounds = bounds;
 
-    graphicsContext->translate(-bounds.x(), -bounds.y());
-
     for (const auto& rect : rects) {
-        m_webPage.drawRect(*graphicsContext, rect);
+        if (graphicsContext)
+            m_webPage.drawRect(*graphicsContext, rect);
         updateInfo.updateRects.append(rect);
     }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -856,6 +856,9 @@
     // FIXME: We should consider providing a way to use subpixel antialiasing for the snapshot
     // if we're compositing this image onto a solid color (e.g. the modern find indicator style).
     auto graphicsContext = sharedSnapshot->createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
     float deviceScaleFactor = coreFrame()->page()->deviceScaleFactor();
     graphicsContext->scale(deviceScaleFactor);
     graphicsContext->drawConsumingImageBuffer(WTFMove(snapshot), FloatPoint());

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (247920 => 247921)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-07-29 21:19:41 UTC (rev 247920)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-07-29 21:21:54 UTC (rev 247921)
@@ -2372,6 +2372,8 @@
     if (!snapshot)
         return nullptr;
     auto graphicsContext = snapshot->bitmap().createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
 
     paintSnapshotAtSize(rect, bitmapSize, options, *coreFrame, *frameView, *graphicsContext);
 
@@ -2441,6 +2443,8 @@
     if (!snapshot)
         return nullptr;
     auto graphicsContext = snapshot->bitmap().createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
 
     if (!(options & SnapshotOptionsExcludeDeviceScaleFactor)) {
         double deviceScaleFactor = corePage()->deviceScaleFactor();
@@ -4782,20 +4786,21 @@
             return;
         }
         auto graphicsContext = bitmap->createGraphicsContext();
+        if (graphicsContext) {
+            float printingScale = static_cast<float>(imageSize.width()) / rect.width();
+            graphicsContext->scale(printingScale);
 
-        float printingScale = static_cast<float>(imageSize.width()) / rect.width();
-        graphicsContext->scale(printingScale);
-
 #if PLATFORM(MAC)
-        if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
-            ASSERT(!m_printContext);
-            graphicsContext->scale(FloatSize(1, -1));
-            graphicsContext->translate(0, -rect.height());
-            drawPDFDocument(graphicsContext->platformContext(), pdfDocument.get(), printInfo, rect);
-        } else
+            if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
+                ASSERT(!m_printContext);
+                graphicsContext->scale(FloatSize(1, -1));
+                graphicsContext->translate(0, -rect.height());
+                drawPDFDocument(graphicsContext->platformContext(), pdfDocument.get(), printInfo, rect);
+            } else
 #endif
-        {
-            m_printContext->spoolRect(*graphicsContext, rect);
+            {
+                m_printContext->spoolRect(*graphicsContext, rect);
+            }
         }
 
         image = WebImage::create(bitmap.releaseNonNull());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to