Auto merge of #15536 - asajeffrey:script-document-domain-setter, r=nox

Implement setter for document.domain

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

This PR implements the setter for `document.domain`.

It builds on #15438 and #15478, only the last commit is part of this PR.

It includes tests for similar-origin security checks.

---
<!-- 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 #934.
- [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/15536)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-15 08:35:41 -07:00 committed by GitHub
commit e600e0495c
104 changed files with 413 additions and 1057 deletions

View file

@ -108,7 +108,7 @@ use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_rand::{Rng, SeedableRng, ServoRng, random};
use servo_remutex::ReentrantMutex;
use servo_url::ServoUrl;
use servo_url::{Host, ServoUrl};
use std::borrow::ToOwned;
use std::collections::{HashMap, VecDeque};
use std::iter::once;
@ -229,13 +229,13 @@ pub struct Constellation<Message, LTF, STF> {
/// event loop for each registered domain name (aka eTLD+1) in
/// each top-level frame. We store the event loops in a map
/// indexed by top-level frame id (as a `FrameId`) and registered
/// domain name (as a `String`) to event loops. This double
/// domain name (as a `Host`) to event loops. This double
/// indirection ensures that separate tabs do not share event
/// loops, even if the same domain is loaded in each.
/// It is important that scripts with the same eTLD+1
/// share an event loop, since they can use `document.domain`
/// to become same-origin, at which point they can share DOM objects.
event_loops: HashMap<FrameId, HashMap<String, Weak<EventLoop>>>,
event_loops: HashMap<FrameId, HashMap<Host, Weak<EventLoop>>>,
/// The set of all the pipelines in the browser.
/// (See the `pipeline` module for more details.)
@ -604,16 +604,18 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
None => self.root_frame_id,
};
debug!("Creating new pipeline {} in top-level frame {}.", pipeline_id, top_level_frame_id);
let (event_loop, host) = match sandbox {
IFrameSandboxState::IFrameSandboxed => (None, None),
IFrameSandboxState::IFrameUnsandboxed => match reg_host(&load_data.url) {
None => (None, None),
Some(host) => {
let event_loop = self.event_loops.get(&top_level_frame_id)
.and_then(|map| map.get(host))
.and_then(|map| map.get(&host))
.and_then(|weak| weak.upgrade());
match event_loop {
None => (None, Some(String::from(host))),
None => (None, Some(host)),
Some(event_loop) => (Some(event_loop.clone()), None),
}
},
@ -677,6 +679,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
};
if let Some(host) = host {
debug!("Adding new host entry {} for top-level frame {}.", host, top_level_frame_id);
self.event_loops.entry(top_level_frame_id)
.or_insert_with(HashMap::new)
.insert(host, Rc::downgrade(&pipeline.event_loop));