Added the initial value for ewk orientation
[platform/framework/web/wrt.git] / src / wrt-client / wrt-client.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 "wrt-client.h"
17 #include <appcore-efl.h>
18 #include <appcore-common.h>
19 #include <cstdlib>
20 #include <cstdio>
21 #include <string>
22 #include <dpl/log/log.h>
23 #include <dpl/optional_typedefs.h>
24 #include <dpl/exception.h>
25 #include <common/application_data.h>
26 #include <core_module.h>
27 #include <localization_setting.h>
28 #include <widget_deserialize_model.h>
29 #include <EWebKit2.h>
30 #include <dpl/localization/w3c_file_localization.h>
31 #include <dpl/localization/LanguageTagsProvider.h>
32 #include "webkit/bundles/plugin_module_support.h"
33
34 //W3C PACKAGING enviroment variable name
35 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
36
37 // window signal callback
38 const char *EDJE_SHOW_BACKWARD_SIGNAL = "show,backward,signal";
39 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
40 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
41 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
42 const char* const BUNDLE_PATH = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
43
44 static Ewk_Context* s_ewk_context = NULL;
45
46 WrtClient::WrtClient(int argc, char **argv) :
47     Application(argc, argv, "wrt-client", false),
48     DPL::TaskDecl<WrtClient>(this),
49     m_launched(false),
50     m_initializing(false),
51     m_initialized(false),
52     m_sdkLauncherPid(0),
53     m_debugMode(false),
54     m_debuggerPort(0),
55     m_returnStatus(ReturnStatus::Succeeded),
56     m_widgetState(WidgetState::WidgetState_Stopped)
57 {
58     Touch();
59     LogDebug("App Created");
60 }
61
62 WrtClient::~WrtClient()
63 {
64     LogDebug("App Finished");
65 }
66
67 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
68 {
69     return m_returnStatus;
70 }
71
72 void WrtClient::OnStop()
73 {
74     LogInfo("Stopping Dummy Client");
75 }
76
77 void WrtClient::OnCreate()
78 {
79     LogInfo("On Create");
80     ADD_PROFILING_POINT("OnCreate callback", "point");
81     ewk_init();
82 }
83
84 void WrtClient::OnResume()
85 {
86     if (m_widgetState != WidgetState_Suspended) {
87         LogWarning("Widget is not suspended, resuming was skipped");
88         return;
89     }
90     m_widget->Resume();
91     m_widgetState = WidgetState_Running;
92 }
93
94 void WrtClient::OnPause()
95 {
96     LogDebug("On pause");
97
98     if (m_widgetState != WidgetState_Running) {
99         LogWarning("Widget is not running to be suspended");
100         return;
101     }
102     m_widget->Suspend();
103     m_widgetState = WidgetState_Suspended;
104 }
105
106 void WrtClient::OnReset(bundle *b)
107 {
108     LogDebug("OnReset");
109     // bundle argument is freed after OnReset() is returned
110     // So bundle duplication is needed
111     ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
112
113     if (true == m_initializing) {
114         LogDebug("can not handle reset event");
115         return;
116     }
117     if (true == m_launched) {
118         if (m_widgetState == WidgetState_Stopped) {
119             LogError("Widget is not running to be reset");
120             return;
121         }
122         m_widget->Reset();
123         m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
124         m_widgetState = WidgetState_Running;
125     } else {
126         if (true == checkArgument()) {
127             setStep();
128         } else {
129             showHelpAndQuit();
130         }
131     }
132
133     // low memory callback set
134     appcore_set_event_callback(
135             APPCORE_EVENT_LOW_MEMORY,
136             WrtClient::appcoreLowMemoryCallback,
137             this);
138 }
139
140 void WrtClient::OnTerminate()
141 {
142     LogDebug("Wrt Shutdown now");
143     shutdownStep();
144 }
145
146 void WrtClient::showHelpAndQuit()
147 {
148     printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
149            "launch widgets.\n"
150            "Mandatory arguments to long options are mandatory for short "
151            "options too.\n"
152            "  -h,    --help                                 show this help\n"
153            "  -l,    --launch                               "
154            "launch widget with given tizen ID\n"
155            "  -t,    --tizen                                "
156            "launch widget with given tizen ID\n"
157            "\n");
158
159     Quit();
160 }
161
162 bool WrtClient::checkArgument()
163 {
164     std::string tizenId = getTizenIdFromArgument(m_argc, m_argv);
165
166     if (tizenId.empty()) {
167         // Just show help
168         return false;
169     } else {
170         m_tizenId = tizenId;
171         LogDebug("Tizen id: " << m_tizenId);
172         return true;
173     }
174 }
175
176 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
177 {
178     LogInfo("checkArgument");
179     std::string arg = argv[0];
180
181     if (arg.empty()) {
182         return "";
183     }
184
185     if (arg.find("wrt-client") != std::string::npos) {
186         if (argc <= 1) {
187             return "";
188         }
189
190         arg = argv[1];
191
192         if (arg == "-h" || arg == "--help") {
193             return "";
194         } else if (arg == "-l" || arg == "--launch" ||
195                    arg == "-t" || arg == "--tizen")
196         {
197             if (argc != 3) {
198                 return "";
199             }
200             return argv[2];
201         } else {
202             return "";
203         }
204     } else {
205         // Launch widget based on application basename
206         size_t pos = arg.find_last_of('/');
207
208         if (pos != std::string::npos) {
209             arg = arg.erase(0, pos + 1);
210         }
211
212         return arg;
213     }
214 }
215
216 void WrtClient::setStep()
217 {
218     LogInfo("setStep");
219
220     AddStep(&WrtClient::initStep);
221
222     setSdkLauncherDebugData();
223
224     AddStep(&WrtClient::launchStep);
225     AddStep(&WrtClient::shutdownStep);
226
227     m_initializing = true;
228
229     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
230 }
231
232 void WrtClient::setSdkLauncherDebugData()
233 {
234     LogDebug("setSdkLauncherDebugData");
235
236     /* check bundle from sdk launcher */
237     bundle *bundleFromSdkLauncher;
238     bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
239     const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
240     const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
241     if (bundle_debug != NULL && bundle_pid != NULL) {
242         if (strcmp(bundle_debug, "true") == 0) {
243             m_debugMode = true;
244             m_sdkLauncherPid = atoi(bundle_pid);
245         } else {
246             m_debugMode = false;
247         }
248     }
249     bundle_free(bundleFromSdkLauncher);
250 }
251
252 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
253 {
254     LogError("Checking for debug mode");
255     Assert(m_dao);
256
257     bool debugMode = debugData->debugMode;
258
259     LogInfo("[DEBUG_MODE] Widget is launched in " <<
260             (debugMode ? "DEBUG" : "RETAIL") <<
261             " mode.");
262
263     if (debugMode == true) {
264         // In WAC widget, only test widgets can use web inspector.
265         // In TIZEN widget,
266         // every launched widgets as debug mode can use it.
267         if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_WAC20) {
268             bool developerMode =
269                 WRT::CoreModuleSingleton::Instance().developerMode();
270             //This code will be activated
271             //after WAC test certificate is used by SDK
272             //bool isTestWidget = view->m_widgetModel->IsTestWidget.Get();
273             //if(!isTestWidget)
274             //{
275             //    LogInfo("This is not WAC Test Widget");
276             //    break;
277             //}
278             if (!developerMode) {
279                 LogInfo("This is not WAC Developer Mode");
280                 debugMode = false;
281             }
282         }
283     }
284     return debugMode;
285 }
286
287 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
288 {
289     LogDebug("Executing next step");
290     NextStep();
291 }
292
293 void WrtClient::initStep()
294 {
295     LogDebug("");
296     if (WRT::CoreModuleSingleton::Instance().Init()) {
297         m_initialized = true;
298     } else {
299         m_returnStatus = ReturnStatus::Failed;
300         SwitchToStep(&WrtClient::shutdownStep);
301     }
302
303     // ecore_event_jobs are processed sequentially without concession to
304     // other type events. To give a chance of execute to other events,
305     // ecore_timer_add was used.
306     DPL::Event::ControllerEventHandler<NextStepEvent>::PostTimedEvent(
307         NextStepEvent(), 0.001);
308 }
309
310 bool WrtClient::checkWACTestCertififedWidget()
311 {
312     // WAC Waikiki Beta Release Core Specification: Widget Runtime
313     // 10 Dec 2010
314     //
315     // WR-4710 The WRT MUST enable debug functions only for WAC test widgets
316     // i.e. the functions must not be usable for normal WAC widgets, even when
317     // a WAC test widget is executing.
318     ADD_PROFILING_POINT("DeveloperModeCheck", "start");
319     Assert(!!m_dao);
320     // WAC test widget
321     // A widget signed with a WAC-issued test certificate as described in
322     // Developer Mode.
323
324     bool developerWidget = m_dao->isTestWidget();
325     bool developerMode = WRT::CoreModuleSingleton::Instance().developerMode();
326
327     LogDebug("Is WAC test widget: " << developerWidget);
328     LogDebug("Is developer Mode: " << developerMode);
329
330     if (developerWidget) {
331         if (!developerMode) {
332             LogError("WAC test certified developer widget is needed for " <<
333                      "developer mode");
334             return false;
335         } else {
336             //TODO: WR-4660 (show popup about developer widget
337             //      during launch
338             LogInfo("POPUP: THIS IS TEST WIDGET!");
339         }
340     }
341     ADD_PROFILING_POINT("DeveloperModeCheck", "stop");
342     return true;
343 }
344
345 void WrtClient::loadFinishCallback(Evas_Object* webview)
346 {
347     ADD_PROFILING_POINT("loadFinishCallback", "start");
348     SDKDebugData* debug = new SDKDebugData;
349     debug->debugMode = m_debugMode;
350     debug->pid = new unsigned long(getpid());
351
352     LogInfo("Post result of launch");
353
354     // Start inspector server, if current mode is debugger mode.
355     // In the WK2 case, ewk_view_inspector_server_start should
356     // be called after WebProcess is created.
357     if (checkDebugMode(debug)) {
358         debug->portnum =
359             ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
360         if (debug->portnum == 0) {
361             LogWarning("Failed to get portnum");
362         } else {
363             LogInfo("Assigned port number for inspector : "
364                     << debug->portnum);
365         }
366     } else {
367         LogDebug("Debug mode is disabled");
368     }
369
370     //w3c packaging test debug (message on 4>)
371     const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
372     if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
373         FILE* doutput = fdopen(4, "w");
374         fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
375         fclose(doutput);
376     }
377
378     if (webview) {
379         LogDebug("Launch succesfull");
380
381         m_launched = true;
382         m_initializing = false;
383         setlinebuf(stdout);
384         ADD_PROFILING_POINT("loadFinishCallback", "stop");
385         printf("launched\n");
386         fflush(stdout);
387     } else {
388         printf("failed\n");
389
390         m_returnStatus = ReturnStatus::Failed;
391         //shutdownStep
392         DPL::Event::ControllerEventHandler<NextStepEvent>::
393             PostEvent(NextStepEvent());
394     }
395
396     if (debug->debugMode) {
397         LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
398         union sigval sv;
399         /* send real time signal with result to wrt-launcher */
400         if (webview) {
401             LogDebug("userData->portnum : " << debug->portnum);
402             sv.sival_int = debug->portnum;
403         } else {
404             sv.sival_int = -1;
405         }
406         sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
407     }
408
409     ApplicationDataSingleton::Instance().freeBundle();
410
411     LogDebug("Cleaning wrtClient launch resources...");
412     delete debug->pid;
413     delete debug;
414 }
415
416 void WrtClient::progressFinishCallback()
417 {
418     m_splashScreen->stopSplashScreen();
419 }
420
421 void WrtClient::webkitExitCallback()
422 {
423     LogDebug("window close called, terminating app");
424     SwitchToStep(&WrtClient::shutdownStep);
425     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
426         NextStepEvent());
427 }
428
429 void WrtClient::webCrashCallback()
430 {
431     LogError("webProcess crashed");
432     SwitchToStep(&WrtClient::shutdownStep);
433     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
434         NextStepEvent());
435 }
436
437 void WrtClient::launchStep()
438 {
439     ADD_PROFILING_POINT("launchStep", "start");
440     LogDebug("Launching widget ...");
441
442     ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
443     m_widget = WRT::CoreModuleSingleton::Instance()
444             .getRunnableWidgetObject(m_tizenId);
445     ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
446
447     if (!m_widget) {
448         LogError("RunnableWidgetObject is NULL, stop launchStep");
449         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
450             NextStepEvent());
451         return;
452     }
453
454     if (m_widgetState == WidgetState_Running) {
455         LogWarning("Widget already running, stop launchStep");
456         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
457             NextStepEvent());
458         return;
459     }
460
461     if (m_widgetState == WidgetState_Authorizing) {
462         LogWarning("Widget already authorizing, stop launchStep");
463         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
464             NextStepEvent());
465         return;
466     }
467
468     m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
469     DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
470     if (!defloc.IsNull()) {
471         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
472             *defloc);
473     }
474
475     // For localizationsetting not changed on widget running
476     //LocalizationSetting::SetLanguageChangedCallback(
477     //        languageChangedCallback, this);
478
479     ADD_PROFILING_POINT("CreateWindow", "start");
480     m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()),
481                                       true));
482     ADD_PROFILING_POINT("CreateWindow", "stop");
483
484     WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
485     ADD_PROFILING_POINT("Create splash screen", "start");
486     m_splashScreen.reset(
487         new SplashScreenSupport(m_windowData->m_win));
488     if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
489         m_splashScreen->startSplashScreen();
490         cbs->progressFinish = DPL::MakeDelegate(
491                 this,
492                 &WrtClient::
493                     progressFinishCallback);
494     }
495     ADD_PROFILING_POINT("Create splash screen", "stop");
496     DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
497     if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
498             m_windowData->m_win, s_ewk_context))
499     {
500         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
501             NextStepEvent());
502         return;
503     }
504     //you can't show window with splash screen before PrepareView
505     //ewk_view_add_with_context() in viewLogic breaks window
506
507     m_windowData->init();
508
509     WrtDB::WidgetLocalizedInfo localizedInfo =
510         W3CFileLocalization::getLocalizedInfo(m_dao);
511     std::string name = "";
512     if (!(localizedInfo.name.IsNull())) {
513         name = DPL::ToUTF8String(*(localizedInfo.name));
514     }
515     elm_win_title_set(m_windowData->m_win, name.c_str());
516     evas_object_show(m_windowData->m_win);
517     initializeWindowModes();
518     connectElmCallback();
519
520     if (!checkWACTestCertififedWidget()) {
521         LogWarning("WAC Certificate failed, stop launchStep");
522         return;
523     }
524
525     m_widgetState = WidgetState_Authorizing;
526     if (!m_widget->CheckBeforeLaunch()) {
527         LogError("CheckBeforeLaunch failed, stop launchStep");
528         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
529             NextStepEvent());
530         return;
531     }
532     LogInfo("Widget launch accepted. Entering running state");
533     m_widgetState = WidgetState_Running;
534
535     cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
536     cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
537     cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
538     cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
539     cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
540     cbs->toggleFullscreen = DPL::MakeDelegate(
541             m_windowData.get(), &WindowData::toggleFullscreen);
542
543     m_widget->SetUserDelegates(cbs);
544     m_widget->Show();
545     m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
546     ADD_PROFILING_POINT("launchStep", "stop");
547 }
548
549 void WrtClient::initializeWindowModes()
550 {
551     Assert(m_windowData);
552     Assert(m_dao);
553     auto windowModes = m_dao->getWindowModes();
554     bool fullscreen = false;
555     bool backbutton = false;
556     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
557         WidgetSettings widgetSettings;
558         m_dao->getWidgetSettings(widgetSettings);
559         WidgetSettingList settings(widgetSettings);
560         backbutton =
561             (settings.getBackButtonPresence() == BackButton_Enable);
562     }
563
564     FOREACH(it, windowModes)
565     {
566         std::string viewMode = DPL::ToUTF8String(*it);
567         if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
568             fullscreen = true;
569             break;
570         } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
571             break;
572         }
573     }
574
575     m_windowData->setViewMode(fullscreen,
576                               backbutton);
577 }
578
579 void WrtClient::backButtonCallback(void* data,
580                                    Evas_Object * /*obj*/,
581                                    void * /*event_info*/)
582 {
583     LogInfo("BackButtonCallback");
584     Assert(data);
585
586     WrtClient* This = static_cast<WrtClient*>(data);
587
588     This->m_widget->Backward();
589 }
590
591 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
592 {
593     LogInfo("appcoreLowMemoryCallback");
594     //WrtClient* This = static_cast<WrtClient*>(data);
595
596     // TODO call RunnableWidgetObject API regarding low memory
597     // The API should be implemented
598
599     return 0;
600 }
601
602 void WrtClient::connectElmCallback()
603 {
604     Assert(m_windowData);
605     Assert(m_dao);
606     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
607         WidgetSettings widgetSettings;
608         m_dao->getWidgetSettings(widgetSettings);
609         WidgetSettingList settings(widgetSettings);
610         if (settings.getBackButtonPresence() == BackButton_Enable) {
611             m_windowData->addFloatBackButtonCallback(
612                 "clicked",
613                 &WrtClient::backButtonCallback,
614                 this);
615         }
616
617         WidgetSettingScreenLock rotationValue = settings.getRotationValue();
618         if (rotationValue == Screen_Portrait) {
619             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
620             ewk_view_orientation_send(m_widget->GetCurrentWebview(), 0);
621         } else if (rotationValue == Screen_Landscape) {
622             elm_win_rotation_with_resize_set(m_windowData->m_win, 270);
623             ewk_view_orientation_send(m_widget->GetCurrentWebview(), 90);
624         } else {
625             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
626             ewk_view_orientation_send(m_widget->GetCurrentWebview(), 0);
627         }
628     }
629 }
630
631 void WrtClient::setLayout(Evas_Object* newBuffer)
632 {
633     LogDebug("add new webkit buffer to window");
634     Assert(newBuffer);
635
636     elm_object_part_content_set(m_windowData->m_user_layout,
637                                 ELM_SWALLOW_CONTENT,
638                                 newBuffer);
639
640     evas_object_show(newBuffer);
641 }
642
643 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
644 {
645     LogDebug("remove current webkit buffer from window");
646     Assert(currentBuffer);
647     evas_object_hide(currentBuffer);
648
649     elm_object_part_content_unset(m_windowData->m_user_layout,
650                                   ELM_SWALLOW_CONTENT);
651 }
652
653 void WrtClient::shutdownStep()
654 {
655     LogDebug("Closing Wrt connection ...");
656
657     if (m_widget && m_widgetState) {
658         m_widgetState = WidgetState_Stopped;
659         m_widget->Hide();
660         m_widget.reset();
661         ewk_context_delete(s_ewk_context);
662         WRT::CoreModuleSingleton::Instance().Terminate();
663     }
664     if (m_initialized) {
665         m_initialized = false;
666     }
667     m_windowData.reset();
668     Quit();
669 }
670
671 int WrtClient::languageChangedCallback(void *data)
672 {
673     LogDebug("Language Changed");
674     if (!data) {
675         return 0;
676     }
677     WrtClient* wrtClient = static_cast<WrtClient*>(data);
678     if (!(wrtClient->m_dao)) {
679         return 0;
680     }
681
682     // reset function fetches system locales and recreates language tags
683     LanguageTagsProviderSingleton::Instance().resetLanguageTags();
684     // widget default locales are added to language tags below
685     DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
686     if (!defloc.IsNull()) {
687         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
688             *defloc);
689     }
690
691     if (wrtClient->m_launched &&
692         wrtClient->m_widgetState != WidgetState_Stopped)
693     {
694         wrtClient->m_widget->ReloadStartPage();
695     }
696     return 0;
697 }
698
699 void WrtClient::Quit()
700 {
701     ewk_shutdown();
702     DPL::Application::Quit();
703 }
704
705 int main(int argc,
706          char *argv[])
707 {
708     UNHANDLED_EXCEPTION_HANDLER_BEGIN
709     {
710         ADD_PROFILING_POINT("main-entered", "point");
711
712         // Set log tagging
713         DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
714
715         // set evas backend type
716         if (!getenv("ELM_ENGINE")) {
717             if (!setenv("ELM_ENGINE", "gl", 1)) {
718                 LogDebug("Enable backend");
719             }
720         } else {
721             LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
722         }
723
724     #ifndef TIZEN_PUBLIC
725         setenv("COREGL_FASTPATH", "1", 1);
726     #endif
727         setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
728         setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
729         setenv("ELM_IMAGE_CACHE", "0", 1);
730
731         // This code is to fork a web process without exec.
732         std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
733
734         if (!tizenId.empty()) {
735             LogDebug("Launching by fork mode");
736             // Language env setup
737             appcore_set_i18n("wrt-client", NULL);
738             ewk_init();
739             ewk_set_arguments(argc, argv);
740             setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
741             s_ewk_context = ewk_context_new_with_injected_bundle_path(
742                     BUNDLE_PATH);
743
744             // plugin init
745             PluginModuleSupport::init(s_ewk_context, tizenId);
746         }
747
748         // Output on stdout will be flushed after every newline character,
749         // even if it is redirected to a pipe. This is useful for running
750         // from a script and parsing output.
751         // (Standard behavior of stdlib is to use full buffering when
752         // redirected to a pipe, which means even after an end of line
753         // the output may not be flushed).
754         setlinebuf(stdout);
755
756         WrtClient app(argc, argv);
757
758         ADD_PROFILING_POINT("Before appExec", "point");
759         int ret = app.Exec();
760         LogDebug("App returned: " << ret);
761         ret = app.getReturnStatus();
762         LogDebug("WrtClient returned: " << ret);
763         return ret;
764     }
765     UNHANDLED_EXCEPTION_HANDLER_END
766 }