4b56ba96f3aae57d9d5cc29a3def414e3146ff62
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / public / ewk_main.cc
1 /*
2  * Copyright (C) 2009-2010 ProFUSION embedded systems
3  * Copyright (C) 2009-2013 Samsung Electronics. All rights reserved.
4  * Copyright (C) 2012 Intel Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301, USA.
20  *
21  */
22
23 #include "ewk_main.h"
24
25 #include <Ecore.h>
26 #include <Ecore_Evas.h>
27 #include <Ecore_IMF.h>
28 #include <Edje.h>
29 #include <Eina.h>
30 #include <Evas.h>
31
32 #if defined(HAVE_ECORE_X)
33 #include <Ecore_X.h>
34 #endif
35
36 #include "public/ewk_log.h"
37 #include "private/webview_delegate_ewk.h"
38 #include "private/ewk_private.h"
39 #include "private/ewk_main_private.h"
40
41 // TODO: remove dependency
42 #include <../impl/command_line_efl.h>
43 #include <../impl/eweb_context.h>
44 #include <../impl/ewk_global_data.h>
45
46 static int _ewkInitCount = 0;
47
48 /////////////////////////////////////////////////////////////////////////////
49 //private function declaration here
50 static void _ewk_init_web_engine(void);
51 static void _ewk_shutdown_web_engine(void);
52
53 extern std::string g_homeDirectory;
54
55 /**
56  * \var     _ewk_log_dom
57  * @brief   the log domain identifier that is used with EINA's macros
58  */
59 int _ewk_log_dom = -1;
60
61 int ewk_init(void)
62 {
63   if (_ewkInitCount)
64       return ++_ewkInitCount;
65
66   if (!eina_init())
67       goto error_eina;
68
69   _ewk_log_dom = eina_log_domain_register("ewebview-blink", EINA_COLOR_ORANGE);
70   if (_ewk_log_dom < 0) {
71       EINA_LOG_CRIT("could not register log domain 'ewebview-blink'");
72       goto error_log_domain;
73   }
74
75   if (!evas_init()) {
76       CRITICAL("could not init evas.");
77       goto error_evas;
78   }
79
80   if (!ecore_init()) {
81       CRITICAL("could not init ecore.");
82       goto error_ecore;
83   }
84
85   if (!ecore_evas_init()) {
86       CRITICAL("could not init ecore_evas.");
87       goto error_ecore_evas;
88   }
89
90   if (!ecore_imf_init()) {
91       CRITICAL("could not init ecore_imf.");
92       goto error_ecore_imf;
93   }
94
95 #if defined(HAVE_ECORE_X)
96   if (!ecore_x_init(0)) {
97       CRITICAL("could not init ecore_x.");
98       goto error_ecore_x;
99   }
100 #endif
101
102   if (!edje_init()) {
103       CRITICAL("Could not init edje.");
104       goto error_edje;
105   }
106
107   // FIXME: do we need glib integration like WebKit?
108 #if 0
109 #if !GLIB_CHECK_VERSION(2, 35, 0)
110   g_type_init();
111 #endif
112
113   if (!ecore_main_loop_glib_integrate()) {
114       WARN("Ecore was not compiled with GLib support, some plugins will not "
115           "work (ie: Adobe Flash)");
116   }
117 #endif
118
119   _ewk_init_web_engine();
120   return ++_ewkInitCount;
121
122 error_edje:
123 #if defined(HAVE_ECORE_X)
124   ecore_x_shutdown();
125 error_ecore_x:
126 #endif
127   ecore_imf_shutdown();
128 error_ecore_imf:
129   ecore_evas_shutdown();
130 error_ecore_evas:
131   ecore_shutdown();
132 error_ecore:
133   evas_shutdown();
134 error_evas:
135   eina_log_domain_unregister(_ewk_log_dom);
136   _ewk_log_dom = -1;
137 error_log_domain:
138   eina_shutdown();
139 error_eina:
140   return 0;
141 }
142
143 int ewk_shutdown(void)
144 {
145   if (!_ewkInitCount || --_ewkInitCount)
146       return _ewkInitCount;
147
148   _ewk_shutdown_web_engine();
149
150   edje_shutdown();
151 #if defined(HAVE_ECORE_X)
152   ecore_x_shutdown();
153 #endif
154   ecore_imf_shutdown();
155   ecore_evas_shutdown();
156   ecore_shutdown();
157   evas_shutdown();
158   eina_log_domain_unregister(_ewk_log_dom);
159   _ewk_log_dom = -1;
160   eina_shutdown();
161
162   return 0;
163 }
164
165 void ewk_set_arguments(int argc, char** argv)
166 {
167     CommandLineEfl::Init(argc, argv);
168 }
169
170 void ewk_home_directory_set(const char* path)
171 {
172   if (!path)
173     g_homeDirectory.clear();
174   else
175     g_homeDirectory = path;
176 }
177
178 /////////////////////////////////////////////////////////////////////////////////////////////
179 //Private functions implementations for ewk_main module
180
181 //Initialize web engine
182 void _ewk_init_web_engine()
183 {
184   if(!WebViewDelegate::IsDelegateRegistered()) {
185     WebViewDelegate::RegisterDelegate(
186       const_cast<WebViewDelegateEwk*>(&WebViewDelegateEwk::GetInstance()));
187   }
188 }
189
190 void _ewk_shutdown_web_engine(void)
191 {
192   //TODO: any web engine destroy to be done here
193   CommandLineEfl::Shutdown();
194   EwkGlobalData::Delete();
195 }
196