Replace LogProvider to Dlog
[platform/framework/web/wrt-plugins-common.git] / src / plugin-loading / plugin_logic.cpp
index c91f309..d3df0da 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <dpl/assert.h>
 #include <dpl/scoped_array.h>
-#include <dpl/log/log.h>
+#include <dpl/log/secure_log.h>
 #include <dpl/foreach.h>
 #include <dpl/singleton_impl.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
@@ -122,7 +122,7 @@ bool PluginLogic::Impl::s_sanityCheck = false;
 #define PLUGIN_LOGIC_SANITY_CHECK \
     if (!s_sanityCheck) \
     { \
-        LogError("Object is not available. Wrong flow occured"); \
+        _E("Object is not available. Wrong flow occured"); \
         return; \
     }
 
@@ -132,7 +132,7 @@ PluginLogic::Impl::Impl() :
     s_sanityCheck = true;
 
     DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
-    LogDebug("Initializing Plugin Logic...");
+    _D("Initializing Plugin Logic...");
     m_pluginsSupport = PluginContainerSupportPtr(new PluginContainerSupport());
 
     // explicit call to keep singleton's lifetime until calling destructor.
@@ -142,17 +142,15 @@ PluginLogic::Impl::Impl() :
 
 PluginLogic::Impl::~Impl()
 {
-    LogDebug("");
+    _D("called");
 
     s_sanityCheck = false;
 
     FOREACH(it, m_sessions)
     {
-        LogError("Must stop widget session before exit!");
+        _W("Must stop widget session before exit!");
         it->second->stopSession();
     }
-
-    LogDebug("Deinitializing plugin Logic...");
 }
 
 void PluginLogic::initSession(int widgetHandle)
@@ -176,7 +174,7 @@ void PluginLogic::stopSession(JSGlobalContextRef context)
 
 void PluginLogic::performLibrariesUnload()
 {
-    LogError("Libraries unload TURNED OFF");
+    _W("This function is DEPRECATED");
     //    m_impl->performLibrariesUnload();
 }
 
@@ -190,14 +188,14 @@ bool PluginLogic::loadPluginOnDemand(
 
 void PluginLogic::loadPluginsIntoIframes(JSGlobalContextRef /*context*/)
 {
-    LogError("This function is Deprecated");
+    _W("This function is DEPRECATED");
 }
 
 void PluginLogic::setCustomProperties(double /*scaleFactor*/,
                                       const char* /*encodedBundle*/,
                                       const char* /*theme*/)
 {
-    LogError("This function is DEPRECATED");
+    _W("This function is DEPRECATED");
 }
 
 void PluginLogic::setCustomProperties(JSGlobalContextRef context,
@@ -210,7 +208,7 @@ void PluginLogic::setCustomProperties(JSGlobalContextRef context,
 
 void PluginLogic::dispatchJavaScriptEvent(CustomEventType /*eventType*/)
 {
-    LogError("This function is DEPRECATED");
+    _W("This function is DEPRECATED");
 }
 
 void PluginLogic::dispatchJavaScriptEvent(JSGlobalContextRef context,
@@ -248,13 +246,9 @@ PluginLogic::~PluginLogic()
 
 void PluginLogic::Impl::initSession(int widgetHandle)
 {
-    LogDebug("init pluginLogic...");
+    _D(">---------------------[init session START]---------------------<");
 
     m_pluginsSupport->Initialize(widgetHandle);
-
-    //add standard objects
-    LogDebug("Preload plugins so file");
-
     PluginContainerSupport::PluginsList rootPluginList =
         m_pluginsSupport->getRootPlugins();
 
@@ -271,20 +265,17 @@ void PluginLogic::Impl::initSession(int widgetHandle)
             pluginLib = Plugin::LoadFromFile(path);
 
             if (!pluginLib) {
-                LogError("Loading library failed");
+                _W("Loading library failed");
             } else {
                 pluginModel->LibraryInstance.Set(pluginLib);
-
-                LogDebug(
-                    "pluginModel->LibraryInstance.Set() : " <<
-                    pluginLib->GetFileName());
+                _D("pluginModel->LibraryInstance.Set() : %s",
+                   pluginLib->GetFileName().c_str());
             }
         } else {
-            LogDebug("Already loaded");
+            _D("Already loaded");
         }
     }
-
-    LogDebug("Preload plugins so file_done");
+    _D("========== init session END ==========");
 }
 
 void PluginLogic::Impl::startSession(int widgetHandle,
@@ -293,7 +284,7 @@ void PluginLogic::Impl::startSession(int widgetHandle,
                                      const char* encodedBundle,
                                      const char* theme)
 {
-    LogDebug("Starting widget session...");
+    _D("========== start session START ==========");
 
     if (!m_pluginsSupport->isInitialized()) {
         m_pluginsSupport->Initialize(widgetHandle);
@@ -302,34 +293,32 @@ void PluginLogic::Impl::startSession(int widgetHandle,
 
     // Check if corresponding session if not already created
     if (sessionIt != m_sessions.end()) {
-        LogWarning("Session already started!");
-        return;
+        _W("Session already started!");
+    } else {
+        auto newSession = JSPageSessionPtr(new JSPageSession(m_pluginsSupport));
+        newSession->startSession(widgetHandle,
+                                 context,
+                                 scaleFactor,
+                                 encodedBundle,
+                                 theme);
+
+        m_sessions[context] = newSession;
     }
-
-    auto newSession = JSPageSessionPtr(new JSPageSession(m_pluginsSupport));
-    newSession->startSession(widgetHandle,
-                             context,
-                             scaleFactor,
-                             encodedBundle,
-                             theme);
-
-    m_sessions[context] = newSession;
+    _D("========== start session END ==========");
 }
 
 void PluginLogic::Impl::stopSession(JSGlobalContextRef context)
 {
-    LogDebug("Stopping widget session...");
+    _D("========== stop session START ==========");
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
-        LogError("Session not exist!");
-        return;
+        _W("Session not exist!");
+    } else {
+        sessionIt->second->stopSession();
+        m_sessions.erase(sessionIt);
     }
-
-    sessionIt->second->stopSession();
-    m_sessions.erase(sessionIt);
-
-    LogDebug("Widget session stopped.");
+    _D("========== stop session END ==========");
 }
 
 bool PluginLogic::Impl::loadPluginOnDemand(
@@ -338,11 +327,11 @@ bool PluginLogic::Impl::loadPluginOnDemand(
     JSGlobalContextRef context
     )
 {
-    LogDebug("Load plugin on demand");
+    _D("========== load ondemand plugin ==========");
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
-        LogWarning("Session not exist!");
+        _W("Session not exist!");
         return false;
     }
 
@@ -353,36 +342,34 @@ bool PluginLogic::Impl::loadPluginOnDemand(
 
 void PluginLogic::Impl::loadFrame(JSGlobalContextRef context)
 {
-    LogDebug("Load a frame");
-
+    _D("========== load frame START ==========");
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
-        LogWarning("Session not exist!");
-        return;
+        _W("Session not exist!");
+    } else {
+        sessionIt->second->loadFrame(context);
     }
-
-    sessionIt->second->loadFrame(context);
+    _D("========== load frame END ==========");
 }
 
 void PluginLogic::Impl::unloadFrame(JSGlobalContextRef context)
 {
-    LogDebug("Unload a frame");
-
+    _D("========== unload frame START ==========");
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
-        return;
-    }
-
-    sessionIt->second->unloadFrame(context);
+    } else {
+        sessionIt->second->unloadFrame(context);
 
-    // I don't know why this session should be removed here.
-    // session list is removed also from stopSession().
-    //m_sessions.erase(sessionIt);
+        // I don't know why this session should be removed here.
+        // session list is removed also from stopSession().
+        //m_sessions.erase(sessionIt);
+        }
+    _D("========== unload frame END ==========");
 }
 
 void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
@@ -390,16 +377,11 @@ void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
                                             const char* encodedBundle,
                                             const char* theme)
 {
-    LogDebug(
-        "set properties of window object " << scaleFactor << ", "
-                                           << encodedBundle << ", " <<
-        theme);
-
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
-        LogWarning("Session not exist!");
+        _W("Session not exist!");
         return;
     }
 
@@ -412,13 +394,11 @@ void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
                                                 CustomEventType eventType,
                                                 void* data)
 {
-    LogDebug("Dispatch event");
-
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
     if (sessionIt == m_sessions.end()) {
-        LogWarning("Session not exist!");
+        _W("Session not exist!");
         return;
     }
 
@@ -427,8 +407,7 @@ void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
 
 unsigned int PluginLogic::Impl::windowHandle() const
 {
-    if (!s_sanityCheck)
-    {
+    if (!s_sanityCheck) {
         LogError("Object is not available. Wrong flow occured");
     }
     return m_windowHandle;
@@ -437,6 +416,5 @@ unsigned int PluginLogic::Impl::windowHandle() const
 void PluginLogic::Impl::setWindowHandle(unsigned int handle)
 {
     PLUGIN_LOGIC_SANITY_CHECK
-    LogDebug("XWindow handle " << handle);
     m_windowHandle = handle;
 }