Remove extraneous script_chan parameter from Trusted::new

This commit is contained in:
Keith Yeung 2016-04-26 16:40:40 -04:00 committed by Ms2ger
parent fbc575407d
commit 33acb1937c
15 changed files with 38 additions and 62 deletions

View file

@ -72,7 +72,8 @@ impl<T: Reflectable> Trusted<T> {
/// Create a new `Trusted<T>` instance from an existing DOM pointer. The DOM object will /// 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 /// be prevented from being GCed for the duration of the resulting `Trusted<T>` object's
/// lifetime. /// 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| { LIVE_REFERENCES.with(|ref r| {
let r = r.borrow(); let r = r.borrow();
let live_references = r.as_ref().unwrap(); let live_references = r.as_ref().unwrap();

View file

@ -100,7 +100,7 @@ use num_traits::ToPrimitive;
use origin::Origin; use origin::Origin;
use parse::{ParserRoot, ParserRef, MutNullableParserField}; use parse::{ParserRoot, ParserRef, MutNullableParserField};
use script_runtime::ScriptChan; use script_runtime::ScriptChan;
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, Runnable}; use script_thread::{MainThreadScriptMsg, Runnable};
use script_traits::UntrustedNodeAddress; use script_traits::UntrustedNodeAddress;
use script_traits::{AnimationState, MouseButton, MouseEventType, MozBrowserEvent}; use script_traits::{AnimationState, MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{ScriptMsg as ConstellationMsg, ScriptToCompositorMsg}; use script_traits::{ScriptMsg as ConstellationMsg, ScriptToCompositorMsg};
@ -1460,8 +1460,7 @@ impl Document {
update_with_current_time_ms(&self.dom_content_loaded_event_start); 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>());
let doctarget = Trusted::new(self.upcast::<EventTarget>(), chan);
let task_source = self.window().dom_manipulation_task_source(); let task_source = self.window().dom_manipulation_task_source();
let _ = task_source.queue(DOMManipulationTask::FireEvent( let _ = task_source.queue(DOMManipulationTask::FireEvent(
atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable)); atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable));

View file

@ -333,8 +333,6 @@ impl FileReader {
} }
fn read(&self, function: FileReaderFunction, blob: &Blob, label: Option<DOMString>) -> ErrorResult { fn read(&self, function: FileReaderFunction, blob: &Blob, label: Option<DOMString>) -> ErrorResult {
let root = self.global();
let global = root.r();
// Step 1 // Step 1
if self.ready_state.get() == FileReaderReadyState::Loading { if self.ready_state.get() == FileReaderReadyState::Loading {
return Err(Error::InvalidState); return Err(Error::InvalidState);
@ -359,10 +357,10 @@ impl FileReader {
let load_data = ReadMetaData::new(String::from(type_), label.map(String::from), function); 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 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 || { spawn_named("file reader async operation".to_owned(), move || {
perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, script_chan) perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, script_chan)

View file

@ -14,8 +14,7 @@ use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement; use dom::htmlelement::HTMLElement;
use dom::node::{Node, window_from_node}; use dom::node::{Node, window_from_node};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use script_runtime::ScriptChan; use script_thread::Runnable;
use script_thread::{MainThreadScriptChan, Runnable};
use std::cell::Cell; use std::cell::Cell;
use string_cache::Atom; use string_cache::Atom;
use task_source::dom_manipulation::DOMManipulationTask; use task_source::dom_manipulation::DOMManipulationTask;
@ -74,8 +73,7 @@ impl VirtualMethods for HTMLDetailsElement {
let window = window_from_node(self); let window = window_from_node(self);
let window = window.r(); let window = window.r();
let task_source = window.dom_manipulation_task_source(); let task_source = window.dom_manipulation_task_source();
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone(); let details = Trusted::new(self);
let details = Trusted::new(self, chan.clone());
let runnable = box ToggleEventRunnable { let runnable = box ToggleEventRunnable {
element: details, element: details,
toggle_number: counter toggle_number: counter

View file

@ -38,7 +38,7 @@ use hyper::method::Method;
use hyper::mime; use hyper::mime;
use msg::constellation_msg::{LoadData, PipelineId}; use msg::constellation_msg::{LoadData, PipelineId};
use script_runtime::ScriptChan; use script_runtime::ScriptChan;
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, Runnable}; use script_thread::{MainThreadScriptMsg, Runnable};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
@ -331,13 +331,12 @@ impl HTMLFormElement {
self.generation_id.set(GenerationId(prev_id + 1)); self.generation_id.set(GenerationId(prev_id + 1));
// Step 2 // Step 2
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
let nav = box PlannedNavigation { let nav = box PlannedNavigation {
load_data: load_data, load_data: load_data,
pipeline_id: window.pipeline(), pipeline_id: window.pipeline(),
script_chan: window.main_thread_script_chan().clone(), script_chan: window.main_thread_script_chan().clone(),
generation_id: self.generation_id.get(), generation_id: self.generation_id.get(),
form: Trusted::new(self, chan) form: Trusted::new(self)
}; };
// Step 3 // Step 3

View file

@ -128,7 +128,7 @@ impl HTMLImageElement {
let img_url = img_url.unwrap(); let img_url = img_url.unwrap();
self.current_request.borrow_mut().url = Some(img_url.clone()); 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 (responder_sender, responder_receiver) = ipc::channel().unwrap();
let script_chan = window.networking_task_source(); let script_chan = window.networking_task_source();
let wrapper = window.get_runnable_wrapper(); let wrapper = window.get_runnable_wrapper();

View file

@ -1122,13 +1122,11 @@ pub struct ChangeEventRunnable {
impl ChangeEventRunnable { impl ChangeEventRunnable {
pub fn send(node: &Node) { pub fn send(node: &Node) {
let window = window_from_node(node); let handler = Trusted::new(node);
let window = window.r();
let chan = window.user_interaction_task_source();
let handler = Trusted::new(node, chan.clone());
let dispatcher = ChangeEventRunnable { let dispatcher = ChangeEventRunnable {
element: handler, element: handler,
}; };
let chan = window_from_node(node).user_interaction_task_source();
let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher)); let _ = chan.send(CommonScriptMsg::RunnableMsg(InputEvent, box dispatcher));
} }
} }

View file

@ -204,8 +204,7 @@ impl HTMLLinkElement {
let media = parse_media_query_list(&mut css_parser); let media = parse_media_query_list(&mut css_parser);
// TODO: #8085 - Don't load external stylesheets if the node's mq doesn't match. // 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);
let elem = Trusted::new(self, script_chan.clone());
let context = Arc::new(Mutex::new(StylesheetContext { let context = Arc::new(Mutex::new(StylesheetContext {
elem: elem, elem: elem,
@ -218,7 +217,7 @@ impl HTMLLinkElement {
let (action_sender, action_receiver) = ipc::channel().unwrap(); let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener { let listener = NetworkListener {
context: context, context: context,
script_chan: script_chan, script_chan: document.window().networking_task_source(),
}; };
let response_target = AsyncResponseTarget { let response_target = AsyncResponseTarget {
sender: action_sender, sender: action_sender,

View file

@ -36,7 +36,6 @@ use js::jsval::UndefinedValue;
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError}; use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError};
use network_listener::{NetworkListener, PreInvoke}; use network_listener::{NetworkListener, PreInvoke};
use script_runtime::ScriptChan; use script_runtime::ScriptChan;
use script_thread::MainThreadScriptChan;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::cell::Cell; use std::cell::Cell;
use std::mem; use std::mem;
@ -299,8 +298,7 @@ impl HTMLScriptElement {
// Step 16.6. // Step 16.6.
// TODO(#9186): use the fetch infrastructure. // TODO(#9186): use the fetch infrastructure.
let script_chan = doc.window().networking_task_source(); let elem = Trusted::new(self);
let elem = Trusted::new(self, script_chan.clone());
let context = Arc::new(Mutex::new(ScriptContext { let context = Arc::new(Mutex::new(ScriptContext {
elem: elem, elem: elem,
@ -313,7 +311,7 @@ impl HTMLScriptElement {
let (action_sender, action_receiver) = ipc::channel().unwrap(); let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener { let listener = NetworkListener {
context: context, context: context,
script_chan: script_chan, script_chan: doc.window().networking_task_source(),
}; };
let response_target = AsyncResponseTarget { let response_target = AsyncResponseTarget {
sender: action_sender, sender: action_sender,
@ -465,19 +463,15 @@ impl HTMLScriptElement {
if external { if external {
self.dispatch_load_event(); self.dispatch_load_event();
} else { } else {
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone(); let script_element = Trusted::new(self.upcast::<EventTarget>());
let script_element = Trusted::new(self.upcast::<EventTarget>(), chan);
let task_source = window.dom_manipulation_task_source(); let task_source = window.dom_manipulation_task_source();
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap(); task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap();
} }
} }
pub fn queue_error_event(&self) { pub fn queue_error_event(&self) {
let window = window_from_node(self); let task_source = window_from_node(self).dom_manipulation_task_source();
let window = window.r(); let script_element = Trusted::new(self.upcast::<EventTarget>());
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);
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap(); task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap();
} }

View file

@ -62,21 +62,17 @@ pub struct ParserContext {
id: PipelineId, id: PipelineId,
/// The subpage associated with this document. /// The subpage associated with this document.
subpage: Option<SubpageId>, subpage: Option<SubpageId>,
/// The target event loop for the response notifications.
script_chan: Box<ScriptChan + Send>,
/// The URL for this document. /// The URL for this document.
url: Url, url: Url,
} }
impl ParserContext { impl ParserContext {
pub fn new(id: PipelineId, subpage: Option<SubpageId>, script_chan: Box<ScriptChan + Send>, pub fn new(id: PipelineId, subpage: Option<SubpageId>, url: Url) -> ParserContext {
url: Url) -> ParserContext {
ParserContext { ParserContext {
parser: None, parser: None,
is_synthesized_document: false, is_synthesized_document: false,
id: id, id: id,
subpage: subpage, subpage: subpage,
script_chan: script_chan,
url: url, url: url,
} }
} }
@ -107,11 +103,9 @@ impl AsyncResponseListener for ParserContext {
let parser = parser.r(); let parser = parser.r();
self.parser = Some(match parser { self.parser = Some(match parser {
ParserRef::HTML(parser) => TrustedParser::HTML( ParserRef::HTML(parser) => TrustedParser::HTML(
Trusted::new(parser, Trusted::new(parser)),
self.script_chan.clone())),
ParserRef::XML(parser) => TrustedParser::XML( ParserRef::XML(parser) => TrustedParser::XML(
Trusted::new(parser, Trusted::new(parser)),
self.script_chan.clone())),
}); });
match content_type { match content_type {

View file

@ -17,7 +17,7 @@ use ipc_channel::ipc;
use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType}; use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
use page::IterablePage; use page::IterablePage;
use script_runtime::ScriptChan; use script_runtime::ScriptChan;
use script_thread::{MainThreadRunnable, MainThreadScriptChan, ScriptThread}; use script_thread::{MainThreadRunnable, ScriptThread};
use task_source::dom_manipulation::DOMManipulationTask; use task_source::dom_manipulation::DOMManipulationTask;
use url::Url; use url::Url;
use util::str::DOMString; use util::str::DOMString;
@ -160,8 +160,7 @@ impl Storage {
let global_root = self.global(); let global_root = self.global();
let global_ref = global_root.r(); let global_ref = global_root.r();
let task_source = global_ref.as_window().dom_manipulation_task_source(); 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);
let trusted_storage = Trusted::new(self, chan);
task_source.queue(DOMManipulationTask::SendStorageNotification( task_source.queue(DOMManipulationTask::SendStorageNotification(
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap(); box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
} }

View file

@ -245,7 +245,7 @@ impl WebSocket {
// Step 7. // Step 7.
let ws = WebSocket::new(global, resource_url.clone()); 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 { let connect_data = WebSocketConnectData {
resource_url: resource_url.clone(), resource_url: resource_url.clone(),
@ -314,9 +314,7 @@ impl WebSocket {
WebSocketRequestState::Closing | WebSocketRequestState::Closed => true, WebSocketRequestState::Closing | WebSocketRequestState::Closed => true,
}; };
let global = self.global(); let address = Trusted::new(self);
let chan = global.r().networking_task_source();
let address = Trusted::new(self, chan.clone());
match data_byte_len.checked_add(self.buffered_amount.get()) { match data_byte_len.checked_add(self.buffered_amount.get()) {
None => panic!(), None => panic!(),
@ -334,7 +332,8 @@ impl WebSocket {
address: address, 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) Ok(true)
@ -440,9 +439,8 @@ impl WebSocketMethods for WebSocket {
will abort connecting the websocket*/ will abort connecting the websocket*/
self.ready_state.set(WebSocketRequestState::Closing); self.ready_state.set(WebSocketRequestState::Closing);
let global = self.global(); let address = Trusted::new(self);
let sender = global.r().networking_task_source(); let sender = self.global().r().networking_task_source();
let address = Trusted::new(self, sender.clone());
fail_the_websocket_connection(address, sender); fail_the_websocket_connection(address, sender);
} }
WebSocketRequestState::Open => { WebSocketRequestState::Open => {

View file

@ -81,7 +81,7 @@ impl Worker {
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let closing = Arc::new(AtomicBool::new(false)); let closing = Arc::new(AtomicBool::new(false));
let worker = Worker::new(global, sender.clone(), closing.clone()); 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 worker_id = global.get_next_worker_id();
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); 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 // https://html.spec.whatwg.org/multipage/#dom-worker-postmessage
fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult { fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = try!(StructuredCloneData::write(cx, message)); 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(); self.sender.send((address, WorkerScriptMsg::DOMMessage(data))).unwrap();
Ok(()) Ok(())
} }

View file

@ -1079,11 +1079,11 @@ impl XMLHttpRequest {
fn set_timeout(&self, duration_ms: u32) { fn set_timeout(&self, duration_ms: u32) {
// Sets up the object to timeout in a given number of milliseconds // Sets up the object to timeout in a given number of milliseconds
// This will cancel all previous timeouts // This will cancel all previous timeouts
let global = self.global();
let callback = OneshotTimerCallback::XhrTimeout(XHRTimeoutCallback { let callback = OneshotTimerCallback::XhrTimeout(XHRTimeoutCallback {
xhr: Trusted::new(self, global.r().networking_task_source()), xhr: Trusted::new(self),
generation_id: self.generation_id.get(), generation_id: self.generation_id.get(),
}); });
let global = self.global();
let duration = Length::new(duration_ms as u64); let duration = Length::new(duration_ms as u64);
*self.timeout_cancel.borrow_mut() = Some(global.r().schedule_callback(callback, duration)); *self.timeout_cancel.borrow_mut() = Some(global.r().schedule_callback(callback, duration));
} }
@ -1300,7 +1300,7 @@ impl XMLHttpRequest {
Ok(req) => req, Ok(req) => req,
}; };
let xhr = Trusted::new(self, global.networking_task_source()); let xhr = Trusted::new(self);
let context = Arc::new(Mutex::new(XHRContext { let context = Arc::new(Mutex::new(XHRContext {
xhr: xhr, xhr: xhr,

View file

@ -1118,7 +1118,7 @@ impl ScriptThread {
doc.mut_loader().inhibit_events(); doc.mut_loader().inhibit_events();
// https://html.spec.whatwg.org/multipage/#the-end step 7 // 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()); let handler = box DocumentProgressHandler::new(addr.clone());
self.dom_manipulation_task_source.queue(DOMManipulationTask::DocumentProgress(handler)).unwrap(); self.dom_manipulation_task_source.queue(DOMManipulationTask::DocumentProgress(handler)).unwrap();
@ -1866,8 +1866,7 @@ impl ScriptThread {
let script_chan = self.chan.clone(); let script_chan = self.chan.clone();
let resource_thread = self.resource_thread.clone(); let resource_thread = self.resource_thread.clone();
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, script_chan.clone(), let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, load_data.url.clone())));
load_data.url.clone())));
let (action_sender, action_receiver) = ipc::channel().unwrap(); let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener { let listener = NetworkListener {
context: context, context: context,