aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/window.rs25
-rw-r--r--components/script/script_thread.rs21
2 files changed, 22 insertions, 24 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 3a24a1ac95d..756bfb5a555 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -11,6 +11,7 @@ use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarker
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
+use dom::bindings::codegen::Bindings::HistoryBinding::HistoryBinding::HistoryMethods;
use dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionState;
use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
@@ -543,9 +544,27 @@ impl WindowMethods for Window {
// https://html.spec.whatwg.org/multipage/#dom-window-close
fn Close(&self) {
- self.main_thread_script_chan()
- .send(MainThreadScriptMsg::ExitWindow(self.upcast::<GlobalScope>().pipeline_id()))
- .unwrap();
+ // Note: check the length of the "session history", as opposed to the joint session history?
+ // see https://github.com/whatwg/html/issues/3734
+ if let Ok(history_length) = self.History().GetLength() {
+ // TODO: allow auxilliary browsing contexts created by script to be script-closeable,
+ // regardless of history length.
+ // https://html.spec.whatwg.org/multipage/#script-closable
+ let is_script_closable = self.is_top_level() && history_length == 1;
+ if is_script_closable {
+ let doc = self.Document();
+ // https://html.spec.whatwg.org/multipage/#closing-browsing-contexts
+ // Step 1, prompt to unload.
+ if doc.prompt_to_unload(false) {
+ // Step 2, unload.
+ doc.unload(false, false);
+ // Step 3, remove from the user interface
+ let _ = self.send_to_embedder(EmbedderMsg::CloseBrowser);
+ // Step 4, discard browsing context.
+ let _ = self.send_to_constellation(ScriptMsg::DiscardTopLevelBrowsingContext);
+ }
+ }
+ }
}
// https://html.spec.whatwg.org/multipage/#dom-document-2
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index a28bdfbb5bf..1852e467189 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -220,9 +220,6 @@ enum MixedMessage {
pub enum MainThreadScriptMsg {
/// Common variants associated with the script messages
Common(CommonScriptMsg),
- /// Notifies the script that a window associated with a particular pipeline
- /// should be closed (only dispatched to ScriptThread).
- ExitWindow(PipelineId),
/// Begins a content-initiated load on the specified pipeline (only
/// dispatched to ScriptThread). Allows for a replace bool to be passed. If true,
/// the current entry will be replaced instead of a new entry being added.
@@ -1193,7 +1190,6 @@ impl ScriptThread {
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id)) =>
pipeline_id,
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(_)) => None,
- MainThreadScriptMsg::ExitWindow(pipeline_id) => Some(pipeline_id),
MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id),
MainThreadScriptMsg::WorkletLoaded(pipeline_id) => Some(pipeline_id),
MainThreadScriptMsg::RegisterPaintWorklet { pipeline_id, .. } => Some(pipeline_id),
@@ -1344,9 +1340,6 @@ impl ScriptThread {
MainThreadScriptMsg::Navigate(parent_pipeline_id, load_data, replace) => {
self.handle_navigate(parent_pipeline_id, None, load_data, replace)
},
- MainThreadScriptMsg::ExitWindow(id) => {
- self.handle_exit_window_msg(id)
- },
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task, _)) => {
task.run_box()
}
@@ -1715,20 +1708,6 @@ impl ScriptThread {
window.set_window_size(new_size);
}
- /// We have gotten a window.close from script, which we pass on to the compositor.
- /// We do not shut down the script thread now, because the compositor will ask the
- /// constellation to shut down the pipeline, which will clean everything up
- /// normally. If we do exit, we will tear down the DOM nodes, possibly at a point
- /// where layout is still accessing them.
- fn handle_exit_window_msg(&self, id: PipelineId) {
- debug!("script thread handling exit window msg");
-
- // TODO(tkuehn): currently there is only one window,
- // so this can afford to be naive and just shut down the
- // constellation. In the future it'll need to be smarter.
- self.script_sender.send((id, ScriptMsg::Exit)).unwrap();
- }
-
/// We have received notification that the response associated with a load has completed.
/// Kick off the document and frame tree creation process using the result.
fn handle_page_headers_available(&self, id: &PipelineId,