Skip to content

Commit d6c1f7b

Browse files
committed
Implement Document.referrer
1 parent 9e010a8 commit d6c1f7b

17 files changed

Lines changed: 55 additions & 32 deletions

File tree

components/net/about_loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn factory(mut load_data: LoadData,
3636
headers: None,
3737
status: Some(RawStatus(200, "OK".into())),
3838
https_state: HttpsState::None,
39+
referrer: None,
3940
};
4041
if let Ok(chan) = start_sending_sniffed_opt(start_chan,
4142
metadata,

components/net/blob_loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn load_blob(load_data: LoadData, start_chan: LoadConsumer,
5151
// https://w3c.github.io/FileAPI/#TwoHundredOK
5252
status: Some(RawStatus(200, "OK".into())),
5353
https_state: HttpsState::None,
54+
referrer: None
5455
};
5556

5657
if let Ok(chan) =

components/net/http_loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ pub fn load<A, B>(load_data: &LoadData,
10701070
} else {
10711071
HttpsState::None
10721072
};
1073+
metadata.referrer = referrer_url;
10731074

10741075
// Only notify the devtools about the final request that received a response.
10751076
if let Some(msg) = msg {

components/net_traits/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ pub struct Metadata {
565565

566566
/// Is successful HTTPS connection
567567
pub https_state: HttpsState,
568+
569+
/// Referrer Url
570+
pub referrer: Option<Url>,
568571
}
569572

570573
impl Metadata {
@@ -578,6 +581,7 @@ impl Metadata {
578581
// https://fetch.spec.whatwg.org/#concept-response-status-message
579582
status: Some(RawStatus(200, "OK".into())),
580583
https_state: HttpsState::None,
584+
referrer: None,
581585
}
582586
}
583587

components/script/dom/document.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ pub struct Document {
239239
origin: Origin,
240240
/// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states
241241
referrer_policy: Cell<Option<ReferrerPolicy>>,
242+
/// https://html.spec.whatwg.org/multipage/#dom-document-referrer
243+
referrer: Option<String>,
242244
}
243245

244246
#[derive(JSTraceable, HeapSizeOf)]
@@ -1629,7 +1631,8 @@ impl Document {
16291631
content_type: Option<DOMString>,
16301632
last_modified: Option<String>,
16311633
source: DocumentSource,
1632-
doc_loader: DocumentLoader)
1634+
doc_loader: DocumentLoader,
1635+
referrer: Option<String>)
16331636
-> Document {
16341637
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
16351638

@@ -1716,6 +1719,7 @@ impl Document {
17161719
origin: origin,
17171720
//TODO - setting this for now so no Referer header set
17181721
referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)),
1722+
referrer: referrer,
17191723
}
17201724
}
17211725

@@ -1732,7 +1736,8 @@ impl Document {
17321736
None,
17331737
None,
17341738
DocumentSource::NotFromParser,
1735-
docloader))
1739+
docloader,
1740+
None))
17361741
}
17371742

17381743
pub fn new(window: &Window,
@@ -1742,7 +1747,8 @@ impl Document {
17421747
content_type: Option<DOMString>,
17431748
last_modified: Option<String>,
17441749
source: DocumentSource,
1745-
doc_loader: DocumentLoader)
1750+
doc_loader: DocumentLoader,
1751+
referrer: Option<String>)
17461752
-> Root<Document> {
17471753
let document = reflect_dom_object(box Document::new_inherited(window,
17481754
browsing_context,
@@ -1751,7 +1757,8 @@ impl Document {
17511757
content_type,
17521758
last_modified,
17531759
source,
1754-
doc_loader),
1760+
doc_loader,
1761+
referrer),
17551762
GlobalRef::Window(window),
17561763
DocumentBinding::Wrap);
17571764
{
@@ -1815,7 +1822,8 @@ impl Document {
18151822
None,
18161823
None,
18171824
DocumentSource::NotFromParser,
1818-
DocumentLoader::new(&self.loader()));
1825+
DocumentLoader::new(&self.loader()),
1826+
None);
18191827
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
18201828
new_doc
18211829
})
@@ -1934,6 +1942,14 @@ impl DocumentMethods for Document {
19341942
}
19351943
}
19361944

1945+
// https://html.spec.whatwg.org/multipage/#dom-document-referrer
1946+
fn Referrer(&self) -> DOMString {
1947+
match self.referrer {
1948+
Some(ref referrer) => DOMString::from(referrer.to_string()),
1949+
None => DOMString::new()
1950+
}
1951+
}
1952+
19371953
// https://dom.spec.whatwg.org/#dom-document-documenturi
19381954
fn DocumentURI(&self) -> USVString {
19391955
self.URL()

components/script/dom/domimplementation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ impl DOMImplementationMethods for DOMImplementation {
129129
None,
130130
None,
131131
DocumentSource::NotFromParser,
132-
loader);
132+
loader,
133+
None);
133134

134135
{
135136
// Step 3.

components/script/dom/domparser.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl DOMParserMethods for DOMParser {
6868
Some(content_type),
6969
None,
7070
DocumentSource::FromParser,
71-
loader);
71+
loader,
72+
None);
7273
parse_html(document.r(), s, url, ParseContext::Owner(None));
7374
document.set_ready_state(DocumentReadyState::Complete);
7475
Ok(document)
@@ -82,7 +83,8 @@ impl DOMParserMethods for DOMParser {
8283
Some(content_type),
8384
None,
8485
DocumentSource::NotFromParser,
85-
loader);
86+
loader,
87+
None);
8688
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
8789
Ok(document)
8890
}

components/script/dom/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ impl Node {
17211721
let document = Document::new(window, None,
17221722
Some((*document.url()).clone()),
17231723
is_html_doc, None,
1724-
None, DocumentSource::NotFromParser, loader);
1724+
None, DocumentSource::NotFromParser, loader, None);
17251725
Root::upcast::<Node>(document)
17261726
},
17271727
NodeTypeId::Element(..) => {

components/script/dom/webidls/Document.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ partial /*sealed*/ interface Document {
8282
[/*PutForwards=href, */Unforgeable]
8383
readonly attribute Location? location;
8484
readonly attribute DOMString domain;
85-
// readonly attribute DOMString referrer;
85+
readonly attribute DOMString referrer;
8686
[Throws]
8787
attribute DOMString cookie;
8888
readonly attribute DOMString lastModified;

components/script/dom/xmldocument.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl XMLDocument {
4141
content_type,
4242
last_modified,
4343
source,
44-
doc_loader),
44+
doc_loader,
45+
None),
4546
}
4647
}
4748

0 commit comments

Comments
 (0)