2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "wrt-client.h"
19 #include <sys/resource.h>
20 #include <appcore-efl.h>
21 #include <appcore-common.h>
25 #include <dpl/log/log.h>
26 #include <dpl/optional_typedefs.h>
27 #include <dpl/exception.h>
28 #include <common/application_data.h>
29 #include <core_module.h>
30 #include <localization_setting.h>
31 #include <widget_deserialize_model.h>
33 #include <dpl/localization/w3c_file_localization.h>
34 #include <dpl/localization/LanguageTagsProvider.h>
35 #include <popup-runner/PopupInvoker.h>
36 #include <prepare_external_storage.h>
38 #include "auto_rotation_support.h"
40 #include <process_pool.h>
41 #include <process_pool_launchpad_util.h>
44 #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_BACKWARD_SIGNAL = "show,backward,signal";
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),
76 m_appControlIndex(DPL::OptionalUInt()),
78 m_initializing(false),
83 m_returnStatus(ReturnStatus::Succeeded),
84 m_widgetState(WidgetState::WidgetState_Stopped),
85 m_initialViewMode(VIEWMODE_TYPE_MAXIMIZED),
86 m_currentViewMode(VIEWMODE_TYPE_MAXIMIZED)
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 LogInfo("Stopping Dummy Client");
107 void WrtClient::OnCreate()
109 LogInfo("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");
131 m_widgetState = WidgetState_Suspended;
134 void WrtClient::OnReset(bundle *b)
137 // bundle argument is freed after OnReset() is returned
138 // So bundle duplication is needed
139 ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
140 ApplicationDataSingleton::Instance().setEncodedBundle(b);
142 if (true == m_initializing) {
143 LogDebug("can not handle reset event");
146 if (true == m_launched) {
147 if (m_widgetState == WidgetState_Stopped) {
148 LogError("Widget is not running to be reset");
152 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
153 m_widgetState = WidgetState_Running;
155 if (true == checkArgument()) {
162 // low memory callback set
163 appcore_set_event_callback(
164 APPCORE_EVENT_LOW_MEMORY,
165 WrtClient::appcoreLowMemoryCallback,
169 void WrtClient::OnTerminate()
171 LogDebug("Wrt Shutdown now");
175 void WrtClient::showHelpAndQuit()
177 printf("Usage: wrt-client [OPTION]... [WIDGET: ID]...\n"
179 "Mandatory arguments to long options are mandatory for short "
181 " -h, --help show this help\n"
183 "launch widget with given tizen ID\n"
185 "launch widget with given tizen ID\n"
191 bool WrtClient::checkArgument()
193 std::string tizenId = getTizenIdFromArgument(m_argc, m_argv);
195 if (tizenId.empty()) {
200 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
201 if (pos != std::string::npos) {
202 std::string id = tizenId.substr(pos);
203 id.erase(strlen(WrtDB::AppControlPrefix::PROCESS_PREFIX));
204 std::stringstream s(id);
205 unsigned int appControlIndex;
206 s >> appControlIndex;
207 m_appControlIndex = appControlIndex;
209 LogDebug("app-control execute-index : " << appControlIndex);
212 LogDebug("Tizen id: " << m_tizenId);
217 std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
219 LogInfo("checkArgument");
220 std::string arg = argv[0];
226 if (arg.find("wrt-client") != std::string::npos) {
233 if (arg == "-h" || arg == "--help") {
235 } else if (arg == "-l" || arg == "--launch" ||
236 arg == "-t" || arg == "--tizen")
246 // Launch widget based on application basename
247 size_t pos = arg.find_last_of('/');
249 if (pos != std::string::npos) {
250 arg = arg.erase(0, pos + 1);
257 void WrtClient::setStep()
261 AddStep(&WrtClient::initStep);
263 setSdkLauncherDebugData();
265 AddStep(&WrtClient::launchStep);
266 AddStep(&WrtClient::shutdownStep);
268 m_initializing = true;
270 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
273 void WrtClient::setSdkLauncherDebugData()
275 LogDebug("setSdkLauncherDebugData");
277 /* check bundle from sdk launcher */
278 bundle *bundleFromSdkLauncher;
279 bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
280 const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
281 const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
282 if (bundle_debug != NULL && bundle_pid != NULL) {
283 if (strcmp(bundle_debug, "true") == 0) {
285 m_sdkLauncherPid = atoi(bundle_pid);
290 bundle_free(bundleFromSdkLauncher);
293 bool WrtClient::checkDebugMode(SDKDebugData* debugData)
295 LogError("Checking for debug mode");
298 bool debugMode = debugData->debugMode;
300 LogInfo("[DEBUG_MODE] Widget is launched in " <<
301 (debugMode ? "DEBUG" : "RETAIL") <<
307 void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
309 LogDebug("Executing next step");
313 void WrtClient::initStep()
316 if (WRT::CoreModuleSingleton::Instance().Init()) {
317 m_initialized = true;
319 m_returnStatus = ReturnStatus::Failed;
320 SwitchToStep(&WrtClient::shutdownStep);
323 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
326 void WrtClient::loadFinishCallback(Evas_Object* webview)
328 ADD_PROFILING_POINT("loadFinishCallback", "start");
331 if (m_splashScreen && m_splashScreen->isShowing())
333 m_splashScreen->stopSplashScreenBuffered();
336 SDKDebugData* debug = new SDKDebugData;
337 debug->debugMode = m_debugMode;
338 debug->pid = new unsigned long(getpid());
340 LogInfo("Post result of launch");
342 // Start inspector server, if current mode is debugger mode.
343 // In the WK2 case, ewk_view_inspector_server_start should
344 // be called after WebProcess is created.
345 if (checkDebugMode(debug)) {
347 ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
348 if (debug->portnum == 0) {
349 LogWarning("Failed to get portnum");
351 LogInfo("Assigned port number for inspector : "
355 LogDebug("Debug mode is disabled");
358 //w3c packaging test debug (message on 4>)
359 const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
360 if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
361 FILE* doutput = fdopen(4, "w");
362 fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
367 LogDebug("Launch succesfull");
370 m_initializing = false;
372 ADD_PROFILING_POINT("loadFinishCallback", "stop");
373 printf("launched\n");
378 m_returnStatus = ReturnStatus::Failed;
380 DPL::Event::ControllerEventHandler<NextStepEvent>::
381 PostEvent(NextStepEvent());
384 if (debug->debugMode) {
385 LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
387 /* send real time signal with result to wrt-launcher */
389 LogDebug("userData->portnum : " << debug->portnum);
390 sv.sival_int = debug->portnum;
395 bundle* request = NULL;
396 appsvc_create_result_bundle(
397 ApplicationDataSingleton::Instance().getBundle(),
399 char port[10] = {0,};
400 sprintf(port, "%d", debug->portnum);
401 appsvc_add_data(request, "port", port);
402 appsvc_send_result(request, APPSVC_RES_OK);
405 ApplicationDataSingleton::Instance().freeBundle();
407 LogDebug("Cleaning wrtClient launch resources...");
412 void WrtClient::resetCallback(bool result)
415 LogDebug("Fail to handle reset event");
417 ApplicationDataSingleton::Instance().freeBundle();
421 void WrtClient::progressStartedCallback()
423 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
424 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
426 m_windowData->emitSignalForUserLayout(EDJE_SHOW_PROGRESS_SIGNAL, "");
427 m_windowData->updateProgress(0);
431 void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
433 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
434 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
436 m_windowData->updateProgress(value);
440 void WrtClient::progressFinishCallback()
442 if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
443 m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
445 m_windowData->emitSignalForUserLayout(EDJE_HIDE_PROGRESS_SIGNAL, "");
449 void WrtClient::webkitExitCallback()
451 LogDebug("window close called, terminating app");
452 SwitchToStep(&WrtClient::shutdownStep);
453 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
457 void WrtClient::webCrashCallback()
459 LogError("webProcess crashed");
460 SwitchToStep(&WrtClient::shutdownStep);
461 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
465 void WrtClient::toggleFullscreenCallback(bool fullscreen)
467 LogError("toggleFullscreen");
471 m_windowData->toggleFullscreen(true);
472 m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
475 m_windowData->toggleFullscreen(false);
476 m_currentViewMode = m_initialViewMode;
480 void WrtClient::launchStep()
482 ADD_PROFILING_POINT("launchStep", "start");
483 LogDebug("Launching widget ...");
485 ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
486 m_widget = WRT::CoreModuleSingleton::Instance()
487 .getRunnableWidgetObject(m_tizenId, m_appControlIndex);
488 ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
491 LogError("RunnableWidgetObject is NULL, stop launchStep");
492 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
497 if (m_widgetState == WidgetState_Running) {
498 LogWarning("Widget already running, stop launchStep");
499 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
504 if (m_widgetState == WidgetState_Authorizing) {
505 LogWarning("Widget already authorizing, stop launchStep");
506 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
511 m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
512 WrtDB::WidgetSettings widgetSettings;
513 m_dao->getWidgetSettings(widgetSettings);
514 m_settingList.reset(new WidgetSettingList(widgetSettings));
516 DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
517 if (!defloc.IsNull()) {
518 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
522 setInitialViewMode();
523 PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
525 /* remove language change callback */
527 LocalizationSetting::SetLanguageChangedCallback(
528 languageChangedCallback, this);
531 ADD_PROFILING_POINT("CreateWindow", "start");
532 if (s_preparedWindowData == NULL) {
533 m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
535 m_windowData.reset(s_preparedWindowData);
536 s_preparedWindowData = NULL;
538 ADD_PROFILING_POINT("CreateWindow", "stop");
540 // rotate window to initial value
541 setWindowInitialOrientation();
544 WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
546 ADD_PROFILING_POINT("Create splash screen", "start");
547 DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
548 if (!splashImgSrc.IsNull())
550 m_splashScreen.reset(new SplashScreenSupport(m_windowData->m_win,
551 (DPL::ToUTF8String(*splashImgSrc)).c_str(),
552 m_currentViewMode != VIEWMODE_TYPE_FULLSCREEN,
553 m_settingList->getRotationValue() == Screen_Landscape));
554 m_splashScreen->startSplashScreen();
556 ADD_PROFILING_POINT("Create splash screen", "stop");
558 DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
559 if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
560 m_windowData->m_win, s_preparedEwkContext))
562 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
566 // send rotate information to ewk
567 setEwkInitialOrientation();
569 //you can't show window with splash screen before PrepareView
570 //ewk_view_add_with_context() in viewLogic breaks window
571 m_windowData->init();
572 m_windowData->focusCallbackAdd("focused", focusedCallback, this);
573 m_windowData->focusCallbackAdd("unfocused", unfocusedCallback, this);
575 WrtDB::WidgetLocalizedInfo localizedInfo =
576 W3CFileLocalization::getLocalizedInfo(m_dao);
577 std::string name = "";
578 if (!(localizedInfo.name.IsNull())) {
579 name = DPL::ToUTF8String(*(localizedInfo.name));
581 elm_win_title_set(m_windowData->m_win, name.c_str());
584 evas_object_show(m_windowData->m_win);
586 initializeWindowModes();
588 m_widgetState = WidgetState_Authorizing;
589 if (!m_widget->CheckBeforeLaunch()) {
590 LogError("CheckBeforeLaunch failed, stop launchStep");
591 DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
595 LogInfo("Widget launch accepted. Entering running state");
596 m_widgetState = WidgetState_Running;
598 cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
599 cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
600 cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
601 cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
602 cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
603 cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
604 cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
605 cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
606 cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
607 cbs->toggleFullscreen = DPL::MakeDelegate(this, &WrtClient::toggleFullscreenCallback);
608 cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
609 cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
611 m_widget->SetUserDelegates(cbs);
613 m_windowData->emitSignalForUserLayout(EDJE_SHOW_BACKWARD_SIGNAL, "");
615 ADD_PROFILING_POINT("launchStep", "stop");
618 void WrtClient::initializeWindowModes()
620 Assert(m_windowData);
622 (m_settingList->getBackButtonPresence() == BackButton_Enable ||
623 m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
624 m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
628 void WrtClient::backButtonCallback(void* data,
629 Evas_Object * /*obj*/,
630 void * /*event_info*/)
632 LogInfo("BackButtonCallback");
635 WrtClient* This = static_cast<WrtClient*>(data);
636 This->m_widget->Backward();
639 Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
640 Elm_Object_Item* /*it*/)
642 LogInfo("BackButtonCallback");
645 WrtClient* This = static_cast<WrtClient*>(data);
646 This->m_widget->Backward();
650 int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
652 LogInfo("appcoreLowMemoryCallback");
653 //WrtClient* This = static_cast<WrtClient*>(data);
655 // TODO call RunnableWidgetObject API regarding low memory
656 // The API should be implemented
661 void WrtClient::setInitialViewMode(void)
664 WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
665 FOREACH(it, windowModes) {
666 std::string viewMode = DPL::ToUTF8String(*it);
667 switch(viewMode[0]) {
669 if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
670 m_initialViewMode = viewMode;
671 m_currentViewMode = m_initialViewMode;
676 if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
677 m_initialViewMode = viewMode;
678 m_currentViewMode = m_initialViewMode;
683 if (viewMode == VIEWMODE_TYPE_WINDOWED) {
684 m_initialViewMode = viewMode;
685 m_currentViewMode = m_initialViewMode;
695 void WrtClient::setWindowInitialOrientation(void)
697 Assert(m_windowData);
700 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
701 if (rotationValue == Screen_Portrait) {
702 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
703 } else if (rotationValue == Screen_Landscape) {
704 setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
705 } else if (rotationValue == Screen_AutoRotation) {
706 if (!AutoRotationSupport::setAutoRotation(m_windowData->m_win,
707 autoRotationCallback,
710 LogError("Fail to set auto rotation");
713 setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
717 void WrtClient::setWindowOrientation(int angle)
719 Assert(m_windowData);
720 m_windowData->setOrientation(angle);
723 void WrtClient::unsetWindowOrientation(void)
725 Assert(m_windowData);
728 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
729 if (rotationValue == Screen_AutoRotation) {
730 AutoRotationSupport::unsetAutoRotation(m_windowData->m_win, autoRotationCallback);
734 void WrtClient::setEwkInitialOrientation(void)
739 WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
740 if (rotationValue == Screen_Portrait) {
741 ewk_view_orientation_send(
742 m_widget->GetCurrentWebview(),
743 OrientationAngle::W3C::Portrait::PRIMARY);
744 } else if (rotationValue == Screen_Landscape) {
745 ewk_view_orientation_send(
746 m_widget->GetCurrentWebview(),
747 OrientationAngle::W3C::Landscape::PRIMARY);
748 } else if (rotationValue == Screen_AutoRotation) {
749 ewk_view_orientation_send(
750 m_widget->GetCurrentWebview(),
751 OrientationAngle::W3C::Portrait::PRIMARY);
753 ewk_view_orientation_send(
754 m_widget->GetCurrentWebview(),
755 OrientationAngle::W3C::Portrait::PRIMARY);
759 void WrtClient::setCtxpopupItem(void)
761 WindowData::CtxpopupItemDataList data;
764 WindowData::CtxpopupCallbackType shareCallback =
765 DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
766 WindowData::CtxpopupItemData shareData("Share",
771 WindowData::CtxpopupCallbackType reloadCallback =
772 DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
773 WindowData::CtxpopupItemData reloadData("Reload",
777 // 3. Open in browser
778 WindowData::CtxpopupCallbackType launchBrowserCallback =
779 DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
780 WindowData::CtxpopupItemData launchBrowserData("Open in browser",
782 launchBrowserCallback);
783 data.push_back(shareData);
784 data.push_back(reloadData);
785 data.push_back(launchBrowserData);
786 m_windowData->setCtxpopupItemData(data);
789 void WrtClient::ctxpopupShare(void)
792 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
794 LogError("url is empty");
797 if (ClientModule::ServiceSupport::launchShareService(
798 elm_win_xwindow_get(m_windowData->m_win),
807 void WrtClient::ctxpopupReload(void)
810 ewk_view_reload(m_widget->GetCurrentWebview());
813 void WrtClient::ctxpopupLaunchBrowser(void)
815 LogDebug("launchBrowser");
816 const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
818 LogError("url is empty");
821 if (ClientModule::ServiceSupport::launchViewService(
822 elm_win_xwindow_get(m_windowData->m_win),
831 void WrtClient::hwkeyCallback(const std::string& key)
833 if (m_settingList->getBackButtonPresence() == BackButton_Enable
834 || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
837 m_widget->Backward();
838 } else if (key == "menu") {
839 // UX isn't confirmed
840 // m_windowData->showCtxpopup();
845 void WrtClient::setLayout(Evas_Object* newBuffer)
847 LogDebug("add new webkit buffer to window");
849 m_windowData->setEvasObjectForLayout(newBuffer);
850 evas_object_show(newBuffer);
853 void WrtClient::unsetLayout(Evas_Object* currentBuffer)
855 LogDebug("remove current webkit buffer from window");
856 Assert(currentBuffer);
857 evas_object_hide(currentBuffer);
858 m_windowData->unsetEvasObjectForLayout();
861 void WrtClient::shutdownStep()
863 LogDebug("Closing Wrt connection ...");
865 if (m_widget && m_widgetState) {
866 m_widgetState = WidgetState_Stopped;
868 // AutoRotation use m_widget pointer internally.
869 // It must be unset before m_widget is released.
870 unsetWindowOrientation();
872 ewk_context_delete(s_preparedEwkContext);
873 PrepareExternalStorageSingleton::Instance().Deinitialize();
874 WRT::CoreModuleSingleton::Instance().Terminate();
877 m_initialized = false;
879 m_windowData->focusCallbackDel("focused", focusedCallback);
880 m_windowData->focusCallbackDel("unfocused", unfocusedCallback);
881 m_windowData.reset();
885 void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
892 WrtClient* This = static_cast<WrtClient*>(data);
894 This->autoRotationSetOrientation(obj);
897 void WrtClient::focusedCallback(void* data,
898 Evas_Object* /*obj*/,
903 WrtClient* This = static_cast<WrtClient*>(data);
904 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
907 void WrtClient::unfocusedCallback(void* data,
908 Evas_Object* /*obj*/,
913 WrtClient* This = static_cast<WrtClient*>(data);
914 elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
917 void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
922 AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
923 (m_splashScreen) ? m_splashScreen.get(): NULL);
926 int WrtClient::languageChangedCallback(void *data)
928 LogDebug("Language Changed");
932 WrtClient* wrtClient = static_cast<WrtClient*>(data);
933 if (!(wrtClient->m_dao)) {
937 // reset function fetches system locales and recreates language tags
938 LanguageTagsProviderSingleton::Instance().resetLanguageTags();
939 // widget default locales are added to language tags below
940 DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
941 if (!defloc.IsNull()) {
942 LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
946 if (wrtClient->m_launched &&
947 wrtClient->m_widgetState != WidgetState_Stopped)
949 wrtClient->m_widget->ReloadStartPage();
954 void WrtClient::Quit()
957 DPL::Application::Quit();
960 static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
962 int fd = ecore_main_fd_handler_fd_get(handler);
964 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
966 LogDebug("ECORE_FD_ERROR");
974 return ECORE_CALLBACK_CANCEL;
977 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
979 LogDebug("ECORE_FD_READ");
981 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
982 memset(pkt, 0, AUL_SOCK_MAXBUFF);
984 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
993 LogDebug("recv error!");
996 LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
998 ecore_main_fd_handler_del(handler);
1000 process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
1005 ecore_main_loop_quit();
1006 return ECORE_CALLBACK_CANCEL;
1009 return ECORE_CALLBACK_CANCEL;
1012 static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
1014 LogInfo("VCONFKEY_LANGSET vconf-key was changed!");
1016 // When system language is changed, the candidate process will be created again.
1022 // set evas backend type
1023 if (!getenv("ELM_ENGINE"))
1025 if (!setenv("ELM_ENGINE", "gl", 1))
1027 LogDebug("Enable backend");
1032 LogDebug("ELM_ENGINE : " << getenv("ELM_ENGINE"));
1035 #ifndef TIZEN_PUBLIC
1036 setenv("COREGL_FASTPATH", "1", 1);
1038 setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
1039 setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
1040 setenv("ELM_IMAGE_CACHE", "0", 1);
1046 // process pool - store arg's value
1050 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1052 ADD_PROFILING_POINT("main-entered", "point");
1055 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
1057 // Set environment variables
1060 if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
1062 LogInfo("Entered dummy process mode");
1063 sprintf(argv[0], "%s ",
1064 DUMMY_PROCESS_PATH);
1066 // Set 'root' home directory
1067 setenv(HOME, ROOT_HOME_PATH, 1);
1069 LogInfo("Prepare ewk_context");
1070 appcore_set_i18n("wrt-client", NULL);
1071 ewk_set_arguments(argc, argv);
1072 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1073 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
1075 if (s_preparedEwkContext == NULL)
1077 LogInfo("Creating webkit context was failed!");
1081 int client_fd = __connect_process_pool_server();
1083 if (client_fd == -1)
1085 LogInfo("Connecting process_pool_server was failed!");
1089 // register language changed callback
1090 vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
1092 LogInfo("Prepare window_data");
1093 // Temporarily change HOME path to app
1094 // This change is needed for getting elementary profile
1095 // /opt/home/app/.elementary/config/mobile/base.cfg
1096 const char* backupEnv = getenv(HOME);
1097 setenv(HOME, APP_HOME_PATH, 1);
1098 LogInfo("elm_init()");
1099 elm_init(argc, argv);
1100 setenv(HOME, backupEnv, 1);
1102 LogInfo("WindowData()");
1103 s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
1105 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
1106 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
1107 proces_pool_fd_handler, NULL, NULL, NULL);
1109 if (fd_handler == NULL)
1111 LogInfo("fd_handler is NULL");
1115 setpriority(PRIO_PROCESS, 0, 0);
1117 LogDebug("ecore_main_loop_begin()");
1118 ecore_main_loop_begin();
1119 LogDebug("ecore_main_loop_begin()_end");
1121 // deregister language changed callback
1122 vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
1124 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
1125 ewk_context_message_post_to_injected_bundle(
1126 s_preparedEwkContext,
1127 MESSAGE_NAME_INITIALIZE,
1133 // This code is to fork a web process without exec.
1134 std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
1135 if (!tizenId.empty()) {
1137 tizenId.find(WrtDB::AppControlPrefix::PROCESS_PREFIX);
1138 if (pos != std::string::npos) {
1142 LogDebug("Launching by fork mode");
1143 // Language env setup
1144 appcore_set_i18n("wrt-client", NULL);
1145 ewk_set_arguments(argc, argv);
1146 setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
1147 s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
1150 if (s_preparedEwkContext == NULL)
1152 LogInfo("Creating webkit context was failed!");
1153 Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
1158 ewk_context_message_post_to_injected_bundle(
1159 s_preparedEwkContext,
1160 MESSAGE_NAME_INITIALIZE,
1165 // Output on stdout will be flushed after every newline character,
1166 // even if it is redirected to a pipe. This is useful for running
1167 // from a script and parsing output.
1168 // (Standard behavior of stdlib is to use full buffering when
1169 // redirected to a pipe, which means even after an end of line
1170 // the output may not be flushed).
1173 WrtClient app(app_argc, app_argv);
1175 ADD_PROFILING_POINT("Before appExec", "point");
1176 int ret = app.Exec();
1177 LogDebug("App returned: " << ret);
1178 ret = app.getReturnStatus();
1179 LogDebug("WrtClient returned: " << ret);
1182 UNHANDLED_EXCEPTION_HANDLER_END