Tizen 2.0 Release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / PluginManager / PluginManager.cpp
index 53dae94..8f71524 100644 (file)
@@ -26,6 +26,7 @@
 #include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
 #include <dpl/wrt-dao-ro/WrtDatabase.h>
 #include <plugin_logic.h>
+#include <js_types.h>
 #include <dpl/wrt-dao-ro/common_dao_types.h>
 #include <Commons/Exception.h>
 #include <CommonsJavaScript/Converter.h>
@@ -33,6 +34,7 @@
 #include <dpl/log/log.h>
 #include <dpl/foreach.h>
 
+
 using namespace std;
 
 namespace {
@@ -46,13 +48,16 @@ namespace PluginManager {
 
 PluginManager::PluginManager(int widgetHandle,
                              const string &objectUri,
+                             JSObjectRef object,
                              JSContextRef context) :
     m_widgetHandle(widgetHandle),
+    m_objectInstance(object),
     m_objectUri(GLOBAL_OBJECT_NAME),
+    m_shortUri(objectUri),
     m_context(context)
 {
     m_objectUri.append(SEPARATOR).append(objectUri);
-    WrtDB::WrtDatabase::attachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
 }
 
 PluginManager::~PluginManager()
@@ -84,12 +89,13 @@ bool PluginManager::loadChild(const string &name) const
         return false;
     }
 
-    // Create dao
     WrtDB::DbWidgetFeatureSet features;
+    WrtDB::WidgetType widgetType;
     Try
     {
         WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
         features = dao.getFeaturesList();
+        widgetType = dao.getWidgetType();
     }
     Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
     {
@@ -99,10 +105,29 @@ bool PluginManager::loadChild(const string &name) const
         return false;
     }
 
-    FOREACH (it, features) {
-        if (it->pluginId == handle) {
-            PluginLogicSingleton::Instance().addSpecialFeatureToSession(*it);
-            return true;
+    if (widgetType == WrtDB::APP_TYPE_TIZENWEBAPP) {
+        JavaScriptObject jsObject = {m_objectInstance,
+                                          m_shortUri};
+        return PluginLogicSingleton::Instance().loadPluginOnDemand(
+            handle, jsObject, const_cast<JSGlobalContextRef>(m_context));
+    }
+
+    //check does plugin with feature was requested
+    FOREACH (it, features)
+    {
+        if (it->pluginId == handle)
+        {
+            if(it->rejected)
+            {
+                LogWarning("Feature rejected by ACE");
+                continue;
+            }
+
+            JavaScriptObject jsObject = {m_objectInstance,
+                                                      m_shortUri};
+
+            return PluginLogicSingleton::Instance().loadPluginOnDemand(
+                handle, jsObject, const_cast<JSGlobalContextRef>(m_context));
         }
     }
     LogError("Plugin not loaded");
@@ -163,40 +188,75 @@ Api::IPluginManager::PropertyList PluginManager::getProperties() const
 
     m_propertyCache = PropertyList();
 
-    WrtDB::DbWidgetFeatureSet features;
-    Try
+    WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
+    string localUri = m_objectUri + SEPARATOR;
+
+    if (dao.getWidgetType() == WrtDB::APP_TYPE_TIZENWEBAPP)
     {
-        WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
-        features = dao.getFeaturesList();
+        WrtDB::PluginHandleList pluginHandleList =
+            WrtDB::PluginDAOReadOnly::getPluginHandleList();
+
+        FOREACH(it_pluginHandle, pluginHandleList)
+        {
+            WrtDB::ImplementedObjectsList implObjectList =
+                WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+                    *it_pluginHandle);
+
+            FOREACH(it_implObject, implObjectList)
+            {
+                //check if implemented object stats with localUri
+                if (it_implObject->find(localUri) == 0) {
+                    string property = *it_implObject;
+                    //remove local uri that predicts property name.
+                    property.erase(0, localUri.size());
+                    //check if property has its own properties.
+                    size_t pos = property.find(SEPARATOR);
+                    if (pos != string::npos) {
+                        //if so then remove them.
+                        property.erase(pos);
+                    }
+                    m_propertyCache->push_back(property);
+                }
+            }
+        }
     }
-    Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+    else
     {
-        LogError("Cannot get feature list");
-        ReThrow(Commons::PlatformException);
-    }
+        WrtDB::DbWidgetFeatureSet features;
 
-    string localUri = m_objectUri + SEPARATOR;
-    WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
-    for (; feature != features.end(); ++feature) {
-        WrtDB::ImplementedObjectsList implObjs =
-            WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
-                feature->pluginId);
-        FOREACH(it, implObjs) {
-            //check if implemented object stats with localUri
-            if (it->find(localUri) == 0) {
-                string property = *it;
-                //remove local uri that predicts property name.
-                property.erase(0, localUri.size());
-                //check if property has its own properties.
-                size_t pos = property.find(SEPARATOR);
-                if (pos != string::npos) {
-                    //if so then remove them.
-                    property.erase(pos);
+        Try
+        {
+            features = dao.getFeaturesList();
+        }
+        Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+        {
+            LogError("Cannot get feature list");
+            ReThrow(Commons::PlatformException);
+        }
+
+        WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
+        for (; feature != features.end(); ++feature) {
+            WrtDB::ImplementedObjectsList implObjs =
+                WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+                    feature->pluginId);
+            FOREACH(it, implObjs) {
+                //check if implemented object stats with localUri
+                if (it->find(localUri) == 0) {
+                    string property = *it;
+                    //remove local uri that predicts property name.
+                    property.erase(0, localUri.size());
+                    //check if property has its own properties.
+                    size_t pos = property.find(SEPARATOR);
+                    if (pos != string::npos) {
+                        //if so then remove them.
+                        property.erase(pos);
+                    }
+                    m_propertyCache->push_back(property);
                 }
-                m_propertyCache->push_back(property);
             }
         }
     }
+
     return *m_propertyCache;
 }