Bug 92761 - Add callbacks to the FrameLoaderClient when a resource is requested
Summary: Add callbacks to the FrameLoaderClient when a resource is requested
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Marja Hölttä
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-31 08:40 PDT by jochen
Modified: 2012-11-28 00:20 PST (History)
11 users (show)

See Also:


Attachments
Patch (25.35 KB, patch)
2012-07-31 08:45 PDT, jochen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from gce-cr-linux-05 (111.68 KB, application/zip)
2012-07-31 09:12 PDT, WebKit Review Bot
no flags Details
Patch (25.33 KB, patch)
2012-08-01 00:26 PDT, jochen
no flags Details | Formatted Diff | Diff
Patch (25.30 KB, patch)
2012-08-01 00:32 PDT, jochen
no flags Details | Formatted Diff | Diff
Patch (25.62 KB, patch)
2012-08-01 03:40 PDT, jochen
no flags Details | Formatted Diff | Diff
Patch (19.67 KB, patch)
2012-10-16 19:36 PDT, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (19.57 KB, patch)
2012-10-17 10:13 PDT, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (20.74 KB, patch)
2012-11-22 01:33 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (23.02 KB, patch)
2012-11-22 05:11 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (31.30 KB, patch)
2012-11-23 03:45 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (31.86 KB, patch)
2012-11-23 06:35 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (31.55 KB, patch)
2012-11-23 06:52 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (31.22 KB, patch)
2012-11-27 07:31 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (30.66 KB, patch)
2012-11-27 07:44 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (30.56 KB, patch)
2012-11-27 09:21 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jochen 2012-07-31 08:40:01 PDT
Add callbacks to the FrameLoaderClient for when a resource request finished for a script or image element
Comment 1 jochen 2012-07-31 08:45:14 PDT
Created attachment 155552 [details]
Patch
Comment 2 jochen 2012-07-31 08:45:44 PDT
Adam, can you have a look plz
Comment 3 WebKit Review Bot 2012-07-31 08:58:01 PDT
Please wait for approval from abarth@webkit.org, dglazkov@chromium.org, fishd@chromium.org, jamesr@chromium.org or tkent@chromium.org before submitting, as this patch contains changes to the Chromium public API. See also https://trac.webkit.org/wiki/ChromiumWebKitAPI.
Comment 4 WebKit Review Bot 2012-07-31 09:12:33 PDT
Comment on attachment 155552 [details]
Patch

Attachment 155552 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13386888

New failing tests:
canvas/philip/tests/2d.composite.image.source-over.html
http/tests/cache/stopped-revalidation.html
canvas/philip/tests/2d.composite.globalAlpha.canvas.html
canvas/philip/tests/2d.composite.globalAlpha.fill.html
canvas/philip/tests/2d.composite.clip.source-over.html
canvas/philip/tests/2d.composite.globalAlpha.imagepattern.html
canvas/philip/tests/2d.clearRect.zero.html
canvas/philip/tests/2d.composite.canvas.source-in.html
canvas/philip/tests/2d.composite.canvas.destination-out.html
accessibility/loading-iframe-sends-notification.html
canvas/philip/tests/2d.clearRect.globalcomposite.html
canvas/philip/tests/2d.clearRect.clip.html
canvas/philip/tests/2d.composite.clip.lighter.html
canvas/philip/tests/2d.composite.image.source-in.html
canvas/philip/tests/2d.composite.image.lighter.html
canvas/philip/tests/2d.composite.clip.destination-atop.html
canvas/philip/tests/2d.composite.image.destination-out.html
canvas/philip/tests/2d.composite.image.destination-atop.html
canvas/philip/tests/2d.clearRect.path.html
accessibility/image-link-inline-cont.html
canvas/philip/tests/2d.composite.canvas.destination-atop.html
canvas/philip/tests/2d.composite.clip.destination-out.html
accessibility/content-changed-notification-causes-crash.html
canvas/philip/tests/2d.composite.canvas.lighter.html
accessibility/img-alt-tag-only-whitespace.html
canvas/philip/tests/2d.composite.canvas.source-over.html
canvas/philip/tests/2d.composite.clip.source-in.html
canvas/philip/tests/2d.clearRect+fillRect.alpha0.html
Comment 5 WebKit Review Bot 2012-07-31 09:12:39 PDT
Created attachment 155562 [details]
Archive of layout-test-results from gce-cr-linux-05

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-05  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 6 Build Bot 2012-07-31 09:38:18 PDT
Comment on attachment 155552 [details]
Patch

Attachment 155552 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13400486
Comment 7 jochen 2012-08-01 00:26:17 PDT
Created attachment 155734 [details]
Patch
Comment 8 jochen 2012-08-01 00:32:11 PDT
Created attachment 155735 [details]
Patch
Comment 9 jochen 2012-08-01 03:40:31 PDT
Created attachment 155773 [details]
Patch
Comment 10 Adam Barth 2012-08-01 11:30:03 PDT
Comment on attachment 155773 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=155773&action=review

I'm tempted to r+ this with comments, but I think I'd like to see one more round, if that's ok with you.

> Source/WebCore/loader/FrameLoaderClient.h:167
> +        virtual void dispatchImageLoadFinished(Element*, CachedResource*) { }
> +        virtual void dispatchScriptLoadFinished(Element*, CachedResource*) { }

Why not provide more concerete types?  e.g., dispatchImageLoadFinished(Element*, CachedImage*) { }

> Source/WebCore/loader/ImageLoader.cpp:270
> +    document()->loader()->frameLoader()->client()->dispatchImageLoadFinished(client()->sourceElement(), resource);

Going through the DocumentLoader for these calls doesn't seem quite right.  It makes more sense to me to go through the Frame:

document()->frame()->loader()->client()->dispatchImageLoadFinished(client()->sourceElement(), resource);

Also, do we need to null-check the frame?

> Source/WebKit/chromium/public/WebFrameClient.h:227
> +    // The URL request for the given image element finished loading.
> +    virtual void imageLoadFinished(WebFrame*, const WebElement&, const WebURLRequest&) { }

imageLoadFinished -> didFinishImageLoad

That fits the naming pattern of the functions above.

> Source/WebKit/chromium/public/WebFrameClient.h:230
> +    // The URL request for the given script element finished loading.
> +    virtual void scriptLoadFinished(WebFrame*, const WebElement&, const WebURLRequest&) { }

ditto

> Source/WebKit/chromium/src/FrameLoaderClientImpl.h:111
> +    virtual void dispatchImageLoadFinished(WebCore::Element* sourceElement, WebCore::CachedResource*);
> +    virtual void dispatchScriptLoadFinished(WebCore::Element* sourceElement, WebCore::CachedResource*);

These should also probably be like dispatchDidFinishImageLoad to match the similar callbacks above.
Comment 11 jochen 2012-08-01 11:44:49 PDT
I have another question for you:

as is, the callbacks are only invoked when the requested resource was not in the cache but had to be loaded. I guess that's ok for the targetted use case, because we'd return a temporary error for the resource load, and I expect that every element will end up trying to load the resource over the network. Is that correct?
Comment 12 Adam Barth 2012-08-01 11:59:10 PDT
> as is, the callbacks are only invoked when the requested resource was not in the cache but had to be loaded. I guess that's ok for the targetted use case, because we'd return a temporary error for the resource load, and I expect that every element will end up trying to load the resource over the network. Is that correct?

Doesn't didLoadResourceFromMemoryCache cover that case?  Maybe we should have a unified didLoadResourceFromNetwork callback rather than per-type notifications.
Comment 13 jochen 2012-08-01 12:21:55 PDT
(In reply to comment #12)
> > as is, the callbacks are only invoked when the requested resource was not in the cache but had to be loaded. I guess that's ok for the targetted use case, because we'd return a temporary error for the resource load, and I expect that every element will end up trying to load the resource over the network. Is that correct?
> 
> Doesn't didLoadResourceFromMemoryCache cover that case?  Maybe we should have a unified didLoadResourceFromNetwork callback rather than per-type notifications.

that callback doesn't have the element that requested the resource. The main point of the new callbacks is to connect the element with the request for the embedder.

Of course, not all requests have an associated element, so I didn't come up with a good name and figured individual callbacks would be clearer
Comment 14 Adam Barth 2012-08-01 13:25:16 PDT
> Of course, not all requests have an associated element, so I didn't come up with a good name and figured individual callbacks would be clearer

I mean, not all image loads have an element either, so we need to solve that problem in any case.
Comment 15 Marja Hölttä 2012-10-16 19:36:38 PDT
Created attachment 169073 [details]
Patch
Comment 16 Marja Hölttä 2012-10-17 10:13:02 PDT
Created attachment 169205 [details]
Patch
Comment 17 Adam Barth 2012-10-17 10:43:28 PDT
This is another example of a use-case we have for tracking who initiated a load.
Comment 18 Adam Barth 2012-10-17 10:44:18 PDT
Bug 84883 has another approach for doing something similar.
Comment 19 Adam Barth 2012-10-17 11:56:38 PDT
Comment on attachment 169205 [details]
Patch

We discussed this over VC.  We're going to merge this work with the work on the bug mentioned above.  The plan is to create a CachedResourceRequest and then to have a frameloaderclient callback similar to willSendRequest but for this CachedResourceRequest.
Comment 20 Marja Hölttä 2012-11-22 01:33:47 PST
Created attachment 175621 [details]
Patch
Comment 21 Marja Hölttä 2012-11-22 05:11:28 PST
Created attachment 175651 [details]
Patch
Comment 22 Build Bot 2012-11-22 06:07:50 PST
Comment on attachment 175651 [details]
Patch

Attachment 175651 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14961377
Comment 23 jochen 2012-11-22 06:58:14 PST
Comment on attachment 175651 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175651&action=review

> Source/WebCore/loader/FrameLoaderClient.h:170
> +        virtual void dispatchResourceRequested(const AtomicString& initiatorName, const KURL&) { }

you need to omit "initatorName" as it's unused

> Source/WebCore/loader/cache/CachedResourceLoader.cpp:426
> +    if (Frame* f = frame()) {

do you know when frame is 0?

> Source/WebCore/loader/cache/CachedResourceLoader.cpp:430
> +            f->loader()->client()->dispatchResourceRequested(request.initiatorName(), request.resourceRequest().url());

what should happen if initiatorName is ""?

> LayoutTests/platform/chromium/fast/loader/resource-request-callbacks.html:62
> +  This test checks that the correct callbacks for resource requests are

nit. indent 4 spaces
Comment 24 Adam Barth 2012-11-22 08:54:36 PST
Comment on attachment 175651 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175651&action=review

> Source/WebCore/loader/FrameLoaderClient.h:169
> +        virtual void dispatchResourceRequested(Element*, const KURL&) { }

These are really "WillRequestResource" since the request hasn't happened yet.

Also, why not pass the entire CachedResourceRequest?  That would seem to give the WebKit layer the most flexibility.
Comment 25 Marja Hölttä 2012-11-23 03:45:15 PST
Created attachment 175771 [details]
Patch
Comment 26 Marja Hölttä 2012-11-23 03:48:14 PST
Comment on attachment 175651 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175651&action=review

>> Source/WebCore/loader/FrameLoaderClient.h:169
>> +        virtual void dispatchResourceRequested(Element*, const KURL&) { }
> 
> These are really "WillRequestResource" since the request hasn't happened yet.
> 
> Also, why not pass the entire CachedResourceRequest?  That would seem to give the WebKit layer the most flexibility.

Renamed this to dispatchWillRequestResource & renamed other funcs correspondingly. Added WebCachedResourceRequest and passed that to the WebKit layer.

>> Source/WebCore/loader/FrameLoaderClient.h:170
>> +        virtual void dispatchResourceRequested(const AtomicString& initiatorName, const KURL&) { }
> 
> you need to omit "initatorName" as it's unused

Done

>> Source/WebCore/loader/cache/CachedResourceLoader.cpp:426
>> +    if (Frame* f = frame()) {
> 
> do you know when frame is 0?

In requestImage, there is check for frame() being 0, and it calls this func even in that case -> we need to check here, too.

>> Source/WebCore/loader/cache/CachedResourceLoader.cpp:430
>> +            f->loader()->client()->dispatchResourceRequested(request.initiatorName(), request.resourceRequest().url());
> 
> what should happen if initiatorName is ""?

This is no longer an issue since we're passing a WebCachedResourceRequest.

>> LayoutTests/platform/chromium/fast/loader/resource-request-callbacks.html:62
>> +  This test checks that the correct callbacks for resource requests are
> 
> nit. indent 4 spaces

Done
Comment 27 WebKit Review Bot 2012-11-23 04:32:27 PST
Comment on attachment 175771 [details]
Patch

Attachment 175771 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/14961729

New failing tests:
fast/text/atsui-small-caps-punctuation-size.html
Comment 28 jochen 2012-11-23 04:40:24 PST
Comment on attachment 175771 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175771&action=review

> Source/WebKit/chromium/public/WebCachedResourceRequest.h:32
> +#define WebCachedResourceRequest_h

I think this should go into Source/Platform/chromium/public

> Source/WebKit/chromium/public/WebCachedResourceRequest.h:53
> +    WEBKIT_EXPORT WebURL url() const;

why not return a WebURLRequest?

> Source/WebKit/chromium/public/WebCachedResourceRequest.h:65
> +protected:

why not private?
Comment 29 jochen 2012-11-23 05:04:54 PST
(In reply to comment #28)
> (From update of attachment 175771 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=175771&action=review
> 
> > Source/WebKit/chromium/public/WebCachedResourceRequest.h:32
> > +#define WebCachedResourceRequest_h
> 
> I think this should go into Source/Platform/chromium/public

Actually, disregard that comment, the location is already correct
Comment 30 Marja Hölttä 2012-11-23 06:35:17 PST
Created attachment 175795 [details]
Patch
Comment 31 Marja Hölttä 2012-11-23 06:36:02 PST
Comment on attachment 175771 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175771&action=review

>> Source/WebKit/chromium/public/WebCachedResourceRequest.h:53
>> +    WEBKIT_EXPORT WebURL url() const;
> 
> why not return a WebURLRequest?

Done

>> Source/WebKit/chromium/public/WebCachedResourceRequest.h:65
>> +protected:
> 
> why not private?

Done
Comment 32 jochen 2012-11-23 06:43:41 PST
looks quite reasonable, I like it. Let's wait for Adam
Comment 33 Marja Hölttä 2012-11-23 06:52:51 PST
Created attachment 175800 [details]
Patch
Comment 34 Marja Hölttä 2012-11-23 06:56:24 PST
The latest patch also renames the new class to WebCachedURLRequest (as discussed).

abarth@, could you have a look?
Comment 35 Adam Barth 2012-11-26 11:22:44 PST
Comment on attachment 175800 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175800&action=review

> Source/WebKit/chromium/public/WebCachedURLRequest.h:48
> +    ~WebCachedURLRequest();

This isn't quite the right pattern for the dtor.  The problem is that you haven't exported the dtor and it's neither virtual nor inline.  Take a look at WebURLRequest for the correct pattern.  Basically, you want an inline dtor that calls an exported reset() function.

> Source/WebKit/chromium/public/WebCachedURLRequest.h:53
> +    void assign(const WebCachedURLRequest&);
> +    bool equals(const WebCachedURLRequest&) const;

These need to be exported.  See WebURLRequest for an example.

> Source/WebKit/chromium/public/WebCachedURLRequest.h:56
> +    WEBKIT_EXPORT WebString charset() const;

Don't you need to include WebString.h for these declaration?

> Source/WebKit/chromium/public/WebCachedURLRequest.h:59
> +    WEBKIT_EXPORT WebElement initiatorElement() const;

I would expect you'd need to include WebElement as well.

> Source/WebKit/chromium/src/WebCachedURLRequest.cpp:37
> +#include <public/WebElement.h>

There's no public/ prefix for WebElement.

We need to improve the header including patterns, but headers in the Client part of the API (the part in WebKit/chromium/public) are just included with their base name.  Headers in the Platform part of the API (the part in Platform/chromium/public) need the public/WebFoo.h pattern.
Comment 36 Adam Barth 2012-11-26 11:29:35 PST
Comment on attachment 175800 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175800&action=review

> Source/WebKit/chromium/public/WebCachedURLRequest.h:50
> +    WebCachedURLRequest(const WebCachedURLRequest& r) { assign(r); }

The problem with this API is that it implies that the embedder can retain a WebCachedURLRequest object.  However, because m_private is a raw pointer, the embedder has no control over the lifetime of the object m_private points to and can easily end up with a garbage pointer.

The solution to this problem is to move the constructor, destructor, and operator= to the private section of the class declaration.  That implies that the embedder can receive a pointer (or a reference) to this type of object but cannot make a copy.

> Source/WebKit/chromium/src/WebCachedURLRequest.cpp:52
> +    m_private = other.m_private;

This assign() function doesn't move over m_resourceRequestWrapper.  That's likely because m_resourceRequestWrapper is a WebPrivateOwnPtr, which prevents copies.  Instead of having a wonky asign() function, we just need to prevent copies of WebCachedURLRequest as well.
Comment 37 Adam Barth 2012-11-26 11:29:55 PST
The general approach in this patch looks good.  We just need to clean up the API design a bit.
Comment 38 Marja Hölttä 2012-11-27 07:31:20 PST
Created attachment 176263 [details]
Patch
Comment 39 Adam Barth 2012-11-27 07:39:52 PST
Comment on attachment 176263 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176263&action=review

> Source/WebKit/chromium/public/WebCachedURLRequest.h:38
> +#include <wtf/Noncopyable.h>

We cannot include WTF headers in the API.

> Source/WebKit/chromium/public/WebCachedURLRequest.h:50
> +WTF_MAKE_NONCOPYABLE(WebCachedURLRequest);

You need to do this manually rather than using the macro.
Comment 40 Marja Hölttä 2012-11-27 07:44:09 PST
Created attachment 176266 [details]
Patch
Comment 41 Marja Hölttä 2012-11-27 07:47:35 PST
Comment on attachment 175800 [details]
Patch

Thanks for comments!
Comment 42 Adam Barth 2012-11-27 09:13:34 PST
Comment on attachment 176266 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176266&action=review

Thanks for iterating on the API.  This patch looks good with one minor nit below.

> Source/WebKit/chromium/public/WebCachedURLRequest.h:37
> +#include "platform/WebCommon.h"
> +#include "platform/WebPrivateOwnPtr.h"
> +#include <public/WebString.h>

These includes are inconsistent.  I think we use the "platform/" style in the API.
Comment 43 Marja Hölttä 2012-11-27 09:21:27 PST
Created attachment 176285 [details]
Patch
Comment 44 Adam Barth 2012-11-27 09:25:52 PST
Comment on attachment 176285 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176285&action=review

> Source/WebKit/chromium/public/WebCachedURLRequest.h:44
> +class WebElement;
> +class WebString;

These aren't needed anymore, but they're also not harmful.
Comment 45 WebKit Review Bot 2012-11-27 10:01:46 PST
Comment on attachment 176285 [details]
Patch

Clearing flags on attachment: 176285

Committed r135872: <http://trac.webkit.org/changeset/135872>
Comment 46 WebKit Review Bot 2012-11-27 10:01:53 PST
All reviewed patches have been landed.  Closing bug.
Comment 47 Tony Chang 2012-11-27 10:34:25 PST
This broke the clang compile. I landed a fix in http://trac.webkit.org/changeset/135877.
Comment 48 Marja Hölttä 2012-11-28 00:20:20 PST
tony@: Ahh, I see. Thanks for fixing it!