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 #ifdef MULTIPROCESS_SERVICE_SUPPORT
481 m_widget = WRT::CoreModuleSingleton::Instance()
482 .getRunnableWidgetObject(m_tizenId, m_serviceIndex);
484 m_widget = WRT::CoreModuleSingleton::Instance()
485 .getRunnableWidgetObject(m_tizenId);
487 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
490 LogError("RunnableWidgetObject is NULL, stop launchStep");
491 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
496 if (m_widgetState == WidgetState_Running) {
497 LogWarning("Widget already running, stop launchStep");
498 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
503 if (m_widgetState == WidgetState_Authorizing) {
504 LogWarning("Widget already authorizing, stop launchStep");
505 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
510 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
511 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
512 if (!defloc.IsNull()) {
513 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
517 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
519 /* remove language change callback */
521 LocalizationSetting::SetLanguageChangedCallback(
522 languageChangedCallback, this);
525 ADD_PROFILING_POINT("CreateWindow", "start");
526 if (s_preparedWindowData == NULL) {
527 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
529 m_windowData.reset(s_preparedWindowData);
530 s_preparedWindowData = NULL;
532 ADD_PROFILING_POINT("CreateWindow", "stop");
533 evas_object_show(m_windowData->m_win);
534 // rotate window to initial value
535 setOrientationWindow();
537 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
538 ADD_PROFILING_POINT("Create splash screen", "start");
539 m_splashScreen.reset(
540 new SplashScreenSupport(m_windowData->m_win));
541 if (m_splashScreen->createSplashScreen(m_dao->getSplashImgSrc())) {
542 m_splashScreen->startSplashScreen();
543 cbs->progressFinish = DPL::MakeDelegate(
546 progressFinishCallback);
548 ADD_PROFILING_POINT("Create splash screen", "stop");
549 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
550 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
551 m_windowData->m_win, s_preparedEwkContext))
553 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
557 // send rotate information to ewk
560 //you can't show window with splash screen before PrepareView
561 //ewk_view_add_with_context() in viewLogic breaks window
563 m_windowData->init();
565 WrtDB::WidgetLocalizedInfo localizedInfo =
566 W3CFileLocalization::getLocalizedInfo(m_dao);
567 std::string name = "";
568 if (!(localizedInfo.name.IsNull())) {
569 name = DPL::ToUTF8String(*(localizedInfo.name));
571 elm_win_title_set(m_windowData->m_win, name.c_str());
573 initializeWindowModes();
574 connectElmCallback();
576 if (!checkWACTestCertififedWidget()) {
577 LogWarning("WAC Certificate failed, stop launchStep");
581 m_widgetState = WidgetState_Authorizing;
582 if (!m_widget->CheckBeforeLaunch()) {
583 LogError("CheckBeforeLaunch failed, stop launchStep");
584 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
588 LogInfo("Widget launch accepted. Entering running state");
589 m_widgetState = WidgetState_Running;
591 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
592 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
593 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
594 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
595 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
596 cbs->toggleFullscreen = DPL::MakeDelegate(
597 m_windowData.get(), &WindowData::toggleFullscreen);
599 m_widget->SetUserDelegates(cbs);
602 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
604 ADD_PROFILING_POINT("launchStep", "stop");
607 void WrtClient::initializeWindowModes()
609 Assert(m_windowData);
611 auto windowModes = m_dao->getWindowModes();
612 bool fullscreen = false;
613 bool backbutton = false;
614 if (m_dao->getWidgetType().appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
615 WidgetSettings widgetSettings;
616 m_dao->getWidgetSettings(widgetSettings);
617 WidgetSettingList settings(widgetSettings);
619 (settings.getBackButtonPresence() == BackButton_Enable);
622 FOREACH(it, windowModes)
624 std::string viewMode = DPL::ToUTF8String(*it);
625 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
628 } else if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
633 m_windowData->setViewMode(fullscreen,
637 void WrtClient::backButtonCallback(void* data,
638 Evas_Object * /*obj*/,
639 void * /*event_info*/)
641 LogInfo("BackButtonCallback");
644 WrtClient* This = static_cast<WrtClient*>(data);
646 This->m_widget->Backward();
649 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
651 LogInfo("appcoreLowMemoryCallback");
652 //WrtClient* This = static_cast<WrtClient*>(data);
654 // TODO call RunnableWidgetObject API regarding low memory
655 // The API should be implemented
660 void WrtClient::setOrientationWindow(void)
662 Assert(m_windowData);
665 WidgetSettings widgetSettings;
666 m_dao->getWidgetSettings(widgetSettings);
667 WidgetSettingList settings(widgetSettings);
668 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
669 if (rotationValue == Screen_Portrait) {
670 elm_win_wm_rotation_preferred_rotation_set(
672 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
673 } else if (rotationValue == Screen_Landscape) {
674 elm_win_wm_rotation_preferred_rotation_set(
676 WIN_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
678 elm_win_wm_rotation_preferred_rotation_set(
680 WIN_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
684 void WrtClient::setOrientationEwk(void)
689 WidgetSettings widgetSettings;
690 m_dao->getWidgetSettings(widgetSettings);
691 WidgetSettingList settings(widgetSettings);
692 WidgetSettingScreenLock rotationValue = settings.getRotationValue();
693 if (rotationValue == Screen_Portrait) {
694 ewk_view_orientation_send(
695 m_widget->GetCurrentWebview(),
696 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
697 } else if (rotationValue == Screen_Landscape) {
698 ewk_view_orientation_send(
699 m_widget->GetCurrentWebview(),
700 W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE);
702 ewk_view_orientation_send(
703 m_widget->GetCurrentWebview(),
704 W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE);
708 void WrtClient::connectElmCallback()
710 Assert(m_windowData);
712 WidgetSettings widgetSettings;
713 m_dao->getWidgetSettings(widgetSettings);
714 WidgetSettingList settings(widgetSettings);
715 if (settings.getBackButtonPresence() == BackButton_Enable) {
716 m_windowData->addFloatBackButtonCallback(
718 &WrtClient::backButtonCallback,
723 void WrtClient::setLayout(Evas_Object* newBuffer)
725 LogDebug("add new webkit buffer to window");
728 elm_object_part_content_set(m_windowData->m_user_layout,
732 evas_object_show(newBuffer);
735 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
737 LogDebug("remove current webkit buffer from window");
738 Assert(currentBuffer);
739 evas_object_hide(currentBuffer);
741 elm_object_part_content_unset(m_windowData->m_user_layout,
742 ELM_SWALLOW_CONTENT);
745 void WrtClient::shutdownStep()
747 LogDebug("Closing Wrt connection ...");
749 if (m_widget && m_widgetState) {
750 m_widgetState = WidgetState_Stopped;
753 ewk_context_delete(s_preparedEwkContext);
754 PrepareExternalStorageSingleton::Instance().Deinitialize();
755 WRT::CoreModuleSingleton::Instance().Terminate();
758 m_initialized = false;
760 m_windowData.reset();
764 int WrtClient::languageChangedCallback(void *data)
766 LogDebug("Language Changed");
770 WrtClient* wrtClient = static_cast<WrtClient*>(data);
771 if (!(wrtClient->m_dao)) {
775 // reset function fetches system locales and recreates language tags
776 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
777 // widget default locales are added to language tags below
778 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
779 if (!defloc.IsNull()) {
780 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
784 if (wrtClient->m_launched &&
785 wrtClient->m_widgetState != WidgetState_Stopped)
787 wrtClient->m_widget->ReloadStartPage();
792 void WrtClient::Quit()
795 DPL::Application::Quit();
798 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
800 int fd = ecore_main_fd_handler_fd_get(handler);
802 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
804 LogDebug("ECORE_FD_ERROR");
812 return ECORE_CALLBACK_CANCEL;
815 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
817 LogDebug("ECORE_FD_READ");
819 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
820 memset(pkt, 0, AUL_SOCK_MAXBUFF);
822 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
831 LogDebug("recv error!");
834 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
836 ecore_main_fd_handler_del(handler);
838 __wrt_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
843 ecore_main_loop_quit();
844 return ECORE_CALLBACK_CANCEL;
847 return ECORE_CALLBACK_CANCEL;
853 // set evas backend type
854 if (!getenv("ELM_ENGINE"))
856 if (!setenv("ELM_ENGINE", "gl", 1))
858 LogDebug("Enable backend");
863 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
867 setenv("COREGL_FASTPATH", "1", 1);
869 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
870 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
871 setenv("ELM_IMAGE_CACHE", "0", 1);
878 // process pool - store arg's value
882 UNHANDLED_EXCEPTION_HANDLER_BEGIN
884 ADD_PROFILING_POINT("main-entered", "point");
887 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
889 // Set environment variables
892 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
894 LogInfo("Entered dummy process mode");
895 sprintf(argv[0], "%s ",
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 LogInfo("ewk_context_certificate_file_set()");
911 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
913 int client_fd = __connect_process_pool_server();
917 LogInfo("Connecting process_pool_server was failed!");
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 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
951 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
956 // This code is to fork a web process without exec.
957 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
959 if (!tizenId.empty())
961 #ifdef MULTIPROCESS_SERVICE_SUPPORT
962 std::size_t pos = tizenId.find("-__SERVICE_PROCESS__");
963 if (pos != std::string::npos) {
967 LogDebug("Launching by fork mode");
968 // Language env setup
969 appcore_set_i18n("wrt-client", NULL);
970 ewk_set_arguments(argc, argv);
971 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
972 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
975 if (s_preparedEwkContext == NULL)
977 LogInfo("Creating webkit context was failed!");
978 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
983 PluginModuleSupport::init(s_preparedEwkContext, tizenId);
985 LogInfo("ewk_context_certificate_file_set()");
986 ewk_context_certificate_file_set(s_preparedEwkContext, caCertPath);
990 // Output on stdout will be flushed after every newline character,
991 // even if it is redirected to a pipe. This is useful for running
992 // from a script and parsing output.
993 // (Standard behavior of stdlib is to use full buffering when
994 // redirected to a pipe, which means even after an end of line
995 // the output may not be flushed).
998 WrtClient app(app_argc, app_argv);
1000 ADD_PROFILING_POINT("Before appExec", "point");
1001 int ret = app.Exec();
1002 LogDebug("App returned: " << ret);
1003 ret = app.getReturnStatus();
1004 LogDebug("WrtClient returned: " << ret);
1007 UNHANDLED_EXCEPTION_HANDLER_END