mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Introduce GlobalScope::get_url
This commit is contained in:
parent
092504b4e3
commit
f38159b7d3
10 changed files with 39 additions and 39 deletions
|
@ -32,7 +32,6 @@ use std::ffi::CString;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use task_source::file_reading::FileReadingTaskSource;
|
use task_source::file_reading::FileReadingTaskSource;
|
||||||
use timers::{OneshotTimerCallback, OneshotTimerHandle};
|
use timers::{OneshotTimerCallback, OneshotTimerHandle};
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
/// A freely-copyable reference to a rooted global object.
|
/// A freely-copyable reference to a rooted global object.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -91,14 +90,6 @@ impl<'a> GlobalRef<'a> {
|
||||||
self.resource_threads().sender()
|
self.resource_threads().sender()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the URL for this global scope.
|
|
||||||
pub fn get_url(&self) -> Url {
|
|
||||||
match *self {
|
|
||||||
GlobalRef::Window(ref window) => window.get_url(),
|
|
||||||
GlobalRef::Worker(ref worker) => worker.get_url().clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `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
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
||||||
|
@ -158,7 +149,7 @@ impl<'a> GlobalRef<'a> {
|
||||||
&self, code: &str, filename: &str, rval: MutableHandleValue) {
|
&self, code: &str, filename: &str, rval: MutableHandleValue) {
|
||||||
let metadata = time::TimerMetadata {
|
let metadata = time::TimerMetadata {
|
||||||
url: if filename.is_empty() {
|
url: if filename.is_empty() {
|
||||||
self.get_url().as_str().into()
|
self.as_global_scope().get_url().as_str().into()
|
||||||
} else {
|
} else {
|
||||||
filename.into()
|
filename.into()
|
||||||
},
|
},
|
||||||
|
|
|
@ -190,6 +190,7 @@ impl Blob {
|
||||||
/// valid or invalid Blob URL.
|
/// valid or invalid Blob URL.
|
||||||
fn promote(&self, set_valid: bool) -> Uuid {
|
fn promote(&self, set_valid: bool) -> Uuid {
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
|
let global_url = self.global_scope().get_url();
|
||||||
|
|
||||||
match *self.blob_impl.borrow_mut() {
|
match *self.blob_impl.borrow_mut() {
|
||||||
BlobImpl::Sliced(_, _) => {
|
BlobImpl::Sliced(_, _) => {
|
||||||
|
@ -199,8 +200,7 @@ impl Blob {
|
||||||
}
|
}
|
||||||
BlobImpl::File(ref f) => {
|
BlobImpl::File(ref f) => {
|
||||||
if set_valid {
|
if set_valid {
|
||||||
let global = self.global();
|
let origin = get_blob_origin(&global_url);
|
||||||
let origin = get_blob_origin(&global.r().get_url());
|
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
let (tx, rx) = ipc::channel().unwrap();
|
||||||
|
|
||||||
let msg = FileManagerThreadMsg::ActivateBlobURL(f.id.clone(), tx, origin.clone());
|
let msg = FileManagerThreadMsg::ActivateBlobURL(f.id.clone(), tx, origin.clone());
|
||||||
|
@ -219,8 +219,7 @@ impl Blob {
|
||||||
BlobImpl::Memory(ref mut bytes_in) => mem::swap(bytes_in, &mut bytes),
|
BlobImpl::Memory(ref mut bytes_in) => mem::swap(bytes_in, &mut bytes),
|
||||||
};
|
};
|
||||||
|
|
||||||
let global = self.global();
|
let origin = get_blob_origin(&global_url);
|
||||||
let origin = get_blob_origin(&global.r().get_url());
|
|
||||||
|
|
||||||
let blob_buf = BlobBuf {
|
let blob_buf = BlobBuf {
|
||||||
filename: None,
|
filename: None,
|
||||||
|
@ -251,9 +250,7 @@ impl Blob {
|
||||||
/// Get a FileID representing sliced parent-blob content
|
/// Get a FileID representing sliced parent-blob content
|
||||||
fn create_sliced_url_id(&self, parent_id: &Uuid,
|
fn create_sliced_url_id(&self, parent_id: &Uuid,
|
||||||
rel_pos: &RelativePos, parent_len: u64) -> Uuid {
|
rel_pos: &RelativePos, parent_len: u64) -> Uuid {
|
||||||
let global = self.global();
|
let origin = get_blob_origin(&self.global_scope().get_url());
|
||||||
|
|
||||||
let origin = get_blob_origin(&global.r().get_url());
|
|
||||||
|
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
let (tx, rx) = ipc::channel().unwrap();
|
||||||
let msg = FileManagerThreadMsg::AddSlicedURLEntry(parent_id.clone(),
|
let msg = FileManagerThreadMsg::AddSlicedURLEntry(parent_id.clone(),
|
||||||
|
@ -282,8 +279,7 @@ impl Blob {
|
||||||
/// Cleanups at the time of destruction/closing
|
/// Cleanups at the time of destruction/closing
|
||||||
fn clean_up_file_resource(&self) {
|
fn clean_up_file_resource(&self) {
|
||||||
if let BlobImpl::File(ref f) = *self.blob_impl.borrow() {
|
if let BlobImpl::File(ref f) = *self.blob_impl.borrow() {
|
||||||
let global = self.global();
|
let origin = get_blob_origin(&self.global_scope().get_url());
|
||||||
let origin = get_blob_origin(&global.r().get_url());
|
|
||||||
|
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
let (tx, rx) = ipc::channel().unwrap();
|
||||||
|
|
||||||
|
@ -311,7 +307,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.resource_threads();
|
||||||
let (chan, recv) = ipc::channel().map_err(|_|())?;
|
let (chan, recv) = ipc::channel().map_err(|_|())?;
|
||||||
let origin = get_blob_origin(&global.get_url());
|
let origin = get_blob_origin(&global.as_global_scope().get_url());
|
||||||
let check_url_validity = false;
|
let check_url_validity = false;
|
||||||
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
|
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
|
||||||
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
||||||
|
|
|
@ -52,14 +52,15 @@ impl EventSource {
|
||||||
pub fn Constructor(global: GlobalRef,
|
pub fn Constructor(global: GlobalRef,
|
||||||
url_str: DOMString,
|
url_str: DOMString,
|
||||||
event_source_init: &EventSourceInit) -> Fallible<Root<EventSource>> {
|
event_source_init: &EventSourceInit) -> Fallible<Root<EventSource>> {
|
||||||
|
let global_scope = global.as_global_scope();
|
||||||
// Steps 1-2
|
// Steps 1-2
|
||||||
let base_url = global.get_url();
|
let base_url = global_scope.get_url();
|
||||||
let url = match base_url.join(&*url_str) {
|
let url = match base_url.join(&*url_str) {
|
||||||
Ok(u) => u,
|
Ok(u) => u,
|
||||||
Err(_) => return Err(Error::Syntax)
|
Err(_) => return Err(Error::Syntax)
|
||||||
};
|
};
|
||||||
// Step 3
|
// Step 3
|
||||||
let event_source = EventSource::new(global.as_global_scope(), url, event_source_init.withCredentials);
|
let event_source = EventSource::new(global_scope, url, event_source_init.withCredentials);
|
||||||
// Step 4
|
// Step 4
|
||||||
// Step 5
|
// Step 5
|
||||||
// Step 6
|
// Step 6
|
||||||
|
|
|
@ -179,6 +179,17 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the URL for this global scope.
|
||||||
|
pub fn get_url(&self) -> Url {
|
||||||
|
if let Some(window) = self.downcast::<Window>() {
|
||||||
|
return window.get_url();
|
||||||
|
}
|
||||||
|
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
|
||||||
|
return worker.get_url().clone();
|
||||||
|
}
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl Request {
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
// TODO: `entry settings object` is not implemented in Servo yet.
|
// TODO: `entry settings object` is not implemented in Servo yet.
|
||||||
let base_url = global.get_url();
|
let base_url = global.as_global_scope().get_url();
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
// Step 5
|
// Step 5
|
||||||
|
@ -130,7 +130,7 @@ impl Request {
|
||||||
|
|
||||||
// Step 7
|
// Step 7
|
||||||
// TODO: `entry settings object` is not implemented yet.
|
// TODO: `entry settings object` is not implemented yet.
|
||||||
let origin = global.get_url().origin();
|
let origin = base_url.origin();
|
||||||
|
|
||||||
// Step 8
|
// Step 8
|
||||||
let mut window = Window::Client;
|
let mut window = Window::Client;
|
||||||
|
@ -450,8 +450,9 @@ impl Request {
|
||||||
fn net_request_from_global(global: GlobalRef,
|
fn net_request_from_global(global: GlobalRef,
|
||||||
url: Url,
|
url: Url,
|
||||||
is_service_worker_global_scope: bool) -> NetTraitsRequest {
|
is_service_worker_global_scope: bool) -> NetTraitsRequest {
|
||||||
let origin = Origin::Origin(global.get_url().origin());
|
let global_scope = global.as_global_scope();
|
||||||
let pipeline_id = global.as_global_scope().pipeline_id();
|
let origin = Origin::Origin(global_scope.get_url().origin());
|
||||||
|
let pipeline_id = global_scope.pipeline_id();
|
||||||
NetTraitsRequest::new(url,
|
NetTraitsRequest::new(url,
|
||||||
Some(origin),
|
Some(origin),
|
||||||
is_service_worker_global_scope,
|
is_service_worker_global_scope,
|
||||||
|
|
|
@ -149,9 +149,10 @@ impl Response {
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#dom-response-redirect
|
// https://fetch.spec.whatwg.org/#dom-response-redirect
|
||||||
pub fn Redirect(global: GlobalRef, url: USVString, status: u16) -> Fallible<Root<Response>> {
|
pub fn Redirect(global: GlobalRef, url: USVString, status: u16) -> Fallible<Root<Response>> {
|
||||||
|
let global_scope = global.as_global_scope();
|
||||||
// Step 1
|
// Step 1
|
||||||
// TODO: `entry settings object` is not implemented in Servo yet.
|
// TODO: `entry settings object` is not implemented in Servo yet.
|
||||||
let base_url = global.get_url();
|
let base_url = global_scope.get_url();
|
||||||
let parsed_url = base_url.join(&url.0);
|
let parsed_url = base_url.join(&url.0);
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
|
@ -167,7 +168,7 @@ impl Response {
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
// see Step 4 continued
|
// see Step 4 continued
|
||||||
let r = Response::new(global.as_global_scope());
|
let r = Response::new(global_scope);
|
||||||
|
|
||||||
// Step 5
|
// Step 5
|
||||||
*r.status.borrow_mut() = Some(StatusCode::from_u16(status));
|
*r.status.borrow_mut() = Some(StatusCode::from_u16(status));
|
||||||
|
|
|
@ -40,9 +40,7 @@ impl Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_url(&self) -> Url {
|
fn get_url(&self) -> Url {
|
||||||
let global_root = self.global();
|
self.global_scope().get_url()
|
||||||
let global_ref = global_root.r();
|
|
||||||
global_ref.get_url()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
|
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl URL {
|
||||||
pub fn CreateObjectURL(global: GlobalRef, blob: &Blob) -> DOMString {
|
pub fn CreateObjectURL(global: GlobalRef, blob: &Blob) -> DOMString {
|
||||||
/// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
|
/// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
|
||||||
/// and should not be trusted. See issue https://github.com/servo/servo/issues/11722
|
/// and should not be trusted. See issue https://github.com/servo/servo/issues/11722
|
||||||
let origin = get_blob_origin(&global.get_url());
|
let origin = get_blob_origin(&global.as_global_scope().get_url());
|
||||||
|
|
||||||
if blob.IsClosed() {
|
if blob.IsClosed() {
|
||||||
// Generate a dummy id
|
// Generate a dummy id
|
||||||
|
@ -142,7 +142,7 @@ 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.get_url());
|
let origin = get_blob_origin(&global.as_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) {
|
||||||
|
|
|
@ -239,10 +239,11 @@ impl WebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6: Origin.
|
// Step 6: Origin.
|
||||||
let origin = UrlHelper::Origin(&global.get_url()).0;
|
let global_scope = global.as_global_scope();
|
||||||
|
let origin = UrlHelper::Origin(&global_scope.get_url()).0;
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
let ws = WebSocket::new(global.as_global_scope(), resource_url.clone());
|
let ws = WebSocket::new(global_scope, resource_url.clone());
|
||||||
let address = Trusted::new(ws.r());
|
let address = Trusted::new(ws.r());
|
||||||
|
|
||||||
let connect_data = WebSocketConnectData {
|
let connect_data = WebSocketConnectData {
|
||||||
|
|
|
@ -595,7 +595,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
use_cors_preflight: has_handlers,
|
use_cors_preflight: has_handlers,
|
||||||
credentials_mode: credentials_mode,
|
credentials_mode: credentials_mode,
|
||||||
use_url_credentials: use_url_credentials,
|
use_url_credentials: use_url_credentials,
|
||||||
origin: self.global().r().get_url(),
|
origin: self.global_scope().get_url(),
|
||||||
referrer_url: self.referrer_url.clone(),
|
referrer_url: self.referrer_url.clone(),
|
||||||
referrer_policy: self.referrer_policy.clone(),
|
referrer_policy: self.referrer_policy.clone(),
|
||||||
pipeline_id: self.pipeline_id(),
|
pipeline_id: self.pipeline_id(),
|
||||||
|
@ -1204,7 +1204,7 @@ impl XMLHttpRequest {
|
||||||
// TODO: Disable scripting while parsing
|
// TODO: Disable scripting while parsing
|
||||||
parse_html(document.r(),
|
parse_html(document.r(),
|
||||||
DOMString::from(decoded),
|
DOMString::from(decoded),
|
||||||
wr.get_url(),
|
wr.as_global_scope().get_url(),
|
||||||
ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
|
ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
|
||||||
document
|
document
|
||||||
}
|
}
|
||||||
|
@ -1218,7 +1218,7 @@ impl XMLHttpRequest {
|
||||||
// TODO: Disable scripting while parsing
|
// TODO: Disable scripting while parsing
|
||||||
parse_xml(document.r(),
|
parse_xml(document.r(),
|
||||||
DOMString::from(decoded),
|
DOMString::from(decoded),
|
||||||
wr.get_url(),
|
wr.as_global_scope().get_url(),
|
||||||
xml::ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
|
xml::ParseContext::Owner(Some(wr.as_global_scope().pipeline_id())));
|
||||||
document
|
document
|
||||||
}
|
}
|
||||||
|
@ -1230,7 +1230,7 @@ impl XMLHttpRequest {
|
||||||
let doc = win.Document();
|
let doc = win.Document();
|
||||||
let doc = doc.r();
|
let doc = doc.r();
|
||||||
let docloader = DocumentLoader::new(&*doc.loader());
|
let docloader = DocumentLoader::new(&*doc.loader());
|
||||||
let base = self.global().r().get_url();
|
let base = self.global_scope().get_url();
|
||||||
let parsed_url = match base.join(&self.ResponseURL().0) {
|
let parsed_url = match base.join(&self.ResponseURL().0) {
|
||||||
Ok(parsed) => Some(parsed),
|
Ok(parsed) => Some(parsed),
|
||||||
Err(_) => None // Step 7
|
Err(_) => None // Step 7
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue