[Release] wrt_0.8.274
[platform/framework/web/wrt.git] / src / api_new / core_module.cpp
index fe3571f..d5c07de 100644 (file)
 #include "runnable_widget_object.h"
 #include <string>
 #include <main_thread.h>
-#include <global_context.h>
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
 #include <dpl/exception.h>
-#include <dpl/popup/popup_controller.h>
 #include <dpl/singleton_impl.h>
+#include <dpl/optional_typedefs.h>
 #include "localization_setting.h"
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <profiling_util.h>
 #include <widget_deserialize_model.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
-
-#include <EWebKit2.h>
+#include <dpl/wrt-dao-ro/global_dao_read_only.h>
 
 IMPLEMENT_SINGLETON(WRT::CoreModule)
 
-namespace { //Anonymous
-
-const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
+namespace {
+const char* const TEXT_DOMAIN = "wrt";
+const char* const TEXT_LOCALE_PATH = "/usr/share/wrt-engine/locale";
 
 std::string cutOffFileName(const std::string& path)
 {
@@ -72,37 +70,18 @@ bool checkPaths()
 
     bool if_ok = true;
     if_ok &= (isDir(cutOffFileName(GetWrtDatabaseFilePath())));
-    if (!if_ok) {
-        LogError("Path <" << GetWrtDatabaseFilePath() << "> does not exist.");
-    }
-
     if_ok &= (isDir(GetDevicePluginPath()));
-    if (!if_ok) {
-        LogError("Path <" << GetDevicePluginPath() << "> does not exist.");
-    }
-
-    if_ok &= (isDir(GetFactoryInstalledWidgetPath()));
-    if (!if_ok) {
-        LogError("Path <" << GetFactoryInstalledWidgetPath() <<
-            "> does not exist.");
-    }
-
     if_ok &= (isDir(GetUserInstalledWidgetPath()));
-    if (!if_ok) {
-        LogError("Path <" << GetUserInstalledWidgetPath() <<
-            "> does not exist.");
-    }
     return if_ok;
 }
-}// namespace anonymous
+} // namespace anonymous
 
 namespace WRT {
-
 class CoreModuleImpl
 {
-public:
+  public:
 
-    CoreModuleImpl() : m_initialized(false), m_ewkContext(NULL)
+    CoreModuleImpl() : m_initialized(false)
     {
         LogDebug("enter");
     }
@@ -124,37 +103,9 @@ public:
             }
             Try
             {
-
-                // Needed settings for WKContext are located here
-                // create Ewk_Context
-                Ewk_Context* newEwkContext =
-                    ewk_context_new_with_injected_bundle_path(bundlePath);
-                if (!newEwkContext) {
-                    LogError("Failed to create Ewk_Context");
-                    ThrowMsg(DPL::Exception, "Failed to create ewk context");
-                }
-                    // cache model setting
-                ewk_context_cache_model_set(newEwkContext,
-                                            EWK_CACHE_MODEL_DOCUMENT_BROWSER);
-                m_ewkContext = newEwkContext;
-                ADD_PROFILING_POINT("WebProcess fork", "start");
-
-                // To fork a Webprocess as soon as possible,
-                // the following ewk_api is called explicitly.
-                ewk_context_cookies_policy_set(m_ewkContext,
-                                               EWK_COOKIE_JAR_ACCEPT_ALWAYS);
-                ADD_PROFILING_POINT("WebProcess fork", "stop");
-
-                GlobalContext::TouchArchitecture();
-
                 ADD_PROFILING_POINT("attach databases", "start");
                 MainThreadSingleton::Instance().AttachDatabases();
                 ADD_PROFILING_POINT("attach databases", "stop");
-
-                // Initialize popup manager
-                DPL::Popup::PopupManagerSingleton::Instance().Initialize(
-                    DPL::Popup::PopupRendererPtr(new DPL::Popup::PopupRenderer));
-
                 LogDebug("Initialize finished");
             } catch (const DPL::Exception& ex) {
                 LogError("Internal Error during screen preparation:");
@@ -162,9 +113,10 @@ public:
                 /* TODO:
                  * Do deinitialization: check on which step exception occured
                  * and deinitialize only initialized parts.
-                */
+                 */
                 return false;
             }
+            bindtextdomain(TEXT_DOMAIN, TEXT_LOCALE_PATH);
             m_initialized = true;
         }
         return true;
@@ -172,26 +124,19 @@ public:
 
     void Terminate()
     {
-        if (m_ewkContext) {
-            LogInfo("finalizeEwkContext called");
-            ewk_context_delete(m_ewkContext);
-            m_ewkContext = 0;
-        }
         MainThreadSingleton::Instance().DetachDatabases();
-        // Deinitialize popup manager
-        DPL::Popup::PopupManagerSingleton::Instance().Deinitialize();
-
         m_initialized = false;
     }
 
     RunnableWidgetObjectPtr getRunnableWidgetObject(
-            const std::string& tizenId)
+        const std::string& tizenId)
     {
         try {
             RunnableWidgetObjectPtr runnable;
-            WidgetModelPtr model = Domain::deserializeWidgetModel(tizenId);
+            WidgetModelPtr model =
+                Domain::deserializeWidgetModel(tizenId);
             if (!!model) {
-                runnable.reset(new RunnableWidgetObject(model, m_ewkContext));
+                runnable.reset(new RunnableWidgetObject(model));
             }
             return runnable;
         } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
@@ -200,18 +145,47 @@ public:
         }
     }
 
-private:
+    CoreModule::NetworkAccessMode homeNetworkAccess()
+    {
+        switch (WrtDB::GlobalDAOReadOnly::GetHomeNetworkDataUsage()) {
+        case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
+            return CoreModule::NEVER_CONNECT;
+        case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
+            return CoreModule::ALWAYS_ASK;
+        case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
+            return CoreModule::CONNECT_AUTOMATICALLY;
+        default:
+            break;
+        }
+        LogWarning("using default value");
+        return CoreModule::ALWAYS_ASK;
+    }
+
+    CoreModule::NetworkAccessMode roamingNetworkAccess()
+    {
+        switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
+        case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
+            return CoreModule::NEVER_CONNECT;
+        case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
+            return CoreModule::ALWAYS_ASK;
+        case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
+            return CoreModule::CONNECT_AUTOMATICALLY;
+        default:
+            break;
+        }
+        LogWarning("using default value");
+        return CoreModule::ALWAYS_ASK;
+    }
+
+  private:
     bool m_initialized;
-    Ewk_Context* m_ewkContext;
 };
 
 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
-{
-}
+{}
 
 CoreModule::~CoreModule()
-{
-}
+{}
 
 bool CoreModule::Init()
 {
@@ -224,9 +198,19 @@ void CoreModule::Terminate()
 }
 
 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
-        const std::string& tizenId)
+    const std::string& tizenId)
 {
     return m_impl->getRunnableWidgetObject(tizenId);
 }
 
+CoreModule::NetworkAccessMode CoreModule::homeNetworkAccess()
+{
+    return m_impl->homeNetworkAccess();
+}
+
+CoreModule::NetworkAccessMode CoreModule::roamingNetworkAccess()
+{
+    return m_impl->roamingNetworkAccess();
+}
+
 } /* namespace WRT */