mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
* Remove script_plugins * Use crown instead of script_plugins * crown_is_not_used * Use crown in command base * bootstrap crown * tidy happy * disable sccache * Bring crown in tree * Install crown from tree * fix windows ci * fix warning * fix mac libscript_plugins.dylib is not available anymore * Update components/script/lib.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> * Update for nightly-2023-03-18 Mostly just based off https://github.com/servo/servo/pull/30630 * Always install crown it's slow only when there is new version * Run crown test with `mach test-unit` * Small fixups; better trace_in_no_trace tests * Better doc * crown in config.toml * Fix tidy for real * no sccache on rustc_wrapper * document rustc overrides * fixup of compiletest * Make a few minor comment adjustments * Fix a typo in python/servo/platform/base.py Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com> * Proper test types * Ignore tidy on crown/tests --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
132 lines
4 KiB
Rust
132 lines
4 KiB
Rust
/* 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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
use dom_struct::dom_struct;
|
|
use html5ever::{LocalName, Prefix};
|
|
use js::rust::HandleObject;
|
|
use style::str::HTML_SPACE_CHARACTERS;
|
|
|
|
use crate::dom::attr::Attr;
|
|
use crate::dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods;
|
|
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
|
use crate::dom::bindings::inheritance::Castable;
|
|
use crate::dom::bindings::root::DomRoot;
|
|
use crate::dom::bindings::str::DOMString;
|
|
use crate::dom::document::Document;
|
|
use crate::dom::element::{AttributeMutation, Element};
|
|
use crate::dom::htmlelement::HTMLElement;
|
|
use crate::dom::htmlheadelement::HTMLHeadElement;
|
|
use crate::dom::node::{BindContext, Node, UnbindContext};
|
|
use crate::dom::virtualmethods::VirtualMethods;
|
|
|
|
#[dom_struct]
|
|
pub struct HTMLMetaElement {
|
|
htmlelement: HTMLElement,
|
|
}
|
|
|
|
impl HTMLMetaElement {
|
|
fn new_inherited(
|
|
local_name: LocalName,
|
|
prefix: Option<Prefix>,
|
|
document: &Document,
|
|
) -> HTMLMetaElement {
|
|
HTMLMetaElement {
|
|
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
|
|
}
|
|
}
|
|
|
|
#[allow(crown::unrooted_must_root)]
|
|
pub fn new(
|
|
local_name: LocalName,
|
|
prefix: Option<Prefix>,
|
|
document: &Document,
|
|
proto: Option<HandleObject>,
|
|
) -> DomRoot<HTMLMetaElement> {
|
|
Node::reflect_node_with_proto(
|
|
Box::new(HTMLMetaElement::new_inherited(local_name, prefix, document)),
|
|
document,
|
|
proto,
|
|
)
|
|
}
|
|
|
|
fn process_attributes(&self) {
|
|
let element = self.upcast::<Element>();
|
|
if let Some(ref name) = element.get_name() {
|
|
let name = name.to_ascii_lowercase();
|
|
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
|
|
if name == "referrer" {
|
|
self.apply_referrer();
|
|
}
|
|
}
|
|
}
|
|
|
|
fn process_referrer_attribute(&self) {
|
|
let element = self.upcast::<Element>();
|
|
if let Some(ref name) = element.get_name() {
|
|
let name = name.to_ascii_lowercase();
|
|
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
|
|
|
|
if name == "referrer" {
|
|
self.apply_referrer();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <https://html.spec.whatwg.org/multipage/#meta-referrer>
|
|
fn apply_referrer(&self) {
|
|
if let Some(parent) = self.upcast::<Node>().GetParentElement() {
|
|
if let Some(head) = parent.downcast::<HTMLHeadElement>() {
|
|
head.set_document_referrer();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl HTMLMetaElementMethods for HTMLMetaElement {
|
|
// https://html.spec.whatwg.org/multipage/#dom-meta-name
|
|
make_getter!(Name, "name");
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-meta-name
|
|
make_atomic_setter!(SetName, "name");
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-meta-content
|
|
make_getter!(Content, "content");
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-meta-content
|
|
make_setter!(SetContent, "content");
|
|
}
|
|
|
|
impl VirtualMethods for HTMLMetaElement {
|
|
fn super_type(&self) -> Option<&dyn VirtualMethods> {
|
|
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
|
|
}
|
|
|
|
fn bind_to_tree(&self, context: &BindContext) {
|
|
if let Some(ref s) = self.super_type() {
|
|
s.bind_to_tree(context);
|
|
}
|
|
|
|
if context.tree_connected {
|
|
self.process_attributes();
|
|
}
|
|
}
|
|
|
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
|
if let Some(s) = self.super_type() {
|
|
s.attribute_mutated(attr, mutation);
|
|
}
|
|
|
|
self.process_referrer_attribute();
|
|
}
|
|
|
|
fn unbind_from_tree(&self, context: &UnbindContext) {
|
|
if let Some(ref s) = self.super_type() {
|
|
s.unbind_from_tree(context);
|
|
}
|
|
|
|
if context.tree_connected {
|
|
self.process_referrer_attribute();
|
|
}
|
|
}
|
|
}
|