Task TT-75 Implement "Main page loading UI" view
[profile/tv/apps/web/browser.git] / core / main.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "browser_config.h"
17
18 #include "BrowserLogger.h"
19 #include <Ecore.h>
20 #include <Edje.h>
21 #include <Elementary.h>
22 #include <stdexcept>
23
24 #if PLATFORM(TIZEN)
25 #include <app.h>
26 #endif
27
28 #include <ewk_chromium.h>
29
30 // for tests...
31 #include "Lifecycle.h"
32 #include "ServiceManager.h"
33 #include "BasicUI/AbstractMainWindow.h"
34
35 ///\note Odroid platform modification
36 #if PLATFORM(TIZEN)
37 const std::string DEFAULT_URL = "";
38
39 static bool app_create(void * /*app_data*/)
40 {
41 // MERGE_ME not sure which should be chosen
42 //  elm_config_accel_preference_set("opengl");
43     elm_config_accel_preference_set("3d");
44
45     elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
46     // Enabling focus
47     elm_config_focus_highlight_enabled_set(EINA_TRUE);
48
49     /// \todo: clean casts, depends on ServiceManager
50     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
51     std::dynamic_pointer_cast
52     <
53         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
54         tizen_browser::core::AbstractService
55     >
56     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
57
58     //mainUi->exec("");
59     return true;
60 }
61
62 static void app_terminate(void */*app_data*/)
63 {
64     BROWSER_LOGD("%s\n", __func__);
65     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
66     std::dynamic_pointer_cast
67     <
68         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
69         tizen_browser::core::AbstractService
70     >
71     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
72     mainUi->destroyUI();
73 }
74
75 static void app_service(service_h service, void */*app_data*/){
76     /* to test this functionality please use aul_test command on target:
77      *  $aul_test org.tizen.browser __APP_SVC_URI__ <http://full.url.com/>
78      */
79     BROWSER_LOGD("%s\n", __func__);
80
81     char *operation = NULL;
82     char *request_uri = NULL;
83     char *request_mime_type = NULL;
84
85     if (service_get_operation(service, &operation) != SERVICE_ERROR_NONE) {
86         BROWSER_LOGD("get service operation failed");
87         return;
88     }
89
90     if (service_get_uri(service, &request_uri) != SERVICE_ERROR_NONE)
91         BROWSER_LOGD("get service uri failed");
92
93     if (service_get_mime(service, &request_mime_type) != SERVICE_ERROR_NONE)
94         BROWSER_LOGD("get service mime failed");
95
96
97     BROWSER_LOGD("operation = [%s], request_uri = [%s], request_mime_type = [%s]"
98             , operation, request_uri, request_mime_type);
99
100     std::string uri = request_uri != NULL ? std::string(request_uri) : DEFAULT_URL;
101
102     BROWSER_LOGD("[%s] uri=%s", __func__, uri.c_str());
103     free(request_uri);
104     free(request_mime_type);
105     free(operation);
106
107     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
108     std::dynamic_pointer_cast
109     <
110         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
111         tizen_browser::core::AbstractService
112     >
113     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
114
115     mainUi->exec(uri);
116
117     evas_object_show(mainUi->getMainWindow().get());
118     elm_win_activate(mainUi->getMainWindow().get());
119 }
120
121 static void app_pause(void *){
122     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
123 }
124
125 static void app_resume(void *){
126     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
127 }
128
129 int main(int argc, char* argv[])try
130 {
131     BEGIN()
132     ewk_init();
133     setenv("ELM_PROFILE", "tv", true);
134
135 //#if !defined(NDEBUG)
136     //Initialization of logger module
137     tizen_browser::logger::Logger::getInstance().init();
138     tizen_browser::logger::Logger::getInstance().setLogTag("browser");
139 //#endif
140
141         BROWSER_LOGD("BROWSER IS SAYING HELLO");
142         BROWSER_LOGD("BROWSER TAG: %s",tizen_browser::logger::Logger::getInstance().getLogTag().c_str());
143         BROWSER_LOGD("BROWSER REGISTERED LOGGERS COUNT: %d",tizen_browser::logger::Logger::getInstance().getLoggersCount());
144
145     app_event_callback_s ops;
146     memset(&ops, 0x00, sizeof(app_event_callback_s));
147
148     ops.create = app_create;
149     ops.terminate = app_terminate;
150     ops.service = app_service;
151
152     ops.pause = app_pause;
153     ops.resume = app_resume;
154
155     app_efl_main(&argc, &argv, &ops, NULL);
156
157     ewk_shutdown();
158     END()
159
160 } catch (std::exception & e)
161 {
162     std::cerr << "UNHANDLED EXCEPTION " << e.what() << std::endl;
163 } catch (...)
164 {
165     std::cerr << "UNHANDLED EXCEPTION" << std::endl;
166 }
167 #else
168 int main(int argc, char* argv[]) try
169 {
170     BEGIN()
171     elm_init(argc, argv);
172
173 #if PLATFORM(TIZEN)
174     elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
175     // Enabling focus
176     elm_config_focus_highlight_enabled_set(EINA_TRUE);
177 #endif
178
179     tizen_browser::logger::Logger::getInstance().init();
180     tizen_browser::logger::Logger::getInstance().setLogTag("browser");
181
182     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
183     std::dynamic_pointer_cast
184     <
185         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
186         tizen_browser::core::AbstractService
187     >
188     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
189
190     if (mainUi) {
191         evas_object_show(mainUi->getMainWindow().get());
192         mainUi->exec("http://enlightenment.org");
193     }
194
195     elm_run();
196
197     elm_shutdown();
198     END()
199 } catch (std::exception & e)
200 {
201     std::cerr << "UNHANDLED EXCEPTION " << e.what() << std::endl;
202 } catch (...)
203 {
204     std::cerr << "UNHANDLED EXCEPTION" << std::endl;
205 }
206 #endif