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 <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>
37 #include "auto_rotation_support.h"
39 #include <process_pool.h>
40 #include <process_pool_launchpad_util.h>
42 #include "client_command_line_parser.h"
43 #include "client_ide_support.h"
44 #include "client_security_support.h"
45 #include "client_service_support.h"
46 #include "client_submode_support.h"
48 //W3C PACKAGING enviroment variable name
49 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
51 // window signal callback
52 const char *EDJE_SHOW_PROGRESS_SIGNAL = "show,progress,signal";
53 const char *EDJE_HIDE_PROGRESS_SIGNAL = "hide,progress,signal";
54 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
55 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
56 const std::string VIEWMODE_TYPE_WINDOWED = "windowed";
57 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
58 const char* const BUNDLE_PATH = LIBDIR_PREFIX "/libwrt-injected-bundle.so";
59 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
60 const unsigned int UID_ROOT = 0;
63 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
64 static Ewk_Context* s_preparedEwkContext = NULL;
65 static WindowData* s_preparedWindowData = NULL;
66 static int app_argc = 0;
67 static char** app_argv = NULL;
70 const char* const HOME = "HOME";
71 const char* const APP_HOME_PATH = "/opt/home/app";
72 const char* const ROOT_HOME_PATH = "/opt/home/root";
74 WrtClient::WrtClient(int argc, char **argv) :
75 Application(argc, argv, "wrt-client", false),
76 DPL::TaskDecl<WrtClient>(this),
78 m_initializing(false),
81 m_returnStatus(ReturnStatus::Succeeded),
82 m_widgetState(WidgetState::WidgetState_Stopped),
83 m_initialViewMode(VIEWMODE_TYPE_MAXIMIZED),
84 m_currentViewMode(VIEWMODE_TYPE_MAXIMIZED),
85 m_isWebkitFullscreen(false),
86 m_submodeSupport(new ClientModule::SubmodeSupport())
89 LogDebug("App Created");
92 WrtClient::~WrtClient()
94 LogDebug("App Finished");
97 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
99 return m_returnStatus;
102 void WrtClient::OnStop()
104 LogDebug("Stopping Dummy Client");
107 void WrtClient::OnCreate()
109 LogDebug("On Create");
110 ADD_PROFILING_POINT("OnCreate callback", "point");
114 void WrtClient::OnResume()
116 if (m_widgetState != WidgetState_Suspended) {
117 LogWarning("Widget is not suspended, resuming was skipped");
121 m_widgetState = WidgetState_Running;
124 void WrtClient::OnPause()
126 if (m_widgetState != WidgetState_Running) {
127 LogWarning("Widget is not running to be suspended");
130 if (m_submodeSupport->isNeedTerminateOnSuspend()) {
131 LogDebug("Current mode cannot support suspend");
136 m_widgetState = WidgetState_Suspended;
139 void WrtClient::OnReset(bundle *b)
142 // bundle argument is freed after OnReset() is returned
143 // So bundle duplication is needed
144 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
145 ApplicationDataSingleton::Instance().setEncodedBundle(b);
147 if (true == m_initializing) {
148 LogDebug("can not handle reset event");
151 if (true == m_launched) {
152 if (m_widgetState == WidgetState_Stopped) {
153 LogError("Widget is not running to be reset");
157 m_widgetState = WidgetState_Running;
160 ClientModule::CommandLineParser::getTizenId(m_argc, m_argv);
161 if (m_tizenId.empty()) {
169 // low memory callback set
170 appcore_set_event_callback(
171 APPCORE_EVENT_LOW_MEMORY,
172 WrtClient::appcoreLowMemoryCallback,
176 void WrtClient::OnTerminate()
178 LogDebug("Wrt Shutdown now");
182 void WrtClient::showHelpAndQuit()
184 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
186 "Mandatory arguments to long options are mandatory for short "
188 " -h, --help show this help\n"
190 "launch widget with given tizen ID\n"
192 "launch widget with given tizen ID\n"
198 void WrtClient::setStep()
202 AddStep(&WrtClient::initStep);
203 AddStep(&WrtClient::launchStep);
204 AddStep(&WrtClient::shutdownStep);
206 m_initializing = true;
208 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
211 void WrtClient::setDebugMode(bundle* b)
213 m_debugMode = ClientModule::IDESupport::getDebugMode(b);
214 LogDebug("debug mode : " << m_debugMode);
217 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
219 LogDebug("Executing next step");
223 void WrtClient::initStep()
226 if (WRT::CoreModuleSingleton::Instance().Init()) {
227 m_initialized = true;
229 m_returnStatus = ReturnStatus::Failed;
230 SwitchToStep(&WrtClient::shutdownStep);
233 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
236 void WrtClient::loadFinishCallback(Evas_Object* webview)
238 ADD_PROFILING_POINT("loadFinishCallback", "start");
241 if (m_splashScreen && m_splashScreen->isShowing())
243 m_splashScreen->stopSplashScreenBuffered();
246 LogDebug("Post result of launch");
248 //w3c packaging test debug (message on 4>)
249 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
250 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
251 FILE* doutput = fdopen(4, "w");
252 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
257 LogDebug("Launch succesfull");
260 m_initializing = false;
262 ADD_PROFILING_POINT("loadFinishCallback", "stop");
263 printf("launched\n");
268 m_returnStatus = ReturnStatus::Failed;
270 DPL::Event::ControllerEventHandler<NextStepEvent>::
271 PostEvent(NextStepEvent());
275 unsigned int portNum =
276 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
277 LogDebug("Port for inspector : " << portNum);
278 bool ret = ClientModule::IDESupport::sendReply(
279 ApplicationDataSingleton::Instance().getBundle(),
282 LogWarning("Fail to send reply");
286 ApplicationDataSingleton::Instance().freeBundle();
289 void WrtClient::resetCallback(bool result)
292 LogDebug("Fail to handle reset event");
294 ApplicationDataSingleton::Instance().freeBundle();
298 void WrtClient::progressStartedCallback()
300 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
301 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
303 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
304 EDJE_SHOW_PROGRESS_SIGNAL,
306 m_windowData->updateProgress(0);
310 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
312 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
313 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
315 m_windowData->updateProgress(value);
319 void WrtClient::progressFinishCallback()
321 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
322 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
324 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
325 EDJE_HIDE_PROGRESS_SIGNAL,
330 void WrtClient::webkitExitCallback()
332 LogDebug("window close called, terminating app");
333 SwitchToStep(&WrtClient::shutdownStep);
334 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
338 void WrtClient::webCrashCallback()
340 LogError("webProcess crashed");
341 SwitchToStep(&WrtClient::shutdownStep);
342 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
346 void WrtClient::enterFullscreenCallback(Evas_Object* /*obj*/)
349 m_windowData->toggleFullscreen(true);
350 m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
351 m_isWebkitFullscreen = true;
354 void WrtClient::exitFullscreenCallback(Evas_Object* /*obj*/)
357 m_windowData->toggleFullscreen(false);
358 m_currentViewMode = m_initialViewMode;
359 m_isWebkitFullscreen = false;
362 void WrtClient::launchStep()
364 ADD_PROFILING_POINT("launchStep", "start");
365 LogDebug("Launching widget ...");
367 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
368 m_widget = WRT::CoreModuleSingleton::Instance()
369 .getRunnableWidgetObject(m_tizenId);
370 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
373 LogError("RunnableWidgetObject is NULL, stop launchStep");
374 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
379 if (m_widgetState == WidgetState_Running) {
380 LogWarning("Widget already running, stop launchStep");
381 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
386 if (m_widgetState == WidgetState_Authorizing) {
387 LogWarning("Widget already authorizing, stop launchStep");
388 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
393 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
394 WrtDB::WidgetSettings widgetSettings;
395 m_dao->getWidgetSettings(widgetSettings);
396 m_settingList.reset(new WidgetSettingList(widgetSettings));
397 m_submodeSupport->initialize(DPL::FromASCIIString(m_tizenId));
399 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
400 if (!defloc.IsNull()) {
401 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
405 setInitialViewMode();
407 /* remove language change callback */
409 LocalizationSetting::SetLanguageChangedCallback(
410 languageChangedCallback, this);
413 ADD_PROFILING_POINT("CreateWindow", "start");
414 if (s_preparedWindowData == NULL) {
415 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
417 m_windowData.reset(s_preparedWindowData);
418 s_preparedWindowData = NULL;
420 ADD_PROFILING_POINT("CreateWindow", "stop");
421 if (!m_windowData->initScreenReaderSupport(
422 m_settingList->getAccessibility() == Accessibility_Enable))
424 LogWarning("Fail to set screen reader support set");
427 // rotate window to initial value
428 setWindowInitialOrientation();
431 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
433 ADD_PROFILING_POINT("Create splash screen", "start");
434 DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
435 if (!splashImgSrc.IsNull())
437 m_splashScreen.reset(
438 new SplashScreenSupport(
439 m_windowData->getEvasObject(Layer::WINDOW),
440 (DPL::ToUTF8String(*splashImgSrc)).c_str(),
441 m_currentViewMode != VIEWMODE_TYPE_FULLSCREEN,
442 m_settingList->getRotationValue() == Screen_Landscape));
443 m_splashScreen->startSplashScreen();
445 ADD_PROFILING_POINT("Create splash screen", "stop");
447 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
448 if (!m_widget->PrepareView(
449 DPL::ToUTF8String(*startUrl),
450 m_windowData->getEvasObject(Layer::WINDOW),
451 s_preparedEwkContext))
453 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
457 // send rotate information to ewk
458 setEwkInitialOrientation();
460 //you can't show window with splash screen before PrepareView
461 //ewk_view_add_with_context() in viewLogic breaks window
462 m_windowData->init();
463 m_windowData->postInit();
467 if (m_submodeSupport->isInlineMode()) {
468 if (m_submodeSupport->transientWindow(
470 m_windowData->getEvasObject(Layer::WINDOW))))
472 LogDebug("Success to set submode");
474 LogWarning("Fail to set submode");
478 m_windowData->smartCallbackAdd(Layer::FOCUS,
482 m_windowData->smartCallbackAdd(Layer::FOCUS,
487 WrtDB::WidgetLocalizedInfo localizedInfo =
488 W3CFileLocalization::getLocalizedInfo(m_dao);
489 std::string name = "";
490 if (!(localizedInfo.name.IsNull())) {
491 name = DPL::ToUTF8String(*(localizedInfo.name));
493 elm_win_title_set(m_windowData->getEvasObject(Layer::WINDOW),
497 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
499 initializeWindowModes();
501 m_widgetState = WidgetState_Authorizing;
502 if (!m_widget->CheckBeforeLaunch()) {
503 LogError("CheckBeforeLaunch failed, stop launchStep");
504 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
508 LogDebug("Widget launch accepted. Entering running state");
509 m_widgetState = WidgetState_Running;
511 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
512 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
513 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
514 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
515 cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
516 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
517 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
518 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
519 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
520 cbs->enterFullscreen = DPL::MakeDelegate(this, &WrtClient::enterFullscreenCallback);
521 cbs->exitFullscreen = DPL::MakeDelegate(this, &WrtClient::exitFullscreenCallback);
522 cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
523 cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
525 m_widget->SetUserDelegates(cbs);
528 ADD_PROFILING_POINT("launchStep", "stop");
531 void WrtClient::initializeWindowModes()
533 Assert(m_windowData);
535 (m_settingList->getBackButtonPresence() == BackButton_Enable ||
536 m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
537 m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
541 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
542 Elm_Object_Item* /*it*/)
544 LogDebug("BackButtonCallback");
547 WrtClient* This = static_cast<WrtClient*>(data);
548 This->m_widget->Backward();
552 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
554 LogDebug("appcoreLowMemoryCallback");
555 //WrtClient* This = static_cast<WrtClient*>(data);
557 // TODO call RunnableWidgetObject API regarding low memory
558 // The API should be implemented
560 // temporary solution because we have no way to get ewk_context from runnable object.
561 if (s_preparedEwkContext)
563 ewk_context_cache_clear(s_preparedEwkContext);
564 ewk_context_notify_low_memory(s_preparedEwkContext);
570 void WrtClient::setInitialViewMode(void)
573 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
574 FOREACH(it, windowModes) {
575 std::string viewMode = DPL::ToUTF8String(*it);
576 switch(viewMode[0]) {
578 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
579 m_initialViewMode = viewMode;
580 m_currentViewMode = m_initialViewMode;
585 if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
586 m_initialViewMode = viewMode;
587 m_currentViewMode = m_initialViewMode;
592 if (viewMode == VIEWMODE_TYPE_WINDOWED) {
593 m_initialViewMode = viewMode;
594 m_currentViewMode = m_initialViewMode;
604 void WrtClient::setWindowInitialOrientation(void)
606 Assert(m_windowData);
609 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
610 if (rotationValue == Screen_Portrait) {
611 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
612 } else if (rotationValue == Screen_Landscape) {
613 setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
614 } else if (rotationValue == Screen_AutoRotation) {
615 if (!AutoRotationSupport::setAutoRotation(
616 m_windowData->getEvasObject(Layer::WINDOW),
617 autoRotationCallback,
620 LogError("Fail to set auto rotation");
623 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
627 void WrtClient::setWindowOrientation(int angle)
629 Assert(m_windowData);
630 m_windowData->setOrientation(angle);
633 void WrtClient::unsetWindowOrientation(void)
635 Assert(m_windowData);
638 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
639 if (rotationValue == Screen_AutoRotation) {
640 AutoRotationSupport::unsetAutoRotation(
641 m_windowData->getEvasObject(Layer::WINDOW),
642 autoRotationCallback);
646 void WrtClient::setEwkInitialOrientation(void)
651 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
652 if (rotationValue == Screen_Portrait) {
653 ewk_view_orientation_send(
654 m_widget->GetCurrentWebview(),
655 OrientationAngle::W3C::Portrait::PRIMARY);
656 } else if (rotationValue == Screen_Landscape) {
657 ewk_view_orientation_send(
658 m_widget->GetCurrentWebview(),
659 OrientationAngle::W3C::Landscape::PRIMARY);
660 } else if (rotationValue == Screen_AutoRotation) {
661 ewk_view_orientation_send(
662 m_widget->GetCurrentWebview(),
663 OrientationAngle::W3C::Portrait::PRIMARY);
665 ewk_view_orientation_send(
666 m_widget->GetCurrentWebview(),
667 OrientationAngle::W3C::Portrait::PRIMARY);
671 void WrtClient::setCtxpopupItem(void)
673 WindowData::CtxpopupItemDataList data;
676 WindowData::CtxpopupCallbackType shareCallback =
677 DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
678 WindowData::CtxpopupItemData shareData("Share",
683 WindowData::CtxpopupCallbackType reloadCallback =
684 DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
685 WindowData::CtxpopupItemData reloadData("Reload",
689 // 3. Open in browser
690 WindowData::CtxpopupCallbackType launchBrowserCallback =
691 DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
692 WindowData::CtxpopupItemData launchBrowserData("Open in browser",
694 launchBrowserCallback);
695 data.push_back(shareData);
696 data.push_back(reloadData);
697 data.push_back(launchBrowserData);
698 m_windowData->setCtxpopupItemData(data);
701 void WrtClient::ctxpopupShare(void)
705 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
707 LogError("url is empty");
710 if (ClientModule::ServiceSupport::launchShareService(
711 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
721 void WrtClient::ctxpopupReload(void)
724 ewk_view_reload(m_widget->GetCurrentWebview());
727 void WrtClient::ctxpopupLaunchBrowser(void)
729 LogDebug("launchBrowser");
731 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
733 LogError("url is empty");
736 if (ClientModule::ServiceSupport::launchViewService(
737 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
747 void WrtClient::hwkeyCallback(const std::string& key)
749 if (m_settingList->getBackButtonPresence() == BackButton_Enable
750 || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
752 // windowed UX - hosted application
753 if (key == KeyName::BACK) {
754 if (m_isWebkitFullscreen) {
755 // FIXME!!! This method has not yet landed in the tizen 3.0
756 // webkit-efl source tree
757 //ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
759 m_widget->Backward();
761 } else if (key == KeyName::MENU) {
762 // UX isn't confirmed
763 // m_windowData->showCtxpopup();
768 void WrtClient::setLayout(Evas_Object* webview)
770 LogDebug("add new webkit buffer to window");
772 m_windowData->setWebview(webview);
773 evas_object_show(webview);
776 void WrtClient::unsetLayout(Evas_Object* webview)
778 LogDebug("remove current webkit buffer from window");
780 evas_object_hide(webview);
781 m_windowData->unsetWebview();
784 void WrtClient::shutdownStep()
786 LogDebug("Closing Wrt connection ...");
788 if (m_widget && m_widgetState) {
789 m_widgetState = WidgetState_Stopped;
791 // AutoRotation, focusCallback use m_widget pointer internally.
792 // It must be unset before m_widget is released.
793 m_submodeSupport->deinitialize();
794 unsetWindowOrientation();
795 m_windowData->smartCallbackDel(Layer::FOCUS,
798 m_windowData->smartCallbackDel(Layer::FOCUS,
802 ewk_context_delete(s_preparedEwkContext);
803 WRT::CoreModuleSingleton::Instance().Terminate();
806 m_initialized = false;
808 m_windowData.reset();
812 void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
819 WrtClient* This = static_cast<WrtClient*>(data);
820 This->autoRotationSetOrientation(obj);
823 void WrtClient::focusedCallback(void* data,
824 Evas_Object* /*obj*/,
829 WrtClient* This = static_cast<WrtClient*>(data);
830 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
833 void WrtClient::unfocusedCallback(void* data,
834 Evas_Object* /*obj*/,
839 WrtClient* This = static_cast<WrtClient*>(data);
840 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
843 void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
848 AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
849 (m_splashScreen) ? m_splashScreen.get(): NULL);
852 int WrtClient::languageChangedCallback(void *data)
854 LogDebug("Language Changed");
858 WrtClient* wrtClient = static_cast<WrtClient*>(data);
859 if (!(wrtClient->m_dao)) {
863 // reset function fetches system locales and recreates language tags
864 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
865 // widget default locales are added to language tags below
866 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
867 if (!defloc.IsNull()) {
868 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
872 if (wrtClient->m_launched &&
873 wrtClient->m_widgetState != WidgetState_Stopped)
875 wrtClient->m_widget->ReloadStartPage();
880 void WrtClient::Quit()
883 DPL::Application::Quit();
886 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
888 int fd = ecore_main_fd_handler_fd_get(handler);
892 LogDebug("ECORE_FD_GET");
896 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
898 LogDebug("ECORE_FD_ERROR");
903 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
905 LogDebug("ECORE_FD_READ");
907 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
908 memset(pkt, 0, AUL_SOCK_MAXBUFF);
910 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
915 LogDebug("recv error!");
920 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
921 ecore_main_fd_handler_del(handler);
922 process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
925 ecore_main_loop_quit();
928 return ECORE_CALLBACK_CANCEL;
931 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
933 LogDebug("VCONFKEY_LANGSET vconf-key was changed!");
935 // When system language is changed, the candidate process will be created again.
942 setenv("COREGL_FASTPATH", "1", 1);
944 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
945 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
946 setenv("ELM_IMAGE_CACHE", "0", 1);
952 // process pool - store arg's value
957 // Mesa does a bad job detecting the correct EGL
958 // platform to use, and ends up assuming that the
959 // wrt-client is using X
960 setenv("EGL_PLATFORM", "wayland", 1);
963 UNHANDLED_EXCEPTION_HANDLER_BEGIN
965 ADD_PROFILING_POINT("main-entered", "point");
968 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
970 // Set environment variables
973 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
975 LogDebug("Entered dummy process mode");
976 sprintf(argv[0], "%s ",
979 // Set 'root' home directory
980 setenv(HOME, ROOT_HOME_PATH, 1);
982 LogDebug("Prepare ewk_context");
983 appcore_set_i18n("wrt-client", NULL);
984 ewk_set_arguments(argc, argv);
985 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
986 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
988 if (s_preparedEwkContext == NULL)
990 LogDebug("Creating webkit context was failed!");
994 int client_fd = __connect_process_pool_server();
998 LogDebug("Connecting process_pool_server was failed!");
1002 // register language changed callback
1003 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
1005 LogDebug("Prepare window_data");
1006 // Temporarily change HOME path to app
1007 // This change is needed for getting elementary profile
1008 // /opt/home/app/.elementary/config/mobile/base.cfg
1009 const char* backupEnv = getenv(HOME);
1011 // If getenv return "NULL", set empty string
1014 setenv(HOME, APP_HOME_PATH, 1);
1015 LogDebug("elm_init()");
1016 elm_init(argc, argv);
1017 setenv(HOME, backupEnv, 1);
1019 LogDebug("WindowData()");
1020 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
1022 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
1023 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
1024 proces_pool_fd_handler, NULL, NULL, NULL);
1026 if (fd_handler == NULL)
1028 LogDebug("fd_handler is NULL");
1032 setpriority(PRIO_PROCESS, 0, 0);
1034 LogDebug("ecore_main_loop_begin()");
1035 ecore_main_loop_begin();
1036 LogDebug("ecore_main_loop_begin()_end");
1038 // deregister language changed callback
1039 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
1041 std::string tizenId =
1042 ClientModule::CommandLineParser::getTizenId(argc, argv);
1043 ewk_context_message_post_to_injected_bundle(
1044 s_preparedEwkContext,
1045 MESSAGE_NAME_INITIALIZE,
1051 // This code is to fork a web process without exec.
1052 std::string tizenId =
1053 ClientModule::CommandLineParser::getTizenId(argc, argv);
1055 if (!tizenId.empty()) {
1056 if (UID_ROOT == getuid()) {
1057 // Drop root permission
1058 // Only launch web application by console command case has root permission
1059 if (!ClientModule::SecuritySupport::setAppPrivilege(tizenId)) {
1060 LogError("Fail to set app privilege : [" << tizenId << "]");
1065 LogDebug("Launching by fork mode");
1066 // Language env setup
1067 appcore_set_i18n("wrt-client", NULL);
1068 ewk_set_arguments(argc, argv);
1069 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1070 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1073 if (s_preparedEwkContext == NULL)
1075 LogDebug("Creating webkit context was failed!");
1076 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1081 ewk_context_message_post_to_injected_bundle(
1082 s_preparedEwkContext,
1083 MESSAGE_NAME_INITIALIZE,
1088 // Output on stdout will be flushed after every newline character,
1089 // even if it is redirected to a pipe. This is useful for running
1090 // from a script and parsing output.
1091 // (Standard behavior of stdlib is to use full buffering when
1092 // redirected to a pipe, which means even after an end of line
1093 // the output may not be flushed).
1096 WrtClient app(app_argc, app_argv);
1098 ADD_PROFILING_POINT("Before appExec", "point");
1099 int ret = app.Exec();
1100 LogDebug("App returned: " << ret);
1101 ret = app.getReturnStatus();
1102 LogDebug("WrtClient returned: " << ret);
1105 UNHANDLED_EXCEPTION_HANDLER_END