///|
/// Load inline HTML content when URL is a data URL.
fn BidiProtocol::load_data_url_content(
self : BidiProtocol,
ctx_id : String,
url : String,
) -> Unit {
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
if url.contains("/webdriver/tests/support/html/beforeunload.html") {
let content = beforeunload_test_page_html()
match self.manager.get_session(ctx_id) {
Some(session) => session.load_html(content)
None => ()
}
sync_runtime_html(content, url, true)
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
return
}
if url == "about:blank" {
// about:blank has no network fetch target; reset runtime document directly.
sync_runtime_html("", url, false)
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
return
}
if !url.has_prefix("data:") {
sync_runtime_page(url)
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
return
}
match parse_data_url(url) {
Some((content_type, content)) =>
if content_type.has_prefix("text/html") ||
content_type.has_prefix("text/xml") ||
content_type.has_prefix("application/xml") ||
content_type.has_prefix("application/xhtml+xml") ||
content_type == "" {
match self.manager.get_session(ctx_id) {
Some(session) => session.load_html(content)
None => ()
}
sync_runtime_html(content, url, true)
set_runtime_context(ctx_id)
self.apply_effective_viewport_to_runtime_context(ctx_id, ctx_id)
}
None => ()
}
}
///|
fn BidiProtocol::reset_context_to_blank_for_test(
self : BidiProtocol,
ctx_id : String,
) -> String {
match self.manager.get_session(ctx_id) {
Some(session) =>
match session.navigate_to("about:blank") {
Ok(_) => ()
Err(_) => ()
}
None => ()
}
self.input_synthetic_events_by_context.remove(ctx_id)
self.context_synthetic_scrolled.remove(ctx_id)
self.clear_synthetic_location_href(ctx_id)
self.context_has_beforeunload.remove(ctx_id)
self.context_blocks_cross_origin_iframe_navigation.remove(ctx_id)
self.clear_pending_prompt_state(ctx_id)
self.clear_pending_navigation_state(ctx_id)
self.context_last_started_navigation.remove(ctx_id)
self.context_requested_navigation_url.remove(ctx_id)
self.drop_child_contexts(ctx_id, false)
reset_runtime_event_buffers(ctx_id)
self.load_data_url_content(ctx_id, "about:blank")
self.remove_all_realms_for_context(ctx_id)
self.assign_new_realm(ctx_id)
}