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