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 "/usr/lib/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_isFullscreenByPlatform(false),
87 m_submodeSupport(new ClientModule::SubmodeSupport())
90 LogDebug("App Created");
93 WrtClient::~WrtClient()
95 LogDebug("App Finished");
98 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
100 return m_returnStatus;
103 void WrtClient::OnStop()
105 LogDebug("Stopping Dummy Client");
108 void WrtClient::OnCreate()
110 LogDebug("On Create");
111 ADD_PROFILING_POINT("OnCreate callback", "point");
115 void WrtClient::OnResume()
117 if (m_widgetState != WidgetState_Suspended) {
118 LogWarning("Widget is not suspended, resuming was skipped");
122 m_widgetState = WidgetState_Running;
125 void WrtClient::OnPause()
127 if (m_widgetState != WidgetState_Running) {
128 LogWarning("Widget is not running to be suspended");
131 if (m_submodeSupport->isNeedTerminateOnSuspend()) {
132 LogDebug("Current mode cannot support suspend");
137 m_widgetState = WidgetState_Suspended;
140 void WrtClient::OnReset(bundle *b)
143 // bundle argument is freed after OnReset() is returned
144 // So bundle duplication is needed
145 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
146 ApplicationDataSingleton::Instance().setEncodedBundle(b);
148 if (true == m_initializing) {
149 LogDebug("can not handle reset event");
152 if (true == m_launched) {
153 if (m_widgetState == WidgetState_Stopped) {
154 LogError("Widget is not running to be reset");
158 m_widgetState = WidgetState_Running;
161 ClientModule::CommandLineParser::getTizenId(m_argc, m_argv);
162 if (m_tizenId.empty()) {
170 // low memory callback set
171 appcore_set_event_callback(
172 APPCORE_EVENT_LOW_MEMORY,
173 WrtClient::appcoreLowMemoryCallback,
177 void WrtClient::OnTerminate()
179 LogDebug("Wrt Shutdown now");
183 void WrtClient::showHelpAndQuit()
185 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
187 "Mandatory arguments to long options are mandatory for short "
189 " -h, --help show this help\n"
191 "launch widget with given tizen ID\n"
193 "launch widget with given tizen ID\n"
199 void WrtClient::setStep()
203 AddStep(&WrtClient::initStep);
204 AddStep(&WrtClient::launchStep);
205 AddStep(&WrtClient::shutdownStep);
207 m_initializing = true;
209 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
212 void WrtClient::setDebugMode(bundle* b)
214 m_debugMode = ClientModule::IDESupport::getDebugMode(b);
215 LogDebug("debug mode : " << m_debugMode);
218 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
220 LogDebug("Executing next step");
224 void WrtClient::initStep()
227 if (WRT::CoreModuleSingleton::Instance().Init()) {
228 m_initialized = true;
230 m_returnStatus = ReturnStatus::Failed;
231 SwitchToStep(&WrtClient::shutdownStep);
234 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
237 void WrtClient::loadFinishCallback(Evas_Object* webview)
239 ADD_PROFILING_POINT("loadFinishCallback", "start");
242 if (m_splashScreen && m_splashScreen->isShowing())
244 m_splashScreen->stopSplashScreenBuffered();
247 LogDebug("Post result of launch");
249 //w3c packaging test debug (message on 4>)
250 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
251 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
252 FILE* doutput = fdopen(4, "w");
253 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
258 LogDebug("Launch succesfull");
261 m_initializing = false;
263 ADD_PROFILING_POINT("loadFinishCallback", "stop");
264 printf("launched\n");
269 m_returnStatus = ReturnStatus::Failed;
271 DPL::Event::ControllerEventHandler<NextStepEvent>::
272 PostEvent(NextStepEvent());
276 unsigned int portNum =
277 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
278 LogDebug("Port for inspector : " << portNum);
279 bool ret = ClientModule::IDESupport::sendReply(
280 ApplicationDataSingleton::Instance().getBundle(),
283 LogWarning("Fail to send reply");
287 ApplicationDataSingleton::Instance().freeBundle();
290 void WrtClient::resetCallback(bool result)
293 LogDebug("Fail to handle reset event");
295 ApplicationDataSingleton::Instance().freeBundle();
299 void WrtClient::progressStartedCallback()
301 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
302 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
304 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
305 EDJE_SHOW_PROGRESS_SIGNAL,
307 m_windowData->updateProgress(0);
311 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
313 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
314 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
316 m_windowData->updateProgress(value);
320 void WrtClient::progressFinishCallback()
322 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
323 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
325 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
326 EDJE_HIDE_PROGRESS_SIGNAL,
331 void WrtClient::webkitExitCallback()
333 LogDebug("window close called, terminating app");
334 SwitchToStep(&WrtClient::shutdownStep);
335 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
339 void WrtClient::webCrashCallback()
341 LogError("webProcess crashed");
342 SwitchToStep(&WrtClient::shutdownStep);
343 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
347 void WrtClient::enterFullscreenCallback(Evas_Object* /*obj*/,
348 bool isFullscreenByPlatform)
351 m_windowData->toggleFullscreen(true);
352 m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
353 m_isWebkitFullscreen = true;
354 if (isFullscreenByPlatform) {
355 m_isFullscreenByPlatform = true;
359 void WrtClient::exitFullscreenCallback(Evas_Object* /*obj*/)
362 m_windowData->toggleFullscreen(false);
363 m_currentViewMode = m_initialViewMode;
364 m_isWebkitFullscreen = false;
365 m_isFullscreenByPlatform = false;
368 void WrtClient::launchStep()
370 ADD_PROFILING_POINT("launchStep", "start");
371 LogDebug("Launching widget ...");
373 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
374 m_widget = WRT::CoreModuleSingleton::Instance()
375 .getRunnableWidgetObject(m_tizenId);
376 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
379 LogError("RunnableWidgetObject is NULL, stop launchStep");
380 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
385 if (m_widgetState == WidgetState_Running) {
386 LogWarning("Widget already running, stop launchStep");
387 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
392 if (m_widgetState == WidgetState_Authorizing) {
393 LogWarning("Widget already authorizing, stop launchStep");
394 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
399 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
400 WrtDB::WidgetSettings widgetSettings;
401 m_dao->getWidgetSettings(widgetSettings);
402 m_settingList.reset(new WidgetSettingList(widgetSettings));
403 m_submodeSupport->initialize(DPL::FromASCIIString(m_tizenId));
405 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
406 if (!defloc.IsNull()) {
407 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
411 setInitialViewMode();
413 /* remove language change callback */
415 LocalizationSetting::SetLanguageChangedCallback(
416 languageChangedCallback, this);
419 ADD_PROFILING_POINT("CreateWindow", "start");
420 if (s_preparedWindowData == NULL) {
421 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
423 m_windowData.reset(s_preparedWindowData);
424 s_preparedWindowData = NULL;
426 ADD_PROFILING_POINT("CreateWindow", "stop");
427 if (!m_windowData->initScreenReaderSupport(
428 m_settingList->getAccessibility() == Accessibility_Enable))
430 LogWarning("Fail to set screen reader support set");
433 // rotate window to initial value
434 setWindowInitialOrientation();
437 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
439 ADD_PROFILING_POINT("Create splash screen", "start");
440 DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
441 if (!splashImgSrc.IsNull())
443 m_splashScreen.reset(
444 new SplashScreenSupport(
445 m_windowData->getEvasObject(Layer::WINDOW),
446 (DPL::ToUTF8String(*splashImgSrc)).c_str(),
447 m_currentViewMode != VIEWMODE_TYPE_FULLSCREEN,
448 m_settingList->getRotationValue() == Screen_Landscape));
449 m_splashScreen->startSplashScreen();
451 ADD_PROFILING_POINT("Create splash screen", "stop");
453 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
454 if (!m_widget->PrepareView(
455 DPL::ToUTF8String(*startUrl),
456 m_windowData->getEvasObject(Layer::WINDOW),
457 s_preparedEwkContext))
459 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
463 // send rotate information to ewk
464 setEwkInitialOrientation();
466 //you can't show window with splash screen before PrepareView
467 //ewk_view_add_with_context() in viewLogic breaks window
468 m_windowData->init();
469 m_windowData->postInit();
472 if (m_submodeSupport->isInlineMode()) {
473 if (m_submodeSupport->transientWindow(
475 m_windowData->getEvasObject(Layer::WINDOW))))
477 LogDebug("Success to set submode");
479 LogWarning("Fail to set submode");
482 m_windowData->smartCallbackAdd(Layer::FOCUS,
486 m_windowData->smartCallbackAdd(Layer::FOCUS,
491 WrtDB::WidgetLocalizedInfo localizedInfo =
492 W3CFileLocalization::getLocalizedInfo(m_dao);
493 std::string name = "";
494 if (!(localizedInfo.name.IsNull())) {
495 name = DPL::ToUTF8String(*(localizedInfo.name));
497 elm_win_title_set(m_windowData->getEvasObject(Layer::WINDOW),
501 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
503 initializeWindowModes();
505 m_widgetState = WidgetState_Authorizing;
506 if (!m_widget->CheckBeforeLaunch()) {
507 LogError("CheckBeforeLaunch failed, stop launchStep");
508 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
512 LogDebug("Widget launch accepted. Entering running state");
513 m_widgetState = WidgetState_Running;
515 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
516 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
517 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
518 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
519 cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
520 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
521 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
522 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
523 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
524 cbs->enterFullscreen = DPL::MakeDelegate(this, &WrtClient::enterFullscreenCallback);
525 cbs->exitFullscreen = DPL::MakeDelegate(this, &WrtClient::exitFullscreenCallback);
526 cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
527 cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
529 m_widget->SetUserDelegates(cbs);
532 ADD_PROFILING_POINT("launchStep", "stop");
535 void WrtClient::initializeWindowModes()
537 Assert(m_windowData);
539 (m_settingList->getBackButtonPresence() == BackButton_Enable ||
540 m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
541 m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
545 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
546 Elm_Object_Item* /*it*/)
548 LogDebug("BackButtonCallback");
551 WrtClient* This = static_cast<WrtClient*>(data);
552 This->m_widget->Backward();
556 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
558 LogDebug("appcoreLowMemoryCallback");
559 //WrtClient* This = static_cast<WrtClient*>(data);
561 // TODO call RunnableWidgetObject API regarding low memory
562 // The API should be implemented
564 // temporary solution because we have no way to get ewk_context from runnable object.
565 if (s_preparedEwkContext)
567 ewk_context_cache_clear(s_preparedEwkContext);
568 ewk_context_notify_low_memory(s_preparedEwkContext);
574 void WrtClient::setInitialViewMode(void)
577 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
578 FOREACH(it, windowModes) {
579 std::string viewMode = DPL::ToUTF8String(*it);
580 switch(viewMode[0]) {
582 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
583 m_initialViewMode = viewMode;
584 m_currentViewMode = m_initialViewMode;
589 if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
590 m_initialViewMode = viewMode;
591 m_currentViewMode = m_initialViewMode;
596 if (viewMode == VIEWMODE_TYPE_WINDOWED) {
597 m_initialViewMode = viewMode;
598 m_currentViewMode = m_initialViewMode;
608 void WrtClient::setWindowInitialOrientation(void)
610 Assert(m_windowData);
613 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
614 if (rotationValue == Screen_Portrait) {
615 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
616 } else if (rotationValue == Screen_Landscape) {
617 setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
618 } else if (rotationValue == Screen_AutoRotation) {
619 if (!AutoRotationSupport::setAutoRotation(
620 m_windowData->getEvasObject(Layer::WINDOW),
621 autoRotationCallback,
624 LogError("Fail to set auto rotation");
627 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
631 void WrtClient::setWindowOrientation(int angle)
633 Assert(m_windowData);
634 m_windowData->setOrientation(angle);
637 void WrtClient::unsetWindowOrientation(void)
639 Assert(m_windowData);
642 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
643 if (rotationValue == Screen_AutoRotation) {
644 AutoRotationSupport::unsetAutoRotation(
645 m_windowData->getEvasObject(Layer::WINDOW),
646 autoRotationCallback);
650 void WrtClient::setEwkInitialOrientation(void)
655 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
656 if (rotationValue == Screen_Portrait) {
657 ewk_view_orientation_send(
658 m_widget->GetCurrentWebview(),
659 OrientationAngle::W3C::Portrait::PRIMARY);
660 } else if (rotationValue == Screen_Landscape) {
661 ewk_view_orientation_send(
662 m_widget->GetCurrentWebview(),
663 OrientationAngle::W3C::Landscape::PRIMARY);
664 } else if (rotationValue == Screen_AutoRotation) {
665 ewk_view_orientation_send(
666 m_widget->GetCurrentWebview(),
667 OrientationAngle::W3C::Portrait::PRIMARY);
669 ewk_view_orientation_send(
670 m_widget->GetCurrentWebview(),
671 OrientationAngle::W3C::Portrait::PRIMARY);
675 void WrtClient::ExitCallback(void* data,
676 Evas_Object * /*obj*/,
677 void * /*event_info*/)
679 LogInfo("ExitCallback");
682 WrtClient* This = static_cast<WrtClient*>(data);
687 void WrtClient::setCtxpopupItem(void)
689 WindowData::CtxpopupItemDataList data;
692 WindowData::CtxpopupCallbackType shareCallback =
693 DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
694 WindowData::CtxpopupItemData shareData("Share",
699 WindowData::CtxpopupCallbackType reloadCallback =
700 DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
701 WindowData::CtxpopupItemData reloadData("Reload",
705 // 3. Open in browser
706 WindowData::CtxpopupCallbackType launchBrowserCallback =
707 DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
708 WindowData::CtxpopupItemData launchBrowserData("Open in browser",
710 launchBrowserCallback);
711 data.push_back(shareData);
712 data.push_back(reloadData);
713 data.push_back(launchBrowserData);
714 m_windowData->setCtxpopupItemData(data);
717 void WrtClient::ctxpopupShare(void)
720 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
722 LogError("url is empty");
725 if (ClientModule::ServiceSupport::launchShareService(
726 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
733 evas_object_smart_callback_add(m_windowData->m_win,
735 &WrtClient::ExitCallback,
739 void WrtClient::ctxpopupReload(void)
742 ewk_view_reload(m_widget->GetCurrentWebview());
745 void WrtClient::ctxpopupLaunchBrowser(void)
747 LogDebug("launchBrowser");
748 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
750 LogError("url is empty");
753 if (ClientModule::ServiceSupport::launchViewService(
754 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
763 void WrtClient::hwkeyCallback(const std::string& key)
765 if (m_settingList->getBackButtonPresence() == BackButton_Enable
766 || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
768 // windowed UX - hosted application
769 if (key == KeyName::BACK) {
770 if (m_isWebkitFullscreen) {
771 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
773 m_widget->Backward();
775 } else if (key == KeyName::MENU) {
776 // UX isn't confirmed
777 // m_windowData->showCtxpopup();
780 // packaged application
781 if (key == KeyName::BACK) {
782 if (m_isFullscreenByPlatform) {
783 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
789 void WrtClient::setLayout(Evas_Object* webview)
791 LogDebug("add new webkit buffer to window");
793 m_windowData->setWebview(webview);
794 evas_object_show(webview);
795 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
798 void WrtClient::unsetLayout(Evas_Object* webview)
800 LogDebug("remove current webkit buffer from window");
802 evas_object_hide(webview);
803 m_windowData->unsetWebview();
806 void WrtClient::shutdownStep()
808 LogDebug("Closing Wrt connection ...");
810 if (m_widget && m_widgetState) {
811 m_widgetState = WidgetState_Stopped;
813 // AutoRotation, focusCallback use m_widget pointer internally.
814 // It must be unset before m_widget is released.
815 m_submodeSupport->deinitialize();
816 unsetWindowOrientation();
817 m_windowData->smartCallbackDel(Layer::FOCUS,
820 m_windowData->smartCallbackDel(Layer::FOCUS,
824 ewk_context_delete(s_preparedEwkContext);
825 WRT::CoreModuleSingleton::Instance().Terminate();
828 m_initialized = false;
830 m_windowData.reset();
834 void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
841 WrtClient* This = static_cast<WrtClient*>(data);
842 This->autoRotationSetOrientation(obj);
845 void WrtClient::focusedCallback(void* data,
846 Evas_Object* /*obj*/,
851 WrtClient* This = static_cast<WrtClient*>(data);
852 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
855 void WrtClient::unfocusedCallback(void* data,
856 Evas_Object* /*obj*/,
861 WrtClient* This = static_cast<WrtClient*>(data);
862 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
865 void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
870 AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
871 (m_splashScreen) ? m_splashScreen.get(): NULL);
874 int WrtClient::languageChangedCallback(void *data)
876 LogDebug("Language Changed");
880 WrtClient* wrtClient = static_cast<WrtClient*>(data);
881 if (!(wrtClient->m_dao)) {
885 // reset function fetches system locales and recreates language tags
886 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
887 // widget default locales are added to language tags below
888 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
889 if (!defloc.IsNull()) {
890 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
894 if (wrtClient->m_launched &&
895 wrtClient->m_widgetState != WidgetState_Stopped)
897 wrtClient->m_widget->ReloadStartPage();
902 void WrtClient::Quit()
905 DPL::Application::Quit();
908 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
910 int fd = ecore_main_fd_handler_fd_get(handler);
914 LogDebug("ECORE_FD_GET");
918 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
920 LogDebug("ECORE_FD_ERROR");
925 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
927 LogDebug("ECORE_FD_READ");
929 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
930 memset(pkt, 0, AUL_SOCK_MAXBUFF);
932 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
937 LogDebug("recv error!");
942 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
943 ecore_main_fd_handler_del(handler);
944 process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
947 ecore_main_loop_quit();
950 return ECORE_CALLBACK_CANCEL;
953 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
955 LogDebug("VCONFKEY_LANGSET vconf-key was changed!");
957 // When system language is changed, the candidate process will be created again.
964 setenv("COREGL_FASTPATH", "1", 1);
966 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
967 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
968 setenv("ELM_IMAGE_CACHE", "0", 1);
974 // process pool - store arg's value
979 // Mesa does a bad job detecting the correct EGL
980 // platform to use, and ends up assuming that the
981 // wrt-client is using X
982 setenv("EGL_PLATFORM", "wayland", 1);
985 UNHANDLED_EXCEPTION_HANDLER_BEGIN
987 ADD_PROFILING_POINT("main-entered", "point");
990 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
992 // Set environment variables
995 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
997 LogDebug("Entered dummy process mode");
998 sprintf(argv[0], "%s ",
1001 // Set 'root' home directory
1002 setenv(HOME, ROOT_HOME_PATH, 1);
1004 LogDebug("Prepare ewk_context");
1005 appcore_set_i18n("wrt-client", NULL);
1006 ewk_set_arguments(argc, argv);
1007 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1008 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
1010 if (s_preparedEwkContext == NULL)
1012 LogDebug("Creating webkit context was failed!");
1016 int client_fd = __connect_process_pool_server();
1018 if (client_fd == -1)
1020 LogDebug("Connecting process_pool_server was failed!");
1024 // register language changed callback
1025 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
1027 LogDebug("Prepare window_data");
1028 // Temporarily change HOME path to app
1029 // This change is needed for getting elementary profile
1030 // /opt/home/app/.elementary/config/mobile/base.cfg
1031 const char* backupEnv = getenv(HOME);
1032 setenv(HOME, APP_HOME_PATH, 1);
1033 LogDebug("elm_init()");
1034 elm_init(argc, argv);
1035 setenv(HOME, backupEnv, 1);
1037 LogDebug("WindowData()");
1038 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
1040 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
1041 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
1042 proces_pool_fd_handler, NULL, NULL, NULL);
1044 if (fd_handler == NULL)
1046 LogDebug("fd_handler is NULL");
1050 setpriority(PRIO_PROCESS, 0, 0);
1052 LogDebug("ecore_main_loop_begin()");
1053 ecore_main_loop_begin();
1054 LogDebug("ecore_main_loop_begin()_end");
1056 // deregister language changed callback
1057 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
1059 std::string tizenId =
1060 ClientModule::CommandLineParser::getTizenId(argc, argv);
1061 ewk_context_message_post_to_injected_bundle(
1062 s_preparedEwkContext,
1063 MESSAGE_NAME_INITIALIZE,
1069 // This code is to fork a web process without exec.
1070 std::string tizenId =
1071 ClientModule::CommandLineParser::getTizenId(argc, argv);
1073 if (!tizenId.empty()) {
1074 if (UID_ROOT == getuid()) {
1075 // Drop root permission
1076 // Only launch web application by console command case has root permission
1077 if (!ClientModule::SecuritySupport::setAppPrivilege(tizenId)) {
1078 LogError("Fail to set app privilege : [" << tizenId << "]");
1083 LogDebug("Launching by fork mode");
1084 // Language env setup
1085 appcore_set_i18n("wrt-client", NULL);
1086 ewk_set_arguments(argc, argv);
1087 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1088 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1091 if (s_preparedEwkContext == NULL)
1093 LogDebug("Creating webkit context was failed!");
1094 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1099 ewk_context_message_post_to_injected_bundle(
1100 s_preparedEwkContext,
1101 MESSAGE_NAME_INITIALIZE,
1106 // Output on stdout will be flushed after every newline character,
1107 // even if it is redirected to a pipe. This is useful for running
1108 // from a script and parsing output.
1109 // (Standard behavior of stdlib is to use full buffering when
1110 // redirected to a pipe, which means even after an end of line
1111 // the output may not be flushed).
1114 WrtClient app(app_argc, app_argv);
1116 ADD_PROFILING_POINT("Before appExec", "point");
1117 int ret = app.Exec();
1118 LogDebug("App returned: " << ret);
1119 ret = app.getReturnStatus();
1120 LogDebug("WrtClient returned: " << ret);
1123 UNHANDLED_EXCEPTION_HANDLER_END