2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "wrt-client.h"
19 #include <sys/resource.h>
20 #include <appcore-efl.h>
21 #include <appcore-common.h>
25 #include <dpl/log/log.h>
26 #include <dpl/optional_typedefs.h>
27 #include <dpl/exception.h>
28 #include <common/application_data.h>
29 #include <core_module.h>
30 #include <localization_setting.h>
31 #include <widget_deserialize_model.h>
33 #include <dpl/localization/w3c_file_localization.h>
34 #include <dpl/localization/LanguageTagsProvider.h>
35 #include "webkit/bundles/plugin_module_support.h"
36 #include <popup-runner/PopupInvoker.h>
37 #include <prepare_external_storage.h>
40 #include "process_pool.h"
41 #include "menu_db_util.h"
42 #include "launchpad_util.h"
44 //W3C PACKAGING enviroment variable name
45 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
47 // window signal callback
48 const char *EDJE_SHOW_BACKWARD_SIGNAL = "show,backward,signal";
49 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
50 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
51 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
52 const char* const BUNDLE_PATH = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
53 const char* const caCertPath = "/opt/usr/share/certs/ca-certificate.crt";
56 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
57 static Ewk_Context* s_preparedEwkContext = NULL;
58 static WindowData* s_preparedWindowData = NULL;
59 static int app_argc = 0;
60 static char** app_argv = NULL;
63 const int WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE = 0;
64 const int WIN_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE = 270;
65 const int W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE = 0;
66 const int W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE = 90;
69 const char* const HOME = "HOME";
70 const char* const APP_HOME_PATH = "/opt/home/app";
72 WrtClient::WrtClient(int argc, char **argv) :
73 Application(argc, argv, "wrt-client", false),
74 DPL::TaskDecl<WrtClient>(this),
76 m_initializing(false),
81 m_returnStatus(ReturnStatus::Succeeded),
82 m_widgetState(WidgetState::WidgetState_Stopped)
85 LogDebug("App Created");
88 WrtClient::~WrtClient()
90 LogDebug("App Finished");
93 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
95 return m_returnStatus;
98 void WrtClient::OnStop()
100 LogInfo("Stopping Dummy Client");
103 void WrtClient::OnCreate()
105 LogInfo("On Create");
106 ADD_PROFILING_POINT("OnCreate callback", "point");
110 void WrtClient::OnResume()
112 if (m_widgetState != WidgetState_Suspended) {
113 LogWarning("Widget is not suspended, resuming was skipped");
117 m_widgetState = WidgetState_Running;
120 void WrtClient::OnPause()
122 if (m_widgetState != WidgetState_Running) {
123 LogWarning("Widget is not running to be suspended");
127 m_widgetState = WidgetState_Suspended;
130 void WrtClient::OnReset(bundle *b)
133 // bundle argument is freed after OnReset() is returned
134 // So bundle duplication is needed
135 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
137 if (true == m_initializing) {
138 LogDebug("can not handle reset event");
141 if (true == m_launched) {
142 if (m_widgetState == WidgetState_Stopped) {
143 LogError("Widget is not running to be reset");
147 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
148 m_widgetState = WidgetState_Running;
150 if (true == checkArgument()) {
157 // low memory callback set
158 appcore_set_event_callback(
159 APPCORE_EVENT_LOW_MEMORY,
160 WrtClient::appcoreLowMemoryCallback,
164 void WrtClient::OnTerminate()
166 LogDebug("Wrt Shutdown now");
170 void WrtClient::showHelpAndQuit()
172 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
174 "Mandatory arguments to long options are mandatory for short "
176 " -h, --help show this help\n"
178 "launch widget with given tizen ID\n"
180 "launch widget with given tizen ID\n"
186 bool WrtClient::checkArgument()
188 std::string tizenId = getTizenIdFromArgument(m_argc, m_argv);
190 if (tizenId.empty()) {
194 #ifdef MULTIPROCESS_SERVICE_SUPPORT
195 const char * SERVICE_POSTFIX = "-__SERVICE_PROCESS__";
196 std::size_t pos = tizenId.find(SERVICE_POSTFIX);
197 if (pos != std::string::npos) {
198 std::string id = tizenId.substr(pos);
199 id.erase(strlen(SERVICE_POSTFIX));
200 std::stringstream s(id);
201 unsigned serviceIndex;
203 m_serviceIndex = serviceIndex;
205 LogDebug("service index " << serviceIndex);
209 LogDebug("Tizen id: " << m_tizenId);
214 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
216 LogInfo("checkArgument");
217 std::string arg = argv[0];
223 if (arg.find("wrt-client") != std::string::npos) {
230 if (arg == "-h" || arg == "--help") {
232 } else if (arg == "-l" || arg == "--launch" ||
233 arg == "-t" || arg == "--tizen")
243 // Launch widget based on application basename
244 size_t pos = arg.find_last_of('/');
246 if (pos != std::string::npos) {
247 arg = arg.erase(0, pos + 1);
254 void WrtClient::setStep()
258 AddStep(&WrtClient::initStep);
260 setSdkLauncherDebugData();
262 AddStep(&WrtClient::launchStep);
263 AddStep(&WrtClient::shutdownStep);
265 m_initializing = true;
267 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
270 void WrtClient::setSdkLauncherDebugData()
272 LogDebug("setSdkLauncherDebugData");
274 /* check bundle from sdk launcher */
275 bundle *bundleFromSdkLauncher;
276 bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
277 const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
278 const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
279 if (bundle_debug != NULL && bundle_pid != NULL) {
280 if (strcmp(bundle_debug, "true") == 0) {
282 m_sdkLauncherPid = atoi(bundle_pid);
287 bundle_free(bundleFromSdkLauncher);
290 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
292 LogError("Checking for debug mode");
295 bool debugMode = debugData->debugMode;
297 LogInfo("[DEBUG_MODE] Widget is launched in " <<
298 (debugMode ? "DEBUG" : "RETAIL") <<
301 if (debugMode == true) {
302 // In WAC widget, only test widgets can use web inspector.
304 // every launched widgets as debug mode can use it.
305 if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_WAC20) {
307 WRT::CoreModuleSingleton::Instance().developerMode();
308 //This code will be activated
309 //after WAC test certificate is used by SDK
310 //bool isTestWidget = view->m_widgetModel->IsTestWidget.Get();
313 // LogInfo("This is not WAC Test Widget");
316 if (!developerMode) {
317 LogInfo("This is not WAC Developer Mode");
325 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
327 LogDebug("Executing next step");
331 void WrtClient::initStep()
334 if (WRT::CoreModuleSingleton::Instance().Init()) {
335 m_initialized = true;
337 m_returnStatus = ReturnStatus::Failed;
338 SwitchToStep(&WrtClient::shutdownStep);
341 // ecore_event_jobs are processed sequentially without concession to
342 // other type events. To give a chance of execute to other events,
343 // ecore_timer_add was used.
344 DPL::Event::ControllerEventHandler<NextStepEvent>::PostTimedEvent(
345 NextStepEvent(), 0.001);
348 bool WrtClient::checkWACTestCertififedWidget()
350 // WAC Waikiki Beta Release Core Specification: Widget Runtime
353 // WR-4710 The WRT MUST enable debug functions only for WAC test widgets
354 // i.e. the functions must not be usable for normal WAC widgets, even when
355 // a WAC test widget is executing.
356 ADD_PROFILING_POINT("DeveloperModeCheck", "start");
359 // A widget signed with a WAC-issued test certificate as described in
362 bool developerWidget = m_dao->isTestWidget();
363 bool developerMode = WRT::CoreModuleSingleton::Instance().developerMode();
365 LogDebug("Is WAC test widget: " << developerWidget);
366 LogDebug("Is developer Mode: " << developerMode);
368 if (developerWidget) {
369 if (!developerMode) {
370 LogError("WAC test certified developer widget is needed for " <<
374 //TODO: WR-4660 (show popup about developer widget
376 LogInfo("POPUP: THIS IS TEST WIDGET!");
379 ADD_PROFILING_POINT("DeveloperModeCheck", "stop");
383 void WrtClient::loadFinishCallback(Evas_Object* webview)
385 ADD_PROFILING_POINT("loadFinishCallback", "start");
386 SDKDebugData* debug = new SDKDebugData;
387 debug->debugMode = m_debugMode;
388 debug->pid = new unsigned long(getpid());
390 LogInfo("Post result of launch");
392 // Start inspector server, if current mode is debugger mode.
393 // In the WK2 case, ewk_view_inspector_server_start should
394 // be called after WebProcess is created.
395 if (checkDebugMode(debug)) {
397 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
398 if (debug->portnum == 0) {
399 LogWarning("Failed to get portnum");
401 LogInfo("Assigned port number for inspector : "
405 LogDebug("Debug mode is disabled");
408 //w3c packaging test debug (message on 4>)
409 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
410 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
411 FILE* doutput = fdopen(4, "w");
412 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
417 LogDebug("Launch succesfull");
420 m_initializing = false;
422 ADD_PROFILING_POINT("loadFinishCallback", "stop");
423 printf("launched\n");
428 m_returnStatus = ReturnStatus::Failed;
430 DPL::Event::ControllerEventHandler<NextStepEvent>::
431 PostEvent(NextStepEvent());
434 if (debug->debugMode) {
435 LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
437 /* send real time signal with result to wrt-launcher */
439 LogDebug("userData->portnum : " << debug->portnum);
440 sv.sival_int = debug->portnum;
444 sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
447 ApplicationDataSingleton::Instance().freeBundle();
449 LogDebug("Cleaning wrtClient launch resources...");
454 void WrtClient::progressFinishCallback()
456 m_splashScreen->stopSplashScreen();
459 void WrtClient::webkitExitCallback()
461 LogDebug("window close called, terminating app");
462 SwitchToStep(&WrtClient::shutdownStep);
463 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
467 void WrtClient::webCrashCallback()
469 LogError("webProcess crashed");
470 SwitchToStep(&WrtClient::shutdownStep);
471 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
475 void WrtClient::launchStep()
477 ADD_PROFILING_POINT("launchStep", "start");
478 LogDebug("Launching widget ...");
480 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
481 #ifdef MULTIPROCESS_SERVICE_SUPPORT
482 m_widget = WRT::CoreModuleSingleton::Instance()
483 .getRunnableWidgetObject(m_tizenId, m_serviceIndex);
485 m_widget = WRT::CoreModuleSingleton::Instance()
486 .getRunnableWidgetObject(m_tizenId);
488 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
491 LogError("RunnableWidgetObject is NULL, stop launchStep");
492 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
497 if (m_widgetState == WidgetState_Running) {
498 LogWarning("Widget already running, stop launchStep");
499 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
504 if (m_widgetState == WidgetState_Authorizing) {
505 LogWarning("Widget already authorizing, stop launchStep");
506 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
511 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
512 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
513 if (!defloc.IsNull()) {
514 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
518 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
520 /* remove language change callback */
522 LocalizationSetting::SetLanguageChangedCallback(
523 languageChangedCallback, this);
526 ADD_PROFILING_POINT("CreateWindow", "start");
527 if (s_preparedWindowData == NULL) {
528 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
530 m_windowData.reset(s_preparedWindowData);
531 s_preparedWindowData = NULL;
533 ADD_PROFILING_POINT("CreateWindow", "stop");
534 evas_object_show(m_windowData->m_win);
535 // rotate window to initial value
536 setOrientationWindow();
538 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
539 ADD_PROFILING_POINT("Create splash screen", "start");
540 m_splashScreen.reset(
541 new SplashScreenSupport(m_windowData->m_win));
542 if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
543 m_splashScreen->startSplashScreen();
544 cbs->progressFinish = DPL::MakeDelegate(
547 progressFinishCallback);
549 ADD_PROFILING_POINT("Create splash screen", "stop");
550 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
551 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
552 m_windowData->m_win, s_preparedEwkContext))
554 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
558 // send rotate information to ewk
561 //you can't show window with splash screen before PrepareView
562 //ewk_view_add_with_context() in viewLogic breaks window
564 m_windowData->init();
566 WrtDB::WidgetLocalizedInfo localizedInfo =
567 W3CFileLocalization::getLocalizedInfo(m_dao);
568 std::string name = "";
569 if (!(localizedInfo.name.IsNull())) {
570 name = DPL::ToUTF8String(*(localizedInfo.name));
572 elm_win_title_set(m_windowData->m_win, name.c_str());
574 initializeWindowModes();
575 connectElmCallback();
577 if (!checkWACTestCertififedWidget()) {
578 LogWarning("WAC Certificate failed, stop launchStep");
582 m_widgetState = WidgetState_Authorizing;
583 if (!m_widget->CheckBeforeLaunch()) {
584 LogError("CheckBeforeLaunch failed, stop launchStep");
585 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
589 LogInfo("Widget launch accepted. Entering running state");
590 m_widgetState = WidgetState_Running;
592 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
593 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
594 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
595 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
596 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
597 cbs->toggleFullscreen = DPL::MakeDelegate(
598 m_windowData.get(), &WindowData::toggleFullscreen);
600 m_widget->SetUserDelegates(cbs);
603 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
605 ADD_PROFILING_POINT("launchStep", "stop");
608 void WrtClient::initializeWindowModes()
610 Assert(m_windowData);
612 auto windowModes = m_dao->getWindowModes();
613 bool fullscreen = false;
614 bool backbutton = false;
615 if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
616 WidgetSettings widgetSettings;
617 m_dao->getWidgetSettings(widgetSettings);
618 WidgetSettingList settings(widgetSettings);
620 (settings.getBackButtonPresence() == BackButton_Enable);
623 FOREACH(it, windowModes)
625 std::string viewMode = DPL::ToUTF8String(*it);
626 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
629 } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
634 m_windowData->setViewMode(fullscreen,
638 void WrtClient::backButtonCallback(void* data,
639 Evas_Object * /*obj*/,
640 void * /*event_info*/)
642 LogInfo("BackButtonCallback");
645 WrtClient* This = static_cast<WrtClient*>(data);
647 This->m_widget->Backward();
650 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
652 LogInfo("appcoreLowMemoryCallback");
653 //WrtClient* This = static_cast<WrtClient*>(data);
655 // TODO call RunnableWidgetObject API regarding low memory
656 // The API should be implemented
661 void WrtClient::setOrientationWindow(void)
663 Assert(m_windowData);
666 WidgetSettings widgetSettings;
667 m_dao->getWidgetSettings(widgetSettings);
668 WidgetSettingList settings(widgetSettings);
669 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
670 if (rotationValue == Screen_Portrait) {
671 elm_win_wm_rotation_preferred_rotation_set(
673 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
674 } else if (rotationValue == Screen_Landscape) {
675 elm_win_wm_rotation_preferred_rotation_set(
677 WIN_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
679 elm_win_wm_rotation_preferred_rotation_set(
681 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
685 void WrtClient::setOrientationEwk(void)
690 WidgetSettings widgetSettings;
691 m_dao->getWidgetSettings(widgetSettings);
692 WidgetSettingList settings(widgetSettings);
693 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
694 if (rotationValue == Screen_Portrait) {
695 ewk_view_orientation_send(
696 m_widget->GetCurrentWebview(),
697 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
698 } else if (rotationValue == Screen_Landscape) {
699 ewk_view_orientation_send(
700 m_widget->GetCurrentWebview(),
701 W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
703 ewk_view_orientation_send(
704 m_widget->GetCurrentWebview(),
705 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
709 void WrtClient::connectElmCallback()
711 Assert(m_windowData);
713 WidgetSettings widgetSettings;
714 m_dao->getWidgetSettings(widgetSettings);
715 WidgetSettingList settings(widgetSettings);
716 if (settings.getBackButtonPresence() == BackButton_Enable) {
717 m_windowData->addFloatBackButtonCallback(
719 &WrtClient::backButtonCallback,
724 void WrtClient::setLayout(Evas_Object* newBuffer)
726 LogDebug("add new webkit buffer to window");
729 elm_object_part_content_set(m_windowData->m_user_layout,
733 evas_object_show(newBuffer);
736 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
738 LogDebug("remove current webkit buffer from window");
739 Assert(currentBuffer);
740 evas_object_hide(currentBuffer);
742 elm_object_part_content_unset(m_windowData->m_user_layout,
743 ELM_SWALLOW_CONTENT);
746 void WrtClient::shutdownStep()
748 LogDebug("Closing Wrt connection ...");
750 if (m_widget && m_widgetState) {
751 m_widgetState = WidgetState_Stopped;
754 ewk_context_delete(s_preparedEwkContext);
755 PrepareExternalStorageSingleton::Instance().Deinitialize();
756 WRT::CoreModuleSingleton::Instance().Terminate();
759 m_initialized = false;
761 m_windowData.reset();
765 int WrtClient::languageChangedCallback(void *data)
767 LogDebug("Language Changed");
771 WrtClient* wrtClient = static_cast<WrtClient*>(data);
772 if (!(wrtClient->m_dao)) {
776 // reset function fetches system locales and recreates language tags
777 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
778 // widget default locales are added to language tags below
779 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
780 if (!defloc.IsNull()) {
781 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
785 if (wrtClient->m_launched &&
786 wrtClient->m_widgetState != WidgetState_Stopped)
788 wrtClient->m_widget->ReloadStartPage();
793 void WrtClient::Quit()
796 DPL::Application::Quit();
799 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
801 int fd = ecore_main_fd_handler_fd_get(handler);
803 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
805 LogDebug("ECORE_FD_ERROR");
813 return ECORE_CALLBACK_CANCEL;
816 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
818 LogDebug("ECORE_FD_READ");
820 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
821 memset(pkt, 0, AUL_SOCK_MAXBUFF);
823 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
832 LogDebug("recv error!");
835 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
837 ecore_main_fd_handler_del(handler);
839 __wrt_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
844 ecore_main_loop_quit();
845 return ECORE_CALLBACK_CANCEL;
848 return ECORE_CALLBACK_CANCEL;
852 static void vconf_changed_handler(keynode_t *key, void *data)
854 LogInfo("VCONFKEY_LANGSET vconf-key was changed!");
861 // set evas backend type
862 if (!getenv("ELM_ENGINE"))
864 if (!setenv("ELM_ENGINE", "gl", 1))
866 LogDebug("Enable backend");
871 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
875 setenv("COREGL_FASTPATH", "1", 1);
877 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
878 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
879 setenv("ELM_IMAGE_CACHE", "0", 1);
885 // process pool - store arg's value
889 UNHANDLED_EXCEPTION_HANDLER_BEGIN
891 ADD_PROFILING_POINT("main-entered", "point");
894 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
896 // Set environment variables
899 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
901 LogInfo("Entered dummy process mode");
902 sprintf(argv[0], "%s ",
905 LogInfo("Prepare ewk_context");
906 appcore_set_i18n("wrt-client", NULL);
907 ewk_set_arguments(argc, argv);
908 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
909 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
911 if (s_preparedEwkContext == NULL)
913 LogInfo("Creating webkit context was failed!");
917 LogInfo("ewk_context_certificate_file_set()");
918 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
920 int client_fd = __connect_process_pool_server();
924 LogInfo("Connecting process_pool_server was failed!");
928 // register language change callback
929 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
931 LogInfo("Prepare window_data");
932 // Temporarily change HOME path to app
933 // This change is needed for getting elementary profile
934 // /opt/home/app/.elementary/config/mobile/base.cfg
935 const char* backupEnv = getenv(HOME);
936 setenv(HOME, APP_HOME_PATH, 1);
937 LogInfo("elm_init()");
938 elm_init(argc, argv);
939 setenv(HOME, backupEnv, 1);
941 LogInfo("WindowData()");
942 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
944 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
945 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
946 proces_pool_fd_handler, NULL, NULL, NULL);
948 if (fd_handler == NULL)
950 LogInfo("fd_handler is NULL");
954 setpriority(PRIO_PROCESS, 0, 0);
956 LogDebug("ecore_main_loop_begin()");
957 ecore_main_loop_begin();
958 LogDebug("ecore_main_loop_begin()_end");
960 // deregister language change callback
961 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
963 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
964 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
969 // This code is to fork a web process without exec.
970 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
972 if (!tizenId.empty())
974 #ifdef MULTIPROCESS_SERVICE_SUPPORT
975 std::size_t pos = tizenId.find("-__SERVICE_PROCESS__");
976 if (pos != std::string::npos) {
980 LogDebug("Launching by fork mode");
981 // Language env setup
982 appcore_set_i18n("wrt-client", NULL);
983 ewk_set_arguments(argc, argv);
984 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
985 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
988 if (s_preparedEwkContext == NULL)
990 LogInfo("Creating webkit context was failed!");
991 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
996 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
998 LogInfo("ewk_context_certificate_file_set()");
999 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
1003 // Output on stdout will be flushed after every newline character,
1004 // even if it is redirected to a pipe. This is useful for running
1005 // from a script and parsing output.
1006 // (Standard behavior of stdlib is to use full buffering when
1007 // redirected to a pipe, which means even after an end of line
1008 // the output may not be flushed).
1011 WrtClient app(app_argc, app_argv);
1013 ADD_PROFILING_POINT("Before appExec", "point");
1014 int ret = app.Exec();
1015 LogDebug("App returned: " << ret);
1016 ret = app.getReturnStatus();
1017 LogDebug("WrtClient returned: " << ret);
1020 UNHANDLED_EXCEPTION_HANDLER_END