mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Remove extraneous script_chan parameter from Trusted::new
This commit is contained in:
parent
fbc575407d
commit
33acb1937c
15 changed files with 38 additions and 62 deletions
|
@ -72,7 +72,8 @@ impl<T: Reflectable> Trusted<T> {
|
|||
/// Create a new `Trusted<T>` instance from an existing DOM pointer. The DOM object will
|
||||
/// be prevented from being GCed for the duration of the resulting `Trusted<T>` object's
|
||||
/// lifetime.
|
||||
pub fn new(ptr: &T, script_chan: Box<ScriptChan + Send>) -> Trusted<T> {
|
||||
pub fn new(ptr: &T) -> Trusted<T> {
|
||||
let script_chan = ptr.global().r().script_chan();
|
||||
LIVE_REFERENCES.with(|ref r| {
|
||||
let r = r.borrow();
|
||||
let live_references = r.as_ref().unwrap();
|
||||
|
|
|
@ -100,7 +100,7 @@ use num_traits::ToPrimitive;
|
|||
use origin::Origin;
|
||||
use parse::{ParserRoot, ParserRef, MutNullableParserField};
|
||||
use script_runtime::ScriptChan;
|
||||
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, Runnable};
|
||||
use script_thread::{MainThreadScriptMsg, Runnable};
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
use script_traits::{AnimationState, MouseButton, MouseEventType, MozBrowserEvent};
|
||||
use script_traits::{ScriptMsg as ConstellationMsg, ScriptToCompositorMsg};
|
||||
|
@ -1460,8 +1460,7 @@ impl Document {
|
|||
|
||||
update_with_current_time_ms(&self.dom_content_loaded_event_start);
|
||||
|
||||
let chan = MainThreadScriptChan(self.window().main_thread_script_chan().clone()).clone();
|
||||
let doctarget = Trusted::new(self.upcast::<EventTarget>(), chan);
|
||||
let doctarget = Trusted::new(self.upcast::<EventTarget>());
|
||||
let task_source = self.window().dom_manipulation_task_source();
|
||||
let _ = task_source.queue(DOMManipulationTask::FireEvent(
|
||||
atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable));
|
||||
|
|
|
@ -333,8 +333,6 @@ impl FileReader {
|
|||
}
|
||||
|
||||
fn read(&self, function: FileReaderFunction, blob: &Blob, label: Option<DOMString>) -> ErrorResult {
|
||||
let root = self.global();
|
||||
let global = root.r();
|
||||
// Step 1
|
||||
if self.ready_state.get() == FileReaderReadyState::Loading {
|
||||
return Err(Error::InvalidState);
|
||||
|
@ -359,10 +357,10 @@ impl FileReader {
|
|||
|
||||
let load_data = ReadMetaData::new(String::from(type_), label.map(String::from), function);
|
||||
|
||||
let fr = Trusted::new(self, global.file_reading_task_source());
|
||||
let fr = Trusted::new(self);
|
||||
let gen_id = self.generation_id.get();
|
||||
|
||||
let script_chan = global.file_reading_task_source();
|
||||
let script_chan = self.global().r().file_reading_task_source();
|
||||
|
||||
spawn_named("file reader async operation".to_owned(), move || {
|
||||
perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, script_chan)
|
||||
|
|
|
@ -14,8 +14,7 @@ use dom::eventtarget::EventTarget;
|
|||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use script_runtime::ScriptChan;
|
||||
use script_thread::{MainThreadScriptChan, Runnable};
|
||||
use script_thread::Runnable;
|
||||
use std::cell::Cell;
|
||||
use string_cache::Atom;
|
||||
use task_source::dom_manipulation::DOMManipulationTask;
|
||||
|
@ -74,8 +73,7 @@ impl VirtualMethods for HTMLDetailsElement {
|
|||
let window = window_from_node(self);
|
||||
let window = window.r();
|
||||
let task_source = window.dom_manipulation_task_source();
|
||||
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
|
||||
let details = Trusted::new(self, chan.clone());
|
||||
let details = Trusted::new(self);
|
||||
let runnable = box ToggleEventRunnable {
|
||||
element: details,
|
||||
toggle_number: counter
|
||||
|
|
|
@ -38,7 +38,7 @@ use hyper::method::Method;
|
|||
use hyper::mime;
|
||||
use msg::constellation_msg::{LoadData, PipelineId};
|
||||
use script_runtime::ScriptChan;
|
||||
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, Runnable};
|
||||
use script_thread::{MainThreadScriptMsg, Runnable};
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::Cell;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
@ -331,13 +331,12 @@ impl HTMLFormElement {
|
|||
self.generation_id.set(GenerationId(prev_id + 1));
|
||||
|
||||
// Step 2
|
||||
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
|
||||
let nav = box PlannedNavigation {
|
||||
load_data: load_data,
|
||||
pipeline_id: window.pipeline(),
|
||||
script_chan: window.main_thread_script_chan().clone(),
|
||||
generation_id: self.generation_id.get(),
|
||||
form: Trusted::new(self, chan)
|
||||
form: Trusted::new(self)
|
||||
};
|
||||
|
||||
// Step 3
|
||||
|
|
|
@ -128,7 +128,7 @@ impl HTMLImageElement {
|
|||
let img_url = img_url.unwrap();
|
||||
self.current_request.borrow_mut().url = Some(img_url.clone());
|
||||
|
||||
let trusted_node = Trusted::new(self, window.networking_task_source());
|
||||
let trusted_node = Trusted::new(self);
|
||||
let (responder_sender, responder_receiver) = ipc::channel().unwrap();
|
||||
let script_chan = window.networking_task_source();
|
||||
let wrapper = window.get_runnable_wrapper();
|
||||
|
|
|
@ -1122,13 +1122,11 @@ pub struct ChangeEventRunnable {
|
|||
|
||||
impl ChangeEventRunnable {
|
||||
pub fn send(node: &Node) {
|
||||
let window = window_from_node(node);
|
||||
let window = window.r();
|
||||
let chan = window.user_interaction_task_source();
|
||||
let handler = Trusted::new(node, chan.clone());
|
||||
let handler = Trusted::new(node);
|
||||
let dispatcher = ChangeEventRunnable {
|
||||
element: handler,
|
||||
};
|
||||
let chan = window_from_node(node).user_interaction_task_source();
|
||||
let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,8 +204,7 @@ impl HTMLLinkElement {
|
|||
let media = parse_media_query_list(&mut css_parser);
|
||||
|
||||
// TODO: #8085 - Don't load external stylesheets if the node's mq doesn't match.
|
||||
let script_chan = document.window().networking_task_source();
|
||||
let elem = Trusted::new(self, script_chan.clone());
|
||||
let elem = Trusted::new(self);
|
||||
|
||||
let context = Arc::new(Mutex::new(StylesheetContext {
|
||||
elem: elem,
|
||||
|
@ -218,7 +217,7 @@ impl HTMLLinkElement {
|
|||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
script_chan: script_chan,
|
||||
script_chan: document.window().networking_task_source(),
|
||||
};
|
||||
let response_target = AsyncResponseTarget {
|
||||
sender: action_sender,
|
||||
|
|
|
@ -36,7 +36,6 @@ use js::jsval::UndefinedValue;
|
|||
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError};
|
||||
use network_listener::{NetworkListener, PreInvoke};
|
||||
use script_runtime::ScriptChan;
|
||||
use script_thread::MainThreadScriptChan;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::cell::Cell;
|
||||
use std::mem;
|
||||
|
@ -299,8 +298,7 @@ impl HTMLScriptElement {
|
|||
|
||||
// Step 16.6.
|
||||
// TODO(#9186): use the fetch infrastructure.
|
||||
let script_chan = doc.window().networking_task_source();
|
||||
let elem = Trusted::new(self, script_chan.clone());
|
||||
let elem = Trusted::new(self);
|
||||
|
||||
let context = Arc::new(Mutex::new(ScriptContext {
|
||||
elem: elem,
|
||||
|
@ -313,7 +311,7 @@ impl HTMLScriptElement {
|
|||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
script_chan: script_chan,
|
||||
script_chan: doc.window().networking_task_source(),
|
||||
};
|
||||
let response_target = AsyncResponseTarget {
|
||||
sender: action_sender,
|
||||
|
@ -465,19 +463,15 @@ impl HTMLScriptElement {
|
|||
if external {
|
||||
self.dispatch_load_event();
|
||||
} else {
|
||||
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
|
||||
let script_element = Trusted::new(self.upcast::<EventTarget>(), chan);
|
||||
let script_element = Trusted::new(self.upcast::<EventTarget>());
|
||||
let task_source = window.dom_manipulation_task_source();
|
||||
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_error_event(&self) {
|
||||
let window = window_from_node(self);
|
||||
let window = window.r();
|
||||
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
|
||||
let task_source = window.dom_manipulation_task_source();
|
||||
let script_element = Trusted::new(self.upcast::<EventTarget>(), chan);
|
||||
let task_source = window_from_node(self).dom_manipulation_task_source();
|
||||
let script_element = Trusted::new(self.upcast::<EventTarget>());
|
||||
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,21 +62,17 @@ pub struct ParserContext {
|
|||
id: PipelineId,
|
||||
/// The subpage associated with this document.
|
||||
subpage: Option<SubpageId>,
|
||||
/// The target event loop for the response notifications.
|
||||
script_chan: Box<ScriptChan + Send>,
|
||||
/// The URL for this document.
|
||||
url: Url,
|
||||
}
|
||||
|
||||
impl ParserContext {
|
||||
pub fn new(id: PipelineId, subpage: Option<SubpageId>, script_chan: Box<ScriptChan + Send>,
|
||||
url: Url) -> ParserContext {
|
||||
pub fn new(id: PipelineId, subpage: Option<SubpageId>, url: Url) -> ParserContext {
|
||||
ParserContext {
|
||||
parser: None,
|
||||
is_synthesized_document: false,
|
||||
id: id,
|
||||
subpage: subpage,
|
||||
script_chan: script_chan,
|
||||
url: url,
|
||||
}
|
||||
}
|
||||
|
@ -107,11 +103,9 @@ impl AsyncResponseListener for ParserContext {
|
|||
let parser = parser.r();
|
||||
self.parser = Some(match parser {
|
||||
ParserRef::HTML(parser) => TrustedParser::HTML(
|
||||
Trusted::new(parser,
|
||||
self.script_chan.clone())),
|
||||
Trusted::new(parser)),
|
||||
ParserRef::XML(parser) => TrustedParser::XML(
|
||||
Trusted::new(parser,
|
||||
self.script_chan.clone())),
|
||||
Trusted::new(parser)),
|
||||
});
|
||||
|
||||
match content_type {
|
||||
|
|
|
@ -17,7 +17,7 @@ use ipc_channel::ipc;
|
|||
use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
|
||||
use page::IterablePage;
|
||||
use script_runtime::ScriptChan;
|
||||
use script_thread::{MainThreadRunnable, MainThreadScriptChan, ScriptThread};
|
||||
use script_thread::{MainThreadRunnable, ScriptThread};
|
||||
use task_source::dom_manipulation::DOMManipulationTask;
|
||||
use url::Url;
|
||||
use util::str::DOMString;
|
||||
|
@ -160,8 +160,7 @@ impl Storage {
|
|||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
let task_source = global_ref.as_window().dom_manipulation_task_source();
|
||||
let chan = MainThreadScriptChan(global_ref.as_window().main_thread_script_chan().clone()).clone();
|
||||
let trusted_storage = Trusted::new(self, chan);
|
||||
let trusted_storage = Trusted::new(self);
|
||||
task_source.queue(DOMManipulationTask::SendStorageNotification(
|
||||
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ impl WebSocket {
|
|||
|
||||
// Step 7.
|
||||
let ws = WebSocket::new(global, resource_url.clone());
|
||||
let address = Trusted::new(ws.r(), global.networking_task_source());
|
||||
let address = Trusted::new(ws.r());
|
||||
|
||||
let connect_data = WebSocketConnectData {
|
||||
resource_url: resource_url.clone(),
|
||||
|
@ -314,9 +314,7 @@ impl WebSocket {
|
|||
WebSocketRequestState::Closing | WebSocketRequestState::Closed => true,
|
||||
};
|
||||
|
||||
let global = self.global();
|
||||
let chan = global.r().networking_task_source();
|
||||
let address = Trusted::new(self, chan.clone());
|
||||
let address = Trusted::new(self);
|
||||
|
||||
match data_byte_len.checked_add(self.buffered_amount.get()) {
|
||||
None => panic!(),
|
||||
|
@ -334,7 +332,8 @@ impl WebSocket {
|
|||
address: address,
|
||||
};
|
||||
|
||||
chan.send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task)).unwrap();
|
||||
let global = self.global();
|
||||
global.r().script_chan().send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task)).unwrap();
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
|
@ -440,9 +439,8 @@ impl WebSocketMethods for WebSocket {
|
|||
will abort connecting the websocket*/
|
||||
self.ready_state.set(WebSocketRequestState::Closing);
|
||||
|
||||
let global = self.global();
|
||||
let sender = global.r().networking_task_source();
|
||||
let address = Trusted::new(self, sender.clone());
|
||||
let address = Trusted::new(self);
|
||||
let sender = self.global().r().networking_task_source();
|
||||
fail_the_websocket_connection(address, sender);
|
||||
}
|
||||
WebSocketRequestState::Open => {
|
||||
|
|
|
@ -81,7 +81,7 @@ impl Worker {
|
|||
let (sender, receiver) = channel();
|
||||
let closing = Arc::new(AtomicBool::new(false));
|
||||
let worker = Worker::new(global, sender.clone(), closing.clone());
|
||||
let worker_ref = Trusted::new(worker.r(), global.script_chan());
|
||||
let worker_ref = Trusted::new(worker.r());
|
||||
let worker_id = global.get_next_worker_id();
|
||||
|
||||
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap();
|
||||
|
@ -166,7 +166,7 @@ impl WorkerMethods for Worker {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-worker-postmessage
|
||||
fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
||||
let data = try!(StructuredCloneData::write(cx, message));
|
||||
let address = Trusted::new(self, self.global().r().script_chan());
|
||||
let address = Trusted::new(self);
|
||||
self.sender.send((address, WorkerScriptMsg::DOMMessage(data))).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1079,11 +1079,11 @@ impl XMLHttpRequest {
|
|||
fn set_timeout(&self, duration_ms: u32) {
|
||||
// Sets up the object to timeout in a given number of milliseconds
|
||||
// This will cancel all previous timeouts
|
||||
let global = self.global();
|
||||
let callback = OneshotTimerCallback::XhrTimeout(XHRTimeoutCallback {
|
||||
xhr: Trusted::new(self, global.r().networking_task_source()),
|
||||
xhr: Trusted::new(self),
|
||||
generation_id: self.generation_id.get(),
|
||||
});
|
||||
let global = self.global();
|
||||
let duration = Length::new(duration_ms as u64);
|
||||
*self.timeout_cancel.borrow_mut() = Some(global.r().schedule_callback(callback, duration));
|
||||
}
|
||||
|
@ -1300,7 +1300,7 @@ impl XMLHttpRequest {
|
|||
Ok(req) => req,
|
||||
};
|
||||
|
||||
let xhr = Trusted::new(self, global.networking_task_source());
|
||||
let xhr = Trusted::new(self);
|
||||
|
||||
let context = Arc::new(Mutex::new(XHRContext {
|
||||
xhr: xhr,
|
||||
|
|
|
@ -1118,7 +1118,7 @@ impl ScriptThread {
|
|||
doc.mut_loader().inhibit_events();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-end step 7
|
||||
let addr: Trusted<Document> = Trusted::new(doc, self.chan.clone());
|
||||
let addr: Trusted<Document> = Trusted::new(doc);
|
||||
let handler = box DocumentProgressHandler::new(addr.clone());
|
||||
self.dom_manipulation_task_source.queue(DOMManipulationTask::DocumentProgress(handler)).unwrap();
|
||||
|
||||
|
@ -1866,8 +1866,7 @@ impl ScriptThread {
|
|||
let script_chan = self.chan.clone();
|
||||
let resource_thread = self.resource_thread.clone();
|
||||
|
||||
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, script_chan.clone(),
|
||||
load_data.url.clone())));
|
||||
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, load_data.url.clone())));
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue