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