mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Introduce GlobalScope::resource_threads
This commit is contained in:
parent
86d2008137
commit
bad49e4696
10 changed files with 41 additions and 44 deletions
|
@ -22,7 +22,7 @@ use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
|
||||||
use js::jsapi::{JS_GetClass, MutableHandleValue};
|
use js::jsapi::{JS_GetClass, MutableHandleValue};
|
||||||
use js::rust::CompileOptionsWrapper;
|
use js::rust::CompileOptionsWrapper;
|
||||||
use libc;
|
use libc;
|
||||||
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
|
use net_traits::{CoreResourceThread, IpcSend};
|
||||||
use profile_traits::time;
|
use profile_traits::time;
|
||||||
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
||||||
use script_runtime::{ScriptPort, maybe_take_panic_result};
|
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
|
/// Get the `CoreResourceThread` for this global scope
|
||||||
pub fn core_resource_thread(&self) -> CoreResourceThread {
|
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
|
/// `ScriptChan` used to send messages to the event loop of this global's
|
||||||
|
|
|
@ -290,8 +290,8 @@ impl Blob {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_to_file_manager(&self, msg: FileManagerThreadMsg) {
|
fn send_to_file_manager(&self, msg: FileManagerThreadMsg) {
|
||||||
let global = self.global();
|
let global = self.global_scope();
|
||||||
let resource_threads = global.r().resource_threads();
|
let resource_threads = global.resource_threads();
|
||||||
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
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>, ()> {
|
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 (chan, recv) = ipc::channel().map_err(|_|())?;
|
||||||
let origin = get_blob_origin(&global.as_global_scope().get_url());
|
let origin = get_blob_origin(&global.as_global_scope().get_url());
|
||||||
let check_url_validity = false;
|
let check_url_validity = false;
|
||||||
|
|
|
@ -2728,7 +2728,10 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
let url = self.url();
|
let url = self.url();
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
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();
|
let cookies = rx.recv().unwrap();
|
||||||
Ok(cookies.map_or(DOMString::new(), DOMString::from))
|
Ok(cookies.map_or(DOMString::new(), DOMString::from))
|
||||||
}
|
}
|
||||||
|
@ -2745,6 +2748,7 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
let url = self.url();
|
let url = self.url();
|
||||||
let _ = self.window
|
let _ = self.window
|
||||||
|
.upcast::<GlobalScope>()
|
||||||
.resource_threads()
|
.resource_threads()
|
||||||
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP));
|
.send(SetCookiesForUrl((*url).clone(), String::from(cookie), NonHTTP));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -21,6 +21,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use js::jsapi::{HandleValue, JS_GetContext, JS_GetObjectRuntime, JSContext};
|
use js::jsapi::{HandleValue, JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
|
use net_traits::ResourceThreads;
|
||||||
use profile_traits::{mem, time};
|
use profile_traits::{mem, time};
|
||||||
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -66,6 +67,10 @@ pub struct GlobalScope {
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
||||||
in_error_reporting_mode: Cell<bool>,
|
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 {
|
impl GlobalScope {
|
||||||
|
@ -75,7 +80,8 @@ impl GlobalScope {
|
||||||
mem_profiler_chan: mem::ProfilerChan,
|
mem_profiler_chan: mem::ProfilerChan,
|
||||||
time_profiler_chan: time::ProfilerChan,
|
time_profiler_chan: time::ProfilerChan,
|
||||||
constellation_chan: IpcSender<ConstellationMsg>,
|
constellation_chan: IpcSender<ConstellationMsg>,
|
||||||
scheduler_chan: IpcSender<TimerEventRequest>)
|
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||||
|
resource_threads: ResourceThreads)
|
||||||
-> Self {
|
-> Self {
|
||||||
GlobalScope {
|
GlobalScope {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
@ -90,6 +96,7 @@ impl GlobalScope {
|
||||||
constellation_chan: constellation_chan,
|
constellation_chan: constellation_chan,
|
||||||
scheduler_chan: scheduler_chan,
|
scheduler_chan: scheduler_chan,
|
||||||
in_error_reporting_mode: Default::default(),
|
in_error_reporting_mode: Default::default(),
|
||||||
|
resource_threads: resource_threads,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +247,11 @@ impl GlobalScope {
|
||||||
// Step 14
|
// Step 14
|
||||||
self.in_error_reporting_mode.set(false);
|
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 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -795,7 +795,7 @@ impl HTMLInputElement {
|
||||||
fn select_files(&self, opt_test_paths: Option<Vec<DOMString>>) {
|
fn select_files(&self, opt_test_paths: Option<Vec<DOMString>>) {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let origin = get_blob_origin(&window.get_url());
|
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 files: Vec<Root<File>> = vec![];
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
|
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
|
||||||
self.global_scope().as_window().resource_threads().sender()
|
self.global_scope().resource_threads().sender()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,7 @@ impl URL {
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
|
// https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
|
||||||
pub fn RevokeObjectURL(global: GlobalRef, url: DOMString) {
|
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 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
|
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
|
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(url) = Url::parse(&url) {
|
||||||
if let Ok((id, _, _)) = parse_blob_url(&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 (tx, rx) = ipc::channel().unwrap();
|
||||||
let msg = FileManagerThreadMsg::RevokeBlobURL(id, origin, tx);
|
let msg = FileManagerThreadMsg::RevokeBlobURL(id, origin, tx);
|
||||||
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
||||||
|
|
|
@ -200,10 +200,6 @@ pub struct Window {
|
||||||
/// The current size of the window, in pixels.
|
/// The current size of the window, in pixels.
|
||||||
window_size: Cell<Option<WindowSizeData>>,
|
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.
|
/// A handle for communicating messages to the bluetooth thread.
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||||
|
@ -1371,10 +1367,6 @@ impl Window {
|
||||||
(*self.Document().url()).clone()
|
(*self.Document().url()).clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resource_threads(&self) -> &ResourceThreads {
|
|
||||||
&self.resource_threads
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn layout_chan(&self) -> &Sender<Msg> {
|
pub fn layout_chan(&self) -> &Sender<Msg> {
|
||||||
&self.layout_chan
|
&self.layout_chan
|
||||||
}
|
}
|
||||||
|
@ -1587,7 +1579,8 @@ impl Window {
|
||||||
mem_profiler_chan,
|
mem_profiler_chan,
|
||||||
time_profiler_chan,
|
time_profiler_chan,
|
||||||
constellation_chan,
|
constellation_chan,
|
||||||
scheduler_chan.clone()),
|
scheduler_chan.clone(),
|
||||||
|
resource_threads),
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
dom_manipulation_task_source: dom_task_source,
|
dom_manipulation_task_source: dom_task_source,
|
||||||
user_interaction_task_source: user_task_source,
|
user_interaction_task_source: user_task_source,
|
||||||
|
@ -1610,7 +1603,6 @@ impl Window {
|
||||||
parent_info: parent_info,
|
parent_info: parent_info,
|
||||||
dom_static: GlobalStaticData::new(),
|
dom_static: GlobalStaticData::new(),
|
||||||
js_runtime: DOMRefCell::new(Some(runtime.clone())),
|
js_runtime: DOMRefCell::new(Some(runtime.clone())),
|
||||||
resource_threads: resource_threads,
|
|
||||||
bluetooth_thread: bluetooth_thread,
|
bluetooth_thread: bluetooth_thread,
|
||||||
page_clip_rect: Cell::new(max_rect()),
|
page_clip_rect: Cell::new(max_rect()),
|
||||||
fragment_name: DOMRefCell::new(None),
|
fragment_name: DOMRefCell::new(None),
|
||||||
|
|
|
@ -30,7 +30,7 @@ use js::jsval::UndefinedValue;
|
||||||
use js::rust::Runtime;
|
use js::rust::Runtime;
|
||||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||||
use net_traits::{IpcSend, LoadOrigin};
|
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::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
|
||||||
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
|
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
|
||||||
use script_thread::{Runnable, RunnableWrapper};
|
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 constellation_chan = global_scope.constellation_chan().clone();
|
||||||
let scheduler_chan = global_scope.scheduler_chan().clone();
|
let scheduler_chan = global_scope.scheduler_chan().clone();
|
||||||
let pipeline_id = global_scope.pipeline_id();
|
let pipeline_id = global_scope.pipeline_id();
|
||||||
|
let resource_threads = global_scope.resource_threads().clone();
|
||||||
let init = WorkerGlobalScopeInit {
|
let init = WorkerGlobalScopeInit {
|
||||||
resource_threads: global.resource_threads(),
|
resource_threads: resource_threads,
|
||||||
mem_profiler_chan: mem_profiler_chan,
|
mem_profiler_chan: mem_profiler_chan,
|
||||||
to_devtools_sender: to_devtools_sender,
|
to_devtools_sender: to_devtools_sender,
|
||||||
time_profiler_chan: time_profiler_chan,
|
time_profiler_chan: time_profiler_chan,
|
||||||
|
@ -82,8 +83,6 @@ pub struct WorkerGlobalScope {
|
||||||
closing: Option<Arc<AtomicBool>>,
|
closing: Option<Arc<AtomicBool>>,
|
||||||
#[ignore_heap_size_of = "Defined in js"]
|
#[ignore_heap_size_of = "Defined in js"]
|
||||||
runtime: Runtime,
|
runtime: Runtime,
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
|
||||||
resource_threads: ResourceThreads,
|
|
||||||
location: MutNullableHeap<JS<WorkerLocation>>,
|
location: MutNullableHeap<JS<WorkerLocation>>,
|
||||||
navigator: MutNullableHeap<JS<WorkerNavigator>>,
|
navigator: MutNullableHeap<JS<WorkerNavigator>>,
|
||||||
timers: OneshotTimers,
|
timers: OneshotTimers,
|
||||||
|
@ -117,12 +116,12 @@ impl WorkerGlobalScope {
|
||||||
init.mem_profiler_chan,
|
init.mem_profiler_chan,
|
||||||
init.time_profiler_chan,
|
init.time_profiler_chan,
|
||||||
init.constellation_chan,
|
init.constellation_chan,
|
||||||
init.scheduler_chan.clone()),
|
init.scheduler_chan.clone(),
|
||||||
|
init.resource_threads),
|
||||||
worker_id: init.worker_id,
|
worker_id: init.worker_id,
|
||||||
worker_url: worker_url,
|
worker_url: worker_url,
|
||||||
closing: closing,
|
closing: closing,
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
resource_threads: init.resource_threads,
|
|
||||||
location: Default::default(),
|
location: Default::default(),
|
||||||
navigator: Default::default(),
|
navigator: Default::default(),
|
||||||
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan),
|
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 {
|
pub fn get_url(&self) -> &Url {
|
||||||
&self.worker_url
|
&self.worker_url
|
||||||
}
|
}
|
||||||
|
@ -245,8 +240,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
|
|
||||||
rooted!(in(self.runtime.cx()) let mut rval = UndefinedValue());
|
rooted!(in(self.runtime.cx()) let mut rval = UndefinedValue());
|
||||||
for url in urls {
|
for url in urls {
|
||||||
|
let global_scope = self.upcast::<GlobalScope>();
|
||||||
let (url, source) = match load_whole_resource(LoadContext::Script,
|
let (url, source) = match load_whole_resource(LoadContext::Script,
|
||||||
&self.resource_threads.sender(),
|
&global_scope.resource_threads().sender(),
|
||||||
url,
|
url,
|
||||||
self) {
|
self) {
|
||||||
Err(_) => return Err(Error::Network),
|
Err(_) => return Err(Error::Network),
|
||||||
|
|
|
@ -209,7 +209,7 @@ pub fn handle_get_cookies(context: &BrowsingContext,
|
||||||
let document = context.active_document();
|
let document = context.active_document();
|
||||||
let url = document.url();
|
let url = document.url();
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
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)
|
GetCookiesDataForUrl(url.clone(), sender, NonHTTP)
|
||||||
);
|
);
|
||||||
let cookies = receiver.recv().unwrap();
|
let cookies = receiver.recv().unwrap();
|
||||||
|
@ -224,7 +224,7 @@ pub fn handle_get_cookie(context: &BrowsingContext,
|
||||||
let document = context.active_document();
|
let document = context.active_document();
|
||||||
let url = document.url();
|
let url = document.url();
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
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)
|
GetCookiesDataForUrl(url.clone(), sender, NonHTTP)
|
||||||
);
|
);
|
||||||
let cookies = receiver.recv().unwrap();
|
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()) {
|
reply.send(match (document.is_cookie_averse(), cookie.domain.clone()) {
|
||||||
(true, _) => Err(WebDriverCookieError::InvalidDomain),
|
(true, _) => Err(WebDriverCookieError::InvalidDomain),
|
||||||
(false, Some(ref domain)) if url.host_str().map(|x| { x == &**domain }).unwrap_or(false) => {
|
(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)
|
SetCookiesForUrlWithData(url.clone(), cookie, method)
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
(false, None) => {
|
(false, None) => {
|
||||||
let _ = document.window().resource_threads().send(
|
let _ = document.window().upcast::<GlobalScope>().resource_threads().send(
|
||||||
SetCookiesForUrlWithData(url.clone(), cookie, method)
|
SetCookiesForUrlWithData(url.clone(), cookie, method)
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue