mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #20865 - gterzian:improve_spec_compliance_window_close, r=cbrewster
improve spec compliance of window.close <!-- Please describe your changes on the following line: --> Improve the spec compliance of https://html.spec.whatwg.org/multipage/window-object.html#dom-window-close, mainly by implementing the steps related to [closing a browsing context](https://html.spec.whatwg.org/multipage/window-object.html#close-a-browsing-context) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20865) <!-- Reviewable:end -->
This commit is contained in:
commit
65eff4fb8a
12 changed files with 123 additions and 39 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue