Fix prevent issue
[platform/framework/web/wrt.git] / src / wrt-client / wrt-client.cpp
index 1f62eea..188bf04 100644 (file)
@@ -33,7 +33,6 @@
 #include <dpl/localization/w3c_file_localization.h>
 #include <dpl/localization/LanguageTagsProvider.h>
 #include <popup-runner/PopupInvoker.h>
-#include <prepare_external_storage.h>
 #include <vconf.h>
 #include "auto_rotation_support.h"
 
@@ -42,6 +41,7 @@
 
 #include "client_command_line_parser.h"
 #include "client_ide_support.h"
+#include "client_security_support.h"
 #include "client_service_support.h"
 #include "client_submode_support.h"
 
@@ -57,6 +57,7 @@ const std::string VIEWMODE_TYPE_WINDOWED = "windowed";
 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
 const char* const BUNDLE_PATH = LIBDIR_PREFIX "/usr/lib/libwrt-injected-bundle.so";
 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
+const unsigned int UID_ROOT = 0;
 
 // process pool
 const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
@@ -408,7 +409,6 @@ void WrtClient::launchStep()
     }
 
     setInitialViewMode();
-    PrepareExternalStorageSingleton::Instance().Initialize(m_dao->getTizenPkgId());
 
     /* remove language change callback */
     /*
@@ -468,6 +468,7 @@ void WrtClient::launchStep()
     m_windowData->init();
     m_windowData->postInit();
 
+#if X11
     // sub-mode support
     if (m_submodeSupport->isInlineMode()) {
         if (m_submodeSupport->transientWindow(
@@ -479,6 +480,7 @@ void WrtClient::launchStep()
             LogWarning("Fail to set submode");
         }
     }
+#endif
     m_windowData->smartCallbackAdd(Layer::FOCUS,
                                    "focused",
                                    focusedCallback,
@@ -717,6 +719,7 @@ void WrtClient::setCtxpopupItem(void)
 void WrtClient::ctxpopupShare(void)
 {
     LogDebug("share");
+#ifdef X11
     const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
     if (!url) {
         LogError("url is empty");
@@ -734,6 +737,7 @@ void WrtClient::ctxpopupShare(void)
             "delete,request",
             &WrtClient::ExitCallback,
             this);
+#endif
 }
 
 void WrtClient::ctxpopupReload(void)
@@ -745,6 +749,7 @@ void WrtClient::ctxpopupReload(void)
 void WrtClient::ctxpopupLaunchBrowser(void)
 {
     LogDebug("launchBrowser");
+#ifdef X11
     const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
     if (!url) {
         LogError("url is empty");
@@ -758,6 +763,7 @@ void WrtClient::ctxpopupLaunchBrowser(void)
     } else {
         LogDebug("fail");
     }
+#endif
 }
 
 void WrtClient::hwkeyCallback(const std::string& key)
@@ -768,7 +774,9 @@ void WrtClient::hwkeyCallback(const std::string& key)
         // windowed UX - hosted application
         if (key == KeyName::BACK) {
             if (m_isWebkitFullscreen) {
-                ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
+                // FIXME!!! This method has not yet landed in the tizen 3.0
+                //          webkit-efl source tree
+                //ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
             } else {
                 m_widget->Backward();
             }
@@ -780,7 +788,9 @@ void WrtClient::hwkeyCallback(const std::string& key)
         // packaged application
         if (key == KeyName::BACK) {
             if (m_isFullscreenByPlatform) {
-                ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
+                // FIXME!!! This method has not yet landed in the tizen 3.0
+                //          webkit-efl source tree
+                //ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
             }
         }
     }
@@ -822,7 +832,6 @@ void WrtClient::shutdownStep()
                                        unfocusedCallback);
         m_widget.reset();
         ewk_context_delete(s_preparedEwkContext);
-        PrepareExternalStorageSingleton::Instance().Deinitialize();
         WRT::CoreModuleSingleton::Instance().Terminate();
     }
     if (m_initialized) {
@@ -910,17 +919,17 @@ static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handle
 {
     int fd = ecore_main_fd_handler_fd_get(handler);
 
+    if (fd == -1)
+    {
+        LogDebug("ECORE_FD_GET");
+        exit(-1);
+    }
+
     if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
     {
         LogDebug("ECORE_FD_ERROR");
-
-        if (fd != -1)
-        {
-            close(fd);
-        }
-
+        close(fd);
         exit(-1);
-        return ECORE_CALLBACK_CANCEL;
     }
 
     if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
@@ -931,28 +940,21 @@ static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handle
             memset(pkt, 0, AUL_SOCK_MAXBUFF);
 
             int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
-
-            if (fd != -1)
-            {
-                close(fd);
-            }
+            close(fd);
 
             if (recv_ret == -1)
             {
                 LogDebug("recv error!");
+                free(pkt);
                 exit(-1);
             }
-            LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
 
+            LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
             ecore_main_fd_handler_del(handler);
-
             process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
-
             free(pkt);
         }
-
         ecore_main_loop_quit();
-        return ECORE_CALLBACK_CANCEL;
     }
 
     return ECORE_CALLBACK_CANCEL;
@@ -1037,6 +1039,10 @@ int main(int argc,
             // This change is needed for getting elementary profile
             // /opt/home/app/.elementary/config/mobile/base.cfg
             const char* backupEnv = getenv(HOME);
+            if (!backupEnv) {
+                // If getenv return "NULL", set empty string
+                backupEnv = "";
+            }
             setenv(HOME, APP_HOME_PATH, 1);
             LogDebug("elm_init()");
             elm_init(argc, argv);
@@ -1079,6 +1085,15 @@ int main(int argc,
                 ClientModule::CommandLineParser::getTizenId(argc, argv);
 
             if (!tizenId.empty()) {
+                if (UID_ROOT == getuid()) {
+                    // Drop root permission
+                    // Only launch web application by console command case has root permission
+                    if (!ClientModule::SecuritySupport::setAppPrivilege(tizenId)) {
+                        LogError("Fail to set app privilege : [" << tizenId << "]");
+                        exit(-1);
+                    }
+                }
+
                 LogDebug("Launching by fork mode");
                 // Language env setup
                 appcore_set_i18n("wrt-client", NULL);