[Release] wrt-plugins-common_0.3.101
[platform/framework/web/wrt-plugins-common.git] / src / standards / W3C / Widget / JSWidget.cpp
index 8a6843c..f4b9684 100644 (file)
@@ -32,6 +32,9 @@
 #include <LocalStorage/LocalStorageMgr.h>
 #include <Commons/WrtAccess/WrtAccess.h>
 
+// temporary
+extern "C" JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx);
+
 #define CATCH_EXCEPTION_NO_MODIFABLE \
     Catch(Commons::LocalStorageValueNoModifableException) { \
         LogError("The item is read only"); \
@@ -232,12 +235,17 @@ const JSClassDefinition* JSWidget::getClassInfo()
 
 JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
 
-JSContextRef JSWidget::m_globalContext = NULL;
-
 void JSWidget::initialize(JSContextRef context,
                           JSObjectRef object)
 {
-    LogDebug("entered. Context : " << context << ", Object: " << object);
+    JSGlobalContextRef g_context = JSContextGetGlobalContext(context);
+
+    LogDebug("entered. Context : " << context << "(global:" << g_context << "), Object: " << object);
+
+    if (context != g_context)
+    {
+        context = g_context;
+    }
 
     JSWidgetPrivateObject* priv =
         static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
@@ -295,18 +303,6 @@ void JSWidget::finalize(JSObjectRef object)
     }
 }
 
-void JSWidget::acquireGlobalContext(java_script_context_t global_context,
-                                    js_object_instance_t /*iframe*/,
-                                    js_object_instance_t /*object*/)
-{
-    if (!m_globalContext) {
-        m_globalContext = static_cast<JSContextRef>(global_context);
-        LogInfo("Global context acquired.");
-    } else {
-        LogInfo("Global context already set.");
-    }
-}
-
 JSValueRef JSWidget::getAuthor(JSContextRef context,
                                JSObjectRef object,
                                JSStringRef /*propertyName*/,
@@ -550,12 +546,7 @@ JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
                                         JSValueRef* /*exception*/)
 {
     LogDebug("widget constructor");
-    if (!m_globalContext) {
-        LogError("Global context not set. Creating 'widget' object with "
-                 "local context!");
-        return JSObjectMake(context, JSWidget::getClassRef(), NULL);
-    }
-    return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
+    return JSObjectMake(context, JSWidget::getClassRef(), NULL);
 }
 
 #undef CATCH_EXCEPTION_NO_MODIFABLE