Code review comments and upstream merge conflicts

Incorporated code review comments in components/net/http_loader.rs
Resolved merge conflicts in cargo.lock file. Updated ReferrerPolicy in
lib.rs
This commit is contained in:
Raghav 2016-11-04 11:18:22 -04:00
commit 26dac98546
340 changed files with 9134 additions and 452 deletions

View file

@ -6276,7 +6276,7 @@ class CGCallback(CGClass):
})
bodyWithoutThis = string.Template(
setupCall +
"rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut());"
"rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut());\n"
"return ${methodName}(${callArgs});").substitute({
"callArgs": ", ".join(argnamesWithoutThis),
"methodName": 'self.' + method.name,

View file

@ -58,8 +58,8 @@ use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
use js::jsval::JSVal;
use js::rust::Runtime;
use libc;
use msg::constellation_msg::{FrameId, FrameType, PipelineId, ReferrerPolicy};
use net_traits::{Metadata, NetworkError, ResourceThreads};
use msg::constellation_msg::{FrameId, FrameType, PipelineId};
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads};
use net_traits::filemanager_thread::RelativePos;
use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};

View file

@ -3,6 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use bluetooth_traits::{BluetoothError, BluetoothMethodMsg};
use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence};
use bluetooth_traits::scanfilter::{RequestDeviceoptions, ServiceUUIDSequence};
use core::clone::Clone;
use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothMethods, BluetoothRequestDeviceFilter};
use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions;
@ -18,9 +21,6 @@ use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use ipc_channel::ipc::{self, IpcSender};
use js::conversions::ToJSValConvertible;
use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence};
use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence};
use net_traits::bluetooth_thread::{BluetoothError, BluetoothMethodMsg};
use std::rc::Rc;
const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices.";

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use bluetooth_traits::BluetoothMethodMsg;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::
BluetoothCharacteristicPropertiesMethods;
@ -25,7 +26,6 @@ use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use std::rc::Rc;
// Maximum length of an attribute value.

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use bluetooth_traits::BluetoothMethodMsg;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
@ -21,7 +22,6 @@ use dom::bluetoothremotegattcharacteristic::{BluetoothRemoteGATTCharacteristic,
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use std::rc::Rc;
// http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use bluetooth_traits::BluetoothMethodMsg;
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
@ -18,7 +19,6 @@ use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use std::cell::Cell;
use std::rc::Rc;

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
use bluetooth_traits::BluetoothMethodMsg;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
use dom::bindings::error::Error::{self, Security};
@ -18,7 +19,6 @@ use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, Blue
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use std::rc::Rc;
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice

View file

@ -96,9 +96,8 @@ use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSObject, JSRuntime};
use js::jsapi::JS_GetRuntime;
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use net_traits::{FetchResponseMsg, IpcSend};
use msg::constellation_msg::{FrameId, Key, KeyModifiers, KeyState};
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
use net_traits::CookieSource::NonHTTP;
use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl};
use net_traits::request::RequestInit;
@ -606,7 +605,7 @@ impl Document {
self.ready_state.set(state);
self.upcast::<EventTarget>().fire_simple_event("readystatechange");
self.upcast::<EventTarget>().fire_event(atom!("readystatechange"));
}
/// Return whether scripting is enabled or not
@ -1400,7 +1399,7 @@ impl Document {
if let Some((parent_pipeline_id, _)) = self.window.parent_info() {
let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id,
Some(global_scope.pipeline_id()),
global_scope.pipeline_id(),
event);
global_scope.constellation_chan().send(event).unwrap();
}
@ -1513,8 +1512,10 @@ impl Document {
}
}
let loader = self.loader.borrow();
if !loader.is_blocked() && !loader.events_inhibited() {
if !self.loader.borrow().is_blocked() && !self.loader.borrow().events_inhibited() {
// Schedule a task to fire a "load" event (if no blocking loads have arrived in the mean time)
// NOTE: we can end up executing this code more than once, in case more blocking loads arrive.
debug!("Document loads are complete.");
let win = self.window();
let msg = MainThreadScriptMsg::DocumentLoadsComplete(
win.upcast::<GlobalScope>().pipeline_id());
@ -1630,11 +1631,11 @@ impl Document {
}
/// Find an iframe element in the document.
pub fn find_iframe(&self, pipeline: PipelineId) -> Option<Root<HTMLIFrameElement>> {
pub fn find_iframe(&self, frame_id: FrameId) -> Option<Root<HTMLIFrameElement>> {
self.upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLIFrameElement>)
.find(|node| node.pipeline_id() == Some(pipeline))
.find(|node| node.frame_id() == frame_id)
}
pub fn get_dom_loading(&self) -> u64 {

View file

@ -330,7 +330,9 @@ impl Runnable for EventRunnable {
fn handler(self: Box<EventRunnable>) {
let target = self.target.root();
target.fire_event(&*self.name, self.bubbles, self.cancelable);
let bubbles = self.bubbles.clone();
let cancelable = self.cancelable.clone();
target.fire_event_with_params(self.name, bubbles, cancelable);
}
}
@ -345,6 +347,6 @@ impl Runnable for SimpleEventRunnable {
fn handler(self: Box<SimpleEventRunnable>) {
let target = self.target.root();
target.fire_simple_event(&*self.name);
target.fire_event(self.name);
}
}

View file

@ -490,21 +490,42 @@ impl EventTarget {
!self.handlers.borrow().is_empty()
}
// https://html.spec.whatwg.org/multipage/#fire-a-simple-event
pub fn fire_simple_event(&self, name: &str) -> Root<Event> {
self.fire_event(name, EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable)
// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_event(&self, name: Atom) -> Root<Event> {
self.fire_event_with_params(name,
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable)
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_event(&self, name: &str,
bubbles: EventBubbles,
cancelable: EventCancelable)
-> Root<Event> {
let event = Event::new(&self.global(), Atom::from(name), bubbles, cancelable);
pub fn fire_bubbling_event(&self, name: Atom) -> Root<Event> {
self.fire_event_with_params(name,
EventBubbles::Bubbles,
EventCancelable::NotCancelable)
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_cancelable_event(&self, name: Atom) -> Root<Event> {
self.fire_event_with_params(name,
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable)
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_bubbling_cancelable_event(&self, name: Atom) -> Root<Event> {
self.fire_event_with_params(name,
EventBubbles::Bubbles,
EventCancelable::Cancelable)
}
// https://dom.spec.whatwg.org/#concept-event-fire
pub fn fire_event_with_params(&self,
name: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable)
-> Root<Event> {
let event = Event::new(&self.global(), name, bubbles, cancelable);
event.fire(self);
event
}
}

View file

@ -25,7 +25,7 @@ use dom::node::{Node, document_from_node, window_from_node};
use dom::urlhelper::UrlHelper;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use msg::constellation_msg::ReferrerPolicy;
use net_traits::ReferrerPolicy;
use num_traits::ToPrimitive;
use script_traits::MozBrowserEvent;
use std::default::Default;

View file

@ -206,24 +206,24 @@ impl HTMLCollection {
HTMLCollection::create(window, root, box ElementChildFilter)
}
pub fn elements_iter_after(&self, after: &Node) -> HTMLCollectionElementsIter {
pub fn elements_iter_after<'a>(&'a self, after: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate forwards from a node.
HTMLCollectionElementsIter {
node_iter: box after.following_nodes(&self.root),
node_iter: after.following_nodes(&self.root),
root: Root::from_ref(&self.root),
filter: &self.filter,
}
}
pub fn elements_iter(&self) -> HTMLCollectionElementsIter {
pub fn elements_iter<'a>(&'a self) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate forwards from the root.
self.elements_iter_after(&*self.root)
}
pub fn elements_iter_before(&self, before: &Node) -> HTMLCollectionElementsIter {
pub fn elements_iter_before<'a>(&'a self, before: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a {
// Iterate backwards from a node.
HTMLCollectionElementsIter {
node_iter: box before.preceding_nodes(&self.root),
node_iter: before.preceding_nodes(&self.root),
root: Root::from_ref(&self.root),
filter: &self.filter,
}
@ -235,13 +235,13 @@ impl HTMLCollection {
}
// TODO: Make this generic, and avoid code duplication
pub struct HTMLCollectionElementsIter<'a> {
node_iter: Box<Iterator<Item = Root<Node>>>,
struct HTMLCollectionElementsIter<'a, I> {
node_iter: I,
root: Root<Node>,
filter: &'a Box<CollectionFilter>,
}
impl<'a> Iterator for HTMLCollectionElementsIter<'a> {
impl<'a, I: Iterator<Item=Root<Node>>> Iterator for HTMLCollectionElementsIter<'a, I> {
type Item = Root<Element>;
fn next(&mut self) -> Option<Self::Item> {
@ -285,13 +285,15 @@ impl HTMLCollectionMethods for HTMLCollection {
// Iterate forwards, starting at the cursor.
let offset = index - (cached_index + 1);
let node: Root<Node> = Root::upcast(element);
self.set_cached_cursor(index, self.elements_iter_after(&node).nth(offset as usize))
let mut iter = self.elements_iter_after(&node);
self.set_cached_cursor(index, iter.nth(offset as usize))
} else {
// The cursor is after the element we're looking for
// Iterate backwards, starting at the cursor.
let offset = cached_index - (index + 1);
let node: Root<Node> = Root::upcast(element);
self.set_cached_cursor(index, self.elements_iter_before(&node).nth(offset as usize))
let mut iter = self.elements_iter_before(&node);
self.set_cached_cursor(index, iter.nth(offset as usize))
}
} else {
// Cache miss

View file

@ -94,7 +94,7 @@ impl Runnable for DetailsNotificationRunnable {
fn handler(self: Box<DetailsNotificationRunnable>) {
let target = self.element.root();
if target.check_toggle_count(self.toggle_number) {
target.upcast::<EventTarget>().fire_simple_event("toggle");
target.upcast::<EventTarget>().fire_event(atom!("toggle"));
}
}
}

View file

@ -20,7 +20,6 @@ use dom::bindings::str::DOMString;
use dom::blob::Blob;
use dom::document::Document;
use dom::element::Element;
use dom::event::{EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
use dom::file::File;
use dom::globalscope::GlobalScope;
@ -305,16 +304,14 @@ impl HTMLFormElement {
{
if self.interactive_validation().is_err() {
// TODO: Implement event handlers on all form control elements
self.upcast::<EventTarget>().fire_simple_event("invalid");
self.upcast::<EventTarget>().fire_event(atom!("invalid"));
return;
}
}
// Step 5
if submit_method_flag == SubmittedFrom::NotFromForm {
let event = self.upcast::<EventTarget>()
.fire_event("submit",
EventBubbles::Bubbles,
EventCancelable::Cancelable);
.fire_bubbling_cancelable_event(atom!("submit"));
if event.DefaultPrevented() {
return;
}
@ -484,9 +481,7 @@ impl HTMLFormElement {
// Step 5-6
let unhandled_invalid_controls = invalid_controls.into_iter().filter_map(|field| {
let event = field.as_event_target()
.fire_event("invalid",
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable);
.fire_cancelable_event(atom!("invalid"));
if !event.DefaultPrevented() { return Some(field); }
None
}).collect::<Vec<FormSubmittableElement>>();
@ -615,9 +610,7 @@ impl HTMLFormElement {
}
let event = self.upcast::<EventTarget>()
.fire_event("reset",
EventBubbles::Bubbles,
EventCancelable::Cancelable);
.fire_bubbling_cancelable_event(atom!("reset"));
if event.DefaultPrevented() {
return;
}

View file

@ -207,6 +207,11 @@ impl HTMLIFrameElement {
self.pipeline_id.get()
}
#[inline]
pub fn frame_id(&self) -> FrameId {
self.frame_id
}
pub fn change_visibility_status(&self, visibility: bool) {
if self.visibility.get() != visibility {
self.visibility.set(visibility);
@ -239,7 +244,7 @@ impl HTMLIFrameElement {
// TODO Step 3 - set child document `mut iframe load` flag
// Step 4
self.upcast::<EventTarget>().fire_simple_event("load");
self.upcast::<EventTarget>().fire_event(atom!("load"));
let mut blocker = self.load_blocker.borrow_mut();
LoadBlocker::terminate(&mut blocker);
@ -409,7 +414,7 @@ unsafe fn build_mozbrowser_event_detail(event: MozBrowserEvent,
pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> ErrorResult {
if iframe.Mozbrowser() {
if iframe.upcast::<Node>().is_in_doc() {
if iframe.upcast::<Node>().is_in_doc_with_browsing_context() {
let window = window_from_node(iframe);
let msg = ConstellationMsg::TraverseHistory(iframe.pipeline_id(), direction);
window.upcast::<GlobalScope>().constellation_chan().send(msg).unwrap();
@ -495,7 +500,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload
fn Reload(&self, _hard_reload: bool) -> ErrorResult {
if self.Mozbrowser() {
if self.upcast::<Node>().is_in_doc() {
if self.upcast::<Node>().is_in_doc_with_browsing_context() {
self.navigate_or_reload_child_browsing_context(None, true);
}
Ok(())
@ -593,7 +598,16 @@ impl VirtualMethods for HTMLIFrameElement {
},
&local_name!("src") => {
if let AttributeMutation::Set(_) = mutation {
if self.upcast::<Node>().is_in_doc() {
// https://html.spec.whatwg.org/multipage/#the-iframe-element
// "Similarly, whenever an iframe element with a non-null nested browsing context
// but with no srcdoc attribute specified has its src attribute set, changed, or removed,
// the user agent must process the iframe attributes,"
// but we can't check that directly, since the child browsing context
// may be in a different script thread. Instread, we check to see if the parent
// is in a document tree and has a browsing context, which is what causes
// the child browsing context to be created.
if self.upcast::<Node>().is_in_doc_with_browsing_context() {
debug!("iframe {} src set while in browsing context.", self.frame_id);
self.process_the_iframe_attributes();
}
}
@ -616,7 +630,14 @@ impl VirtualMethods for HTMLIFrameElement {
s.bind_to_tree(tree_in_doc);
}
if tree_in_doc {
// https://html.spec.whatwg.org/multipage/#the-iframe-element
// "When an iframe element is inserted into a document that has
// a browsing context, the user agent must create a new
// browsing context, set the element's nested browsing context
// to the newly-created browsing context, and then process the
// iframe attributes for the "first time"."
if self.upcast::<Node>().is_in_doc_with_browsing_context() {
debug!("iframe {} bound to browsing context.", self.frame_id);
self.process_the_iframe_attributes();
}
}

View file

@ -105,12 +105,12 @@ impl Runnable for ImageResponseHandlerRunnable {
// Fire image.onload
if trigger_image_load {
element.upcast::<EventTarget>().fire_simple_event("load");
element.upcast::<EventTarget>().fire_event(atom!("load"));
}
// Fire image.onerror
if trigger_image_error {
element.upcast::<EventTarget>().fire_simple_event("error");
element.upcast::<EventTarget>().fire_event(atom!("error"));
}
// Trigger reflow
@ -180,8 +180,8 @@ impl HTMLImageElement {
// Step 11, substep 5
let img = self.img.root();
img.current_request.borrow_mut().source_url = Some(self.src.into());
img.upcast::<EventTarget>().fire_simple_event("error");
img.upcast::<EventTarget>().fire_simple_event("loadend");
img.upcast::<EventTarget>().fire_event(atom!("error"));
img.upcast::<EventTarget>().fire_event(atom!("loadend"));
}
}

View file

@ -849,12 +849,8 @@ impl HTMLInputElement {
let filelist = FileList::new(&window, files);
self.filelist.set(Some(&filelist));
target.fire_event("input",
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
target.fire_event("change",
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
target.fire_bubbling_event(atom!("input"));
target.fire_bubbling_event(atom!("change"));
}
}
}
@ -1290,12 +1286,8 @@ impl Activatable for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
// Check if document owner is fully active
let target = self.upcast::<EventTarget>();
target.fire_event("input",
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
target.fire_event("change",
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
target.fire_bubbling_event(atom!("input"));
target.fire_bubbling_event(atom!("change"));
},
InputType::InputFile => self.select_files(None),
_ => ()

View file

@ -30,8 +30,7 @@ use hyper::mime::{Mime, TopLevel, SubLevel};
use hyper_serde::Serde;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use msg::constellation_msg::ReferrerPolicy;
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError};
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError, ReferrerPolicy};
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
use network_listener::{NetworkListener, PreInvoke};
use script_layout_interface::message::Msg;
@ -325,7 +324,7 @@ impl FetchResponseListener for StylesheetContext {
if let Some(ref meta) = self.metadata {
if let Some(Serde(ContentType(Mime(TopLevel::Text, SubLevel::Css, _)))) = meta.content_type {
} else {
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
self.elem.root().upcast::<EventTarget>().fire_event(atom!("error"));
}
}
}
@ -380,9 +379,9 @@ impl FetchResponseListener for StylesheetContext {
document.finish_load(LoadType::Stylesheet(self.url.clone()));
let event = if successful { "load" } else { "error" };
let event = if successful { atom!("load") } else { atom!("error") };
elem.upcast::<EventTarget>().fire_simple_event(event);
elem.upcast::<EventTarget>().fire_event(event);
}
}

View file

@ -142,7 +142,7 @@ impl WeakMediaQueryListVec {
pub fn evaluate_and_report_changes(&self) {
for mql in self.cell.borrow().iter() {
if let MediaQueryListMatchState::Changed(_) = mql.root().unwrap().evaluate_changes() {
mql.root().unwrap().upcast::<EventTarget>().fire_simple_event("change");
mql.root().unwrap().upcast::<EventTarget>().fire_event(atom!("change"));
}
}
}

View file

@ -399,6 +399,7 @@ pub mod testbinding;
pub mod testbindingiterable;
pub mod testbindingpairiterable;
pub mod testbindingproxy;
pub mod testrunner;
pub mod text;
pub mod textdecoder;
pub mod textencoder;

View file

@ -771,6 +771,10 @@ impl Node {
self.owner_doc().is_html_document()
}
pub fn is_in_doc_with_browsing_context(&self) -> bool {
self.is_in_doc() && self.owner_doc().browsing_context().is_some()
}
pub fn children(&self) -> NodeSiblingIterator {
NodeSiblingIterator {
current: self.GetFirstChild(),
@ -849,22 +853,23 @@ impl Node {
let tr = new_child();
let after_node = if index == -1 {
None
} else {
match get_items().elements_iter()
.map(Root::upcast::<Node>)
.map(Some)
.chain(iter::once(None))
.nth(index as usize) {
None => return Err(Error::IndexSize),
Some(node) => node,
}
};
{
let tr_node = tr.upcast::<Node>();
try!(self.InsertBefore(tr_node, after_node.r()));
if index == -1 {
try!(self.InsertBefore(tr_node, None));
} else {
let items = get_items();
let node = match items.elements_iter()
.map(Root::upcast::<Node>)
.map(Some)
.chain(iter::once(None))
.nth(index as usize) {
None => return Err(Error::IndexSize),
Some(node) => node,
};
try!(self.InsertBefore(tr_node, node.r()));
}
}
Ok(Root::upcast::<HTMLElement>(tr))

View file

@ -25,7 +25,7 @@ use dom::headers::{Guard, Headers};
use dom::promise::Promise;
use dom::xmlhttprequest::Extractable;
use hyper::method::Method as HttpMethod;
use msg::constellation_msg::ReferrerPolicy as MsgReferrerPolicy;
use net_traits::ReferrerPolicy as MsgReferrerPolicy;
use net_traits::request::{Origin, Window};
use net_traits::request::CacheMode as NetTraitsRequestCache;
use net_traits::request::CredentialsMode as NetTraitsRequestCredentials;

View file

@ -18,6 +18,7 @@ use dom::globalscope::GlobalScope;
use js::jsapi::{HandleValue, JSContext};
use script_thread::Runnable;
use script_traits::{ScriptMsg, DOMMessage};
use servo_atoms::Atom;
use std::cell::Cell;
use url::Url;
@ -56,12 +57,12 @@ impl ServiceWorker {
pub fn dispatch_simple_error(address: TrustedServiceWorkerAddress) {
let service_worker = address.root();
service_worker.upcast().fire_simple_event("error");
service_worker.upcast().fire_event(atom!("error"));
}
pub fn set_transition_state(&self, state: ServiceWorkerState) {
self.state.set(state);
self.upcast::<EventTarget>().fire_simple_event("statechange");
self.upcast::<EventTarget>().fire_event(Atom::from("statechange"));
}
pub fn get_script_url(&self) -> Url {

View file

@ -15,6 +15,7 @@ use dom::promise::Promise;
use dom::serviceworker::ServiceWorker;
use dom::serviceworkerregistration::ServiceWorkerRegistration;
use script_thread::ScriptThread;
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::default::Default;
use std::rc::Rc;
@ -45,7 +46,7 @@ pub trait Controllable {
impl Controllable for ServiceWorkerContainer {
fn set_controller(&self, active_worker: &ServiceWorker) {
self.controller.set(Some(active_worker));
self.upcast::<EventTarget>().fire_simple_event("controllerchange");
self.upcast::<EventTarget>().fire_event(Atom::from("controllerchange"));
}
}

View file

@ -28,6 +28,7 @@ use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as Req
use rand::random;
use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan};
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
use servo_atoms::Atom;
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
use std::thread;
use std::time::Duration;
@ -268,7 +269,7 @@ impl ServiceWorkerGlobalScope {
// TODO XXXcreativcoder This will eventually use a FetchEvent interface to fire event
// when we have the Request and Response dom api's implemented
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/index.html#fetch-event-section
self.upcast::<EventTarget>().fire_simple_event("fetch");
self.upcast::<EventTarget>().fire_event(Atom::from("fetch"));
let _ = mediator.response_chan.send(None);
}
}

View file

@ -0,0 +1,53 @@
/* 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 bluetooth_traits::BluetoothMethodMsg;
use dom::bindings::codegen::Bindings::TestRunnerBinding;
use dom::bindings::codegen::Bindings::TestRunnerBinding::TestRunnerMethods;
use dom::bindings::error::{Error, ErrorResult};
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use ipc_channel::ipc::{self, IpcSender};
// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner
#[dom_struct]
pub struct TestRunner {
reflector_: Reflector,
}
impl TestRunner {
pub fn new_inherited() -> TestRunner {
TestRunner {
reflector_: Reflector::new(),
}
}
pub fn new(global: &GlobalScope) -> Root<TestRunner> {
reflect_dom_object(box TestRunner::new_inherited(),
global,
TestRunnerBinding::Wrap)
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
self.global().as_window().bluetooth_thread()
}
}
impl TestRunnerMethods for TestRunner {
// https://webbluetoothcg.github.io/web-bluetooth/tests#setBluetoothMockDataSet
fn SetBluetoothMockDataSet(&self, dataSetName: DOMString) -> ErrorResult {
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(BluetoothMethodMsg::Test(String::from(dataSetName), sender)).unwrap();
match receiver.recv().unwrap().into() {
Ok(()) => {
Ok(())
},
Err(error) => {
Err(Error::from(error))
},
}
}
}

View file

@ -0,0 +1,16 @@
/* 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/. */
// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner
// callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events);
[Pref="dom.bluetooth.testing.enabled", Exposed=Window]
interface TestRunner {
[Throws]
void setBluetoothMockDataSet(DOMString dataSetName);
// void setBluetoothManualChooser();
// void getBluetoothManualChooserEvents(BluetoothManualChooserEventsCallback callback);
// void sendBluetoothManualChooserEvent(DOMString event, DOMString argument);
};

View file

@ -185,3 +185,10 @@ Window implements WindowLocalStorage;
// http://w3c.github.io/animation-timing/#framerequestcallback
callback FrameRequestCallback = void (DOMHighResTimeStamp time);
// https://webbluetoothcg.github.io/web-bluetooth/tests#test-interfaces
partial interface Window {
[Pref="dom.bluetooth.testing.enabled", Exposed=Window]
readonly attribute TestRunner testRunner;
//readonly attribute EventSender eventSender;
};

View file

@ -498,7 +498,7 @@ impl Runnable for ConnectionEstablishedTask {
}
// Step 6.
ws.upcast().fire_simple_event("open");
ws.upcast().fire_event(atom!("open"));
}
}
@ -548,7 +548,7 @@ impl Runnable for CloseTask {
// Step 2.
if self.failed {
ws.upcast().fire_simple_event("error");
ws.upcast().fire_event(atom!("error"));
}
// Step 3.

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use app_units::Au;
use bluetooth_traits::BluetoothMethodMsg;
use cssparser::Parser;
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
use dom::bindings::callback::ExceptionHandling;
@ -44,6 +45,7 @@ use dom::performance::Performance;
use dom::promise::Promise;
use dom::screen::Screen;
use dom::storage::Storage;
use dom::testrunner::TestRunner;
use euclid::{Point2D, Rect, Size2D};
use fetch;
use ipc_channel::ipc::{self, IpcSender};
@ -51,9 +53,8 @@ use js::jsapi::{HandleObject, HandleValue, JSAutoCompartment, JSContext};
use js::jsapi::{JS_GC, JS_GetRuntime, SetWindowProxy};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
use msg::constellation_msg::{FrameType, PipelineId, ReferrerPolicy};
use net_traits::ResourceThreads;
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use msg::constellation_msg::{FrameType, PipelineId};
use net_traits::{ResourceThreads, ReferrerPolicy};
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::storage_thread::StorageType;
use num_traits::ToPrimitive;
@ -239,6 +240,8 @@ pub struct Window {
/// All the MediaQueryLists we need to update
media_query_lists: WeakMediaQueryListVec,
test_runner: MutNullableHeap<JS<TestRunner>>,
}
impl Window {
@ -881,6 +884,10 @@ impl WindowMethods for Window {
fn Fetch(&self, input: RequestOrUSVString, init: &RequestInit) -> Rc<Promise> {
fetch::Fetch(&self.upcast(), input, init)
}
fn TestRunner(&self) -> Root<TestRunner> {
self.test_runner.or_init(|| TestRunner::new(self.upcast()))
}
}
impl Window {
@ -1588,6 +1595,7 @@ impl Window {
error_reporter: error_reporter,
scroll_offsets: DOMRefCell::new(HashMap::new()),
media_query_lists: WeakMediaQueryListVec::new(),
test_runner: Default::default(),
};
WindowBinding::Wrap(runtime.cx(), win)

View file

@ -138,7 +138,7 @@ impl Worker {
pub fn dispatch_simple_error(address: TrustedWorkerAddress) {
let worker = address.root();
worker.upcast().fire_simple_event("error");
worker.upcast().fire_event(atom!("error"));
}
#[allow(unsafe_code)]

View file

@ -48,9 +48,9 @@ use ipc_channel::router::ROUTER;
use js::jsapi::{JSContext, JS_ParseJSON};
use js::jsapi::JS_ClearPendingException;
use js::jsval::{JSVal, NullValue, UndefinedValue};
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, FetchMetadata, FilteredMetadata};
use net_traits::{FetchResponseListener, LoadOrigin, NetworkError};
use net_traits::{FetchResponseListener, LoadOrigin, NetworkError, ReferrerPolicy};
use net_traits::CoreResourceMsg::Fetch;
use net_traits::request::{CredentialsMode, Destination, RequestInit, RequestMode};
use net_traits::trim_http_whitespace;