e20617b16ddf2cd35793d4cdcdebb79e530f0357
[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-2016 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 Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #include "ewk_main_internal.h"
22
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25 #include <Ecore_IMF.h>
26 #include <Edje.h>
27 #include <Eina.h>
28 #include <Evas.h>
29
30 #include "command_line_efl.h"
31 #include "eweb_context.h"
32 #include "ewk_global_data.h"
33 #include "ewk_log_internal.h"
34 #include "ewk_view.h"
35 #include "private/webview_delegate_ewk.h"
36 #include "private/ewk_context_private.h"
37 #include "private/ewk_private.h"
38 #include "private/ewk_main_private.h"
39
40 #include "ecore_x_wayland_wrapper.h"
41
42 static int _ewkInitCount = 0;
43
44 /////////////////////////////////////////////////////////////////////////////
45 //private function declaration here
46 static void _ewk_init_web_engine(void);
47 static void _ewk_shutdown_web_engine(void);
48
49 extern std::string g_homeDirectory;
50
51 /**
52  * \var     _ewk_log_dom
53  * @brief   the log domain identifier that is used with EINA's macros
54  */
55 int _ewk_log_dom = -1;
56 #if defined(USE_WAYLAND) && TIZEN_VERSION_AT_LEAST(5, 0, 0)
57 Ecore_Wl2_Display* _ecore_wl2_display = NULL;
58 #endif
59
60 int ewk_init(void)
61 {
62   if (_ewkInitCount)
63     return ++_ewkInitCount;
64
65   if (!eina_init()) {
66     ERR("could not init eina.");
67     goto error_eina;
68   }
69
70   _ewk_log_dom = eina_log_domain_register("ewebview-blink", EINA_COLOR_ORANGE);
71   if (_ewk_log_dom < 0) {
72     EINA_LOG_ERR("could not register log domain 'ewebview-blink'");
73     goto error_log_domain;
74   }
75
76   if (!evas_init()) {
77     ERR("could not init evas.");
78     goto error_evas;
79   }
80
81   if (!ecore_init()) {
82     ERR("could not init ecore.");
83     goto error_ecore;
84   }
85
86   if (!ecore_evas_init()) {
87     ERR("could not init ecore_evas.");
88     goto error_ecore_evas;
89   }
90
91   if (!ecore_imf_init()) {
92     ERR("could not init ecore_imf.");
93     goto error_ecore_imf;
94   }
95
96 #if defined(USE_WAYLAND)
97 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
98   if (!ecore_wl2_init()) {
99 #else
100   if (!ecore_wl_init(0)) {
101 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
102     ERR("could not init ecore_wl.");
103     goto error_ecore_wl;
104   }
105 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
106   if (!_ecore_wl2_display)
107     _ecore_wl2_display = ecore_wl2_display_connect(NULL);
108 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
109 #else
110   if (!ecore_x_init(0)) {
111     ERR("could not init ecore_x.");
112     goto error_ecore_x;
113   }
114 #endif
115
116   if (!edje_init()) {
117     ERR("Could not init edje.");
118     goto error_edje;
119   }
120
121   _ewk_init_web_engine();
122   return ++_ewkInitCount;
123
124 error_edje:
125 #if defined(USE_WAYLAND)
126 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
127   if (_ecore_wl2_display) {
128     ecore_wl2_display_disconnect(_ecore_wl2_display);
129     _ecore_wl2_display = NULL;
130     ecore_wl2_shutdown();
131   }
132 #else
133   ecore_wl_shutdown();
134 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
135 error_ecore_wl:
136 #else
137   ecore_x_shutdown();
138 error_ecore_x:
139 #endif
140   ecore_imf_shutdown();
141 error_ecore_imf:
142   ecore_evas_shutdown();
143 error_ecore_evas:
144   ecore_shutdown();
145 error_ecore:
146   evas_shutdown();
147 error_evas:
148   eina_log_domain_unregister(_ewk_log_dom);
149   _ewk_log_dom = -1;
150 error_log_domain:
151   eina_shutdown();
152 error_eina:
153   return 0;
154 }
155
156 int ewk_shutdown(void)
157 {
158   if (!_ewkInitCount || --_ewkInitCount)
159       return _ewkInitCount;
160
161   _ewk_shutdown_web_engine();
162
163   edje_shutdown();
164 #if defined(USE_WAYLAND)
165 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
166   if (_ecore_wl2_display) {
167     ecore_wl2_display_disconnect(_ecore_wl2_display);
168     _ecore_wl2_display = NULL;
169     ecore_wl2_shutdown();
170   }
171 #else
172   ecore_wl_shutdown();
173 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
174 #else
175   ecore_x_shutdown();
176 #endif
177   ecore_imf_shutdown();
178   ecore_evas_shutdown();
179   ecore_shutdown();
180   evas_shutdown();
181   eina_log_domain_unregister(_ewk_log_dom);
182   _ewk_log_dom = -1;
183   eina_shutdown();
184
185   return 0;
186 }
187
188 void ewk_set_arguments(int argc, char** argv)
189 {
190     CommandLineEfl::Init(argc, argv);
191 }
192
193 void ewk_process_model_set(Ewk_Process_Model process_model)
194 {
195   LOG_EWK_API_MOCKUP();
196 }
197
198 void ewk_memory_optimization_mode_enable(void)
199 {
200   LOG_EWK_API_MOCKUP();
201 }
202
203 void ewk_home_directory_set(const char* path)
204 {
205   if (!path)
206     g_homeDirectory.clear();
207   else
208     g_homeDirectory = path;
209 }
210
211 /////////////////////////////////////////////////////////////////////////////////////////////
212 //Private functions implementations for ewk_main module
213
214 //Initialize web engine
215 void _ewk_init_web_engine()
216 {
217 }
218
219 void _ewk_shutdown_web_engine(void)
220 {
221   //TODO: any web engine destroy to be done here
222   CommandLineEfl::Shutdown();
223   Ewk_Context::DefaultContextRelease();
224   EwkGlobalData::Delete();
225 }
226