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),
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));
135 ApplicationDataSingleton::Instance().setEncodedBundle(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()) {
195 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
196 if (pos != std::string::npos) {
197 std::string id = tizenId.substr(pos);
198 id.erase(strlen(WrtDB::AppControlPrefix::PROCESS_PREFIX));
199 std::stringstream s(id);
200 unsigned int appControlIndex;
201 s >> appControlIndex;
202 m_appControlIndex = appControlIndex;
204 LogDebug("app-control execute-index : " << appControlIndex);
207 LogDebug("Tizen id: " << m_tizenId);
212 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
214 LogInfo("checkArgument");
215 std::string arg = argv[0];
221 if (arg.find("wrt-client") != std::string::npos) {
228 if (arg == "-h" || arg == "--help") {
230 } else if (arg == "-l" || arg == "--launch" ||
231 arg == "-t" || arg == "--tizen")
241 // Launch widget based on application basename
242 size_t pos = arg.find_last_of('/');
244 if (pos != std::string::npos) {
245 arg = arg.erase(0, pos + 1);
252 void WrtClient::setStep()
256 AddStep(&WrtClient::initStep);
258 setSdkLauncherDebugData();
260 AddStep(&WrtClient::launchStep);
261 AddStep(&WrtClient::shutdownStep);
263 m_initializing = true;
265 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
268 void WrtClient::setSdkLauncherDebugData()
270 LogDebug("setSdkLauncherDebugData");
272 /* check bundle from sdk launcher */
273 bundle *bundleFromSdkLauncher;
274 bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
275 const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
276 const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
277 if (bundle_debug != NULL && bundle_pid != NULL) {
278 if (strcmp(bundle_debug, "true") == 0) {
280 m_sdkLauncherPid = atoi(bundle_pid);
285 bundle_free(bundleFromSdkLauncher);
288 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
290 LogError("Checking for debug mode");
293 bool debugMode = debugData->debugMode;
295 LogInfo("[DEBUG_MODE] Widget is launched in " <<
296 (debugMode ? "DEBUG" : "RETAIL") <<
302 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
304 LogDebug("Executing next step");
308 void WrtClient::initStep()
311 if (WRT::CoreModuleSingleton::Instance().Init()) {
312 m_initialized = true;
314 m_returnStatus = ReturnStatus::Failed;
315 SwitchToStep(&WrtClient::shutdownStep);
318 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
321 void WrtClient::loadFinishCallback(Evas_Object* webview)
323 ADD_PROFILING_POINT("loadFinishCallback", "start");
326 if (m_splashScreen && m_splashScreen->isShowing())
328 m_splashScreen->stopSplashScreenBuffered();
331 SDKDebugData* debug = new SDKDebugData;
332 debug->debugMode = m_debugMode;
333 debug->pid = new unsigned long(getpid());
335 LogInfo("Post result of launch");
337 // Start inspector server, if current mode is debugger mode.
338 // In the WK2 case, ewk_view_inspector_server_start should
339 // be called after WebProcess is created.
340 if (checkDebugMode(debug)) {
342 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
343 if (debug->portnum == 0) {
344 LogWarning("Failed to get portnum");
346 LogInfo("Assigned port number for inspector : "
350 LogDebug("Debug mode is disabled");
353 //w3c packaging test debug (message on 4>)
354 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
355 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
356 FILE* doutput = fdopen(4, "w");
357 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
362 LogDebug("Launch succesfull");
365 m_initializing = false;
367 ADD_PROFILING_POINT("loadFinishCallback", "stop");
368 printf("launched\n");
373 m_returnStatus = ReturnStatus::Failed;
375 DPL::Event::ControllerEventHandler<NextStepEvent>::
376 PostEvent(NextStepEvent());
379 if (debug->debugMode) {
380 LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
382 /* send real time signal with result to wrt-launcher */
384 LogDebug("userData->portnum : " << debug->portnum);
385 sv.sival_int = debug->portnum;
389 sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
392 ApplicationDataSingleton::Instance().freeBundle();
394 LogDebug("Cleaning wrtClient launch resources...");
399 void WrtClient::progressStartedCallback()
401 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable) {
402 m_windowData->emitSignalForUserLayout(EDJE_SHOW_PROGRESS_SIGNAL, "");
403 m_windowData->updateProgress(0);
407 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
409 m_windowData->updateProgress(value);
412 void WrtClient::progressFinishCallback()
414 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable) {
415 m_windowData->emitSignalForUserLayout(EDJE_HIDE_PROGRESS_SIGNAL, "");
419 void WrtClient::webkitExitCallback()
421 LogDebug("window close called, terminating app");
422 SwitchToStep(&WrtClient::shutdownStep);
423 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
427 void WrtClient::webCrashCallback()
429 LogError("webProcess crashed");
430 SwitchToStep(&WrtClient::shutdownStep);
431 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
435 void WrtClient::toggleFullscreenCallback(bool fullscreen)
437 LogError("toggleFullscreen");
440 m_windowData->toggleFullscreen(true);
441 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
442 m_windowData->toggleToolbar(false);
445 m_windowData->toggleFullscreen(false);
446 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
447 m_windowData->toggleToolbar(true);
452 void WrtClient::imeChangedCallback(bool open)
454 LogError("imeChangedCallback");
455 if (m_settingList->getBackButtonPresence() == BackButton_Enable &&
456 m_windowData->isFullscreen())
458 m_windowData->toggleToolbar(open);
462 void WrtClient::launchStep()
464 ADD_PROFILING_POINT("launchStep", "start");
465 LogDebug("Launching widget ...");
467 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
468 m_widget = WRT::CoreModuleSingleton::Instance()
469 .getRunnableWidgetObject(m_tizenId, m_appControlIndex);
470 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
473 LogError("RunnableWidgetObject is NULL, stop launchStep");
474 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
479 if (m_widgetState == WidgetState_Running) {
480 LogWarning("Widget already running, stop launchStep");
481 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
486 if (m_widgetState == WidgetState_Authorizing) {
487 LogWarning("Widget already authorizing, stop launchStep");
488 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
493 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
494 WrtDB::WidgetSettings widgetSettings;
495 m_dao->getWidgetSettings(widgetSettings);
496 m_settingList.reset(new WidgetSettingList(widgetSettings));
498 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
499 if (!defloc.IsNull()) {
500 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
504 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
506 /* remove language change callback */
508 LocalizationSetting::SetLanguageChangedCallback(
509 languageChangedCallback, this);
512 ADD_PROFILING_POINT("CreateWindow", "start");
513 if (s_preparedWindowData == NULL) {
514 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
516 m_windowData.reset(s_preparedWindowData);
517 s_preparedWindowData = NULL;
519 ADD_PROFILING_POINT("CreateWindow", "stop");
521 // rotate window to initial value
522 setOrientationWindow();
524 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
526 ADD_PROFILING_POINT("Create splash screen", "start");
527 DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
528 if (!splashImgSrc.IsNull())
530 m_splashScreen.reset(new SplashScreenSupport(m_windowData->m_win,
531 (DPL::ToUTF8String(*splashImgSrc)).c_str(),
533 (m_settingList->getRotationValue() == Screen_Landscape)));
534 m_splashScreen->startSplashScreen();
536 ADD_PROFILING_POINT("Create splash screen", "stop");
538 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
539 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
540 m_windowData->m_win, s_preparedEwkContext))
542 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
546 // send rotate information to ewk
549 //you can't show window with splash screen before PrepareView
550 //ewk_view_add_with_context() in viewLogic breaks window
551 m_windowData->init();
552 m_windowData->toggleToolbar(
553 m_settingList->getBackButtonPresence() == BackButton_Enable);
555 WrtDB::WidgetLocalizedInfo localizedInfo =
556 W3CFileLocalization::getLocalizedInfo(m_dao);
557 std::string name = "";
558 if (!(localizedInfo.name.IsNull())) {
559 name = DPL::ToUTF8String(*(localizedInfo.name));
561 elm_win_title_set(m_windowData->m_win, name.c_str());
564 evas_object_show(m_windowData->m_win);
566 initializeWindowModes();
567 connectElmCallback();
569 m_widgetState = WidgetState_Authorizing;
570 if (!m_widget->CheckBeforeLaunch()) {
571 LogError("CheckBeforeLaunch failed, stop launchStep");
572 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
576 LogInfo("Widget launch accepted. Entering running state");
577 m_widgetState = WidgetState_Running;
579 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
580 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
581 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
582 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
583 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
584 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
585 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
586 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
587 cbs->toggleFullscreen = DPL::MakeDelegate(this, &WrtClient::toggleFullscreenCallback);
588 cbs->editorClientIme = DPL::MakeDelegate(this, &WrtClient::imeChangedCallback);
590 m_widget->SetUserDelegates(cbs);
592 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
594 ADD_PROFILING_POINT("launchStep", "stop");
597 bool WrtClient::isFullscreen()
599 static bool first = true;
606 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
608 FOREACH(it, windowModes)
610 std::string viewMode = DPL::ToUTF8String(*it);
611 if (viewMode == VIEWMODE_TYPE_FULLSCREEN)
616 else if (viewMode == VIEWMODE_TYPE_MAXIMIZED)
626 void WrtClient::initializeWindowModes()
628 Assert(m_windowData);
630 bool fullscreen = isFullscreen();
631 bool backbutton = (m_settingList->getBackButtonPresence() == BackButton_Enable);
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);
645 This->m_widget->Backward();
648 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
651 LogInfo("BackButtonCallback");
654 WrtClient* This = static_cast<WrtClient*>(data);
655 This->m_widget->Backward();
659 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
661 LogInfo("appcoreLowMemoryCallback");
662 //WrtClient* This = static_cast<WrtClient*>(data);
664 // TODO call RunnableWidgetObject API regarding low memory
665 // The API should be implemented
670 void WrtClient::setOrientationWindow(void)
672 Assert(m_windowData);
675 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
676 if (rotationValue == Screen_Portrait) {
677 elm_win_wm_rotation_preferred_rotation_set(
679 OrientationAngle::Window::Portrait::PRIMARY);
680 } else if (rotationValue == Screen_Landscape) {
681 elm_win_wm_rotation_preferred_rotation_set(
683 OrientationAngle::Window::Landscape::PRIMARY);
684 } else if (rotationValue == Screen_AutoRotation) {
685 LogInfo("Nothing to do");
687 elm_win_wm_rotation_preferred_rotation_set(
689 OrientationAngle::W3C::Portrait::PRIMARY);
693 void WrtClient::unsetOrientationWindow(void)
695 Assert(m_windowData);
698 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
699 if (rotationValue == Screen_AutoRotation) {
700 LogInfo("Nothing to do");
705 void WrtClient::setOrientationEwk(void)
710 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
711 if (rotationValue == Screen_Portrait) {
712 ewk_view_orientation_send(
713 m_widget->GetCurrentWebview(),
714 OrientationAngle::W3C::Portrait::PRIMARY);
715 } else if (rotationValue == Screen_Landscape) {
716 ewk_view_orientation_send(
717 m_widget->GetCurrentWebview(),
718 OrientationAngle::W3C::Landscape::PRIMARY);
719 } else if (rotationValue == Screen_AutoRotation) {
720 ewk_view_orientation_send(
721 m_widget->GetCurrentWebview(),
722 OrientationAngle::W3C::Portrait::PRIMARY);
724 ewk_view_orientation_send(
725 m_widget->GetCurrentWebview(),
726 OrientationAngle::W3C::Portrait::PRIMARY);
730 void WrtClient::connectElmCallback()
732 Assert(m_windowData);
735 if (m_settingList->getBackButtonPresence() == BackButton_Enable) {
736 m_windowData->addNaviframeItemPopCallback(
737 WrtClient::naviframeBackButtonCallback,
742 void WrtClient::setLayout(Evas_Object* newBuffer)
744 LogDebug("add new webkit buffer to window");
747 elm_object_part_content_set(m_windowData->m_user_layout,
751 evas_object_show(newBuffer);
754 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
756 LogDebug("remove current webkit buffer from window");
757 Assert(currentBuffer);
758 evas_object_hide(currentBuffer);
760 elm_object_part_content_unset(m_windowData->m_user_layout,
761 ELM_SWALLOW_CONTENT);
764 void WrtClient::shutdownStep()
766 LogDebug("Closing Wrt connection ...");
768 if (m_widget && m_widgetState) {
769 m_widgetState = WidgetState_Stopped;
771 // AutoRotation use m_widget pointer internally.
772 // It must be unset before m_widget is released.
773 unsetOrientationWindow();
775 ewk_context_delete(s_preparedEwkContext);
776 PrepareExternalStorageSingleton::Instance().Deinitialize();
777 WRT::CoreModuleSingleton::Instance().Terminate();
780 m_initialized = false;
782 m_windowData.reset();
786 int WrtClient::languageChangedCallback(void *data)
788 LogDebug("Language Changed");
792 WrtClient* wrtClient = static_cast<WrtClient*>(data);
793 if (!(wrtClient->m_dao)) {
797 // reset function fetches system locales and recreates language tags
798 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
799 // widget default locales are added to language tags below
800 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
801 if (!defloc.IsNull()) {
802 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
806 if (wrtClient->m_launched &&
807 wrtClient->m_widgetState != WidgetState_Stopped)
809 wrtClient->m_widget->ReloadStartPage();
814 void WrtClient::Quit()
817 DPL::Application::Quit();
820 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
822 int fd = ecore_main_fd_handler_fd_get(handler);
824 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
826 LogDebug("ECORE_FD_ERROR");
834 return ECORE_CALLBACK_CANCEL;
837 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
839 LogDebug("ECORE_FD_READ");
841 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
842 memset(pkt, 0, AUL_SOCK_MAXBUFF);
844 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
853 LogDebug("recv error!");
856 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
858 ecore_main_fd_handler_del(handler);
860 __wrt_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
865 ecore_main_loop_quit();
866 return ECORE_CALLBACK_CANCEL;
869 return ECORE_CALLBACK_CANCEL;
872 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
874 LogInfo("VCONFKEY_LANGSET vconf-key was changed!");
876 // When system language is changed, the candidate process will be created again.
882 // set evas backend type
883 if (!getenv("ELM_ENGINE"))
885 if (!setenv("ELM_ENGINE", "gl", 1))
887 LogDebug("Enable backend");
892 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
896 setenv("COREGL_FASTPATH", "1", 1);
898 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
899 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
900 setenv("ELM_IMAGE_CACHE", "0", 1);
906 // process pool - store arg's value
910 UNHANDLED_EXCEPTION_HANDLER_BEGIN
912 ADD_PROFILING_POINT("main-entered", "point");
915 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
917 // Set environment variables
920 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
922 LogInfo("Entered dummy process mode");
923 sprintf(argv[0], "%s ",
926 // Set 'root' home directory
927 setenv(HOME, ROOT_HOME_PATH, 1);
929 LogInfo("Prepare ewk_context");
930 appcore_set_i18n("wrt-client", NULL);
931 ewk_set_arguments(argc, argv);
932 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
933 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
935 if (s_preparedEwkContext == NULL)
937 LogInfo("Creating webkit context was failed!");
941 int client_fd = __connect_process_pool_server();
945 LogInfo("Connecting process_pool_server was failed!");
949 // register language changed callback
950 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
952 LogInfo("Prepare window_data");
953 // Temporarily change HOME path to app
954 // This change is needed for getting elementary profile
955 // /opt/home/app/.elementary/config/mobile/base.cfg
956 const char* backupEnv = getenv(HOME);
957 setenv(HOME, APP_HOME_PATH, 1);
958 LogInfo("elm_init()");
959 elm_init(argc, argv);
960 setenv(HOME, backupEnv, 1);
962 LogInfo("WindowData()");
963 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
965 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
966 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
967 proces_pool_fd_handler, NULL, NULL, NULL);
969 if (fd_handler == NULL)
971 LogInfo("fd_handler is NULL");
975 setpriority(PRIO_PROCESS, 0, 0);
977 LogDebug("ecore_main_loop_begin()");
978 ecore_main_loop_begin();
979 LogDebug("ecore_main_loop_begin()_end");
981 // deregister language changed callback
982 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
984 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
985 ewk_context_message_post_to_injected_bundle(
986 s_preparedEwkContext,
987 MESSAGE_NAME_INITIALIZE,
992 // This code is to fork a web process without exec.
993 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
994 if (!tizenId.empty()) {
996 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
997 if (pos != std::string::npos) {
1001 LogDebug("Launching by fork mode");
1002 // Language env setup
1003 appcore_set_i18n("wrt-client", NULL);
1004 ewk_set_arguments(argc, argv);
1005 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1006 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1009 if (s_preparedEwkContext == NULL)
1011 LogInfo("Creating webkit context was failed!");
1012 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1017 ewk_context_message_post_to_injected_bundle(
1018 s_preparedEwkContext,
1019 MESSAGE_NAME_INITIALIZE,
1024 // Output on stdout will be flushed after every newline character,
1025 // even if it is redirected to a pipe. This is useful for running
1026 // from a script and parsing output.
1027 // (Standard behavior of stdlib is to use full buffering when
1028 // redirected to a pipe, which means even after an end of line
1029 // the output may not be flushed).
1032 WrtClient app(app_argc, app_argv);
1034 ADD_PROFILING_POINT("Before appExec", "point");
1035 int ret = app.Exec();
1036 LogDebug("App returned: " << ret);
1037 ret = app.getReturnStatus();
1038 LogDebug("WrtClient returned: " << ret);
1041 UNHANDLED_EXCEPTION_HANDLER_END