Title: [101350] trunk/Source/WebKit2
Revision
101350
Author
carlo...@webkit.org
Date
2011-11-29 03:10:53 -0800 (Tue, 29 Nov 2011)

Log Message

[GTK] Add WebKitURIResponse to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=72946

Reviewed by Martin Robinson.

* GNUmakefile.am: Add new files to compilation.
* UIProcess/API/gtk/WebKitURIResponse.cpp: Added.
(webkitURIResponseFinalize):
(webkitURIResponseGetProperty):
(webkitURIResponseSetProperty):
(webkit_uri_response_class_init):
(webkit_uri_response_init):
(webkit_uri_response_get_uri): Return the URI of the response.
(webkit_uri_response_get_status_code): Return the status code of
the response, or SOUP_STATUS_NONE.
(webkit_uri_response_get_content_length): Return the expected
content length of the response.
(webkitURIResponseCreateForSoupMessage): Private function to
create a response object from a SoupMessage.
(webkitURIResponseGetSoupMessage): Return the soup message
associated to the response.
(webkitURIResponseSetContentLength): Set the expected content
length of the response. This is useful for non http responses.
* UIProcess/API/gtk/WebKitURIResponse.h: Added.
* UIProcess/API/gtk/WebKitURIResponsePrivate.h: Added.
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
* UIProcess/API/gtk/docs/webkit2gtk.types: Add
webkit_uri_response_get_type().
* UIProcess/API/gtk/webkit2.h: Add WebKitURIResponse.h.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (101349 => 101350)


--- trunk/Source/WebKit2/ChangeLog	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-29 11:10:53 UTC (rev 101350)
@@ -1,3 +1,36 @@
+2011-11-29  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitURIResponse to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=72946
+
+        Reviewed by Martin Robinson.
+
+        * GNUmakefile.am: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitURIResponse.cpp: Added.
+        (webkitURIResponseFinalize):
+        (webkitURIResponseGetProperty):
+        (webkitURIResponseSetProperty):
+        (webkit_uri_response_class_init):
+        (webkit_uri_response_init):
+        (webkit_uri_response_get_uri): Return the URI of the response.
+        (webkit_uri_response_get_status_code): Return the status code of
+        the response, or SOUP_STATUS_NONE.
+        (webkit_uri_response_get_content_length): Return the expected
+        content length of the response.
+        (webkitURIResponseCreateForSoupMessage): Private function to
+        create a response object from a SoupMessage.
+        (webkitURIResponseGetSoupMessage): Return the soup message
+        associated to the response.
+        (webkitURIResponseSetContentLength): Set the expected content
+        length of the response. This is useful for non http responses.
+        * UIProcess/API/gtk/WebKitURIResponse.h: Added.
+        * UIProcess/API/gtk/WebKitURIResponsePrivate.h: Added.
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/docs/webkit2gtk.types: Add
+        webkit_uri_response_get_type().
+        * UIProcess/API/gtk/webkit2.h: Add WebKitURIResponse.h.
+
 2011-11-29  Kenneth Rohde Christiansen  <kenn...@webkit.org>
 
         [Qt] QQuickWebView gets wrong position after reload

Modified: trunk/Source/WebKit2/GNUmakefile.am (101349 => 101350)


--- trunk/Source/WebKit2/GNUmakefile.am	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/GNUmakefile.am	2011-11-29 11:10:53 UTC (rev 101350)
@@ -83,6 +83,7 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitWebLoaderClient.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitSettings.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitURIRequest.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitURIResponse.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitWebView.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitWebViewBase.h \
 	$(WebKit2)/UIProcess/API/gtk/webkit2.h
@@ -508,6 +509,9 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h \

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp (0 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp	2011-11-29 11:10:53 UTC (rev 101350)
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#include "config.h"
+#include "WebKitURIResponse.h"
+
+#include "WebKitPrivate.h"
+#include "WebKitURIResponsePrivate.h"
+#include "WebURLResponse.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+enum {
+    PROP_0,
+
+    PROP_URI,
+    PROP_STATUS_CODE,
+    PROP_CONTENT_LENGTH
+};
+
+using namespace WebCore;
+
+G_DEFINE_TYPE(WebKitURIResponse, webkit_uri_response, G_TYPE_OBJECT)
+
+struct _WebKitURIResponsePrivate {
+    CString uri;
+    GRefPtr<SoupMessage> message;
+    guint64 contentLength;
+};
+
+static void webkitURIResponseFinalize(GObject* object)
+{
+    WEBKIT_URI_RESPONSE(object)->priv->~WebKitURIResponsePrivate();
+    G_OBJECT_CLASS(webkit_uri_response_parent_class)->finalize(object);
+}
+
+static void webkitURIResponseGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+    WebKitURIResponse* response = WEBKIT_URI_RESPONSE(object);
+
+    switch (propId) {
+    case PROP_URI:
+        g_value_set_string(value, webkit_uri_response_get_uri(response));
+        break;
+    case PROP_STATUS_CODE:
+        g_value_set_uint(value, webkit_uri_response_get_status_code(response));
+        break;
+    case PROP_CONTENT_LENGTH:
+        g_value_set_uint64(value, webkit_uri_response_get_content_length(response));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
+static void webkitURIResponseSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
+{
+    WebKitURIResponse* response = WEBKIT_URI_RESPONSE(object);
+
+    switch (propId) {
+    case PROP_URI:
+        response->priv->uri = g_value_get_string(value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
+static void webkit_uri_response_class_init(WebKitURIResponseClass* responseClass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(responseClass);
+
+    objectClass->finalize = webkitURIResponseFinalize;
+    objectClass->get_property = webkitURIResponseGetProperty;
+    objectClass->set_property = webkitURIResponseSetProperty;
+
+    /**
+     * WebKitURIResponse:uri:
+     *
+     * The URI for which the response was made.
+     */
+    g_object_class_install_property(objectClass,
+                                    PROP_URI,
+                                    g_param_spec_string("uri",
+                                                        _("URI"),
+                                                        _("The URI for which the response was made."),
+                                                        0,
+                                                        static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+    /**
+     * WebKitURIResponse:status-code:
+     *
+     * The status code of the response as returned by the server.
+     */
+    g_object_class_install_property(objectClass,
+                                    PROP_STATUS_CODE,
+                                    g_param_spec_uint("status-code",
+                                                      _("Status Code"),
+                                                      _("The status code of the response as returned by the server."),
+                                                      0, G_MAXUINT, SOUP_STATUS_NONE,
+                                                      WEBKIT_PARAM_READABLE));
+
+    /**
+     * WebKitURIResponse:content-length:
+     *
+     * The expected content length of the response.
+     */
+    g_object_class_install_property(objectClass,
+                                    PROP_CONTENT_LENGTH,
+                                    g_param_spec_uint64("content-length",
+                                                        _("Content Length"),
+                                                        _("The expected content length of the response."),
+                                                        0, G_MAXUINT64, 0,
+                                                        WEBKIT_PARAM_READABLE));
+
+    g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate));
+}
+
+static void webkit_uri_response_init(WebKitURIResponse* response)
+{
+    WebKitURIResponsePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(response, WEBKIT_TYPE_URI_RESPONSE, WebKitURIResponsePrivate);
+    response->priv = priv;
+    new (priv) WebKitURIResponsePrivate();
+}
+
+/**
+ * webkit_uri_response_get_uri:
+ * @response: a #WebKitURIResponse
+ *
+ * Returns: the uri of the #WebKitURIResponse
+ */
+const gchar* webkit_uri_response_get_uri(WebKitURIResponse* response)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0);
+
+    return response->priv->uri.data();
+}
+
+/**
+ * webkit_uri_response_get_status_code:
+ * @response: a #WebKitURIResponse
+ *
+ * Get the status code of the #WebKitURIResponse as returned by
+ * the server. It will normally be a #SoupKnownStatusCode, for
+ * example %SOUP_STATUS_OK, though the server can respond with any
+ * unsigned integer.
+ *
+ * Returns: the status code of @response
+ */
+guint webkit_uri_response_get_status_code(WebKitURIResponse* response)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), SOUP_STATUS_NONE);
+
+    if (!response->priv->message)
+        return SOUP_STATUS_NONE;
+
+    return response->priv->message->status_code;
+}
+
+/**
+ * webkit_uri_response_get_content_length:
+ * @response: a #WebKitURIResponse
+ *
+ * Get the expected content length of the #WebKitURIResponse. It can
+ * be 0 if the server provided an incorrect or missing Content-Length.
+ *
+ * Returns: the expected content length of @response.
+ */
+guint64 webkit_uri_response_get_content_length(WebKitURIResponse* response)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0);
+
+    if (response->priv->contentLength)
+        return response->priv->contentLength;
+
+    if (!response->priv->message)
+        return 0;
+
+    SoupMessage* message = response->priv->message.get();
+    return static_cast<guint64>(soup_message_headers_get_content_length(message->response_headers));
+}
+
+WebKitURIResponse* webkitURIResponseCreateForSoupMessage(SoupMessage* message)
+{
+    GOwnPtr<char> uri(soup_uri_to_string(soup_message_get_uri(message), FALSE));
+    WebKitURIResponse* response = WEBKIT_URI_RESPONSE(g_object_new(WEBKIT_TYPE_URI_RESPONSE, "uri", uri.get(), NULL));
+    response->priv->message = message;
+    return response;
+}
+
+SoupMessage* webkitURIResponseGetSoupMessage(WebKitURIResponse* response)
+{
+    return response->priv->message.get();
+}
+
+void webkitURIResponseSetContentLength(WebKitURIResponse* response, guint64 contentLength)
+{
+    response->priv->contentLength = contentLength;
+}

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h (0 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	2011-11-29 11:10:53 UTC (rev 101350)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitURIResponse_h
+#define WebKitURIResponse_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_URI_RESPONSE            (webkit_uri_response_get_type())
+#define WEBKIT_URI_RESPONSE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_URI_RESPONSE, WebKitURIResponse))
+#define WEBKIT_IS_URI_RESPONSE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_URI_RESPONSE))
+#define WEBKIT_URI_RESPONSE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_URI_RESPONSE, WebKitURIResponseClass))
+#define WEBKIT_IS_URI_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_URI_RESPONSE))
+#define WEBKIT_URI_RESPONSE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_URI_RESPONSE, WebKitURIResponseClass))
+
+typedef struct _WebKitURIResponse WebKitURIResponse;
+typedef struct _WebKitURIResponseClass WebKitURIResponseClass;
+typedef struct _WebKitURIResponsePrivate WebKitURIResponsePrivate;
+
+struct _WebKitURIResponse {
+    GObject parent;
+
+    /*< private >*/
+    WebKitURIResponsePrivate *priv;
+};
+
+struct _WebKitURIResponseClass {
+    GObjectClass parent_class;
+
+};
+
+WEBKIT_API GType
+webkit_uri_response_get_type           (void);
+
+WEBKIT_API const gchar *
+webkit_uri_response_get_uri            (WebKitURIResponse *response);
+
+WEBKIT_API guint
+webkit_uri_response_get_status_code    (WebKitURIResponse *response);
+
+WEBKIT_API guint64
+webkit_uri_response_get_content_length (WebKitURIResponse *response);
+
+G_END_DECLS
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h (0 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h	2011-11-29 11:10:53 UTC (rev 101350)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 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 INC. AND ITS CONTRIBUTORS ``AS IS''
+ * 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 INC. 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.
+ */
+
+#ifndef WebKitURIResponsePrivate_h
+#define WebKitURIResponsePrivate_h
+
+#include "WebKitURIResponse.h"
+#include <libsoup/soup.h>
+
+WebKitURIResponse* webkitURIResponseCreateForSoupMessage(SoupMessage*);
+SoupMessage* webkitURIResponseGetSoupMessage(WebKitURIResponse*);
+void webkitURIResponseSetContentLength(WebKitURIResponse*, guint64 contentLength);
+
+#endif // WebKitURIResponsePrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (101349 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2011-11-29 11:10:53 UTC (rev 101350)
@@ -18,7 +18,8 @@
     <xi:include href=""
     <xi:include href=""
     <xi:include href=""
-    <xi:include href=""
+    <xi:include href=""
+    <xi:include href=""
     <xi:include href=""
   </chapter>
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (101349 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-11-29 11:10:53 UTC (rev 101350)
@@ -250,6 +250,27 @@
 </SECTION>
 
 <SECTION>
+<FILE>WebKitURIResponse</FILE>
+WebKitURIResponse
+webkit_uri_response_get_uri
+webkit_uri_response_get_status_code
+webkit_uri_response_get_content_length
+
+<SUBSECTION Standard>
+WebKitURIResponseClass
+WEBKIT_TYPE_URI_RESPONSE
+WEBKIT_URI_RESPONSE
+WEBKIT_IS_URI_RESPONSE
+WEBKIT_URI_RESPONSE_CLASS
+WEBKIT_IS_URI_RESPONSE_CLASS
+WEBKIT_URI_RESPONSE_GET_CLASS
+
+<SUBSECTION Private>
+WebKitURIResponsePrivate
+webkit_uri_response_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitError</FILE>
 WEBKIT_NETWORK_ERROR
 WEBKIT_PLUGIN_ERROR

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types (101349 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types	2011-11-29 11:10:53 UTC (rev 101350)
@@ -6,3 +6,4 @@
 webkit_back_forward_list_get_type
 webkit_back_forward_list_item_get_type
 webkit_settings_get_type
+webkit_uri_response_get_type

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (101349 => 101350)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2011-11-29 11:04:43 UTC (rev 101349)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2011-11-29 11:10:53 UTC (rev 101350)
@@ -30,6 +30,7 @@
 #include <webkit2/WebKitError.h>
 #include <webkit2/WebKitSettings.h>
 #include <webkit2/WebKitURIRequest.h>
+#include <webkit2/WebKitURIResponse.h>
 #include <webkit2/WebKitWebContext.h>
 #include <webkit2/WebKitWebLoaderClient.h>
 #include <webkit2/WebKitWebViewBase.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to