aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorZhen Zhang <izgzhen@gmail.com>2016-05-18 00:07:42 +0800
committerZhen Zhang <izgzhen@gmail.com>2016-05-20 08:00:16 +0800
commita51db4cfa857d7567ce1078830f5c00ea7bd9f59 (patch)
tree9a604ff41983c9bded331f4ec80f94c9f6b1cd45 /components/script/dom
parent051a749e0d0ff298a3cbce8c6284386dc0d67f24 (diff)
downloadservo-a51db4cfa857d7567ce1078830f5c00ea7bd9f59.tar.gz
servo-a51db4cfa857d7567ce1078830f5c00ea7bd9f59.zip
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
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/global.rs8
-rw-r--r--components/script/dom/dedicatedworkerglobalscope.rs2
-rw-r--r--components/script/dom/document.rs10
-rw-r--r--components/script/dom/storage.rs3
-rw-r--r--components/script/dom/websocket.rs7
-rw-r--r--components/script/dom/window.rs30
-rw-r--r--components/script/dom/worker.rs4
-rw-r--r--components/script/dom/workerglobalscope.rs14
-rw-r--r--components/script/dom/xmlhttprequest.rs22
9 files changed, 46 insertions, 54 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index b48a941af01..61b948dbf35 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -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(),
}
}
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs
index 42b2dad043a..bd5cd63fcfb 100644
--- a/components/script/dom/dedicatedworkerglobalscope.rs
+++ b/components/script/dom/dedicatedworkerglobalscope.rs
@@ -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(_) => {
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index f6000e28a8b..ddf23297282 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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(())
}
diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs
index 9801c701ec7..c3004a1031a 100644
--- a/components/script/dom/storage.rs
+++ b/components/script/dom/storage.rs
@@ -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()
}
}
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs
index 76f311a185d..796fb6a6d5f 100644
--- a/components/script/dom/websocket.rs
+++ b/components/script/dom/websocket.rs
@@ -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));
}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index e665add7928..c9111ad15e5 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -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);
diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs
index 11dca86573d..661d397460f 100644
--- a/components/script/dom/worker.rs
+++ b/components/script/dom/worker.rs
@@ -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(),
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 8b5b2637179..ef9afd34cf7 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -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())
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index e3d14ce6e67..b72d5995b20 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -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 {