Support Wayland
[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 = "file:///usr/apps/org.tizen.browser/res/demo/b.htm";
38
39 static bool app_create(void * /*app_data*/)
40 {
41     elm_config_accel_preference_set("opengl");
42
43     elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
44     // Enabling focus
45     elm_config_focus_highlight_enabled_set(EINA_TRUE);
46
47     /// \todo: clean casts, depends on ServiceManager
48     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
49     std::dynamic_pointer_cast
50     <
51         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
52         tizen_browser::core::AbstractService
53     >
54     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
55
56     //mainUi->exec("");
57     return true;
58 }
59
60 static void app_terminate(void */*app_data*/)
61 {
62     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
63     std::dynamic_pointer_cast
64     <
65         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
66         tizen_browser::core::AbstractService
67     >
68     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
69     mainUi->destroyUI();
70 }
71
72 static void app_service(service_h service, void */*app_data*/){
73     /* to test this functionality please use aul_test command on target:
74      *  $aul_test org.tizen.browser __APP_SVC_URI__ <http://full.url.com/>
75      */
76     BROWSER_LOGD("%s\n", __func__);
77
78     char *operation = NULL;
79     char *request_uri = NULL;
80     char *request_mime_type = NULL;
81
82     if (service_get_operation(service, &operation) != SERVICE_ERROR_NONE) {
83         BROWSER_LOGD("get service operation failed");
84         return;
85     }
86
87     if (service_get_uri(service, &request_uri) != SERVICE_ERROR_NONE)
88         BROWSER_LOGD("get service uri failed");
89
90     if (service_get_mime(service, &request_mime_type) != SERVICE_ERROR_NONE)
91         BROWSER_LOGD("get service mime failed");
92
93
94     BROWSER_LOGD("operation = [%s], request_uri = [%s], request_mime_type = [%s]"
95             , operation, request_uri, request_mime_type);
96
97     std::string uri = request_uri != NULL ? std::string(request_uri) : DEFAULT_URL;
98
99     BROWSER_LOGD("[%s] uri=%s", __func__, uri.c_str());
100     free(request_uri);
101     free(request_mime_type);
102     free(operation);
103
104     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
105     std::dynamic_pointer_cast
106     <
107         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
108         tizen_browser::core::AbstractService
109     >
110     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
111
112     mainUi->exec(uri);
113
114     evas_object_show(mainUi->getMainWindow().get());
115     elm_win_activate(mainUi->getMainWindow().get());
116 }
117
118 static void app_pause(void *){
119     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
120 }
121
122 static void app_resume(void *){
123     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
124 }
125
126 int main(int argc, char* argv[])try
127 {
128     BEGIN()
129     ewk_init();
130     setenv("ELM_PROFILE", "tv", true);
131
132 //#if !defined(NDEBUG)
133     //Initialization of logger module
134     tizen_browser::logger::Logger::getInstance().init();
135     tizen_browser::logger::Logger::getInstance().setLogTag("browser");
136 //#endif
137
138         BROWSER_LOGD("BROWSER IS SAYING HELLO");
139         BROWSER_LOGD("BROWSER TAG: %s",tizen_browser::logger::Logger::getInstance().getLogTag().c_str());
140         BROWSER_LOGD("BROWSER REGISTERED LOGGERS COUNT: %d",tizen_browser::logger::Logger::getInstance().getLoggersCount());
141
142     app_event_callback_s ops;
143     memset(&ops, 0x00, sizeof(app_event_callback_s));
144
145     ops.create = app_create;
146     ops.terminate = app_terminate;
147     ops.service = app_service;
148
149     ops.pause = app_pause;
150     ops.resume = app_resume;
151
152     app_efl_main(&argc, &argv, &ops, NULL);
153
154     ewk_shutdown();
155     END()
156
157 } catch (std::exception & e)
158 {
159     std::cerr << "UNHANDLED EXCEPTION " << e.what() << std::endl;
160 } catch (...)
161 {
162     std::cerr << "UNHANDLED EXCEPTION" << std::endl;
163 }
164 #else
165 int main(int argc, char* argv[]) try
166 {
167     BEGIN()
168     elm_init(argc, argv);
169
170 #if PLATFORM(TIZEN)
171     elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
172     // Enabling focus
173     elm_config_focus_highlight_enabled_set(EINA_TRUE);
174 #endif
175
176     tizen_browser::logger::Logger::getInstance().init();
177     tizen_browser::logger::Logger::getInstance().setLogTag("browser");
178
179     std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
180     std::dynamic_pointer_cast
181     <
182         tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
183         tizen_browser::core::AbstractService
184     >
185     (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
186
187     if (mainUi) {
188         evas_object_show(mainUi->getMainWindow().get());
189         mainUi->exec("http://enlightenment.org");
190     }
191
192     elm_run();
193
194     elm_shutdown();
195     END()
196 } catch (std::exception & e)
197 {
198     std::cerr << "UNHANDLED EXCEPTION " << e.what() << std::endl;
199 } catch (...)
200 {
201     std::cerr << "UNHANDLED EXCEPTION" << std::endl;
202 }
203 #endif