tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / efl / ewk / ewk_network_before_upversion.cpp
1 /*
2     Copyright (C) 2011 Samsung Electronics
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 "ewk_network.h"
22
23 #include "EWebKit.h"
24 #include "ewk_logging.h"
25
26 #if USE(SOUP)
27 #include "ResourceHandle.h"
28 #include <libsoup/soup.h>
29 #endif
30
31 #include <wtf/text/CString.h>
32
33 /**
34  * Cancel pending request in network session.
35  * The pending network requests cannot be sent when
36  * network device is changed. New socket need to be opened.
37  */
38 void ewk_network_session_requests_cancel(void)
39 {
40 #if ENABLE(TIZEN_SESSION_REQUEST_CANCEL)
41 #if USE(SOUP)
42     SoupSession* session = WebCore::ResourceHandle::defaultSession();
43     soup_session_abort(session);
44 #elif USE(CURL)
45     EINA_SAFETY_ON_TRUE_RETURN(1);
46 #endif // ENABLE(TIZEN_SESSION_RESET)
47 #else
48     LOG_ERROR("TIZEN_SESSION_RESET is disabled. \n");
49 #endif
50 }
51
52 /**
53  * Sets the given proxy URI to network backend.
54  *
55  * @param proxy URI.
56  */
57 void ewk_network_proxy_uri_set(const char* proxy)
58 {
59 #if ENABLE(TIZEN_SET_PROXY)
60     SoupSession* session = WebCore::ResourceHandle::defaultSession();
61
62     if (!proxy || (strstr(proxy, "0.0.0.0") != NULL)) {
63         ERR("no proxy uri. remove proxy feature in soup.");
64
65         g_object_set(session, SOUP_SESSION_PROXY_URI, NULL, NULL);
66         soup_session_remove_feature_by_type(session, SOUP_TYPE_PROXY_RESOLVER);
67     } else {
68         WTF::String proxyValue;
69         proxyValue = WTF::String(proxy);
70
71         // improve proxy string
72         if (proxyValue.length() > 0) {
73             if (proxyValue.startsWith("http://", false) == false)
74                 proxyValue.insert("http://", 0);
75         }
76
77         SoupURI* uri = soup_uri_new(proxyValue.utf8().data());
78         EINA_SAFETY_ON_NULL_RETURN(uri);
79
80         g_object_set(session, SOUP_SESSION_PROXY_URI, uri, NULL);
81         soup_uri_free(uri);
82     }
83 #else // ENABLE(TIZEN_SET_PROXY)
84 #if USE(SOUP)
85     SoupURI* uri = soup_uri_new(proxy);
86     EINA_SAFETY_ON_NULL_RETURN(uri);
87
88     g_object_set(session, SOUP_SESSION_PROXY_URI, uri, NULL);
89     soup_uri_free(uri);
90 #elif USE(CURL)
91     EINA_SAFETY_ON_TRUE_RETURN(1);
92 #endif
93 #endif
94 }
95
96 void ewk_network_http_request_append(const char* name, const char* value)
97 {
98 #if ENABLE(TIZEN_HTTP_HEADER_REQUEST_APPEND)
99 #if USE(SOUP)
100     WebCore::ResourceHandle::appendHttpRequestHeader(name, value);
101 #elif USE(CURL)
102     EINA_SAFETY_ON_TRUE_RETURN(1);
103 #endif
104 #endif
105 }