servo: Merge #20181 - Fire the pageshow event at the end of the page load (from fabricedesre:end-load-pageshow); r=jdm
authorFabrice Desré <fabrice@desre.org>
Tue, 06 Mar 2018 10:49:51 -0500
changeset 461773 9ea189de40f3e1d0a026da68915166c17ab91044
parent 461772 d493cadf47666a6e092e2599a7d164b7f8656380
child 461774 3c3ae4a1a7ede1ed97de25bd6206fcd0fb38a3b6
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #20181 - Fire the pageshow event at the end of the page load (from fabricedesre:end-load-pageshow); r=jdm <!-- Please describe your changes on the following line: --> This implements step 8 of https://html.spec.whatwg.org/multipage/parsing.html#the-end --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because I could not find a wpt test for that, which is strange. I likely missed it :( <!-- 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94a6c2c429eb0415a277ff49fa19ae0eaefb0be9
servo/components/atoms/static_atoms.txt
servo/components/script/dom/document.rs
--- a/servo/components/atoms/static_atoms.txt
+++ b/servo/components/atoms/static_atoms.txt
@@ -42,16 +42,17 @@ message
 message
 monospace
 month
 mouseover
 none
 number
 onchange
 open
+pageshow
 password
 pause
 play
 playing
 print
 progress
 radio
 range
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -359,16 +359,18 @@ pub struct Document {
     /// See https://html.spec.whatwg.org/multipage/#form-owner
     form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
     interactive_time: DomRefCell<InteractiveMetrics>,
     tti_window: DomRefCell<InteractiveWindow>,
     /// RAII canceller for Fetch
     canceller: FetchCanceller,
     /// https://html.spec.whatwg.org/multipage/#throw-on-dynamic-markup-insertion-counter
     throw_on_dynamic_markup_insertion_counter: Cell<u64>,
+    /// https://html.spec.whatwg.org/multipage/#page-showing
+    page_showing: Cell<bool>,
 }
 
 #[derive(JSTraceable, MallocSizeOf)]
 struct ImagesFilter;
 impl CollectionFilter for ImagesFilter {
     fn filter(&self, elem: &Element, _root: &Node) -> bool {
         elem.is::<HTMLImageElement>()
     }
@@ -1629,17 +1631,47 @@ impl Document {
                 if let Some(fragment) = document.url().fragment() {
                     document.check_and_scroll_fragment(fragment);
                 }
             }),
             self.window.upcast(),
         ).unwrap();
 
         // Step 8.
-        // TODO: pageshow event.
+        let document = Trusted::new(self);
+        if document.root().browsing_context().is_some() {
+            self.window.dom_manipulation_task_source().queue(
+                task!(fire_pageshow_event: move || {
+                    let document = document.root();
+                    let window = document.window();
+                    if document.page_showing.get() || !window.is_alive() {
+                        return;
+                    }
+
+                    document.page_showing.set(true);
+
+                    let event = PageTransitionEvent::new(
+                        window,
+                        atom!("pageshow"),
+                        false, // bubbles
+                        false, // cancelable
+                        false, // persisted
+                    );
+                    let event = event.upcast::<Event>();
+                    event.set_trusted(true);
+
+                    // FIXME(nox): Why are errors silenced here?
+                    let _ = window.upcast::<EventTarget>().dispatch_event_with_target(
+                        document.upcast(),
+                        &event,
+                    );
+                }),
+                self.window.upcast(),
+            ).unwrap();
+        }
 
         // Step 9.
         // TODO: pending application cache download process tasks.
 
         // Step 10.
         // TODO: printing steps.
 
         // Step 11.
@@ -2220,16 +2252,17 @@ impl Document {
             spurious_animation_frames: Cell::new(0),
             dom_count: Cell::new(1),
             fullscreen_element: MutNullableDom::new(None),
             form_id_listener_map: Default::default(),
             interactive_time: DomRefCell::new(interactive_time),
             tti_window: DomRefCell::new(InteractiveWindow::new()),
             canceller: canceller,
             throw_on_dynamic_markup_insertion_counter: Cell::new(0),
+            page_showing: Cell::new(false),
         }
     }
 
     // https://dom.spec.whatwg.org/#dom-document-document
     pub fn Constructor(window: &Window) -> Fallible<DomRoot<Document>> {
         let doc = window.Document();
         let docloader = DocumentLoader::new(&*doc.loader());
         Ok(Document::new(window,