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

Implement browsing context discarding #14559

Merged

Conversation

asajeffrey
Copy link
Member

@asajeffrey asajeffrey commented Dec 12, 2016

Implement browsing context discarding (https://html.spec.whatwg.org/multipage/browsers.html#discard-a-document).

  • When a pipeline is closed, inform the script thread whether the browsing context is to be discarded.
  • In script threads, synchronously discard any similar-origin documents and browsing contexts.
  • When a browsing context is discarded, it loses the reference to the active document, but the window keeps it, so we need to move the Document pointer from BrowsingContext to Window.
  • Fix the webIDL for Window to make parent and top optional (the spec says they can return null when the browsing context is discarded).


This change is Reviewable

@asajeffrey asajeffrey added the A-content/script Related to the script thread label Dec 12, 2016
@highfive
Copy link

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmliframeelement.rs, components/script/dom/document.rs, components/script/dom/browsingcontext.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script/script_thread.rs, components/script/dom/window.rs, components/script/dom/webidls/Window.webidl, components/script_traits/lib.rs, components/script_traits/lib.rs
  • @KiChjang: components/script/dom/htmliframeelement.rs, components/script/dom/document.rs, components/script/dom/browsingcontext.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script/script_thread.rs, components/script/dom/window.rs, components/script/dom/webidls/Window.webidl, components/script_traits/lib.rs, components/script_traits/lib.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 12, 2016
@asajeffrey
Copy link
Member Author

This should help with the crash we were seeing in #13996 (comment) (though that crash has mysteriously disappeared). cc @Ms2ger @jdm

@asajeffrey
Copy link
Member Author

Also see #14434

@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 13, 2016
@asajeffrey asajeffrey force-pushed the script-track-document-and-bc-discarding branch from 9d314d3 to 7f5f9d6 Compare December 13, 2016 15:10
@asajeffrey asajeffrey removed the S-needs-rebase There are merge conflict errors. label Dec 13, 2016
@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 15, 2016
@asajeffrey asajeffrey force-pushed the script-track-document-and-bc-discarding branch from 7f5f9d6 to 8be8c54 Compare December 15, 2016 04:27
@asajeffrey asajeffrey removed the S-needs-rebase There are merge conflict errors. label Dec 15, 2016
@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 15, 2016
@asajeffrey asajeffrey force-pushed the script-track-document-and-bc-discarding branch from 8be8c54 to c4d1813 Compare December 23, 2016 15:09
@asajeffrey
Copy link
Member Author

Rebased. r? @ConnorGBrewster

@highfive highfive assigned cbrewster and unassigned wafflespeanut Dec 23, 2016
Copy link
Contributor

@cbrewster cbrewster left a comment

Choose a reason for hiding this comment

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

Looks good! Although it looks like removing the reference to the active document in the browsing context caused a couple of regressions. I think we should find a way to fix those before merging.

Also since the BS doesn't store the active document, we will need to find a way to determine if the document is active vs fully_active.

@@ -3190,8 +3187,8 @@ impl DocumentMethods for Document {

// Step 2.
// TODO: handle throw-on-dynamic-markup-insertion counter.

if !self.is_active() {
// FIXME: this should check for being active rather than fully active
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we implement is_active again before merging this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that we're currently not sending enough information from the constellation to the script thread to determine if a document is active. We're sending freeze/thaw messages to determine if a document is fully active, but not any messages about being active. I think this is a spec issue, the spec should really say "fully active" here.

@@ -2304,7 +2295,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
for entry in evicted_pipelines {
self.close_pipeline(entry.pipeline_id, ExitPipelineMode::Normal);
self.close_pipeline(entry.pipeline_id, DiscardBrowsingContext::No, ExitPipelineMode::Normal);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we not discard the Browsing Context here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This code is used when a browsing context navigates, we don't want to close the BC in this case. Nested BCs will get closed, when the recursive call is made it's with DiscardBrowsingContext::Yes.

}

pub fn active_document(&self) -> Root<Document> {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the reasons behind not storing a reference to the Document in the BC?

Copy link
Member Author

Choose a reason for hiding this comment

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

We never needed it, so I removed it! SpiderMonkey does the dance to resolve WindowProxy to Window, which tracks the current document.

}
// TODO Step 3.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should find a way to do this, and other cases that may have regressed with this PR before merging.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's broken in the same way as it was before. Did this cause a regression?

@@ -1345,6 +1357,13 @@ impl Window {
unsafe { SetWindowProxy(cx, window, browsing_context.reflector().get_jsobject()); }
}

#[allow(unsafe_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

@@ -183,6 +183,15 @@ pub struct NewLayoutInfo {
pub layout_threads: usize,
}

/// When a pipeline is closed, should its browsing context be discarded too?
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a spec link here that discussing when to discard browsing contexts?

@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 24, 2016
@asajeffrey asajeffrey force-pushed the script-track-document-and-bc-discarding branch from e3788d8 to 7c2de62 Compare January 5, 2017 21:13
@asajeffrey
Copy link
Member Author

Rebased.

@asajeffrey
Copy link
Member Author

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit 7c2de62 with merge c0706a2...

bors-servo pushed a commit that referenced this pull request Jan 5, 2017
…ding, r=<try>

Implement browsing context discarding

<!-- Please describe your changes on the following line: -->

Implement browsing context discarding (https://html.spec.whatwg.org/multipage/browsers.html#discard-a-document).

* When a pipeline is closed, inform the script thread whether the browsing context is to be discarded.
* In script threads, synchronously discard any similar-origin documents and browsing contexts.
* When a browsing context is discarded, it loses the reference to the active document, but the window keeps it, so we need to move the `Document` pointer from `BrowsingContext` to `Window`.
* Fix the webIDL for Window to make parent and top optional (the spec says they can return null when the browsing context is discarded).

---
<!-- 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 #14411
- [X] There are tests for these changes

<!-- 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/14559)
<!-- Reviewable:end -->
@asajeffrey asajeffrey removed the S-needs-rebase There are merge conflict errors. label Jan 5, 2017
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jan 5, 2017
@bors-servo
Copy link
Contributor

⌛ Trying commit 7c2de62 with merge 1d5503b...

bors-servo pushed a commit that referenced this pull request Jan 6, 2017
…ding, r=<try>

Implement browsing context discarding

<!-- Please describe your changes on the following line: -->

Implement browsing context discarding (https://html.spec.whatwg.org/multipage/browsers.html#discard-a-document).

* When a pipeline is closed, inform the script thread whether the browsing context is to be discarded.
* In script threads, synchronously discard any similar-origin documents and browsing contexts.
* When a browsing context is discarded, it loses the reference to the active document, but the window keeps it, so we need to move the `Document` pointer from `BrowsingContext` to `Window`.
* Fix the webIDL for Window to make parent and top optional (the spec says they can return null when the browsing context is discarded).

---
<!-- 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 #14411
- [X] There are tests for these changes

<!-- 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/14559)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

@cbrewster
Copy link
Contributor

@bors-servo r+ retry

@bors-servo
Copy link
Contributor

📌 Commit 7c2de62 has been approved by cbrewster

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-tests-failed The changes caused existing tests to fail. labels Jan 6, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 7c2de62 with merge 8b274f2...

bors-servo pushed a commit that referenced this pull request Jan 6, 2017
…ding, r=cbrewster

Implement browsing context discarding

<!-- Please describe your changes on the following line: -->

Implement browsing context discarding (https://html.spec.whatwg.org/multipage/browsers.html#discard-a-document).

* When a pipeline is closed, inform the script thread whether the browsing context is to be discarded.
* In script threads, synchronously discard any similar-origin documents and browsing contexts.
* When a browsing context is discarded, it loses the reference to the active document, but the window keeps it, so we need to move the `Document` pointer from `BrowsingContext` to `Window`.
* Fix the webIDL for Window to make parent and top optional (the spec says they can return null when the browsing context is discarded).

---
<!-- 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 #14411
- [X] There are tests for these changes

<!-- 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/14559)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-gnu-dev, windows-msvc-dev

@bors-servo bors-servo merged commit 7c2de62 into servo:master Jan 6, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/script Related to the script thread
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discard documents and browsing contexts synchronously
6 participants