static void test_network_request_create_destroy() { WebKitNetworkRequest* request; SoupMessage* message; /* Test creation with URI */ request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL)); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); message = webkit_network_request_get_message(request); g_assert(!message); g_object_unref(request); /* Test creation with SoupMessage */ message = soup_message_new("GET", "http://debian.org/"); request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL)); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); g_object_unref(request); g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); g_object_unref(message); /* Test creation with both SoupMessage and URI */ message = soup_message_new("GET", "http://debian.org/"); request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL)); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/"); g_object_unref(request); g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); g_object_unref(message); }
WebKitNetworkRequest* kitNew(const WebCore::ResourceRequest& resourceRequest) { GRefPtr<SoupMessage> soupMessage(adoptGRef(resourceRequest.toSoupMessage())); if (soupMessage) return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", soupMessage.get(), NULL)); return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", resourceRequest.url().string().utf8().data(), NULL)); }
// for internal use only WebKitNetworkRequest* webkit_network_request_new_with_core_request(const WebCore::ResourceRequest& resourceRequest) { GOwnPtr<SoupMessage> soupMessage(resourceRequest.toSoupMessage()); if (soupMessage) return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", soupMessage.get(), NULL)); return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", resourceRequest.url().string().utf8().data(), NULL)); }
static void test_network_request_properties() { WebKitNetworkRequest* request; SoupMessage* message; gchar* soupURI; /* Test URI is set correctly when creating with URI */ request = webkit_network_request_new("http://debian.org/"); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); g_object_unref(request); /* Test URI is set correctly when creating with Message */ message = soup_message_new("GET", "http://debian.org/"); request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL)); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_object_unref(message); message = webkit_network_request_get_message(request); soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE); g_assert_cmpstr(soupURI, ==, "http://debian.org/"); g_free(soupURI); g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); g_object_unref(request); }
static void webkit_network_request_finalize(GObject* object) { WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); WebKitNetworkRequestPrivate* priv = request->priv; g_free(priv->uri); G_OBJECT_CLASS(webkit_network_request_parent_class)->finalize(object); }
static void webkit_network_request_dispose(GObject* object) { WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); WebKitNetworkRequestPrivate* priv = request->priv; if (priv->message) { g_object_unref(priv->message); priv->message = NULL; } G_OBJECT_CLASS(webkit_network_request_parent_class)->dispose(object); }
static void webkit_network_request_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec) { WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); switch(propertyID) { case PROP_URI: g_value_set_string(value, webkit_network_request_get_uri(request)); break; case PROP_MESSAGE: g_value_set_object(value, webkit_network_request_get_message(request)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); } }
static void webkit_network_request_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec) { WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); WebKitNetworkRequestPrivate* priv = request->priv; switch(propertyID) { case PROP_URI: webkit_network_request_set_uri(request, g_value_get_string(value)); break; case PROP_MESSAGE: priv->message = SOUP_MESSAGE(g_value_dup_object(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); } }
/** * webkit_network_request_new: * @uri: an URI * * Creates a new #WebKitNetworkRequest initialized with an URI. * * Returns: a new #WebKitNetworkRequest, or %NULL if the URI is * invalid. */ WebKitNetworkRequest* webkit_network_request_new(const gchar* uri) { g_return_val_if_fail(uri, NULL); return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", uri, NULL)); }