aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-10-03 18:39:03 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-10-06 21:35:46 +0200
commitbad49e46964915afeac3aab4f7de9a9d6c2c55c6 (patch)
treec811eda23275a494a03c3288096a8147486f5bd5 /components
parent86d2008137f48432ba14aed5009775cfd4dadcc5 (diff)
downloadservo-bad49e46964915afeac3aab4f7de9a9d6c2c55c6.tar.gz
servo-bad49e46964915afeac3aab4f7de9a9d6c2c55c6.zip
Introduce GlobalScope::resource_threads
Diffstat (limited to 'components')
-rw-r--r--components/script/dom/bindings/global.rs12
-rw-r--r--components/script/dom/blob.rs6
-rw-r--r--components/script/dom/document.rs6
-rw-r--r--components/script/dom/globalscope.rs14
-rw-r--r--components/script/dom/htmlinputelement.rs2
-rw-r--r--components/script/dom/storage.rs2
-rw-r--r--components/script/dom/url.rs5
-rw-r--r--components/script/dom/window.rs12
-rw-r--r--components/script/dom/workerglobalscope.rs18
-rw-r--r--components/script/webdriver_handlers.rs8
10 files changed, 41 insertions, 44 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index 9ff4ae047da..eac887b8a2f 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -22,7 +22,7 @@ use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
use js::jsapi::{JS_GetClass, MutableHandleValue};
use js::rust::CompileOptionsWrapper;
use libc;
-use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
+use net_traits::{CoreResourceThread, IpcSend};
use profile_traits::time;
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
@@ -68,17 +68,9 @@ impl<'a> GlobalRef<'a> {
}
}
- /// Get the `ResourceThreads` for this global scope.
- pub fn resource_threads(&self) -> ResourceThreads {
- match *self {
- GlobalRef::Window(ref window) => window.resource_threads().clone(),
- GlobalRef::Worker(ref worker) => worker.resource_threads().clone(),
- }
- }
-
/// Get the `CoreResourceThread` for this global scope
pub fn core_resource_thread(&self) -> CoreResourceThread {
- self.resource_threads().sender()
+ self.as_global_scope().resource_threads().sender()
}
/// `ScriptChan` used to send messages to the event loop of this global's
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index fa6600224e8..52248c25845 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -290,8 +290,8 @@ impl Blob {
}
fn send_to_file_manager(&self, msg: FileManagerThreadMsg) {
- let global = self.global();
- let resource_threads = global.r().resource_threads();
+ let global = self.global_scope();
+ let resource_threads = global.resource_threads();
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
}
}
@@ -305,7 +305,7 @@ impl Drop for Blob {
}
fn read_file(global: GlobalRef, id: Uuid) -> Result<Vec<u8>, ()> {
- let resource_threads = global.resource_threads();
+ let resource_threads = global.as_global_scope().resource_threads();
let (chan, recv) = ipc::channel().map_err(|_|())?;
let origin = get_blob_origin(&global.as_global_scope().get_url());
let check_url_validity = false;
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 5a5507b0c20..0fbf4eb9c0c 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -2728,7 +2728,10 @@ impl DocumentMethods for Document {
let url = self.url();
let (tx, rx) = ipc::channel().unwrap();
- let _ = self.window.resource_threads().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
+ let _ = self.window
+ .upcast::<GlobalScope>()
+ .resource_threads()
+ .send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
let cookies = rx.recv().unwrap();
Ok(cookies.map_or(DOMString::new(), DOMString::from))
}
@@ -2745,6 +2748,7 @@ impl DocumentMethods for Document {
let url = self.url();
let _ = self.window
+ .upcast::<GlobalScope>()
.resource_threads()
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP));
Ok(())
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 95cd8c4bd4a..08e5f84ab06 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -21,6 +21,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JS_GetContext, JS_GetObjectRuntime, JSContext};
use msg::constellation_msg::PipelineId;
+use net_traits::ResourceThreads;
use profile_traits::{mem, time};
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
use std::cell::Cell;
@@ -66,6 +67,10 @@ pub struct GlobalScope {
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
in_error_reporting_mode: Cell<bool>,
+
+ /// Associated resource threads for use by DOM objects like XMLHttpRequest,
+ /// including resource_thread, filemanager_thread and storage_thread
+ resource_threads: ResourceThreads,
}
impl GlobalScope {
@@ -75,7 +80,8 @@ impl GlobalScope {
mem_profiler_chan: mem::ProfilerChan,
time_profiler_chan: time::ProfilerChan,
constellation_chan: IpcSender<ConstellationMsg>,
- scheduler_chan: IpcSender<TimerEventRequest>)
+ scheduler_chan: IpcSender<TimerEventRequest>,
+ resource_threads: ResourceThreads)
-> Self {
GlobalScope {
eventtarget: EventTarget::new_inherited(),
@@ -90,6 +96,7 @@ impl GlobalScope {
constellation_chan: constellation_chan,
scheduler_chan: scheduler_chan,
in_error_reporting_mode: Default::default(),
+ resource_threads: resource_threads,
}
}
@@ -240,6 +247,11 @@ impl GlobalScope {
// Step 14
self.in_error_reporting_mode.set(false);
}
+
+ /// Get the `&ResourceThreads` for this global scope.
+ pub fn resource_threads(&self) -> &ResourceThreads {
+ &self.resource_threads
+ }
}
fn timestamp_in_ms(time: Timespec) -> u64 {
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 4097b885d91..ab184463bb2 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -795,7 +795,7 @@ impl HTMLInputElement {
fn select_files(&self, opt_test_paths: Option<Vec<DOMString>>) {
let window = window_from_node(self);
let origin = get_blob_origin(&window.get_url());
- let resource_threads = window.resource_threads();
+ let resource_threads = window.upcast::<GlobalScope>().resource_threads();
let mut files: Vec<Root<File>> = vec![];
let mut error = None;
diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs
index 76b04f60d6f..f19ac5ebbb6 100644
--- a/components/script/dom/storage.rs
+++ b/components/script/dom/storage.rs
@@ -44,7 +44,7 @@ impl Storage {
}
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
- self.global_scope().as_window().resource_threads().sender()
+ self.global_scope().resource_threads().sender()
}
}
diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs
index 33520beee9d..8912ece7183 100644
--- a/components/script/dom/url.rs
+++ b/components/script/dom/url.rs
@@ -133,6 +133,7 @@ impl URL {
// https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
pub fn RevokeObjectURL(global: GlobalRef, url: DOMString) {
+ let global_scope = global.as_global_scope();
/*
If the url refers to a Blob that has a readability state of CLOSED OR
if the value provided for the url argument is not a Blob URL, OR
@@ -142,11 +143,11 @@ impl URL {
NOTE: The first step is unnecessary, since closed blobs do not exist in the store
*/
- let origin = get_blob_origin(&global.as_global_scope().get_url());
+ let origin = get_blob_origin(&global_scope.get_url());
if let Ok(url) = Url::parse(&url) {
if let Ok((id, _, _)) = parse_blob_url(&url) {
- let resource_threads = global.resource_threads();
+ let resource_threads = global_scope.resource_threads();
let (tx, rx) = ipc::channel().unwrap();
let msg = FileManagerThreadMsg::RevokeBlobURL(id, origin, tx);
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 21b108360f0..0d55cb98f91 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -200,10 +200,6 @@ pub struct Window {
/// The current size of the window, in pixels.
window_size: Cell<Option<WindowSizeData>>,
- /// 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>,
@@ -1371,10 +1367,6 @@ impl Window {
(*self.Document().url()).clone()
}
- pub fn resource_threads(&self) -> &ResourceThreads {
- &self.resource_threads
- }
-
pub fn layout_chan(&self) -> &Sender<Msg> {
&self.layout_chan
}
@@ -1587,7 +1579,8 @@ impl Window {
mem_profiler_chan,
time_profiler_chan,
constellation_chan,
- scheduler_chan.clone()),
+ scheduler_chan.clone(),
+ resource_threads),
script_chan: script_chan,
dom_manipulation_task_source: dom_task_source,
user_interaction_task_source: user_task_source,
@@ -1610,7 +1603,6 @@ impl Window {
parent_info: parent_info,
dom_static: GlobalStaticData::new(),
js_runtime: DOMRefCell::new(Some(runtime.clone())),
- resource_threads: resource_threads,
bluetooth_thread: bluetooth_thread,
page_clip_rect: Cell::new(max_rect()),
fragment_name: DOMRefCell::new(None),
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index b83c36a1aee..59478818cfa 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -30,7 +30,7 @@ use js::jsval::UndefinedValue;
use js::rust::Runtime;
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use net_traits::{IpcSend, LoadOrigin};
-use net_traits::{LoadContext, ResourceThreads, load_whole_resource};
+use net_traits::{LoadContext, load_whole_resource};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper};
@@ -56,8 +56,9 @@ pub fn prepare_workerscope_init(global: GlobalRef,
let constellation_chan = global_scope.constellation_chan().clone();
let scheduler_chan = global_scope.scheduler_chan().clone();
let pipeline_id = global_scope.pipeline_id();
+ let resource_threads = global_scope.resource_threads().clone();
let init = WorkerGlobalScopeInit {
- resource_threads: global.resource_threads(),
+ resource_threads: resource_threads,
mem_profiler_chan: mem_profiler_chan,
to_devtools_sender: to_devtools_sender,
time_profiler_chan: time_profiler_chan,
@@ -82,8 +83,6 @@ pub struct WorkerGlobalScope {
closing: Option<Arc<AtomicBool>>,
#[ignore_heap_size_of = "Defined in js"]
runtime: Runtime,
- #[ignore_heap_size_of = "Defined in std"]
- resource_threads: ResourceThreads,
location: MutNullableHeap<JS<WorkerLocation>>,
navigator: MutNullableHeap<JS<WorkerNavigator>>,
timers: OneshotTimers,
@@ -117,12 +116,12 @@ impl WorkerGlobalScope {
init.mem_profiler_chan,
init.time_profiler_chan,
init.constellation_chan,
- init.scheduler_chan.clone()),
+ init.scheduler_chan.clone(),
+ init.resource_threads),
worker_id: init.worker_id,
worker_url: worker_url,
closing: closing,
runtime: runtime,
- resource_threads: init.resource_threads,
location: Default::default(),
navigator: Default::default(),
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan),
@@ -166,10 +165,6 @@ impl WorkerGlobalScope {
}
}
- pub fn resource_threads(&self) -> &ResourceThreads {
- &self.resource_threads
- }
-
pub fn get_url(&self) -> &Url {
&self.worker_url
}
@@ -245,8 +240,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
rooted!(in(self.runtime.cx()) let mut rval = UndefinedValue());
for url in urls {
+ let global_scope = self.upcast::<GlobalScope>();
let (url, source) = match load_whole_resource(LoadContext::Script,
- &self.resource_threads.sender(),
+ &global_scope.resource_threads().sender(),
url,
self) {
Err(_) => return Err(Error::Network),
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index 870b3235d38..95e300b1527 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -209,7 +209,7 @@ pub fn handle_get_cookies(context: &BrowsingContext,
let document = context.active_document();
let url = document.url();
let (sender, receiver) = ipc::channel().unwrap();
- let _ = document.window().resource_threads().send(
+ let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
GetCookiesDataForUrl(url.clone(), sender, NonHTTP)
);
let cookies = receiver.recv().unwrap();
@@ -224,7 +224,7 @@ pub fn handle_get_cookie(context: &BrowsingContext,
let document = context.active_document();
let url = document.url();
let (sender, receiver) = ipc::channel().unwrap();
- let _ = document.window().resource_threads().send(
+ let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
GetCookiesDataForUrl(url.clone(), sender, NonHTTP)
);
let cookies = receiver.recv().unwrap();
@@ -246,13 +246,13 @@ pub fn handle_add_cookie(context: &BrowsingContext,
reply.send(match (document.is_cookie_averse(), cookie.domain.clone()) {
(true, _) => Err(WebDriverCookieError::InvalidDomain),
(false, Some(ref domain)) if url.host_str().map(|x| { x == &**domain }).unwrap_or(false) => {
- let _ = document.window().resource_threads().send(
+ let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
SetCookiesForUrlWithData(url.clone(), cookie, method)
);
Ok(())
},
(false, None) => {
- let _ = document.window().resource_threads().send(
+ let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
SetCookiesForUrlWithData(url.clone(), cookie, method)
);
Ok(())