Change action of appservice in case that serviced page is same to current page of...
[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 }
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     m_widgetState = WidgetState_Running;
86 }
87
88
89 void WrtClient::OnPause()
90 {
91     LogDebug("On pause");
92
93     if (m_widgetState != WidgetState_Running) {
94         LogWarning("Widget is not running to be suspended");
95         return;
96     }
97     m_widget->Suspend();
98     m_widgetState = WidgetState_Suspended;
99 }
100
101 void WrtClient::OnReset(bundle *b)
102 {
103     LogDebug("OnReset");
104     // bundle argument is freed after OnReset() is returned
105     // So bundle duplication is needed
106     ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
107
108     if (true == m_initializing) {
109         LogDebug("can not handle reset event");
110         return;
111     }
112     if (true == m_launched) {
113         if (m_widgetState == WidgetState_Stopped) {
114             LogError("Widget is not running to be reset");
115             return;
116         }
117         m_widget->Reset();
118         m_widgetState = WidgetState_Running;
119     } else {
120         if (true == checkArgument())
121         {
122             setStep();
123         }
124         else
125         {
126             showHelpAndQuit();
127         }
128     }
129 }
130
131 void WrtClient::OnTerminate()
132 {
133     LogDebug("Wrt Shutdown now");
134     shutdownStep();
135 }
136
137 void WrtClient::showHelpAndQuit()
138 {
139     printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
140            "launch widgets.\n"
141            "Mandatory arguments to long options are mandatory for short "
142            "options too.\n"
143            "  -h,    --help                                 show this help\n"
144            "  -l,    --launch                               "
145            "launch widget with given tizen ID\n"
146            "  -t,    --tizen                                "
147            "launch widget with given tizen ID\n"
148            "\n");
149
150     Quit();
151 }
152
153 bool WrtClient::checkArgument()
154 {
155     LogInfo("checkArgument");
156
157     std::string arg = m_argv[0];
158
159     if (arg.empty()) {
160         return false;
161     }
162
163     if (arg.find("wrt-client") != std::string::npos)
164     {
165         if (m_argc <= 1) {
166             return false;
167         }
168
169         arg = m_argv[1];
170
171         if (arg == "-h" || arg == "--help") {
172             // Just show help
173             return false;
174         } else if (arg == "-l" || arg == "--launch" ||
175                 arg == "-t" || arg == "--tizen") {
176             if (m_argc != 3) {
177                 return false;
178             }
179             m_tizenId = std::string(m_argv[2]);
180         } else {
181             return false;
182         }
183     } else {
184         size_t pos = arg.find_last_of('/');
185
186         if (pos != std::string::npos) {
187             arg = arg.erase(0, pos + 1);
188         }
189
190         // Launch widget based on application basename
191         m_tizenId = arg;
192         LogDebug("Tizen id: " << m_tizenId);
193     }
194
195     return true;
196 }
197
198 void WrtClient::setStep()
199 {
200     LogInfo("setStep");
201
202     AddStep(&WrtClient::initStep);
203
204     setSdkLauncherDebugData();
205
206     AddStep(&WrtClient::launchStep);
207     AddStep(&WrtClient::shutdownStep);
208
209     m_initializing = true;
210
211     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
212 }
213
214 void WrtClient::setSdkLauncherDebugData()
215 {
216     LogDebug("setSdkLauncherDebugData");
217
218     /* check bundle from sdk launcher */
219     bundle *bundleFromSdkLauncher;
220     bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
221     const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
222     const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
223     if (bundle_debug != NULL && bundle_pid != NULL) {
224         if (strcmp(bundle_debug, "true") == 0) {
225             m_debugMode = true;
226             m_sdkLauncherPid = atoi(bundle_pid);
227         } else {
228             m_debugMode = false;
229         }
230     }
231     bundle_free(bundleFromSdkLauncher);
232 }
233
234 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
235 {
236     LogError("Checking for debug mode");
237     Assert(m_dao);
238
239     bool debugMode = debugData->debugMode;
240
241     LogInfo("[DEBUG_MODE] Widget is launched in " <<
242             (debugMode ? "DEBUG" : "RETAIL") <<
243             " mode.");
244
245     if (debugMode == true) {
246         // In WAC widget, only test widgets can use web inspector.
247         // In TIZEN widget,
248         // every launched widgets as debug mode can use it.
249         if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_WAC20)
250         {
251             bool developerMode =
252                 GlobalLogicSingleton::Instance().GetGlobalModel()
253                 ->DeveloperMode.Get();
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 =
310         GlobalLogicSingleton::Instance().GetGlobalModel()->DeveloperMode.Get();
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(bool success)
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 (success) {
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: "
387                 << m_sdkLauncherPid << ", status: " << success);
388         union sigval sv;
389         /* send real time signal with result to wrt-launcher */
390         if(success)
391         {
392             LogDebug("userData->portnum : " << debug->portnum);
393             sv.sival_int = debug->portnum;
394         }
395         else
396         {
397            sv.sival_int = -1;
398         }
399         sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
400     }
401
402     ApplicationDataSingleton::Instance().freeBundle();
403
404     LogDebug("Cleaning wrtClient launch resources...");
405     delete debug->pid;
406     delete debug;
407 }
408
409 void WrtClient::progressFinishCallback()
410 {
411     m_splashScreen->stopSplashScreen();
412 }
413
414 void WrtClient::windowCloseCallback()
415 {
416     LogDebug("window close called, terminating app");
417     SwitchToStep(&WrtClient::shutdownStep);
418     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
419             NextStepEvent());
420 }
421
422 void WrtClient::webCrashCallback()
423 {
424     LogError("webProcess crashed");
425     SwitchToStep(&WrtClient::shutdownStep);
426     DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
427             NextStepEvent());
428 }
429
430
431 void WrtClient::launchStep()
432 {
433     ADD_PROFILING_POINT("launchStep", "start");
434     LogDebug("Launching widget ...");
435
436     ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
437     m_widget = WRT::CoreModuleSingleton::Instance()
438                     .getRunnableWidgetObject(m_tizenId);
439     ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
440
441     if (!m_widget) {
442         LogError("RunnableWidgetObject is NULL, stop launchStep");
443         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
444                     NextStepEvent());
445         return;
446     }
447
448     if (m_widgetState == WidgetState_Running) {
449         LogWarning("Widget already running, stop launchStep");
450         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
451                     NextStepEvent());
452         return;
453     }
454
455     if (m_widgetState == WidgetState_Authorizing) {
456         LogWarning("Widget already authorizing, stop launchStep");
457         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
458                     NextStepEvent());
459         return;
460     }
461
462     m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
463     DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
464     if(!defloc.IsNull())
465     {
466         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
467     }
468
469     LocalizationSetting::SetLanguageChangedCallback(
470             languageChangedCallback, this);
471
472     ADD_PROFILING_POINT("CreateWindow", "start");
473     m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid())));
474     ADD_PROFILING_POINT("CreateWindow", "stop");
475
476     WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
477     ADD_PROFILING_POINT("Create splash screen", "start");
478     m_splashScreen.reset(
479             new SplashScreenSupport(m_windowData->m_win));
480     if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
481         m_splashScreen->startSplashScreen();
482         cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
483     }
484     ADD_PROFILING_POINT("Create splash screen", "stop");
485     DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
486     m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
487             m_windowData->m_win);
488     //you can't show window with splash screen before PrepareView
489     //ewk_view_add_with_context() in viewLogic breaks window
490
491     WrtDB::WidgetLocalizedInfo localizedInfo =
492         W3CFileLocalization::getLocalizedInfo(m_dao);
493     std:: string name = "";
494     if (!(localizedInfo.name.IsNull())) {
495         name = DPL::ToUTF8String(*(localizedInfo.name));
496     }
497     elm_win_title_set(m_windowData->m_win, name.c_str());
498     evas_object_show(m_windowData->m_win);
499     initializeWindowModes();
500     connectElmCallback();
501
502     if (!checkWACTestCertififedWidget())
503     {
504         LogWarning("WAC Certificate failed, stop launchStep");
505         return;
506     }
507
508     m_widgetState = WidgetState_Authorizing;
509     if (!m_widget->CheckBeforeLaunch()) {
510         LogError("CheckBeforeLaunch failed, stop launchStep");
511         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
512                     NextStepEvent());
513         return;
514     }
515     LogInfo("Widget launch accepted. Entering running state");
516     m_widgetState = WidgetState_Running;
517
518     cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
519     cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
520     cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
521     cbs->windowClose = DPL::MakeDelegate(this, &WrtClient::windowCloseCallback);
522     cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
523     cbs->toggleFullscreen = DPL::MakeDelegate(m_windowData.get(), &WindowData::toggleFullscreen);
524
525     m_widget->SetUserDelegates(cbs);
526     m_widget->Show();
527     ADD_PROFILING_POINT("launchStep", "stop");
528 }
529
530 void WrtClient::initializeWindowModes()
531 {
532     Assert(m_windowData);
533     Assert(m_dao);
534     auto windowModes = m_dao->getWindowModes();
535     bool fullscreen = false;
536     FOREACH(it, windowModes)
537     {
538         std::string viewMode = DPL::ToUTF8String(*it);
539         if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
540             fullscreen = true;
541             break;
542         } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
543             break;
544         }
545     }
546
547     WrtDB::WidgetLocalizedInfo localizedInfo =
548             W3CFileLocalization::getLocalizedInfo(m_dao);
549     std::string name = "";
550     if (!(localizedInfo.name.IsNull())) {
551         name = DPL::ToUTF8String(*(localizedInfo.name));
552     }
553     LogInfo("initializeWindowModes " << m_debugMode);
554 #if 1
555     m_windowData->m_debugMode = FALSE;
556 #else
557     if(m_debugMode) {
558         m_windowData->m_debugMode = TRUE;
559     }
560     else {
561         m_windowData->m_debugMode = FALSE;
562     }
563 #endif
564     WindowData::CtxMenuItems ctxMenuItems;
565
566     WindowData::CtxMenuItem ctxMenuBackword;
567     ctxMenuBackword.label = WRT_OPTION_LABEL_BACKWARD;
568     ctxMenuBackword.icon = WRT_OPTION_ICON_BACKWARD;
569     ctxMenuBackword.callback = backwardCallback;
570     ctxMenuBackword.data = this;
571     ctxMenuItems.push_back(ctxMenuBackword);
572
573     WindowData::CtxMenuItem ctxMenuReload;
574     ctxMenuReload.label = WRT_OPTION_LABEL_RELOAD;
575     ctxMenuReload.icon = WRT_OPTION_ICON_RELOAD;
576     ctxMenuReload.callback = reloadCallback;
577     ctxMenuReload.data = this;
578     ctxMenuItems.push_back(ctxMenuReload);
579
580     WindowData::CtxMenuItem ctxMenuForward;
581     ctxMenuForward.label = WRT_OPTION_LABEL_FORWARD;
582     ctxMenuForward.icon = WRT_OPTION_ICON_FORWARD;
583     ctxMenuForward.callback = forwardCallback;
584     ctxMenuForward.data = this;
585     ctxMenuItems.push_back(ctxMenuForward);
586
587     m_windowData->setViewMode(name.c_str(),
588             fullscreen,
589             ctxMenuItems);
590 }
591
592 void WrtClient::backButtonCallback(void* data,
593                                      Evas_Object * /*obj*/,
594                                      void * /*event_info*/)
595 {
596     LogInfo("BackButtonCallback");
597     Assert(data);
598
599     WrtClient* This = static_cast<WrtClient*>(data);
600
601     This->m_widget->Backward();
602 }
603
604 void WrtClient::backwardCallback(void *data,
605         Evas_Object */*obj*/,
606         void */*event_info*/)
607 {
608     LogInfo("BackButtonCallback");
609     Assert(data);
610
611     WrtClient* This = static_cast<WrtClient*>(data);
612
613     This->m_widget->Backward();
614     This->m_windowData->initFullViewMode();
615 }
616
617 void WrtClient::reloadCallback(void *data,
618         Evas_Object */*obj*/,
619         void */*event_info*/)
620 {
621     LogInfo("reloadCallback");
622
623     WrtClient* This = static_cast<WrtClient*>(data);
624
625     This->m_widget->Reload();
626     This->m_windowData->initFullViewMode();
627 }
628
629 void WrtClient::forwardCallback(void *data,
630         Evas_Object */*obj*/,
631         void */*event_info*/)
632 {
633     LogInfo("forwardCallback");
634
635     WrtClient* This = static_cast<WrtClient*>(data);
636
637     This->m_widget->Forward();
638     This->m_windowData->initFullViewMode();
639 }
640
641
642 void WrtClient::connectElmCallback()
643 {
644     Assert(m_windowData);
645     Assert(m_dao);
646     if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
647         WidgetSettings widgetSettings;
648         m_dao->getWidgetSettings(widgetSettings);
649         WidgetSettingList settings(widgetSettings);
650         WidgetSettingScreenLock rotationValue = settings.getRotationValue();
651         if (rotationValue == Screen_Portrait) {
652             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
653         } else if (rotationValue == Screen_Landscape) {
654             elm_win_rotation_with_resize_set(m_windowData->m_win, 270);
655         } else {
656             elm_win_rotation_with_resize_set(m_windowData->m_win, 0);
657         }
658     }
659 }
660
661 void WrtClient::setLayout(Evas_Object* newBuffer) {
662     LogDebug("add new webkit buffer to window");
663     Assert(newBuffer);
664     elm_object_content_set(m_windowData->m_conformant, newBuffer);
665     evas_object_show(newBuffer);
666     evas_object_focus_set(newBuffer, EINA_TRUE);
667 }
668
669 void WrtClient::unsetLayout(Evas_Object* currentBuffer) {
670     LogDebug("remove current webkit buffer from window");
671     Assert(currentBuffer);
672     evas_object_hide(currentBuffer);
673     elm_object_content_unset(m_windowData->m_conformant);
674 }
675
676 void WrtClient::shutdownStep()
677 {
678     LogDebug("Closing Wrt connection ...");
679     if (m_initialized && m_widget) {
680         m_widgetState = WidgetState_Stopped;
681         m_widget->Hide();
682         m_widget.reset();
683         m_windowData.reset();
684         WRT::CoreModuleSingleton::Instance().Terminate();
685         m_initialized = false;
686     }
687     Quit();
688 }
689
690 int WrtClient::languageChangedCallback(void *data)
691 {
692     LogDebug("Language Changed");
693     if(!data)
694         return 0;
695     WrtClient* wrtClient = static_cast<WrtClient*>(data);
696     if(!(wrtClient->m_dao))
697         return 0;
698
699     // reset function fetches system locales and recreates language tags
700     LanguageTagsProviderSingleton::Instance().resetLanguageTags();
701     // widget default locales are added to language tags below
702     DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
703     if(!defloc.IsNull())
704     {
705         LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
706     }
707
708     if (wrtClient->m_launched &&
709             wrtClient->m_widgetState != WidgetState_Stopped) {
710         wrtClient->m_widget->ReloadStartPage();
711     }
712     return 0;
713 }
714
715 int main(int argc,
716          char *argv[])
717 {
718     ADD_PROFILING_POINT("main-entered", "point");
719
720     // Output on stdout will be flushed after every newline character,
721     // even if it is redirected to a pipe. This is useful for running
722     // from a script and parsing output.
723     // (Standard behavior of stdlib is to use full buffering when
724     // redirected to a pipe, which means even after an end of line
725     // the output may not be flushed).
726     setlinebuf(stdout);
727
728     // set evas backend type
729     if (!getenv("ELM_ENGINE")) {
730         if (setenv("ELM_ENGINE", "gl", 1)) {
731                 LogDebug("Enable backend");
732         }
733     }
734 #ifndef TIZEN_PUBLIC
735     setenv("COREGL_FASTPATH", "1", 1);
736 #endif
737     setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
738     setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
739     setenv("ELM_IMAGE_CACHE", "0", 1);
740
741     // Set log tagging
742     DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
743
744     WrtClient app(argc, argv);
745
746     ADD_PROFILING_POINT("Before appExec", "point");
747     int ret = app.Exec();
748     LogDebug("App returned: " << ret);
749     ret = app.getReturnStatus();
750     LogDebug("WrtClient returned: " << ret);
751     return ret;
752 }