tizen 2.4 release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / PluginManager / PluginManager.cpp
old mode 100644 (file)
new mode 100755 (executable)
similarity index 94%
rename from src_wearable/modules/tizen/PluginManager/PluginManager.cpp
rename to src/modules/tizen/PluginManager/PluginManager.cpp
index 8e528b1..e56d83d
@@ -33,6 +33,7 @@
 #include <dpl/exception.h>
 #include <dpl/log/secure_log.h>
 #include <dpl/foreach.h>
+#include <CommonsJavaScript/JSLifeManager.h>
 
 using namespace std;
 
@@ -43,7 +44,7 @@ const char* SEPARATOR = ".";
 
 namespace WrtDeviceApis {
 namespace PluginManager {
-PluginManager::PluginManager(int widgetHandle,
+PluginManager::PluginManager(WidgetHandle widgetHandle,
                              const string &objectUri,
                              JSObjectRef object,
                              JSContextRef context) :
@@ -61,7 +62,7 @@ PluginManager::~PluginManager()
 {
     ObjectList::iterator it = m_objectList.begin();
     for (; it != m_objectList.end(); ++it) {
-        JSValueUnprotect(m_context, it->second);
+        JSValueSafeUnprotect(m_context, it->second);
     }
     WrtDB::WrtDatabase::detachFromThread();
 }
@@ -138,6 +139,10 @@ JSValueRef PluginManager::getProperty(const string &name) const
         return it->second;
     }
 
+    if( !hasChild(name) )
+        return JSValueMakeUndefined(m_context);
+
+
     if (!loadChild(name)) {
         ThrowMsg(Commons::PlatformException, "Cannot load plugin");
     }
@@ -155,10 +160,14 @@ bool PluginManager::setProperty(const string &name,
                                 JSValueRef value)
 {
     _D("setProperty %s", name.c_str());
+    if( !hasChild(name) ){
+        return false;
+    }
+
     if (m_objectList.count(name) > 0) {
-        JSValueUnprotect(m_context, m_objectList[name]);
+        JSValueSafeUnprotect(m_context, m_objectList[name]);
     }
-    JSValueProtect(m_context, value);
+    JSValueSafeProtect(m_context, value);
     m_objectList[name] = value;
     return true;
 }
@@ -167,7 +176,7 @@ bool PluginManager::deleteProperty(const string &name)
 {
     if (m_objectList.count(name) > 0) {
         _D("deleteProperty %s", name.c_str());
-        JSValueUnprotect(m_context, m_objectList[name]);
+        JSValueSafeUnprotect(m_context, m_objectList[name]);
         m_objectList.erase(name);
         return true;
     }