Skip to content

Implement document load tracking. - #3714

Closed
jdm wants to merge 4 commits into
servo:masterfrom
jdm:docloader
Closed

jdm wants to merge 4 commits into
servo:masterfrom
jdm:docloader

Conversation

@jdm

@jdm jdm commented Oct 17, 2014

Copy link
Copy Markdown
Member

Improves on the state of the art for #1416. Images, XHR, stylesheets, and scripts now block the document load event from firing, and DOMContentLoaded is dispatched after parsing is complete.

@hoppipolla-critic-bot

Copy link
Copy Markdown

Critic review: https://critic.hoppipolla.co.uk/r/2898

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@Ms2ger

Ms2ger commented Oct 17, 2014

Copy link
Copy Markdown
Contributor

r? @hsivonen

Comment thread components/net/image_cache_task.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this cause the load event either for the image or for the document to fire synchronously? If yes, that's bad. Events that can fire asynchronously should always fire asynchronously. Otherwise, you get weirdness/bugs like those that can be seen in Gecko around file: URLs (whose channels exhibit sync behavior) when code has usually been tested with http: URLs (whose channels exhibit async behavior).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; this causes an event to be posted to the script task event queue that could cause the load event handler to be invokved. In general, however, we're going to shake out the synchronous parts of Servo after #4057 merges, since that will enable us to hold on to DOM references in asynchronous runnables.

@hsivonen

Copy link
Copy Markdown
Contributor

Does Servo have readyState yet? I don't see readyState updating code here. Is there an object that tracks a given navigation such that the object survives across redirects that happen between the link is clicked and before you actually get to instantiate a Document that knows its real URL?

If Servo doesn't have these, I suggest implementing these sooner than later. When I tried to make Gecko's readyState sane, I discovered that such an object representing navigation was needed, state tracking should live on that object and the Document should get a reference to that object when it is created. Basically, tracking the state of the a load needs to start before the Document is created but once it is created, the state should be trivially reachable from Document.

@jdm jdm added S-needs-rebase There are merge conflict errors. S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. labels Nov 28, 2014
@jdm

jdm commented Dec 8, 2014

Copy link
Copy Markdown
Member Author

There's readyState support in master. Right now redirects are handled at the networking layer, so the document just sees the final network response which has an accompanying URL. What sort of load are you talking about that commences before there's a Document object?

@jdm jdm added S-awaiting-answer Someone asked a question that requires an answer. and removed S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. labels Dec 9, 2014
@hsivonen

Copy link
Copy Markdown
Contributor

What sort of load are you talking about that commences before there's a Document object?

I mean a load associated with a navigation away from a given Document. When you click a link, there's a period of time when the old Document occupies the browsing context, but the browsing context is busy with a load that's not about the Document in the browsing context but about the next Document that will occupy the browsing context (unless the navigation gets canceled!) and the next Document cannot be constructed before its Content-Type has arrived from the network after resolving redirects.

Gecko's handling of this period of time is very broken if you dig deeply into it, but it's OK enough that most of the time no one needs to care about the brokenness. Still, the brokenness results in not being able to assert or otherwise 100% reason about readyState transitions.

Once the next Document is created, the state of the navigation will be tracked by readyState, but before the next document exists, the navigation exists without a Document, since the old Document's readyState is not at all the right thing for tracking the navigation.

My thinking is that there should be an object representing the state of the navigation that contains an enum that progresses monotonically and the later stages of the enum map to readyState. Once the new Document exists, its readyState should reflect these later stages of the enum. It seems reasonable for the Document, once created, to take the ownership of the navigation object and to have readyState getter call through to the enum it wraps. But the browsing context should point to the most current navigation, too.

When a link has been clicked but the next Document has not been instantiated, because the final Content-Type hasn't arrived yet, the most current navigation of the browsing context and the navigation of the Document in the browsing context differ. At other times, they are the same.

(Gecko doesn't have this, and I so wish it had this.)

@jdm

jdm commented Dec 19, 2014

Copy link
Copy Markdown
Member Author

That's a super explanation; thanks!

jdm added 3 commits January 10, 2015 12:03
…s the script task when the queue is empty. Replace the current DOM load event with DOMContentLoaded and dispatch the real load event based on the DocumentLoader's notification.
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-answer Someone asked a question that requires an answer. labels Jan 10, 2015
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Jan 11, 2015
@jdm

jdm commented Mar 31, 2015

Copy link
Copy Markdown
Member Author

I'll rebase this and work on addressing Henri's suggestions at some point. Until then, no need to keep this open.

@jdm jdm closed this Mar 31, 2015
bors-servo pushed a commit that referenced this pull request May 11, 2015
This implements a simple load-tracking system and tracks stylesheet loads as an example of how it fits together. This is a simplified and rebased version of #3714; I do not believe that the main thrust of hsivonen's comments (related to tracking navigation in browsing contexts) affect this part of the work. 

r? @Ms2ger

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5804)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-code-changes Changes have not yet been made that were requested by a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants