mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Implement Document.referrer
This commit is contained in:
parent
9e010a8aec
commit
d6c1f7b5e3
17 changed files with 55 additions and 32 deletions
|
@ -36,6 +36,7 @@ pub fn factory(mut load_data: LoadData,
|
||||||
headers: None,
|
headers: None,
|
||||||
status: Some(RawStatus(200, "OK".into())),
|
status: Some(RawStatus(200, "OK".into())),
|
||||||
https_state: HttpsState::None,
|
https_state: HttpsState::None,
|
||||||
|
referrer: None,
|
||||||
};
|
};
|
||||||
if let Ok(chan) = start_sending_sniffed_opt(start_chan,
|
if let Ok(chan) = start_sending_sniffed_opt(start_chan,
|
||||||
metadata,
|
metadata,
|
||||||
|
|
|
@ -51,6 +51,7 @@ pub fn load_blob(load_data: LoadData, start_chan: LoadConsumer,
|
||||||
// https://w3c.github.io/FileAPI/#TwoHundredOK
|
// https://w3c.github.io/FileAPI/#TwoHundredOK
|
||||||
status: Some(RawStatus(200, "OK".into())),
|
status: Some(RawStatus(200, "OK".into())),
|
||||||
https_state: HttpsState::None,
|
https_state: HttpsState::None,
|
||||||
|
referrer: None
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(chan) =
|
if let Ok(chan) =
|
||||||
|
|
|
@ -1070,6 +1070,7 @@ pub fn load<A, B>(load_data: &LoadData,
|
||||||
} else {
|
} else {
|
||||||
HttpsState::None
|
HttpsState::None
|
||||||
};
|
};
|
||||||
|
metadata.referrer = referrer_url;
|
||||||
|
|
||||||
// Only notify the devtools about the final request that received a response.
|
// Only notify the devtools about the final request that received a response.
|
||||||
if let Some(msg) = msg {
|
if let Some(msg) = msg {
|
||||||
|
|
|
@ -565,6 +565,9 @@ pub struct Metadata {
|
||||||
|
|
||||||
/// Is successful HTTPS connection
|
/// Is successful HTTPS connection
|
||||||
pub https_state: HttpsState,
|
pub https_state: HttpsState,
|
||||||
|
|
||||||
|
/// Referrer Url
|
||||||
|
pub referrer: Option<Url>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
|
@ -578,6 +581,7 @@ impl Metadata {
|
||||||
// https://fetch.spec.whatwg.org/#concept-response-status-message
|
// https://fetch.spec.whatwg.org/#concept-response-status-message
|
||||||
status: Some(RawStatus(200, "OK".into())),
|
status: Some(RawStatus(200, "OK".into())),
|
||||||
https_state: HttpsState::None,
|
https_state: HttpsState::None,
|
||||||
|
referrer: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,8 @@ pub struct Document {
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
/// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states
|
/// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states
|
||||||
referrer_policy: Cell<Option<ReferrerPolicy>>,
|
referrer_policy: Cell<Option<ReferrerPolicy>>,
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#dom-document-referrer
|
||||||
|
referrer: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
|
@ -1629,7 +1631,8 @@ impl Document {
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader)
|
doc_loader: DocumentLoader,
|
||||||
|
referrer: Option<String>)
|
||||||
-> Document {
|
-> Document {
|
||||||
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
||||||
|
|
||||||
|
@ -1716,6 +1719,7 @@ impl Document {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
//TODO - setting this for now so no Referer header set
|
//TODO - setting this for now so no Referer header set
|
||||||
referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)),
|
referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)),
|
||||||
|
referrer: referrer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1732,7 +1736,8 @@ impl Document {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
docloader))
|
docloader,
|
||||||
|
None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window,
|
pub fn new(window: &Window,
|
||||||
|
@ -1742,7 +1747,8 @@ impl Document {
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader)
|
doc_loader: DocumentLoader,
|
||||||
|
referrer: Option<String>)
|
||||||
-> Root<Document> {
|
-> Root<Document> {
|
||||||
let document = reflect_dom_object(box Document::new_inherited(window,
|
let document = reflect_dom_object(box Document::new_inherited(window,
|
||||||
browsing_context,
|
browsing_context,
|
||||||
|
@ -1751,7 +1757,8 @@ impl Document {
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
source,
|
source,
|
||||||
doc_loader),
|
doc_loader,
|
||||||
|
referrer),
|
||||||
GlobalRef::Window(window),
|
GlobalRef::Window(window),
|
||||||
DocumentBinding::Wrap);
|
DocumentBinding::Wrap);
|
||||||
{
|
{
|
||||||
|
@ -1815,7 +1822,8 @@ impl Document {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
DocumentLoader::new(&self.loader()));
|
DocumentLoader::new(&self.loader()),
|
||||||
|
None);
|
||||||
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
||||||
new_doc
|
new_doc
|
||||||
})
|
})
|
||||||
|
@ -1934,6 +1942,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
|
// https://dom.spec.whatwg.org/#dom-document-documenturi
|
||||||
fn DocumentURI(&self) -> USVString {
|
fn DocumentURI(&self) -> USVString {
|
||||||
self.URL()
|
self.URL()
|
||||||
|
|
|
@ -129,7 +129,8 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
loader);
|
loader,
|
||||||
|
None);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Step 3.
|
// Step 3.
|
||||||
|
|
|
@ -68,7 +68,8 @@ impl DOMParserMethods for DOMParser {
|
||||||
Some(content_type),
|
Some(content_type),
|
||||||
None,
|
None,
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader);
|
loader,
|
||||||
|
None);
|
||||||
parse_html(document.r(), s, url, ParseContext::Owner(None));
|
parse_html(document.r(), s, url, ParseContext::Owner(None));
|
||||||
document.set_ready_state(DocumentReadyState::Complete);
|
document.set_ready_state(DocumentReadyState::Complete);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
|
@ -82,7 +83,8 @@ impl DOMParserMethods for DOMParser {
|
||||||
Some(content_type),
|
Some(content_type),
|
||||||
None,
|
None,
|
||||||
DocumentSource::NotFromParser,
|
DocumentSource::NotFromParser,
|
||||||
loader);
|
loader,
|
||||||
|
None);
|
||||||
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
|
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1721,7 +1721,7 @@ impl Node {
|
||||||
let document = Document::new(window, None,
|
let document = Document::new(window, None,
|
||||||
Some((*document.url()).clone()),
|
Some((*document.url()).clone()),
|
||||||
is_html_doc, None,
|
is_html_doc, None,
|
||||||
None, DocumentSource::NotFromParser, loader);
|
None, DocumentSource::NotFromParser, loader, None);
|
||||||
Root::upcast::<Node>(document)
|
Root::upcast::<Node>(document)
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
|
|
|
@ -82,7 +82,7 @@ partial /*sealed*/ interface Document {
|
||||||
[/*PutForwards=href, */Unforgeable]
|
[/*PutForwards=href, */Unforgeable]
|
||||||
readonly attribute Location? location;
|
readonly attribute Location? location;
|
||||||
readonly attribute DOMString domain;
|
readonly attribute DOMString domain;
|
||||||
// readonly attribute DOMString referrer;
|
readonly attribute DOMString referrer;
|
||||||
[Throws]
|
[Throws]
|
||||||
attribute DOMString cookie;
|
attribute DOMString cookie;
|
||||||
readonly attribute DOMString lastModified;
|
readonly attribute DOMString lastModified;
|
||||||
|
|
|
@ -41,7 +41,8 @@ impl XMLDocument {
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
source,
|
source,
|
||||||
doc_loader),
|
doc_loader,
|
||||||
|
None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1234,7 +1234,9 @@ impl XMLHttpRequest {
|
||||||
is_html_document,
|
is_html_document,
|
||||||
content_type,
|
content_type,
|
||||||
None,
|
None,
|
||||||
DocumentSource::FromParser, docloader)
|
DocumentSource::FromParser,
|
||||||
|
docloader,
|
||||||
|
None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_response_headers(&self) -> Headers {
|
fn filter_response_headers(&self) -> Headers {
|
||||||
|
|
|
@ -279,7 +279,8 @@ pub fn parse_html_fragment(context_node: &Node,
|
||||||
IsHTMLDocument::HTMLDocument,
|
IsHTMLDocument::HTMLDocument,
|
||||||
None, None,
|
None, None,
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader);
|
loader,
|
||||||
|
None);
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
document.set_quirks_mode(context_document.quirks_mode());
|
document.set_quirks_mode(context_document.quirks_mode());
|
||||||
|
|
|
@ -1704,6 +1704,11 @@ impl ScriptThread {
|
||||||
_ => IsHTMLDocument::HTMLDocument,
|
_ => IsHTMLDocument::HTMLDocument,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let referrer = match metadata.referrer {
|
||||||
|
Some(ref referrer) => Some(referrer.clone().into_string()),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let document = Document::new(window.r(),
|
let document = Document::new(window.r(),
|
||||||
Some(&browsing_context),
|
Some(&browsing_context),
|
||||||
Some(final_url.clone()),
|
Some(final_url.clone()),
|
||||||
|
@ -1711,7 +1716,8 @@ impl ScriptThread {
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader);
|
loader,
|
||||||
|
referrer);
|
||||||
if using_new_context {
|
if using_new_context {
|
||||||
browsing_context.init(&document);
|
browsing_context.init(&document);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
[domain]
|
[domain]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[referrer]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[readyState]
|
[readyState]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
[Document interface: attribute domain]
|
[Document interface: attribute domain]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Document interface: attribute referrer]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Document interface: attribute dir]
|
[Document interface: attribute dir]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -6990,9 +6987,6 @@
|
||||||
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "enableStyleSheetsForSet" with the proper type (33)]
|
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "enableStyleSheetsForSet" with the proper type (33)]
|
||||||
expected: FAIL
|
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)]
|
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "dir" with the proper type (42)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7350,9 +7344,6 @@
|
||||||
[Document interface: new Document() must have own property "location"]
|
[Document interface: new Document() must have own property "location"]
|
||||||
expected: FAIL
|
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)]
|
[Document interface: new Document() must inherit property "dir" with the proper type (42)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -105,11 +105,10 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
|
||||||
|
|
||||||
// Check the reported URL.
|
// Check the reported URL.
|
||||||
test.step(function() {
|
test.step(function() {
|
||||||
// TODO - can uncomment when Document::Referrer is implemented
|
assert_equals(result.referrer,
|
||||||
// assert_equals(result.referrer,
|
t._expectedReferrerUrl,
|
||||||
// t._expectedReferrerUrl,
|
"Reported Referrer URL is '" +
|
||||||
// "Reported Referrer URL is '" +
|
t._scenario.referrer_url + "'.");
|
||||||
// t._scenario.referrer_url + "'.");
|
|
||||||
assert_equals(result.headers.referer,
|
assert_equals(result.headers.referer,
|
||||||
t._expectedReferrerUrl,
|
t._expectedReferrerUrl,
|
||||||
"Reported Referrer URL from HTTP header is '" +
|
"Reported Referrer URL from HTTP header is '" +
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var referrer = 'referrer' in document ? document.referrer : undefined;
|
var referrer = document.referrer.length > 0 ? document.referrer : undefined;
|
||||||
|
|
||||||
var result = {
|
var result = {
|
||||||
location: document.location.toString(),
|
location: document.location.toString(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue