Skip to content

Share script threads by tab and by eTLD+1#14211

Merged
bors-servo merged 1 commit intoservo:masterfrom
asajeffrey:constellation-share-more-script-threads
Nov 22, 2016
Merged

Share script threads by tab and by eTLD+1#14211
bors-servo merged 1 commit intoservo:masterfrom
asajeffrey:constellation-share-more-script-threads

Conversation

@asajeffrey
Copy link
Copy Markdown
Contributor

@asajeffrey asajeffrey commented Nov 14, 2016

This PR shares script threads among all similar-origin documents in the same tab. This allows DOM object to be shared among same-origin same-tab documents.



This change is Reviewable

@asajeffrey asajeffrey added the A-constellation Involves the constellation label Nov 14, 2016
@highfive
Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/dedicatedworkerglobalscope.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script/script_thread.rs, components/script_traits/lib.rs, components/script_traits/lib.rs
  • @KiChjang: components/script/dom/dedicatedworkerglobalscope.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script/script_thread.rs, 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 Nov 14, 2016
@asajeffrey asajeffrey changed the title S Share script threads by tab and by eTLD+1 Nov 14, 2016
@asajeffrey
Copy link
Copy Markdown
Contributor Author

There's two commits in this PR. The first one is #14173, the second one is the subject of this PR.

@asajeffrey asajeffrey added the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label Nov 14, 2016
@bors-servo
Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Nov 15, 2016
@asajeffrey asajeffrey force-pushed the constellation-share-more-script-threads branch 2 times, most recently from 8db72d1 to 0f92143 Compare November 15, 2016 19:58
@bors-servo
Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Nov 17, 2016
@asajeffrey asajeffrey force-pushed the constellation-share-more-script-threads branch from 0f92143 to daaf77a Compare November 18, 2016 00:09
@KiChjang KiChjang removed the S-needs-rebase There are merge conflict errors. label Nov 18, 2016
@asajeffrey asajeffrey force-pushed the constellation-share-more-script-threads branch from daaf77a to 4ef42c1 Compare November 21, 2016 23:22
@asajeffrey
Copy link
Copy Markdown
Contributor Author

This is now ready for review, since #14173 landed. @bors-servo r? @jdm

@highfive highfive assigned jdm and unassigned emilio Nov 21, 2016
@asajeffrey asajeffrey force-pushed the constellation-share-more-script-threads branch from 4ef42c1 to 5c472e9 Compare November 21, 2016 23:29
@jdm jdm removed the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label Nov 22, 2016
Copy link
Copy Markdown
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

Excellent work! This feels like a sensible design, and it's nice that new_pipeline is completely in control of selecting a script thread now.

}

/// The initial data associated with a newly-created framed pipeline.
/// The initial data associated to create a new layout attached to an existing script thread.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/associated/required/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

match self.documents.borrow().iter().next() {
None => panic!("Layout attached to empty script thread."),
// Tell the layout thread factory to actually spawn the thread.
Some((_, document)) => document.window().layout_chan().send(msg).unwrap(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could keep trying other threads if sending to the first one fails. Maybe file as a followup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Really we should provide the script thread with a factory method for building layout threads, this would also deal with the corner case where a pipeline is asked to create a layout thread despite not having any current layout threads.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That does sound better. A followup would be good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Filed #14328

if self.shutting_down { return; }

// TODO: think about the case where the child pipeline is created
// before the parent is part of the frame tree.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand what this means. It doesn't sound possible as written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made this comment into a question. You're right, I don't think this can happen, but I'm not sure we should be relying on that.

let window_size = pipeline_id.and_then(|id| self.pipelines.get(&id).and_then(|pipeline| pipeline.size));

self.close_frame_children(frame_id, ExitPipelineMode::Force);
self.close_frame_children(top_level_frame_id, ExitPipelineMode::Force);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we remove any entries from the script channels map?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Once we've got document discarding, that should all happen automatically, because the old page will be discarded, which will remove the script channel map entry.

/// Returns None if the URL has no host name.
/// Returns the registered suffix for the host name if it is a domain.
/// Leaves the host name alone if it is an IP address.
fn reg_host<'a>(&self, url: &'a ServoUrl) -> Option<&'a str> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be a free function instead, since it never uses self.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

/// to receive sw manager message
swmanager_receiver: Receiver<SWManagerMsg>,

/// A map from top-level frame id and registered domain name to script channels.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add a comment to the effect of "This double indirection ensures that separate tabs do not share script threads, even if the same domain is loaded in each."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 22, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 22, 2016
@asajeffrey asajeffrey added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 22, 2016
@asajeffrey asajeffrey added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 22, 2016
@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 22, 2016
@asajeffrey asajeffrey force-pushed the constellation-share-more-script-threads branch from 5ab118f to 7ae19c0 Compare November 22, 2016 21:02
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 22, 2016
@asajeffrey asajeffrey removed the S-needs-squash Some (or all) of the commits in the PR should be combined. label Nov 22, 2016
@asajeffrey
Copy link
Copy Markdown
Contributor Author

@bors-servo r=jdm

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit 7ae19c0 has been approved by jdm

@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. labels Nov 22, 2016
@jdm jdm closed this Nov 22, 2016
@jdm jdm reopened this Nov 22, 2016
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 7ae19c0 with merge 1535f84...

bors-servo pushed a commit that referenced this pull request Nov 22, 2016
…eads, r=jdm

Share script threads by tab and by eTLD+1

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

This PR shares script threads among all similar-origin documents in the same tab. This allows DOM object to be shared among same-origin same-tab documents.

---
<!-- 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 #633.
- [X] These changes do not require tests because refactoring.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-constellation Involves the constellation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share Script Threads by eTLD+1, not by parent origin

6 participants