Revert "Performance improvement of PluginManager with clean up some plugin code."
[platform/framework/web/wrt-plugins-common.git] / src / plugin-loading / explorer.cpp
index 3b385f6..1ecad15 100644 (file)
@@ -28,6 +28,7 @@
 #include "plugin_property_support.h"
 
 // JS overlay
+#include <js_overlay_support.h>
 #include <js_overlay_types.h>
 
 namespace {
@@ -50,6 +51,7 @@ Explorer::Explorer(JSGlobalContextRef context) :
     m_globalObject =
         JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
 
+    LogDebug("Register main frame");
     //register main frame;
     m_iframeSupport.registerIframe(m_globalObject);
 
@@ -63,6 +65,7 @@ Explorer::~Explorer()
 JSObjectPtr Explorer::getJSObjectProperty(const std::string& propertyName,
                                           JSObjectPtr object)
 {
+    LogDebug("Get object property " << propertyName);
     return JavaScriptInterfaceSingleton::Instance().getJSObjectProperty(
                m_context, object, propertyName);
 }
@@ -108,11 +111,15 @@ JSObjectPtr Explorer::getProperty(
 bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
                               JSGlobalContextRef context)
 {
+    LogDebug("Register to global object");
+
     bool retValue;
 
     if (declaration->getParentName() == GLOBAL_OBJECT_NAME) {
+        LogDebug("Connect to Global object");
         retValue = register_(declaration, m_globalObject, context);
     } else { //PIM support
+        LogDebug("Connect to NOT global object");
         //it should be master object name
         string masterName = declaration->getParentName();
         auto pos = masterName.find(".");
@@ -131,10 +138,13 @@ bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
     }
 
     if (declaration->checkIframesSupported()) {
+        LogDebug("Iframe supported");
         m_iframeSupport.registerDeclaration(declaration);
         //        m_iframeSupport.invokeCallbackForMainFrame(m_context,
         //                                                   declaration,
         //                                                   newObject);
+    } else {
+        LogDebug("Iframe NOT supported");
     }
 
     return retValue;
@@ -145,16 +155,19 @@ bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
                               JSObjectPtr providedObject,
                               JSGlobalContextRef context)
 {
-    LogDebug("'" << providedObjectName << "' <- '" << declaration->getName() << "'");
+    LogDebug(
+        "Register object. Provided object name: '" << providedObjectName
+                                                   <<
+        "', registration of: '" << declaration->getName() << "'");
 
     std::string fullParentName = declaration->getParentName();
+    LogDebug("Parent name: " << declaration->getParentName());
 
     if (fullParentName == providedObjectName) {
+        LogDebug("Provided object match equaly to requested parent");
         return register_(declaration, providedObject, context);
     }
 
-    LogDebug("Provided object was not matched!!");
-
     //check if object exists in fullParentName
     auto pos = fullParentName.find(providedObjectName);
     if (pos == string::npos) {
@@ -206,14 +219,43 @@ bool Explorer::register_(const JSObjectDeclarationPtr& declaration,
     typedef JSObjectDeclaration::Options JO;
 
     JSGlobalContextRef gContext = (context == NULL) ? m_context : context;
+    JSObjectPtr newObject;
+
     JSObjectPtr objectInstance = JavaScriptInterfaceSingleton::Instance().
             createObject(gContext, declaration);
 
+    //function creation
+    if (declaration->getOptions() &&
+        declaration->getOptions()->getType() == JO::ClassType::Function)
+    {
+        LogDebug("Loading function object " << declaration->getName());
+
+        auto type = declaration->getOptions()->getIframeOverlay();
+        if (JO::IFrameOverlay::OverlayedBeforeOriginal == type) {
+            LogDebug("Create overlayed function");
+            JSObjectPtr original =
+                JavaScriptInterfaceSingleton::Instance().
+                    getJSObjectProperty(gContext,
+                                        parent,
+                                        declaration->getName());
+            newObject = JSOverlaySupport::
+                    createWrappedFunction(gContext,
+                                          original,
+                                          objectInstance,
+                                          declaration->getName());
+        } else {
+            LogDebug("create normal function");
+            newObject = objectInstance;
+        }
+    } else { //object creation
+        newObject = objectInstance;
+    }
+
     JavaScriptInterfaceSingleton::Instance().setObjectProperty(
         gContext,
         parent,
         declaration->getName(),
-        objectInstance);
+        newObject);
 
     //notice
     if (declaration->getOptions() &&
@@ -327,7 +369,7 @@ void Explorer::cleanIframesData()
     m_iframeSupport.clean();
 }
 
-void Explorer::callEventListeners(CustomEventType /*eventType*/, void* /*data*/)
+void Explorer::callEventListeners(CustomEventType eventType, void* data)
 {
 #if 0 // deprecated
     using namespace WrtPlugins::Tizen;