2 Copyright (C) 2009-2010 ProFUSION embedded systems
3 Copyright (C) 2009-2011 Samsung Electronics
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
25 #include "FileSystem.h"
27 #include "PageCache.h"
28 #include "PageGroup.h"
29 #include "ScriptController.h"
30 #include "ewk_private.h"
31 #include "ewk_settings.h"
32 #include "runtime/InitializeThreading.h"
35 #include <Ecore_Evas.h>
41 #include <wtf/Threading.h>
43 #if ENABLE(GLIB_SUPPORT)
44 #include <glib-object.h>
47 #ifdef ENABLE_GTK_PLUGINS_SUPPORT
54 // REMOVE-ME: see todo below
55 #include "ResourceHandle.h"
56 #include "ewk_auth_soup.h"
57 #include <libsoup/soup.h>
60 static int _ewk_init_count = 0;
64 * @brief the log domain identifier that is used with EINA's macros
66 int _ewk_log_dom = -1;
68 static Eina_Bool _ewk_init_body(void);
71 * Initializes webkit's instance.
73 * - initializes components needed by Efl,
74 * - sets web database location,
75 * - sets page cache capacity,
76 * - increases a reference count of webkit's instance.
78 * @return a reference count of webkit's instance on success or 0 on failure
83 return ++_ewk_init_count;
88 _ewk_log_dom = eina_log_domain_register("ewebkit", EINA_COLOR_ORANGE);
89 if (_ewk_log_dom < 0) {
90 EINA_LOG_CRIT("could not register log domain 'ewebkit'");
91 goto error_log_domain;
95 CRITICAL("could not init evas.");
100 CRITICAL("could not init ecore.");
104 if (!ecore_evas_init()) {
105 CRITICAL("could not init ecore_evas.");
106 goto error_ecore_evas;
110 CRITICAL("could not init edje.");
114 if (!_ewk_init_body()) {
115 CRITICAL("could not init body");
119 return ++_ewk_init_count;
122 ecore_evas_shutdown();
128 eina_log_domain_unregister(_ewk_log_dom);
137 * Decreases a reference count of webkit's instance, possibly destroying it.
139 * If the reference count reaches 0 webkit's instance is destroyed.
141 * @return a reference count of webkit's instance
143 int ewk_shutdown(void)
147 return _ewk_init_count;
149 ecore_evas_shutdown();
152 eina_log_domain_unregister(_ewk_log_dom);
159 Eina_Bool _ewk_init_body(void)
162 #if ENABLE(GLIB_SUPPORT)
165 if (!g_thread_supported())
168 #ifdef ENABLE_GTK_PLUGINS_SUPPORT
170 if (!gtk_init_check(0, 0))
171 WRN("Could not initialize GTK support.");
174 if (!ecore_main_loop_glib_integrate())
175 WRN("Ecore was not compiled with GLib support, some plugins will not "
176 "work (ie: Adobe Flash)");
179 WebCore::ScriptController::initializeThreading();
180 WebCore::InitializeLoggingChannelsIfNecessary();
182 // Page cache capacity (in pages). Comment from Mac port:
183 // (Research indicates that value / page drops substantially after 3 pages.)
184 // FIXME: Expose this with an API and/or calculate based on available resources
185 WebCore::pageCache()->setCapacity(3);
186 WebCore::PageGroup::setShouldTrackVisitedLinks(true);
188 String home = WebCore::homeDirectoryPath();
190 // check home directory first
191 if (stat(home.utf8().data(), &state) == -1) {
192 // Exit now - otherwise you may have some crash later
193 int errnowas = errno;
194 CRITICAL("Can't access HOME dir (or /tmp) - no place to save databases: %s", strerror(errnowas));
198 WTF::String wkdir = home + "/.webkit";
199 if (WebCore::makeAllDirectories(wkdir)) {
200 ewk_settings_web_database_path_set(wkdir.utf8().data());
202 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
203 ewk_settings_cache_directory_path_set(wkdir.utf8().data());
207 // TODO: this should move to WebCore, already reported to webkit-gtk folks:
210 SoupSession* session = WebCore::ResourceHandle::defaultSession();
211 soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_SNIFFER);
212 soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
214 SoupSessionFeature* auth_dialog = static_cast<SoupSessionFeature*>(g_object_new(EWK_TYPE_SOUP_AUTH_DIALOG, 0));
215 soup_session_add_feature(session, auth_dialog);