Create string tightly when retrive string from cbhm callback event
[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 #endif
41
42 static int _ewkInitCount = 0;
43
44 /**
45  * \var     _ewk_log_dom
46  * @brief   the log domain identifier that is used with EINA's macros
47  */
48 int _ewk_log_dom = -1;
49
50 int _ewkArgc = 0;
51 char** _ewkArgv = 0;
52
53 int ewk_init(void)
54 {
55     if (_ewkInitCount)
56         return ++_ewkInitCount;
57
58     if (!eina_init())
59         goto error_eina;
60
61     _ewk_log_dom = eina_log_domain_register("ewebkit2", EINA_COLOR_ORANGE);
62     if (_ewk_log_dom < 0) {
63         EINA_LOG_CRIT("could not register log domain 'ewebkit2'");
64         goto error_log_domain;
65     }
66
67     if (!evas_init()) {
68         CRITICAL("could not init evas.");
69         goto error_evas;
70     }
71
72     if (!ecore_init()) {
73         CRITICAL("could not init ecore.");
74         goto error_ecore;
75     }
76
77     if (!ecore_evas_init()) {
78         CRITICAL("could not init ecore_evas.");
79         goto error_ecore_evas;
80     }
81
82     if (!ecore_imf_init()) {
83         CRITICAL("could not init ecore_imf.");
84         goto error_ecore_imf;
85     }
86
87 #ifdef HAVE_ECORE_X
88     if (!ecore_x_init(0)) {
89         CRITICAL("could not init ecore_x.");
90         goto error_ecore_x;
91     }
92 #endif
93
94     g_type_init();
95
96     if (!ecore_main_loop_glib_integrate()) {
97         WARN("Ecore was not compiled with GLib support, some plugins will not "
98             "work (ie: Adobe Flash)");
99     }
100
101     return ++_ewkInitCount;
102
103 #ifdef HAVE_ECORE_X
104 error_ecore_x:
105     ecore_imf_shutdown();
106 #endif
107 error_ecore_imf:
108     ecore_evas_shutdown();
109 error_ecore_evas:
110     ecore_shutdown();
111 error_ecore:
112     evas_shutdown();
113 error_evas:
114     eina_log_domain_unregister(_ewk_log_dom);
115     _ewk_log_dom = -1;
116 error_log_domain:
117     eina_shutdown();
118 error_eina:
119     return 0;
120 }
121
122 int ewk_shutdown(void)
123 {
124     if (--_ewkInitCount)
125         return _ewkInitCount;
126
127 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
128     // FIXME : ewk_context_cache_dump() is called on deconstructor of Ewk_Context.
129     // But, I helplessly adds it here because the deconstructor is not called for default ewk context.
130     ewk_context_default_get()->dumpCache();
131 #endif
132
133 #ifdef HAVE_ECORE_X
134     ecore_x_shutdown();
135 #endif
136     ecore_imf_shutdown();
137     ecore_evas_shutdown();
138     ecore_shutdown();
139     evas_shutdown();
140     eina_log_domain_unregister(_ewk_log_dom);
141     _ewk_log_dom = -1;
142     eina_shutdown();
143
144     return 0;
145 }
146
147 void ewk_set_arguments(int argc, char** argv)
148 {
149     _ewkArgc = argc;
150     _ewkArgv = argv;
151 }