RESOLVED FIXED 101935
Add initiator to CachedResourceRequest.
https://bugs.webkit.org/show_bug.cgi?id=101935
Summary Add initiator to CachedResourceRequest.
Marja Hölttä
Reported 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.
Attachments
Patch (30.98 KB, patch)
2012-11-12 07:03 PST, Marja Hölttä
no flags
Patch (48.98 KB, patch)
2012-11-13 08:08 PST, Marja Hölttä
no flags
Patch (48.97 KB, patch)
2012-11-13 08:11 PST, Marja Hölttä
no flags
Patch (48.96 KB, patch)
2012-11-13 08:19 PST, Marja Hölttä
no flags
Patch (48.43 KB, patch)
2012-11-13 10:01 PST, Marja Hölttä
no flags
Patch (48.43 KB, patch)
2012-11-14 05:23 PST, Marja Hölttä
no flags
Patch (48.36 KB, patch)
2012-11-14 09:52 PST, Marja Hölttä
no flags
Patch (48.37 KB, patch)
2012-11-15 07:49 PST, Marja Hölttä
no flags
Marja Hölttä
Comment 1 2012-11-12 07:03:41 PST
jochen
Comment 2 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)
Adam Barth
Comment 3 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.
Adam Barth
Comment 4 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?
Adam Barth
Comment 5 2012-11-12 12:23:03 PST
I think this generally looks fine. The comments above are all somewhat minor.
Marja Hölttä
Comment 6 2012-11-13 08:08:50 PST
Marja Hölttä
Comment 7 2012-11-13 08:11:42 PST
WebKit Review Bot
Comment 8 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.
Marja Hölttä
Comment 9 2012-11-13 08:19:55 PST
Marja Hölttä
Comment 10 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.
Marja Hölttä
Comment 11 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..
Adam Barth
Comment 12 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.
Marja Hölttä
Comment 13 2012-11-13 10:01:58 PST
Marja Hölttä
Comment 14 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.
Adam Barth
Comment 15 2012-11-13 10:09:23 PST
Comment on attachment 173917 [details] Patch Thanks for iterating on this patch.
WebKit Review Bot
Comment 16 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>
WebKit Review Bot
Comment 17 2012-11-13 10:53:13 PST
All reviewed patches have been landed. Closing bug.
Darin Adler
Comment 18 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.
Marja Hölttä
Comment 19 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.
Oliver Hunt
Comment 20 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.
Adam Barth
Comment 21 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
WebKit Review Bot
Comment 22 2012-11-13 11:46:24 PST
Re-opened since this is blocked by bug 102111
Oliver Hunt
Comment 23 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.
Adam Barth
Comment 24 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.
Marja Hölttä
Comment 25 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.
Marja Hölttä
Comment 26 2012-11-14 05:23:02 PST
Marja Hölttä
Comment 27 2012-11-14 09:52:15 PST
Marja Hölttä
Comment 28 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.)
Build Bot
Comment 29 2012-11-14 10:28:57 PST
Build Bot
Comment 30 2012-11-14 20:24:19 PST
Marja Hölttä
Comment 31 2012-11-15 07:49:51 PST
Marja Hölttä
Comment 32 2012-11-16 03:43:31 PST
Comment on attachment 174440 [details] Patch The bots are green now.
WebKit Review Bot
Comment 33 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>
WebKit Review Bot
Comment 34 2012-11-16 04:22:40 PST
All reviewed patches have been landed. Closing bug.
James Simonsen
Comment 35 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?
Marja Hölttä
Comment 36 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).
Note You need to log in before you can comment on or make changes to this bug.