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