mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement trait-based ResourceThreads and clean up related naming issues
Changes include: - Introduce an IpcSend trait to abstract over a collection of IpcSenders - Implement ResourceThreads collection to abstract the resource-related sub threads across the component - Rename original ResourceThread and ControlMsg into an unifed CoreResource__ to accommodate above changes and avoid confusions
This commit is contained in:
parent
051a749e0d
commit
a51db4cfa8
22 changed files with 213 additions and 179 deletions
|
@ -19,7 +19,7 @@ use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment};
|
|||
use js::jsapi::{JSContext, JSObject, JS_GetClass, MutableHandleValue};
|
||||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||
use msg::constellation_msg::{PanicMsg, PipelineId};
|
||||
use net_traits::ResourceThread;
|
||||
use net_traits::CoreResourceThread;
|
||||
use profile_traits::{mem, time};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
use script_thread::{MainThreadScriptChan, ScriptThread};
|
||||
|
@ -114,8 +114,8 @@ impl<'a> GlobalRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the `ResourceThread` for this global scope.
|
||||
pub fn resource_thread(&self) -> ResourceThread {
|
||||
/// Get the `CoreResourceThread` for this global scope.
|
||||
pub fn core_resource_thread(&self) -> CoreResourceThread {
|
||||
match *self {
|
||||
GlobalRef::Window(ref window) => {
|
||||
let doc = window.Document();
|
||||
|
@ -123,7 +123,7 @@ impl<'a> GlobalRef<'a> {
|
|||
let loader = doc.loader();
|
||||
(*loader.resource_thread).clone()
|
||||
}
|
||||
GlobalRef::Worker(ref worker) => worker.resource_thread().clone(),
|
||||
GlobalRef::Worker(ref worker) => worker.core_resource_thread().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
|
||||
let (url, source) = match load_whole_resource(LoadContext::Script,
|
||||
&init.resource_thread,
|
||||
&init.core_resource_thread,
|
||||
worker_url,
|
||||
None) {
|
||||
Err(_) => {
|
||||
|
|
|
@ -96,11 +96,11 @@ use layout_interface::{LayoutChan, Msg, ReflowQueryType};
|
|||
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy, SubpageId};
|
||||
use net_traits::ControlMsg::{GetCookiesForUrl, SetCookiesForUrl};
|
||||
use net_traits::CookieSource::NonHTTP;
|
||||
use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl};
|
||||
use net_traits::response::HttpsState;
|
||||
use net_traits::{AsyncResponseTarget, PendingAsyncLoad};
|
||||
use num_traits::ToPrimitive;
|
||||
use net_traits::{AsyncResponseTarget, PendingAsyncLoad, IpcSend};
|
||||
use num_traits::{ToPrimitive};
|
||||
use origin::Origin;
|
||||
use parse::{ParserRoot, ParserRef, MutNullableParserField};
|
||||
use script_thread::{MainThreadScriptMsg, Runnable};
|
||||
|
@ -2570,7 +2570,7 @@ impl DocumentMethods for Document {
|
|||
|
||||
let url = self.url();
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
let _ = self.window.resource_thread().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
||||
let _ = self.window.resource_threads().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
||||
let cookies = rx.recv().unwrap();
|
||||
Ok(cookies.map_or(DOMString::new(), DOMString::from))
|
||||
}
|
||||
|
@ -2587,7 +2587,7 @@ impl DocumentMethods for Document {
|
|||
|
||||
let url = self.url();
|
||||
let _ = self.window
|
||||
.resource_thread()
|
||||
.resource_threads()
|
||||
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP));
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
|
|||
use dom::storageevent::StorageEvent;
|
||||
use dom::urlhelper::UrlHelper;
|
||||
use ipc_channel::ipc;
|
||||
use net_traits::IpcSend;
|
||||
use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
|
||||
use script_thread::{MainThreadRunnable, ScriptThread};
|
||||
use task_source::dom_manipulation::DOMManipulationTask;
|
||||
|
@ -48,7 +49,7 @@ impl Storage {
|
|||
fn get_storage_thread(&self) -> StorageThread {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().storage_thread()
|
||||
global_ref.as_window().resource_threads().sender()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ use js::jsapi::{JSAutoCompartment, RootedValue};
|
|||
use js::jsapi::{JS_GetArrayBufferData, JS_NewArrayBuffer};
|
||||
use js::jsval::UndefinedValue;
|
||||
use libc::{uint32_t, uint8_t};
|
||||
use net_traits::ControlMsg::{WebsocketConnect, SetCookiesForUrl};
|
||||
use net_traits::CookieSource::HTTP;
|
||||
use net_traits::CoreResourceMsg::{WebsocketConnect, SetCookiesForUrl};
|
||||
use net_traits::MessageData;
|
||||
use net_traits::hosts::replace_hosts;
|
||||
use net_traits::unwrap_websocket_protocol;
|
||||
|
@ -265,8 +265,7 @@ impl WebSocket {
|
|||
action_receiver: resource_action_receiver,
|
||||
};
|
||||
|
||||
let resource_thread = global.resource_thread();
|
||||
let _ = resource_thread.send(WebsocketConnect(connect, connect_data));
|
||||
let _ = global.core_resource_thread().send(WebsocketConnect(connect, connect_data));
|
||||
|
||||
*ws.sender.borrow_mut() = Some(dom_action_sender);
|
||||
|
||||
|
@ -493,7 +492,7 @@ impl Runnable for ConnectionEstablishedTask {
|
|||
if let Some(cookies) = self.headers.get_raw("set-cookie") {
|
||||
for cookie in cookies.iter() {
|
||||
if let Ok(cookie_value) = String::from_utf8(cookie.clone()) {
|
||||
let _ = ws.global().r().resource_thread().send(SetCookiesForUrl(ws.url.clone(),
|
||||
let _ = ws.global().r().core_resource_thread().send(SetCookiesForUrl(ws.url.clone(),
|
||||
cookie_value,
|
||||
HTTP));
|
||||
}
|
||||
|
|
|
@ -45,10 +45,10 @@ use libc;
|
|||
use msg::constellation_msg::{LoadData, PanicMsg, PipelineId, SubpageId};
|
||||
use msg::constellation_msg::{WindowSizeData, WindowSizeType};
|
||||
use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||
use net_traits::ResourceThread;
|
||||
use net_traits::ResourceThreads;
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
|
||||
use net_traits::storage_thread::{StorageThread, StorageType};
|
||||
use net_traits::storage_thread::StorageType;
|
||||
use num_traits::ToPrimitive;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time::{ProfilerCategory, TimerMetadata, TimerMetadataFrameType};
|
||||
|
@ -214,18 +214,14 @@ pub struct Window {
|
|||
/// The current size of the window, in pixels.
|
||||
window_size: Cell<Option<WindowSizeData>>,
|
||||
|
||||
/// Associated resource thread for use by DOM objects like XMLHttpRequest
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
resource_thread: Arc<ResourceThread>,
|
||||
/// Associated resource threads for use by DOM objects like XMLHttpRequest,
|
||||
/// including resource_thread, filemanager_thread and storage_thread
|
||||
resource_threads: ResourceThreads,
|
||||
|
||||
/// A handle for communicating messages to the bluetooth thread.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||
|
||||
/// A handle for communicating messages to the storage thread.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
storage_thread: StorageThread,
|
||||
|
||||
/// A handle for communicating messages to the constellation thread.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
constellation_chan: IpcSender<ConstellationMsg>,
|
||||
|
@ -347,10 +343,6 @@ impl Window {
|
|||
self.bluetooth_thread.clone()
|
||||
}
|
||||
|
||||
pub fn storage_thread(&self) -> StorageThread {
|
||||
self.storage_thread.clone()
|
||||
}
|
||||
|
||||
pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
|
||||
self.error_reporter.clone()
|
||||
}
|
||||
|
@ -1276,8 +1268,8 @@ impl Window {
|
|||
(*self.Document().url()).clone()
|
||||
}
|
||||
|
||||
pub fn resource_thread(&self) -> ResourceThread {
|
||||
(*self.resource_thread).clone()
|
||||
pub fn resource_threads(&self) -> &ResourceThreads {
|
||||
&self.resource_threads
|
||||
}
|
||||
|
||||
pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
|
||||
|
@ -1453,9 +1445,8 @@ impl Window {
|
|||
image_cache_chan: ImageCacheChan,
|
||||
compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
image_cache_thread: ImageCacheThread,
|
||||
resource_thread: Arc<ResourceThread>,
|
||||
resource_threads: ResourceThreads,
|
||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||
storage_thread: StorageThread,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
time_profiler_chan: ProfilerChan,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
|
@ -1511,9 +1502,8 @@ impl Window {
|
|||
parent_info: parent_info,
|
||||
dom_static: GlobalStaticData::new(),
|
||||
js_runtime: DOMRefCell::new(Some(runtime.clone())),
|
||||
resource_thread: resource_thread,
|
||||
resource_threads: resource_threads,
|
||||
bluetooth_thread: bluetooth_thread,
|
||||
storage_thread: storage_thread,
|
||||
constellation_chan: constellation_chan,
|
||||
page_clip_rect: Cell::new(MAX_RECT),
|
||||
fragment_name: DOMRefCell::new(None),
|
||||
|
@ -1605,3 +1595,5 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue
|
|||
|
||||
println!("{}", debug_msg);
|
||||
}
|
||||
|
||||
no_jsmanaged_fields!(ResourceThreads);
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Worker {
|
|||
Err(_) => return Err(Error::Syntax),
|
||||
};
|
||||
|
||||
let resource_thread = global.resource_thread();
|
||||
let core_resource_thread = global.core_resource_thread();
|
||||
let constellation_chan = global.constellation_chan().clone();
|
||||
let scheduler_chan = global.scheduler_chan().clone();
|
||||
|
||||
|
@ -100,7 +100,7 @@ impl Worker {
|
|||
};
|
||||
|
||||
let init = WorkerGlobalScopeInit {
|
||||
resource_thread: resource_thread,
|
||||
core_resource_thread: core_resource_thread,
|
||||
mem_profiler_chan: global.mem_profiler_chan().clone(),
|
||||
time_profiler_chan: global.time_profiler_chan().clone(),
|
||||
to_devtools_sender: global.devtools_chan(),
|
||||
|
|
|
@ -22,7 +22,7 @@ use js::jsapi::{HandleValue, JSContext, JSRuntime, RootedValue};
|
|||
use js::jsval::UndefinedValue;
|
||||
use js::rust::Runtime;
|
||||
use msg::constellation_msg::{PanicMsg, PipelineId};
|
||||
use net_traits::{LoadContext, ResourceThread, load_whole_resource};
|
||||
use net_traits::{LoadContext, CoreResourceThread, load_whole_resource};
|
||||
use profile_traits::{mem, time};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
use script_traits::ScriptMsg as ConstellationMsg;
|
||||
|
@ -43,7 +43,7 @@ pub enum WorkerGlobalScopeTypeId {
|
|||
}
|
||||
|
||||
pub struct WorkerGlobalScopeInit {
|
||||
pub resource_thread: ResourceThread,
|
||||
pub core_resource_thread: CoreResourceThread,
|
||||
pub mem_profiler_chan: mem::ProfilerChan,
|
||||
pub time_profiler_chan: time::ProfilerChan,
|
||||
pub to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
|
@ -66,7 +66,7 @@ pub struct WorkerGlobalScope {
|
|||
runtime: Runtime,
|
||||
next_worker_id: Cell<WorkerId>,
|
||||
#[ignore_heap_size_of = "Defined in std"]
|
||||
resource_thread: ResourceThread,
|
||||
core_resource_thread: CoreResourceThread,
|
||||
location: MutNullableHeap<JS<WorkerLocation>>,
|
||||
navigator: MutNullableHeap<JS<WorkerNavigator>>,
|
||||
console: MutNullableHeap<JS<Console>>,
|
||||
|
@ -118,7 +118,7 @@ impl WorkerGlobalScope {
|
|||
worker_url: worker_url,
|
||||
closing: init.closing,
|
||||
runtime: runtime,
|
||||
resource_thread: init.resource_thread,
|
||||
core_resource_thread: init.core_resource_thread,
|
||||
location: Default::default(),
|
||||
navigator: Default::default(),
|
||||
console: Default::default(),
|
||||
|
@ -186,8 +186,8 @@ impl WorkerGlobalScope {
|
|||
self.closing.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn resource_thread(&self) -> &ResourceThread {
|
||||
&self.resource_thread
|
||||
pub fn core_resource_thread(&self) -> &CoreResourceThread {
|
||||
&self.core_resource_thread
|
||||
}
|
||||
|
||||
pub fn get_url(&self) -> &Url {
|
||||
|
@ -236,7 +236,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
|
||||
let mut rval = RootedValue::new(self.runtime.cx(), UndefinedValue());
|
||||
for url in urls {
|
||||
let (url, source) = match load_whole_resource(LoadContext::Script, &self.resource_thread, url, None) {
|
||||
let (url, source) = match load_whole_resource(LoadContext::Script, &self.core_resource_thread, url, None) {
|
||||
Err(_) => return Err(Error::Network),
|
||||
Ok((metadata, bytes)) => {
|
||||
(metadata.final_url, String::from_utf8(bytes).unwrap())
|
||||
|
|
|
@ -44,9 +44,9 @@ use ipc_channel::router::ROUTER;
|
|||
use js::jsapi::JS_ClearPendingException;
|
||||
use js::jsapi::{JSContext, JS_ParseJSON, RootedValue};
|
||||
use js::jsval::{JSVal, NullValue, UndefinedValue};
|
||||
use net_traits::ControlMsg::Load;
|
||||
use net_traits::CoreResourceMsg::Load;
|
||||
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError};
|
||||
use net_traits::{LoadConsumer, LoadContext, LoadData, ResourceCORSData, ResourceThread};
|
||||
use net_traits::{LoadConsumer, LoadContext, LoadData, ResourceCORSData, CoreResourceThread};
|
||||
use network_listener::{NetworkListener, PreInvoke};
|
||||
use parse::html::{ParseContext, parse_html};
|
||||
use parse::xml::{self, parse_xml};
|
||||
|
@ -207,13 +207,13 @@ impl XMLHttpRequest {
|
|||
load_data: LoadData,
|
||||
req: CORSRequest,
|
||||
script_chan: Box<ScriptChan + Send>,
|
||||
resource_thread: ResourceThread) {
|
||||
core_resource_thread: CoreResourceThread) {
|
||||
struct CORSContext {
|
||||
xhr: Arc<Mutex<XHRContext>>,
|
||||
load_data: RefCell<Option<LoadData>>,
|
||||
req: CORSRequest,
|
||||
script_chan: Box<ScriptChan + Send>,
|
||||
resource_thread: ResourceThread,
|
||||
core_resource_thread: CoreResourceThread,
|
||||
}
|
||||
|
||||
impl AsyncCORSResponseListener for CORSContext {
|
||||
|
@ -233,7 +233,7 @@ impl XMLHttpRequest {
|
|||
});
|
||||
|
||||
XMLHttpRequest::initiate_async_xhr(self.xhr.clone(), self.script_chan.clone(),
|
||||
self.resource_thread.clone(), load_data);
|
||||
self.core_resource_thread.clone(), load_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ impl XMLHttpRequest {
|
|||
load_data: RefCell::new(Some(load_data)),
|
||||
req: req.clone(),
|
||||
script_chan: script_chan.clone(),
|
||||
resource_thread: resource_thread,
|
||||
core_resource_thread: core_resource_thread,
|
||||
};
|
||||
|
||||
req.http_fetch_async(box cors_context, script_chan);
|
||||
|
@ -250,7 +250,7 @@ impl XMLHttpRequest {
|
|||
|
||||
fn initiate_async_xhr(context: Arc<Mutex<XHRContext>>,
|
||||
script_chan: Box<ScriptChan + Send>,
|
||||
resource_thread: ResourceThread,
|
||||
core_resource_thread: CoreResourceThread,
|
||||
load_data: LoadData) {
|
||||
impl AsyncResponseListener for XHRContext {
|
||||
fn headers_available(&mut self, metadata: Result<Metadata, NetworkError>) {
|
||||
|
@ -291,7 +291,7 @@ impl XMLHttpRequest {
|
|||
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||
listener.notify(message.to().unwrap());
|
||||
});
|
||||
resource_thread.send(Load(load_data, LoadConsumer::Listener(response_target), None)).unwrap();
|
||||
core_resource_thread.send(Load(load_data, LoadConsumer::Listener(response_target), None)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1318,13 +1318,13 @@ impl XMLHttpRequest {
|
|||
(global.networking_task_source(), None)
|
||||
};
|
||||
|
||||
let resource_thread = global.resource_thread();
|
||||
let core_resource_thread = global.core_resource_thread();
|
||||
if let Some(req) = cors_request {
|
||||
XMLHttpRequest::check_cors(context.clone(), load_data, req.clone(),
|
||||
script_chan.clone(), resource_thread);
|
||||
script_chan.clone(), core_resource_thread);
|
||||
} else {
|
||||
XMLHttpRequest::initiate_async_xhr(context.clone(), script_chan,
|
||||
resource_thread, load_data);
|
||||
core_resource_thread, load_data);
|
||||
}
|
||||
|
||||
if let Some(script_port) = script_port {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue