initial import
[vuplus_webkit] / Source / WebKit / efl / ewk / ewk_network.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 "NetworkStateNotifier.h"
24 #include "ewk_logging.h"
25 #include <Eina.h>
26 #include <wtf/text/CString.h>
27
28 #if USE(SOUP)
29 #include "ResourceHandle.h"
30 #include <libsoup/soup.h>
31 #endif
32
33 void ewk_network_proxy_uri_set(const char *proxy)
34 {
35 #if USE(SOUP)
36     SoupSession *session = WebCore::ResourceHandle::defaultSession();
37
38     if (!proxy) {
39         ERR("no proxy uri. remove proxy feature in soup.");
40         soup_session_remove_feature_by_type(session, SOUP_TYPE_PROXY_RESOLVER);
41         return;
42     }
43
44     SoupURI *uri = soup_uri_new(proxy);
45     EINA_SAFETY_ON_NULL_RETURN(uri);
46
47     g_object_set(session, SOUP_SESSION_PROXY_URI, uri, NULL);
48     soup_uri_free(uri);
49 #elif USE(CURL)
50     EINA_SAFETY_ON_TRUE_RETURN(1);
51 #endif
52 }
53
54 const char *ewk_network_proxy_uri_get(void)
55 {
56 #if USE(SOUP)
57     SoupURI *uri;
58     SoupSession *session = WebCore::ResourceHandle::defaultSession();
59     g_object_get(session, SOUP_SESSION_PROXY_URI, &uri, NULL);
60
61     if (!uri) {
62         ERR("no proxy uri");
63         return 0;
64     }
65
66     WTF::String proxy = soup_uri_to_string(uri, EINA_FALSE);
67     return eina_stringshare_add(proxy.utf8().data());
68 #elif USE(CURL)
69     EINA_SAFETY_ON_TRUE_RETURN_VAL(1, 0);
70 #endif
71 }
72
73 void ewk_network_state_notifier_online_set(Eina_Bool online)
74 {
75     WebCore::networkStateNotifier().setOnLine(online);
76 }