summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2014-03-08 00:45:17 +0100
committerportix <portix@gmx.net>2014-03-08 00:45:17 +0100
commit5fcfc1e6d66ee74bbcb582becd8593b4d81c1d3b (patch)
tree1a0a7f9fe7298b209a1967d96a22f2ca20b3cd6d
parentbaba30024300cf49d74c37fae59fa6942d0676cb (diff)
downloaddwb-5fcfc1e6d66ee74bbcb582becd8593b4d81c1d3b.zip
Destroy all programmatically created widgets when context is released
-rw-r--r--src/scripts.c31
-rw-r--r--src/scripts.h4
2 files changed, 23 insertions, 12 deletions
diff --git a/src/scripts.c b/src/scripts.c
index fec38f3e..0b3f9485 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -261,6 +261,7 @@ enum {
CLASS_WIDGET,
CLASS_MENU,
CLASS_SECURE_WIDGET,
+ CLASS_HIDDEN_WEBVIEW,
CLASS_MESSAGE,
CLASS_DEFERRED,
CLASS_HISTORY,
@@ -285,6 +286,7 @@ typedef struct ScriptContext_s {
GSList *script_list;
GSList *autoload;
GSList *timers;
+ GSList *created_widgets;
GPtrArray *gobject_signals;
GHashTable *exports;
@@ -408,6 +410,15 @@ script_context_free(ScriptContext *ctx) {
g_slist_free(ctx->timers);
ctx->timers = NULL;
}
+ for (GSList *l = s_ctx->created_widgets; l; l=l->next) {
+ GtkWidget *w = l->data;
+ JSObjectRef ref = g_object_steal_qdata(G_OBJECT(w), s_ctx->ref_quark);
+ if (ref != NULL) {
+ JSObjectSetPrivate(ref, NULL);
+ }
+ gtk_widget_destroy(w);
+ }
+
if (s_ctx->global_context != NULL) {
if (ctx->constructors != NULL) {
for (int i=0; i<CONSTRUCTOR_LAST; i++)
@@ -4777,7 +4788,7 @@ static JSObjectRef
hwv_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
GObject *wv = G_OBJECT(webkit_web_view_new());
- return make_object_for_class(ctx, s_ctx->classes[CLASS_WEBVIEW], wv, false);
+ return make_object_for_class(ctx, s_ctx->classes[CLASS_HIDDEN_WEBVIEW], wv, false);
}
/**
@@ -5012,6 +5023,7 @@ widget_destroy(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t
GtkWidget *widget = JSObjectGetPrivate(this);
g_return_val_if_fail(widget != NULL, UNDEFINED);
+ s_ctx->created_widgets = g_slist_remove_all(s_ctx->created_widgets, widget);
gtk_widget_destroy(widget);
return UNDEFINED;
}
@@ -5032,6 +5044,7 @@ widget_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, co
return JSValueToObject(ctx, NIL, NULL);
}
GtkWidget *widget = gtk_widget_new(type, NULL);
+ s_ctx->created_widgets = g_slist_prepend(s_ctx->created_widgets, widget);
return make_object(ctx, G_OBJECT(widget));
}
return JSValueToObject(ctx, NIL, NULL);
@@ -6886,13 +6899,6 @@ create_global_object()
s_ctx->constructors[CONSTRUCTOR_WEBVIEW] = create_constructor(ctx, "WebKitWebView", s_ctx->classes[CLASS_WEBVIEW], NULL, NULL);
- cd = kJSClassDefinitionEmpty;
- cd.className = "HiddenWebView";
- cd.staticFunctions = wv_functions;
- cd.parentClass = s_ctx->classes[CLASS_GOBJECT];
-
- s_ctx->constructors[CONSTRUCTOR_HIDDEN_WEB_VIEW] = create_constructor(ctx, "HiddenWebView", s_ctx->classes[CLASS_WEBVIEW], hwv_constructor_cb, NULL);
-
/* Frame */
/**
@@ -7086,6 +7092,14 @@ create_global_object()
s_ctx->classes[CLASS_WIDGET] = JSClassCreate(&cd);
s_ctx->constructors[CONSTRUCTOR_WIDGET] = create_constructor(ctx, "GtkWidget", s_ctx->classes[CLASS_WIDGET], widget_constructor_cb, NULL);
+ cd = kJSClassDefinitionEmpty;
+ cd.className = "HiddenWebView";
+ cd.staticFunctions = widget_functions;
+ cd.parentClass = s_ctx->classes[CLASS_WEBVIEW];
+ s_ctx->classes[CLASS_HIDDEN_WEBVIEW] = JSClassCreate(&cd);
+
+ s_ctx->constructors[CONSTRUCTOR_HIDDEN_WEB_VIEW] = create_constructor(ctx, "HiddenWebView", s_ctx->classes[CLASS_HIDDEN_WEBVIEW], hwv_constructor_cb, NULL);
+
/**
* @class
* Widget that will be created when a context menu is shown, can be
@@ -7644,7 +7658,6 @@ scripts_end(gboolean clean_all)
pthread_rwlock_wrlock(&s_context_lock);
if (s_ctx != NULL)
{
- // keys
GList *next, *l;
next = dwb.override_keys;
while (next != NULL)
diff --git a/src/scripts.h b/src/scripts.h
index c20653a0..aa29d1f8 100644
--- a/src/scripts.h
+++ b/src/scripts.h
@@ -53,9 +53,7 @@
#define SCRIPTS_SIG_FOLLOW 28
#define SCRIPTS_SIG_ADD_COOKIE 29
#define SCRIPTS_SIG_READY 30
-#define SCRIPTS_SIG_SERVER_RUN 31
-#define SCRIPTS_SIG_SERVER_STOP 32
-#define SCRIPTS_SIG_LAST 33
+#define SCRIPTS_SIG_LAST 31
#define SCRIPT_MAX_SIG_OBJECTS 8