Revert Back button
[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 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 =
254                 GlobalLogicSingleton::Instance().GetGlobalModel()
255                 ->DeveloperMode.Get();
256             //This code will be activated
257             //after WAC test certificate is used by SDK
258             //bool isTestWidget = view->m_widgetModel->IsTestWidget.Get();
259             //if(!isTestWidget)
260             //{
261             //    LogInfo("This is not WAC Test Widget");
262             //    break;
263             //}
264             if (!developerMode) {
265                 LogInfo("This is not WAC Developer Mode");
266                 debugMode = false;
267             }
268         }
269     }
270     return debugMode;
271 }
272
273 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
274 {
275     LogDebug("Executing next step");
276     NextStep();
277 }
278
279 void WrtClient::initStep()
280 {
281     LogDebug("");
282     if (WRT::CoreModuleSingleton::Instance().Init()) {
283         m_initialized = true;
284     } else {
285         m_returnStatus = ReturnStatus::Failed;
286         SwitchToStep(&WrtClient::shutdownStep);
287     }
288
289     // ecore_event_jobs are processed sequentially without concession to
290     // other type events. To give a chance of execute to other events,
291     // ecore_timer_add was used.
292     DPL::Event::ControllerEventHandler<NextStepEvent>::PostTimedEvent(
293             NextStepEvent(),0.001);
294 }
295
296 bool WrtClient::checkWACTestCertififedWidget()
297 {
298     // WAC Waikiki Beta Release Core Specification: Widget Runtime
299     // 10 Dec 2010
300     //
301     // WR-4710 The WRT MUST enable debug functions only for WAC test widgets
302     // i.e. the functions must not be usable for normal WAC widgets, even when
303     // a WAC test widget is executing.
304     ADD_PROFILING_POINT("DeveloperModeCheck", "start");
305     Assert(!!m_dao);
306     // WAC test widget
307     // A widget signed with a WAC-issued test certificate as described in
308     // Developer Mode.
309
310     bool developerWidget = m_dao->isTestWidget();
311     bool developerMode =
312         GlobalLogicSingleton::Instance().GetGlobalModel()->DeveloperMode.Get();
313
314     LogDebug("Is WAC test widget: " << developerWidget);
315     LogDebug("Is developer Mode: " << developerMode);
316
317     if (developerWidget) {
318         if(!developerMode)
319         {
320             LogError("WAC test certified developer widget is needed for " <<
321                     "developer mode");
322             return false;
323         }else{
324             //TODO: WR-4660 (show popup about developer widget
325             //      during launch
326             LogInfo("POPUP: THIS IS TEST WIDGET!");
327         }
328     }
329     ADD_PROFILING_POINT("DeveloperModeCheck", "stop");
330     return true;
331 }
332
333 void WrtClient::loadFinishCallback(Evas_Object* webview)
334 {
335     ADD_PROFILING_POINT("loadFinishCallback", "start");
336     SDKDebugData* debug = new SDKDebugData;
337     debug->debugMode = m_debugMode;
338     debug->pid = new unsigned long(getpid());
339
340     LogInfo("Post result of launch");
341
342     // Start inspector server, if current mode is debugger mode.
343     // In the WK2 case, ewk_view_inspector_server_start should
344     // be called after WebProcess is created.
345     if (checkDebugMode(debug))
346     {
347         debug->portnum =
348             ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
349         if (debug->portnum == 0) {
350             LogWarning("Failed to get portnum");
351         } else {
352             LogInfo("Assigned port number for inspector : "
353                     << debug->portnum);
354         }
355     } else {
356         LogDebug("Debug mode is disabled");
357     }
358
359     //w3c packaging test debug (message on 4>)
360     const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
361     if(makeScreen != NULL && strcmp(makeScreen, "1") == 0)
362     {
363         FILE* doutput = fdopen(4, "w");
364         fprintf(doutput,"didFinishLoadForFrameCallback: ready\n");
365         fclose(doutput);
366     }
367
368     if (webview) {
369         LogDebug("Launch succesfull");
370
371         m_launched = true;
372         m_initializing = false;
373         setlinebuf(stdout);
374         ADD_PROFILING_POINT("loadFinishCallback", "stop");
375         printf("launched\n");
376         fflush(stdout);
377     } else {
378         printf("failed\n");
379
380         m_returnStatus = ReturnStatus::Failed;
381         //shutdownStep
382         DPL::Event::ControllerEventHandler<NextStepEvent>::
383                 PostEvent(NextStepEvent());
384     }
385
386     if(debug->debugMode)
387     {
388         LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
389         union sigval sv;
390         /* send real time signal with result to wrt-launcher */
391         if(webview) {
392             LogDebug("userData->portnum : " << debug->portnum);
393             sv.sival_int = debug->portnum;
394         } else {
395            sv.sival_int = -1;
396         }
397         sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
398     }
399
400     ApplicationDataSingleton::Instance().freeBundle();
401
402     LogDebug("Cleaning wrtClient launch resources...");
403     delete debug->pid;
404     delete debug;
405 }
406
407 void WrtClient::progressFinishCallback()
408 {
409     m_splashScreen->stopSplashScreen();
410 }
411
412 void WrtClient::webkitExitCallback()
413 {
414     LogDebug("window close called, terminating app");
415     SwitchToStep(&WrtClient::shutdownStep);
416     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
417             NextStepEvent());
418 }
419
420 void WrtClient::webCrashCallback()
421 {
422     LogError("webProcess crashed");
423     SwitchToStep(&WrtClient::shutdownStep);
424     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
425             NextStepEvent());
426 }
427
428
429 void WrtClient::launchStep()
430 {
431     ADD_PROFILING_POINT("launchStep", "start");
432     LogDebug("Launching widget ...");
433
434     ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
435     m_widget = WRT::CoreModuleSingleton::Instance()
436                     .getRunnableWidgetObject(m_tizenId);
437     ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
438
439     if (!m_widget) {
440         LogError("RunnableWidgetObject is NULL, stop launchStep");
441         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
442                     NextStepEvent());
443         return;
444     }
445
446     if (m_widgetState == WidgetState_Running) {
447         LogWarning("Widget already running, stop launchStep");
448         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
449                     NextStepEvent());
450         return;
451     }
452
453     if (m_widgetState == WidgetState_Authorizing) {
454         LogWarning("Widget already authorizing, stop launchStep");
455         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
456                     NextStepEvent());
457         return;
458     }
459
460     m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
461     DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
462     if(!defloc.IsNull())
463     {
464         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
465     }
466
467     LocalizationSetting::SetLanguageChangedCallback(
468             languageChangedCallback, this);
469
470     ADD_PROFILING_POINT("CreateWindow", "start");
471     m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid())));
472     ADD_PROFILING_POINT("CreateWindow", "stop");
473
474     WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
475     ADD_PROFILING_POINT("Create splash screen", "start");
476     m_splashScreen.reset(
477             new SplashScreenSupport(m_windowData->m_win));
478     if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
479         m_splashScreen->startSplashScreen();
480         cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
481     }
482     ADD_PROFILING_POINT("Create splash screen", "stop");
483     DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
484     m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
485             m_windowData->m_win);
486     //you can't show window with splash screen before PrepareView
487     //ewk_view_add_with_context() in viewLogic breaks window
488
489     WrtDB::WidgetLocalizedInfo localizedInfo =
490         W3CFileLocalization::getLocalizedInfo(m_dao);
491     std:: string name = "";
492     if (!(localizedInfo.name.IsNull())) {
493         name = DPL::ToUTF8String(*(localizedInfo.name));
494     }
495     elm_win_title_set(m_windowData->m_win, name.c_str());
496     evas_object_show(m_windowData->m_win);
497     initializeWindowModes();
498     connectElmCallback();
499
500     if (!checkWACTestCertififedWidget())
501     {
502         LogWarning("WAC Certificate failed, stop launchStep");
503         return;
504     }
505
506     m_widgetState = WidgetState_Authorizing;
507     if (!m_widget->CheckBeforeLaunch()) {
508         LogError("CheckBeforeLaunch failed, stop launchStep");
509         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
510                     NextStepEvent());
511         return;
512     }
513     LogInfo("Widget launch accepted. Entering running state");
514     m_widgetState = WidgetState_Running;
515
516     cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
517     cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
518     cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
519     cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
520     cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
521     cbs->toggleFullscreen = DPL::MakeDelegate(m_windowData.get(), &WindowData::toggleFullscreen);
522
523     m_widget->SetUserDelegates(cbs);
524     m_widget->Show();
525     m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
526     ADD_PROFILING_POINT("launchStep", "stop");
527 }
528
529 void WrtClient::initializeWindowModes()
530 {
531     Assert(m_windowData);
532     Assert(m_dao);
533     auto windowModes = m_dao->getWindowModes();
534     bool fullscreen = false;
535     bool backbutton = false;
536      if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
537          WidgetSettings widgetSettings;
538          m_dao->getWidgetSettings(widgetSettings);
539          WidgetSettingList settings(widgetSettings);
540         backbutton =
541             (settings.getBackButtonPresence() == BackButton_Enable);
542      }
543
544
545     FOREACH(it, windowModes)
546     {
547         std::string viewMode = DPL::ToUTF8String(*it);
548         if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
549             fullscreen = true;
550             break;
551         } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
552             break;
553         }
554     }
555
556     WrtDB::WidgetLocalizedInfo localizedInfo =
557             W3CFileLocalization::getLocalizedInfo(m_dao);
558     std::string name = "";
559     if (!(localizedInfo.name.IsNull())) {
560         name = DPL::ToUTF8String(*(localizedInfo.name));
561     }
562     LogInfo("initializeWindowModes " << m_debugMode);
563 #if 1
564     m_windowData->m_debugMode = FALSE;
565 #else
566     if(m_debugMode) {
567         m_windowData->m_debugMode = TRUE;
568     }
569     else {
570         m_windowData->m_debugMode = FALSE;
571     }
572 #endif
573     WindowData::CtxMenuItems ctxMenuItems;
574
575     WindowData::CtxMenuItem ctxMenuBackword;
576     ctxMenuBackword.label = WRT_OPTION_LABEL_BACKWARD;
577     ctxMenuBackword.icon = WRT_OPTION_ICON_BACKWARD;
578     ctxMenuBackword.callback = backwardCallback;
579     ctxMenuBackword.data = this;
580     ctxMenuItems.push_back(ctxMenuBackword);
581
582     WindowData::CtxMenuItem ctxMenuReload;
583     ctxMenuReload.label = WRT_OPTION_LABEL_RELOAD;
584     ctxMenuReload.icon = WRT_OPTION_ICON_RELOAD;
585     ctxMenuReload.callback = reloadCallback;
586     ctxMenuReload.data = this;
587     ctxMenuItems.push_back(ctxMenuReload);
588
589     WindowData::CtxMenuItem ctxMenuForward;
590     ctxMenuForward.label = WRT_OPTION_LABEL_FORWARD;
591     ctxMenuForward.icon = WRT_OPTION_ICON_FORWARD;
592     ctxMenuForward.callback = forwardCallback;
593     ctxMenuForward.data = this;
594     ctxMenuItems.push_back(ctxMenuForward);
595
596     m_windowData->setViewMode(name.c_str(),
597             fullscreen,
598             backbutton,
599             ctxMenuItems);
600 }
601
602 void WrtClient::backButtonCallback(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 }
613
614 void WrtClient::backwardCallback(void *data,
615         Evas_Object */*obj*/,
616         void */*event_info*/)
617 {
618     LogInfo("BackButtonCallback");
619     Assert(data);
620
621     WrtClient* This = static_cast<WrtClient*>(data);
622
623     This->m_widget->Backward();
624     This->m_windowData->initFullViewMode();
625 }
626
627 void WrtClient::reloadCallback(void *data,
628         Evas_Object */*obj*/,
629         void */*event_info*/)
630 {
631     LogInfo("reloadCallback");
632
633     WrtClient* This = static_cast<WrtClient*>(data);
634
635     This->m_widget->Reload();
636     This->m_windowData->initFullViewMode();
637 }
638
639 void WrtClient::forwardCallback(void *data,
640         Evas_Object */*obj*/,
641         void */*event_info*/)
642 {
643     LogInfo("forwardCallback");
644
645     WrtClient* This = static_cast<WrtClient*>(data);
646
647     This->m_widget->Forward();
648     This->m_windowData->initFullViewMode();
649 }
650
651
652 void WrtClient::connectElmCallback()
653 {
654     Assert(m_windowData);
655     Assert(m_dao);
656     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
657         WidgetSettings widgetSettings;
658         m_dao->getWidgetSettings(widgetSettings);
659         WidgetSettingList settings(widgetSettings);
660         if (settings.getBackButtonPresence() == BackButton_Enable) {
661             m_windowData->addFloatBackButtonCallback(
662             "clicked",
663             &WrtClient::backButtonCallback,
664             this);
665         }
666
667         WidgetSettingScreenLock rotationValue = settings.getRotationValue();
668         if (rotationValue == Screen_Portrait) {
669             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
670         } else if (rotationValue == Screen_Landscape) {
671             elm_win_rotation_with_resize_set(m_windowData->m_win, 270);
672         } else {
673             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
674         }
675     }
676 }
677
678 void WrtClient::setLayout(Evas_Object* newBuffer) {
679     LogDebug("add new webkit buffer to window");
680     Assert(newBuffer);
681     elm_object_content_set(m_windowData->m_conformant, newBuffer);
682     evas_object_show(newBuffer);
683     evas_object_focus_set(newBuffer, EINA_TRUE);
684 }
685
686 void WrtClient::unsetLayout(Evas_Object* currentBuffer) {
687     LogDebug("remove current webkit buffer from window");
688     Assert(currentBuffer);
689     evas_object_hide(currentBuffer);
690     elm_object_content_unset(m_windowData->m_conformant);
691 }
692
693 void WrtClient::shutdownStep()
694 {
695     LogDebug("Closing Wrt connection ...");
696     if (m_initialized && m_widget) {
697         m_widgetState = WidgetState_Stopped;
698         m_widget->Hide();
699         m_widget.reset();
700         m_windowData.reset();
701         WRT::CoreModuleSingleton::Instance().Terminate();
702         m_initialized = false;
703     }
704     Quit();
705 }
706
707 int WrtClient::languageChangedCallback(void *data)
708 {
709     LogDebug("Language Changed");
710     if(!data)
711         return 0;
712     WrtClient* wrtClient = static_cast<WrtClient*>(data);
713     if(!(wrtClient->m_dao))
714         return 0;
715
716     // reset function fetches system locales and recreates language tags
717     LanguageTagsProviderSingleton::Instance().resetLanguageTags();
718     // widget default locales are added to language tags below
719     DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
720     if(!defloc.IsNull())
721     {
722         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
723     }
724
725     if (wrtClient->m_launched &&
726             wrtClient->m_widgetState != WidgetState_Stopped) {
727         wrtClient->m_widget->ReloadStartPage();
728     }
729     return 0;
730 }
731
732 void WrtClient::Quit()
733 {
734     ewk_shutdown();
735     DPL::Application::Quit();
736 }
737
738 int main(int argc,
739          char *argv[])
740 {
741     ADD_PROFILING_POINT("main-entered", "point");
742
743     // Output on stdout will be flushed after every newline character,
744     // even if it is redirected to a pipe. This is useful for running
745     // from a script and parsing output.
746     // (Standard behavior of stdlib is to use full buffering when
747     // redirected to a pipe, which means even after an end of line
748     // the output may not be flushed).
749     setlinebuf(stdout);
750
751     // set evas backend type
752     if (!getenv("ELM_ENGINE")) {
753         if (!setenv("ELM_ENGINE", "gl", 1)) {
754                 LogDebug("Enable backend");
755         }
756     }
757     else {
758         LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
759     }
760
761 #ifndef TIZEN_PUBLIC
762     setenv("COREGL_FASTPATH", "1", 1);
763 #endif
764     setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
765     setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
766     setenv("ELM_IMAGE_CACHE", "0", 1);
767
768     // Set log tagging
769     DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
770
771     WrtClient app(argc, argv);
772
773     ADD_PROFILING_POINT("Before appExec", "point");
774     int ret = app.Exec();
775     LogDebug("App returned: " << ret);
776     ret = app.getReturnStatus();
777     LogDebug("WrtClient returned: " << ret);
778     return ret;
779 }