Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect document loads manually #15354

Merged
merged 1 commit into from Jun 2, 2017
Merged

Conversation

@cynicaldevil
Copy link
Contributor

cynicaldevil commented Feb 2, 2017


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14596 .

r? @jdm

I ran some tests at random from the navigating-across-documents folder, and they are passing.


This change is Reviewable

@highfive
Copy link

highfive commented Feb 2, 2017

Heads up! This PR modifies the following files:

  • @asajeffrey: components/constellation/Cargo.toml, components/constellation/constellation.rs, components/constellation/lib.rs
  • @fitzgen: components/script/script_thread.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script_traits/lib.rs, components/script_traits/lib.rs
  • @KiChjang: components/net/resource_thread.rs, components/net/http_loader.rs, components/script/script_thread.rs, components/net_traits/lib.rs, components/net_traits/lib.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/net_traits/response.rs, components/net_traits/response.rs, components/script_traits/lib.rs, components/script_traits/lib.rs
@highfive
Copy link

highfive commented Feb 2, 2017

warning Warning warning

  • These commits modify net and script code, but no tests are modified. Please consider adding a test!
@jdm
Copy link
Member

jdm commented Feb 2, 2017

0.04s$ bash etc/ci/check_no_panic.sh

components/compositing/compositor.rs

ports/glutin/lib.rs

ports/glutin/window.rs

components/constellation/:

Cargo.toml

constellation.rs

event_loop.rs

frame.rs

lib.rs

pipeline.rs

sandboxing.rs

timer_scheduler.rs

components/constellation/constellation.rs:1411:            let (sender, receiver) = ipc::channel().unwrap();

components/constellation/constellation.rs:1414:                                              sender)).unwrap();

components/constellation/constellation.rs:1419:                            match res_metadata.unwrap() {

components/constellation/constellation.rs:1437:                                            req_init.url = ServoUrl::parse(url).unwrap();

The command "bash etc/ci/check_no_panic.sh" exited with 1.
@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch 2 times, most recently from 5430cd9 to f12f783 Feb 3, 2017
@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Feb 3, 2017

@jdm Fixed.

FetchResponseMsg::ProcessResponse(res_metadata) => {
match res_metadata {
Ok(metadata) => {
match metadata {

This comment has been minimized.

@KiChjang

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.

@cynicaldevil

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.

Copy link
Member

jdm left a comment

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.

@jdm

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.

@jdm

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.

@jdm

jdm Feb 3, 2017

Member

A more fitting name would be InitiateNavigateRequest.

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.

@jdm

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.

@jdm

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.

@jdm

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.

@jdm

jdm Feb 3, 2017

Member

Why do we need this implementation?

};
}

let msg = ConstellationControlMsg::FinalRequest(id, req_init);

This comment has been minimized.

@jdm

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.

@jdm

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.

@jdm

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.

@cynicaldevil

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.

@jdm

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.

@jdm

jdm Feb 10, 2017

Member

Although it occurs to me that that would break the following case:

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.

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch from f12f783 to fe06513 Feb 14, 2017
Copy link
Contributor Author

cynicaldevil left a comment

@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.

@cynicaldevil

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.

@cynicaldevil

cynicaldevil Feb 14, 2017

Author Contributor

I send a message back to constellation so that the process starts all over again from here.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 16, 2017

The latest upstream changes (presumably #15537) made this pull request unmergeable. Please resolve the merge conflicts.

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch from fe06513 to 424b194 Feb 16, 2017
@jdm
Copy link
Member

jdm commented Feb 17, 2017

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.

@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Feb 18, 2017

@jdm Hmm...so right now I am only processing headers by acknowledging messages of type ProcessResponse, but when I receive a non-redirecting response, I should also intercept a ProcessResponseEOF type message, right?

@jdm
Copy link
Member

jdm commented Feb 18, 2017

All of the FetchResponseMsg messages will be send to the constellation for every response, whether it redirects or not.

@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Feb 18, 2017

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

@bors-servo
Copy link
Contributor

bors-servo commented Feb 18, 2017

The latest upstream changes (presumably #15588) made this pull request unmergeable. Please resolve the merge conflicts.

@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented Feb 20, 2017

I don't see how we can do async fetches if we want to use http_redirect_fetch as well, because internally, it uses a main fetch with the recursive flag set, which means main fetch will return the response early, before the FetchTaskTarget functions are called.

@jdm
Copy link
Member

jdm commented Feb 24, 2017

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.

@jdm
Copy link
Member

jdm commented Feb 24, 2017

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.

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch from cc2b6be to ea59b0b May 31, 2017
@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented May 31, 2017

@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

Trying commit ea59b0b with merge bf3335b...

bors-servo added a commit that referenced this pull request May 31, 2017
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

💔 Test failed - linux-rel-wpt

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch from ea59b0b to bb8db03 May 31, 2017
@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented May 31, 2017

@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

Trying commit bb8db03 with merge 1085653...

bors-servo added a commit that referenced this pull request May 31, 2017
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented May 31, 2017

💔 Test failed - linux-dev

@cynicaldevil cynicaldevil force-pushed the cynicaldevil:manual-redirect branch from bb8db03 to 541baaf May 31, 2017
@cynicaldevil
Copy link
Contributor Author

cynicaldevil commented May 31, 2017

@jdm Ready for merge now.

@jdm
Copy link
Member

jdm commented Jun 2, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jun 2, 2017

📌 Commit 541baaf has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jun 2, 2017

Testing commit 541baaf with merge eac4f40...

bors-servo added a commit that referenced this pull request Jun 2, 2017
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 2, 2017

@bors-servo bors-servo merged commit 541baaf into servo:master Jun 2, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Jun 2, 2017
4 of 5 tasks complete
@cynicaldevil cynicaldevil deleted the cynicaldevil:manual-redirect branch Jun 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.