Delete default context in ewk
[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 "public/ewk_view.h"
38 #include "private/webview_delegate_ewk.h"
39 #include "private/ewk_private.h"
40 #include "private/ewk_main_private.h"
41
42 // TODO: remove dependency
43 #include <../impl/command_line_efl.h>
44 #include <../impl/eweb_context.h>
45 #include <../impl/ewk_global_data.h>
46
47 static int _ewkInitCount = 0;
48
49 /////////////////////////////////////////////////////////////////////////////
50 //private function declaration here
51 static void _ewk_init_web_engine(void);
52 static void _ewk_shutdown_web_engine(void);
53
54 extern std::string g_homeDirectory;
55
56 /**
57  * \var     _ewk_log_dom
58  * @brief   the log domain identifier that is used with EINA's macros
59  */
60 int _ewk_log_dom = -1;
61
62 int ewk_init(void)
63 {
64   if (_ewkInitCount)
65       return ++_ewkInitCount;
66
67   if (!eina_init())
68       goto error_eina;
69
70   _ewk_log_dom = eina_log_domain_register("ewebview-blink", EINA_COLOR_ORANGE);
71   if (_ewk_log_dom < 0) {
72       EINA_LOG_CRIT("could not register log domain 'ewebview-blink'");
73       goto error_log_domain;
74   }
75
76   if (!evas_init()) {
77       CRITICAL("could not init evas.");
78       goto error_evas;
79   }
80
81   if (!ecore_init()) {
82       CRITICAL("could not init ecore.");
83       goto error_ecore;
84   }
85
86   if (!ecore_evas_init()) {
87       CRITICAL("could not init ecore_evas.");
88       goto error_ecore_evas;
89   }
90
91   if (!ecore_imf_init()) {
92       CRITICAL("could not init ecore_imf.");
93       goto error_ecore_imf;
94   }
95
96 #if defined(HAVE_ECORE_X)
97   if (!ecore_x_init(0)) {
98       CRITICAL("could not init ecore_x.");
99       goto error_ecore_x;
100   }
101 #endif
102
103   if (!edje_init()) {
104       CRITICAL("Could not init edje.");
105       goto error_edje;
106   }
107
108   // FIXME: do we need glib integration like WebKit?
109 #if 0
110 #if !GLIB_CHECK_VERSION(2, 35, 0)
111   g_type_init();
112 #endif
113
114   if (!ecore_main_loop_glib_integrate()) {
115       WARN("Ecore was not compiled with GLib support, some plugins will not "
116           "work (ie: Adobe Flash)");
117   }
118 #endif
119
120   _ewk_init_web_engine();
121   return ++_ewkInitCount;
122
123 error_edje:
124 #if defined(HAVE_ECORE_X)
125   ecore_x_shutdown();
126 error_ecore_x:
127 #endif
128   ecore_imf_shutdown();
129 error_ecore_imf:
130   ecore_evas_shutdown();
131 error_ecore_evas:
132   ecore_shutdown();
133 error_ecore:
134   evas_shutdown();
135 error_evas:
136   eina_log_domain_unregister(_ewk_log_dom);
137   _ewk_log_dom = -1;
138 error_log_domain:
139   eina_shutdown();
140 error_eina:
141   return 0;
142 }
143
144 int ewk_shutdown(void)
145 {
146   if (!_ewkInitCount || --_ewkInitCount)
147       return _ewkInitCount;
148
149   _ewk_shutdown_web_engine();
150
151   edje_shutdown();
152 #if defined(HAVE_ECORE_X)
153   ecore_x_shutdown();
154 #endif
155   ecore_imf_shutdown();
156   ecore_evas_shutdown();
157   ecore_shutdown();
158   evas_shutdown();
159   eina_log_domain_unregister(_ewk_log_dom);
160   _ewk_log_dom = -1;
161   eina_shutdown();
162
163   return 0;
164 }
165
166 void ewk_set_arguments(int argc, char** argv)
167 {
168     CommandLineEfl::Init(argc, argv);
169 }
170
171 void ewk_home_directory_set(const char* path)
172 {
173   if (!path)
174     g_homeDirectory.clear();
175   else
176     g_homeDirectory = path;
177 }
178
179 /////////////////////////////////////////////////////////////////////////////////////////////
180 //Private functions implementations for ewk_main module
181
182 //Initialize web engine
183 void _ewk_init_web_engine()
184 {
185   if(!WebViewDelegate::IsDelegateRegistered()) {
186     WebViewDelegate::RegisterDelegate(
187       const_cast<WebViewDelegateEwk*>(&WebViewDelegateEwk::GetInstance()));
188   }
189 }
190
191 void _ewk_shutdown_web_engine(void)
192 {
193   //TODO: any web engine destroy to be done here
194   CommandLineEfl::Shutdown();
195   ewk_context_delete(ewk_context_default_get());
196   EwkGlobalData::Delete();
197 }
198