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 <popup-runner/PopupInvoker.h>
36 #include <prepare_external_storage.h>
39 #include "process_pool.h"
40 #include "menu_db_util.h"
41 #include "launchpad_util.h"
43 //W3C PACKAGING enviroment variable name
44 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
46 // window signal callback
47 const char *EDJE_SHOW_BACKWARD_SIGNAL = "show,backward,signal";
48 const char *EDJE_SHOW_PROGRESS_SIGNAL = "show,progress,signal";
49 const char *EDJE_HIDE_PROGRESS_SIGNAL = "hide,progress,signal";
50 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
51 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
52 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
53 const char* const BUNDLE_PATH = "/usr/lib/libwrt-injected-bundle.so";
54 const char* const caCertPath = "/opt/usr/share/certs/ca-certificate.crt";
55 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
58 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
59 static Ewk_Context* s_preparedEwkContext = NULL;
60 static WindowData* s_preparedWindowData = NULL;
61 static int app_argc = 0;
62 static char** app_argv = NULL;
65 const char* const HOME = "HOME";
66 const char* const APP_HOME_PATH = "/opt/home/app";
67 const char* const ROOT_HOME_PATH = "/opt/home/root";
69 WrtClient::WrtClient(int argc, char **argv) :
70 Application(argc, argv, "wrt-client", false),
71 DPL::TaskDecl<WrtClient>(this),
72 m_appControlIndex(DPL::OptionalUInt()),
74 m_initializing(false),
79 m_returnStatus(ReturnStatus::Succeeded),
80 m_widgetState(WidgetState::WidgetState_Stopped)
83 LogDebug("App Created");
86 WrtClient::~WrtClient()
88 LogDebug("App Finished");
91 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
93 return m_returnStatus;
96 void WrtClient::OnStop()
98 LogInfo("Stopping Dummy Client");
101 void WrtClient::OnCreate()
103 LogInfo("On Create");
104 ADD_PROFILING_POINT("OnCreate callback", "point");
108 void WrtClient::OnResume()
110 if (m_widgetState != WidgetState_Suspended) {
111 LogWarning("Widget is not suspended, resuming was skipped");
115 m_widgetState = WidgetState_Running;
118 void WrtClient::OnPause()
120 if (m_widgetState != WidgetState_Running) {
121 LogWarning("Widget is not running to be suspended");
125 m_widgetState = WidgetState_Suspended;
128 void WrtClient::OnReset(bundle *b)
131 // bundle argument is freed after OnReset() is returned
132 // So bundle duplication is needed
133 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
134 ApplicationDataSingleton::Instance().setEncodedBundle(b);
136 if (true == m_initializing) {
137 LogDebug("can not handle reset event");
140 if (true == m_launched) {
141 if (m_widgetState == WidgetState_Stopped) {
142 LogError("Widget is not running to be reset");
146 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
147 m_widgetState = WidgetState_Running;
149 if (true == checkArgument()) {
156 // low memory callback set
157 appcore_set_event_callback(
158 APPCORE_EVENT_LOW_MEMORY,
159 WrtClient::appcoreLowMemoryCallback,
163 void WrtClient::OnTerminate()
165 LogDebug("Wrt Shutdown now");
169 void WrtClient::showHelpAndQuit()
171 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
173 "Mandatory arguments to long options are mandatory for short "
175 " -h, --help show this help\n"
177 "launch widget with given tizen ID\n"
179 "launch widget with given tizen ID\n"
185 bool WrtClient::checkArgument()
187 std::string tizenId = getTizenIdFromArgument(m_argc, m_argv);
189 if (tizenId.empty()) {
194 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
195 if (pos != std::string::npos) {
196 std::string id = tizenId.substr(pos);
197 id.erase(strlen(WrtDB::AppControlPrefix::PROCESS_PREFIX));
198 std::stringstream s(id);
199 unsigned int appControlIndex;
200 s >> appControlIndex;
201 m_appControlIndex = appControlIndex;
203 LogDebug("app-control execute-index : " << appControlIndex);
206 LogDebug("Tizen id: " << m_tizenId);
211 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
213 LogInfo("checkArgument");
214 std::string arg = argv[0];
220 if (arg.find("wrt-client") != std::string::npos) {
227 if (arg == "-h" || arg == "--help") {
229 } else if (arg == "-l" || arg == "--launch" ||
230 arg == "-t" || arg == "--tizen")
240 // Launch widget based on application basename
241 size_t pos = arg.find_last_of('/');
243 if (pos != std::string::npos) {
244 arg = arg.erase(0, pos + 1);
251 void WrtClient::setStep()
255 AddStep(&WrtClient::initStep);
257 setSdkLauncherDebugData();
259 AddStep(&WrtClient::launchStep);
260 AddStep(&WrtClient::shutdownStep);
262 m_initializing = true;
264 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
267 void WrtClient::setSdkLauncherDebugData()
269 LogDebug("setSdkLauncherDebugData");
271 /* check bundle from sdk launcher */
272 bundle *bundleFromSdkLauncher;
273 bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
274 const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
275 const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
276 if (bundle_debug != NULL && bundle_pid != NULL) {
277 if (strcmp(bundle_debug, "true") == 0) {
279 m_sdkLauncherPid = atoi(bundle_pid);
284 bundle_free(bundleFromSdkLauncher);
287 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
289 LogError("Checking for debug mode");
292 bool debugMode = debugData->debugMode;
294 LogInfo("[DEBUG_MODE] Widget is launched in " <<
295 (debugMode ? "DEBUG" : "RETAIL") <<
301 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
303 LogDebug("Executing next step");
307 void WrtClient::initStep()
310 if (WRT::CoreModuleSingleton::Instance().Init()) {
311 m_initialized = true;
313 m_returnStatus = ReturnStatus::Failed;
314 SwitchToStep(&WrtClient::shutdownStep);
317 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
320 void WrtClient::loadFinishCallback(Evas_Object* webview)
322 ADD_PROFILING_POINT("loadFinishCallback", "start");
323 SDKDebugData* debug = new SDKDebugData;
324 debug->debugMode = m_debugMode;
325 debug->pid = new unsigned long(getpid());
327 LogInfo("Post result of launch");
329 // Start inspector server, if current mode is debugger mode.
330 // In the WK2 case, ewk_view_inspector_server_start should
331 // be called after WebProcess is created.
332 if (checkDebugMode(debug)) {
334 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
335 if (debug->portnum == 0) {
336 LogWarning("Failed to get portnum");
338 LogInfo("Assigned port number for inspector : "
342 LogDebug("Debug mode is disabled");
345 //w3c packaging test debug (message on 4>)
346 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
347 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
348 FILE* doutput = fdopen(4, "w");
349 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
354 LogDebug("Launch succesfull");
357 m_initializing = false;
359 ADD_PROFILING_POINT("loadFinishCallback", "stop");
360 printf("launched\n");
365 m_returnStatus = ReturnStatus::Failed;
367 DPL::Event::ControllerEventHandler<NextStepEvent>::
368 PostEvent(NextStepEvent());
371 if (debug->debugMode) {
372 LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
374 /* send real time signal with result to wrt-launcher */
376 LogDebug("userData->portnum : " << debug->portnum);
377 sv.sival_int = debug->portnum;
381 sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
384 ApplicationDataSingleton::Instance().freeBundle();
386 LogDebug("Cleaning wrtClient launch resources...");
391 void WrtClient::progressStartedCallback()
393 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable) {
394 m_windowData->emitSignalForUserLayout(EDJE_SHOW_PROGRESS_SIGNAL, "");
395 m_windowData->updateProgress(0);
399 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
401 m_windowData->updateProgress(value);
404 void WrtClient::progressFinishCallback()
406 if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
407 m_splashScreen->stopSplashScreen();
409 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable) {
410 m_windowData->emitSignalForUserLayout(EDJE_HIDE_PROGRESS_SIGNAL, "");
414 void WrtClient::webkitExitCallback()
416 LogDebug("window close called, terminating app");
417 SwitchToStep(&WrtClient::shutdownStep);
418 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
422 void WrtClient::webCrashCallback()
424 LogError("webProcess crashed");
425 SwitchToStep(&WrtClient::shutdownStep);
426 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
430 void WrtClient::toggleFullscreenCallback(bool fullscreen)
432 LogError("toggleFullscreen");
435 m_windowData->toggleFullscreen(true);
436 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
437 m_windowData->toggleToolbar(false);
440 m_windowData->toggleFullscreen(false);
441 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
442 m_windowData->toggleToolbar(true);
447 void WrtClient::imeChangedCallback(bool open)
449 LogError("imeChangedCallback");
450 if (m_settingList->getBackButtonPresence() == BackButton_Enable &&
451 m_windowData->isFullscreen())
453 m_windowData->toggleToolbar(open);
457 void WrtClient::launchStep()
459 ADD_PROFILING_POINT("launchStep", "start");
460 LogDebug("Launching widget ...");
462 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
463 m_widget = WRT::CoreModuleSingleton::Instance()
464 .getRunnableWidgetObject(m_tizenId, m_appControlIndex);
465 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
468 LogError("RunnableWidgetObject is NULL, stop launchStep");
469 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
474 if (m_widgetState == WidgetState_Running) {
475 LogWarning("Widget already running, stop launchStep");
476 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
481 if (m_widgetState == WidgetState_Authorizing) {
482 LogWarning("Widget already authorizing, stop launchStep");
483 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
488 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
489 WrtDB::WidgetSettings widgetSettings;
490 m_dao->getWidgetSettings(widgetSettings);
491 m_settingList.reset(new WidgetSettingList(widgetSettings));
493 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
494 if (!defloc.IsNull()) {
495 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
499 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
501 /* remove language change callback */
503 LocalizationSetting::SetLanguageChangedCallback(
504 languageChangedCallback, this);
507 ADD_PROFILING_POINT("CreateWindow", "start");
508 if (s_preparedWindowData == NULL) {
509 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
511 m_windowData.reset(s_preparedWindowData);
512 s_preparedWindowData = NULL;
514 ADD_PROFILING_POINT("CreateWindow", "stop");
515 evas_object_show(m_windowData->m_win);
516 // rotate window to initial value
517 setOrientationWindow();
519 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
520 ADD_PROFILING_POINT("Create splash screen", "start");
521 m_splashScreen.reset(
522 new SplashScreenSupport(m_windowData->m_win));
523 if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
524 m_splashScreen->startSplashScreen();
526 ADD_PROFILING_POINT("Create splash screen", "stop");
527 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
528 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
529 m_windowData->m_win, s_preparedEwkContext))
531 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
535 // send rotate information to ewk
538 //you can't show window with splash screen before PrepareView
539 //ewk_view_add_with_context() in viewLogic breaks window
540 m_windowData->init();
541 m_windowData->toggleToolbar(
542 m_settingList->getBackButtonPresence() == BackButton_Enable);
544 WrtDB::WidgetLocalizedInfo localizedInfo =
545 W3CFileLocalization::getLocalizedInfo(m_dao);
546 std::string name = "";
547 if (!(localizedInfo.name.IsNull())) {
548 name = DPL::ToUTF8String(*(localizedInfo.name));
550 elm_win_title_set(m_windowData->m_win, name.c_str());
552 initializeWindowModes();
553 connectElmCallback();
555 m_widgetState = WidgetState_Authorizing;
556 if (!m_widget->CheckBeforeLaunch()) {
557 LogError("CheckBeforeLaunch failed, stop launchStep");
558 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
562 LogInfo("Widget launch accepted. Entering running state");
563 m_widgetState = WidgetState_Running;
565 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
566 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
567 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
568 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
569 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
570 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
571 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
572 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
573 cbs->toggleFullscreen = DPL::MakeDelegate(this, &WrtClient::toggleFullscreenCallback);
574 cbs->editorClientIme = DPL::MakeDelegate(this, &WrtClient::imeChangedCallback);
576 m_widget->SetUserDelegates(cbs);
578 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
580 ADD_PROFILING_POINT("launchStep", "stop");
583 void WrtClient::initializeWindowModes()
585 Assert(m_windowData);
587 auto windowModes = m_dao->getWindowModes();
588 bool fullscreen = false;
589 bool backbutton = false;
590 backbutton = (m_settingList->getBackButtonPresence() == BackButton_Enable);
592 FOREACH(it, windowModes)
594 std::string viewMode = DPL::ToUTF8String(*it);
595 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
598 } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
603 m_windowData->setViewMode(fullscreen,
607 void WrtClient::backButtonCallback(void* data,
608 Evas_Object * /*obj*/,
609 void * /*event_info*/)
611 LogInfo("BackButtonCallback");
614 WrtClient* This = static_cast<WrtClient*>(data);
615 This->m_widget->Backward();
618 void WrtClient::naviframeBackButtonCallback(void* data,
621 LogInfo("BackButtonCallback");
624 WrtClient* This = static_cast<WrtClient*>(data);
625 This->m_widget->Backward();
628 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
630 LogInfo("appcoreLowMemoryCallback");
631 //WrtClient* This = static_cast<WrtClient*>(data);
633 // TODO call RunnableWidgetObject API regarding low memory
634 // The API should be implemented
639 void WrtClient::setOrientationWindow(void)
641 Assert(m_windowData);
644 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
645 if (rotationValue == Screen_Portrait) {
646 elm_win_wm_rotation_preferred_rotation_set(
648 OrientationAngle::Window::Portrait::PRIMARY);
649 } else if (rotationValue == Screen_Landscape) {
650 elm_win_wm_rotation_preferred_rotation_set(
652 OrientationAngle::Window::Landscape::PRIMARY);
653 } else if (rotationValue == Screen_AutoRotation) {
654 LogInfo("Nothing to do");
656 elm_win_wm_rotation_preferred_rotation_set(
658 OrientationAngle::W3C::Portrait::PRIMARY);
662 void WrtClient::unsetOrientationWindow(void)
664 Assert(m_windowData);
667 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
668 if (rotationValue == Screen_AutoRotation) {
669 LogInfo("Nothing to do");
674 void WrtClient::setOrientationEwk(void)
679 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
680 if (rotationValue == Screen_Portrait) {
681 ewk_view_orientation_send(
682 m_widget->GetCurrentWebview(),
683 OrientationAngle::W3C::Portrait::PRIMARY);
684 } else if (rotationValue == Screen_Landscape) {
685 ewk_view_orientation_send(
686 m_widget->GetCurrentWebview(),
687 OrientationAngle::W3C::Landscape::PRIMARY);
688 } else if (rotationValue == Screen_AutoRotation) {
689 ewk_view_orientation_send(
690 m_widget->GetCurrentWebview(),
691 OrientationAngle::W3C::Portrait::PRIMARY);
693 ewk_view_orientation_send(
694 m_widget->GetCurrentWebview(),
695 OrientationAngle::W3C::Portrait::PRIMARY);
699 void WrtClient::connectElmCallback()
701 Assert(m_windowData);
704 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
705 m_windowData->addNaviframeItemPopCallback(
706 WrtClient::naviframeBackButtonCallback,
711 void WrtClient::setLayout(Evas_Object* newBuffer)
713 LogDebug("add new webkit buffer to window");
716 elm_object_part_content_set(m_windowData->m_user_layout,
720 evas_object_show(newBuffer);
723 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
725 LogDebug("remove current webkit buffer from window");
726 Assert(currentBuffer);
727 evas_object_hide(currentBuffer);
729 elm_object_part_content_unset(m_windowData->m_user_layout,
730 ELM_SWALLOW_CONTENT);
733 void WrtClient::shutdownStep()
735 LogDebug("Closing Wrt connection ...");
737 if (m_widget && m_widgetState) {
738 m_widgetState = WidgetState_Stopped;
740 // AutoRotation use m_widget pointer internally.
741 // It must be unset before m_widget is released.
742 unsetOrientationWindow();
744 ewk_context_delete(s_preparedEwkContext);
745 PrepareExternalStorageSingleton::Instance().Deinitialize();
746 WRT::CoreModuleSingleton::Instance().Terminate();
749 m_initialized = false;
751 m_windowData.reset();
755 int WrtClient::languageChangedCallback(void *data)
757 LogDebug("Language Changed");
761 WrtClient* wrtClient = static_cast<WrtClient*>(data);
762 if (!(wrtClient->m_dao)) {
766 // reset function fetches system locales and recreates language tags
767 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
768 // widget default locales are added to language tags below
769 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
770 if (!defloc.IsNull()) {
771 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
775 if (wrtClient->m_launched &&
776 wrtClient->m_widgetState != WidgetState_Stopped)
778 wrtClient->m_widget->ReloadStartPage();
783 void WrtClient::Quit()
786 DPL::Application::Quit();
789 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
791 int fd = ecore_main_fd_handler_fd_get(handler);
793 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
795 LogDebug("ECORE_FD_ERROR");
803 return ECORE_CALLBACK_CANCEL;
806 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
808 LogDebug("ECORE_FD_READ");
810 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
811 memset(pkt, 0, AUL_SOCK_MAXBUFF);
813 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
822 LogDebug("recv error!");
825 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
827 ecore_main_fd_handler_del(handler);
829 __wrt_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
834 ecore_main_loop_quit();
835 return ECORE_CALLBACK_CANCEL;
838 return ECORE_CALLBACK_CANCEL;
841 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
843 LogInfo("VCONFKEY_LANGSET vconf-key was changed!");
845 // When system language is changed, the candidate process will be created again.
851 // set evas backend type
852 if (!getenv("ELM_ENGINE"))
854 if (!setenv("ELM_ENGINE", "gl", 1))
856 LogDebug("Enable backend");
861 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
865 setenv("COREGL_FASTPATH", "1", 1);
867 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
868 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
869 setenv("ELM_IMAGE_CACHE", "0", 1);
875 // process pool - store arg's value
879 UNHANDLED_EXCEPTION_HANDLER_BEGIN
881 ADD_PROFILING_POINT("main-entered", "point");
884 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
886 // Set environment variables
889 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
891 LogInfo("Entered dummy process mode");
892 sprintf(argv[0], "%s ",
895 // Set 'root' home directory
896 setenv(HOME, ROOT_HOME_PATH, 1);
898 LogInfo("Prepare ewk_context");
899 appcore_set_i18n("wrt-client", NULL);
900 ewk_set_arguments(argc, argv);
901 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
902 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
904 if (s_preparedEwkContext == NULL)
906 LogInfo("Creating webkit context was failed!");
910 int client_fd = __connect_process_pool_server();
914 LogInfo("Connecting process_pool_server was failed!");
918 // register language changed callback
919 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
921 LogInfo("Prepare window_data");
922 // Temporarily change HOME path to app
923 // This change is needed for getting elementary profile
924 // /opt/home/app/.elementary/config/mobile/base.cfg
925 const char* backupEnv = getenv(HOME);
926 setenv(HOME, APP_HOME_PATH, 1);
927 LogInfo("elm_init()");
928 elm_init(argc, argv);
929 setenv(HOME, backupEnv, 1);
931 LogInfo("WindowData()");
932 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
934 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
935 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
936 proces_pool_fd_handler, NULL, NULL, NULL);
938 if (fd_handler == NULL)
940 LogInfo("fd_handler is NULL");
944 setpriority(PRIO_PROCESS, 0, 0);
946 LogDebug("ecore_main_loop_begin()");
947 ecore_main_loop_begin();
948 LogDebug("ecore_main_loop_begin()_end");
950 // deregister language changed callback
951 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
953 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
954 ewk_context_message_post_to_injected_bundle(
955 s_preparedEwkContext,
956 MESSAGE_NAME_INITIALIZE,
961 // This code is to fork a web process without exec.
962 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
963 if (!tizenId.empty()) {
965 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
966 if (pos != std::string::npos) {
970 LogDebug("Launching by fork mode");
971 // Language env setup
972 appcore_set_i18n("wrt-client", NULL);
973 ewk_set_arguments(argc, argv);
974 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
975 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
978 if (s_preparedEwkContext == NULL)
980 LogInfo("Creating webkit context was failed!");
981 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
986 ewk_context_message_post_to_injected_bundle(
987 s_preparedEwkContext,
988 MESSAGE_NAME_INITIALIZE,
993 // Output on stdout will be flushed after every newline character,
994 // even if it is redirected to a pipe. This is useful for running
995 // from a script and parsing output.
996 // (Standard behavior of stdlib is to use full buffering when
997 // redirected to a pipe, which means even after an end of line
998 // the output may not be flushed).
1001 WrtClient app(app_argc, app_argv);
1003 ADD_PROFILING_POINT("Before appExec", "point");
1004 int ret = app.Exec();
1005 LogDebug("App returned: " << ret);
1006 ret = app.getReturnStatus();
1007 LogDebug("WrtClient returned: " << ret);
1010 UNHANDLED_EXCEPTION_HANDLER_END