Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRedirect document loads manually #15354
Conversation
highfive
commented
Feb 2, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Feb 2, 2017
|
5430cd9
to
f12f783
|
@jdm Fixed. |
| FetchResponseMsg::ProcessResponse(res_metadata) => { | ||
| match res_metadata { | ||
| Ok(metadata) => { | ||
| match metadata { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 3, 2017
Member
It looks very much like you can combine the 4 matches above into a single match.
This comment has been minimized.
This comment has been minimized.
cynicaldevil
Feb 3, 2017
Author
Contributor
Yeah, I thought there might be a better method to do this, but I went for the easy route anyway :P I'll look into it.
|
This is a good start! The conversion to process the response asynchronously is the biggest issue here; I recommend taking a look at how the ParserContext and NetworkListener types work, since that's what the script crate uses for the same purpose |
| sender)) { | ||
| warn!("Exit resource thread failed ({})", e); | ||
| } | ||
| match receiver.recv() { |
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
One problem here is that this is a synchronous interaction with the network thread. This means that the constellation will not be able to process anything else besides a single network request at a time, which will be very inefficient. We should be using a mechanism like script's NetworkListener, which receives notifications on the network thread and forwards them to the script thread's event loop via a sender. This means that the constellation will need to keep track of in-progress loads so it can know how to deal with them from the regular event loop.
| @@ -197,6 +198,9 @@ pub enum DiscardBrowsingContext { | |||
| /// Messages sent from the constellation or layout to the script thread. | |||
| #[derive(Deserialize, Serialize)] | |||
| pub enum ConstellationControlMsg { | |||
| /// Sends the final request to script thread for fetching after all redirections | |||
| /// have been resolved | |||
| FinalRequest(PipelineId, RequestInit), | |||
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
This will be able to contain a Result<FetchMetadata, ...> instead of RequestInit if the constellation sends the final response header received instead. We can call it NavigationResponse instead
| @@ -66,6 +66,9 @@ pub enum LogEntry { | |||
| /// Messages from the script to the constellation. | |||
| #[derive(Deserialize, Serialize)] | |||
| pub enum ScriptMsg { | |||
| /// Requests are sent to constellation and fetches are checked manually | |||
| /// for cross-origin loads | |||
| ManualRedirect(PipelineId, LoadData), | |||
This comment has been minimized.
This comment has been minimized.
| let context = Arc::new(Mutex::new(ParserContext::new(id, load_data.url.clone()))); | ||
| /// Initiate a non-blocking fetch for a specified resource. | ||
| fn start_page_load(&self, id: PipelineId, mut req_init: RequestInit) { | ||
| let context = Arc::new(Mutex::new(ParserContext::new(id, req_init.url.clone()))); |
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
This is where we should be able to invoke the FetchResponseListener methods using the data provided by the constellation.
| @@ -2073,12 +2075,17 @@ impl ScriptThread { | |||
| window.evaluate_media_queries_and_report_changes(); | |||
| } | |||
|
|
|||
| /// Initiate a non-blocking fetch for a specified resource. Stores the InProgressLoad | |||
| /// Sends a message to constellation to check for cross-origin redirects. Stores the InProgressLoad | |||
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
/// Instructs the constellation to fetch the document that will be loaded. Stores the ...
| @@ -75,6 +75,19 @@ pub enum ResponseMsg { | |||
| Errored, | |||
| } | |||
|
|
|||
| #[derive(Serialize, Deserialize, Clone)] | |||
| pub struct ResponseInit { | |||
| pub url: ServoUrl, | |||
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
We will need more data here; for example, http_redirect_fetch looks at the headers of the response, and those will be initialized as empty in this case. The FetchMetadata type is serializable and contains everything we should need, I believe.
| pub url: ServoUrl, | ||
| } | ||
|
|
||
| impl Default for ResponseInit { |
This comment has been minimized.
This comment has been minimized.
| }; | ||
| } | ||
|
|
||
| let msg = ConstellationControlMsg::FinalRequest(id, req_init); |
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
I'm not looking at the rest of the code in this method, because I believe that restructuring it to use an async fetch listener will change it significantly.
| _ => break | ||
| }; | ||
| match data { | ||
| Some((FilteredMetadata::OpaqueRedirect, _)) => { |
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
We will need to deal with non-cross-origin redirects as well, which won't be tagged as OpaqueRedirect.
| match unsafe_metadata.headers { | ||
| Some(headers) => match headers.get::<Location>() { | ||
| Some(url) => { | ||
| match ServoUrl::parse(url) { |
This comment has been minimized.
This comment has been minimized.
jdm
Feb 3, 2017
Member
We should not need to process the location header at all; that's handled by http_redirect_fetch. We only need to check if the header is present.
This comment has been minimized.
This comment has been minimized.
cynicaldevil
Feb 9, 2017
Author
Contributor
@jdm But how else do I extract the url to modify req_init to be sent to resource_thread?
This comment has been minimized.
This comment has been minimized.
jdm
Feb 10, 2017
Member
Why does req_init need to be modified? Send the original one along with the response.
This comment has been minimized.
This comment has been minimized.
jdm
Feb 10, 2017
•
Member
Although it occurs to me that that would break the following case:
- fetch http://foo.com
- redirect to http://bar.com
- redirect to /foo.html
However, the response contains a url list, so it should be possible to parse the location value using the most recent entry in the url list, and progressively move backwards until a successfull URL is parsed.
f12f783
to
fe06513
|
@jdm I've implemented the listener code and also added other small changes, but I'm not sure if this is what you had in mind :) |
| } | ||
|
|
||
| impl NetworkListener { | ||
| pub fn notify(&self, message: Result<FetchMetadata, NetworkError>) { |
This comment has been minimized.
This comment has been minimized.
cynicaldevil
Feb 14, 2017
Author
Contributor
I stole most of the names from script/network_listener.rs, since I'm not very good at naming things :P
| Some(headers) => { | ||
| if headers.has::<Location>() { | ||
| let (sender, _) = ipc::channel().expect("Failed to create IPC channel!"); | ||
| result = Some(sender.send(ScriptMsg::InitiateNavigateRequest( |
This comment has been minimized.
This comment has been minimized.
cynicaldevil
Feb 14, 2017
Author
Contributor
I send a message back to constellation so that the process starts all over again from here.
|
|
fe06513
to
424b194
|
Have you tried running this on any pages? As far as I can tell, there's no code that propagates the response body from the constellation to the script thread, so no pages will end up being parsed. Additionally, I would expect the message conversion code in the router listener to panic. |
|
@jdm Hmm...so right now I am only processing headers by acknowledging messages of type |
|
All of the FetchResponseMsg messages will be send to the constellation for every response, whether it redirects or not. |
|
weird, the closure inside the router listener is never being called, although I'm pretty sure that the message is being sent. Am I using the router listener correctly? Edit: nvm, the response I'm sending doesn't have any location headers set and therefore http_redirect_fetch is returning early. Hence this :P |
|
|
|
I don't see how we can do async fetches if we want to use |
|
Let's duplicate the code inside main fetch step 19 before returning early in step 13. I've filed whatwg/html#2396 about resolving this issue in the specification. |
|
Actually, that issue points out that we could probably address this by not setting the recursive flag when invoking the http-redirect fetch algorithm as a top-level algorithm as we do in this PR. |
cc2b6be
to
ea59b0b
|
@bors-servo try |
Redirect document loads manually <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14596 . r? @jdm I ran some tests at random from the `navigating-across-documents` folder, and they are passing. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15354) <!-- Reviewable:end -->
|
|
ea59b0b
to
bb8db03
|
@bors-servo try |
Redirect document loads manually <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14596 . r? @jdm I ran some tests at random from the `navigating-across-documents` folder, and they are passing. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15354) <!-- Reviewable:end -->
|
|
bb8db03
to
541baaf
|
@jdm Ready for merge now. |
|
@bors-servo: r+ |
|
|
Redirect document loads manually <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14596 . r? @jdm I ran some tests at random from the `navigating-across-documents` folder, and they are passing. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15354) <!-- Reviewable:end -->
|
|
cynicaldevil commentedFeb 2, 2017
•
edited
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsr? @jdm
I ran some tests at random from the
navigating-across-documentsfolder, and they are passing.This change is