Replace LogProvider to Dlog
[platform/framework/web/wrt-plugins-common.git] / src / plugin-loading / plugin_logic.cpp
index c6913b1..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>
@@ -67,7 +67,6 @@ using namespace WrtPlugins::W3C;
 
 namespace {
 const char *LIBRARY_PATH_SEPARATOR = "/";
-const char* FEATURE_WAC20_DEVICAPIS_NAME = "http://wacapps.net/api/deviceapis";
 }
 
 class PluginLogic::Impl
@@ -76,6 +75,7 @@ class PluginLogic::Impl
 
     typedef std::map<JSContextRef, JSPageSessionPtr> PagesSessionsSet;
     PagesSessionsSet m_sessions;
+    unsigned int m_windowHandle;
 
   public:
     Impl();
@@ -109,6 +109,9 @@ class PluginLogic::Impl
                                  CustomEventType eventType,
                                  void* data);
 
+    unsigned int windowHandle() const;
+    void setWindowHandle(unsigned int handle);
+
     static bool s_sanityCheck;
 };
 
@@ -119,16 +122,17 @@ 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; \
     }
 
-PluginLogic::Impl::Impl()
+PluginLogic::Impl::Impl() :
+    m_windowHandle(0)
 {
     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.
@@ -138,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)
@@ -172,7 +174,7 @@ void PluginLogic::stopSession(JSGlobalContextRef context)
 
 void PluginLogic::performLibrariesUnload()
 {
-    LogError("Libraries unload TURNED OFF");
+    _W("This function is DEPRECATED");
     //    m_impl->performLibrariesUnload();
 }
 
@@ -184,16 +186,16 @@ bool PluginLogic::loadPluginOnDemand(
     return m_impl->loadPluginOnDemand(pluginHandle, parentObject, context);
 }
 
-void PluginLogic::loadPluginsIntoIframes(JSGlobalContextRef context)
+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)
+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,
@@ -204,9 +206,9 @@ void PluginLogic::setCustomProperties(JSGlobalContextRef context,
     m_impl->setCustomProperties(context, scaleFactor, encodedBundle, theme);
 }
 
-void PluginLogic::dispatchJavaScriptEvent(CustomEventType eventType)
+void PluginLogic::dispatchJavaScriptEvent(CustomEventType /*eventType*/)
 {
-    LogError("This function is DEPRECATED");
+    _W("This function is DEPRECATED");
 }
 
 void PluginLogic::dispatchJavaScriptEvent(JSGlobalContextRef context,
@@ -226,6 +228,16 @@ void PluginLogic::unloadFrame(JSGlobalContextRef context)
     m_impl->unloadFrame(context);
 }
 
+unsigned int PluginLogic::windowHandle() const
+{
+    return m_impl->windowHandle();
+}
+
+void PluginLogic::setWindowHandle(unsigned int handle)
+{
+    m_impl->setWindowHandle(handle);
+}
+
 PluginLogic::PluginLogic() : m_impl(new PluginLogic::Impl())
 {}
 
@@ -234,25 +246,15 @@ PluginLogic::~PluginLogic()
 
 void PluginLogic::Impl::initSession(int widgetHandle)
 {
-    LogInfo("init pluginLogic...");
+    _D(">---------------------[init session START]---------------------<");
 
     m_pluginsSupport->Initialize(widgetHandle);
+    PluginContainerSupport::PluginsList rootPluginList =
+        m_pluginsSupport->getRootPlugins();
 
-    //add standard objects
-    LogDebug("Preload plugins so file");
-
-    PluginContainerSupport::PluginsList pluginList =
-        m_pluginsSupport->getPluginsList();
-
-    FOREACH(it, pluginList)
+    FOREACH(it, rootPluginList)
     {
         PluginModelPtr& pluginModel = *it;
-
-        if (!pluginModel->LibraryDependencies.Get()->empty()) {
-            // Only Root Object
-            continue;
-        }
-
         PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
 
         if (!pluginLib) {
@@ -263,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,
@@ -285,7 +284,7 @@ void PluginLogic::Impl::startSession(int widgetHandle,
                                      const char* encodedBundle,
                                      const char* theme)
 {
-    LogInfo("Starting widget session...");
+    _D("========== start session START ==========");
 
     if (!m_pluginsSupport->isInitialized()) {
         m_pluginsSupport->Initialize(widgetHandle);
@@ -294,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)
 {
-    LogInfo("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);
-
-    LogInfo("Widget session stopped.");
+    _D("========== stop session END ==========");
 }
 
 bool PluginLogic::Impl::loadPluginOnDemand(
@@ -330,11 +327,11 @@ bool PluginLogic::Impl::loadPluginOnDemand(
     JSGlobalContextRef context
     )
 {
-    LogInfo("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;
     }
 
@@ -345,33 +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;
-    }
+    } else {
+        sessionIt->second->unloadFrame(context);
 
-    sessionIt->second->unloadFrame(context);
-    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,
@@ -379,16 +377,11 @@ void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
                                             const char* encodedBundle,
                                             const char* theme)
 {
-    LogInfo(
-        "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;
     }
 
@@ -401,15 +394,27 @@ 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;
     }
 
     sessionIt->second->dispatchJavaScriptEvent(eventType, data);
 }
+
+unsigned int PluginLogic::Impl::windowHandle() const
+{
+    if (!s_sanityCheck) {
+        LogError("Object is not available. Wrong flow occured");
+    }
+    return m_windowHandle;
+}
+
+void PluginLogic::Impl::setWindowHandle(unsigned int handle)
+{
+    PLUGIN_LOGIC_SANITY_CHECK
+    m_windowHandle = handle;
+}