コード例 #1
0
void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage)
{
    bool shouldPortBeResetToZero = m_url.hasPort() && !m_url.port();
    m_url = soupURIToKURL(soup_message_get_uri(soupMessage));

    // SoupURI cannot differeniate between an explicitly specified port 0 and
    // no port specified.
    if (shouldPortBeResetToZero)
        m_url.setPort(0);

    m_httpMethod = String::fromUTF8(soupMessage->method);

    updateFromSoupMessageHeaders(soupMessage->request_headers);

    if (soupMessage->request_body->data)
        m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length);

    SoupURI* firstParty = soup_message_get_first_party(soupMessage);
    if (firstParty)
        m_firstPartyForCookies = soupURIToKURL(firstParty);

    m_soupFlags = soup_message_get_flags(soupMessage);

    // FIXME: m_allowCookies should probably be handled here and on
    // doUpdatePlatformRequest somehow.
}
コード例 #2
0
void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage)
{
    SoupURI* soupURI = soup_message_get_uri(soupMessage);
    GOwnPtr<gchar> uri(soup_uri_to_string(soupURI, FALSE));
    m_url = KURL(KURL(), String::fromUTF8(uri.get()));

    m_httpMethod = String::fromUTF8(soupMessage->method);

    SoupMessageHeadersIter headersIter;
    const char* headerName;
    const char* headerValue;

    soup_message_headers_iter_init(&headersIter, soupMessage->request_headers);
    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue))
        m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));

    if (soupMessage->request_body->data)
        m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length);

#ifdef HAVE_LIBSOUP_2_29_90
    SoupURI* firstParty = soup_message_get_first_party(soupMessage);
    if (firstParty) {
        GOwnPtr<gchar> firstPartyURI(soup_uri_to_string(firstParty, FALSE));
        m_firstPartyForCookies = KURL(KURL(), String::fromUTF8(firstPartyURI.get()));
    }
#endif

    m_soupFlags = soup_message_get_flags(soupMessage);

    // FIXME: m_allowCookies should probably be handled here and on
    // doUpdatePlatformRequest somehow.
}
コード例 #3
0
void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage)
{
    m_url = soupURIToKURL(soup_message_get_uri(soupMessage));

    m_httpMethod = String::fromUTF8(soupMessage->method);

    m_httpHeaderFields.clear();
    SoupMessageHeadersIter headersIter;
    const char* headerName;
    const char* headerValue;
    soup_message_headers_iter_init(&headersIter, soupMessage->request_headers);
    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue)) {
        m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));
    }

    if (soupMessage->request_body->data)
        m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length);

    SoupURI* firstParty = soup_message_get_first_party(soupMessage);
    if (firstParty)
        m_firstPartyForCookies = soupURIToKURL(firstParty);

    m_soupFlags = soup_message_get_flags(soupMessage);

    // FIXME: m_allowCookies should probably be handled here and on
    // doUpdatePlatformRequest somehow.
}
コード例 #4
0
/* We received the HTTP headers of the request and it contains cookie-managing headers */
static void _cookie_permission_manager_on_response_received(WebKitWebView *inView,
															WebKitWebFrame *inFrame,
															WebKitWebResource *inResource,
															WebKitNetworkResponse *inResponse,
															gpointer inUserData)
{
	g_return_if_fail(IS_COOKIE_PERMISSION_MANAGER(inUserData));

	CookiePermissionManager			*self=COOKIE_PERMISSION_MANAGER(inUserData);
	CookiePermissionManagerPrivate	*priv=self->priv;
	GSList							*newCookies, *cookie;
	GSList							*unknownCookies=NULL, *acceptedCookies=NULL;
	SoupURI							*firstParty;
	SoupCookieJarAcceptPolicy		cookiePolicy;
	gint							unknownCookiesPolicy;
	SoupMessage						*message;

	/* If policy is to deny all cookies return immediately */
	cookiePolicy=soup_cookie_jar_get_accept_policy(priv->cookieJar);
	if(cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NEVER) return;

	/* Get SoupMessage */
	message=webkit_network_response_get_message(inResponse);
	if(!message || !SOUP_IS_MESSAGE(message)) return;

	/* Iterate through cookies in response and check if they should be
	 * blocked (remove from cookies list) or accepted (added to cookie jar).
	 * If we could not determine what to do collect these cookies and
	 * ask user
	 */
	newCookies=soup_cookies_from_response(message);
	firstParty=soup_message_get_first_party(message);
	for(cookie=newCookies; cookie; cookie=cookie->next)
	{
		switch(_cookie_permission_manager_get_policy(self, cookie->data))
		{
			case COOKIE_PERMISSION_MANAGER_POLICY_BLOCK:
				soup_cookie_free(cookie->data);
				break;

			case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT:
			case COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION:
				if((cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY &&
						firstParty!=NULL &&
						firstParty->host &&
						soup_cookie_domain_matches(cookie->data, firstParty->host)) ||
						cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
				{
					acceptedCookies=g_slist_prepend(acceptedCookies, cookie->data);
				}
					else soup_cookie_free(cookie->data);
				break;

			case COOKIE_PERMISSION_MANAGER_POLICY_UNDETERMINED:
			default:
				if((cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY &&
						firstParty!=NULL &&
						firstParty->host &&
						soup_cookie_domain_matches(cookie->data, firstParty->host)) ||
						cookiePolicy==SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
				{
					unknownCookies=g_slist_prepend(unknownCookies, cookie->data);
				}
					else soup_cookie_free(cookie->data);
				break;
		}
	}

	/* Prepending an item to list is the fastest method but the order of cookies
	 * is reversed now and may be added to cookie jar in the wrong order. So we
	 * need to reverse list now of both - undetermined and accepted cookies
	 */
	unknownCookies=g_slist_reverse(unknownCookies);
	acceptedCookies=g_slist_reverse(acceptedCookies);

	/* Ask user for his decision what to do with cookies whose policy is undetermined
	 * But only ask if there is any undetermined one
	 */
	if(g_slist_length(unknownCookies)>0)
	{
		/* Get view */
		MidoriView					*view;

		view=MIDORI_VIEW(g_object_get_data(G_OBJECT(inView), "midori-view"));

		/* Ask for user's decision */
		unknownCookiesPolicy=_cookie_permission_manager_ask_for_policy(self, view, message, unknownCookies);
		if(unknownCookiesPolicy==COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT ||
			unknownCookiesPolicy==COOKIE_PERMISSION_MANAGER_POLICY_ACCEPT_FOR_SESSION)
		{
			/* Add accepted undetermined cookies to cookie jar */
			for(cookie=unknownCookies; cookie; cookie=cookie->next)
			{
				soup_cookie_jar_add_cookie(priv->cookieJar, (SoupCookie*)cookie->data);
			}
		}
			else
			{
				/* Free cookies because they should be blocked */
				for(cookie=unknownCookies; cookie; cookie=cookie->next)
				{
					soup_cookie_free((SoupCookie*)cookie->data);
				}
			}
	}

	/* Add accepted cookies to cookie jar */
	for(cookie=acceptedCookies; cookie; cookie=cookie->next)
	{
		soup_cookie_jar_add_cookie(priv->cookieJar, (SoupCookie*)cookie->data);
	}

	/* Free list of cookies */
	g_slist_free(unknownCookies);
	g_slist_free(acceptedCookies);
	g_slist_free(newCookies);
}