servo: Merge #5006 - Cleanup ScriptTask::load (from Ms2ger:script_task); r=saneyuki
authorMs2ger <ms2ger@gmail.com>
Sat, 21 Feb 2015 10:48:46 -0700
changeset 335864 a4f3fc30045ec59201a8cfd0ec18250c6772a614
parent 335863 471d46d34745e30d6a87f8cb6f861a6e84aad74d
child 335865 fcd82528c22e7a7bc0a99f6372eac6a2bfc21e9b
push id86548
push userkwierso@gmail.com
push dateSat, 04 Feb 2017 01:35:21 +0000
treeherdermozilla-inbound@e7b96d015d03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssaneyuki
servo: Merge #5006 - Cleanup ScriptTask::load (from Ms2ger:script_task); r=saneyuki Source-Repo: https://github.com/servo/servo Source-Revision: 31c8f97b4b493d828f1b96144772f3df1aff145b
servo/components/script/script_task.rs
--- a/servo/components/script/script_task.rs
+++ b/servo/components/script/script_task.rs
@@ -22,17 +22,16 @@ use dom::bindings::refcounted::{LiveDOMR
 use dom::bindings::structuredclone::StructuredCloneData;
 use dom::bindings::trace::JSTraceable;
 use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
 use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressHandler, DocumentProgressTask, DocumentSource};
 use dom::element::{Element, ActivationElementHelpers};
 use dom::event::{Event, EventHelpers, EventBubbles, EventCancelable};
 use dom::uievent::UIEvent;
 use dom::eventtarget::EventTarget;
-use dom::htmliframeelement::HTMLIFrameElement;
 use dom::keyboardevent::KeyboardEvent;
 use dom::mouseevent::MouseEvent;
 use dom::node::{self, Node, NodeHelpers, NodeDamage};
 use dom::window::{Window, WindowHelpers, ScriptHelpers};
 use dom::worker::{Worker, TrustedWorkerAddress};
 use parse::html::{HTMLInput, parse_html};
 use layout_interface::{ScriptLayoutChan, LayoutChan, ReflowGoal, ReflowQueryType};
 use layout_interface;
@@ -747,41 +746,38 @@ impl ScriptTask {
 
     }
 
     /// The entry point to document loading. Defines bindings, sets up the window and document
     /// objects, parses HTML and CSS, and kicks off initial layout.
     fn load(&self, pipeline_id: PipelineId,
             parent: Option<(PipelineId, SubpageId)>, load_data: LoadData) {
         let url = load_data.url.clone();
-        debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id);
+        debug!("ScriptTask: loading {} on page {:?}", url.serialize(), pipeline_id);
 
         let borrowed_page = self.page.borrow_mut();
 
         let frame_element = parent.and_then(|(parent_id, subpage_id)| {
-          // In the case a parent id exists but the matching page
-          // cannot be found, this means the page exists in a different
-          // script task (due to origin) so it shouldn't be returned.
-          // TODO: window.parent will continue to return self in that
-          // case, which is wrong. We should be returning an object that
-          // denies access to most properties (per
-          // https://github.com/servo/servo/issues/3939#issuecomment-62287025).
-          borrowed_page.find(parent_id).and_then(|page| {
-            let match_iframe = |&:&node: &JSRef<HTMLIFrameElement>| {
-              node.subpage_id().map_or(false, |id| id == subpage_id)
-            };
+            // In the case a parent id exists but the matching page
+            // cannot be found, this means the page exists in a different
+            // script task (due to origin) so it shouldn't be returned.
+            // TODO: window.parent will continue to return self in that
+            // case, which is wrong. We should be returning an object that
+            // denies access to most properties (per
+            // https://github.com/servo/servo/issues/3939#issuecomment-62287025).
+            borrowed_page.find(parent_id).and_then(|page| {
+                let doc = page.frame().as_ref().unwrap().document.root();
+                let doc: JSRef<Node> = NodeCast::from_ref(doc.r());
 
-            let doc = page.frame().as_ref().unwrap().document.root();
-            let doc: JSRef<Node> = NodeCast::from_ref(doc.r());
-
-            doc.traverse_preorder()
-               .filter_map(|node| HTMLIFrameElementCast::to_ref(node))
-               .find(match_iframe)
-               .map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
-          })
+                doc.traverse_preorder()
+                   .filter_map(HTMLIFrameElementCast::to_ref)
+                   .find(|node| node.subpage_id() == Some(subpage_id))
+                   .map(ElementCast::from_ref)
+                   .map(Temporary::from_rooted)
+            })
         }).root();
 
         let page = borrowed_page.find(pipeline_id).expect("ScriptTask: received a load
             message for a layout channel that is not associated with this script task. This
             is a bug.");
 
         // Are we reloading?
         let reloading = match *page.url() {