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>
36 #include <prepare_external_storage.h>
38 #include "auto_rotation_support.h"
40 #include <process_pool.h>
41 #include <process_pool_launchpad_util.h>
43 #include "client_command_line_parser.h"
44 #include "client_ide_support.h"
45 #include "client_service_support.h"
47 //W3C PACKAGING enviroment variable name
48 #define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
50 // window signal callback
51 const char *EDJE_SHOW_PROGRESS_SIGNAL = "show,progress,signal";
52 const char *EDJE_HIDE_PROGRESS_SIGNAL = "hide,progress,signal";
53 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
54 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
55 const std::string VIEWMODE_TYPE_WINDOWED = "windowed";
56 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
57 const char* const BUNDLE_PATH = "/usr/lib/libwrt-injected-bundle.so";
58 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
61 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
62 static Ewk_Context* s_preparedEwkContext = NULL;
63 static WindowData* s_preparedWindowData = NULL;
64 static int app_argc = 0;
65 static char** app_argv = NULL;
68 const char* const HOME = "HOME";
69 const char* const APP_HOME_PATH = "/opt/home/app";
70 const char* const ROOT_HOME_PATH = "/opt/home/root";
72 WrtClient::WrtClient(int argc, char **argv) :
73 Application(argc, argv, "wrt-client", false),
74 DPL::TaskDecl<WrtClient>(this),
75 m_appControlIndex(DPL::OptionalUInt()),
77 m_initializing(false),
80 m_returnStatus(ReturnStatus::Succeeded),
81 m_widgetState(WidgetState::WidgetState_Stopped),
82 m_initialViewMode(VIEWMODE_TYPE_MAXIMIZED),
83 m_currentViewMode(VIEWMODE_TYPE_MAXIMIZED),
84 m_isWebkitFullscreen(false),
85 m_isFullscreenByPlatform(false)
88 LogDebug("App Created");
91 WrtClient::~WrtClient()
93 LogDebug("App Finished");
96 WrtClient::ReturnStatus::Type WrtClient::getReturnStatus() const
98 return m_returnStatus;
101 void WrtClient::OnStop()
103 LogDebug("Stopping Dummy Client");
106 void WrtClient::OnCreate()
108 LogDebug("On Create");
109 ADD_PROFILING_POINT("OnCreate callback", "point");
113 void WrtClient::OnResume()
115 if (m_widgetState != WidgetState_Suspended) {
116 LogWarning("Widget is not suspended, resuming was skipped");
120 m_widgetState = WidgetState_Running;
123 void WrtClient::OnPause()
125 if (m_widgetState != WidgetState_Running) {
126 LogWarning("Widget is not running to be suspended");
130 m_widgetState = WidgetState_Suspended;
133 void WrtClient::OnReset(bundle *b)
136 // bundle argument is freed after OnReset() is returned
137 // So bundle duplication is needed
138 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
139 ApplicationDataSingleton::Instance().setEncodedBundle(b);
141 if (true == m_initializing) {
142 LogDebug("can not handle reset event");
145 if (true == m_launched) {
146 if (m_widgetState == WidgetState_Stopped) {
147 LogError("Widget is not running to be reset");
151 m_widgetState = WidgetState_Running;
154 ClientModule::CommandLineParser::getTizenId(m_argc, m_argv);
155 if (m_tizenId.empty()) {
159 ClientModule::CommandLineParser::getAppControlIndex(m_argc,
166 // low memory callback set
167 appcore_set_event_callback(
168 APPCORE_EVENT_LOW_MEMORY,
169 WrtClient::appcoreLowMemoryCallback,
173 void WrtClient::OnTerminate()
175 LogDebug("Wrt Shutdown now");
179 void WrtClient::showHelpAndQuit()
181 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
183 "Mandatory arguments to long options are mandatory for short "
185 " -h, --help show this help\n"
187 "launch widget with given tizen ID\n"
189 "launch widget with given tizen ID\n"
195 void WrtClient::setStep()
199 AddStep(&WrtClient::initStep);
200 AddStep(&WrtClient::launchStep);
201 AddStep(&WrtClient::shutdownStep);
203 m_initializing = true;
205 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
208 void WrtClient::setDebugMode(bundle* b)
210 m_debugMode = ClientModule::IDESupport::getDebugMode(b);
211 LogDebug("debug mode : " << m_debugMode);
214 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
216 LogDebug("Executing next step");
220 void WrtClient::initStep()
223 if (WRT::CoreModuleSingleton::Instance().Init()) {
224 m_initialized = true;
226 m_returnStatus = ReturnStatus::Failed;
227 SwitchToStep(&WrtClient::shutdownStep);
230 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
233 void WrtClient::loadFinishCallback(Evas_Object* webview)
235 ADD_PROFILING_POINT("loadFinishCallback", "start");
238 if (m_splashScreen && m_splashScreen->isShowing())
240 m_splashScreen->stopSplashScreenBuffered();
243 LogDebug("Post result of launch");
245 //w3c packaging test debug (message on 4>)
246 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
247 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
248 FILE* doutput = fdopen(4, "w");
249 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
254 LogDebug("Launch succesfull");
257 m_initializing = false;
259 ADD_PROFILING_POINT("loadFinishCallback", "stop");
260 printf("launched\n");
265 m_returnStatus = ReturnStatus::Failed;
267 DPL::Event::ControllerEventHandler<NextStepEvent>::
268 PostEvent(NextStepEvent());
272 unsigned int portNum =
273 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
274 LogDebug("Port for inspector : " << portNum);
275 bool ret = ClientModule::IDESupport::sendReply(
276 ApplicationDataSingleton::Instance().getBundle(),
279 LogWarning("Fail to send reply");
283 ApplicationDataSingleton::Instance().freeBundle();
286 void WrtClient::resetCallback(bool result)
289 LogDebug("Fail to handle reset event");
291 ApplicationDataSingleton::Instance().freeBundle();
295 void WrtClient::progressStartedCallback()
297 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
298 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
300 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
301 EDJE_SHOW_PROGRESS_SIGNAL,
303 m_windowData->updateProgress(0);
307 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
309 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
310 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
312 m_windowData->updateProgress(value);
316 void WrtClient::progressFinishCallback()
318 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
319 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
321 m_windowData->signalEmit(Layer::MAIN_LAYOUT,
322 EDJE_HIDE_PROGRESS_SIGNAL,
327 void WrtClient::webkitExitCallback()
329 LogDebug("window close called, terminating app");
330 SwitchToStep(&WrtClient::shutdownStep);
331 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
335 void WrtClient::webCrashCallback()
337 LogError("webProcess crashed");
338 SwitchToStep(&WrtClient::shutdownStep);
339 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
343 void WrtClient::enterFullscreenCallback(Evas_Object* /*obj*/,
344 bool isFullscreenByPlatform)
347 m_windowData->toggleFullscreen(true);
348 m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
349 m_isWebkitFullscreen = true;
350 if (isFullscreenByPlatform) {
351 m_isFullscreenByPlatform = true;
355 void WrtClient::exitFullscreenCallback(Evas_Object* /*obj*/)
358 m_windowData->toggleFullscreen(false);
359 m_currentViewMode = m_initialViewMode;
360 m_isWebkitFullscreen = false;
361 m_isFullscreenByPlatform = false;
364 void WrtClient::launchStep()
366 ADD_PROFILING_POINT("launchStep", "start");
367 LogDebug("Launching widget ...");
369 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
370 m_widget = WRT::CoreModuleSingleton::Instance()
371 .getRunnableWidgetObject(m_tizenId, m_appControlIndex);
372 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
375 LogError("RunnableWidgetObject is NULL, stop launchStep");
376 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
381 if (m_widgetState == WidgetState_Running) {
382 LogWarning("Widget already running, stop launchStep");
383 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
388 if (m_widgetState == WidgetState_Authorizing) {
389 LogWarning("Widget already authorizing, stop launchStep");
390 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
395 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
396 WrtDB::WidgetSettings widgetSettings;
397 m_dao->getWidgetSettings(widgetSettings);
398 m_settingList.reset(new WidgetSettingList(widgetSettings));
400 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
401 if (!defloc.IsNull()) {
402 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
406 setInitialViewMode();
407 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
409 /* remove language change callback */
411 LocalizationSetting::SetLanguageChangedCallback(
412 languageChangedCallback, this);
415 ADD_PROFILING_POINT("CreateWindow", "start");
416 if (s_preparedWindowData == NULL) {
417 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
419 m_windowData.reset(s_preparedWindowData);
420 s_preparedWindowData = NULL;
422 ADD_PROFILING_POINT("CreateWindow", "stop");
423 if (!m_windowData->initScreenReaderSupport(
424 m_settingList->getAccessibility() == Accessibility_Enable))
426 LogWarning("Fail to set screen reader support set");
429 // rotate window to initial value
430 setWindowInitialOrientation();
433 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
435 ADD_PROFILING_POINT("Create splash screen", "start");
436 DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
437 if (!splashImgSrc.IsNull())
439 m_splashScreen.reset(
440 new SplashScreenSupport(
441 m_windowData->getEvasObject(Layer::WINDOW),
442 (DPL::ToUTF8String(*splashImgSrc)).c_str(),
443 m_currentViewMode != VIEWMODE_TYPE_FULLSCREEN,
444 m_settingList->getRotationValue() == Screen_Landscape));
445 m_splashScreen->startSplashScreen();
447 ADD_PROFILING_POINT("Create splash screen", "stop");
449 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
450 if (!m_widget->PrepareView(
451 DPL::ToUTF8String(*startUrl),
452 m_windowData->getEvasObject(Layer::WINDOW),
453 s_preparedEwkContext))
455 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
459 // send rotate information to ewk
460 setEwkInitialOrientation();
462 //you can't show window with splash screen before PrepareView
463 //ewk_view_add_with_context() in viewLogic breaks window
464 m_windowData->init();
465 m_windowData->smartCallbackAdd(Layer::FOCUS,
469 m_windowData->smartCallbackAdd(Layer::FOCUS,
474 WrtDB::WidgetLocalizedInfo localizedInfo =
475 W3CFileLocalization::getLocalizedInfo(m_dao);
476 std::string name = "";
477 if (!(localizedInfo.name.IsNull())) {
478 name = DPL::ToUTF8String(*(localizedInfo.name));
480 elm_win_title_set(m_windowData->getEvasObject(Layer::WINDOW),
484 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
486 initializeWindowModes();
488 m_widgetState = WidgetState_Authorizing;
489 if (!m_widget->CheckBeforeLaunch()) {
490 LogError("CheckBeforeLaunch failed, stop launchStep");
491 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
495 LogDebug("Widget launch accepted. Entering running state");
496 m_widgetState = WidgetState_Running;
498 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
499 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
500 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
501 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
502 cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
503 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
504 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
505 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
506 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
507 cbs->enterFullscreen = DPL::MakeDelegate(this, &WrtClient::enterFullscreenCallback);
508 cbs->exitFullscreen = DPL::MakeDelegate(this, &WrtClient::exitFullscreenCallback);
509 cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
510 cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
512 m_widget->SetUserDelegates(cbs);
515 ADD_PROFILING_POINT("launchStep", "stop");
518 void WrtClient::initializeWindowModes()
520 Assert(m_windowData);
522 (m_settingList->getBackButtonPresence() == BackButton_Enable ||
523 m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
524 m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
528 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
529 Elm_Object_Item* /*it*/)
531 LogDebug("BackButtonCallback");
534 WrtClient* This = static_cast<WrtClient*>(data);
535 This->m_widget->Backward();
539 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
541 LogDebug("appcoreLowMemoryCallback");
542 //WrtClient* This = static_cast<WrtClient*>(data);
544 // TODO call RunnableWidgetObject API regarding low memory
545 // The API should be implemented
547 // temporary solution because we have no way to get ewk_context from runnable object.
548 if (s_preparedEwkContext)
550 ewk_context_cache_clear(s_preparedEwkContext);
551 ewk_context_notify_low_memory(s_preparedEwkContext);
557 void WrtClient::setInitialViewMode(void)
560 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
561 FOREACH(it, windowModes) {
562 std::string viewMode = DPL::ToUTF8String(*it);
563 switch(viewMode[0]) {
565 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
566 m_initialViewMode = viewMode;
567 m_currentViewMode = m_initialViewMode;
572 if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
573 m_initialViewMode = viewMode;
574 m_currentViewMode = m_initialViewMode;
579 if (viewMode == VIEWMODE_TYPE_WINDOWED) {
580 m_initialViewMode = viewMode;
581 m_currentViewMode = m_initialViewMode;
591 void WrtClient::setWindowInitialOrientation(void)
593 Assert(m_windowData);
596 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
597 if (rotationValue == Screen_Portrait) {
598 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
599 } else if (rotationValue == Screen_Landscape) {
600 setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
601 } else if (rotationValue == Screen_AutoRotation) {
602 if (!AutoRotationSupport::setAutoRotation(
603 m_windowData->getEvasObject(Layer::WINDOW),
604 autoRotationCallback,
607 LogError("Fail to set auto rotation");
610 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
614 void WrtClient::setWindowOrientation(int angle)
616 Assert(m_windowData);
617 m_windowData->setOrientation(angle);
620 void WrtClient::unsetWindowOrientation(void)
622 Assert(m_windowData);
625 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
626 if (rotationValue == Screen_AutoRotation) {
627 AutoRotationSupport::unsetAutoRotation(
628 m_windowData->getEvasObject(Layer::WINDOW),
629 autoRotationCallback);
633 void WrtClient::setEwkInitialOrientation(void)
638 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
639 if (rotationValue == Screen_Portrait) {
640 ewk_view_orientation_send(
641 m_widget->GetCurrentWebview(),
642 OrientationAngle::W3C::Portrait::PRIMARY);
643 } else if (rotationValue == Screen_Landscape) {
644 ewk_view_orientation_send(
645 m_widget->GetCurrentWebview(),
646 OrientationAngle::W3C::Landscape::PRIMARY);
647 } else if (rotationValue == Screen_AutoRotation) {
648 ewk_view_orientation_send(
649 m_widget->GetCurrentWebview(),
650 OrientationAngle::W3C::Portrait::PRIMARY);
652 ewk_view_orientation_send(
653 m_widget->GetCurrentWebview(),
654 OrientationAngle::W3C::Portrait::PRIMARY);
658 void WrtClient::setCtxpopupItem(void)
660 WindowData::CtxpopupItemDataList data;
663 WindowData::CtxpopupCallbackType shareCallback =
664 DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
665 WindowData::CtxpopupItemData shareData("Share",
670 WindowData::CtxpopupCallbackType reloadCallback =
671 DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
672 WindowData::CtxpopupItemData reloadData("Reload",
676 // 3. Open in browser
677 WindowData::CtxpopupCallbackType launchBrowserCallback =
678 DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
679 WindowData::CtxpopupItemData launchBrowserData("Open in browser",
681 launchBrowserCallback);
682 data.push_back(shareData);
683 data.push_back(reloadData);
684 data.push_back(launchBrowserData);
685 m_windowData->setCtxpopupItemData(data);
688 void WrtClient::ctxpopupShare(void)
691 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
693 LogError("url is empty");
696 if (ClientModule::ServiceSupport::launchShareService(
697 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
706 void WrtClient::ctxpopupReload(void)
709 ewk_view_reload(m_widget->GetCurrentWebview());
712 void WrtClient::ctxpopupLaunchBrowser(void)
714 LogDebug("launchBrowser");
715 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
717 LogError("url is empty");
720 if (ClientModule::ServiceSupport::launchViewService(
721 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
730 void WrtClient::hwkeyCallback(const std::string& key)
732 if (m_settingList->getBackButtonPresence() == BackButton_Enable
733 || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
735 // windowed UX - hosted application
736 if (key == KeyName::BACK) {
737 if (m_isWebkitFullscreen) {
738 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
740 m_widget->Backward();
742 } else if (key == KeyName::MENU) {
743 // UX isn't confirmed
744 // m_windowData->showCtxpopup();
747 // packaged application
748 if (key == KeyName::BACK) {
749 if (m_isFullscreenByPlatform) {
750 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
756 void WrtClient::setLayout(Evas_Object* webview)
758 LogDebug("add new webkit buffer to window");
760 m_windowData->setWebview(webview);
761 evas_object_show(webview);
762 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
765 void WrtClient::unsetLayout(Evas_Object* webview)
767 LogDebug("remove current webkit buffer from window");
769 evas_object_hide(webview);
770 m_windowData->unsetWebview();
773 void WrtClient::shutdownStep()
775 LogDebug("Closing Wrt connection ...");
777 if (m_widget && m_widgetState) {
778 m_widgetState = WidgetState_Stopped;
780 // AutoRotation, focusCallback use m_widget pointer internally.
781 // It must be unset before m_widget is released.
782 unsetWindowOrientation();
783 m_windowData->smartCallbackDel(Layer::FOCUS,
786 m_windowData->smartCallbackDel(Layer::FOCUS,
790 ewk_context_delete(s_preparedEwkContext);
791 PrepareExternalStorageSingleton::Instance().Deinitialize();
792 WRT::CoreModuleSingleton::Instance().Terminate();
795 m_initialized = false;
797 m_windowData.reset();
801 void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
808 WrtClient* This = static_cast<WrtClient*>(data);
809 This->autoRotationSetOrientation(obj);
812 void WrtClient::focusedCallback(void* data,
813 Evas_Object* /*obj*/,
818 WrtClient* This = static_cast<WrtClient*>(data);
819 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
822 void WrtClient::unfocusedCallback(void* data,
823 Evas_Object* /*obj*/,
828 WrtClient* This = static_cast<WrtClient*>(data);
829 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
832 void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
837 AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
838 (m_splashScreen) ? m_splashScreen.get(): NULL);
841 int WrtClient::languageChangedCallback(void *data)
843 LogDebug("Language Changed");
847 WrtClient* wrtClient = static_cast<WrtClient*>(data);
848 if (!(wrtClient->m_dao)) {
852 // reset function fetches system locales and recreates language tags
853 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
854 // widget default locales are added to language tags below
855 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
856 if (!defloc.IsNull()) {
857 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
861 if (wrtClient->m_launched &&
862 wrtClient->m_widgetState != WidgetState_Stopped)
864 wrtClient->m_widget->ReloadStartPage();
869 void WrtClient::Quit()
872 DPL::Application::Quit();
875 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
877 int fd = ecore_main_fd_handler_fd_get(handler);
879 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
881 LogDebug("ECORE_FD_ERROR");
889 return ECORE_CALLBACK_CANCEL;
892 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
894 LogDebug("ECORE_FD_READ");
896 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
897 memset(pkt, 0, AUL_SOCK_MAXBUFF);
899 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
908 LogDebug("recv error!");
911 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
913 ecore_main_fd_handler_del(handler);
915 process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
920 ecore_main_loop_quit();
921 return ECORE_CALLBACK_CANCEL;
924 return ECORE_CALLBACK_CANCEL;
927 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
929 LogDebug("VCONFKEY_LANGSET vconf-key was changed!");
931 // When system language is changed, the candidate process will be created again.
937 // set evas backend type
938 if (!getenv("ELM_ENGINE"))
940 if (!setenv("ELM_ENGINE", "gl", 1))
942 LogDebug("Enable backend");
947 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
951 setenv("COREGL_FASTPATH", "1", 1);
953 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
954 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
955 setenv("ELM_IMAGE_CACHE", "0", 1);
961 // process pool - store arg's value
965 UNHANDLED_EXCEPTION_HANDLER_BEGIN
967 ADD_PROFILING_POINT("main-entered", "point");
970 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
972 // Set environment variables
975 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
977 LogDebug("Entered dummy process mode");
978 sprintf(argv[0], "%s ",
981 // Set 'root' home directory
982 setenv(HOME, ROOT_HOME_PATH, 1);
984 LogDebug("Prepare ewk_context");
985 appcore_set_i18n("wrt-client", NULL);
986 ewk_set_arguments(argc, argv);
987 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
988 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
990 if (s_preparedEwkContext == NULL)
992 LogDebug("Creating webkit context was failed!");
996 int client_fd = __connect_process_pool_server();
1000 LogDebug("Connecting process_pool_server was failed!");
1004 // register language changed callback
1005 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
1007 LogDebug("Prepare window_data");
1008 // Temporarily change HOME path to app
1009 // This change is needed for getting elementary profile
1010 // /opt/home/app/.elementary/config/mobile/base.cfg
1011 const char* backupEnv = getenv(HOME);
1012 setenv(HOME, APP_HOME_PATH, 1);
1013 LogDebug("elm_init()");
1014 elm_init(argc, argv);
1015 setenv(HOME, backupEnv, 1);
1017 LogDebug("WindowData()");
1018 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
1020 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
1021 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
1022 proces_pool_fd_handler, NULL, NULL, NULL);
1024 if (fd_handler == NULL)
1026 LogDebug("fd_handler is NULL");
1030 setpriority(PRIO_PROCESS, 0, 0);
1032 LogDebug("ecore_main_loop_begin()");
1033 ecore_main_loop_begin();
1034 LogDebug("ecore_main_loop_begin()_end");
1036 // deregister language changed callback
1037 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
1039 std::string tizenId =
1040 ClientModule::CommandLineParser::getTizenId(argc, argv);
1041 ewk_context_message_post_to_injected_bundle(
1042 s_preparedEwkContext,
1043 MESSAGE_NAME_INITIALIZE,
1049 // This code is to fork a web process without exec.
1050 std::string tizenId =
1051 ClientModule::CommandLineParser::getTizenId(argc, argv);
1053 if (!tizenId.empty()) {
1054 LogDebug("Launching by fork mode");
1055 // Language env setup
1056 appcore_set_i18n("wrt-client", NULL);
1057 ewk_set_arguments(argc, argv);
1058 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1059 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1062 if (s_preparedEwkContext == NULL)
1064 LogDebug("Creating webkit context was failed!");
1065 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1070 ewk_context_message_post_to_injected_bundle(
1071 s_preparedEwkContext,
1072 MESSAGE_NAME_INITIALIZE,
1077 // Output on stdout will be flushed after every newline character,
1078 // even if it is redirected to a pipe. This is useful for running
1079 // from a script and parsing output.
1080 // (Standard behavior of stdlib is to use full buffering when
1081 // redirected to a pipe, which means even after an end of line
1082 // the output may not be flushed).
1085 WrtClient app(app_argc, app_argv);
1087 ADD_PROFILING_POINT("Before appExec", "point");
1088 int ret = app.Exec();
1089 LogDebug("App returned: " << ret);
1090 ret = app.getReturnStatus();
1091 LogDebug("WrtClient returned: " << ret);
1094 UNHANDLED_EXCEPTION_HANDLER_END