merge with master
[platform/framework/web/wrt-plugins-common.git] / src / plugin-loading / plugin_logic.cpp
index 5fb5d70..c3bf0fd 100644 (file)
@@ -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
@@ -77,7 +76,6 @@ class PluginLogic::Impl
     typedef std::map<JSContextRef, JSPageSessionPtr> PagesSessionsSet;
     PagesSessionsSet m_sessions;
 
-
   public:
     Impl();
     ~Impl();
@@ -118,10 +116,10 @@ IMPLEMENT_SINGLETON(PluginLogic);
 bool PluginLogic::Impl::s_sanityCheck = false;
 
 #define PLUGIN_LOGIC_SANITY_CHECK \
-    if(!s_sanityCheck)\
-    {\
-        LogError("Object is not available. Wrong flow occured");\
-        return;\
+    if (!s_sanityCheck) \
+    { \
+        LogError("Object is not available. Wrong flow occured"); \
+        return; \
     }
 
 PluginLogic::Impl::Impl()
@@ -174,7 +172,7 @@ void PluginLogic::stopSession(JSGlobalContextRef context)
 void PluginLogic::performLibrariesUnload()
 {
     LogError("Libraries unload TURNED OFF");
-//    m_impl->performLibrariesUnload();
+    //    m_impl->performLibrariesUnload();
 }
 
 bool PluginLogic::loadPluginOnDemand(
@@ -185,14 +183,14 @@ 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");
 }
 
-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");
 }
@@ -205,7 +203,7 @@ 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");
 }
@@ -228,12 +226,10 @@ void PluginLogic::unloadFrame(JSGlobalContextRef context)
 }
 
 PluginLogic::PluginLogic() : m_impl(new PluginLogic::Impl())
-{
-}
+{}
 
 PluginLogic::~PluginLogic()
-{
-}
+{}
 
 void PluginLogic::Impl::initSession(int widgetHandle)
 {
@@ -245,33 +241,36 @@ void PluginLogic::Impl::initSession(int widgetHandle)
     LogDebug("Preload plugins so file");
 
     PluginContainerSupport::PluginsList pluginList =
-                                          m_pluginsSupport->getPluginsList();
+        m_pluginsSupport->getPluginsList();
 
     FOREACH(it, pluginList)
     {
         PluginModelPtr& pluginModel = *it;
+
+        if (!pluginModel->LibraryDependencies.Get()->empty()) {
+            // Only Root Object
+            continue;
+        }
+
         PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
 
-        if (!pluginLib)
-        {
+        if (!pluginLib) {
             std::string path = pluginModel->LibraryPath.Get() +
-                               std::string(LIBRARY_PATH_SEPARATOR) +
-                               pluginModel->LibraryName.Get();
+                std::string(LIBRARY_PATH_SEPARATOR) +
+                pluginModel->LibraryName.Get();
 
             pluginLib = Plugin::LoadFromFile(path);
 
-            if (!pluginLib)
-            {
+            if (!pluginLib) {
                 LogError("Loading library failed");
-            } else
-            {
+            } else {
                 pluginModel->LibraryInstance.Set(pluginLib);
 
-                LogDebug("pluginModel->LibraryInstance.Set() : " << pluginLib->GetFileName());
+                LogDebug(
+                    "pluginModel->LibraryInstance.Set() : " <<
+                    pluginLib->GetFileName());
             }
-        }
-        else
-        {
+        } else {
             LogDebug("Already loaded");
         }
     }
@@ -287,15 +286,13 @@ void PluginLogic::Impl::startSession(int widgetHandle,
 {
     LogInfo("Starting widget session...");
 
-    if (!m_pluginsSupport->isInitialized())
-    {
+    if (!m_pluginsSupport->isInitialized()) {
         m_pluginsSupport->Initialize(widgetHandle);
     }
     auto sessionIt = m_sessions.find(context);
 
     // Check if corresponding session if not already created
-    if (sessionIt != m_sessions.end())
-    {
+    if (sessionIt != m_sessions.end()) {
         LogWarning("Session already started!");
         return;
     }
@@ -315,8 +312,7 @@ void PluginLogic::Impl::stopSession(JSGlobalContextRef context)
     LogInfo("Stopping widget session...");
 
     auto sessionIt = m_sessions.find(context);
-    if (sessionIt == m_sessions.end())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogError("Session not exist!");
         return;
     }
@@ -336,8 +332,7 @@ bool PluginLogic::Impl::loadPluginOnDemand(
     LogInfo("Load plugin on demand");
 
     auto sessionIt = m_sessions.find(context);
-    if (sessionIt == m_sessions.end())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
         return false;
     }
@@ -354,8 +349,7 @@ void PluginLogic::Impl::loadFrame(JSGlobalContextRef context)
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
-    if (sessionIt == m_sessions.end())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
         return;
     }
@@ -370,14 +364,16 @@ void PluginLogic::Impl::unloadFrame(JSGlobalContextRef context)
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
-    if (sessionIt == m_sessions.end())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
         return;
     }
 
     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);
 }
 
 void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
@@ -385,14 +381,15 @@ void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
                                             const char* encodedBundle,
                                             const char* theme)
 {
-    LogInfo("set properties of window object " << scaleFactor << ", "
-            << encodedBundle << ", " << 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())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
         return;
     }
@@ -400,7 +397,6 @@ void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
     sessionIt->second->setCustomProperties(scaleFactor,
                                            encodedBundle,
                                            theme);
-
 }
 
 void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
@@ -412,13 +408,10 @@ void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
     PLUGIN_LOGIC_SANITY_CHECK
 
     auto sessionIt = m_sessions.find(context);
-    if (sessionIt == m_sessions.end())
-    {
+    if (sessionIt == m_sessions.end()) {
         LogWarning("Session not exist!");
         return;
     }
 
     sessionIt->second->dispatchJavaScriptEvent(eventType, data);
-
-
 }