Created
January 14, 2025 06:21
-
-
Save jdm/1f08c1b8b3c33d3f5c44882a1b5eb822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs | |
index 11602547b7..6ce7f1072a 100644 | |
--- a/components/script/dom/document.rs | |
+++ b/components/script/dom/document.rs | |
@@ -3211,6 +3211,7 @@ impl Document { | |
status_code: Option<u16>, | |
canceller: FetchCanceller, | |
is_initial_about_blank: bool, | |
+ encoding: Option<String>, | |
) -> Document { | |
let url = url.unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap()); | |
@@ -3232,11 +3233,18 @@ impl Document { | |
} | |
}); | |
+ println!("got {:?}", encoding); | |
+ | |
let encoding = content_type | |
.get_param(mime::CHARSET) | |
- .and_then(|charset| Encoding::for_label(charset.as_str().as_bytes())) | |
+ .as_ref() | |
+ .map(mime::Name::as_str) | |
+ .or(encoding.as_deref()) | |
+ .and_then(|charset| Encoding::for_label(charset.as_bytes())) | |
.unwrap_or(UTF_8); | |
+ println!("creating doc with {}", encoding.name()); | |
+ | |
let has_browsing_context = has_browsing_context == HasBrowsingContext::Yes; | |
Document { | |
@@ -3475,6 +3483,7 @@ impl Document { | |
status_code: Option<u16>, | |
canceller: FetchCanceller, | |
is_initial_about_blank: bool, | |
+ encoding: Option<String>, | |
can_gc: CanGc, | |
) -> DomRoot<Document> { | |
Self::new_with_proto( | |
@@ -3493,6 +3502,7 @@ impl Document { | |
status_code, | |
canceller, | |
is_initial_about_blank, | |
+ encoding, | |
can_gc, | |
) | |
} | |
@@ -3514,6 +3524,7 @@ impl Document { | |
status_code: Option<u16>, | |
canceller: FetchCanceller, | |
is_initial_about_blank: bool, | |
+ encoding: Option<String>, | |
can_gc: CanGc, | |
) -> DomRoot<Document> { | |
let document = reflect_dom_object_with_proto( | |
@@ -3532,6 +3543,7 @@ impl Document { | |
status_code, | |
canceller, | |
is_initial_about_blank, | |
+ encoding, | |
)), | |
window, | |
proto, | |
@@ -3663,6 +3675,7 @@ impl Document { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
new_doc | |
@@ -4227,6 +4240,7 @@ impl DocumentMethods<crate::DomTypeHolder> for Document { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
)) | |
} | |
diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs | |
index b9f0a2c29a..d023d54fdb 100644 | |
--- a/components/script/dom/domimplementation.rs | |
+++ b/components/script/dom/domimplementation.rs | |
@@ -165,6 +165,7 @@ impl DOMImplementationMethods<crate::DomTypeHolder> for DOMImplementation { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs | |
index ece1360d46..16a7760fb0 100644 | |
--- a/components/script/dom/domparser.rs | |
+++ b/components/script/dom/domparser.rs | |
@@ -88,6 +88,7 @@ impl DOMParserMethods<crate::DomTypeHolder> for DOMParser { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
ServoParser::parse_html_document(&document, Some(s), url, can_gc); | |
@@ -110,6 +111,7 @@ impl DOMParserMethods<crate::DomTypeHolder> for DOMParser { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
ServoParser::parse_xml_document(&document, Some(s), url, can_gc); | |
diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs | |
index bff3b9757a..e260d50931 100644 | |
--- a/components/script/dom/htmlmetaelement.rs | |
+++ b/components/script/dom/htmlmetaelement.rs | |
@@ -10,11 +10,12 @@ use dom_struct::dom_struct; | |
use html5ever::{LocalName, Prefix}; | |
use js::rust::HandleObject; | |
use regex::bytes::Regex; | |
-use script_traits::NavigationHistoryBehavior; | |
+use script_traits::{NavigationHistoryBehavior}; | |
use servo_url::ServoUrl; | |
use style::str::HTML_SPACE_CHARACTERS; | |
use crate::dom::attr::Attr; | |
+use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; | |
use crate::dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods; | |
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; | |
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; | |
@@ -50,6 +51,7 @@ impl RefreshRedirectDue { | |
self.url.clone(), | |
NavigationHistoryBehavior::Replace, | |
NavigationType::DeclarativeRefresh, | |
+ None, | |
can_gc, | |
); | |
} | |
@@ -98,6 +100,24 @@ impl HTMLMetaElement { | |
"content-security-policy" => self.apply_csp_list(), | |
_ => {}, | |
} | |
+ } else if !element.get_string_attribute(&html5ever::local_name!("charset")).is_empty() { | |
+ let charset = element.get_string_attribute(&html5ever::local_name!("charset")); | |
+ let charset_ref = encoding_rs::Encoding::for_label(charset.to_string().as_bytes()); | |
+ let current_charset = encoding_rs::Encoding::for_label(self.owner_document().CharacterSet().to_string().as_bytes()); | |
+ if charset_ref != current_charset { | |
+ println!("reloading with {} (currently {})", charset, self.owner_document().CharacterSet()); | |
+ let global = self.owner_global(); | |
+ let window = global.as_window(); | |
+ window.Location().navigate( | |
+ window.get_url(), | |
+ NavigationHistoryBehavior::Replace, | |
+ NavigationType::ReloadByConstellation, | |
+ Some(charset.to_string()), | |
+ CanGc::note(), | |
+ ); | |
+ } else { | |
+ println!("charset already matches {}", charset); | |
+ } | |
} | |
} | |
diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs | |
index e3e310c8f8..8d7788ae7e 100644 | |
--- a/components/script/dom/location.rs | |
+++ b/components/script/dom/location.rs | |
@@ -71,6 +71,7 @@ impl Location { | |
url: ServoUrl, | |
history_handling: NavigationHistoryBehavior, | |
navigation_type: NavigationType, | |
+ charset_override: Option<String>, | |
can_gc: CanGc, | |
) { | |
fn incumbent_window() -> DomRoot<Window> { | |
@@ -122,7 +123,7 @@ impl Location { | |
// Initiate navigation | |
// TODO: rethrow exceptions, set exceptions enabled flag. | |
- let load_data = LoadData::new( | |
+ let mut load_data = LoadData::new( | |
LoadOrigin::Script(load_origin), | |
url, | |
creator_pipeline_id, | |
@@ -130,6 +131,7 @@ impl Location { | |
referrer_policy, | |
None, // Top navigation doesn't inherit secure context | |
); | |
+ load_data.charset_override = charset_override; | |
self.window | |
.load_url(history_handling, reload_triggered, load_data, can_gc); | |
} | |
@@ -235,6 +237,7 @@ impl Location { | |
copy_url, | |
NavigationHistoryBehavior::Push, | |
NavigationType::Normal, | |
+ None, | |
can_gc, | |
); | |
} | |
@@ -256,6 +259,7 @@ impl Location { | |
url, | |
NavigationHistoryBehavior::Replace, | |
NavigationType::ReloadByConstellation, | |
+ None, | |
can_gc, | |
); | |
} | |
@@ -292,6 +296,7 @@ impl LocationMethods<crate::DomTypeHolder> for Location { | |
url, | |
NavigationHistoryBehavior::Replace, | |
NavigationType::ReloadByScript, | |
+ None, | |
can_gc, | |
); | |
Ok(()) | |
@@ -314,6 +319,7 @@ impl LocationMethods<crate::DomTypeHolder> for Location { | |
url, | |
NavigationHistoryBehavior::Replace, | |
NavigationType::Normal, | |
+ None, | |
can_gc, | |
); | |
} | |
@@ -426,6 +432,7 @@ impl LocationMethods<crate::DomTypeHolder> for Location { | |
url, | |
NavigationHistoryBehavior::Push, | |
NavigationType::Normal, | |
+ None, | |
can_gc, | |
); | |
} | |
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs | |
index 3925c532a5..776308528c 100644 | |
--- a/components/script/dom/node.rs | |
+++ b/components/script/dom/node.rs | |
@@ -2379,6 +2379,7 @@ impl Node { | |
document.status_code(), | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
DomRoot::upcast::<Node>(document) | |
diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs | |
index 18a7aed45f..6276ecc23b 100644 | |
--- a/components/script/dom/servoparser/mod.rs | |
+++ b/components/script/dom/servoparser/mod.rs | |
@@ -216,6 +216,7 @@ impl ServoParser { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
); | |
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs | |
index 2b79e92359..5ee4c4f591 100644 | |
--- a/components/script/dom/window.rs | |
+++ b/components/script/dom/window.rs | |
@@ -2405,7 +2405,7 @@ impl Window { | |
} else if load_data.url.scheme() == "javascript" || doc.is_initial_about_blank() { | |
NavigationHistoryBehavior::Replace | |
} else { | |
- NavigationHistoryBehavior::Push | |
+ history_handling | |
}; | |
// Step 13 | |
diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs | |
index 278ca24630..ec07f701b8 100644 | |
--- a/components/script/dom/xmldocument.rs | |
+++ b/components/script/dom/xmldocument.rs | |
@@ -58,6 +58,7 @@ impl XMLDocument { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
), | |
} | |
} | |
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs | |
index ff24965369..8a13b1f5c3 100644 | |
--- a/components/script/dom/xmlhttprequest.rs | |
+++ b/components/script/dom/xmlhttprequest.rs | |
@@ -1520,6 +1520,7 @@ impl XMLHttpRequest { | |
None, | |
Default::default(), | |
false, | |
+ None, | |
can_gc, | |
) | |
} | |
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs | |
index a4704cb2b4..a9fc193fab 100644 | |
--- a/components/script/script_thread.rs | |
+++ b/components/script/script_thread.rs | |
@@ -3189,6 +3189,7 @@ impl ScriptThread { | |
Some(metadata.status.raw_code()), | |
incomplete.canceller, | |
is_initial_about_blank, | |
+ incomplete.load_data.charset_override, | |
can_gc, | |
); | |
diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs | |
index e6901be54b..6f42147d16 100644 | |
--- a/components/shared/script/lib.rs | |
+++ b/components/shared/script/lib.rs | |
@@ -164,6 +164,9 @@ pub struct LoadData { | |
/// Servo internal: if crash details are present, trigger a crash error page with these details. | |
pub crash: Option<String>, | |
+ | |
+ /// | |
+ pub charset_override: Option<String>, | |
} | |
/// The result of evaluating a javascript scheme url. | |
@@ -199,6 +202,7 @@ impl LoadData { | |
srcdoc: "".to_string(), | |
inherited_secure_context, | |
crash: None, | |
+ charset_override: None, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment