<!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>[182714] releases/WebKitGTK/webkit-2.8/Source/WebCore</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/182714">182714</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-04-13 05:24:32 -0700 (Mon, 13 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/182523">r182523</a> - [GStreamer] extra-headers and keep-alive properties for HTTP source element
https://bugs.webkit.org/show_bug.cgi?id=143480

Reviewed by Carlos Garcia Campos.

Keep the resource loader around when persistent HTTP connection
support is enabled. The keep-alive property is set to false by
default. Also before sending the HTTP request we now check the
contents of the extra-headers GstStructure and set additional
headers based on the structure contents.

Patch inspired by GStreamer's souphttpsrc element.

* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(webkit_web_src_init):
(webKitWebSrcFinalize):
(webKitWebSrcSetProperty):
(webKitWebSrcGetProperty):
(webKitWebSrcStop): Clear resource loader only for non-persistent connections.
(webKitWebSrcSetExtraHeader): Utility function to append headers
to an existing request based on a GValue contents.
(webKitWebSrcProcessExtraHeaders): Parse a GValue and set headers
based on its contents.
(webKitWebSrcStart): Extra headers and persistent connection
support. The resource loader is now lazily initialized here.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit28SourceWebCoreChangeLog">releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit28SourceWebCoreplatformgraphicsgstreamerWebKitWebSourceGStreamercpp">releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit28SourceWebCoreplatformgraphicsgstreamerGUniquePtrGStreamerh">releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit28SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog (182713 => 182714)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog        2015-04-13 12:01:17 UTC (rev 182713)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog        2015-04-13 12:24:32 UTC (rev 182714)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-04-07  Philippe Normand  &lt;pnormand@igalia.com&gt;
+
+        [GStreamer] extra-headers and keep-alive properties for HTTP source element
+        https://bugs.webkit.org/show_bug.cgi?id=143480
+
+        Reviewed by Carlos Garcia Campos.
+
+        Keep the resource loader around when persistent HTTP connection
+        support is enabled. The keep-alive property is set to false by
+        default. Also before sending the HTTP request we now check the
+        contents of the extra-headers GstStructure and set additional
+        headers based on the structure contents.
+
+        Patch inspired by GStreamer's souphttpsrc element.
+
+        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+        (webkit_web_src_init):
+        (webKitWebSrcFinalize):
+        (webKitWebSrcSetProperty):
+        (webKitWebSrcGetProperty):
+        (webKitWebSrcStop): Clear resource loader only for non-persistent connections.
+        (webKitWebSrcSetExtraHeader): Utility function to append headers
+        to an existing request based on a GValue contents.
+        (webKitWebSrcProcessExtraHeaders): Parse a GValue and set headers
+        based on its contents.
+        (webKitWebSrcStart): Extra headers and persistent connection
+        support. The resource loader is now lazily initialized here.
+
</ins><span class="cx"> 2015-04-06  Žan Doberšek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         FileList constructor should move the passed-in Vector&lt;&gt; rvalue reference into the member variable
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit28SourceWebCoreplatformgraphicsgstreamerGUniquePtrGStreamerh"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h (0 => 182714)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h                                (rev 0)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h        2015-04-13 12:24:32 UTC (rev 182714)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+/*
+ *  Copyright (C) 2015 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GUniquePtrGStreamer_h
+#define GUniquePtrGStreamer_h
+#if USE(GSTREAMER)
+
+#include &lt;gst/gststructure.h&gt;
+#include &lt;wtf/gobject/GUniquePtr.h&gt;
+
+namespace WTF {
+
+WTF_DEFINE_GPTR_DELETER(GstStructure, gst_structure_free)
+
+}
+
+#endif // USE(GSTREAMER)
+#endif
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit28SourceWebCoreplatformgraphicsgstreamerWebKitWebSourceGStreamercpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp (182713 => 182714)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp        2015-04-13 12:01:17 UTC (rev 182713)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp        2015-04-13 12:24:32 UTC (rev 182714)
</span><span class="lines">@@ -24,6 +24,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;GRefPtrGStreamer.h&quot;
</span><span class="cx"> #include &quot;GStreamerUtilities.h&quot;
</span><ins>+#include &quot;GUniquePtrGStreamer.h&quot;
</ins><span class="cx"> #include &quot;HTTPHeaderNames.h&quot;
</span><span class="cx"> #include &quot;MediaPlayer.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><span class="lines">@@ -109,6 +110,8 @@
</span><span class="cx">     GstAppSrc* appsrc;
</span><span class="cx">     GstPad* srcpad;
</span><span class="cx">     gchar* uri;
</span><ins>+    bool keepAlive;
+    GUniquePtr&lt;GstStructure&gt; extraHeaders;
</ins><span class="cx"> 
</span><span class="cx">     WebCore::MediaPlayer* player;
</span><span class="cx"> 
</span><span class="lines">@@ -145,7 +148,9 @@
</span><span class="cx">     PROP_IRADIO_GENRE,
</span><span class="cx">     PROP_IRADIO_URL,
</span><span class="cx">     PROP_IRADIO_TITLE,
</span><del>-    PROP_LOCATION
</del><ins>+    PROP_LOCATION,
+    PROP_KEEP_ALIVE,
+    PROP_EXTRA_HEADERS
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static GstStaticPadTemplate srcTemplate = GST_STATIC_PAD_TEMPLATE(&quot;src&quot;,
</span><span class="lines">@@ -242,6 +247,15 @@
</span><span class="cx">                                                         &quot;Location to read from&quot;,
</span><span class="cx">                                                         0,
</span><span class="cx">                                                         (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
</span><ins>+
+    g_object_class_install_property(oklass, PROP_KEEP_ALIVE,
+        g_param_spec_boolean(&quot;keep-alive&quot;, &quot;keep-alive&quot;, &quot;Use HTTP persistent connections&quot;,
+            FALSE, static_cast&lt;GParamFlags&gt;(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
+
+    g_object_class_install_property(oklass, PROP_EXTRA_HEADERS,
+        g_param_spec_boxed(&quot;extra-headers&quot;, &quot;Extra Headers&quot;, &quot;Extra headers to append to the HTTP request&quot;,
+            GST_TYPE_STRUCTURE, static_cast&lt;GParamFlags&gt;(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
+
</ins><span class="cx">     eklass-&gt;change_state = webKitWebSrcChangeState;
</span><span class="cx"> 
</span><span class="cx">     g_type_class_add_private(klass, sizeof(WebKitWebSrcPrivate));
</span><span class="lines">@@ -327,6 +341,14 @@
</span><span class="cx">     case PROP_LOCATION:
</span><span class="cx">         gst_uri_handler_set_uri(reinterpret_cast&lt;GstURIHandler*&gt;(src), g_value_get_string(value), 0);
</span><span class="cx">         break;
</span><ins>+    case PROP_KEEP_ALIVE:
+        src-&gt;priv-&gt;keepAlive = g_value_get_boolean(value);
+        break;
+    case PROP_EXTRA_HEADERS: {
+        const GstStructure* s = gst_value_get_structure(value);
+        src-&gt;priv-&gt;extraHeaders.reset(s ? gst_structure_copy(s) : nullptr);
+        break;
+    }
</ins><span class="cx">     default:
</span><span class="cx">         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, pspec);
</span><span class="cx">         break;
</span><span class="lines">@@ -355,6 +377,12 @@
</span><span class="cx">     case PROP_LOCATION:
</span><span class="cx">         g_value_set_string(value, priv-&gt;uri);
</span><span class="cx">         break;
</span><ins>+    case PROP_KEEP_ALIVE:
+        g_value_set_boolean(value, priv-&gt;keepAlive);
+        break;
+    case PROP_EXTRA_HEADERS:
+        gst_value_set_structure(value, priv-&gt;extraHeaders.get());
+        break;
</ins><span class="cx">     default:
</span><span class="cx">         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, pspec);
</span><span class="cx">         break;
</span><span class="lines">@@ -389,7 +417,8 @@
</span><span class="cx">         priv-&gt;client = 0;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    priv-&gt;loader = nullptr;
</del><ins>+    if (!priv-&gt;keepAlive)
+        priv-&gt;loader = nullptr;
</ins><span class="cx"> 
</span><span class="cx">     if (priv-&gt;buffer) {
</span><span class="cx">         unmapGstBuffer(priv-&gt;buffer.get());
</span><span class="lines">@@ -430,6 +459,57 @@
</span><span class="cx">     GST_DEBUG_OBJECT(src, &quot;Stopped request&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool webKitWebSrcSetExtraHeader(GQuark fieldId, const GValue* value, gpointer userData)
+{
+    GUniquePtr&lt;gchar&gt; fieldContent;
+
+    if (G_VALUE_HOLDS_STRING(value))
+        fieldContent.reset(g_value_dup_string(value));
+    else {
+        GValue dest = G_VALUE_INIT;
+
+        g_value_init(&amp;dest, G_TYPE_STRING);
+        if (g_value_transform(value, &amp;dest))
+            fieldContent.reset(g_value_dup_string(&amp;dest));
+    }
+
+    const gchar* fieldName = g_quark_to_string(fieldId);
+    if (!fieldContent.get()) {
+        GST_ERROR(&quot;extra-headers field '%s' contains no value or can't be converted to a string&quot;, fieldName);
+        return false;
+    }
+
+    GST_DEBUG(&quot;Appending extra header: \&quot;%s: %s\&quot;&quot;, fieldName, fieldContent.get());
+    ResourceRequest* request = static_cast&lt;ResourceRequest*&gt;(userData);
+    request-&gt;setHTTPHeaderField(fieldName, fieldContent.get());
+    return true;
+}
+
+static gboolean webKitWebSrcProcessExtraHeaders(GQuark fieldId, const GValue* value, gpointer userData)
+{
+    if (G_VALUE_TYPE(value) == GST_TYPE_ARRAY) {
+        unsigned size = gst_value_array_get_size(value);
+
+        for (unsigned i = 0; i &lt; size; i++) {
+            if (!webKitWebSrcSetExtraHeader(fieldId, gst_value_array_get_value(value, i), userData))
+                return FALSE;
+        }
+        return TRUE;
+    }
+
+    if (G_VALUE_TYPE(value) == GST_TYPE_LIST) {
+        unsigned size = gst_value_list_get_size(value);
+
+        for (unsigned i = 0; i &lt; size; i++) {
+            if (!webKitWebSrcSetExtraHeader(fieldId, gst_value_list_get_value(value, i), userData))
+                return FALSE;
+        }
+        return TRUE;
+    }
+
+    return webKitWebSrcSetExtraHeader(fieldId, value, userData);
+}
+
</ins><span class="cx"> static void webKitWebSrcStart(WebKitWebSrc* src)
</span><span class="cx"> {
</span><span class="cx">     WebKitWebSrcPrivate* priv = src-&gt;priv;
</span><span class="lines">@@ -449,7 +529,6 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!priv-&gt;client);
</span><del>-    ASSERT(!priv-&gt;loader);
</del><span class="cx"> 
</span><span class="cx">     URL url = URL(URL(), priv-&gt;uri);
</span><span class="cx"> 
</span><span class="lines">@@ -457,6 +536,8 @@
</span><span class="cx">     request.setAllowCookies(true);
</span><span class="cx">     request.setFirstPartyForCookies(url);
</span><span class="cx"> 
</span><ins>+    priv-&gt;size = 0;
+
</ins><span class="cx">     if (priv-&gt;player)
</span><span class="cx">         request.setHTTPReferrer(priv-&gt;player-&gt;referrer());
</span><span class="cx"> 
</span><span class="lines">@@ -481,21 +562,27 @@
</span><span class="cx">     }
</span><span class="cx">     priv-&gt;offset = priv-&gt;requestedOffset;
</span><span class="cx"> 
</span><ins>+    if (!priv-&gt;keepAlive) {
+        GST_DEBUG_OBJECT(src, &quot;Persistent connection support disabled&quot;);
+        request.setHTTPHeaderField(HTTPHeaderName::Connection, &quot;close&quot;);
+    }
+
+    if (priv-&gt;extraHeaders)
+        gst_structure_foreach(priv-&gt;extraHeaders.get(), webKitWebSrcProcessExtraHeaders, &amp;request);
+
</ins><span class="cx">     // We always request Icecast/Shoutcast metadata, just in case ...
</span><span class="cx">     request.setHTTPHeaderField(HTTPHeaderName::IcyMetadata, &quot;1&quot;);
</span><span class="cx"> 
</span><span class="cx">     bool loadFailed = true;
</span><del>-    if (priv-&gt;player) {
</del><ins>+    if (priv-&gt;player &amp;&amp; !priv-&gt;loader)
</ins><span class="cx">         priv-&gt;loader = priv-&gt;player-&gt;createResourceLoader(std::make_unique&lt;CachedResourceStreamingClient&gt;(src));
</span><del>-        if (priv-&gt;loader) {
-            PlatformMediaResourceLoader::LoadOptions loadOptions = 0;
-            if (request.url().protocolIs(&quot;blob&quot;))
-                loadOptions |= PlatformMediaResourceLoader::LoadOption::BufferData;
-            loadFailed = !priv-&gt;loader-&gt;start(request, loadOptions);
-        }
-    }
</del><span class="cx"> 
</span><del>-    if (!priv-&gt;loader) {
</del><ins>+    if (priv-&gt;loader) {
+        PlatformMediaResourceLoader::LoadOptions loadOptions = 0;
+        if (request.url().protocolIs(&quot;blob&quot;))
+            loadOptions |= PlatformMediaResourceLoader::LoadOption::BufferData;
+        loadFailed = !priv-&gt;loader-&gt;start(request, loadOptions);
+    } else {
</ins><span class="cx">         priv-&gt;client = new ResourceHandleStreamingClient(src, request);
</span><span class="cx">         loadFailed = priv-&gt;client-&gt;loadFailed();
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>