Bug 101935 - Add initiator to CachedResourceRequest.
Summary: Add initiator to CachedResourceRequest.
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: 102111
Blocks: 102064
  Show dependency treegraph
 
Reported: 2012-11-12 06:54 PST by Marja Hölttä
Modified: 2012-11-27 02:10 PST (History)
16 users (show)

See Also:


Attachments
Patch (30.98 KB, patch)
2012-11-12 07:03 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.98 KB, patch)
2012-11-13 08:08 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.97 KB, patch)
2012-11-13 08:11 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.96 KB, patch)
2012-11-13 08:19 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.43 KB, patch)
2012-11-13 10:01 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.43 KB, patch)
2012-11-14 05:23 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.36 KB, patch)
2012-11-14 09:52 PST, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (48.37 KB, patch)
2012-11-15 07:49 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 Marja Hölttä 2012-11-12 06:54:55 PST
This is needed for bug 92761 and for bug 84883.

This differs from simonjam's approach in bug 101300: We don't store a CachedResourceRequest anywhere, so it doesn't store references to the initiator objects.
Comment 1 Marja Hölttä 2012-11-12 07:03:41 PST
Created attachment 173641 [details]
Patch
Comment 2 jochen 2012-11-12 07:14:23 PST
Comment on attachment 173641 [details]
Patch

What are you gonna do about CachedResourceRequests created by the ThreadableLoader?

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

> Source/WebCore/ChangeLog:8
> +        Motivation: at least one embedder needs to know which elements request a

uh, which embedder might that be?

> Source/WebCore/css/CSSFontFaceSrcValue.cpp:100
> +        request.setInitiator("css", document);

should stuff like "css" be an AtomicString (see e.g. dom/EventNames.h)
Comment 3 Adam Barth 2012-11-12 12:20:07 PST
Comment on attachment 173641 [details]
Patch

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

> Source/WebCore/css/CSSImageValue.h:70
> +    RefPtr<Element> m_initiatorElement;

Are we worried about the amount of extra storage this requires?  A document might have many CSSImageValues...

> Source/WebCore/html/parser/HTMLPreloadScanner.cpp:146
> +    RefPtr<Document> m_document;

I don't understand why you made these changes.  It seems like we already had document in preload().  There doesn't seem to be a reason to ref the document here.
Comment 4 Adam Barth 2012-11-12 12:21:27 PST
Comment on attachment 173641 [details]
Patch

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

Should we add an ASSERT somewhere that we always set an initiator?

> Source/WebCore/loader/cache/CachedResourceRequest.h:74
> +    RefPtr<Element> m_initiatorElement;
> +    RefPtr<Document> m_initiatorDocument;

Can both of these be non-0 at the same time?
Comment 5 Adam Barth 2012-11-12 12:23:03 PST
I think this generally looks fine.  The comments above are all somewhat minor.
Comment 6 Marja Hölttä 2012-11-13 08:08:50 PST
Created attachment 173895 [details]
Patch
Comment 7 Marja Hölttä 2012-11-13 08:11:42 PST
Created attachment 173897 [details]
Patch
Comment 8 WebKit Review Bot 2012-11-13 08:16:15 PST
Attachment 173897 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/CMakeLists.txt', u'Source/W..." exit_code: 1
Source/WebCore/platform/ThreadGlobalData.h:44:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
Total errors found: 1 in 35 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Marja Hölttä 2012-11-13 08:19:55 PST
Created attachment 173900 [details]
Patch
Comment 10 Marja Hölttä 2012-11-13 08:29:00 PST
Comment on attachment 173641 [details]
Patch

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

>> Source/WebCore/ChangeLog:8
>> +        Motivation: at least one embedder needs to know which elements request a
> 
> uh, which embedder might that be?

Changed to "Chromium needs to know".

>> Source/WebCore/css/CSSFontFaceSrcValue.cpp:100
>> +        request.setInitiator("css", document);
> 
> should stuff like "css" be an AtomicString (see e.g. dom/EventNames.h)

Done.

>> Source/WebCore/css/CSSImageValue.h:70
>> +    RefPtr<Element> m_initiatorElement;
> 
> Are we worried about the amount of extra storage this requires?  A document might have many CSSImageValues...

Removed m_initiatorElement here; passing it to CSSImageValue::cachedImage as a parameter instead. (CSSCrossFaderValue & CSSCursorImageValue pass 0.)

>> Source/WebCore/html/parser/HTMLPreloadScanner.cpp:146
>> +    RefPtr<Document> m_document;
> 
> I don't understand why you made these changes.  It seems like we already had document in preload().  There doesn't seem to be a reason to ref the document here.

Yes, this was wrong -> cancelled the changes to add m_document.

>> Source/WebCore/loader/cache/CachedResourceRequest.h:74
>> +    RefPtr<Document> m_initiatorDocument;
> 
> Can both of these be non-0 at the same time?

There are asserts in the setInitiator functions which make sure that setInitiator (either version) is called only once, and that only one of these will be non-0.
Comment 11 Marja Hölttä 2012-11-13 08:31:01 PST
Thanks for comments!

abarth, can you have a look at the new patch?

I created a meta bug, bug 102064 for tracking the different phases of this work. I can split this CL further if you'd like..
Comment 12 Adam Barth 2012-11-13 09:28:48 PST
Comment on attachment 173900 [details]
Patch

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

This looks good.  Some nits below.  My main concern here is about maintenance.  We want to make sure this code is well-tested so that the initiator doesn't become copy pasta.  I appreciate that you've broken this work up into small patches, but I would like to get to the point where we can test these changes sooner rather than later.  :)

> Source/WebCore/ChangeLog:5
> +

You should leave the Reviewed by NODBODY (OPPS!) line in the ChangeLog entry.  The bots use that to know where to insert the name of the person who actually reviewed the patch.

> Source/WebCore/css/CSSCursorImageValue.cpp:142
> -    return CSSImageValue::cachedImage(loader, url());
> +    return CSSImageValue::cachedImage(loader, url(), 0);

In these cases, we won't have initiators?  Is that a problem?

> Source/WebCore/css/CSSImageValue.cpp:92
> +            request.setInitiator(cachedResourceRequestInitiators().css, loader->document());

Oh, I see.  It defaults to the document.  In that case, I might add a default argument of 0 so that the callers don't have this funny 0 hanging around.

> Source/WebCore/css/WebKitCSSSVGDocumentValue.cpp:57
> +        request.setInitiator("css", loader->document());

"css" -> cachedResourceRequestInitiators().css

> Source/WebCore/loader/cache/CachedResourceRequest.cpp:73
> +void CachedResourceRequest::setInitiator(AtomicString name, PassRefPtr<Document> document)

AtomicString -> const AtomicString& (that avoid churning the reference count)

> Source/WebCore/platform/ThreadGlobalData.cpp:32
> +#include "CachedResourceRequestInitiators.h"
>  #include "DOMImplementation.h"
>  #include "EventNames.h"

Technically these are all layering violations, but I'm not sure we have a plan for solving this problem without this layering violation.
Comment 13 Marja Hölttä 2012-11-13 10:01:58 PST
Created attachment 173917 [details]
Patch
Comment 14 Marja Hölttä 2012-11-13 10:07:16 PST
Comment on attachment 173900 [details]
Patch

Thanks for comments; the new patch set addresses them.

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

>> Source/WebCore/ChangeLog:5
>> +
> 
> You should leave the Reviewed by NODBODY (OPPS!) line in the ChangeLog entry.  The bots use that to know where to insert the name of the person who actually reviewed the patch.

Done (oops).

>> Source/WebCore/css/CSSImageValue.cpp:92
>> +            request.setInitiator(cachedResourceRequestInitiators().css, loader->document());
> 
> Oh, I see.  It defaults to the document.  In that case, I might add a default argument of 0 so that the callers don't have this funny 0 hanging around.

Done.

>> Source/WebCore/css/WebKitCSSSVGDocumentValue.cpp:57
>> +        request.setInitiator("css", loader->document());
> 
> "css" -> cachedResourceRequestInitiators().css

Done.

>> Source/WebCore/loader/cache/CachedResourceRequest.cpp:73
>> +void CachedResourceRequest::setInitiator(AtomicString name, PassRefPtr<Document> document)
> 
> AtomicString -> const AtomicString& (that avoid churning the reference count)

Done.
Comment 15 Adam Barth 2012-11-13 10:09:23 PST
Comment on attachment 173917 [details]
Patch

Thanks for iterating on this patch.
Comment 16 WebKit Review Bot 2012-11-13 10:53:07 PST
Comment on attachment 173917 [details]
Patch

Clearing flags on attachment: 173917

Committed r134442: <http://trac.webkit.org/changeset/134442>
Comment 17 WebKit Review Bot 2012-11-13 10:53:13 PST
All reviewed patches have been landed.  Closing bug.
Comment 18 Darin Adler 2012-11-13 11:25:28 PST
Comment on attachment 173917 [details]
Patch

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

Architecturally, I’m surprised that tag names are a suitable way to represent the initiator.

> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:34
> +class CachedResourceRequestInitiators {

I don’t understand why this class is named “initiators”. Do objects of this class represent multiple “initiators”? Could you explain further?

> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:38
> +public:
> +    AtomicString css;
> +    AtomicString icon;

Normally a class with public data members would be defined as a “struct” rather than “class” in WebKit.

If these data members are initialized in the constructor then maybe they should be const AtomicString instead of AtomicString?

> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:44
> +inline CachedResourceRequestInitiators& cachedResourceRequestInitiators()

Why does this return a non-const references? I don’t understand why this object is both global and mutable. This seems a different approach than what we’ve done for other global string constants such as HTML attribute names, and I don’t understand the reason for a different idiom.
Comment 19 Marja Hölttä 2012-11-13 11:37:16 PST
Comment on attachment 173917 [details]
Patch

If you'd like me to do the changes below, I could create a follow-up patch tomorrow (UTC...).

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

>> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:34
>> +class CachedResourceRequestInitiators {
> 
> I don’t understand why this class is named “initiators”. Do objects of this class represent multiple “initiators”? Could you explain further?

It could've also been called CachedResourceRequestInitiatorNames (like EventNames), but it's quite long.. Do you mean the plural (why not CachedResourceRequestInitiator instead of CachedResourceRequestInitiators) or the name in general?

>> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:38
>> +    AtomicString icon;
> 
> Normally a class with public data members would be defined as a “struct” rather than “class” in WebKit.
> 
> If these data members are initialized in the constructor then maybe they should be const AtomicString instead of AtomicString?

Copied from EventNames, but I can change them to be const AtomicString.

>> Source/WebCore/loader/cache/CachedResourceRequestInitiators.h:44
>> +inline CachedResourceRequestInitiators& cachedResourceRequestInitiators()
> 
> Why does this return a non-const references? I don’t understand why this object is both global and mutable. This seems a different approach than what we’ve done for other global string constants such as HTML attribute names, and I don’t understand the reason for a different idiom.

Also copied from EventNames, but I can change this, too.
Comment 20 Oliver Hunt 2012-11-13 11:42:51 PST
I think this patch has broken the world. CachedResourceRequestInitiators.h doesn't appear to be where it's expected to be.
Comment 21 Adam Barth 2012-11-13 11:45:19 PST
(In reply to comment #20)
> I think this patch has broken the world. CachedResourceRequestInitiators.h doesn't appear to be where it's expected to be.

rolling out now
Comment 22 WebKit Review Bot 2012-11-13 11:46:24 PST
Re-opened since this is blocked by bug 102111
Comment 23 Oliver Hunt 2012-11-13 11:53:48 PST
Okay, problems in the xcode project:
CachedScript.cpp was dropped from the project
CachedResourceRequestInitiators.{h,cpp} -- I have no idea what happened here, occasionally the hashes are identical, occasionally they mismatch.
Comment 24 Adam Barth 2012-11-13 11:55:12 PST
> Okay, problems in the xcode project:

It's probably worth rolling out anyway given that there are some comments above about the patch.
Comment 25 Marja Hölttä 2012-11-13 12:00:18 PST
Most probably the error is because of my manual xcodeproj additions -> will fix that in the new version of the patch.
Comment 26 Marja Hölttä 2012-11-14 05:23:02 PST
Created attachment 174135 [details]
Patch
Comment 27 Marja Hölttä 2012-11-14 09:52:15 PST
Created attachment 174182 [details]
Patch
Comment 28 Marja Hölttä 2012-11-14 09:54:29 PST
Comment on attachment 174182 [details]
Patch

This patch fixes the xcode build.

Also, changed the CachedResourceRequestInitiators according to Darin's suggestions: it's a struct now, ThreadGlobalData returns a const reference, and the AtomicStrings are const. (Kept the name the same; not sure what do to there.)
Comment 29 Build Bot 2012-11-14 10:28:57 PST
Comment on attachment 174182 [details]
Patch

Attachment 174182 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/14846055
Comment 30 Build Bot 2012-11-14 20:24:19 PST
Comment on attachment 174182 [details]
Patch

Attachment 174182 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14832627
Comment 31 Marja Hölttä 2012-11-15 07:49:51 PST
Created attachment 174440 [details]
Patch
Comment 32 Marja Hölttä 2012-11-16 03:43:31 PST
Comment on attachment 174440 [details]
Patch

The bots are green now.
Comment 33 WebKit Review Bot 2012-11-16 04:22:33 PST
Comment on attachment 174440 [details]
Patch

Clearing flags on attachment: 174440

Committed r134930: <http://trac.webkit.org/changeset/134930>
Comment 34 WebKit Review Bot 2012-11-16 04:22:40 PST
All reviewed patches have been landed.  Closing bug.
Comment 35 James Simonsen 2012-11-20 14:19:05 PST
Comment on attachment 174440 [details]
Patch

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

> Source/WebCore/css/CSSImageValue.cpp:90
> +            request.setInitiator(initiatorElement);

For Resource Timing, the spec says the initiator should be "css" here. Do you need it to be the element instead for some reason?
Comment 36 Marja Hölttä 2012-11-27 02:10:43 PST
Comment on attachment 174440 [details]
Patch

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

>> Source/WebCore/css/CSSImageValue.cpp:90
>> +            request.setInitiator(initiatorElement);
> 
> For Resource Timing, the spec says the initiator should be "css" here. Do you need it to be the element instead for some reason?

Afaics not. This behavior was just copied from your patch (bug 101300).