Ejemplo n.º 1
0
wxString wxWebViewWebKit::GetPageSource() const
{
    WebKitWebResource *resource = webkit_web_view_get_main_resource(m_web_view);
    if (!resource)
    {
        return wxString();
    }

    GAsyncResult *result = NULL;
    webkit_web_resource_get_data(resource, NULL,
                                 (GAsyncReadyCallback)wxgtk_web_resource_get_data_cb,
                                 &result);

    GMainContext *main_context = g_main_context_get_thread_default();
    while (!result)
    {
        g_main_context_iteration(main_context, TRUE);
    }

    guchar *source = webkit_web_resource_get_data_finish(resource, result,
                                                         NULL, NULL);
    if (result)
    {
        g_object_unref(result);
    }

    if (source)
    {
        wxString wxs = wxString(source, wxConvUTF8);
        free(source);
        return wxs;
    }
    return wxString();
}
Ejemplo n.º 2
0
void FrameLoaderClient::dispatchDidFinishLoading(WebCore::DocumentLoader* loader, unsigned long identifier)
{
    static_cast<WebKit::DocumentLoader*>(loader)->decreaseLoadCount(identifier);

    WebKitWebView* webView = getViewFromFrame(m_frame);
    GOwnPtr<gchar> identifierString(toString(identifier));
    WebKitWebResource* webResource = webkit_web_view_get_resource(webView, identifierString.get());

    // A NULL WebResource means the load has been interrupted, and
    // replaced by another one while this resource was being loaded.
    if (!webResource)
        return;

    const char* uri = webkit_web_resource_get_uri(webResource);
    RefPtr<ArchiveResource> coreResource(loader->subresource(KURL(KURL(), uri)));

    // If coreResource is NULL here, the resource failed to load,
    // unless it's the main resource.
    if (!coreResource && webResource != webkit_web_view_get_main_resource(webView))
        return;

    if (!coreResource)
        coreResource = loader->mainResource().releaseRef();

    webkit_web_resource_init_with_core_resource(webResource, coreResource.get());

    // FIXME: This function should notify the application that the resource
    // finished loading, maybe using a load-status property in the
    // WebKitWebResource object, similar to what we do for WebKitWebFrame'
    // signal.
    notImplemented();
}
Ejemplo n.º 3
0
 virtual void resourceFinished(WebKitWebResource* resource)
 {
     g_signal_handlers_disconnect_matched(resource, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     if (webkit_web_view_get_main_resource(m_webView) != resource)
         m_subresources = g_list_prepend(m_subresources, g_object_ref(resource));
     if (++m_resourcesLoaded == m_resourcesToLoad)
         g_main_loop_quit(m_mainLoop);
 }
Ejemplo n.º 4
0
    virtual void loadCommitted()
    {
        WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView);
        g_assert(resource);
        WebKitURIResponse* response = webkit_web_resource_get_response(resource);
        g_assert(response);

        GTlsCertificate* certificate = 0;
        webkit_uri_response_get_https_status(response, &certificate, &m_tlsErrors);
        m_certificate = certificate;
    }
Ejemplo n.º 5
0
const char* WebViewTest::mainResourceData(size_t& mainResourceDataSize)
{
    m_resourceDataSize = 0;
    m_resourceData.clear();
    WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView);
    g_assert(resource);

    webkit_web_resource_get_data(resource, 0, resourceGetDataCallback, this);
    g_main_loop_run(m_mainLoop);

    mainResourceDataSize = m_resourceDataSize;
    return m_resourceData.get();
}
Ejemplo n.º 6
0
static VbResult normal_view_source(Client *c, const NormalCmdInfo *info)
{
    WebKitWebResource *resource;

    if ((resource = webkit_web_view_get_main_resource(c->webview)) == NULL) {
        return RESULT_ERROR;
    }

    webkit_web_resource_get_data(resource, NULL,
            (GAsyncReadyCallback)normal_view_source_loaded, c);

    return RESULT_COMPLETE;
}
Ejemplo n.º 7
0
static void load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data) {
    if (load_event != WEBKIT_LOAD_FINISHED) {
        return;
    }

    if (mhtml_file != NULL) {
        GFile *f = g_file_new_for_path(mhtml_file);
        webkit_web_view_save_to_file(web_view, f, WEBKIT_SAVE_MODE_MHTML, NULL, mhtml_finished, NULL);
    }

    if (html_file != NULL) {
        WebKitWebResource *wr = webkit_web_view_get_main_resource(web_view);
        webkit_web_resource_get_data(wr, NULL, html_finished, NULL);
    }

    if (png_file != NULL) {
        webkit_web_view_get_snapshot(
            web_view,
            WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
            WEBKIT_SNAPSHOT_OPTIONS_NONE,
            NULL,
            png_finished,
            NULL
        );
    }

    if (title_file != NULL) {
        const gchar *title = webkit_web_view_get_title(web_view);
        GString *s = g_string_new(title);
        g_string_append_c(s, '\n');
        FILE *f = open_file(title_file, "w");
        if (fwrite(s->str, s->len, 1, f) != 1) {
            errx(1, "error saving title");
        }
        fclose(f);
        done();
    }
}
Ejemplo n.º 8
0
static gboolean webViewDecidePolicy(WebKitWebView *webView, WebKitPolicyDecision *decision, WebKitPolicyDecisionType decisionType, BrowserWindow *window)
{
    switch (decisionType) {
    case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: {
        WebKitNavigationAction *navigationAction = webkit_navigation_policy_decision_get_navigation_action(WEBKIT_NAVIGATION_POLICY_DECISION(decision));
        if (webkit_navigation_action_get_navigation_type(navigationAction) != WEBKIT_NAVIGATION_TYPE_LINK_CLICKED
            || webkit_navigation_action_get_mouse_button(navigationAction) != GDK_BUTTON_MIDDLE)
            return FALSE;

        // Opening a new window if link clicked with the middle button.
        WebKitWebView *newWebView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(webkit_web_view_get_context(webView)));
        GtkWidget *newWindow = browser_window_new(newWebView, GTK_WINDOW(window));
        webkit_web_view_load_request(newWebView, webkit_navigation_action_get_request(navigationAction));
        gtk_widget_show(newWindow);

        webkit_policy_decision_ignore(decision);
        return TRUE;
    }
    case WEBKIT_POLICY_DECISION_TYPE_RESPONSE: {
        WebKitResponsePolicyDecision *responseDecision = WEBKIT_RESPONSE_POLICY_DECISION(decision);
        if (webkit_response_policy_decision_is_mime_type_supported(responseDecision))
            return FALSE;

        WebKitWebResource *mainResource = webkit_web_view_get_main_resource(webView);
        WebKitURIRequest *request = webkit_response_policy_decision_get_request(responseDecision);
        const char *requestURI = webkit_uri_request_get_uri(request);
        if (g_strcmp0(webkit_web_resource_get_uri(mainResource), requestURI))
            return FALSE;

        webkit_policy_decision_download(decision);
        return TRUE;
    }
    case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
    default:
        return FALSE;
    }
}