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"
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 = "/usr/lib/libwrt-injected-bundle.so";
59 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
62 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
63 static Ewk_Context* s_preparedEwkContext = NULL;
64 static WindowData* s_preparedWindowData = NULL;
65 static int app_argc = 0;
66 static char** app_argv = NULL;
69 const char* const HOME = "HOME";
70 const char* const APP_HOME_PATH = "/opt/home/app";
71 const char* const ROOT_HOME_PATH = "/opt/home/root";
73 WrtClient::WrtClient(int argc, char **argv) :
74 Application(argc, argv, "wrt-client", false),
75 DPL::TaskDecl<WrtClient>(this),
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),
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*/,
347 bool isFullscreenByPlatform)
350 m_windowData->toggleFullscreen(true);
351 m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
352 m_isWebkitFullscreen = true;
353 if (isFullscreenByPlatform) {
354 m_isFullscreenByPlatform = true;
358 void WrtClient::exitFullscreenCallback(Evas_Object* /*obj*/)
361 m_windowData->toggleFullscreen(false);
362 m_currentViewMode = m_initialViewMode;
363 m_isWebkitFullscreen = false;
364 m_isFullscreenByPlatform = false;
367 void WrtClient::launchStep()
369 ADD_PROFILING_POINT("launchStep", "start");
370 LogDebug("Launching widget ...");
372 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
373 m_widget = WRT::CoreModuleSingleton::Instance()
374 .getRunnableWidgetObject(m_tizenId);
375 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
378 LogError("RunnableWidgetObject is NULL, stop launchStep");
379 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
384 if (m_widgetState == WidgetState_Running) {
385 LogWarning("Widget already running, stop launchStep");
386 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
391 if (m_widgetState == WidgetState_Authorizing) {
392 LogWarning("Widget already authorizing, stop launchStep");
393 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
398 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
399 WrtDB::WidgetSettings widgetSettings;
400 m_dao->getWidgetSettings(widgetSettings);
401 m_settingList.reset(new WidgetSettingList(widgetSettings));
402 m_submodeSupport->initialize(DPL::FromASCIIString(m_tizenId));
404 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
405 if (!defloc.IsNull()) {
406 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
410 setInitialViewMode();
411 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
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();
470 if (m_submodeSupport->isInlineMode()) {
471 if (m_submodeSupport->transientWindow(
473 m_windowData->getEvasObject(Layer::WINDOW))))
475 LogDebug("Success to set submode");
477 LogWarning("Fail to set submode");
480 m_windowData->smartCallbackAdd(Layer::FOCUS,
484 m_windowData->smartCallbackAdd(Layer::FOCUS,
489 WrtDB::WidgetLocalizedInfo localizedInfo =
490 W3CFileLocalization::getLocalizedInfo(m_dao);
491 std::string name = "";
492 if (!(localizedInfo.name.IsNull())) {
493 name = DPL::ToUTF8String(*(localizedInfo.name));
495 elm_win_title_set(m_windowData->getEvasObject(Layer::WINDOW),
499 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
501 initializeWindowModes();
503 m_widgetState = WidgetState_Authorizing;
504 if (!m_widget->CheckBeforeLaunch()) {
505 LogError("CheckBeforeLaunch failed, stop launchStep");
506 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
510 LogDebug("Widget launch accepted. Entering running state");
511 m_widgetState = WidgetState_Running;
513 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
514 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
515 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
516 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
517 cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
518 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
519 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
520 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
521 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
522 cbs->enterFullscreen = DPL::MakeDelegate(this, &WrtClient::enterFullscreenCallback);
523 cbs->exitFullscreen = DPL::MakeDelegate(this, &WrtClient::exitFullscreenCallback);
524 cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
525 cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
527 m_widget->SetUserDelegates(cbs);
530 ADD_PROFILING_POINT("launchStep", "stop");
533 void WrtClient::initializeWindowModes()
535 Assert(m_windowData);
537 (m_settingList->getBackButtonPresence() == BackButton_Enable ||
538 m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
539 m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
543 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
544 Elm_Object_Item* /*it*/)
546 LogDebug("BackButtonCallback");
549 WrtClient* This = static_cast<WrtClient*>(data);
550 This->m_widget->Backward();
554 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
556 LogDebug("appcoreLowMemoryCallback");
557 //WrtClient* This = static_cast<WrtClient*>(data);
559 // TODO call RunnableWidgetObject API regarding low memory
560 // The API should be implemented
562 // temporary solution because we have no way to get ewk_context from runnable object.
563 if (s_preparedEwkContext)
565 ewk_context_cache_clear(s_preparedEwkContext);
566 ewk_context_notify_low_memory(s_preparedEwkContext);
572 void WrtClient::setInitialViewMode(void)
575 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
576 FOREACH(it, windowModes) {
577 std::string viewMode = DPL::ToUTF8String(*it);
578 switch(viewMode[0]) {
580 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
581 m_initialViewMode = viewMode;
582 m_currentViewMode = m_initialViewMode;
587 if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
588 m_initialViewMode = viewMode;
589 m_currentViewMode = m_initialViewMode;
594 if (viewMode == VIEWMODE_TYPE_WINDOWED) {
595 m_initialViewMode = viewMode;
596 m_currentViewMode = m_initialViewMode;
606 void WrtClient::setWindowInitialOrientation(void)
608 Assert(m_windowData);
611 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
612 if (rotationValue == Screen_Portrait) {
613 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
614 } else if (rotationValue == Screen_Landscape) {
615 setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
616 } else if (rotationValue == Screen_AutoRotation) {
617 if (!AutoRotationSupport::setAutoRotation(
618 m_windowData->getEvasObject(Layer::WINDOW),
619 autoRotationCallback,
622 LogError("Fail to set auto rotation");
625 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
629 void WrtClient::setWindowOrientation(int angle)
631 Assert(m_windowData);
632 m_windowData->setOrientation(angle);
635 void WrtClient::unsetWindowOrientation(void)
637 Assert(m_windowData);
640 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
641 if (rotationValue == Screen_AutoRotation) {
642 AutoRotationSupport::unsetAutoRotation(
643 m_windowData->getEvasObject(Layer::WINDOW),
644 autoRotationCallback);
648 void WrtClient::setEwkInitialOrientation(void)
653 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
654 if (rotationValue == Screen_Portrait) {
655 ewk_view_orientation_send(
656 m_widget->GetCurrentWebview(),
657 OrientationAngle::W3C::Portrait::PRIMARY);
658 } else if (rotationValue == Screen_Landscape) {
659 ewk_view_orientation_send(
660 m_widget->GetCurrentWebview(),
661 OrientationAngle::W3C::Landscape::PRIMARY);
662 } else if (rotationValue == Screen_AutoRotation) {
663 ewk_view_orientation_send(
664 m_widget->GetCurrentWebview(),
665 OrientationAngle::W3C::Portrait::PRIMARY);
667 ewk_view_orientation_send(
668 m_widget->GetCurrentWebview(),
669 OrientationAngle::W3C::Portrait::PRIMARY);
673 void WrtClient::setCtxpopupItem(void)
675 WindowData::CtxpopupItemDataList data;
678 WindowData::CtxpopupCallbackType shareCallback =
679 DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
680 WindowData::CtxpopupItemData shareData("Share",
685 WindowData::CtxpopupCallbackType reloadCallback =
686 DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
687 WindowData::CtxpopupItemData reloadData("Reload",
691 // 3. Open in browser
692 WindowData::CtxpopupCallbackType launchBrowserCallback =
693 DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
694 WindowData::CtxpopupItemData launchBrowserData("Open in browser",
696 launchBrowserCallback);
697 data.push_back(shareData);
698 data.push_back(reloadData);
699 data.push_back(launchBrowserData);
700 m_windowData->setCtxpopupItemData(data);
703 void WrtClient::ctxpopupShare(void)
706 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
708 LogError("url is empty");
711 if (ClientModule::ServiceSupport::launchShareService(
712 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");
730 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
732 LogError("url is empty");
735 if (ClientModule::ServiceSupport::launchViewService(
736 elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
745 void WrtClient::hwkeyCallback(const std::string& key)
747 if (m_settingList->getBackButtonPresence() == BackButton_Enable
748 || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
750 // windowed UX - hosted application
751 if (key == KeyName::BACK) {
752 if (m_isWebkitFullscreen) {
753 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
755 m_widget->Backward();
757 } else if (key == KeyName::MENU) {
758 // UX isn't confirmed
759 // m_windowData->showCtxpopup();
762 // packaged application
763 if (key == KeyName::BACK) {
764 if (m_isFullscreenByPlatform) {
765 ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
771 void WrtClient::setLayout(Evas_Object* webview)
773 LogDebug("add new webkit buffer to window");
775 m_windowData->setWebview(webview);
776 evas_object_show(webview);
777 evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
780 void WrtClient::unsetLayout(Evas_Object* webview)
782 LogDebug("remove current webkit buffer from window");
784 evas_object_hide(webview);
785 m_windowData->unsetWebview();
788 void WrtClient::shutdownStep()
790 LogDebug("Closing Wrt connection ...");
792 if (m_widget && m_widgetState) {
793 m_widgetState = WidgetState_Stopped;
795 // AutoRotation, focusCallback use m_widget pointer internally.
796 // It must be unset before m_widget is released.
797 m_submodeSupport->deinitialize();
798 unsetWindowOrientation();
799 m_windowData->smartCallbackDel(Layer::FOCUS,
802 m_windowData->smartCallbackDel(Layer::FOCUS,
806 ewk_context_delete(s_preparedEwkContext);
807 PrepareExternalStorageSingleton::Instance().Deinitialize();
808 WRT::CoreModuleSingleton::Instance().Terminate();
811 m_initialized = false;
813 m_windowData.reset();
817 void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
824 WrtClient* This = static_cast<WrtClient*>(data);
825 This->autoRotationSetOrientation(obj);
828 void WrtClient::focusedCallback(void* data,
829 Evas_Object* /*obj*/,
834 WrtClient* This = static_cast<WrtClient*>(data);
835 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
838 void WrtClient::unfocusedCallback(void* data,
839 Evas_Object* /*obj*/,
844 WrtClient* This = static_cast<WrtClient*>(data);
845 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
848 void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
853 AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
854 (m_splashScreen) ? m_splashScreen.get(): NULL);
857 int WrtClient::languageChangedCallback(void *data)
859 LogDebug("Language Changed");
863 WrtClient* wrtClient = static_cast<WrtClient*>(data);
864 if (!(wrtClient->m_dao)) {
868 // reset function fetches system locales and recreates language tags
869 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
870 // widget default locales are added to language tags below
871 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
872 if (!defloc.IsNull()) {
873 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
877 if (wrtClient->m_launched &&
878 wrtClient->m_widgetState != WidgetState_Stopped)
880 wrtClient->m_widget->ReloadStartPage();
885 void WrtClient::Quit()
888 DPL::Application::Quit();
891 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
893 int fd = ecore_main_fd_handler_fd_get(handler);
895 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
897 LogDebug("ECORE_FD_ERROR");
905 return ECORE_CALLBACK_CANCEL;
908 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
910 LogDebug("ECORE_FD_READ");
912 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
913 memset(pkt, 0, AUL_SOCK_MAXBUFF);
915 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
924 LogDebug("recv error!");
927 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
929 ecore_main_fd_handler_del(handler);
931 process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
936 ecore_main_loop_quit();
937 return ECORE_CALLBACK_CANCEL;
940 return ECORE_CALLBACK_CANCEL;
943 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
945 LogDebug("VCONFKEY_LANGSET vconf-key was changed!");
947 // When system language is changed, the candidate process will be created again.
954 setenv("COREGL_FASTPATH", "1", 1);
956 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
957 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
958 setenv("ELM_IMAGE_CACHE", "0", 1);
964 // process pool - store arg's value
968 UNHANDLED_EXCEPTION_HANDLER_BEGIN
970 ADD_PROFILING_POINT("main-entered", "point");
973 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
975 // Set environment variables
978 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
980 LogDebug("Entered dummy process mode");
981 sprintf(argv[0], "%s ",
984 // Set 'root' home directory
985 setenv(HOME, ROOT_HOME_PATH, 1);
987 LogDebug("Prepare ewk_context");
988 appcore_set_i18n("wrt-client", NULL);
989 ewk_set_arguments(argc, argv);
990 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
991 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
993 if (s_preparedEwkContext == NULL)
995 LogDebug("Creating webkit context was failed!");
999 int client_fd = __connect_process_pool_server();
1001 if (client_fd == -1)
1003 LogDebug("Connecting process_pool_server was failed!");
1007 // register language changed callback
1008 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
1010 LogDebug("Prepare window_data");
1011 // Temporarily change HOME path to app
1012 // This change is needed for getting elementary profile
1013 // /opt/home/app/.elementary/config/mobile/base.cfg
1014 const char* backupEnv = getenv(HOME);
1015 setenv(HOME, APP_HOME_PATH, 1);
1016 LogDebug("elm_init()");
1017 elm_init(argc, argv);
1018 setenv(HOME, backupEnv, 1);
1020 LogDebug("WindowData()");
1021 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
1023 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
1024 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
1025 proces_pool_fd_handler, NULL, NULL, NULL);
1027 if (fd_handler == NULL)
1029 LogDebug("fd_handler is NULL");
1033 setpriority(PRIO_PROCESS, 0, 0);
1035 LogDebug("ecore_main_loop_begin()");
1036 ecore_main_loop_begin();
1037 LogDebug("ecore_main_loop_begin()_end");
1039 // deregister language changed callback
1040 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
1042 std::string tizenId =
1043 ClientModule::CommandLineParser::getTizenId(argc, argv);
1044 ewk_context_message_post_to_injected_bundle(
1045 s_preparedEwkContext,
1046 MESSAGE_NAME_INITIALIZE,
1052 // This code is to fork a web process without exec.
1053 std::string tizenId =
1054 ClientModule::CommandLineParser::getTizenId(argc, argv);
1056 if (!tizenId.empty()) {
1057 LogDebug("Launching by fork mode");
1058 // Language env setup
1059 appcore_set_i18n("wrt-client", NULL);
1060 ewk_set_arguments(argc, argv);
1061 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1062 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1065 if (s_preparedEwkContext == NULL)
1067 LogDebug("Creating webkit context was failed!");
1068 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1073 ewk_context_message_post_to_injected_bundle(
1074 s_preparedEwkContext,
1075 MESSAGE_NAME_INITIALIZE,
1080 // Output on stdout will be flushed after every newline character,
1081 // even if it is redirected to a pipe. This is useful for running
1082 // from a script and parsing output.
1083 // (Standard behavior of stdlib is to use full buffering when
1084 // redirected to a pipe, which means even after an end of line
1085 // the output may not be flushed).
1088 WrtClient app(app_argc, app_argv);
1090 ADD_PROFILING_POINT("Before appExec", "point");
1091 int ret = app.Exec();
1092 LogDebug("App returned: " << ret);
1093 ret = app.getReturnStatus();
1094 LogDebug("WrtClient returned: " << ret);
1097 UNHANDLED_EXCEPTION_HANDLER_END