[webkit-dev] How to cancel a resource request

Jaroslav Gresula jgresula.LEAVE-THIS-OUT at gmail.com
Fri Oct 23 07:37:59 PDT 2009

Xan Lopez wrote:
> On Fri, Oct 23, 2009 at 5:05 PM, Jaroslav Gresula
> <jgresula.LEAVE-THIS-OUT at gmail.com> wrote:
>> Xan Lopez wrote:
>>> On Thu, Oct 22, 2009 at 11:18 AM, Jaroslav Gresula
>>> <jgresula.LEAVE-THIS-OUT at gmail.com> wrote:
>>>> Hi,
>>>> In my WebKit port (based on the GTK port) I would like to cancel a
>>>> resource request depending on the resource length or its MIME type.
>>>> I thought, dispatchDidReceiveResponse(DocumentLoader*, ...) in my
>>>> WebCore::FrameLoaderClient implementation could be a good place for such
>>>> action as I can retrieve the length and the MIME type from the
>>>> ResourceResponse argument there. However I did not find the way how to
>>>> cancel the request.
>>>> Any help would be appreciated.
>>> in dispatchWillSendRequest you can modify the URI of the resource
>>> that's about to be requested. If you set it to, say, "about:blank",
>>> nothing will be requested. This is what the GTK+ port does, through a
>>> signal emission, to let clients implement things like adblock.
>> That's a nice trick but is the resource MIME type and its length known
>> at this point? My understanding is that this information is not
>> available until dispatchDidReceiveResponse().
> Well, no, but since you were asking how to cancel the request I
> assumed you wanted to do it before it was done, not after... If you
> want to do things based on the MIME type of the resource see
> dispatchDecidePolicyForMIMEType, which also carries the
> ResourceRequest.

Ok, let me rephrase my question: what I need is to cancel an ongoing
(sub)resource request once its length and MIME type are known. This way
I could avoid retrieving of resources whose length exceeds certain limit
or whose MIME type can't be handled by my port.

I've already looked at dispatchDecidePolicyForMIMEType() and it seemed
to me that it is invoked only for the main resource but not for
sub-resources (i.e. images) - I will look into it closer.


More information about the webkit-dev mailing list