Adding missing wayland initialization.
[platform/framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_main.cpp
1 /*
2     Copyright (C) 2009-2010 ProFUSION embedded systems
3     Copyright (C) 2009-2011 Samsung Electronics
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 License
17     along with this library; see the file COPYING.LIB.  If not, write to
18     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19     Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23 #include "ewk_main.h"
24
25 #include "ewk_private.h"
26 #include <Ecore.h>
27 #include <Ecore_Evas.h>
28 #include <Ecore_IMF.h>
29 #include <Edje.h>
30 #include <Eina.h>
31 #include <Evas.h>
32 #include <glib-object.h>
33 #include <glib.h>
34 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
35 #include "ewk_context_private.h"
36 #endif
37
38 #ifdef HAVE_ECORE_X
39 #include <Ecore_X.h>
40 #else
41 #include <Ecore_Wayland.h>
42 #endif
43
44 static int _ewkInitCount = 0;
45
46 /**
47  * \var     _ewk_log_dom
48  * @brief   the log domain identifier that is used with EINA's macros
49  */
50 int _ewk_log_dom = -1;
51
52 int _ewkArgc = 0;
53 char** _ewkArgv = 0;
54
55 int ewk_init(void)
56 {
57     if (_ewkInitCount)
58         return ++_ewkInitCount;
59
60     if (!eina_init())
61         goto error_eina;
62
63     _ewk_log_dom = eina_log_domain_register("ewebkit2", EINA_COLOR_ORANGE);
64     if (_ewk_log_dom < 0) {
65         EINA_LOG_CRIT("could not register log domain 'ewebkit2'");
66         goto error_log_domain;
67     }
68
69     if (!evas_init()) {
70         CRITICAL("could not init evas.");
71         goto error_evas;
72     }
73
74     if (!ecore_init()) {
75         CRITICAL("could not init ecore.");
76         goto error_ecore;
77     }
78
79     if (!ecore_evas_init()) {
80         CRITICAL("could not init ecore_evas.");
81         goto error_ecore_evas;
82     }
83
84     if (!ecore_imf_init()) {
85         CRITICAL("could not init ecore_imf.");
86         goto error_ecore_imf;
87     }
88
89 #ifdef HAVE_ECORE_X
90     if (!ecore_x_init(0)) {
91         CRITICAL("could not init ecore_x.");
92         goto error_ecore_x;
93     }
94 #else
95     if(!ecore_wl_init(0)) {
96         CRITICAL("could not init ecore_wl.");
97         goto error_ecore_wl;
98     }
99 #endif
100
101     g_type_init();
102
103     if (!ecore_main_loop_glib_integrate()) {
104         WARN("Ecore was not compiled with GLib support, some plugins will not "
105             "work (ie: Adobe Flash)");
106     }
107
108     return ++_ewkInitCount;
109
110 #ifdef HAVE_ECORE_X
111 error_ecore_x:
112     ecore_imf_shutdown();
113 #else
114 error_ecore_wl:
115     ecore_imf_shutdown();
116 #endif
117 error_ecore_imf:
118     ecore_evas_shutdown();
119 error_ecore_evas:
120     ecore_shutdown();
121 error_ecore:
122     evas_shutdown();
123 error_evas:
124     eina_log_domain_unregister(_ewk_log_dom);
125     _ewk_log_dom = -1;
126 error_log_domain:
127     eina_shutdown();
128 error_eina:
129     return 0;
130 }
131
132 int ewk_shutdown(void)
133 {
134     if (--_ewkInitCount)
135         return _ewkInitCount;
136
137 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
138     // FIXME : ewk_context_cache_dump() is called on deconstructor of Ewk_Context.
139     // But, I helplessly adds it here because the deconstructor is not called for default ewk context.
140     ewk_context_default_get()->dumpCache();
141 #endif
142
143 #ifdef HAVE_ECORE_X
144     ecore_x_shutdown();
145 #endif
146     ecore_imf_shutdown();
147     ecore_evas_shutdown();
148     ecore_shutdown();
149     evas_shutdown();
150     eina_log_domain_unregister(_ewk_log_dom);
151     _ewk_log_dom = -1;
152     eina_shutdown();
153
154     return 0;
155 }
156
157 void ewk_set_arguments(int argc, char** argv)
158 {
159     _ewkArgc = argc;
160     _ewkArgv = argv;
161 }