aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2018-05-26 23:41:34 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2018-06-04 15:02:23 +0800
commit2753e5efabd77b83dd94bf59fe3f01535e8ac10a (patch)
treedc6b3463570cd1aaba4d71401837d56c6f28c60f /components/script/dom
parentf63284efc04b298b010f34f5225a3fa9014bf763 (diff)
downloadservo-2753e5efabd77b83dd94bf59fe3f01535e8ac10a.tar.gz
servo-2753e5efabd77b83dd94bf59fe3f01535e8ac10a.zip
improve spec compliance of window.close
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/window.rs25
1 files changed, 22 insertions, 3 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