summaryrefslogtreecommitdiff
path: root/src/plugins.c
diff options
context:
space:
mode:
authorportix <none@none>2012-12-06 12:37:07 +0100
committerportix <none@none>2012-12-06 12:37:07 +0100
commit7b79571c1e9bb4fe3467c7b076bb294e7fdcdac5 (patch)
tree7dfc83fb3edd0963eef9ae73fba940175561a6bf /src/plugins.c
parent7b0f52f71067a8c451a1c19c0437909b51d1cfff (diff)
downloaddwb-7b79571c1e9bb4fe3467c7b076bb294e7fdcdac5.zip
Indentation and cleanup of application, html, entry, plugins
Diffstat (limited to 'src/plugins.c')
-rw-r--r--src/plugins.c253
1 files changed, 139 insertions, 114 deletions
diff --git a/src/plugins.c b/src/plugins.c
index dae33635..be2ada41 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -23,53 +23,64 @@
#define ALLOWED(g) (VIEW(g)->status->allowed_plugins)
Plugins *
-plugins_new() {
- Plugins *p = dwb_malloc(sizeof(Plugins));
- p->created = 0;
- p->clicks = NULL;
- p->status = 0;
- p->elements = NULL;
- p->max = 0;
- return p;
+plugins_new()
+{
+ Plugins *p = dwb_malloc(sizeof(Plugins));
+ p->created = 0;
+ p->clicks = NULL;
+ p->status = 0;
+ p->elements = NULL;
+ p->max = 0;
+ return p;
}
void
-plugins_free(Plugins *p) {
- if (p == NULL)
- return;
- if (p->clicks != NULL) {
- for (GSList *l = p->clicks; l; l=l->next)
- g_object_unref(l->data);
- g_slist_free(p->clicks);
- }
- if (p->elements != NULL) {
- for (GSList *l = p->elements; l; l=l->next)
- g_object_unref(l->data);
- g_slist_free(p->elements);
- }
- FREE0(p);
+plugins_free(Plugins *p)
+{
+ if (p == NULL)
+ return;
+
+ if (p->clicks != NULL)
+ {
+ for (GSList *l = p->clicks; l; l=l->next)
+ g_object_unref(l->data);
+
+ g_slist_free(p->clicks);
+ }
+ if (p->elements != NULL)
+ {
+ for (GSList *l = p->elements; l; l=l->next)
+ g_object_unref(l->data);
+
+ g_slist_free(p->elements);
+ }
+ FREE0(p);
}
static void
-plugins_onclick_cb(WebKitDOMElement *element, WebKitDOMEvent *event, GList *gl) {
- WebKitDOMElement *e = g_object_get_data((gpointer)element, "dwb-plugin-element");
- ALLOWED(gl) = g_slist_append(ALLOWED(gl), e);
- WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
- WebKitDOMNode *child = webkit_dom_node_get_first_child(WEBKIT_DOM_NODE(element));
- webkit_dom_node_remove_child(WEBKIT_DOM_NODE(parent), child, NULL);
- webkit_dom_node_remove_child(parent, WEBKIT_DOM_NODE(element), NULL);
- webkit_dom_node_append_child(parent, WEBKIT_DOM_NODE(e), NULL);
- g_object_unref(parent);
+plugins_onclick_cb(WebKitDOMElement *element, WebKitDOMEvent *event, GList *gl)
+{
+ WebKitDOMElement *e = g_object_get_data((gpointer)element, "dwb-plugin-element");
+ ALLOWED(gl) = g_slist_append(ALLOWED(gl), e);
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
+ WebKitDOMNode *child = webkit_dom_node_get_first_child(WEBKIT_DOM_NODE(element));
+ webkit_dom_node_remove_child(WEBKIT_DOM_NODE(parent), child, NULL);
+ webkit_dom_node_remove_child(parent, WEBKIT_DOM_NODE(element), NULL);
+ webkit_dom_node_append_child(parent, WEBKIT_DOM_NODE(e), NULL);
+ g_object_unref(parent);
}
void
-plugins_create_click_element(WebKitDOMElement *element, GList *gl) {
- WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
- View *v = VIEW(gl);
- WebKitDOMElement *div;
+plugins_create_click_element(WebKitDOMElement *element, GList *gl)
+{
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
+ View *v = VIEW(gl);
+ WebKitDOMElement *div;
+
+ if (parent == NULL)
+ return;
- if (parent != NULL) {
WebKitDOMDocument *doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(element));
WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
-
+
WebKitDOMCSSStyleDeclaration *style = webkit_dom_dom_window_get_computed_style(win, element, "");
char *width = webkit_dom_css_style_declaration_get_property_value(style, "width");
char *height = webkit_dom_css_style_declaration_get_property_value(style, "height");
@@ -78,20 +89,21 @@ plugins_create_click_element(WebKitDOMElement *element, GList *gl) {
char *position = webkit_dom_css_style_declaration_get_property_value(style, "position");
int w, h;
if (sscanf(width, "%dpx", &w) == 1 && w<72)
- w = 72;
+ w = 72;
if (sscanf(height, "%dpx", &h) == 1 && h<24)
- h = 24;
-
+ h = 24;
- if (v->plugins->max <= v->plugins->created) {
- div = webkit_dom_document_create_element(doc, "div", NULL);
- v->plugins->clicks = g_slist_prepend(v->plugins->clicks, div);
- v->plugins->max++;
+
+ if (v->plugins->max <= v->plugins->created)
+ {
+ div = webkit_dom_document_create_element(doc, "div", NULL);
+ v->plugins->clicks = g_slist_prepend(v->plugins->clicks, div);
+ v->plugins->max++;
}
else
- div = g_slist_nth_data(v->plugins->clicks, v->plugins->created);
+ div = g_slist_nth_data(v->plugins->clicks, v->plugins->created);
webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(div),
- "<div style='display:table-cell;vertical-align:middle;text-align:center;color:#fff;background:#000;border:1px solid #666;font:11px monospace bold'>click to enable flash</div>", NULL);
+ "<div style='display:table-cell;vertical-align:middle;text-align:center;color:#fff;background:#000;border:1px solid #666;font:11px monospace bold'>click to enable flash</div>", NULL);
char *new_style = g_strdup_printf("position:%s;width:%dpx;height:%dpx;top:%s;left:%s;display:table;z-index:37000;", position, w, h, top, left);
webkit_dom_element_set_attribute(div, "style", new_style, NULL);
@@ -109,61 +121,68 @@ plugins_create_click_element(WebKitDOMElement *element, GList *gl) {
g_object_unref(style);
g_object_unref(parent);
v->plugins->created++;
- }
}
static gboolean
-plugins_before_load_cb(WebKitDOMDOMWindow *win, WebKitDOMEvent *event, GList *gl) {
- WebKitDOMElement *element = (void*)webkit_dom_event_get_src_element(event);
- char *tagname = webkit_dom_element_get_tag_name(element);
- char *type = webkit_dom_element_get_attribute(element, "type");
-
- if ( (!g_strcmp0(type, "application/x-shockwave-flash")
- && (! g_ascii_strcasecmp(tagname, "object") || ! g_ascii_strcasecmp(tagname, "embed")) )
- && ! g_slist_find(ALLOWED(gl), element) ) {
- VIEW(gl)->plugins->status |= PLUGIN_STATUS_HAS_PLUGIN;
- webkit_dom_event_prevent_default(event);
- webkit_dom_event_stop_propagation(event);
-
- plugins_create_click_element(element, gl);
- }
- g_object_unref(element);
- g_free(tagname);
- g_free(type);
- return true;
+plugins_before_load_cb(WebKitDOMDOMWindow *win, WebKitDOMEvent *event, GList *gl)
+{
+ WebKitDOMElement *element = (void*)webkit_dom_event_get_src_element(event);
+ char *tagname = webkit_dom_element_get_tag_name(element);
+ char *type = webkit_dom_element_get_attribute(element, "type");
+
+ if ( (!g_strcmp0(type, "application/x-shockwave-flash")
+ && (! g_ascii_strcasecmp(tagname, "object") || ! g_ascii_strcasecmp(tagname, "embed")) )
+ && ! g_slist_find(ALLOWED(gl), element) )
+ {
+ VIEW(gl)->plugins->status |= PLUGIN_STATUS_HAS_PLUGIN;
+ webkit_dom_event_prevent_default(event);
+ webkit_dom_event_stop_propagation(event);
+
+ plugins_create_click_element(element, gl);
+ }
+ g_object_unref(element);
+ g_free(tagname);
+ g_free(type);
+ return true;
}
static void
-plugins_remove_all(GList *gl) {
- if (ALLOWED(gl) != NULL) {
- ALLOWED(gl) = g_slist_remove_all(ALLOWED(gl), ALLOWED(gl)->data);
- ALLOWED(gl) = NULL;
- }
- View *v = VIEW(gl);
- v->plugins->created = 0;
- if (v->plugins->elements != NULL) {
- for (GSList *l = v->plugins->elements; l; l=l->next) {
- g_object_unref(l->data);
+plugins_remove_all(GList *gl)
+{
+ if (ALLOWED(gl) != NULL)
+ {
+ ALLOWED(gl) = g_slist_remove_all(ALLOWED(gl), ALLOWED(gl)->data);
+ ALLOWED(gl) = NULL;
+ }
+ View *v = VIEW(gl);
+ v->plugins->created = 0;
+
+ if (v->plugins->elements != NULL)
+ {
+ for (GSList *l = v->plugins->elements; l; l=l->next)
+ g_object_unref(l->data);
+
+ g_slist_free(v->plugins->elements);
+ v->plugins->elements = NULL;
}
- g_slist_free(v->plugins->elements);
- v->plugins->elements = NULL;
- }
}
static gboolean
-plugins_before_unload_cb(WebKitDOMDOMWindow *win, WebKitDOMEvent *event, GList *gl) {
- plugins_remove_all(gl);
- return true;
+plugins_before_unload_cb(WebKitDOMDOMWindow *win, WebKitDOMEvent *event, GList *gl)
+{
+ plugins_remove_all(gl);
+ return true;
}
-
void
-plugins_load_status_cb(WebKitWebView *wv, GParamSpec *p, GList *gl) {
- WebKitLoadStatus status = webkit_web_view_get_load_status(wv);
- if (status == WEBKIT_LOAD_COMMITTED) {
- WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
- WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
- webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
- webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeunload", G_CALLBACK(plugins_before_unload_cb), true, gl);
- }
+plugins_load_status_cb(WebKitWebView *wv, GParamSpec *p, GList *gl)
+{
+ WebKitLoadStatus status = webkit_web_view_get_load_status(wv);
+ if (status == WEBKIT_LOAD_COMMITTED)
+ {
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
+ WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
+ webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
+ webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeunload", G_CALLBACK(plugins_before_unload_cb), true, gl);
+ }
}
#if 0
@@ -179,38 +198,44 @@ plugins_frame_created_cb(WebKitWebView *wv, WebKitWebFrame *frame, GList *gl) {
#endif
void
-plugins_frame_load_cb(WebKitWebFrame *frame, GParamSpec *p, GList *gl) {
- dwb_dom_add_frame_listener(frame, "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
+plugins_frame_load_cb(WebKitWebFrame *frame, GParamSpec *p, GList *gl)
+{
+ dwb_dom_add_frame_listener(frame, "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
}
void
-plugins_frame_created_cb(WebKitWebView *wv, WebKitWebFrame *frame, GList *gl) {
- g_signal_connect(frame, "notify::load-status", G_CALLBACK(plugins_frame_load_cb), gl);
+plugins_frame_created_cb(WebKitWebView *wv, WebKitWebFrame *frame, GList *gl)
+{
+ g_signal_connect(frame, "notify::load-status", G_CALLBACK(plugins_frame_load_cb), gl);
}
void
-plugins_connect(GList *gl) {
- View *v = VIEW(gl);
- if (v->plugins->status & PLUGIN_STATUS_CONNECTED)
- return;
-
- v->status->signals[SIG_PLUGINS_LOAD] = g_signal_connect(WEBVIEW(gl), "notify::load-status", G_CALLBACK(plugins_load_status_cb), gl);
- v->status->signals[SIG_PLUGINS_FRAME_CREATED] = g_signal_connect(WEBVIEW(gl), "frame-created", G_CALLBACK(plugins_frame_created_cb), gl);
- v->plugins->status ^= (v->plugins->status & PLUGIN_STATUS_DISCONNECTED) | PLUGIN_STATUS_CONNECTED;
+plugins_connect(GList *gl)
+{
+ View *v = VIEW(gl);
+ if (v->plugins->status & PLUGIN_STATUS_CONNECTED)
+ return;
+
+ v->status->signals[SIG_PLUGINS_LOAD] = g_signal_connect(WEBVIEW(gl), "notify::load-status", G_CALLBACK(plugins_load_status_cb), gl);
+ v->status->signals[SIG_PLUGINS_FRAME_CREATED] = g_signal_connect(WEBVIEW(gl), "frame-created", G_CALLBACK(plugins_frame_created_cb), gl);
+ v->plugins->status ^= (v->plugins->status & PLUGIN_STATUS_DISCONNECTED) | PLUGIN_STATUS_CONNECTED;
}
void
-plugins_disconnect(GList *gl) {
- View *v = VIEW(gl);
- if (v->plugins->status & PLUGIN_STATUS_DISCONNECTED)
- return;
-
- for (int i=SIG_PLUGINS_FIRST+1; i<SIG_PLUGINS_LAST; i++) {
- if (VIEW(gl)->status->signals[i] > 0) {
- g_signal_handler_disconnect(WEBVIEW(gl), VIEW(gl)->status->signals[i]);
- v->status->signals[i] = 0;
+plugins_disconnect(GList *gl)
+{
+ View *v = VIEW(gl);
+ if (v->plugins->status & PLUGIN_STATUS_DISCONNECTED)
+ return;
+
+ for (int i=SIG_PLUGINS_FIRST+1; i<SIG_PLUGINS_LAST; i++)
+ {
+ if (VIEW(gl)->status->signals[i] > 0)
+ {
+ g_signal_handler_disconnect(WEBVIEW(gl), VIEW(gl)->status->signals[i]);
+ v->status->signals[i] = 0;
+ }
}
- }
- plugins_remove_all(gl);
- v->plugins->status ^= (v->plugins->status & PLUGIN_STATUS_CONNECTED) | PLUGIN_STATUS_DISCONNECTED;
+ plugins_remove_all(gl);
+ v->plugins->status ^= (v->plugins->status & PLUGIN_STATUS_CONNECTED) | PLUGIN_STATUS_DISCONNECTED;
}