<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[207590] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207590">207590</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-10-20 01:33:44 -0700 (Thu, 20 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Wrong use of EGL_DEPTH_SIZE
https://bugs.webkit.org/show_bug.cgi?id=155536

Reviewed by Michael Catanzaro.

Source/WebCore:

What happens here is that the driver doesn't implement EGL_DEPTH_SIZE and the default value, which is 0, is
returned. Then XCreatePixmap fails because 0 is not a valid depth. The thing is that even if EGL_DEPTH_SIZE or
EGL_BUFFER_SIZE returned a valid depth, it still might not be supported by the default screen and XCreatePixmap
can fail. What we need to ensure is that the depth we pass is compatible with the X display, not only with the
EGL config, to avoid failures when creating the pixmap. So, we can use EGL_NATIVE_VISUAL_ID instead, and
then ask X for the visual info for that id. If it isn't found then we just return before creating the pixmap,
but if the visual is found then we can be sure that the depth of the visual will not make the pixmap creation
fail. However, with the driver I'm using it doesn't matter how we create the pixmap that eglCreatePixmapSurface
always fails, again with X errors that are fatal by default. Since the driver is not free, I assume it doesn't
support eglCreatePixmapSurface or it's just buggy, so the only option we have here is trap the x errors and
ignore them. It turns out that the X errors are not fatal in this case, because eglCreatePixmapSurface ends up
returning a surface, and since these are offscreen contexts, it doesn't really matter if they contain an
invalid pixmap, because we never do swap buffer on them, so just ignoring the X errors fixes the crashes and
makes everythig work. This patch adds a helper class XErrorTrapper that allows to trap XErrors and decide what
to do with them (ignore, warn or crash) or even not consider a particular set of errors as errors.

* PlatformEfl.cmake: Add new file to compilation.
* PlatformGTK.cmake: Ditto.
* platform/graphics/egl/GLContextEGL.cpp:
(WebCore::GLContextEGL::createPixmapContext): Use EGL_NATIVE_VISUAL_ID instead of EGL_DEPTH_SIZE to figure out
the depth to be passed to XCreatePixmap. Also use the XErrorTrapper class to ignore all BadDrawable errors
produced by eglCreatePixmapSurface() and only show a warning about all other X errors.
* platform/graphics/x11/XErrorTrapper.cpp: Added.
(WebCore::xErrorTrappersMap):
(WebCore::XErrorTrapper::XErrorTrapper):
(WebCore::XErrorTrapper::~XErrorTrapper):
(WebCore::XErrorTrapper::errorCode):
(WebCore::XErrorTrapper::errorEvent):
* platform/graphics/x11/XErrorTrapper.h: Added.
(WebCore::XErrorTrapper::XErrorTrapper):

Source/WebKit2:

Use XErrorTrapper class instead of the custom XErrorHandler.

* PluginProcess/unix/PluginProcessMainUnix.cpp:
(WebKit::PluginProcessMainUnix):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePlatformEflcmake">trunk/Source/WebCore/PlatformEfl.cmake</a></li>
<li><a href="#trunkSourceWebCorePlatformGTKcmake">trunk/Source/WebCore/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicseglGLContextEGLcpp">trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PluginProcessunixPluginProcessMainUnixcpp">trunk/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicsx11XErrorTrappercpp">trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsx11XErrorTrapperh">trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebCore/ChangeLog        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2016-10-20  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        Wrong use of EGL_DEPTH_SIZE
+        https://bugs.webkit.org/show_bug.cgi?id=155536
+
+        Reviewed by Michael Catanzaro.
+
+        What happens here is that the driver doesn't implement EGL_DEPTH_SIZE and the default value, which is 0, is
+        returned. Then XCreatePixmap fails because 0 is not a valid depth. The thing is that even if EGL_DEPTH_SIZE or
+        EGL_BUFFER_SIZE returned a valid depth, it still might not be supported by the default screen and XCreatePixmap
+        can fail. What we need to ensure is that the depth we pass is compatible with the X display, not only with the
+        EGL config, to avoid failures when creating the pixmap. So, we can use EGL_NATIVE_VISUAL_ID instead, and
+        then ask X for the visual info for that id. If it isn't found then we just return before creating the pixmap,
+        but if the visual is found then we can be sure that the depth of the visual will not make the pixmap creation
+        fail. However, with the driver I'm using it doesn't matter how we create the pixmap that eglCreatePixmapSurface
+        always fails, again with X errors that are fatal by default. Since the driver is not free, I assume it doesn't
+        support eglCreatePixmapSurface or it's just buggy, so the only option we have here is trap the x errors and
+        ignore them. It turns out that the X errors are not fatal in this case, because eglCreatePixmapSurface ends up
+        returning a surface, and since these are offscreen contexts, it doesn't really matter if they contain an
+        invalid pixmap, because we never do swap buffer on them, so just ignoring the X errors fixes the crashes and
+        makes everythig work. This patch adds a helper class XErrorTrapper that allows to trap XErrors and decide what
+        to do with them (ignore, warn or crash) or even not consider a particular set of errors as errors.
+
+        * PlatformEfl.cmake: Add new file to compilation.
+        * PlatformGTK.cmake: Ditto.
+        * platform/graphics/egl/GLContextEGL.cpp:
+        (WebCore::GLContextEGL::createPixmapContext): Use EGL_NATIVE_VISUAL_ID instead of EGL_DEPTH_SIZE to figure out
+        the depth to be passed to XCreatePixmap. Also use the XErrorTrapper class to ignore all BadDrawable errors
+        produced by eglCreatePixmapSurface() and only show a warning about all other X errors.
+        * platform/graphics/x11/XErrorTrapper.cpp: Added.
+        (WebCore::xErrorTrappersMap):
+        (WebCore::XErrorTrapper::XErrorTrapper):
+        (WebCore::XErrorTrapper::~XErrorTrapper):
+        (WebCore::XErrorTrapper::errorCode):
+        (WebCore::XErrorTrapper::errorEvent):
+        * platform/graphics/x11/XErrorTrapper.h: Added.
+        (WebCore::XErrorTrapper::XErrorTrapper):
+
</ins><span class="cx"> 2016-10-20  Nael Ouedraogo  &lt;nael.ouedraogo@crf.canon.fr&gt;
</span><span class="cx"> 
</span><span class="cx">         WebRTC: The MediaStreamTrackEvent init dictionary needs a required track member
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformEflcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformEfl.cmake (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformEfl.cmake        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebCore/PlatformEfl.cmake        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -182,6 +182,7 @@
</span><span class="cx">     platform/graphics/surfaces/glx/X11Helper.cpp
</span><span class="cx"> 
</span><span class="cx">     platform/graphics/x11/PlatformDisplayX11.cpp
</span><ins>+    platform/graphics/x11/XErrorTrapper.cpp
</ins><span class="cx">     platform/graphics/x11/XUniqueResource.cpp
</span><span class="cx"> 
</span><span class="cx">     platform/image-decoders/cairo/ImageBackingStoreCairo.cpp
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformGTK.cmake (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformGTK.cmake        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebCore/PlatformGTK.cmake        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -149,6 +149,7 @@
</span><span class="cx">     platform/graphics/wayland/PlatformDisplayWayland.cpp
</span><span class="cx"> 
</span><span class="cx">     platform/graphics/x11/PlatformDisplayX11.cpp
</span><ins>+    platform/graphics/x11/XErrorTrapper.cpp
</ins><span class="cx">     platform/graphics/x11/XUniqueResource.cpp
</span><span class="cx"> 
</span><span class="cx">     platform/gtk/DragDataGtk.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicseglGLContextEGLcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -36,6 +36,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(X11)
</span><span class="cx"> #include &quot;PlatformDisplayX11.h&quot;
</span><ins>+#include &quot;XErrorTrapper.h&quot;
+#include &quot;XUniquePtr.h&quot;
</ins><span class="cx"> #include &lt;X11/Xlib.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -175,19 +177,37 @@
</span><span class="cx">     if (context == EGL_NO_CONTEXT)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    EGLint depth;
-    if (!eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &amp;depth)) {
</del><ins>+    EGLint visualId;
+    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &amp;visualId)) {
</ins><span class="cx">         eglDestroyContext(display, context);
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Display* x11Display = downcast&lt;PlatformDisplayX11&gt;(platformDisplay).native();
</span><del>-    XUniquePixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, depth);
</del><ins>+
+    XVisualInfo visualInfo;
+    visualInfo.visualid = visualId;
+    int numVisuals = 0;
+    XUniquePtr&lt;XVisualInfo&gt; visualInfoList(XGetVisualInfo(x11Display, VisualIDMask, &amp;visualInfo, &amp;numVisuals));
+    if (!visualInfoList || !numVisuals) {
+        eglDestroyContext(display, context);
+        return nullptr;
+    }
+
+    // We are using VisualIDMask so there must be only one.
+    ASSERT(numVisuals == 1);
+    XUniquePixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, visualInfoList.get()[0].depth);
</ins><span class="cx">     if (!pixmap) {
</span><span class="cx">         eglDestroyContext(display, context);
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // Some drivers fail to create the surface producing BadDrawable X error and the default XError handler normally aborts.
+    // However, if the X error is ignored, eglCreatePixmapSurface() ends up returning a surface and we can continue creating
+    // the context. Since this is an offscreen context, it doesn't matter if the pixmap used is not valid because we never do
+    // swap buffers. So, we use a custom XError handler here that ignores BadDrawable errors and only warns about any other
+    // errors without aborting in any case.
+    XErrorTrapper trapper(x11Display, XErrorTrapper::Policy::Warn, { BadDrawable });
</ins><span class="cx">     EGLSurface surface = eglCreatePixmapSurface(display, config, reinterpret_cast&lt;EGLNativePixmapType&gt;(pixmap.get()), 0);
</span><span class="cx">     if (surface == EGL_NO_SURFACE) {
</span><span class="cx">         eglDestroyContext(display, context);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsx11XErrorTrappercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.cpp (0 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.cpp        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -0,0 +1,101 @@
</span><ins>+/*
+ * Copyright (C) 2016 Igalia S.L
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;XErrorTrapper.h&quot;
+
+#if PLATFORM(X11)
+#include &lt;sys/types.h&gt;
+#include &lt;unistd.h&gt;
+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
+
+namespace WebCore {
+
+static HashMap&lt;Display*, Vector&lt;XErrorTrapper*&gt;&gt;&amp; xErrorTrappersMap()
+{
+    static NeverDestroyed&lt;HashMap&lt;Display*, Vector&lt;XErrorTrapper*&gt;&gt;&gt; trappersMap;
+    return trappersMap;
+}
+
+XErrorTrapper::XErrorTrapper(Display* display, Policy policy, Vector&lt;unsigned char&gt;&amp;&amp; expectedErrors)
+    : m_display(display)
+    , m_policy(policy)
+    , m_expectedErrors(WTFMove(expectedErrors))
+{
+    xErrorTrappersMap().add(m_display, Vector&lt;XErrorTrapper*&gt;()).iterator-&gt;value.append(this);
+    m_previousErrorHandler = XSetErrorHandler([](Display* display, XErrorEvent* event) -&gt; int {
+        auto iterator = xErrorTrappersMap().find(display);
+        if (iterator == xErrorTrappersMap().end())
+            return 0;
+
+        ASSERT(!iterator-&gt;value.isEmpty());
+        iterator-&gt;value.last()-&gt;errorEvent(event);
+        return 0;
+    });
+}
+
+XErrorTrapper::~XErrorTrapper()
+{
+    XSync(m_display, False);
+    auto iterator = xErrorTrappersMap().find(m_display);
+    ASSERT(iterator != xErrorTrappersMap().end());
+    auto* trapper = iterator-&gt;value.takeLast();
+    ASSERT_UNUSED(trapper, trapper == this);
+    if (iterator-&gt;value.isEmpty())
+        xErrorTrappersMap().remove(iterator);
+
+    XSetErrorHandler(m_previousErrorHandler);
+}
+
+unsigned char XErrorTrapper::errorCode() const
+{
+    XSync(m_display, False);
+    return m_errorCode;
+}
+
+void XErrorTrapper::errorEvent(XErrorEvent* event)
+{
+    m_errorCode = event-&gt;error_code;
+    if (m_policy == Policy::Ignore)
+        return;
+
+    if (m_expectedErrors.contains(m_errorCode))
+        return;
+
+    static const char errorFormatString[] = &quot;The program with pid %d received an X Window System error.\n&quot;
+        &quot;The error was '%s'.\n&quot;
+        &quot;  (Details: serial %ld error_code %d request_code %d minor_code %d)\n&quot;;
+    char errorMessage[64];
+    XGetErrorText(m_display, m_errorCode, errorMessage, 63);
+    WTFLogAlways(errorFormatString, getpid(), errorMessage, event-&gt;serial, event-&gt;error_code, event-&gt;request_code, event-&gt;minor_code);
+
+    if (m_policy == Policy::Crash)
+        CRASH();
+}
+
+} // namespace WebCore
+
+#endif // PLATFORM(X11)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsx11XErrorTrapperh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.h (0 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.h                                (rev 0)
+++ trunk/Source/WebCore/platform/graphics/x11/XErrorTrapper.h        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+/*
+ * Copyright (C) 2016 Igalia S.L
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(X11)
+#include &lt;X11/Xlib.h&gt;
+#include &lt;wtf/Vector.h&gt;
+
+namespace WebCore {
+
+class XErrorTrapper {
+public:
+    enum class Policy { Ignore, Warn, Crash };
+    XErrorTrapper(Display*, Policy = Policy::Ignore, Vector&lt;unsigned char&gt;&amp;&amp; expectedErrors = { });
+    ~XErrorTrapper();
+
+    unsigned char errorCode() const;
+
+private:
+    void errorEvent(XErrorEvent*);
+
+    Display* m_display { nullptr };
+    Policy m_policy { Policy::Ignore };
+    Vector&lt;unsigned char&gt; m_expectedErrors;
+    XErrorHandler m_previousErrorHandler { nullptr };
+    unsigned char m_errorCode { 0 };
+};
+
+} // namespace WebCore
+
+#endif // PLATFORM(X11)
</ins></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebKit2/ChangeLog        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-10-20  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        Wrong use of EGL_DEPTH_SIZE
+        https://bugs.webkit.org/show_bug.cgi?id=155536
+
+        Reviewed by Michael Catanzaro.
+
+        Use XErrorTrapper class instead of the custom XErrorHandler.
+
+        * PluginProcess/unix/PluginProcessMainUnix.cpp:
+        (WebKit::PluginProcessMainUnix):
+
</ins><span class="cx"> 2016-10-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SOUP] Add NetworkSession implementation and switch to use it
</span></span></pre></div>
<a id="trunkSourceWebKit2PluginProcessunixPluginProcessMainUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp (207589 => 207590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp        2016-10-20 08:30:13 UTC (rev 207589)
+++ trunk/Source/WebKit2/PluginProcess/unix/PluginProcessMainUnix.cpp        2016-10-20 08:33:44 UTC (rev 207590)
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> #include &quot;PluginProcess.h&quot;
</span><span class="cx"> #include &lt;WebCore/FileSystem.h&gt;
</span><span class="cx"> #include &lt;stdlib.h&gt;
</span><del>-#include &lt;wtf/text/CString.h&gt;
</del><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx"> #include &lt;gtk/gtk.h&gt;
</span><span class="lines">@@ -44,28 +43,15 @@
</span><span class="cx"> #include &lt;Ecore_X.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if defined(XP_UNIX)
+#include &lt;WebCore/PlatformDisplayX11.h&gt;
+#include &lt;WebCore/XErrorTrapper.h&gt;
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> #if defined(XP_UNIX)
</span><del>-
-#if !LOG_DISABLED
-static const char xErrorString[] = &quot;The program '%s' received an X Window System error.\n&quot;
-    &quot;This probably reflects a bug in a browser plugin.\n&quot;
-    &quot;The error was '%s'.\n&quot;
-    &quot;  (Details: serial %ld error_code %d request_code %d minor_code %d)\n&quot;;
-#endif // !LOG_DISABLED
-
-static CString programName;
-
-static int webkitXError(Display* xdisplay, XErrorEvent* error)
-{
-    char errorMessage[64];
-    XGetErrorText(xdisplay, error-&gt;error_code, errorMessage, 63);
-
-    LOG(Plugins, xErrorString, programName.data(), errorMessage, error-&gt;serial, error-&gt;error_code, error-&gt;request_code, error-&gt;minor_code);
-
-    return 0;
-}
</del><ins>+static std::unique_ptr&lt;WebCore::XErrorTrapper&gt; xErrorTrapper;
</ins><span class="cx"> #endif // XP_UNIX
</span><span class="cx"> 
</span><span class="cx"> class PluginProcessMain final: public ChildProcessMainBase {
</span><span class="lines">@@ -98,8 +84,10 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if defined(XP_UNIX)
</span><del>-        programName = WebCore::pathGetFileName(argv[0]).utf8();
-        XSetErrorHandler(webkitXError);
</del><ins>+        if (WebCore::PlatformDisplay::sharedDisplay().type() == WebCore::PlatformDisplay::Type::X11) {
+            auto* display = downcast&lt;WebCore::PlatformDisplayX11&gt;(WebCore::PlatformDisplay::sharedDisplay()).native();
+            xErrorTrapper = std::make_unique&lt;WebCore::XErrorTrapper&gt;(display, WebCore::XErrorTrapper::Policy::Warn);
+        }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">         m_parameters.extraInitializationData.add(&quot;plugin-path&quot;, argv[2]);
</span></span></pre>
</div>
</div>

</body>
</html>