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>
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 std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
49 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
50 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
51 const char* const BUNDLE_PATH = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
52 const char* const caCertPath = "/opt/usr/share/certs/ca-certificate.crt";
55 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
56 static Ewk_Context* s_preparedEwkContext = NULL;
57 static WindowData* s_preparedWindowData = NULL;
58 static int app_argc = 0;
59 static char** app_argv = NULL;
62 const int WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE = 0;
63 const int WIN_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE = 270;
64 const int W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE = 0;
65 const int W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE = 90;
68 const char* const HOME = "HOME";
69 const char* const APP_HOME_PATH = "/opt/home/app";
71 WrtClient::WrtClient(int argc, char **argv) :
72 Application(argc, argv, "wrt-client", false),
73 DPL::TaskDecl<WrtClient>(this),
75 m_initializing(false),
80 m_returnStatus(ReturnStatus::Succeeded),
81 m_widgetState(WidgetState::WidgetState_Stopped)
84 LogDebug("App Created");
87 WrtClient::~WrtClient()
89 LogDebug("App Finished");
92 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
94 return m_returnStatus;
97 void WrtClient::OnStop()
99 LogInfo("Stopping Dummy Client");
102 void WrtClient::OnCreate()
104 LogInfo("On Create");
105 ADD_PROFILING_POINT("OnCreate callback", "point");
109 void WrtClient::OnResume()
111 if (m_widgetState != WidgetState_Suspended) {
112 LogWarning("Widget is not suspended, resuming was skipped");
116 m_widgetState = WidgetState_Running;
119 void WrtClient::OnPause()
121 if (m_widgetState != WidgetState_Running) {
122 LogWarning("Widget is not running to be suspended");
126 m_widgetState = WidgetState_Suspended;
129 void WrtClient::OnReset(bundle *b)
132 // bundle argument is freed after OnReset() is returned
133 // So bundle duplication is needed
134 ApplicationDataSingleton::Instance().setBundle(bundle_dup(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()) {
193 #ifdef MULTIPROCESS_SERVICE_SUPPORT
194 const char * SERVICE_POSTFIX = "-__SERVICE_PROCESS__";
195 std::size_t pos = tizenId.find(SERVICE_POSTFIX);
196 if (pos != std::string::npos) {
197 std::string id = tizenId.substr(pos);
198 id.erase(strlen(SERVICE_POSTFIX));
199 std::stringstream s(id);
200 unsigned serviceIndex;
202 m_serviceIndex = serviceIndex;
204 LogDebug("service index " << serviceIndex);
208 LogDebug("Tizen id: " << m_tizenId);
213 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
215 LogInfo("checkArgument");
216 std::string arg = argv[0];
222 if (arg.find("wrt-client") != std::string::npos) {
229 if (arg == "-h" || arg == "--help") {
231 } else if (arg == "-l" || arg == "--launch" ||
232 arg == "-t" || arg == "--tizen")
242 // Launch widget based on application basename
243 size_t pos = arg.find_last_of('/');
245 if (pos != std::string::npos) {
246 arg = arg.erase(0, pos + 1);
253 void WrtClient::setStep()
257 AddStep(&WrtClient::initStep);
259 setSdkLauncherDebugData();
261 AddStep(&WrtClient::launchStep);
262 AddStep(&WrtClient::shutdownStep);
264 m_initializing = true;
266 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
269 void WrtClient::setSdkLauncherDebugData()
271 LogDebug("setSdkLauncherDebugData");
273 /* check bundle from sdk launcher */
274 bundle *bundleFromSdkLauncher;
275 bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
276 const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
277 const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
278 if (bundle_debug != NULL && bundle_pid != NULL) {
279 if (strcmp(bundle_debug, "true") == 0) {
281 m_sdkLauncherPid = atoi(bundle_pid);
286 bundle_free(bundleFromSdkLauncher);
289 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
291 LogError("Checking for debug mode");
294 bool debugMode = debugData->debugMode;
296 LogInfo("[DEBUG_MODE] Widget is launched in " <<
297 (debugMode ? "DEBUG" : "RETAIL") <<
300 if (debugMode == true) {
301 // In WAC widget, only test widgets can use web inspector.
303 // every launched widgets as debug mode can use it.
304 if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_WAC20) {
306 WRT::CoreModuleSingleton::Instance().developerMode();
307 //This code will be activated
308 //after WAC test certificate is used by SDK
309 //bool isTestWidget = view->m_widgetModel->IsTestWidget.Get();
312 // LogInfo("This is not WAC Test Widget");
315 if (!developerMode) {
316 LogInfo("This is not WAC Developer Mode");
324 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
326 LogDebug("Executing next step");
330 void WrtClient::initStep()
333 if (WRT::CoreModuleSingleton::Instance().Init()) {
334 m_initialized = true;
336 m_returnStatus = ReturnStatus::Failed;
337 SwitchToStep(&WrtClient::shutdownStep);
340 // ecore_event_jobs are processed sequentially without concession to
341 // other type events. To give a chance of execute to other events,
342 // ecore_timer_add was used.
343 DPL::Event::ControllerEventHandler<NextStepEvent>::PostTimedEvent(
344 NextStepEvent(), 0.001);
347 bool WrtClient::checkWACTestCertififedWidget()
349 // WAC Waikiki Beta Release Core Specification: Widget Runtime
352 // WR-4710 The WRT MUST enable debug functions only for WAC test widgets
353 // i.e. the functions must not be usable for normal WAC widgets, even when
354 // a WAC test widget is executing.
355 ADD_PROFILING_POINT("DeveloperModeCheck", "start");
358 // A widget signed with a WAC-issued test certificate as described in
361 bool developerWidget = m_dao->isTestWidget();
362 bool developerMode = WRT::CoreModuleSingleton::Instance().developerMode();
364 LogDebug("Is WAC test widget: " << developerWidget);
365 LogDebug("Is developer Mode: " << developerMode);
367 if (developerWidget) {
368 if (!developerMode) {
369 LogError("WAC test certified developer widget is needed for " <<
373 //TODO: WR-4660 (show popup about developer widget
375 LogInfo("POPUP: THIS IS TEST WIDGET!");
378 ADD_PROFILING_POINT("DeveloperModeCheck", "stop");
382 void WrtClient::loadFinishCallback(Evas_Object* webview)
384 ADD_PROFILING_POINT("loadFinishCallback", "start");
385 SDKDebugData* debug = new SDKDebugData;
386 debug->debugMode = m_debugMode;
387 debug->pid = new unsigned long(getpid());
389 LogInfo("Post result of launch");
391 // Start inspector server, if current mode is debugger mode.
392 // In the WK2 case, ewk_view_inspector_server_start should
393 // be called after WebProcess is created.
394 if (checkDebugMode(debug)) {
396 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
397 if (debug->portnum == 0) {
398 LogWarning("Failed to get portnum");
400 LogInfo("Assigned port number for inspector : "
404 LogDebug("Debug mode is disabled");
407 //w3c packaging test debug (message on 4>)
408 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
409 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
410 FILE* doutput = fdopen(4, "w");
411 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
416 LogDebug("Launch succesfull");
419 m_initializing = false;
421 ADD_PROFILING_POINT("loadFinishCallback", "stop");
422 printf("launched\n");
427 m_returnStatus = ReturnStatus::Failed;
429 DPL::Event::ControllerEventHandler<NextStepEvent>::
430 PostEvent(NextStepEvent());
433 if (debug->debugMode) {
434 LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
436 /* send real time signal with result to wrt-launcher */
438 LogDebug("userData->portnum : " << debug->portnum);
439 sv.sival_int = debug->portnum;
443 sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
446 ApplicationDataSingleton::Instance().freeBundle();
448 LogDebug("Cleaning wrtClient launch resources...");
453 void WrtClient::progressFinishCallback()
455 m_splashScreen->stopSplashScreen();
458 void WrtClient::webkitExitCallback()
460 LogDebug("window close called, terminating app");
461 SwitchToStep(&WrtClient::shutdownStep);
462 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
466 void WrtClient::webCrashCallback()
468 LogError("webProcess crashed");
469 SwitchToStep(&WrtClient::shutdownStep);
470 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
474 void WrtClient::launchStep()
476 ADD_PROFILING_POINT("launchStep", "start");
477 LogDebug("Launching widget ...");
479 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
480 m_widget = WRT::CoreModuleSingleton::Instance()
481 .getRunnableWidgetObject(m_tizenId, m_serviceIndex);
482 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
485 LogError("RunnableWidgetObject is NULL, stop launchStep");
486 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
491 if (m_widgetState == WidgetState_Running) {
492 LogWarning("Widget already running, stop launchStep");
493 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
498 if (m_widgetState == WidgetState_Authorizing) {
499 LogWarning("Widget already authorizing, stop launchStep");
500 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
505 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
506 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
507 if (!defloc.IsNull()) {
508 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
512 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
514 /* remove language change callback */
516 LocalizationSetting::SetLanguageChangedCallback(
517 languageChangedCallback, this);
520 ADD_PROFILING_POINT("CreateWindow", "start");
521 if (s_preparedWindowData == NULL) {
522 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
524 m_windowData.reset(s_preparedWindowData);
525 s_preparedWindowData = NULL;
527 ADD_PROFILING_POINT("CreateWindow", "stop");
528 evas_object_show(m_windowData->m_win);
529 // rotate window to initial value
530 setOrientationWindow();
532 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
533 ADD_PROFILING_POINT("Create splash screen", "start");
534 m_splashScreen.reset(
535 new SplashScreenSupport(m_windowData->m_win));
536 if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
537 m_splashScreen->startSplashScreen();
538 cbs->progressFinish = DPL::MakeDelegate(
541 progressFinishCallback);
543 ADD_PROFILING_POINT("Create splash screen", "stop");
544 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
545 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
546 m_windowData->m_win, s_preparedEwkContext))
548 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
552 // send rotate information to ewk
555 //you can't show window with splash screen before PrepareView
556 //ewk_view_add_with_context() in viewLogic breaks window
558 m_windowData->init();
560 WrtDB::WidgetLocalizedInfo localizedInfo =
561 W3CFileLocalization::getLocalizedInfo(m_dao);
562 std::string name = "";
563 if (!(localizedInfo.name.IsNull())) {
564 name = DPL::ToUTF8String(*(localizedInfo.name));
566 elm_win_title_set(m_windowData->m_win, name.c_str());
568 initializeWindowModes();
569 connectElmCallback();
571 if (!checkWACTestCertififedWidget()) {
572 LogWarning("WAC Certificate failed, stop launchStep");
576 m_widgetState = WidgetState_Authorizing;
577 if (!m_widget->CheckBeforeLaunch()) {
578 LogError("CheckBeforeLaunch failed, stop launchStep");
579 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
583 LogInfo("Widget launch accepted. Entering running state");
584 m_widgetState = WidgetState_Running;
586 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
587 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
588 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
589 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
590 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
591 cbs->toggleFullscreen = DPL::MakeDelegate(
592 m_windowData.get(), &WindowData::toggleFullscreen);
594 m_widget->SetUserDelegates(cbs);
597 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
599 ADD_PROFILING_POINT("launchStep", "stop");
602 void WrtClient::initializeWindowModes()
604 Assert(m_windowData);
606 auto windowModes = m_dao->getWindowModes();
607 bool fullscreen = false;
608 bool backbutton = false;
609 if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
610 WidgetSettings widgetSettings;
611 m_dao->getWidgetSettings(widgetSettings);
612 WidgetSettingList settings(widgetSettings);
614 (settings.getBackButtonPresence() == BackButton_Enable);
617 FOREACH(it, windowModes)
619 std::string viewMode = DPL::ToUTF8String(*it);
620 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
623 } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
628 m_windowData->setViewMode(fullscreen,
632 void WrtClient::backButtonCallback(void* data,
633 Evas_Object * /*obj*/,
634 void * /*event_info*/)
636 LogInfo("BackButtonCallback");
639 WrtClient* This = static_cast<WrtClient*>(data);
641 This->m_widget->Backward();
644 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
646 LogInfo("appcoreLowMemoryCallback");
647 //WrtClient* This = static_cast<WrtClient*>(data);
649 // TODO call RunnableWidgetObject API regarding low memory
650 // The API should be implemented
655 void WrtClient::setOrientationWindow(void)
657 Assert(m_windowData);
660 WidgetSettings widgetSettings;
661 m_dao->getWidgetSettings(widgetSettings);
662 WidgetSettingList settings(widgetSettings);
663 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
664 if (rotationValue == Screen_Portrait) {
665 elm_win_wm_rotation_preferred_rotation_set(
667 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
668 } else if (rotationValue == Screen_Landscape) {
669 elm_win_wm_rotation_preferred_rotation_set(
671 WIN_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
673 elm_win_wm_rotation_preferred_rotation_set(
675 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
679 void WrtClient::setOrientationEwk(void)
684 WidgetSettings widgetSettings;
685 m_dao->getWidgetSettings(widgetSettings);
686 WidgetSettingList settings(widgetSettings);
687 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
688 if (rotationValue == Screen_Portrait) {
689 ewk_view_orientation_send(
690 m_widget->GetCurrentWebview(),
691 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
692 } else if (rotationValue == Screen_Landscape) {
693 ewk_view_orientation_send(
694 m_widget->GetCurrentWebview(),
695 W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
697 ewk_view_orientation_send(
698 m_widget->GetCurrentWebview(),
699 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
703 void WrtClient::connectElmCallback()
705 Assert(m_windowData);
707 WidgetSettings widgetSettings;
708 m_dao->getWidgetSettings(widgetSettings);
709 WidgetSettingList settings(widgetSettings);
710 if (settings.getBackButtonPresence() == BackButton_Enable) {
711 m_windowData->addFloatBackButtonCallback(
713 &WrtClient::backButtonCallback,
718 void WrtClient::setLayout(Evas_Object* newBuffer)
720 LogDebug("add new webkit buffer to window");
723 elm_object_part_content_set(m_windowData->m_user_layout,
727 evas_object_show(newBuffer);
730 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
732 LogDebug("remove current webkit buffer from window");
733 Assert(currentBuffer);
734 evas_object_hide(currentBuffer);
736 elm_object_part_content_unset(m_windowData->m_user_layout,
737 ELM_SWALLOW_CONTENT);
740 void WrtClient::shutdownStep()
742 LogDebug("Closing Wrt connection ...");
744 if (m_widget && m_widgetState) {
745 m_widgetState = WidgetState_Stopped;
748 ewk_context_delete(s_preparedEwkContext);
749 PrepareExternalStorageSingleton::Instance().Deinitialize();
750 WRT::CoreModuleSingleton::Instance().Terminate();
753 m_initialized = false;
755 m_windowData.reset();
759 int WrtClient::languageChangedCallback(void *data)
761 LogDebug("Language Changed");
765 WrtClient* wrtClient = static_cast<WrtClient*>(data);
766 if (!(wrtClient->m_dao)) {
770 // reset function fetches system locales and recreates language tags
771 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
772 // widget default locales are added to language tags below
773 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
774 if (!defloc.IsNull()) {
775 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
779 if (wrtClient->m_launched &&
780 wrtClient->m_widgetState != WidgetState_Stopped)
782 wrtClient->m_widget->ReloadStartPage();
787 void WrtClient::Quit()
790 DPL::Application::Quit();
793 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
795 int fd = ecore_main_fd_handler_fd_get(handler);
797 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
799 LogDebug("ECORE_FD_ERROR");
807 return ECORE_CALLBACK_CANCEL;
810 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
812 LogDebug("ECORE_FD_READ");
814 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
815 memset(pkt, 0, AUL_SOCK_MAXBUFF);
817 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
826 LogDebug("recv error!");
829 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
831 ecore_main_fd_handler_del(handler);
833 __wrt_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
838 ecore_main_loop_quit();
839 return ECORE_CALLBACK_CANCEL;
842 return ECORE_CALLBACK_CANCEL;
848 // set evas backend type
849 if (!getenv("ELM_ENGINE"))
851 if (!setenv("ELM_ENGINE", "gl", 1))
853 LogDebug("Enable backend");
858 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
862 setenv("COREGL_FASTPATH", "1", 1);
864 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
865 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
866 setenv("ELM_IMAGE_CACHE", "0", 1);
873 // process pool - store arg's value
877 UNHANDLED_EXCEPTION_HANDLER_BEGIN
879 ADD_PROFILING_POINT("main-entered", "point");
882 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
884 // Set environment variables
887 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
889 LogInfo("Entered dummy process mode");
890 sprintf(argv[0], "%s ",
893 LogInfo("Prepare ewk_context");
894 appcore_set_i18n("wrt-client", NULL);
895 ewk_set_arguments(argc, argv);
896 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
897 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
899 if (s_preparedEwkContext == NULL)
901 LogInfo("Creating webkit context was failed!");
905 LogInfo("ewk_context_certificate_file_set()");
906 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
908 int client_fd = __connect_process_pool_server();
912 LogInfo("Connecting process_pool_server was failed!");
916 LogInfo("Prepare window_data");
917 // Temporarily change HOME path to app
918 // This change is needed for getting elementary profile
919 // /opt/home/app/.elementary/config/mobile/base.cfg
920 const char* backupEnv = getenv(HOME);
921 setenv(HOME, APP_HOME_PATH, 1);
922 LogInfo("elm_init()");
923 elm_init(argc, argv);
924 setenv(HOME, backupEnv, 1);
926 LogInfo("WindowData()");
927 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
929 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
930 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
931 proces_pool_fd_handler, NULL, NULL, NULL);
933 if (fd_handler == NULL)
935 LogInfo("fd_handler is NULL");
939 setpriority(PRIO_PROCESS, 0, 0);
941 LogDebug("ecore_main_loop_begin()");
942 ecore_main_loop_begin();
943 LogDebug("ecore_main_loop_begin()_end");
945 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
946 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
951 // This code is to fork a web process without exec.
952 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
954 if (!tizenId.empty())
956 #ifdef MULTIPROCESS_SERVICE_SUPPORT
957 std::size_t pos = tizenId.find("-__SERVICE_PROCESS__");
958 if (pos != std::string::npos) {
962 LogDebug("Launching by fork mode");
963 // Language env setup
964 appcore_set_i18n("wrt-client", NULL);
965 ewk_set_arguments(argc, argv);
966 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
967 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
970 if (s_preparedEwkContext == NULL)
972 LogInfo("Creating webkit context was failed!");
973 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
978 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
980 LogInfo("ewk_context_certificate_file_set()");
981 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
985 // Output on stdout will be flushed after every newline character,
986 // even if it is redirected to a pipe. This is useful for running
987 // from a script and parsing output.
988 // (Standard behavior of stdlib is to use full buffering when
989 // redirected to a pipe, which means even after an end of line
990 // the output may not be flushed).
993 WrtClient app(app_argc, app_argv);
995 ADD_PROFILING_POINT("Before appExec", "point");
996 int ret = app.Exec();
997 LogDebug("App returned: " << ret);
998 ret = app.getReturnStatus();
999 LogDebug("WrtClient returned: " << ret);
1002 UNHANDLED_EXCEPTION_HANDLER_END