Make memoryCache() return a reference
[WebKit-https.git] / Source / WebKit2 / WebProcess / soup / WebKitSoupRequestGeneric.cpp
1 /*
2  * Copyright (C) 2012 Igalia S.L.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21 #include "WebKitSoupRequestGeneric.h"
22
23 #include <wtf/text/CString.h>
24
25 using namespace WebKit;
26
27 G_DEFINE_TYPE(WebKitSoupRequestGeneric, webkit_soup_request_generic, SOUP_TYPE_REQUEST)
28
29 struct _WebKitSoupRequestGenericPrivate {
30     CString mimeType;
31     goffset contentLength;
32 };
33
34 static void webkitSoupRequestGenericFinalize(GObject* object)
35 {
36     WEBKIT_SOUP_REQUEST_GENERIC(object)->priv->~WebKitSoupRequestGenericPrivate();
37     G_OBJECT_CLASS(webkit_soup_request_generic_parent_class)->finalize(object);
38 }
39
40 static void webkit_soup_request_generic_init(WebKitSoupRequestGeneric* request)
41 {
42     WebKitSoupRequestGenericPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(request, WEBKIT_TYPE_SOUP_REQUEST_GENERIC, WebKitSoupRequestGenericPrivate);
43     request->priv = priv;
44     new (priv) WebKitSoupRequestGenericPrivate();
45 }
46
47 static void webkitSoupRequestGenericSendAsync(SoupRequest* request, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
48 {
49     CustomProtocolManagerImpl* customProtocolManager = WEBKIT_SOUP_REQUEST_GENERIC_GET_CLASS(request)->customProtocolManager;
50     ASSERT(customProtocolManager);
51     customProtocolManager->send(g_task_new(request, cancellable, callback, userData));
52 }
53
54 static GInputStream* webkitSoupRequestGenericSendFinish(SoupRequest* request, GAsyncResult* result, GError** error)
55 {
56     g_return_val_if_fail(g_task_is_valid(result, request), 0);
57     CustomProtocolManagerImpl* customProtocolManager = WEBKIT_SOUP_REQUEST_GENERIC_GET_CLASS(request)->customProtocolManager;
58     ASSERT(customProtocolManager);
59     return customProtocolManager->finish(G_TASK(result), error);
60 }
61
62 static goffset webkitSoupRequestGenericGetContentLength(SoupRequest* request)
63 {
64     return WEBKIT_SOUP_REQUEST_GENERIC(request)->priv->contentLength;
65 }
66
67 static const char* webkitSoupRequestGenericGetContentType(SoupRequest* request)
68 {
69     return WEBKIT_SOUP_REQUEST_GENERIC(request)->priv->mimeType.data();
70 }
71
72 static void webkit_soup_request_generic_class_init(WebKitSoupRequestGenericClass* requestGenericClass)
73 {
74     GObjectClass* gObjectClass = G_OBJECT_CLASS(requestGenericClass);
75     gObjectClass->finalize = webkitSoupRequestGenericFinalize;
76
77     SoupRequestClass* requestClass = SOUP_REQUEST_CLASS(requestGenericClass);
78     requestClass->send_async = webkitSoupRequestGenericSendAsync;
79     requestClass->send_finish = webkitSoupRequestGenericSendFinish;
80     requestClass->get_content_length = webkitSoupRequestGenericGetContentLength;
81     requestClass->get_content_type = webkitSoupRequestGenericGetContentType;
82
83     g_type_class_add_private(requestGenericClass, sizeof(WebKitSoupRequestGenericPrivate));
84 }
85
86 void webkitSoupRequestGenericSetContentLength(WebKitSoupRequestGeneric* request, goffset contentLength)
87 {
88     request->priv->contentLength = contentLength;
89 }
90
91 void webkitSoupRequestGenericSetContentType(WebKitSoupRequestGeneric* request, const char* mimeType)
92 {
93     request->priv->mimeType = mimeType;
94 }