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