Commit e99d5dff authored by eric@webkit.org's avatar eric@webkit.org

2010-02-02 Philippe Normand <pnormand@igalia.com>

        Reviewed by Gustavo Noronha Silva.

        [Gtk] libsoup critical warning in media player http cookies injection code
        https://bugs.webkit.org/show_bug.cgi?id=34435

        Fixed the critical warning and refactored the
        User-Agent/Referer/cookies injection code, in that order. Previous
        order (cookies first) was wrong because if cookies injection could
        not be done neither the User-Agent not Referer were injected. Also
        started a non-JSC-specific, gtk-specific GOwnPtr module.

        * GNUmakefile.am:
        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
        (WebCore::mediaPlayerPrivateSourceChangedCallback):
        * platform/gtk/GOwnPtrGtk.cpp: Added.
        (WTF::SoupURI):
        (WTF::GstElement):
        * platform/gtk/GOwnPtrGtk.h: Added.

git-svn-id: svn://svn.chromium.org/blink/trunk@54261 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 83a2a34d
2010-02-02 Philippe Normand <pnormand@igalia.com>
Reviewed by Gustavo Noronha Silva.
[Gtk] libsoup critical warning in media player http cookies injection code
https://bugs.webkit.org/show_bug.cgi?id=34435
Fixed the critical warning and refactored the
User-Agent/Referer/cookies injection code, in that order. Previous
order (cookies first) was wrong because if cookies injection could
not be done neither the User-Agent not Referer were injected. Also
started a non-JSC-specific, gtk-specific GOwnPtr module.
* GNUmakefile.am:
* platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
(WebCore::mediaPlayerPrivateSourceChangedCallback):
* platform/gtk/GOwnPtrGtk.cpp: Added.
(WTF::SoupURI):
(WTF::GstElement):
* platform/gtk/GOwnPtrGtk.h: Added.
2010-02-02 Nate Chapin <japhet@chromium.org> 2010-02-02 Nate Chapin <japhet@chromium.org>
Reviewed by Dimitri Glazkov. Reviewed by Dimitri Glazkov.
......
...@@ -2006,6 +2006,8 @@ webcoregtk_sources += \ ...@@ -2006,6 +2006,8 @@ webcoregtk_sources += \
WebCore/platform/gtk/FileSystemGtk.cpp \ WebCore/platform/gtk/FileSystemGtk.cpp \
WebCore/platform/gtk/GRefPtrGtk.cpp \ WebCore/platform/gtk/GRefPtrGtk.cpp \
WebCore/platform/gtk/GRefPtrGtk.h \ WebCore/platform/gtk/GRefPtrGtk.h \
WebCore/platform/gtk/GOwnPtrGtk.cpp \
WebCore/platform/gtk/GOwnPtrGtk.h \
WebCore/platform/gtk/GtkPluginWidget.cpp \ WebCore/platform/gtk/GtkPluginWidget.cpp \
WebCore/platform/gtk/GtkPluginWidget.h \ WebCore/platform/gtk/GtkPluginWidget.h \
WebCore/platform/gtk/KURLGtk.cpp \ WebCore/platform/gtk/KURLGtk.cpp \
......
...@@ -131,52 +131,52 @@ gboolean mediaPlayerPrivateMessageCallback(GstBus* bus, GstMessage* message, gpo ...@@ -131,52 +131,52 @@ gboolean mediaPlayerPrivateMessageCallback(GstBus* bus, GstMessage* message, gpo
void mediaPlayerPrivateSourceChangedCallback(GObject *object, GParamSpec *pspec, gpointer data) void mediaPlayerPrivateSourceChangedCallback(GObject *object, GParamSpec *pspec, gpointer data)
{ {
MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data); MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
GstElement* element; GOwnPtr<GstElement> element;
g_object_get(mp->m_playBin, "source", &element, NULL); g_object_get(mp->m_playBin, "source", &element.outPtr(), NULL);
gst_object_replace((GstObject**) &mp->m_source, (GstObject*) element); gst_object_replace((GstObject**) &mp->m_source, (GstObject*) element.get());
if (element) { if (!element)
GParamSpec* pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(element), "cookies"); return;
// First check if the source element has a cookies property
// of the format we expect
if (!pspec || pspec->value_type != G_TYPE_STRV)
return;
// Then get the cookies for the URI and set them GOwnPtr<char> location;
SoupSession* session = webkit_get_default_session(); g_object_get(element.get(), "location", &location.outPtr(), NULL);
SoupCookieJar* cookieJar = SOUP_COOKIE_JAR(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
char* location; GOwnPtr<SoupURI> uri(soup_uri_new(location.get()));
g_object_get(element, "location", &location, NULL);
SoupURI* uri = soup_uri_new(location); // Let Apple web servers know we want to access their nice movie trailers.
g_free(location); if (g_str_equal(uri->host, "movies.apple.com"))
g_object_set(element.get(), "user-agent", "Quicktime/7.2.0", NULL);
// Let Apple web servers know we want to access their nice movie trailers. // Set the HTTP referer.
if (g_str_equal(uri->host, "movies.apple.com")) Frame* frame = mp->m_player->frameView() ? mp->m_player->frameView()->frame() : 0;
g_object_set(element, "user-agent", "Quicktime/7.2.0", NULL); Document* document = frame ? frame->document() : 0;
if (document) {
GstStructure* extraHeaders = gst_structure_new("extra-headers",
"Referer", G_TYPE_STRING,
document->documentURI().utf8().data(), 0);
g_object_set(element.get(), "extra-headers", extraHeaders, NULL);
gst_structure_free(extraHeaders);
}
char* cookies = soup_cookie_jar_get_cookies(cookieJar, uri, FALSE); // Deal with the cookies from now on.
soup_uri_free(uri); GParamSpec* cookiesParamSpec = g_object_class_find_property(G_OBJECT_GET_CLASS(element.get()), "cookies");
char* cookiesStrv[] = {cookies, NULL}; // First check if the source element has a cookies property
g_object_set(element, "cookies", cookiesStrv, NULL); // of the format we expect
g_free(cookies); if (!cookiesParamSpec || cookiesParamSpec->value_type != G_TYPE_STRV)
return;
Frame* frame = mp->m_player->frameView() ? mp->m_player->frameView()->frame() : 0; // Then get the cookies for the URI and set them
Document* document = frame ? frame->document() : 0; SoupSession* session = webkit_get_default_session();
if (document) { SoupSessionFeature* cookieJarFeature = soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR);
GstStructure* extraHeaders = gst_structure_new("extra-headers", if (!cookieJarFeature)
"Referer", G_TYPE_STRING, return;
document->documentURI().utf8().data(), 0);
g_object_set(element, "extra-headers", extraHeaders, NULL);
gst_structure_free(extraHeaders);
}
}
gst_object_unref(element); SoupCookieJar* cookieJar = SOUP_COOKIE_JAR(cookieJarFeature);
GOwnPtr<char> cookies(soup_cookie_jar_get_cookies(cookieJar, uri.get(), FALSE));
char* cookiesStrv[] = {cookies.get(), 0};
g_object_set(element.get(), "cookies", cookiesStrv, NULL);
} }
void mediaPlayerPrivateVolumeChangedCallback(GObject *element, GParamSpec *pspec, gpointer data) void mediaPlayerPrivateVolumeChangedCallback(GObject *element, GParamSpec *pspec, gpointer data)
......
/*
* Copyright (C) 2010 Igalia S.L
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "GOwnPtrGtk.h"
#include <gst/gstelement.h>
#include <libsoup/soup-uri.h>
namespace WTF {
template <> void freeOwnedGPtr<SoupURI>(SoupURI* ptr)
{
if (ptr)
soup_uri_free(ptr);
}
template <> void freeOwnedGPtr<GstElement>(GstElement* ptr)
{
if (ptr)
gst_object_unref(ptr);
}
}
/*
* Copyright (C) 2010 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 GOwnPtrGtk_h
#define GOwnPtrGtk_h
#include "GOwnPtr.h"
typedef struct _SoupURI SoupURI;
typedef struct _GstElement GstElement;
namespace WTF {
template<> void freeOwnedGPtr<SoupURI>(SoupURI* ptr);
template<> void freeOwnedGPtr<GstElement>(GstElement* ptr);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment