Tizen 2.1 base
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_url_response.cpp
1 /*
2  * Copyright (C) 2012 Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ewk_url_response.h"
28
29 #include "ewk_url_response_private.h"
30 #include <wtf/text/CString.h>
31
32 /**
33  * \struct  _Ewk_Url_Response
34  * @brief   Contains the URL response data.
35  */
36 struct _Ewk_Url_Response {
37     unsigned int __ref; /**< the reference count of the object */
38     WebCore::ResourceResponse coreResponse;
39
40     const char* url;
41     const char* mimeType;
42
43     _Ewk_Url_Response(const WebCore::ResourceResponse& _coreResponse)
44         : __ref(1)
45         , coreResponse(_coreResponse)
46         , url(0)
47         , mimeType(0)
48     { }
49
50     ~_Ewk_Url_Response()
51     {
52         ASSERT(!__ref);
53         eina_stringshare_del(url);
54         eina_stringshare_del(mimeType);
55     }
56 };
57
58 void ewk_url_response_ref(Ewk_Url_Response* response)
59 {
60     EINA_SAFETY_ON_NULL_RETURN(response);
61     ++response->__ref;
62 }
63
64 void ewk_url_response_unref(Ewk_Url_Response* response)
65 {
66     EINA_SAFETY_ON_NULL_RETURN(response);
67
68     if (--response->__ref)
69         return;
70
71     delete response;
72 }
73
74 const char* ewk_url_response_url_get(const Ewk_Url_Response* response)
75 {
76     EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0);
77
78     Ewk_Url_Response* ewkResponse = const_cast<Ewk_Url_Response*>(response);
79     eina_stringshare_replace(&ewkResponse->url, response->coreResponse.url().string().utf8().data());
80
81     return response->url;
82 }
83
84 int ewk_url_response_status_code_get(const Ewk_Url_Response* response)
85 {
86     EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0);
87
88     return response->coreResponse.httpStatusCode();
89 }
90
91 const char* ewk_url_response_mime_type_get(const Ewk_Url_Response* response)
92 {
93     EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0);
94
95     Ewk_Url_Response* ewkResponse = const_cast<Ewk_Url_Response*>(response);
96     eina_stringshare_replace(&ewkResponse->mimeType, response->coreResponse.mimeType().utf8().data());
97
98     return response->mimeType;
99 }
100
101 unsigned long ewk_url_response_content_length_get(const Ewk_Url_Response* response)
102 {
103     EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0);
104
105     return response->coreResponse.expectedContentLength();
106 }
107
108 /**
109  * @internal
110  * Constructs a Ewk_Url_Response from a WebCore::ResourceResponse.
111  */
112 Ewk_Url_Response* ewk_url_response_new(const WebCore::ResourceResponse& coreResponse)
113 {
114     return new Ewk_Url_Response(coreResponse);
115 }