aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmliframeelement.rs
blob: 8cec0aa66599a834a75730aa87693e6e76fed5ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use document_loader::{LoadType, LoadBlocker};
use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementErrorEventDetail;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementIconChangeEventDetail;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementLocationChangeEventDetail;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementSecurityChangeDetail;
use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserShowModalPromptEventDetail;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::conversions::{ToJSValConvertible};
use dom::bindings::error::{Error, ErrorResult};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{Root, LayoutJS};
use dom::bindings::reflector::Reflectable;
use dom::bindings::str::DOMString;
use dom::customevent::CustomEvent;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
use dom::event::Event;
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeDamage, UnbindContext, window_from_node, document_from_node};
use dom::urlhelper::UrlHelper;
use dom::virtualmethods::VirtualMethods;
use dom::window::{ReflowReason, Window};
use ipc_channel::ipc;
use js::jsapi::{JSAutoCompartment, RootedValue, JSContext, MutableHandleValue};
use js::jsval::{UndefinedValue, NullValue};
use layout_interface::ReflowQueryType;
use msg::constellation_msg::{LoadData, NavigationDirection, PipelineId, SubpageId};
use net_traits::response::HttpsState;
use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed};
use script_traits::{IFrameLoadInfo, MozBrowserEvent, ScriptMsg as ConstellationMsg};
use std::cell::Cell;
use string_cache::Atom;
use style::context::ReflowGoal;
use url::Url;
use util::prefs;
use util::str::LengthOrPercentageOrAuto;

pub fn mozbrowser_enabled() -> bool {
    prefs::get_pref("dom.mozbrowser.enabled").as_boolean().unwrap_or(false)
}

#[derive(HeapSizeOf)]
enum SandboxAllowance {
    AllowNothing = 0x00,
    AllowSameOrigin = 0x01,
    AllowTopNavigation = 0x02,
    AllowForms = 0x04,
    AllowScripts = 0x08,
    AllowPointerLock = 0x10,
    AllowPopups = 0x20
}

#[dom_struct]
pub struct HTMLIFrameElement {
    htmlelement: HTMLElement,
    pipeline_id: Cell<Option<PipelineId>>,
    subpage_id: Cell<Option<SubpageId>>,
    sandbox: Cell<Option<u8>>,
    load_blocker: DOMRefCell<Option<LoadBlocker>>,
}

impl HTMLIFrameElement {
    pub fn is_sandboxed(&self) -> bool {
        self.sandbox.get().is_some()
    }

    /// <https://html.spec.whatwg.org/multipage/#otherwise-steps-for-iframe-or-frame-elements>,
    /// step 1.
    fn get_url(&self) -> Url {
        let element = self.upcast::<Element>();
        element.get_attribute(&ns!(), &atom!("src")).and_then(|src| {
            let url = src.value();
            if url.is_empty() {
                None
            } else {
                document_from_node(self).base_url().join(&url).ok()
            }
        }).unwrap_or_else(|| Url::parse("about:blank").unwrap())
    }

    pub fn generate_new_subpage_id(&self) -> (SubpageId, Option<SubpageId>) {
        self.pipeline_id.set(Some(PipelineId::new()));

        let old_subpage_id = self.subpage_id.get();
        let win = window_from_node(self);
        let subpage_id = win.get_next_subpage_id();
        self.subpage_id.set(Some(subpage_id));
        (subpage_id, old_subpage_id)
    }

    pub fn navigate_or_reload_child_browsing_context(&self, load_data: Option<LoadData>) {
        let sandboxed = if self.is_sandboxed() {
            IFrameSandboxed
        } else {
            IFrameUnsandboxed
        };

        let document = document_from_node(self);

        let mut load_blocker = self.load_blocker.borrow_mut();
        // Any oustanding load is finished from the point of view of the blocked
        // document; the new navigation will continue blocking it.
        LoadBlocker::terminate(&mut load_blocker);

        //TODO(#9592): Deal with the case where an iframe is being reloaded so url is None.
        //      The iframe should always have access to the nested context's active
        //      document URL through the browsing context.
        if let Some(ref load_data) = load_data {
            *load_blocker = Some(LoadBlocker::new(&*document, LoadType::Subframe(load_data.url.clone())));
        }

        let window = window_from_node(self);
        let (new_subpage_id, old_subpage_id) = self.generate_new_subpage_id();
        let new_pipeline_id = self.pipeline_id.get().unwrap();
        let private_iframe = self.privatebrowsing();

        let load_info = IFrameLoadInfo {
            load_data: load_data,
            containing_pipeline_id: window.pipeline(),
            new_subpage_id: new_subpage_id,
            old_subpage_id: old_subpage_id,
            new_pipeline_id: new_pipeline_id,
            sandbox: sandboxed,
            is_private: private_iframe,
        };
        window.constellation_chan()
              .send(ConstellationMsg::ScriptLoadedURLInIFrame(load_info))
              .unwrap();

        if mozbrowser_enabled() {
            // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadstart
            self.dispatch_mozbrowser_event(MozBrowserEvent::LoadStart);
        }
    }

    pub fn process_the_iframe_attributes(&self) {
        let url = self.get_url();

        // TODO - loaddata here should have referrer info (not None, None)
        self.navigate_or_reload_child_browsing_context(Some(LoadData::new(url, None, None)));
    }

    #[allow(unsafe_code)]
    pub fn dispatch_mozbrowser_event(&self, event: MozBrowserEvent) {
        // TODO(gw): Support mozbrowser event types that have detail which is not a string.
        // See https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API
        // for a list of mozbrowser events.
        assert!(mozbrowser_enabled());

        if self.Mozbrowser() {
            let window = window_from_node(self);
            let custom_event = unsafe {
                let cx = window.get_cx();
                let _ac = JSAutoCompartment::new(cx, window.reflector().get_jsobject().get());
                let mut detail = RootedValue::new(cx, UndefinedValue());
                let event_name = Atom::from(event.name());
                self.build_mozbrowser_event_detail(event, cx, detail.handle_mut());
                CustomEvent::new(GlobalRef::Window(window.r()),
                                 event_name,
                                 true,
                                 true,
                                 detail.handle())
            };
            custom_event.upcast::<Event>().fire(self.upcast());
        }
    }

    pub fn update_subpage_id(&self, new_subpage_id: SubpageId, new_pipeline_id: PipelineId) {
        self.subpage_id.set(Some(new_subpage_id));
        self.pipeline_id.set(Some(new_pipeline_id));

        let mut blocker = self.load_blocker.borrow_mut();
        LoadBlocker::terminate(&mut blocker);

        self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
    }

    fn new_inherited(localName: Atom,
                     prefix: Option<DOMString>,
                     document: &Document) -> HTMLIFrameElement {
        HTMLIFrameElement {
            htmlelement: HTMLElement::new_inherited(localName, prefix, document),
            pipeline_id: Cell::new(None),
            subpage_id: Cell::new(None),
            sandbox: Cell::new(None),
            load_blocker: DOMRefCell::new(None),
        }
    }

    #[allow(unrooted_must_root)]
    pub fn new(localName: Atom,
               prefix: Option<DOMString>,
               document: &Document) -> Root<HTMLIFrameElement> {
        let element = HTMLIFrameElement::new_inherited(localName, prefix, document);
        Node::reflect_node(box element, document, HTMLIFrameElementBinding::Wrap)
    }

    #[inline]
    pub fn pipeline_id(&self) -> Option<PipelineId> {
        self.pipeline_id.get()
    }

    #[inline]
    pub fn subpage_id(&self) -> Option<SubpageId> {
        self.subpage_id.get()
    }

    pub fn pipeline(&self) -> Option<PipelineId> {
        self.pipeline_id.get()
    }

    /// https://html.spec.whatwg.org/multipage/#iframe-load-event-steps steps 1-4
    pub fn iframe_load_event_steps(&self, loaded_pipeline: PipelineId) {
        // TODO(#9592): assert that the load blocker is present at all times when we
        //              can guarantee that it's created for the case of iframe.reload().
        assert_eq!(loaded_pipeline, self.pipeline().unwrap());

        // TODO A cross-origin child document would not be easily accessible
        //      from this script thread. It's unclear how to implement
        //      steps 2, 3, and 5 efficiently in this case.
        // TODO Step 2 - check child document `mute iframe load` flag
        // TODO Step 3 - set child document  `mut iframe load` flag

        // Step 4
        self.upcast::<EventTarget>().fire_simple_event("load");

        let mut blocker = self.load_blocker.borrow_mut();
        LoadBlocker::terminate(&mut blocker);

        // TODO Step 5 - unset child document `mut iframe load` flag

        let window = window_from_node(self);
        window.reflow(ReflowGoal::ForDisplay,
                      ReflowQueryType::NoQuery,
                      ReflowReason::IFrameLoadEvent);
    }

    /// Check whether the iframe has the mozprivatebrowsing attribute set
    pub fn privatebrowsing(&self) -> bool {
        if self.Mozbrowser() {
            let element = self.upcast::<Element>();
            element.has_attribute(&Atom::from("mozprivatebrowsing"))
        } else {
            false
        }
    }

}

pub trait HTMLIFrameElementLayoutMethods {
    fn pipeline_id(self) -> Option<PipelineId>;
    fn get_width(&self) -> LengthOrPercentageOrAuto;
    fn get_height(&self) -> LengthOrPercentageOrAuto;
}

impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
    #[inline]
    #[allow(unsafe_code)]
    fn pipeline_id(self) -> Option<PipelineId> {
        unsafe {
            (*self.unsafe_get()).pipeline_id.get()
        }
    }

    #[allow(unsafe_code)]
    fn get_width(&self) -> LengthOrPercentageOrAuto {
        unsafe {
            (*self.upcast::<Element>().unsafe_get())
                .get_attr_for_layout(&ns!(), &atom!("width"))
                .map(AttrValue::as_dimension)
                .cloned()
                .unwrap_or(LengthOrPercentageOrAuto::Auto)
        }
    }

    #[allow(unsafe_code)]
    fn get_height(&self) -> LengthOrPercentageOrAuto {
        unsafe {
            (*self.upcast::<Element>().unsafe_get())
                .get_attr_for_layout(&ns!(), &atom!("height"))
                .map(AttrValue::as_dimension)
                .cloned()
                .unwrap_or(LengthOrPercentageOrAuto::Auto)
        }
    }
}

pub trait MozBrowserEventDetailBuilder {
    #[allow(unsafe_code)]
    unsafe fn build_mozbrowser_event_detail(&self,
                                            event: MozBrowserEvent,
                                            cx: *mut JSContext,
                                            rval: MutableHandleValue);
}

impl MozBrowserEventDetailBuilder for HTMLIFrameElement {
    #[allow(unsafe_code)]
    unsafe fn build_mozbrowser_event_detail(&self,
                                            event: MozBrowserEvent,
                                            cx: *mut JSContext,
                                            rval: MutableHandleValue) {
        match event {
            MozBrowserEvent::AsyncScroll | MozBrowserEvent::Close | MozBrowserEvent::ContextMenu |
            MozBrowserEvent::LoadEnd | MozBrowserEvent::LoadStart |
            MozBrowserEvent::Connected | MozBrowserEvent::OpenWindow | MozBrowserEvent::OpenSearch  |
            MozBrowserEvent::UsernameAndPasswordRequired => {
                rval.set(NullValue());
            }
            MozBrowserEvent::Error(error_type, description, report) => {
                BrowserElementErrorEventDetail {
                    type_: Some(DOMString::from(error_type.name())),
                    description: description.map(DOMString::from),
                    report: report.map(DOMString::from),
                }.to_jsval(cx, rval);
            },
            MozBrowserEvent::SecurityChange(https_state) => {
                BrowserElementSecurityChangeDetail {
                    // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsersecuritychange
                    state: Some(DOMString::from(match https_state {
                        HttpsState::Modern => "secure",
                        HttpsState::Deprecated => "broken",
                        HttpsState::None => "insecure",
                    }.to_owned())),
                    // FIXME - Not supported yet:
                    trackingContent: None,
                    mixedContent: None,
                    trackingState: None,
                    extendedValidation: None,
                    mixedState: None,
                }.to_jsval(cx, rval);
            }
            MozBrowserEvent::TitleChange(ref string) => {
                string.to_jsval(cx, rval);
            }
            MozBrowserEvent::LocationChange(uri, can_go_back, can_go_forward) => {
                BrowserElementLocationChangeEventDetail {
                    uri: Some(DOMString::from(uri)),
                    canGoBack: Some(can_go_back),
                    canGoForward: Some(can_go_forward),
                }.to_jsval(cx, rval);
            }
            MozBrowserEvent::IconChange(rel, href, sizes) => {
                BrowserElementIconChangeEventDetail {
                    rel: Some(DOMString::from(rel)),
                    href: Some(DOMString::from(href)),
                    sizes: Some(DOMString::from(sizes)),
                }.to_jsval(cx, rval);
            }
            MozBrowserEvent::ShowModalPrompt(prompt_type, title, message, return_value) => {
                BrowserShowModalPromptEventDetail {
                    promptType: Some(DOMString::from(prompt_type)),
                    title: Some(DOMString::from(title)),
                    message: Some(DOMString::from(message)),
                    returnValue: Some(DOMString::from(return_value)),
                }.to_jsval(cx, rval)
            }
        }
    }
}

pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> ErrorResult {
    if iframe.Mozbrowser() {
        if iframe.upcast::<Node>().is_in_doc() {
            let window = window_from_node(iframe);

            let pipeline_info = Some((window.pipeline(),
                                      iframe.subpage_id().unwrap()));
            let msg = ConstellationMsg::Navigate(pipeline_info, direction);
            window.constellation_chan().send(msg).unwrap();
        }

        Ok(())
    } else {
        debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top
            level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)");
        Err(Error::NotSupported)
    }
}

impl HTMLIFrameElementMethods for HTMLIFrameElement {
    // https://html.spec.whatwg.org/multipage/#dom-iframe-src
    fn Src(&self) -> DOMString {
        self.upcast::<Element>().get_string_attribute(&atom!("src"))
    }

    // https://html.spec.whatwg.org/multipage/#dom-iframe-src
    fn SetSrc(&self, src: DOMString) {
        self.upcast::<Element>().set_url_attribute(&atom!("src"), src)
    }

    // https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
    fn Sandbox(&self) -> DOMString {
        self.upcast::<Element>().get_string_attribute(&atom!("sandbox"))
    }

    // https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
    fn SetSandbox(&self, sandbox: DOMString) {
        self.upcast::<Element>().set_tokenlist_attribute(&atom!("sandbox"), sandbox);
    }

    // https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
    fn GetContentWindow(&self) -> Option<Root<Window>> {
        self.subpage_id.get().and_then(|subpage_id| {
            let window = window_from_node(self);
            let window = window.r();
            let browsing_context = window.browsing_context();
            browsing_context.find_child_by_subpage(subpage_id)
        })
    }

    // https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument
    fn GetContentDocument(&self) -> Option<Root<Document>> {
        self.GetContentWindow().and_then(|window| {
            // FIXME(#10964): this should use the Document's origin and the
            //                origin of the incumbent settings object.
            let self_url = self.get_url();
            let win_url = window_from_node(self).get_url();

            if UrlHelper::SameOrigin(&self_url, &win_url) {
                Some(window.Document())
            } else {
                None
            }
        })
    }

    // Experimental mozbrowser implementation is based on the webidl
    // present in the gecko source tree, and the documentation here:
    // https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API

    // TODO(gw): Use experimental codegen when it is available to avoid
    // exposing these APIs. See https://github.com/servo/servo/issues/5264.

    // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
    fn Mozbrowser(&self) -> bool {
        // We don't want to allow mozbrowser iframes within iframes
        let is_root_pipeline = window_from_node(self).parent_info().is_none();
        if mozbrowser_enabled() && is_root_pipeline {
            let element = self.upcast::<Element>();
            element.has_attribute(&atom!("mozbrowser"))
        } else {
            false
        }
    }

    // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
    fn SetMozbrowser(&self, value: bool) -> ErrorResult {
        if mozbrowser_enabled() {
            let element = self.upcast::<Element>();
            element.set_bool_attribute(&atom!("mozbrowser"), value);
        }
        Ok(())
    }

    // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack
    fn GoBack(&self) -> ErrorResult {
        Navigate(self, NavigationDirection::Back)
    }

    // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goForward
    fn GoForward(&self) -> ErrorResult {
        Navigate(self, NavigationDirection::Forward)
    }

    // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload
    fn Reload(&self, _hardReload: bool) -> ErrorResult {
        if self.Mozbrowser() {
            if self.upcast::<Node>().is_in_doc() {
                self.navigate_or_reload_child_browsing_context(None);
            }
            Ok(())
        } else {
            debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top
                level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)");
            Err(Error::NotSupported)
        }
    }

    // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/stop
    fn Stop(&self) -> ErrorResult {
        Err(Error::NotSupported)
    }

    // https://html.spec.whatwg.org/multipage/#dom-dim-width
    make_getter!(Width, "width");
    // https://html.spec.whatwg.org/multipage/#dom-dim-width
    make_dimension_setter!(SetWidth, "width");

    // https://html.spec.whatwg.org/multipage/#dom-dim-height
    make_getter!(Height, "height");
    // https://html.spec.whatwg.org/multipage/#dom-dim-height
    make_dimension_setter!(SetHeight, "height");
}

impl VirtualMethods for HTMLIFrameElement {
    fn super_type(&self) -> Option<&VirtualMethods> {
        Some(self.upcast::<HTMLElement>() as &VirtualMethods)
    }

    fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
        self.super_type().unwrap().attribute_mutated(attr, mutation);
        match attr.local_name() {
            &atom!("sandbox") => {
                self.sandbox.set(mutation.new_value(attr).map(|value| {
                    let mut modes = SandboxAllowance::AllowNothing as u8;
                    for token in value.as_tokens() {
                        modes |= match &*token.to_ascii_lowercase() {
                            "allow-same-origin" => SandboxAllowance::AllowSameOrigin,
                            "allow-forms" => SandboxAllowance::AllowForms,
                            "allow-pointer-lock" => SandboxAllowance::AllowPointerLock,
                            "allow-popups" => SandboxAllowance::AllowPopups,
                            "allow-scripts" => SandboxAllowance::AllowScripts,
                            "allow-top-navigation" => SandboxAllowance::AllowTopNavigation,
                            _ => SandboxAllowance::AllowNothing
                        } as u8;
                    }
                    modes
                }));
            },
            &atom!("src") => {
                if let AttributeMutation::Set(_) = mutation {
                    if self.upcast::<Node>().is_in_doc() {
                        self.process_the_iframe_attributes();
                    }
                }
            },
            _ => {},
        }
    }

    fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
        match name {
            &atom!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
            &atom!("width") => AttrValue::from_dimension(value.into()),
            &atom!("height") => AttrValue::from_dimension(value.into()),
            _ => self.super_type().unwrap().parse_plain_attribute(name, value),
        }
    }

    fn bind_to_tree(&self, tree_in_doc: bool) {
        if let Some(ref s) = self.super_type() {
            s.bind_to_tree(tree_in_doc);
        }

        if tree_in_doc {
            self.process_the_iframe_attributes();
        }
    }

    fn unbind_from_tree(&self, context: &UnbindContext) {
        self.super_type().unwrap().unbind_from_tree(context);

        let mut blocker = self.load_blocker.borrow_mut();
        LoadBlocker::terminate(&mut blocker);

        // https://html.spec.whatwg.org/multipage/#a-browsing-context-is-discarded
        if let Some(pipeline_id) = self.pipeline_id.get() {
            let window = window_from_node(self);

            // The only reason we're waiting for the iframe to be totally
            // removed is to ensure the script thread can't add iframes faster
            // than the compositor can remove them.
            //
            // Since most of this cleanup doesn't happen on same-origin
            // iframes, and since that would cause a deadlock, don't do it.
            let same_origin = {
                // FIXME(#10968): this should probably match the origin check in
                //                HTMLIFrameElement::contentDocument.
                let self_url = self.get_url();
                let win_url = window_from_node(self).get_url();
                UrlHelper::SameOrigin(&self_url, &win_url)
            };
            let (sender, receiver) = if same_origin {
                (None, None)
            } else {
                let (sender, receiver) = ipc::channel().unwrap();
                (Some(sender), Some(receiver))
            };
            let msg = ConstellationMsg::RemoveIFrame(pipeline_id, sender);
            window.constellation_chan().send(msg).unwrap();
            if let Some(receiver) = receiver {
                receiver.recv().unwrap()
            }

            // Resetting the subpage id to None is required here so that
            // if this iframe is subsequently re-added to the document
            // the load doesn't think that it's a navigation, but instead
            // a new iframe. Without this, the constellation gets very
            // confused.
            self.subpage_id.set(None);
            self.pipeline_id.set(None);
        }
    }
}