Ejemplo n.º 1
0
static void load_status_callback(WebKitWebView* webView, GParamSpec* spec, DomDomviewFixture* fixture)
{
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status == WEBKIT_LOAD_FINISHED) {
        WebKitDOMDocument* document;
        WebKitDOMDOMWindow* domWindow;
        WebKitDOMElement* element;
        WebKitDOMEvent* event;
        glong clientX, clientY;

        document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
        g_assert(document);
        domWindow = webkit_dom_document_get_default_view(document);
        g_assert(domWindow);
        fixture->domWindow = domWindow;

        element = webkit_dom_document_get_element_by_id(document, "test");
        g_assert(element);
        event = webkit_dom_document_create_event(document, "MouseEvent", NULL);
        g_assert(event);
        g_assert(WEBKIT_DOM_IS_EVENT(event));
        g_assert(WEBKIT_DOM_IS_MOUSE_EVENT(event));
        clientX = webkit_dom_element_get_client_left(element);
        clientY = webkit_dom_element_get_client_top(element);
        webkit_dom_mouse_event_init_mouse_event(WEBKIT_DOM_MOUSE_EVENT(event),
                                                "click", TRUE, TRUE,
                                                fixture->domWindow, 0, 0, 0, clientX, clientY,
                                                FALSE, FALSE, FALSE, FALSE,
                                                1, WEBKIT_DOM_EVENT_TARGET(element));
        webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(element), "click", G_CALLBACK(clicked_cb), false, fixture);
        g_assert(fixture->clicked == FALSE);
        webkit_dom_event_target_dispatch_event(WEBKIT_DOM_EVENT_TARGET(element), event, NULL);
    }

}
Ejemplo n.º 2
0
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);
    }
}
Ejemplo n.º 3
0
void
window_object_cleared_cb(WebKitWebView *webview, WebKitWebFrame *frame,
        JSGlobalContextRef *context, JSObjectRef *object) {
    (void) frame; (void) context; (void) object;
#if WEBKIT_CHECK_VERSION (1, 3, 13)
    // Take this opportunity to set some callbacks on the DOM
    WebKitDOMDocument *document = webkit_web_view_get_dom_document (webview);
    webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (document),
        "focus", G_CALLBACK(dom_focus_cb), TRUE, NULL);
    webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (document),
        "blur", G_CALLBACK(dom_focus_cb), TRUE, NULL);
#else
	(void) webview;
#endif
}
Ejemplo n.º 4
0
Archivo: dom.c Proyecto: b80905/vimb
void dom_install_focus_blur_callbacks(Document *doc)
{
    HtmlElement *element = webkit_dom_document_get_body(doc);

    if (!element) {
        element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
    }
    if (element) {
        webkit_dom_event_target_add_event_listener(
            WEBKIT_DOM_EVENT_TARGET(element), "blur", G_CALLBACK(editable_blur_cb), true, NULL
        );
        webkit_dom_event_target_add_event_listener(
            WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), true, NULL
        );
    }
}
Ejemplo n.º 5
0
/**
 * Add observers to doc event for given document and all the contained iframes
 * too.
 */
static void add_onload_event_observers(WebKitDOMDocument *doc,
        WebKitWebPage *page)
{
    WebKitDOMEventTarget *target;

    /* Add the document to the table of known documents or if already exists
     * return to not apply observers multiple times. */
    if (!g_hash_table_add(ext.documents, doc)) {
        return;
    }

    /* We have to use default view instead of the document itself in case this
     * function is called with content document of an iframe. Else the event
     * observing does not work. */
    target = WEBKIT_DOM_EVENT_TARGET(webkit_dom_document_get_default_view(doc));

    webkit_dom_event_target_add_event_listener(target, "focus",
            G_CALLBACK(on_editable_change_focus), TRUE, page);
    webkit_dom_event_target_add_event_listener(target, "blur",
            G_CALLBACK(on_editable_change_focus), TRUE, page);
    /* Check for focused editable elements also if they where focused before
     * the event observer where set up. */
    /* TODO this is not needed for strict-focus=on */
    on_editable_change_focus(target, NULL, page);

    /* Observe scroll events to get current position in the document. */
    webkit_dom_event_target_add_event_listener(target, "scroll",
            G_CALLBACK(on_document_scroll), FALSE, page);
    /* Call the callback explicitly to make sure we have the right position
     * shown in statusbar also in cases the user does not scroll. */
    on_document_scroll(target, NULL, page);
}
Ejemplo n.º 6
0
// active_element_change_cb is called when the active element is changed, and
// updates bookkeeping and the main process.
static void
active_element_change_cb(WebKitDOMEventTarget *target,
                         WebKitDOMEvent       *event,
                         gpointer              user_data)
{
    Exten *exten = user_data;
    WebKitDOMDocument *document;
    if(WEBKIT_DOM_IS_DOCUMENT(target)) {
        document = WEBKIT_DOM_DOCUMENT(target);
    } else {
        // target is a window.
        g_object_get(target, "document", &document, NULL);
    }
    WebKitDOMElement *active = webkit_dom_document_get_active_element(document);
    if(active == NULL || active == exten->active) {
        return;
    }
    if(WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT(active)) {
        // The iframe document handles this, unless it isn't registered yet.
        // In this case, register it and call recursively.
        WebKitDOMDocument *doc =
            webkit_dom_html_iframe_element_get_content_document(
                    WEBKIT_DOM_HTML_IFRAME_ELEMENT(active));
        if(!g_hash_table_contains(exten->registered_documents, doc)) {
            frame_document_loaded(doc, exten);
            active_element_change_cb(
                    WEBKIT_DOM_EVENT_TARGET(doc),
                    NULL,
                    exten);
        }
        return;
    }
    exten->active = active;
    exten->scroll_target = get_scroll_target(active);

    // Check whether the currently active element is an input element.
    // If this has changed, signal DBus.
    //
    // Input elements:
    //
    // WebKitDOMHTMLAppletElement
    // WebKitDOMHTMLEmbedElement
    // WebKitDOMHTMLInputElement
    // WebKitDOMHTMLTextAreaElement
    gboolean input_focus = (
            WEBKIT_DOM_IS_HTML_APPLET_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(active) ||
            WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(active));
    if(input_focus != exten->last_input_focus) {
        exten->last_input_focus = input_focus;
        input_focus_changed(
            exten->page_id,
            input_focus,
            exten);
    }
}
Ejemplo n.º 7
0
WebKitDOMEventTarget* kit(WebCore::EventTarget* obj)
{
    if (!obj)
        return 0;

    if (gpointer ret = DOMObjectCache::get(obj))
        return WEBKIT_DOM_EVENT_TARGET(ret);

    return wrap(obj);
}
Ejemplo n.º 8
0
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;

    if (parent == NULL) 
        return;

    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");
    char *top = webkit_dom_css_style_declaration_get_property_value(style, "top");
    char *left = webkit_dom_css_style_declaration_get_property_value(style, "left");
    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;
    if (sscanf(height, "%dpx", &h) == 1 && 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++;
    }
    else 
        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);

    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);
    g_free(new_style);

    webkit_dom_element_set_attribute(div, "onclick", "return", NULL);

    g_object_set_data((gpointer)div, "dwb-plugin-element", element);

    webkit_dom_node_remove_child(parent, WEBKIT_DOM_NODE(element), NULL);
    webkit_dom_node_append_child(parent, WEBKIT_DOM_NODE(div), NULL);
    v->plugins->elements = g_slist_prepend(v->plugins->elements, element);

    webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(div), "click", G_CALLBACK(plugins_onclick_cb), true, gl);
    g_object_unref(style);
    g_object_unref(parent);
    v->plugins->created++;
}
Ejemplo n.º 9
0
static void load_event_callback(WebKitWebView* webView, GParamSpec* spec, DomDomviewFixture* fixture)
{
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status == WEBKIT_LOAD_FINISHED) {
        webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(fixture->domWindow), "click", G_CALLBACK(clickedCallback), false, fixture);

        g_assert(fixture->clicked == FALSE);
        gtk_test_widget_click(GTK_WIDGET(fixture->webView), 1, 0);
    }

}
Ejemplo n.º 10
0
Archivo: dom.c Proyecto: uggedal/vimb
static gboolean editable_focus_cb(Element *element, Event *event)
{
    webkit_dom_event_target_remove_event_listener(
        WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), false
    );
    if (vb.mode->id != 'i') {
        EventTarget *target = webkit_dom_event_get_target(event);
        auto_insert((void*)target);
    }
    return false;
}
Ejemplo n.º 11
0
// frame_document_loaded watches signals emitted from the given document.
static void
frame_document_loaded(WebKitDOMDocument *doc,
                      Exten             *exten)
{
    // Track document, and don't register multiple times.
    if(!g_hash_table_add(exten->registered_documents, doc)) {
        return;
    }
    WebKitDOMEventTarget *target = WEBKIT_DOM_EVENT_TARGET(
            webkit_dom_document_get_default_view(doc));
    // listen for focus changes
    webkit_dom_event_target_add_event_listener(
            target,
            "blur",
            G_CALLBACK(active_element_change_cb),
            true,
            exten);
    webkit_dom_event_target_add_event_listener(
            target,
            "focus",
            G_CALLBACK(active_element_change_cb),
            true,
            exten);

    // listen for resource loads.
    webkit_dom_event_target_add_event_listener(
            target,
            "beforeload",
            G_CALLBACK(adblock_before_load_cb),
            true,
            exten);

    // Scan for existing iframes, and add them as new frames.
    WebKitDOMNodeList *nodes = webkit_dom_document_get_elements_by_tag_name(
            WEBKIT_DOM_DOCUMENT(doc),
            "IFRAME");
    gulong i;
    gulong len;
    if(nodes == NULL) {
        len = 0;
    } else {
        len = webkit_dom_node_list_get_length(nodes);
    }
    for(i = 0; i < len; i++) {
        WebKitDOMDocument *subdoc =
            webkit_dom_html_iframe_element_get_content_document(
                    WEBKIT_DOM_HTML_IFRAME_ELEMENT(
                        webkit_dom_node_list_item(nodes, i)));
        frame_document_loaded(subdoc, exten);
    }
    // Element hider
    inject_adblock_css(doc, exten);
}
Ejemplo n.º 12
0
// document_loaded_cb is called when a document is loaded, and updates
// internal bookkeeping and attaches to signals from the document.
static void
document_loaded_cb(WebKitWebPage *page,
                   gpointer       user_data)
{
    Exten *exten = user_data;
    if(exten->registered_documents) {
        g_hash_table_unref(exten->registered_documents);
    }
    exten->registered_documents = g_hash_table_new(NULL, NULL);
    exten->document = webkit_web_page_get_dom_document(page);
    frame_document_loaded(exten->document, exten);
    active_element_change_cb(
            WEBKIT_DOM_EVENT_TARGET(exten->document),
            NULL,
            exten);
    // listen for scroll changes.
    webkit_dom_event_target_add_event_listener(
            WEBKIT_DOM_EVENT_TARGET(exten->document),
            "scroll",
            G_CALLBACK(document_scroll_cb),
            false,
            exten);
}
Ejemplo n.º 13
0
Archivo: dom.c Proyecto: uggedal/vimb
void dom_check_auto_insert(WebKitWebView *view)
{
    Document *doc   = webkit_web_view_get_dom_document(view);
    Element *active = get_active_element(doc);

    if (vb.config.strict_focus || !auto_insert(active)) {
        /* if the strict-focus is on also blur the possible active element */
        if (vb.config.strict_focus) {
            dom_clear_focus(view);
        }
        /* the focus was not set automatically - add event listener to track
         * focus events on the document */
        HtmlElement *element = webkit_dom_document_get_body(doc);
        if (!element) {
            element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
        }
        webkit_dom_event_target_add_event_listener(
            WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), false, NULL
        );
    }
}
Ejemplo n.º 14
0
static gboolean clickedCallback(WebKitDOMDOMWindow* view, WebKitDOMEvent* event, DomDomviewFixture* fixture)
{
    WebKitDOMEventTarget* target;
    gushort phase;

    g_assert(event);
    g_assert(WEBKIT_DOM_IS_EVENT(event));

    // We should catch this in the bubbling up phase, since we are connecting to the toplevel object
    phase = webkit_dom_event_get_event_phase(event);
    g_assert_cmpint(phase, ==, 3);

    target = webkit_dom_event_get_current_target(event);
    g_assert(target == WEBKIT_DOM_EVENT_TARGET(view));

    g_assert(fixture->clicked == FALSE);
    fixture->clicked = TRUE;

    finish_loading(fixture);

    return FALSE;
}
Ejemplo n.º 15
0
static void test_dom_domview_signals(DomDomviewFixture* fixture, gconstpointer data)
{
    g_assert(fixture);
    WebKitWebView* view = (WebKitWebView*)fixture->webView;
    g_assert(view);
    WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
    g_assert(document);
    WebKitDOMDOMWindow* domWindow = webkit_dom_document_get_default_view(document);
    g_assert(domWindow);

    fixture->domWindow = domWindow;

    webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(fixture->domWindow), "load", G_CALLBACK(loadedCallback), false, fixture);
    g_signal_connect(fixture->window, "map-event", G_CALLBACK(map_event_cb), fixture);
    g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_event_callback), fixture);

    gtk_widget_show_all(fixture->window);
    gtk_window_present(GTK_WINDOW(fixture->window));

    g_main_loop_run(fixture->loop);

    g_assert(fixture->loaded);
    g_assert(fixture->clicked);
}