webengine/widgetengine/src/WidgetEngineBridge.cpp
changeset 5 10e98eab6f85
parent 0 dd21522fd290
child 25 0ed94ceaa377
--- a/webengine/widgetengine/src/WidgetEngineBridge.cpp	Fri May 08 08:25:06 2009 +0300
+++ b/webengine/widgetengine/src/WidgetEngineBridge.cpp	Fri Jul 03 15:54:40 2009 +0100
@@ -53,6 +53,7 @@
 // ============================= LOCAL FUNCTIONS ===============================
 
 // ============================ MEMBER FUNCTIONS ===============================
+using namespace KJS;
 
 // ----------------------------------------------------------------------------
 // CreateWidgetEngineBridge
@@ -83,10 +84,30 @@
 //
 // ----------------------------------------------------------------------------
 WidgetEngineBridge::~WidgetEngineBridge()
+{
+    Clear();
+    delete m_preferences;
+    m_preferences = NULL;
+}
+// ----------------------------------------------------------------------------
+// WidgetEngineBridge::Clear
+// 
+//
+//
+// ----------------------------------------------------------------------------
+void WidgetEngineBridge::Clear()
 {    
+	// unprotect objects
+	HashSet<JSValue*>::iterator end = m_protectedObjects.end();
+	for (HashSet<JSValue*>::iterator it = m_protectedObjects.begin(); it != end; ++it) {
+		Collector::unprotect(*it);
+	}
+	m_protectedObjects.clear();
+
     delete m_menuclient;
+    m_menuclient = NULL;
     delete m_widgetclient;    
-    delete m_preferences;
+    m_widgetclient = NULL;
 }
 
 // ----------------------------------------------------------------------------
@@ -103,7 +124,7 @@
         if (!m_preferences)
             m_preferences = new (ELeave) WidgetPreferences();
         
-        m_widgetclient = CWidgetClient::NewL(aWidgetCallback,aWidgetEngineCallback,m_preferences);            
+        m_widgetclient = CWidgetClient::NewL(aWidgetCallback, this, aWidgetEngineCallback,m_preferences);            
     }    
     return m_widgetclient->jswidget();  
 }
@@ -120,7 +141,7 @@
     if (!m_menuclient){
         m_menuclient = CMenuClient::NewL(aWidgetCallback,aWidgetEngineCallback);      
     }    
-    return m_menuclient->jsmenu();  
+    return m_menuclient->jsmenu(this);  
 }
 
 // ----------------------------------------------------------------------------
@@ -135,7 +156,7 @@
     if (!m_menuclient){
         m_menuclient = CMenuClient::NewL(aWidgetCallback,aWidgetEngineCallback);      
     }    
-    return m_menuclient->jsmenuitem();      
+    return m_menuclient->jsmenuitem(this);      
 }
 
 // ----------------------------------------------------------------------------
@@ -285,6 +306,18 @@
 }
 
 
+void WidgetEngineBridge::Protect(JSValue* obj)
+{
+	m_protectedObjects.add(obj);
+	Collector::protect(obj);
+}
+
+void WidgetEngineBridge::Unprotect(JSValue* obj)
+{
+	m_protectedObjects.remove(obj);
+	Collector::unprotect(obj);
+}
+
 //END OF FILE