aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bluetooth.rs5
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs10
-rw-r--r--components/script/dom/document.rs2
-rw-r--r--components/script/dom/element.rs69
-rw-r--r--components/script/dom/node.rs6
-rw-r--r--components/script/dom/webidls/Element.webidl2
6 files changed, 79 insertions, 15 deletions
diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs
index e00fb33cf59..7deca26c9d3 100644
--- a/components/script/dom/bluetooth.rs
+++ b/components/script/dom/bluetooth.rs
@@ -125,10 +125,9 @@ fn convert_request_device_options(options: &RequestDeviceOptions,
if let Some(ref opt_services) = options.optionalServices {
for opt_service in opt_services {
let uuid = try!(BluetoothUUID::GetService(global, opt_service.clone())).to_string();
- if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
- return Err(Security)
+ if !uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
+ optional_services.push(uuid);
}
- optional_services.push(uuid);
}
}
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index 48cf9be6361..cf0f896d3f6 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -170,6 +170,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
service: BluetoothServiceUUID)
-> Fallible<Root<BluetoothRemoteGATTService>> {
let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string();
+ if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
+ return Err(Security)
+ }
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GetIncludedService(self.get_instance_id(),
@@ -196,7 +199,12 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
let mut uuid: Option<String> = None;
if let Some(s) = service {
- uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string())
+ uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string());
+ if let Some(ref uuid) = uuid {
+ if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
+ return Err(Security)
+ }
+ }
};
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index c142945d131..4dfb484a301 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -2679,7 +2679,7 @@ impl DocumentMethods for Document {
.filter(|node| filter_by_name(&name, node.r()))
.peekable();
if let Some(first) = elements.next() {
- if elements.is_empty() {
+ if elements.peek().is_none() {
*found = true;
// TODO: Step 2.
// Step 3.
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index e2398a14139..0b639539f5f 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -119,6 +119,25 @@ pub enum ElementCreator {
ScriptCreated,
}
+pub enum AdjacentPosition {
+ BeforeBegin,
+ AfterEnd,
+ AfterBegin,
+ BeforeEnd,
+}
+
+impl AdjacentPosition {
+ pub fn parse(position: &str) -> Fallible<AdjacentPosition> {
+ match_ignore_ascii_case! { &*position,
+ "beforebegin" => Ok(AdjacentPosition::BeforeBegin),
+ "afterbegin" => Ok(AdjacentPosition::AfterBegin),
+ "beforeend" => Ok(AdjacentPosition::BeforeEnd),
+ "afterend" => Ok(AdjacentPosition::AfterEnd),
+ _ => Err(Error::Syntax)
+ }
+ }
+}
+
//
// Element methods
//
@@ -1252,31 +1271,30 @@ impl Element {
}
// https://dom.spec.whatwg.org/#insert-adjacent
- pub fn insert_adjacent(&self, where_: DOMString, node: &Node)
+ pub fn insert_adjacent(&self, where_: AdjacentPosition, node: &Node)
-> Fallible<Option<Root<Node>>> {
let self_node = self.upcast::<Node>();
- match &*where_ {
- "beforebegin" => {
+ match where_ {
+ AdjacentPosition::BeforeBegin => {
if let Some(parent) = self_node.GetParentNode() {
Node::pre_insert(node, &parent, Some(self_node)).map(Some)
} else {
Ok(None)
}
}
- "afterbegin" => {
+ AdjacentPosition::AfterBegin => {
Node::pre_insert(node, &self_node, self_node.GetFirstChild().r()).map(Some)
}
- "beforeend" => {
+ AdjacentPosition::BeforeEnd => {
Node::pre_insert(node, &self_node, None).map(Some)
}
- "afterend" => {
+ AdjacentPosition::AfterEnd => {
if let Some(parent) = self_node.GetParentNode() {
Node::pre_insert(node, &parent, self_node.GetNextSibling().r()).map(Some)
} else {
Ok(None)
}
}
- _ => Err(Error::Syntax)
}
}
@@ -2010,6 +2028,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-insertadjacentelement
fn InsertAdjacentElement(&self, where_: DOMString, element: &Element)
-> Fallible<Option<Root<Element>>> {
+ let where_ = try!(AdjacentPosition::parse(&*where_));
let inserted_node = try!(self.insert_adjacent(where_, element.upcast()));
Ok(inserted_node.map(|node| Root::downcast(node).unwrap()))
}
@@ -2021,8 +2040,44 @@ impl ElementMethods for Element {
let text = Text::new(data, &document_from_node(self));
// Step 2.
+ let where_ = try!(AdjacentPosition::parse(&*where_));
self.insert_adjacent(where_, text.upcast()).map(|_| ())
}
+
+ // https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml
+ fn InsertAdjacentHTML(&self, position: DOMString, text: DOMString)
+ -> ErrorResult {
+ // Step 1.
+ let position = try!(AdjacentPosition::parse(&*position));
+
+ let context = match position {
+ AdjacentPosition::BeforeBegin | AdjacentPosition::AfterEnd => {
+ match self.upcast::<Node>().GetParentNode() {
+ Some(ref node) if node.is::<Document>() => {
+ return Err(Error::NoModificationAllowed)
+ }
+ None => return Err(Error::NoModificationAllowed),
+ Some(node) => node,
+ }
+ }
+ AdjacentPosition::AfterBegin | AdjacentPosition::BeforeEnd => {
+ Root::from_ref(self.upcast::<Node>())
+ }
+ };
+
+ // Step 2.
+ let context = match context.downcast::<Element>() {
+ Some(elem) if elem.local_name() != &atom!("html") ||
+ !elem.html_element_in_html_document() => Root::from_ref(elem),
+ _ => Root::upcast(HTMLBodyElement::new(atom!("body"), None, &*context.owner_doc()))
+ };
+
+ // Step 3.
+ let fragment = try!(context.upcast::<Node>().parse_fragment(text));
+
+ // Step 4.
+ context.insert_adjacent(position, fragment.upcast()).map(|_| ())
+ }
}
pub fn fragment_affecting_attributes() -> [Atom; 3] {
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index d3e6a955284..3032abe0685 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1452,7 +1452,7 @@ impl Node {
0 => (),
// Step 6.1.2
1 => {
- if !parent.child_elements().is_empty() {
+ if !parent.child_elements().peek().is_none() {
return Err(Error::HierarchyRequest);
}
if let Some(child) = child {
@@ -1468,7 +1468,7 @@ impl Node {
},
// Step 6.2
NodeTypeId::Element(_) => {
- if !parent.child_elements().is_empty() {
+ if !parent.child_elements().peek().is_none() {
return Err(Error::HierarchyRequest);
}
if let Some(ref child) = child {
@@ -1495,7 +1495,7 @@ impl Node {
}
},
None => {
- if !parent.child_elements().is_empty() {
+ if !parent.child_elements().peek().is_none() {
return Err(Error::HierarchyRequest);
}
},
diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl
index ee27b78d4e4..48aeed7fbbb 100644
--- a/components/script/dom/webidls/Element.webidl
+++ b/components/script/dom/webidls/Element.webidl
@@ -75,6 +75,8 @@ interface Element : Node {
Element? insertAdjacentElement(DOMString where_, Element element); // historical
[Throws]
void insertAdjacentText(DOMString where_, DOMString data);
+ [Throws]
+ void insertAdjacentHTML(DOMString position, DOMString html);
};
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface