Skip to content

Commit

Permalink
Auto merge of #12416 - canaltinova:referrer, r=jdm
Browse files Browse the repository at this point in the history
Implement Document.referrer

<!-- 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 #12389 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/12416)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jul 14, 2016
2 parents 48a912f + d6c1f7b commit 4b78b9a
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions components/net/about_loader.rs
Expand Up @@ -36,6 +36,7 @@ pub fn factory(mut load_data: LoadData,
headers: None,
status: Some(RawStatus(200, "OK".into())),
https_state: HttpsState::None,
referrer: None,
};
if let Ok(chan) = start_sending_sniffed_opt(start_chan,
metadata,
Expand Down
1 change: 1 addition & 0 deletions components/net/blob_loader.rs
Expand Up @@ -46,6 +46,7 @@ pub fn load_blob(load_data: LoadData, start_chan: LoadConsumer,
// https://w3c.github.io/FileAPI/#TwoHundredOK
status: Some(RawStatus(200, "OK".into())),
https_state: HttpsState::None,
referrer: None
};

if let Ok(chan) =
Expand Down
1 change: 1 addition & 0 deletions components/net/http_loader.rs
Expand Up @@ -1071,6 +1071,7 @@ pub fn load<A, B>(load_data: &LoadData,
} else {
HttpsState::None
};
metadata.referrer = referrer_url;

// Only notify the devtools about the final request that received a response.
if let Some(msg) = msg {
Expand Down
4 changes: 4 additions & 0 deletions components/net_traits/lib.rs
Expand Up @@ -565,6 +565,9 @@ pub struct Metadata {

/// Is successful HTTPS connection
pub https_state: HttpsState,

/// Referrer Url
pub referrer: Option<Url>,
}

impl Metadata {
Expand All @@ -578,6 +581,7 @@ impl Metadata {
// https://fetch.spec.whatwg.org/#concept-response-status-message
status: Some(RawStatus(200, "OK".into())),
https_state: HttpsState::None,
referrer: None,
}
}

Expand Down
26 changes: 21 additions & 5 deletions components/script/dom/document.rs
Expand Up @@ -239,6 +239,8 @@ pub struct Document {
origin: Origin,
/// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states
referrer_policy: Cell<Option<ReferrerPolicy>>,
/// https://html.spec.whatwg.org/multipage/#dom-document-referrer
referrer: Option<String>,
}

#[derive(JSTraceable, HeapSizeOf)]
Expand Down Expand Up @@ -1630,7 +1632,8 @@ impl Document {
content_type: Option<DOMString>,
last_modified: Option<String>,
source: DocumentSource,
doc_loader: DocumentLoader)
doc_loader: DocumentLoader,
referrer: Option<String>)
-> Document {
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());

Expand Down Expand Up @@ -1717,6 +1720,7 @@ impl Document {
origin: origin,
//TODO - setting this for now so no Referer header set
referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)),
referrer: referrer,
}
}

Expand All @@ -1733,7 +1737,8 @@ impl Document {
None,
None,
DocumentSource::NotFromParser,
docloader))
docloader,
None))
}

pub fn new(window: &Window,
Expand All @@ -1743,7 +1748,8 @@ impl Document {
content_type: Option<DOMString>,
last_modified: Option<String>,
source: DocumentSource,
doc_loader: DocumentLoader)
doc_loader: DocumentLoader,
referrer: Option<String>)
-> Root<Document> {
let document = reflect_dom_object(box Document::new_inherited(window,
browsing_context,
Expand All @@ -1752,7 +1758,8 @@ impl Document {
content_type,
last_modified,
source,
doc_loader),
doc_loader,
referrer),
GlobalRef::Window(window),
DocumentBinding::Wrap);
{
Expand Down Expand Up @@ -1816,7 +1823,8 @@ impl Document {
None,
None,
DocumentSource::NotFromParser,
DocumentLoader::new(&self.loader()));
DocumentLoader::new(&self.loader()),
None);
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
new_doc
})
Expand Down Expand Up @@ -1935,6 +1943,14 @@ impl DocumentMethods for Document {
}
}

// https://html.spec.whatwg.org/multipage/#dom-document-referrer
fn Referrer(&self) -> DOMString {
match self.referrer {
Some(ref referrer) => DOMString::from(referrer.to_string()),
None => DOMString::new()
}
}

// https://dom.spec.whatwg.org/#dom-document-documenturi
fn DocumentURI(&self) -> USVString {
self.URL()
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/domimplementation.rs
Expand Up @@ -129,7 +129,8 @@ impl DOMImplementationMethods for DOMImplementation {
None,
None,
DocumentSource::NotFromParser,
loader);
loader,
None);

{
// Step 3.
Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/domparser.rs
Expand Up @@ -68,7 +68,8 @@ impl DOMParserMethods for DOMParser {
Some(content_type),
None,
DocumentSource::FromParser,
loader);
loader,
None);
parse_html(document.r(), s, url, ParseContext::Owner(None));
document.set_ready_state(DocumentReadyState::Complete);
Ok(document)
Expand All @@ -82,7 +83,8 @@ impl DOMParserMethods for DOMParser {
Some(content_type),
None,
DocumentSource::NotFromParser,
loader);
loader,
None);
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
Ok(document)
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/node.rs
Expand Up @@ -1721,7 +1721,7 @@ impl Node {
let document = Document::new(window, None,
Some((*document.url()).clone()),
is_html_doc, None,
None, DocumentSource::NotFromParser, loader);
None, DocumentSource::NotFromParser, loader, None);
Root::upcast::<Node>(document)
},
NodeTypeId::Element(..) => {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Document.webidl
Expand Up @@ -82,7 +82,7 @@ partial /*sealed*/ interface Document {
[/*PutForwards=href, */Unforgeable]
readonly attribute Location? location;
readonly attribute DOMString domain;
// readonly attribute DOMString referrer;
readonly attribute DOMString referrer;
[Throws]
attribute DOMString cookie;
readonly attribute DOMString lastModified;
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/xmldocument.rs
Expand Up @@ -41,7 +41,8 @@ impl XMLDocument {
content_type,
last_modified,
source,
doc_loader),
doc_loader,
None),
}
}

Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/xmlhttprequest.rs
Expand Up @@ -1234,7 +1234,9 @@ impl XMLHttpRequest {
is_html_document,
content_type,
None,
DocumentSource::FromParser, docloader)
DocumentSource::FromParser,
docloader,
None)
}

fn filter_response_headers(&self) -> Headers {
Expand Down
3 changes: 2 additions & 1 deletion components/script/parse/html.rs
Expand Up @@ -279,7 +279,8 @@ pub fn parse_html_fragment(context_node: &Node,
IsHTMLDocument::HTMLDocument,
None, None,
DocumentSource::FromParser,
loader);
loader,
None);

// Step 2.
document.set_quirks_mode(context_document.quirks_mode());
Expand Down
8 changes: 7 additions & 1 deletion components/script/script_thread.rs
Expand Up @@ -1711,14 +1711,20 @@ impl ScriptThread {
_ => IsHTMLDocument::HTMLDocument,
};

let referrer = match metadata.referrer {
Some(ref referrer) => Some(referrer.clone().into_string()),
None => None,
};

let document = Document::new(window.r(),
Some(&browsing_context),
Some(final_url.clone()),
is_html_document,
content_type,
last_modified,
DocumentSource::FromParser,
loader);
loader,
referrer);
if using_new_context {
browsing_context.init(&document);
} else {
Expand Down
Expand Up @@ -3,9 +3,6 @@
[domain]
expected: FAIL

[referrer]
expected: FAIL

[readyState]
expected: FAIL

Expand Down
9 changes: 0 additions & 9 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -3,9 +3,6 @@
[Document interface: attribute domain]
expected: FAIL

[Document interface: attribute referrer]
expected: FAIL

[Document interface: attribute dir]
expected: FAIL

Expand Down Expand Up @@ -6987,9 +6984,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "enableStyleSheetsForSet" with the proper type (33)]
expected: FAIL

[Document interface: document.implementation.createDocument(null, "", null) must inherit property "referrer" with the proper type (36)]
expected: FAIL

[Document interface: document.implementation.createDocument(null, "", null) must inherit property "dir" with the proper type (42)]
expected: FAIL

Expand Down Expand Up @@ -7347,9 +7341,6 @@
[Document interface: new Document() must have own property "location"]
expected: FAIL

[Document interface: new Document() must inherit property "referrer" with the proper type (36)]
expected: FAIL

[Document interface: new Document() must inherit property "dir" with the proper type (42)]
expected: FAIL

Expand Down
Expand Up @@ -105,11 +105,10 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {

// Check the reported URL.
test.step(function() {
// TODO - can uncomment when Document::Referrer is implemented
// assert_equals(result.referrer,
// t._expectedReferrerUrl,
// "Reported Referrer URL is '" +
// t._scenario.referrer_url + "'.");
assert_equals(result.referrer,
t._expectedReferrerUrl,
"Reported Referrer URL is '" +
t._scenario.referrer_url + "'.");
assert_equals(result.headers.referer,
t._expectedReferrerUrl,
"Reported Referrer URL from HTTP header is '" +
Expand Down
Expand Up @@ -16,7 +16,7 @@
return(false);
}

var referrer = 'referrer' in document ? document.referrer : undefined;
var referrer = document.referrer.length > 0 ? document.referrer : undefined;

var result = {
location: document.location.toString(),
Expand Down

0 comments on commit 4b78b9a

Please sign in to comment.