mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
re-structure blob, structured serialization
This commit is contained in:
parent
7aa68c8fe7
commit
6e8a85482c
31 changed files with 997 additions and 489 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4612,6 +4612,7 @@ dependencies = [
|
||||||
"style_traits",
|
"style_traits",
|
||||||
"time",
|
"time",
|
||||||
"url",
|
"url",
|
||||||
|
"uuid",
|
||||||
"webdriver",
|
"webdriver",
|
||||||
"webgpu",
|
"webgpu",
|
||||||
"webrender_api",
|
"webrender_api",
|
||||||
|
|
|
@ -170,6 +170,13 @@ impl PipelineNamespace {
|
||||||
index: MessagePortRouterIndex(self.next_index()),
|
index: MessagePortRouterIndex(self.next_index()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_blob_id(&mut self) -> BlobId {
|
||||||
|
BlobId {
|
||||||
|
namespace_id: self.id,
|
||||||
|
index: BlobIndex(self.next_index()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
|
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
|
||||||
|
@ -373,6 +380,37 @@ impl fmt::Display for MessagePortRouterId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
|
pub struct BlobIndex(pub NonZeroU32);
|
||||||
|
malloc_size_of_is_0!(BlobIndex);
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
|
||||||
|
)]
|
||||||
|
pub struct BlobId {
|
||||||
|
pub namespace_id: PipelineNamespaceId,
|
||||||
|
pub index: BlobIndex,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlobId {
|
||||||
|
pub fn new() -> BlobId {
|
||||||
|
PIPELINE_NAMESPACE.with(|tls| {
|
||||||
|
let mut namespace = tls.get().expect("No namespace set for this thread!");
|
||||||
|
let next_blob_id = namespace.next_blob_id();
|
||||||
|
tls.set(Some(namespace));
|
||||||
|
next_blob_id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for BlobId {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let PipelineNamespaceId(namespace_id) = self.namespace_id;
|
||||||
|
let BlobIndex(index) = self.index;
|
||||||
|
write!(fmt, "({},{})", namespace_id, index.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
pub struct HistoryStateIndex(pub NonZeroU32);
|
pub struct HistoryStateIndex(pub NonZeroU32);
|
||||||
malloc_size_of_is_0!(HistoryStateIndex);
|
malloc_size_of_is_0!(HistoryStateIndex);
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub type FileOrigin = String;
|
||||||
/// Relative slice positions of a sequence,
|
/// Relative slice positions of a sequence,
|
||||||
/// whose semantic should be consistent with (start, end) parameters in
|
/// whose semantic should be consistent with (start, end) parameters in
|
||||||
/// <https://w3c.github.io/FileAPI/#dfn-slice>
|
/// <https://w3c.github.io/FileAPI/#dfn-slice>
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
pub struct RelativePos {
|
pub struct RelativePos {
|
||||||
/// Relative to first byte if non-negative,
|
/// Relative to first byte if non-negative,
|
||||||
/// relative to one past last byte if negative,
|
/// relative to one past last byte if negative,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::USVString;
|
use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::{normalize_type_string, Blob};
|
||||||
use crate::dom::formdata::FormData;
|
use crate::dom::formdata::FormData;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
|
@ -24,6 +24,7 @@ use js::rust::wrappers::JS_GetPendingException;
|
||||||
use js::rust::wrappers::JS_ParseJSON;
|
use js::rust::wrappers::JS_ParseJSON;
|
||||||
use js::typedarray::{ArrayBuffer, CreateWith};
|
use js::typedarray::{ArrayBuffer, CreateWith};
|
||||||
use mime::{self, Mime};
|
use mime::{self, Mime};
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -166,7 +167,10 @@ fn run_blob_data_algorithm(
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
let blob = Blob::new(root, BlobImpl::new_from_bytes(bytes), mime_string);
|
let blob = Blob::new(
|
||||||
|
root,
|
||||||
|
BlobImpl::new_from_bytes(bytes, normalize_type_string(&mime_string)),
|
||||||
|
);
|
||||||
Ok(FetchedData::BlobData(blob))
|
Ok(FetchedData::BlobData(blob))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,5 +148,5 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
|
||||||
}
|
}
|
||||||
worker_scope
|
worker_scope
|
||||||
.upcast::<GlobalScope>()
|
.upcast::<GlobalScope>()
|
||||||
.perform_a_message_port_garbage_collection_checkpoint();
|
.perform_a_dom_garbage_collection_checkpoint();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,14 @@
|
||||||
|
|
||||||
DOMInterfaces = {
|
DOMInterfaces = {
|
||||||
|
|
||||||
|
'Blob': {
|
||||||
|
'weakReferenceable': True,
|
||||||
|
},
|
||||||
|
|
||||||
|
'File': {
|
||||||
|
'weakReferenceable': True,
|
||||||
|
},
|
||||||
|
|
||||||
'MediaQueryList': {
|
'MediaQueryList': {
|
||||||
'weakReferenceable': True,
|
'weakReferenceable': True,
|
||||||
},
|
},
|
||||||
|
|
|
@ -150,6 +150,7 @@ pub mod record;
|
||||||
pub mod refcounted;
|
pub mod refcounted;
|
||||||
pub mod reflector;
|
pub mod reflector;
|
||||||
pub mod root;
|
pub mod root;
|
||||||
|
pub mod serializable;
|
||||||
pub mod settings_stack;
|
pub mod settings_stack;
|
||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod structuredclone;
|
pub mod structuredclone;
|
||||||
|
|
32
components/script/dom/bindings/serializable.rs
Normal file
32
components/script/dom/bindings/serializable.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Trait representing the concept of [serializable objects]
|
||||||
|
//! (https://html.spec.whatwg.org/multipage/#serializable-objects).
|
||||||
|
|
||||||
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::bindings::structuredclone::StructuredDataHolder;
|
||||||
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
|
||||||
|
/// The key corresponding to the storage location
|
||||||
|
/// of a serialized platform object stored in a StructuredDataHolder.
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
pub struct StorageKey {
|
||||||
|
pub index: u32,
|
||||||
|
pub name_space: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Interface for serializable platform objects.
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/#serializable>
|
||||||
|
pub trait Serializable: DomObject {
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/#serialization-steps>
|
||||||
|
fn serialize(&self, sc_holder: &mut StructuredDataHolder) -> Result<StorageKey, ()>;
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/#deserialization-steps>
|
||||||
|
fn deserialize(
|
||||||
|
owner: &DomRoot<GlobalScope>,
|
||||||
|
sc_holder: &mut StructuredDataHolder,
|
||||||
|
extra_data: StorageKey,
|
||||||
|
) -> Result<(), ()>;
|
||||||
|
}
|
|
@ -10,8 +10,9 @@ use crate::dom::bindings::conversions::{root_from_object, ToJSValConvertible};
|
||||||
use crate::dom::bindings::error::{Error, Fallible};
|
use crate::dom::bindings::error::{Error, Fallible};
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::bindings::serializable::{Serializable, StorageKey};
|
||||||
use crate::dom::bindings::transferable::Transferable;
|
use crate::dom::bindings::transferable::Transferable;
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::Blob;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::messageport::MessagePort;
|
use crate::dom::messageport::MessagePort;
|
||||||
use crate::script_runtime::JSContext as SafeJSContext;
|
use crate::script_runtime::JSContext as SafeJSContext;
|
||||||
|
@ -29,12 +30,12 @@ use js::jsapi::TransferableOwnership;
|
||||||
use js::jsapi::JS_STRUCTURED_CLONE_VERSION;
|
use js::jsapi::JS_STRUCTURED_CLONE_VERSION;
|
||||||
use js::jsapi::{JSObject, JS_ClearPendingException};
|
use js::jsapi::{JSObject, JS_ClearPendingException};
|
||||||
use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter};
|
use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter};
|
||||||
use js::jsapi::{JS_ReadBytes, JS_WriteBytes};
|
|
||||||
use js::jsapi::{JS_ReadUint32Pair, JS_WriteUint32Pair};
|
use js::jsapi::{JS_ReadUint32Pair, JS_WriteUint32Pair};
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use js::rust::wrappers::{JS_ReadStructuredClone, JS_WriteStructuredClone};
|
use js::rust::wrappers::{JS_ReadStructuredClone, JS_WriteStructuredClone};
|
||||||
use js::rust::{CustomAutoRooterGuard, HandleValue, MutableHandleValue};
|
use js::rust::{CustomAutoRooterGuard, HandleValue, MutableHandleValue};
|
||||||
use msg::constellation_msg::MessagePortId;
|
use msg::constellation_msg::{BlobId, MessagePortId};
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use script_traits::transferable::MessagePortImpl;
|
use script_traits::transferable::MessagePortImpl;
|
||||||
use script_traits::StructuredSerializedData;
|
use script_traits::StructuredSerializedData;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -54,117 +55,62 @@ enum StructuredCloneTags {
|
||||||
Max = 0xFFFFFFFF,
|
Max = 0xFFFFFFFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
|
||||||
unsafe fn write_length(w: *mut JSStructuredCloneWriter, length: usize) {
|
|
||||||
let high: u32 = (length >> 32) as u32;
|
|
||||||
let low: u32 = length as u32;
|
|
||||||
assert!(JS_WriteUint32Pair(w, high, low));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
|
||||||
unsafe fn write_length(w: *mut JSStructuredCloneWriter, length: usize) {
|
|
||||||
assert!(JS_WriteUint32Pair(w, length as u32, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
|
||||||
unsafe fn read_length(r: *mut JSStructuredCloneReader) -> usize {
|
|
||||||
let mut high: u32 = 0;
|
|
||||||
let mut low: u32 = 0;
|
|
||||||
assert!(JS_ReadUint32Pair(
|
|
||||||
r,
|
|
||||||
&mut high as *mut u32,
|
|
||||||
&mut low as *mut u32
|
|
||||||
));
|
|
||||||
return (low << high) as usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
|
||||||
unsafe fn read_length(r: *mut JSStructuredCloneReader) -> usize {
|
|
||||||
let mut length: u32 = 0;
|
|
||||||
let mut zero: u32 = 0;
|
|
||||||
assert!(JS_ReadUint32Pair(
|
|
||||||
r,
|
|
||||||
&mut length as *mut u32,
|
|
||||||
&mut zero as *mut u32
|
|
||||||
));
|
|
||||||
return length as usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StructuredCloneWriter {
|
|
||||||
w: *mut JSStructuredCloneWriter,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StructuredCloneWriter {
|
|
||||||
unsafe fn write_slice(&self, v: &[u8]) {
|
|
||||||
let type_length = v.len();
|
|
||||||
write_length(self.w, type_length);
|
|
||||||
assert!(JS_WriteBytes(
|
|
||||||
self.w,
|
|
||||||
v.as_ptr() as *const raw::c_void,
|
|
||||||
type_length
|
|
||||||
));
|
|
||||||
}
|
|
||||||
unsafe fn write_str(&self, s: &str) {
|
|
||||||
self.write_slice(s.as_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StructuredCloneReader {
|
|
||||||
r: *mut JSStructuredCloneReader,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StructuredCloneReader {
|
|
||||||
unsafe fn read_bytes(&self) -> Vec<u8> {
|
|
||||||
let mut bytes = vec![0u8; read_length(self.r)];
|
|
||||||
let blob_length = bytes.len();
|
|
||||||
assert!(JS_ReadBytes(
|
|
||||||
self.r,
|
|
||||||
bytes.as_mut_ptr() as *mut raw::c_void,
|
|
||||||
blob_length
|
|
||||||
));
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
unsafe fn read_str(&self) -> String {
|
|
||||||
let str_buffer = self.read_bytes();
|
|
||||||
return String::from_utf8_unchecked(str_buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn read_blob(
|
unsafe fn read_blob(
|
||||||
cx: *mut JSContext,
|
owner: &DomRoot<GlobalScope>,
|
||||||
r: *mut JSStructuredCloneReader,
|
r: *mut JSStructuredCloneReader,
|
||||||
sc_holder: &mut StructuredDataHolder,
|
mut sc_holder: &mut StructuredDataHolder,
|
||||||
) -> *mut JSObject {
|
) -> *mut JSObject {
|
||||||
let structured_reader = StructuredCloneReader { r: r };
|
let mut name_space: u32 = 0;
|
||||||
let blob_buffer = structured_reader.read_bytes();
|
let mut index: u32 = 0;
|
||||||
let type_str = structured_reader.read_str();
|
assert!(JS_ReadUint32Pair(
|
||||||
let target_global = GlobalScope::from_context(cx);
|
r,
|
||||||
let read_blob = Blob::new(
|
&mut name_space as *mut u32,
|
||||||
&target_global,
|
&mut index as *mut u32
|
||||||
BlobImpl::new_from_bytes(blob_buffer),
|
));
|
||||||
type_str,
|
let storage_key = StorageKey { index, name_space };
|
||||||
);
|
if <Blob as Serializable>::deserialize(&owner, &mut sc_holder, storage_key.clone()).is_ok() {
|
||||||
let js_object = read_blob.reflector().get_jsobject().get();
|
let blobs = match sc_holder {
|
||||||
match sc_holder {
|
StructuredDataHolder::Read { blobs, .. } => blobs,
|
||||||
StructuredDataHolder::Read { blob, .. } => {
|
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
||||||
*blob = Some(read_blob);
|
};
|
||||||
},
|
if let Some(blobs) = blobs {
|
||||||
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
let blob = blobs
|
||||||
|
.get(&storage_key)
|
||||||
|
.expect("No blob found at storage key.");
|
||||||
|
return blob.reflector().get_jsobject().get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
js_object
|
warn!(
|
||||||
|
"Reading structured data for a blob failed in {:?}.",
|
||||||
|
owner.get_url()
|
||||||
|
);
|
||||||
|
ptr::null_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn write_blob(blob: DomRoot<Blob>, w: *mut JSStructuredCloneWriter) -> Result<(), ()> {
|
unsafe fn write_blob(
|
||||||
let structured_writer = StructuredCloneWriter { w: w };
|
owner: &DomRoot<GlobalScope>,
|
||||||
let blob_vec = blob.get_bytes()?;
|
blob: DomRoot<Blob>,
|
||||||
assert!(JS_WriteUint32Pair(
|
w: *mut JSStructuredCloneWriter,
|
||||||
w,
|
sc_holder: &mut StructuredDataHolder,
|
||||||
StructuredCloneTags::DomBlob as u32,
|
) -> bool {
|
||||||
0
|
if let Ok(storage_key) = blob.serialize(sc_holder) {
|
||||||
));
|
assert!(JS_WriteUint32Pair(
|
||||||
structured_writer.write_slice(&blob_vec);
|
w,
|
||||||
structured_writer.write_str(&blob.type_string());
|
StructuredCloneTags::DomBlob as u32,
|
||||||
return Ok(());
|
0
|
||||||
|
));
|
||||||
|
assert!(JS_WriteUint32Pair(
|
||||||
|
w,
|
||||||
|
storage_key.name_space,
|
||||||
|
storage_key.index
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
warn!(
|
||||||
|
"Writing structured data for a blob failed in {:?}.",
|
||||||
|
owner.get_url()
|
||||||
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn read_callback(
|
unsafe extern "C" fn read_callback(
|
||||||
|
@ -183,7 +129,11 @@ unsafe extern "C" fn read_callback(
|
||||||
"tag should be higher than StructuredCloneTags::Min"
|
"tag should be higher than StructuredCloneTags::Min"
|
||||||
);
|
);
|
||||||
if tag == StructuredCloneTags::DomBlob as u32 {
|
if tag == StructuredCloneTags::DomBlob as u32 {
|
||||||
return read_blob(cx, r, &mut *(closure as *mut StructuredDataHolder));
|
return read_blob(
|
||||||
|
&GlobalScope::from_context(cx),
|
||||||
|
r,
|
||||||
|
&mut *(closure as *mut StructuredDataHolder),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
|
@ -192,10 +142,15 @@ unsafe extern "C" fn write_callback(
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
w: *mut JSStructuredCloneWriter,
|
w: *mut JSStructuredCloneWriter,
|
||||||
obj: RawHandleObject,
|
obj: RawHandleObject,
|
||||||
_closure: *mut raw::c_void,
|
closure: *mut raw::c_void,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Ok(blob) = root_from_object::<Blob>(*obj, cx) {
|
if let Ok(blob) = root_from_object::<Blob>(*obj, cx) {
|
||||||
return write_blob(blob, w).is_ok();
|
return write_blob(
|
||||||
|
&GlobalScope::from_context(cx),
|
||||||
|
blob,
|
||||||
|
w,
|
||||||
|
&mut *(closure as *mut StructuredDataHolder),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -282,8 +237,8 @@ static STRUCTURED_CLONE_CALLBACKS: JSStructuredCloneCallbacks = JSStructuredClon
|
||||||
/// https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
|
/// https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
|
||||||
pub enum StructuredDataHolder {
|
pub enum StructuredDataHolder {
|
||||||
Read {
|
Read {
|
||||||
/// A deserialized blob, stored temporarily here to keep it rooted.
|
/// A map of deserialized blobs, stored temporarily here to keep them rooted.
|
||||||
blob: Option<DomRoot<Blob>>,
|
blobs: Option<HashMap<StorageKey, DomRoot<Blob>>>,
|
||||||
/// A vec of transfer-received DOM ports,
|
/// A vec of transfer-received DOM ports,
|
||||||
/// to be made available to script through a message event.
|
/// to be made available to script through a message event.
|
||||||
message_ports: Option<Vec<DomRoot<MessagePort>>>,
|
message_ports: Option<Vec<DomRoot<MessagePort>>>,
|
||||||
|
@ -291,10 +246,18 @@ pub enum StructuredDataHolder {
|
||||||
/// used as part of the "transfer-receiving" steps of ports,
|
/// used as part of the "transfer-receiving" steps of ports,
|
||||||
/// to produce the DOM ports stored in `message_ports` above.
|
/// to produce the DOM ports stored in `message_ports` above.
|
||||||
port_impls: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
port_impls: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
||||||
|
/// A map of blob implementations,
|
||||||
|
/// used as part of the "deserialize" steps of blobs,
|
||||||
|
/// to produce the DOM blobs stored in `blobs` above.
|
||||||
|
blob_impls: Option<HashMap<BlobId, BlobImpl>>,
|
||||||
|
},
|
||||||
|
/// A data holder for transferred and serialized objects.
|
||||||
|
Write {
|
||||||
|
/// Transferred ports.
|
||||||
|
ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
||||||
|
/// Serialized blobs.
|
||||||
|
blobs: Option<HashMap<BlobId, BlobImpl>>,
|
||||||
},
|
},
|
||||||
/// A data holder into which transferred ports
|
|
||||||
/// can be written as part of their transfer steps.
|
|
||||||
Write(Option<HashMap<MessagePortId, MessagePortImpl>>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes a structured clone. Returns a `DataClone` error if that fails.
|
/// Writes a structured clone. Returns a `DataClone` error if that fails.
|
||||||
|
@ -308,8 +271,10 @@ pub fn write(
|
||||||
if let Some(transfer) = transfer {
|
if let Some(transfer) = transfer {
|
||||||
transfer.to_jsval(*cx, val.handle_mut());
|
transfer.to_jsval(*cx, val.handle_mut());
|
||||||
}
|
}
|
||||||
|
let mut sc_holder = StructuredDataHolder::Write {
|
||||||
let mut sc_holder = StructuredDataHolder::Write(None);
|
ports: None,
|
||||||
|
blobs: None,
|
||||||
|
};
|
||||||
let sc_holder_ptr = &mut sc_holder as *mut _;
|
let sc_holder_ptr = &mut sc_holder as *mut _;
|
||||||
|
|
||||||
let scbuf = NewJSAutoStructuredCloneBuffer(
|
let scbuf = NewJSAutoStructuredCloneBuffer(
|
||||||
|
@ -343,14 +308,15 @@ pub fn write(
|
||||||
|
|
||||||
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
||||||
|
|
||||||
let mut port_impls = match sc_holder {
|
let (mut blob_impls, mut port_impls) = match sc_holder {
|
||||||
StructuredDataHolder::Write(port_impls) => port_impls,
|
StructuredDataHolder::Write { blobs, ports } => (blobs, ports),
|
||||||
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = StructuredSerializedData {
|
let data = StructuredSerializedData {
|
||||||
serialized: data,
|
serialized: data,
|
||||||
ports: port_impls.take(),
|
ports: port_impls.take(),
|
||||||
|
blobs: blob_impls.take(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
|
@ -367,9 +333,10 @@ pub fn read(
|
||||||
let cx = global.get_cx();
|
let cx = global.get_cx();
|
||||||
let _ac = enter_realm(&*global);
|
let _ac = enter_realm(&*global);
|
||||||
let mut sc_holder = StructuredDataHolder::Read {
|
let mut sc_holder = StructuredDataHolder::Read {
|
||||||
blob: None,
|
blobs: None,
|
||||||
message_ports: None,
|
message_ports: None,
|
||||||
port_impls: data.ports.take(),
|
port_impls: data.ports.take(),
|
||||||
|
blob_impls: data.blobs.take(),
|
||||||
};
|
};
|
||||||
let sc_holder_ptr = &mut sc_holder as *mut _;
|
let sc_holder_ptr = &mut sc_holder as *mut _;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -79,7 +79,7 @@ use media::WindowGLContext;
|
||||||
use metrics::{InteractiveMetrics, InteractiveWindow};
|
use metrics::{InteractiveMetrics, InteractiveWindow};
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use msg::constellation_msg::{
|
use msg::constellation_msg::{
|
||||||
BrowsingContextId, HistoryStateId, MessagePortId, MessagePortRouterId, PipelineId,
|
BlobId, BrowsingContextId, HistoryStateId, MessagePortId, MessagePortRouterId, PipelineId,
|
||||||
TopLevelBrowsingContextId,
|
TopLevelBrowsingContextId,
|
||||||
};
|
};
|
||||||
use net_traits::filemanager_thread::RelativePos;
|
use net_traits::filemanager_thread::RelativePos;
|
||||||
|
@ -94,6 +94,7 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||||
use script_layout_interface::rpc::LayoutRPC;
|
use script_layout_interface::rpc::LayoutRPC;
|
||||||
use script_layout_interface::OpaqueStyleAndLayoutData;
|
use script_layout_interface::OpaqueStyleAndLayoutData;
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use script_traits::transferable::MessagePortImpl;
|
use script_traits::transferable::MessagePortImpl;
|
||||||
use script_traits::{DocumentActivity, DrawAPaintImageResult};
|
use script_traits::{DocumentActivity, DrawAPaintImageResult};
|
||||||
use script_traits::{MediaSessionActionType, ScriptToConstellationChan, TimerEventId, TimerSource};
|
use script_traits::{MediaSessionActionType, ScriptToConstellationChan, TimerEventId, TimerSource};
|
||||||
|
@ -164,6 +165,9 @@ unsafe_no_jsmanaged_fields!(MessagePortId);
|
||||||
unsafe_no_jsmanaged_fields!(RefCell<Option<MessagePortId>>);
|
unsafe_no_jsmanaged_fields!(RefCell<Option<MessagePortId>>);
|
||||||
unsafe_no_jsmanaged_fields!(MessagePortRouterId);
|
unsafe_no_jsmanaged_fields!(MessagePortRouterId);
|
||||||
|
|
||||||
|
unsafe_no_jsmanaged_fields!(BlobId);
|
||||||
|
unsafe_no_jsmanaged_fields!(BlobImpl);
|
||||||
|
|
||||||
unsafe_no_jsmanaged_fields!(CSSError);
|
unsafe_no_jsmanaged_fields!(CSSError);
|
||||||
|
|
||||||
unsafe_no_jsmanaged_fields!(&'static Encoding);
|
unsafe_no_jsmanaged_fields!(&'static Encoding);
|
||||||
|
|
|
@ -2,119 +2,53 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
|
||||||
use crate::dom::bindings::codegen::Bindings::BlobBinding;
|
use crate::dom::bindings::codegen::Bindings::BlobBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
use crate::dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
||||||
use crate::dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString;
|
use crate::dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString;
|
||||||
use crate::dom::bindings::error::{Error, Fallible};
|
use crate::dom::bindings::error::{Error, Fallible};
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::bindings::serializable::{Serializable, StorageKey};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
|
use crate::dom::bindings::structuredclone::StructuredDataHolder;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use net_traits::blob_url_store::{get_blob_origin, BlobBuf};
|
use msg::constellation_msg::{BlobId, BlobIndex, PipelineNamespaceId};
|
||||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
|
use net_traits::filemanager_thread::RelativePos;
|
||||||
use net_traits::{CoreResourceMsg, IpcSend};
|
use script_traits::serializable::BlobImpl;
|
||||||
use profile_traits::ipc;
|
use std::collections::HashMap;
|
||||||
use std::mem;
|
use std::num::NonZeroU32;
|
||||||
use std::ops::Index;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// File-based blob
|
|
||||||
#[derive(JSTraceable)]
|
|
||||||
pub struct FileBlob {
|
|
||||||
id: Uuid,
|
|
||||||
name: Option<PathBuf>,
|
|
||||||
cache: DomRefCell<Option<Vec<u8>>>,
|
|
||||||
size: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Different backends of Blob
|
|
||||||
#[unrooted_must_root_lint::must_root]
|
|
||||||
#[derive(JSTraceable)]
|
|
||||||
pub enum BlobImpl {
|
|
||||||
/// File-based blob, whose content lives in the net process
|
|
||||||
File(FileBlob),
|
|
||||||
/// Memory-based blob, whose content lives in the script process
|
|
||||||
Memory(Vec<u8>),
|
|
||||||
/// Sliced blob, including parent blob reference and
|
|
||||||
/// relative positions of current slicing range,
|
|
||||||
/// IMPORTANT: The depth of tree is only two, i.e. the parent Blob must be
|
|
||||||
/// either File-based or Memory-based
|
|
||||||
Sliced(Dom<Blob>, RelativePos),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlobImpl {
|
|
||||||
/// Construct memory-backed BlobImpl
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
pub fn new_from_bytes(bytes: Vec<u8>) -> BlobImpl {
|
|
||||||
BlobImpl::Memory(bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct file-backed BlobImpl from File ID
|
|
||||||
pub fn new_from_file(file_id: Uuid, name: PathBuf, size: u64) -> BlobImpl {
|
|
||||||
BlobImpl::File(FileBlob {
|
|
||||||
id: file_id,
|
|
||||||
name: Some(name),
|
|
||||||
cache: DomRefCell::new(None),
|
|
||||||
size: size,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#blob
|
// https://w3c.github.io/FileAPI/#blob
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct Blob {
|
pub struct Blob {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
#[ignore_malloc_size_of = "No clear owner"]
|
blob_id: BlobId,
|
||||||
blob_impl: DomRefCell<BlobImpl>,
|
|
||||||
/// content-type string
|
|
||||||
type_string: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Blob {
|
impl Blob {
|
||||||
#[allow(unrooted_must_root)]
|
pub fn new(global: &GlobalScope, blob_impl: BlobImpl) -> DomRoot<Blob> {
|
||||||
pub fn new(global: &GlobalScope, blob_impl: BlobImpl, typeString: String) -> DomRoot<Blob> {
|
let dom_blob = reflect_dom_object(
|
||||||
let boxed_blob = Box::new(Blob::new_inherited(blob_impl, typeString));
|
Box::new(Blob {
|
||||||
reflect_dom_object(boxed_blob, global, BlobBinding::Wrap)
|
reflector_: Reflector::new(),
|
||||||
|
blob_id: blob_impl.blob_id(),
|
||||||
|
}),
|
||||||
|
global,
|
||||||
|
BlobBinding::Wrap,
|
||||||
|
);
|
||||||
|
global.track_blob(&dom_blob, blob_impl);
|
||||||
|
dom_blob
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new_inherited(blob_impl: BlobImpl, type_string: String) -> Blob {
|
pub fn new_inherited(blob_impl: &BlobImpl) -> Blob {
|
||||||
Blob {
|
Blob {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
blob_impl: DomRefCell::new(blob_impl),
|
blob_id: blob_impl.blob_id(),
|
||||||
// NOTE: Guarding the format correctness here,
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-type
|
|
||||||
type_string: normalize_type_string(&type_string),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
fn new_sliced(
|
|
||||||
parent: &Blob,
|
|
||||||
rel_pos: RelativePos,
|
|
||||||
relative_content_type: DOMString,
|
|
||||||
) -> DomRoot<Blob> {
|
|
||||||
let blob_impl = match *parent.blob_impl.borrow() {
|
|
||||||
BlobImpl::File(_) => {
|
|
||||||
// Create new parent node
|
|
||||||
BlobImpl::Sliced(Dom::from_ref(parent), rel_pos)
|
|
||||||
},
|
|
||||||
BlobImpl::Memory(_) => {
|
|
||||||
// Create new parent node
|
|
||||||
BlobImpl::Sliced(Dom::from_ref(parent), rel_pos)
|
|
||||||
},
|
|
||||||
BlobImpl::Sliced(ref grandparent, ref old_rel_pos) => {
|
|
||||||
// Adjust the slicing position, using same parent
|
|
||||||
BlobImpl::Sliced(grandparent.clone(), old_rel_pos.slice_inner(&rel_pos))
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Blob::new(&parent.global(), blob_impl, relative_content_type.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#constructorBlob
|
// https://w3c.github.io/FileAPI/#constructorBlob
|
||||||
pub fn Constructor(
|
pub fn Constructor(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
|
@ -130,212 +64,107 @@ impl Blob {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Blob::new(
|
let type_string = normalize_type_string(&blobPropertyBag.type_.to_string());
|
||||||
global,
|
let blob_impl = BlobImpl::new_from_bytes(bytes, type_string);
|
||||||
BlobImpl::new_from_bytes(bytes),
|
|
||||||
blobPropertyBag.type_.to_string(),
|
Ok(Blob::new(global, blob_impl))
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a slice to inner data, this might incur synchronous read and caching
|
/// Get a slice to inner data, this might incur synchronous read and caching
|
||||||
pub fn get_bytes(&self) -> Result<Vec<u8>, ()> {
|
pub fn get_bytes(&self) -> Result<Vec<u8>, ()> {
|
||||||
match *self.blob_impl.borrow() {
|
self.global().get_blob_bytes(&self.blob_id)
|
||||||
BlobImpl::File(ref f) => {
|
|
||||||
let (buffer, is_new_buffer) = match *f.cache.borrow() {
|
|
||||||
Some(ref bytes) => (bytes.clone(), false),
|
|
||||||
None => {
|
|
||||||
let bytes = read_file(&self.global(), f.id.clone())?;
|
|
||||||
(bytes, true)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cache
|
|
||||||
if is_new_buffer {
|
|
||||||
*f.cache.borrow_mut() = Some(buffer.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(buffer)
|
|
||||||
},
|
|
||||||
BlobImpl::Memory(ref s) => Ok(s.clone()),
|
|
||||||
BlobImpl::Sliced(ref parent, ref rel_pos) => parent.get_bytes().map(|v| {
|
|
||||||
let range = rel_pos.to_abs_range(v.len());
|
|
||||||
v.index(range).to_vec()
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a copy of the type_string
|
/// Get a copy of the type_string
|
||||||
pub fn type_string(&self) -> String {
|
pub fn type_string(&self) -> String {
|
||||||
self.type_string.clone()
|
self.global().get_blob_type_string(&self.blob_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a FileID representing the Blob content,
|
/// Get a FileID representing the Blob content,
|
||||||
/// used by URL.createObjectURL
|
/// used by URL.createObjectURL
|
||||||
pub fn get_blob_url_id(&self) -> Uuid {
|
pub fn get_blob_url_id(&self) -> Uuid {
|
||||||
let opt_sliced_parent = match *self.blob_impl.borrow() {
|
self.global().get_blob_url_id(&self.blob_id)
|
||||||
BlobImpl::Sliced(ref parent, ref rel_pos) => {
|
}
|
||||||
Some((
|
}
|
||||||
parent.promote(/* set_valid is */ false),
|
|
||||||
rel_pos.clone(),
|
impl Serializable for Blob {
|
||||||
parent.Size(),
|
/// <https://w3c.github.io/FileAPI/#ref-for-serialization-steps>
|
||||||
))
|
fn serialize(&self, sc_holder: &mut StructuredDataHolder) -> Result<StorageKey, ()> {
|
||||||
},
|
let blob_impls = match sc_holder {
|
||||||
_ => None,
|
StructuredDataHolder::Write { blobs, .. } => blobs,
|
||||||
|
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
||||||
};
|
};
|
||||||
|
|
||||||
match opt_sliced_parent {
|
let blob_id = self.blob_id.clone();
|
||||||
Some((parent_id, rel_pos, size)) => {
|
|
||||||
self.create_sliced_url_id(&parent_id, &rel_pos, size)
|
// 1. Get a clone of the blob impl.
|
||||||
},
|
let blob_impl = self.global().serialize_blob(&blob_id);
|
||||||
None => self.promote(/* set_valid is */ true),
|
|
||||||
}
|
// We clone the data, but the clone gets its own Id.
|
||||||
|
let new_blob_id = blob_impl.blob_id();
|
||||||
|
|
||||||
|
// 2. Store the object at a given key.
|
||||||
|
let blobs = blob_impls.get_or_insert_with(|| HashMap::new());
|
||||||
|
blobs.insert(new_blob_id.clone(), blob_impl);
|
||||||
|
|
||||||
|
let PipelineNamespaceId(name_space) = new_blob_id.namespace_id;
|
||||||
|
let BlobIndex(index) = new_blob_id.index;
|
||||||
|
let index = index.get();
|
||||||
|
|
||||||
|
let name_space = name_space.to_ne_bytes();
|
||||||
|
let index = index.to_ne_bytes();
|
||||||
|
|
||||||
|
let storage_key = StorageKey {
|
||||||
|
index: u32::from_ne_bytes(index),
|
||||||
|
name_space: u32::from_ne_bytes(name_space),
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. Return the storage key.
|
||||||
|
Ok(storage_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Promote non-Slice blob:
|
/// <https://w3c.github.io/FileAPI/#ref-for-deserialization-steps>
|
||||||
/// 1. Memory-based: The bytes in data slice will be transferred to file manager thread.
|
fn deserialize(
|
||||||
/// 2. File-based: If set_valid, then activate the FileID so it can serve as URL
|
owner: &DomRoot<GlobalScope>,
|
||||||
/// Depending on set_valid, the returned FileID can be part of
|
sc_holder: &mut StructuredDataHolder,
|
||||||
/// valid or invalid Blob URL.
|
storage_key: StorageKey,
|
||||||
fn promote(&self, set_valid: bool) -> Uuid {
|
) -> Result<(), ()> {
|
||||||
let mut bytes = vec![];
|
// 1. Re-build the key for the storage location
|
||||||
let global_url = self.global().get_url();
|
// of the serialized object.
|
||||||
|
let namespace_id = PipelineNamespaceId(storage_key.name_space.clone());
|
||||||
match *self.blob_impl.borrow_mut() {
|
let index = BlobIndex(
|
||||||
BlobImpl::Sliced(_, _) => {
|
NonZeroU32::new(storage_key.index.clone()).expect("Deserialized blob index is zero"),
|
||||||
debug!("Sliced can't have a sliced parent");
|
|
||||||
// Return dummy id
|
|
||||||
return Uuid::new_v4();
|
|
||||||
},
|
|
||||||
BlobImpl::File(ref f) => {
|
|
||||||
if set_valid {
|
|
||||||
let origin = get_blob_origin(&global_url);
|
|
||||||
let (tx, rx) =
|
|
||||||
ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
|
||||||
|
|
||||||
let msg =
|
|
||||||
FileManagerThreadMsg::ActivateBlobURL(f.id.clone(), tx, origin.clone());
|
|
||||||
self.send_to_file_manager(msg);
|
|
||||||
|
|
||||||
match rx.recv().unwrap() {
|
|
||||||
Ok(_) => return f.id.clone(),
|
|
||||||
// Return a dummy id on error
|
|
||||||
Err(_) => return Uuid::new_v4(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// no need to activate
|
|
||||||
return f.id.clone();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
BlobImpl::Memory(ref mut bytes_in) => mem::swap(bytes_in, &mut bytes),
|
|
||||||
};
|
|
||||||
|
|
||||||
let origin = get_blob_origin(&global_url);
|
|
||||||
|
|
||||||
let blob_buf = BlobBuf {
|
|
||||||
filename: None,
|
|
||||||
type_string: self.type_string.clone(),
|
|
||||||
size: bytes.len() as u64,
|
|
||||||
bytes: bytes.to_vec(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let id = Uuid::new_v4();
|
|
||||||
let msg = FileManagerThreadMsg::PromoteMemory(id, blob_buf, set_valid, origin.clone());
|
|
||||||
self.send_to_file_manager(msg);
|
|
||||||
|
|
||||||
*self.blob_impl.borrow_mut() = BlobImpl::File(FileBlob {
|
|
||||||
id: id.clone(),
|
|
||||||
name: None,
|
|
||||||
cache: DomRefCell::new(Some(bytes.to_vec())),
|
|
||||||
size: bytes.len() as u64,
|
|
||||||
});
|
|
||||||
id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a FileID representing sliced parent-blob content
|
|
||||||
fn create_sliced_url_id(
|
|
||||||
&self,
|
|
||||||
parent_id: &Uuid,
|
|
||||||
rel_pos: &RelativePos,
|
|
||||||
parent_len: u64,
|
|
||||||
) -> Uuid {
|
|
||||||
let origin = get_blob_origin(&self.global().get_url());
|
|
||||||
|
|
||||||
let (tx, rx) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
|
||||||
let msg = FileManagerThreadMsg::AddSlicedURLEntry(
|
|
||||||
parent_id.clone(),
|
|
||||||
rel_pos.clone(),
|
|
||||||
tx,
|
|
||||||
origin.clone(),
|
|
||||||
);
|
);
|
||||||
self.send_to_file_manager(msg);
|
|
||||||
match rx.recv().expect("File manager thread is down") {
|
|
||||||
Ok(new_id) => {
|
|
||||||
*self.blob_impl.borrow_mut() = BlobImpl::File(FileBlob {
|
|
||||||
id: new_id.clone(),
|
|
||||||
name: None,
|
|
||||||
cache: DomRefCell::new(None),
|
|
||||||
size: rel_pos.to_abs_range(parent_len as usize).len() as u64,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return the indirect id reference
|
let id = BlobId {
|
||||||
new_id
|
namespace_id,
|
||||||
},
|
index,
|
||||||
Err(_) => {
|
};
|
||||||
// Return dummy id
|
|
||||||
Uuid::new_v4()
|
let (blobs, blob_impls) = match sc_holder {
|
||||||
},
|
StructuredDataHolder::Read {
|
||||||
|
blobs, blob_impls, ..
|
||||||
|
} => (blobs, blob_impls),
|
||||||
|
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Get the transferred object from its storage, using the key.
|
||||||
|
let blob_impls_map = blob_impls
|
||||||
|
.as_mut()
|
||||||
|
.expect("The SC holder does not have any blob impls");
|
||||||
|
let blob_impl = blob_impls_map
|
||||||
|
.remove(&id)
|
||||||
|
.expect("No blob to be deserialized found.");
|
||||||
|
if blob_impls_map.is_empty() {
|
||||||
|
*blob_impls = None;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Cleanups at the time of destruction/closing
|
let deserialized_blob = Blob::new(&**owner, blob_impl);
|
||||||
fn clean_up_file_resource(&self) {
|
|
||||||
if let BlobImpl::File(ref f) = *self.blob_impl.borrow() {
|
|
||||||
let origin = get_blob_origin(&self.global().get_url());
|
|
||||||
|
|
||||||
let (tx, rx) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
let blobs = blobs.get_or_insert_with(|| HashMap::new());
|
||||||
|
blobs.insert(storage_key, deserialized_blob);
|
||||||
|
|
||||||
let msg = FileManagerThreadMsg::DecRef(f.id.clone(), origin, tx);
|
Ok(())
|
||||||
self.send_to_file_manager(msg);
|
|
||||||
let _ = rx.recv();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_to_file_manager(&self, msg: FileManagerThreadMsg) {
|
|
||||||
let global = self.global();
|
|
||||||
let resource_threads = global.resource_threads();
|
|
||||||
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Blob {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.clean_up_file_resource();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_file(global: &GlobalScope, id: Uuid) -> Result<Vec<u8>, ()> {
|
|
||||||
let resource_threads = global.resource_threads();
|
|
||||||
let (chan, recv) = ipc::channel(global.time_profiler_chan().clone()).map_err(|_| ())?;
|
|
||||||
let origin = get_blob_origin(&global.get_url());
|
|
||||||
let check_url_validity = false;
|
|
||||||
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
|
|
||||||
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
|
||||||
|
|
||||||
let mut bytes = vec![];
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match recv.recv().unwrap() {
|
|
||||||
Ok(ReadFileProgress::Meta(mut blob_buf)) => {
|
|
||||||
bytes.append(&mut blob_buf.bytes);
|
|
||||||
},
|
|
||||||
Ok(ReadFileProgress::Partial(mut bytes_in)) => {
|
|
||||||
bytes.append(&mut bytes_in);
|
|
||||||
},
|
|
||||||
Ok(ReadFileProgress::EOF) => {
|
|
||||||
return Ok(bytes);
|
|
||||||
},
|
|
||||||
Err(_) => return Err(()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,18 +201,12 @@ pub fn blob_parts_to_bytes(
|
||||||
impl BlobMethods for Blob {
|
impl BlobMethods for Blob {
|
||||||
// https://w3c.github.io/FileAPI/#dfn-size
|
// https://w3c.github.io/FileAPI/#dfn-size
|
||||||
fn Size(&self) -> u64 {
|
fn Size(&self) -> u64 {
|
||||||
match *self.blob_impl.borrow() {
|
self.global().get_blob_size(&self.blob_id)
|
||||||
BlobImpl::File(ref f) => f.size,
|
|
||||||
BlobImpl::Memory(ref v) => v.len() as u64,
|
|
||||||
BlobImpl::Sliced(ref parent, ref rel_pos) => {
|
|
||||||
rel_pos.to_abs_range(parent.Size() as usize).len() as u64
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-type
|
// https://w3c.github.io/FileAPI/#dfn-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
DOMString::from(self.type_string.clone())
|
DOMString::from(self.type_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#slice-method-algo
|
// https://w3c.github.io/FileAPI/#slice-method-algo
|
||||||
|
@ -393,8 +216,11 @@ impl BlobMethods for Blob {
|
||||||
end: Option<i64>,
|
end: Option<i64>,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
) -> DomRoot<Blob> {
|
) -> DomRoot<Blob> {
|
||||||
|
let type_string =
|
||||||
|
normalize_type_string(&content_type.unwrap_or(DOMString::from("")).to_string());
|
||||||
let rel_pos = RelativePos::from_opts(start, end);
|
let rel_pos = RelativePos::from_opts(start, end);
|
||||||
Blob::new_sliced(self, rel_pos, content_type.unwrap_or(DOMString::from("")))
|
let blob_impl = BlobImpl::new_sliced(rel_pos, self.blob_id.clone(), type_string);
|
||||||
|
Blob::new(&*self.global(), blob_impl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +229,7 @@ impl BlobMethods for Blob {
|
||||||
/// XXX: We will relax the restriction here,
|
/// XXX: We will relax the restriction here,
|
||||||
/// since the spec has some problem over this part.
|
/// since the spec has some problem over this part.
|
||||||
/// see https://github.com/w3c/FileAPI/issues/43
|
/// see https://github.com/w3c/FileAPI/issues/43
|
||||||
fn normalize_type_string(s: &str) -> String {
|
pub fn normalize_type_string(s: &str) -> String {
|
||||||
if is_ascii_printable(s) {
|
if is_ascii_printable(s) {
|
||||||
let s_lower = s.to_ascii_lowercase();
|
let s_lower = s.to_ascii_lowercase();
|
||||||
// match s_lower.parse() as Result<Mime, ()> {
|
// match s_lower.parse() as Result<Mime, ()> {
|
||||||
|
|
|
@ -556,7 +556,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
Some(pipeline_id),
|
Some(pipeline_id),
|
||||||
TaskSourceName::DOMManipulation,
|
TaskSourceName::DOMManipulation,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.expect("Sending to parent failed");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1921,6 +1921,9 @@ impl Document {
|
||||||
let msg = ScriptMsg::DiscardDocument;
|
let msg = ScriptMsg::DiscardDocument;
|
||||||
let _ = global_scope.script_to_constellation_chan().send(msg);
|
let _ = global_scope.script_to_constellation_chan().send(msg);
|
||||||
}
|
}
|
||||||
|
// https://w3c.github.io/FileAPI/#lifeTime
|
||||||
|
global_scope.clean_up_all_file_resources();
|
||||||
|
|
||||||
// Step 15, End
|
// Step 15, End
|
||||||
self.decr_ignore_opens_during_unload_counter();
|
self.decr_ignore_opens_during_unload_counter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,12 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::blob::{blob_parts_to_bytes, Blob, BlobImpl};
|
use crate::dom::blob::{blob_parts_to_bytes, normalize_type_string, Blob};
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use net_traits::filemanager_thread::SelectedFile;
|
use net_traits::filemanager_thread::SelectedFile;
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
|
@ -25,14 +26,9 @@ pub struct File {
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn new_inherited(
|
fn new_inherited(blob_impl: &BlobImpl, name: DOMString, modified: Option<i64>) -> File {
|
||||||
blob_impl: BlobImpl,
|
|
||||||
name: DOMString,
|
|
||||||
modified: Option<i64>,
|
|
||||||
type_string: &str,
|
|
||||||
) -> File {
|
|
||||||
File {
|
File {
|
||||||
blob: Blob::new_inherited(blob_impl, type_string.to_owned()),
|
blob: Blob::new_inherited(blob_impl),
|
||||||
name: name,
|
name: name,
|
||||||
// https://w3c.github.io/FileAPI/#dfn-lastModified
|
// https://w3c.github.io/FileAPI/#dfn-lastModified
|
||||||
modified: match modified {
|
modified: match modified {
|
||||||
|
@ -51,13 +47,14 @@ impl File {
|
||||||
blob_impl: BlobImpl,
|
blob_impl: BlobImpl,
|
||||||
name: DOMString,
|
name: DOMString,
|
||||||
modified: Option<i64>,
|
modified: Option<i64>,
|
||||||
typeString: &str,
|
|
||||||
) -> DomRoot<File> {
|
) -> DomRoot<File> {
|
||||||
reflect_dom_object(
|
let file = reflect_dom_object(
|
||||||
Box::new(File::new_inherited(blob_impl, name, modified, typeString)),
|
Box::new(File::new_inherited(&blob_impl, name, modified)),
|
||||||
global,
|
global,
|
||||||
FileBinding::Wrap,
|
FileBinding::Wrap,
|
||||||
)
|
);
|
||||||
|
global.track_file(&file, blob_impl);
|
||||||
|
file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct from selected file message from file manager thread
|
// Construct from selected file message from file manager thread
|
||||||
|
@ -71,10 +68,14 @@ impl File {
|
||||||
|
|
||||||
File::new(
|
File::new(
|
||||||
window.upcast(),
|
window.upcast(),
|
||||||
BlobImpl::new_from_file(selected.id, selected.filename, selected.size),
|
BlobImpl::new_from_file(
|
||||||
|
selected.id,
|
||||||
|
selected.filename,
|
||||||
|
selected.size,
|
||||||
|
normalize_type_string(&selected.type_string.to_string()),
|
||||||
|
),
|
||||||
name,
|
name,
|
||||||
Some(selected.modified as i64),
|
Some(selected.modified as i64),
|
||||||
&selected.type_string,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,18 +92,17 @@ impl File {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ref blobPropertyBag = filePropertyBag.parent;
|
let ref blobPropertyBag = filePropertyBag.parent;
|
||||||
let ref typeString = blobPropertyBag.type_;
|
|
||||||
|
|
||||||
let modified = filePropertyBag.lastModified;
|
let modified = filePropertyBag.lastModified;
|
||||||
// NOTE: Following behaviour might be removed in future,
|
// NOTE: Following behaviour might be removed in future,
|
||||||
// see https://github.com/w3c/FileAPI/issues/41
|
// see https://github.com/w3c/FileAPI/issues/41
|
||||||
let replaced_filename = DOMString::from_string(filename.replace("/", ":"));
|
let replaced_filename = DOMString::from_string(filename.replace("/", ":"));
|
||||||
|
let type_string = normalize_type_string(&blobPropertyBag.type_.to_string());
|
||||||
Ok(File::new(
|
Ok(File::new(
|
||||||
global,
|
global,
|
||||||
BlobImpl::new_from_bytes(bytes),
|
BlobImpl::new_from_bytes(bytes, type_string),
|
||||||
replaced_filename,
|
replaced_filename,
|
||||||
modified,
|
modified,
|
||||||
typeString,
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,13 @@ use crate::dom::bindings::iterable::Iterable;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::{DOMString, USVString};
|
use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::Blob;
|
||||||
use crate::dom::file::File;
|
use crate::dom::file::File;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::htmlformelement::{FormDatum, FormDatumValue, HTMLFormElement};
|
use crate::dom::htmlformelement::{FormDatum, FormDatumValue, HTMLFormElement};
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use html5ever::LocalName;
|
use html5ever::LocalName;
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct FormData {
|
pub struct FormData {
|
||||||
|
@ -195,10 +196,9 @@ impl FormData {
|
||||||
|
|
||||||
File::new(
|
File::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(bytes),
|
BlobImpl::new_from_bytes(bytes, blob.type_string()),
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
&blob.type_string(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,14 @@ use crate::dom::bindings::settings_stack::{entry_global, incumbent_global, AutoE
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::bindings::structuredclone;
|
use crate::dom::bindings::structuredclone;
|
||||||
use crate::dom::bindings::weakref::{DOMTracker, WeakRef};
|
use crate::dom::bindings::weakref::{DOMTracker, WeakRef};
|
||||||
|
use crate::dom::blob::Blob;
|
||||||
use crate::dom::crypto::Crypto;
|
use crate::dom::crypto::Crypto;
|
||||||
use crate::dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
use crate::dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||||
use crate::dom::errorevent::ErrorEvent;
|
use crate::dom::errorevent::ErrorEvent;
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
||||||
use crate::dom::eventsource::EventSource;
|
use crate::dom::eventsource::EventSource;
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
|
use crate::dom::file::File;
|
||||||
use crate::dom::messageevent::MessageEvent;
|
use crate::dom::messageevent::MessageEvent;
|
||||||
use crate::dom::messageport::MessagePort;
|
use crate::dom::messageport::MessagePort;
|
||||||
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||||
|
@ -61,10 +63,13 @@ use js::rust::wrappers::EvaluateUtf8;
|
||||||
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
|
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
|
||||||
use js::rust::{HandleValue, MutableHandleValue};
|
use js::rust::{HandleValue, MutableHandleValue};
|
||||||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||||
use msg::constellation_msg::{MessagePortId, MessagePortRouterId, PipelineId};
|
use msg::constellation_msg::{BlobId, MessagePortId, MessagePortRouterId, PipelineId};
|
||||||
|
use net_traits::blob_url_store::{get_blob_origin, BlobBuf};
|
||||||
|
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress, RelativePos};
|
||||||
use net_traits::image_cache::ImageCache;
|
use net_traits::image_cache::ImageCache;
|
||||||
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
|
use net_traits::{CoreResourceMsg, CoreResourceThread, IpcSend, ResourceThreads};
|
||||||
use profile_traits::{mem as profile_mem, time as profile_time};
|
use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
|
||||||
|
use script_traits::serializable::{BlobData, BlobImpl, FileBlob};
|
||||||
use script_traits::transferable::MessagePortImpl;
|
use script_traits::transferable::MessagePortImpl;
|
||||||
use script_traits::{
|
use script_traits::{
|
||||||
MessagePortMsg, MsDuration, PortMessageTask, ScriptMsg, ScriptToConstellationChan, TimerEvent,
|
MessagePortMsg, MsDuration, PortMessageTask, ScriptMsg, ScriptToConstellationChan, TimerEvent,
|
||||||
|
@ -76,10 +81,13 @@ use std::cell::Cell;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
use std::mem;
|
||||||
|
use std::ops::Index;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use time::{get_time, Timespec};
|
use time::{get_time, Timespec};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(JSTraceable)]
|
#[derive(JSTraceable)]
|
||||||
pub struct AutoCloseWorker(Arc<AtomicBool>);
|
pub struct AutoCloseWorker(Arc<AtomicBool>);
|
||||||
|
@ -99,6 +107,9 @@ pub struct GlobalScope {
|
||||||
/// The message-port router id for this global, if it is managing ports.
|
/// The message-port router id for this global, if it is managing ports.
|
||||||
message_port_state: DomRefCell<MessagePortState>,
|
message_port_state: DomRefCell<MessagePortState>,
|
||||||
|
|
||||||
|
/// The blobs managed by this global, if any.
|
||||||
|
blob_state: DomRefCell<BlobState>,
|
||||||
|
|
||||||
/// Pipeline id associated with this global.
|
/// Pipeline id associated with this global.
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
|
|
||||||
|
@ -201,6 +212,36 @@ struct TimerListener {
|
||||||
context: Trusted<GlobalScope>,
|
context: Trusted<GlobalScope>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
/// A holder of a weak reference for a DOM blob or file.
|
||||||
|
pub enum BlobTracker {
|
||||||
|
/// A weak ref to a DOM file.
|
||||||
|
File(WeakRef<File>),
|
||||||
|
/// A weak ref to a DOM blob.
|
||||||
|
Blob(WeakRef<Blob>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
/// The info pertaining to a blob managed by this global.
|
||||||
|
pub struct BlobInfo {
|
||||||
|
/// The weak ref to the corresponding DOM object.
|
||||||
|
tracker: BlobTracker,
|
||||||
|
/// The data and logic backing the DOM object.
|
||||||
|
blob_impl: BlobImpl,
|
||||||
|
/// Whether this blob has an outstanding URL,
|
||||||
|
/// <https://w3c.github.io/FileAPI/#url>.
|
||||||
|
has_url: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// State representing whether this global is currently managing blobs.
|
||||||
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
pub enum BlobState {
|
||||||
|
/// A map of managed blobs.
|
||||||
|
Managed(HashMap<BlobId, BlobInfo>),
|
||||||
|
/// This global is not managing any blobs at this time.
|
||||||
|
UnManaged,
|
||||||
|
}
|
||||||
|
|
||||||
/// Data representing a message-port managed by this global.
|
/// Data representing a message-port managed by this global.
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
pub enum ManagedMessagePort {
|
pub enum ManagedMessagePort {
|
||||||
|
@ -345,6 +386,7 @@ impl GlobalScope {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
message_port_state: DomRefCell::new(MessagePortState::UnManaged),
|
message_port_state: DomRefCell::new(MessagePortState::UnManaged),
|
||||||
|
blob_state: DomRefCell::new(BlobState::UnManaged),
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
crypto: Default::default(),
|
crypto: Default::default(),
|
||||||
next_worker_id: Cell::new(WorkerId(0)),
|
next_worker_id: Cell::new(WorkerId(0)),
|
||||||
|
@ -445,6 +487,12 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clean-up DOM related resources
|
||||||
|
pub fn perform_a_dom_garbage_collection_checkpoint(&self) {
|
||||||
|
self.perform_a_message_port_garbage_collection_checkpoint();
|
||||||
|
self.perform_a_blob_garbage_collection_checkpoint();
|
||||||
|
}
|
||||||
|
|
||||||
/// Update our state to un-managed,
|
/// Update our state to un-managed,
|
||||||
/// and tell the constellation to drop the sender to our message-port router.
|
/// and tell the constellation to drop the sender to our message-port router.
|
||||||
pub fn remove_message_ports_router(&self) {
|
pub fn remove_message_ports_router(&self) {
|
||||||
|
@ -814,6 +862,400 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://html.spec.whatwg.org/multipage/#serialization-steps>
|
||||||
|
/// defined at <https://w3c.github.io/FileAPI/#blob-section>.
|
||||||
|
/// Get the snapshot state and underlying bytes of the blob.
|
||||||
|
pub fn serialize_blob(&self, blob_id: &BlobId) -> BlobImpl {
|
||||||
|
// Note: we combine the snapshot state and underlying bytes into one call,
|
||||||
|
// which seems spec compliant.
|
||||||
|
// See https://w3c.github.io/FileAPI/#snapshot-state
|
||||||
|
let bytes = self
|
||||||
|
.get_blob_bytes(blob_id)
|
||||||
|
.expect("Could not read bytes from blob as part of serialization steps.");
|
||||||
|
let type_string = self.get_blob_type_string(blob_id);
|
||||||
|
|
||||||
|
// Note: the new BlobImpl is a clone, but with it's own BlobId.
|
||||||
|
BlobImpl::new_from_bytes(bytes, type_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn track_blob_info(&self, blob_info: BlobInfo, blob_id: BlobId) {
|
||||||
|
let mut blob_state = self.blob_state.borrow_mut();
|
||||||
|
|
||||||
|
match &mut *blob_state {
|
||||||
|
BlobState::UnManaged => {
|
||||||
|
let mut blobs_map = HashMap::new();
|
||||||
|
blobs_map.insert(blob_id, blob_info);
|
||||||
|
*blob_state = BlobState::Managed(blobs_map);
|
||||||
|
},
|
||||||
|
BlobState::Managed(blobs_map) => {
|
||||||
|
blobs_map.insert(blob_id, blob_info);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start tracking a blob
|
||||||
|
pub fn track_blob(&self, dom_blob: &DomRoot<Blob>, blob_impl: BlobImpl) {
|
||||||
|
let blob_id = blob_impl.blob_id();
|
||||||
|
|
||||||
|
let blob_info = BlobInfo {
|
||||||
|
blob_impl,
|
||||||
|
tracker: BlobTracker::Blob(WeakRef::new(dom_blob)),
|
||||||
|
has_url: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.track_blob_info(blob_info, blob_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start tracking a file
|
||||||
|
pub fn track_file(&self, file: &DomRoot<File>, blob_impl: BlobImpl) {
|
||||||
|
let blob_id = blob_impl.blob_id();
|
||||||
|
|
||||||
|
let blob_info = BlobInfo {
|
||||||
|
blob_impl,
|
||||||
|
tracker: BlobTracker::File(WeakRef::new(file)),
|
||||||
|
has_url: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.track_blob_info(blob_info, blob_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clean-up any file or blob that is unreachable from script,
|
||||||
|
/// unless it has an oustanding blob url.
|
||||||
|
/// <https://w3c.github.io/FileAPI/#lifeTime>
|
||||||
|
fn perform_a_blob_garbage_collection_checkpoint(&self) {
|
||||||
|
let mut blob_state = self.blob_state.borrow_mut();
|
||||||
|
if let BlobState::Managed(blobs_map) = &mut *blob_state {
|
||||||
|
blobs_map.retain(|_id, blob_info| {
|
||||||
|
let garbage_collected = match &blob_info.tracker {
|
||||||
|
BlobTracker::File(weak) => weak.root().is_none(),
|
||||||
|
BlobTracker::Blob(weak) => weak.root().is_none(),
|
||||||
|
};
|
||||||
|
if garbage_collected && !blob_info.has_url {
|
||||||
|
if let BlobData::File(ref f) = blob_info.blob_impl.blob_data() {
|
||||||
|
self.decrement_file_ref(f.get_id());
|
||||||
|
}
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if blobs_map.is_empty() {
|
||||||
|
*blob_state = BlobState::UnManaged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clean-up all file related resources on document unload.
|
||||||
|
/// <https://w3c.github.io/FileAPI/#lifeTime>
|
||||||
|
pub fn clean_up_all_file_resources(&self) {
|
||||||
|
let mut blob_state = self.blob_state.borrow_mut();
|
||||||
|
if let BlobState::Managed(blobs_map) = &mut *blob_state {
|
||||||
|
blobs_map.drain().for_each(|(_id, blob_info)| {
|
||||||
|
if let BlobData::File(ref f) = blob_info.blob_impl.blob_data() {
|
||||||
|
self.decrement_file_ref(f.get_id());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
*blob_state = BlobState::UnManaged;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrement_file_ref(&self, id: Uuid) {
|
||||||
|
let origin = get_blob_origin(&self.get_url());
|
||||||
|
|
||||||
|
let (tx, rx) = profile_ipc::channel(self.time_profiler_chan().clone()).unwrap();
|
||||||
|
|
||||||
|
let msg = FileManagerThreadMsg::DecRef(id, origin, tx);
|
||||||
|
self.send_to_file_manager(msg);
|
||||||
|
let _ = rx.recv();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a slice to the inner data of a Blob,
|
||||||
|
/// In the case of a File-backed blob, this might incur synchronous read and caching.
|
||||||
|
pub fn get_blob_bytes(&self, blob_id: &BlobId) -> Result<Vec<u8>, ()> {
|
||||||
|
let parent = {
|
||||||
|
let blob_state = self.blob_state.borrow();
|
||||||
|
if let BlobState::Managed(blobs_map) = &*blob_state {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get(blob_id)
|
||||||
|
.expect("get_blob_bytes for an unknown blob.");
|
||||||
|
match blob_info.blob_impl.blob_data() {
|
||||||
|
BlobData::Sliced(ref parent, ref rel_pos) => {
|
||||||
|
Some((parent.clone(), rel_pos.clone()))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("get_blob_bytes called on a global not managing any blobs.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match parent {
|
||||||
|
Some((parent_id, rel_pos)) => self.get_blob_bytes_non_sliced(&parent_id).map(|v| {
|
||||||
|
let range = rel_pos.to_abs_range(v.len());
|
||||||
|
v.index(range).to_vec()
|
||||||
|
}),
|
||||||
|
None => self.get_blob_bytes_non_sliced(blob_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get bytes from a non-sliced blob
|
||||||
|
fn get_blob_bytes_non_sliced(&self, blob_id: &BlobId) -> Result<Vec<u8>, ()> {
|
||||||
|
let blob_state = self.blob_state.borrow();
|
||||||
|
if let BlobState::Managed(blobs_map) = &*blob_state {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get(blob_id)
|
||||||
|
.expect("get_blob_bytes_non_sliced called for a unknown blob.");
|
||||||
|
match blob_info.blob_impl.blob_data() {
|
||||||
|
BlobData::File(ref f) => {
|
||||||
|
let (buffer, is_new_buffer) = match f.get_cache() {
|
||||||
|
Some(bytes) => (bytes, false),
|
||||||
|
None => {
|
||||||
|
let bytes = self.read_file(f.get_id())?;
|
||||||
|
(bytes, true)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
if is_new_buffer {
|
||||||
|
f.cache_bytes(buffer.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(buffer)
|
||||||
|
},
|
||||||
|
BlobData::Memory(ref s) => Ok(s.clone()),
|
||||||
|
BlobData::Sliced(_, _) => panic!("This blob doesn't have a parent."),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("get_blob_bytes_non_sliced called on a global not managing any blobs.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a copy of the type_string of a blob.
|
||||||
|
pub fn get_blob_type_string(&self, blob_id: &BlobId) -> String {
|
||||||
|
let blob_state = self.blob_state.borrow();
|
||||||
|
if let BlobState::Managed(blobs_map) = &*blob_state {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get(blob_id)
|
||||||
|
.expect("get_blob_type_string called for a unknown blob.");
|
||||||
|
blob_info.blob_impl.type_string()
|
||||||
|
} else {
|
||||||
|
panic!("get_blob_type_string called on a global not managing any blobs.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://w3c.github.io/FileAPI/#dfn-size
|
||||||
|
pub fn get_blob_size(&self, blob_id: &BlobId) -> u64 {
|
||||||
|
let blob_state = self.blob_state.borrow();
|
||||||
|
if let BlobState::Managed(blobs_map) = &*blob_state {
|
||||||
|
let parent = {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get(blob_id)
|
||||||
|
.expect("get_blob_size called for a unknown blob.");
|
||||||
|
match blob_info.blob_impl.blob_data() {
|
||||||
|
BlobData::Sliced(ref parent, ref rel_pos) => {
|
||||||
|
Some((parent.clone(), rel_pos.clone()))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match parent {
|
||||||
|
Some((parent_id, rel_pos)) => {
|
||||||
|
let parent_info = blobs_map
|
||||||
|
.get(&parent_id)
|
||||||
|
.expect("Parent of blob whose size is unknown.");
|
||||||
|
let parent_size = match parent_info.blob_impl.blob_data() {
|
||||||
|
BlobData::File(ref f) => f.get_size(),
|
||||||
|
BlobData::Memory(ref v) => v.len() as u64,
|
||||||
|
BlobData::Sliced(_, _) => panic!("Blob ancestry should be only one level."),
|
||||||
|
};
|
||||||
|
rel_pos.to_abs_range(parent_size as usize).len() as u64
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let blob_info = blobs_map.get(blob_id).expect("Blob whose size is unknown.");
|
||||||
|
match blob_info.blob_impl.blob_data() {
|
||||||
|
BlobData::File(ref f) => f.get_size(),
|
||||||
|
BlobData::Memory(ref v) => v.len() as u64,
|
||||||
|
BlobData::Sliced(_, _) => panic!(
|
||||||
|
"It was previously checked that this blob does not have a parent."
|
||||||
|
),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("get_blob_size called on a global not managing any blobs.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_blob_url_id(&self, blob_id: &BlobId) -> Uuid {
|
||||||
|
let mut blob_state = self.blob_state.borrow_mut();
|
||||||
|
if let BlobState::Managed(blobs_map) = &mut *blob_state {
|
||||||
|
let parent = {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get_mut(blob_id)
|
||||||
|
.expect("get_blob_url_id called for a unknown blob.");
|
||||||
|
|
||||||
|
// Keep track of blobs with outstanding URLs.
|
||||||
|
blob_info.has_url = true;
|
||||||
|
|
||||||
|
match blob_info.blob_impl.blob_data() {
|
||||||
|
BlobData::Sliced(ref parent, ref rel_pos) => {
|
||||||
|
Some((parent.clone(), rel_pos.clone()))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match parent {
|
||||||
|
Some((parent_id, rel_pos)) => {
|
||||||
|
let parent_file_id = {
|
||||||
|
let parent_info = blobs_map
|
||||||
|
.get_mut(&parent_id)
|
||||||
|
.expect("Parent of blob whose url is requested is unknown.");
|
||||||
|
self.promote(parent_info, /* set_valid is */ false)
|
||||||
|
};
|
||||||
|
let parent_size = self.get_blob_size(&parent_id);
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get_mut(blob_id)
|
||||||
|
.expect("Blob whose url is requested is unknown.");
|
||||||
|
self.create_sliced_url_id(blob_info, &parent_file_id, &rel_pos, parent_size)
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
let blob_info = blobs_map
|
||||||
|
.get_mut(blob_id)
|
||||||
|
.expect("Blob whose url is requested is unknown.");
|
||||||
|
self.promote(blob_info, /* set_valid is */ true)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("get_blob_url_id called on a global not managing any blobs.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a FileID representing sliced parent-blob content
|
||||||
|
fn create_sliced_url_id(
|
||||||
|
&self,
|
||||||
|
blob_info: &mut BlobInfo,
|
||||||
|
parent_file_id: &Uuid,
|
||||||
|
rel_pos: &RelativePos,
|
||||||
|
parent_len: u64,
|
||||||
|
) -> Uuid {
|
||||||
|
let origin = get_blob_origin(&self.get_url());
|
||||||
|
|
||||||
|
let (tx, rx) = profile_ipc::channel(self.time_profiler_chan().clone()).unwrap();
|
||||||
|
let msg = FileManagerThreadMsg::AddSlicedURLEntry(
|
||||||
|
parent_file_id.clone(),
|
||||||
|
rel_pos.clone(),
|
||||||
|
tx,
|
||||||
|
origin.clone(),
|
||||||
|
);
|
||||||
|
self.send_to_file_manager(msg);
|
||||||
|
match rx.recv().expect("File manager thread is down.") {
|
||||||
|
Ok(new_id) => {
|
||||||
|
*blob_info.blob_impl.blob_data_mut() = BlobData::File(FileBlob::new(
|
||||||
|
new_id.clone(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
rel_pos.to_abs_range(parent_len as usize).len() as u64,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Return the indirect id reference
|
||||||
|
new_id
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
// Return dummy id
|
||||||
|
Uuid::new_v4()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Promote non-Slice blob:
|
||||||
|
/// 1. Memory-based: The bytes in data slice will be transferred to file manager thread.
|
||||||
|
/// 2. File-based: If set_valid, then activate the FileID so it can serve as URL
|
||||||
|
/// Depending on set_valid, the returned FileID can be part of
|
||||||
|
/// valid or invalid Blob URL.
|
||||||
|
pub fn promote(&self, blob_info: &mut BlobInfo, set_valid: bool) -> Uuid {
|
||||||
|
let mut bytes = vec![];
|
||||||
|
let global_url = self.get_url();
|
||||||
|
|
||||||
|
match blob_info.blob_impl.blob_data_mut() {
|
||||||
|
BlobData::Sliced(_, _) => {
|
||||||
|
panic!("Sliced blobs should use create_sliced_url_id instead of promote.");
|
||||||
|
},
|
||||||
|
BlobData::File(ref f) => {
|
||||||
|
if set_valid {
|
||||||
|
let origin = get_blob_origin(&global_url);
|
||||||
|
let (tx, rx) = profile_ipc::channel(self.time_profiler_chan().clone()).unwrap();
|
||||||
|
|
||||||
|
let msg = FileManagerThreadMsg::ActivateBlobURL(f.get_id(), tx, origin.clone());
|
||||||
|
self.send_to_file_manager(msg);
|
||||||
|
|
||||||
|
match rx.recv().unwrap() {
|
||||||
|
Ok(_) => return f.get_id(),
|
||||||
|
// Return a dummy id on error
|
||||||
|
Err(_) => return Uuid::new_v4(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no need to activate
|
||||||
|
return f.get_id();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BlobData::Memory(ref mut bytes_in) => mem::swap(bytes_in, &mut bytes),
|
||||||
|
};
|
||||||
|
|
||||||
|
let origin = get_blob_origin(&global_url);
|
||||||
|
|
||||||
|
let blob_buf = BlobBuf {
|
||||||
|
filename: None,
|
||||||
|
type_string: blob_info.blob_impl.type_string(),
|
||||||
|
size: bytes.len() as u64,
|
||||||
|
bytes: bytes.to_vec(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let id = Uuid::new_v4();
|
||||||
|
let msg = FileManagerThreadMsg::PromoteMemory(id, blob_buf, set_valid, origin.clone());
|
||||||
|
self.send_to_file_manager(msg);
|
||||||
|
|
||||||
|
*blob_info.blob_impl.blob_data_mut() = BlobData::File(FileBlob::new(
|
||||||
|
id.clone(),
|
||||||
|
None,
|
||||||
|
Some(bytes.to_vec()),
|
||||||
|
bytes.len() as u64,
|
||||||
|
));
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_to_file_manager(&self, msg: FileManagerThreadMsg) {
|
||||||
|
let resource_threads = self.resource_threads();
|
||||||
|
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_file(&self, id: Uuid) -> Result<Vec<u8>, ()> {
|
||||||
|
let resource_threads = self.resource_threads();
|
||||||
|
let (chan, recv) =
|
||||||
|
profile_ipc::channel(self.time_profiler_chan().clone()).map_err(|_| ())?;
|
||||||
|
let origin = get_blob_origin(&self.get_url());
|
||||||
|
let check_url_validity = false;
|
||||||
|
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
|
||||||
|
let _ = resource_threads.send(CoreResourceMsg::ToFileManager(msg));
|
||||||
|
|
||||||
|
let mut bytes = vec![];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match recv.recv().unwrap() {
|
||||||
|
Ok(ReadFileProgress::Meta(mut blob_buf)) => {
|
||||||
|
bytes.append(&mut blob_buf.bytes);
|
||||||
|
},
|
||||||
|
Ok(ReadFileProgress::Partial(mut bytes_in)) => {
|
||||||
|
bytes.append(&mut bytes_in);
|
||||||
|
},
|
||||||
|
Ok(ReadFileProgress::EOF) => {
|
||||||
|
return Ok(bytes);
|
||||||
|
},
|
||||||
|
Err(_) => return Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn track_worker(&self, closing_worker: Arc<AtomicBool>) {
|
pub fn track_worker(&self, closing_worker: Arc<AtomicBool>) {
|
||||||
self.list_auto_close_worker
|
self.list_auto_close_worker
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
|
|
@ -119,6 +119,7 @@ impl History {
|
||||||
let data = StructuredSerializedData {
|
let data = StructuredSerializedData {
|
||||||
serialized: data,
|
serialized: data,
|
||||||
ports: None,
|
ports: None,
|
||||||
|
blobs: None,
|
||||||
};
|
};
|
||||||
let global_scope = self.window.upcast::<GlobalScope>();
|
let global_scope = self.window.upcast::<GlobalScope>();
|
||||||
rooted!(in(*global_scope.get_cx()) let mut state = UndefinedValue());
|
rooted!(in(*global_scope.get_cx()) let mut state = UndefinedValue());
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl Transferable for MessagePort {
|
||||||
}
|
}
|
||||||
|
|
||||||
let port_impls = match sc_holder {
|
let port_impls = match sc_holder {
|
||||||
StructuredDataHolder::Write(port_impls) => port_impls,
|
StructuredDataHolder::Write { ports, .. } => ports,
|
||||||
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
_ => panic!("Unexpected variant of StructuredDataHolder"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::{ByteString, DOMString, USVString};
|
use crate::dom::bindings::str::{ByteString, DOMString, USVString};
|
||||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||||
use crate::dom::bindings::weakref::MutableWeakRef;
|
use crate::dom::bindings::weakref::MutableWeakRef;
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::Blob;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
|
use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
|
||||||
|
@ -58,6 +58,7 @@ use js::jsval::{JSVal, NullValue};
|
||||||
use js::rust::CustomAutoRooterGuard;
|
use js::rust::CustomAutoRooterGuard;
|
||||||
use js::rust::{HandleObject, HandleValue};
|
use js::rust::{HandleObject, HandleValue};
|
||||||
use js::typedarray;
|
use js::typedarray;
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use script_traits::MsDuration;
|
use script_traits::MsDuration;
|
||||||
use servo_config::prefs;
|
use servo_config::prefs;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
@ -174,8 +175,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn InterfaceAttribute(&self) -> DomRoot<Blob> {
|
fn InterfaceAttribute(&self) -> DomRoot<Blob> {
|
||||||
Blob::new(
|
Blob::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(vec![]),
|
BlobImpl::new_from_bytes(vec![], "".to_owned()),
|
||||||
"".to_owned(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn SetInterfaceAttribute(&self, _: &Blob) {}
|
fn SetInterfaceAttribute(&self, _: &Blob) {}
|
||||||
|
@ -320,8 +320,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn GetInterfaceAttributeNullable(&self) -> Option<DomRoot<Blob>> {
|
fn GetInterfaceAttributeNullable(&self) -> Option<DomRoot<Blob>> {
|
||||||
Some(Blob::new(
|
Some(Blob::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(vec![]),
|
BlobImpl::new_from_bytes(vec![], "".to_owned()),
|
||||||
"".to_owned(),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {}
|
fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {}
|
||||||
|
@ -415,8 +414,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveInterface(&self) -> DomRoot<Blob> {
|
fn ReceiveInterface(&self) -> DomRoot<Blob> {
|
||||||
Blob::new(
|
Blob::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(vec![]),
|
BlobImpl::new_from_bytes(vec![], "".to_owned()),
|
||||||
"".to_owned(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn ReceiveAny(&self, _: SafeJSContext) -> JSVal {
|
fn ReceiveAny(&self, _: SafeJSContext) -> JSVal {
|
||||||
|
@ -464,8 +462,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveInterfaceSequence(&self) -> Vec<DomRoot<Blob>> {
|
fn ReceiveInterfaceSequence(&self) -> Vec<DomRoot<Blob>> {
|
||||||
vec![Blob::new(
|
vec![Blob::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(vec![]),
|
BlobImpl::new_from_bytes(vec![], "".to_owned()),
|
||||||
"".to_owned(),
|
|
||||||
)]
|
)]
|
||||||
}
|
}
|
||||||
fn ReceiveUnionIdentity(
|
fn ReceiveUnionIdentity(
|
||||||
|
@ -530,8 +527,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveNullableInterface(&self) -> Option<DomRoot<Blob>> {
|
fn ReceiveNullableInterface(&self) -> Option<DomRoot<Blob>> {
|
||||||
Some(Blob::new(
|
Some(Blob::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
BlobImpl::new_from_bytes(vec![]),
|
BlobImpl::new_from_bytes(vec![], "".to_owned()),
|
||||||
"".to_owned(),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option<NonNull<JSObject>> {
|
fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option<NonNull<JSObject>> {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::bindings::refcounted::Trusted;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::{is_token, DOMString, USVString};
|
use crate::dom::bindings::str::{is_token, DOMString, USVString};
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::Blob;
|
||||||
use crate::dom::closeevent::CloseEvent;
|
use crate::dom::closeevent::CloseEvent;
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
|
@ -37,6 +37,7 @@ use net_traits::MessageData;
|
||||||
use net_traits::{CoreResourceMsg, FetchChannels};
|
use net_traits::{CoreResourceMsg, FetchChannels};
|
||||||
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
|
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
|
||||||
use profile_traits::ipc as ProfiledIpc;
|
use profile_traits::ipc as ProfiledIpc;
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -576,7 +577,7 @@ impl TaskOnce for MessageReceivedTask {
|
||||||
MessageData::Binary(data) => match ws.binary_type.get() {
|
MessageData::Binary(data) => match ws.binary_type.get() {
|
||||||
BinaryType::Blob => {
|
BinaryType::Blob => {
|
||||||
let blob =
|
let blob =
|
||||||
Blob::new(&global, BlobImpl::new_from_bytes(data), "".to_owned());
|
Blob::new(&global, BlobImpl::new_from_bytes(data, "".to_owned()));
|
||||||
blob.to_jsval(*cx, message.handle_mut());
|
blob.to_jsval(*cx, message.handle_mut());
|
||||||
},
|
},
|
||||||
BinaryType::Arraybuffer => {
|
BinaryType::Arraybuffer => {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::dom::bindings::refcounted::Trusted;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||||
use crate::dom::bindings::str::{is_token, ByteString, DOMString, USVString};
|
use crate::dom::bindings::str::{is_token, ByteString, DOMString, USVString};
|
||||||
use crate::dom::blob::{Blob, BlobImpl};
|
use crate::dom::blob::{normalize_type_string, Blob};
|
||||||
use crate::dom::document::DocumentSource;
|
use crate::dom::document::DocumentSource;
|
||||||
use crate::dom::document::{Document, HasBrowsingContext, IsHTMLDocument};
|
use crate::dom::document::{Document, HasBrowsingContext, IsHTMLDocument};
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
@ -65,6 +65,7 @@ use net_traits::CoreResourceMsg::Fetch;
|
||||||
use net_traits::{FetchChannels, FetchMetadata, FilteredMetadata};
|
use net_traits::{FetchChannels, FetchMetadata, FilteredMetadata};
|
||||||
use net_traits::{FetchResponseListener, NetworkError, ReferrerPolicy};
|
use net_traits::{FetchResponseListener, NetworkError, ReferrerPolicy};
|
||||||
use net_traits::{ResourceFetchTiming, ResourceTimingType};
|
use net_traits::{ResourceFetchTiming, ResourceTimingType};
|
||||||
|
use script_traits::serializable::BlobImpl;
|
||||||
use script_traits::DocumentActivity;
|
use script_traits::DocumentActivity;
|
||||||
use servo_atoms::Atom;
|
use servo_atoms::Atom;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
@ -1260,12 +1261,12 @@ impl XMLHttpRequest {
|
||||||
let mime = self
|
let mime = self
|
||||||
.final_mime_type()
|
.final_mime_type()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|m| m.to_string())
|
.map(|m| normalize_type_string(&m.to_string()))
|
||||||
.unwrap_or("".to_owned());
|
.unwrap_or("".to_owned());
|
||||||
|
|
||||||
// Step 3, 4
|
// Step 3, 4
|
||||||
let bytes = self.response.borrow().to_vec();
|
let bytes = self.response.borrow().to_vec();
|
||||||
let blob = Blob::new(&self.global(), BlobImpl::new_from_bytes(bytes), mime);
|
let blob = Blob::new(&self.global(), BlobImpl::new_from_bytes(bytes, mime));
|
||||||
self.response_blob.set(Some(&blob));
|
self.response_blob.set(Some(&blob));
|
||||||
blob
|
blob
|
||||||
}
|
}
|
||||||
|
|
|
@ -1592,7 +1592,7 @@ impl ScriptThread {
|
||||||
|
|
||||||
window
|
window
|
||||||
.upcast::<GlobalScope>()
|
.upcast::<GlobalScope>()
|
||||||
.perform_a_message_port_garbage_collection_checkpoint();
|
.perform_a_dom_garbage_collection_checkpoint();
|
||||||
|
|
||||||
let pending_reflows = window.get_pending_reflow_count();
|
let pending_reflows = window.get_pending_reflow_count();
|
||||||
if pending_reflows > 0 {
|
if pending_reflows > 0 {
|
||||||
|
|
|
@ -39,6 +39,7 @@ servo_url = {path = "../url"}
|
||||||
style_traits = {path = "../style_traits", features = ["servo"]}
|
style_traits = {path = "../style_traits", features = ["servo"]}
|
||||||
time = "0.1.12"
|
time = "0.1.12"
|
||||||
url = "2.0"
|
url = "2.0"
|
||||||
|
uuid = {version = "0.8", features = ["v4"]}
|
||||||
webdriver = "0.40"
|
webdriver = "0.40"
|
||||||
webgpu = {path = "../webgpu"}
|
webgpu = {path = "../webgpu"}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender"}
|
webrender_api = {git = "https://github.com/servo/webrender"}
|
||||||
|
|
|
@ -17,9 +17,11 @@ extern crate malloc_size_of_derive;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
mod script_msg;
|
mod script_msg;
|
||||||
|
pub mod serializable;
|
||||||
pub mod transferable;
|
pub mod transferable;
|
||||||
pub mod webdriver_msg;
|
pub mod webdriver_msg;
|
||||||
|
|
||||||
|
use crate::serializable::BlobImpl;
|
||||||
use crate::transferable::MessagePortImpl;
|
use crate::transferable::MessagePortImpl;
|
||||||
use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
use crate::webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
||||||
use bluetooth_traits::BluetoothRequest;
|
use bluetooth_traits::BluetoothRequest;
|
||||||
|
@ -39,7 +41,9 @@ use libc::c_void;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use media::WindowGLContext;
|
use media::WindowGLContext;
|
||||||
use msg::constellation_msg::BackgroundHangMonitorRegister;
|
use msg::constellation_msg::BackgroundHangMonitorRegister;
|
||||||
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, MessagePortId, PipelineId};
|
use msg::constellation_msg::{
|
||||||
|
BlobId, BrowsingContextId, HistoryStateId, MessagePortId, PipelineId,
|
||||||
|
};
|
||||||
use msg::constellation_msg::{PipelineNamespaceId, TopLevelBrowsingContextId, TraversalDirection};
|
use msg::constellation_msg::{PipelineNamespaceId, TopLevelBrowsingContextId, TraversalDirection};
|
||||||
use net_traits::image::base::Image;
|
use net_traits::image::base::Image;
|
||||||
use net_traits::image_cache::ImageCache;
|
use net_traits::image_cache::ImageCache;
|
||||||
|
@ -1039,6 +1043,8 @@ impl ScriptToConstellationChan {
|
||||||
pub struct StructuredSerializedData {
|
pub struct StructuredSerializedData {
|
||||||
/// Data serialized by SpiderMonkey.
|
/// Data serialized by SpiderMonkey.
|
||||||
pub serialized: Vec<u8>,
|
pub serialized: Vec<u8>,
|
||||||
|
/// Serialized in a structured callback,
|
||||||
|
pub blobs: Option<HashMap<BlobId, BlobImpl>>,
|
||||||
/// Transferred objects.
|
/// Transferred objects.
|
||||||
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
pub ports: Option<HashMap<MessagePortId, MessagePortImpl>>,
|
||||||
}
|
}
|
||||||
|
|
148
components/script_traits/serializable.rs
Normal file
148
components/script_traits/serializable.rs
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! This module contains implementations in script that are serializable,
|
||||||
|
//! as per https://html.spec.whatwg.org/multipage/#serializable-objects.
|
||||||
|
//! The implementations are here instead of in script
|
||||||
|
//! so that the other modules involved in the serialization don't have
|
||||||
|
//! to depend on script.
|
||||||
|
|
||||||
|
use msg::constellation_msg::BlobId;
|
||||||
|
use net_traits::filemanager_thread::RelativePos;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
/// File-based blob
|
||||||
|
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
|
pub struct FileBlob {
|
||||||
|
#[ignore_malloc_size_of = "Uuid are hard(not really)"]
|
||||||
|
id: Uuid,
|
||||||
|
#[ignore_malloc_size_of = "PathBuf are hard"]
|
||||||
|
name: Option<PathBuf>,
|
||||||
|
cache: RefCell<Option<Vec<u8>>>,
|
||||||
|
size: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileBlob {
|
||||||
|
/// Create a new file blob.
|
||||||
|
pub fn new(id: Uuid, name: Option<PathBuf>, cache: Option<Vec<u8>>, size: u64) -> FileBlob {
|
||||||
|
FileBlob {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
cache: RefCell::new(cache),
|
||||||
|
size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the size of the file.
|
||||||
|
pub fn get_size(&self) -> u64 {
|
||||||
|
self.size.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the cached file data, if any.
|
||||||
|
pub fn get_cache(&self) -> Option<Vec<u8>> {
|
||||||
|
self.cache.borrow().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cache data.
|
||||||
|
pub fn cache_bytes(&self, bytes: Vec<u8>) {
|
||||||
|
*self.cache.borrow_mut() = Some(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the file id.
|
||||||
|
pub fn get_id(&self) -> Uuid {
|
||||||
|
self.id.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The data backing a DOM Blob.
|
||||||
|
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
|
pub struct BlobImpl {
|
||||||
|
/// UUID of the blob.
|
||||||
|
blob_id: BlobId,
|
||||||
|
/// Content-type string
|
||||||
|
type_string: String,
|
||||||
|
/// Blob data-type.
|
||||||
|
blob_data: BlobData,
|
||||||
|
/// Sliced blobs referring to this one.
|
||||||
|
slices: Vec<BlobId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Different backends of Blob
|
||||||
|
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
|
pub enum BlobData {
|
||||||
|
/// File-based blob, whose content lives in the net process
|
||||||
|
File(FileBlob),
|
||||||
|
/// Memory-based blob, whose content lives in the script process
|
||||||
|
Memory(Vec<u8>),
|
||||||
|
/// Sliced blob, including parent blob-id and
|
||||||
|
/// relative positions of current slicing range,
|
||||||
|
/// IMPORTANT: The depth of tree is only two, i.e. the parent Blob must be
|
||||||
|
/// either File-based or Memory-based
|
||||||
|
Sliced(BlobId, RelativePos),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BlobImpl {
|
||||||
|
/// Construct memory-backed BlobImpl
|
||||||
|
pub fn new_from_bytes(bytes: Vec<u8>, type_string: String) -> BlobImpl {
|
||||||
|
let blob_id = BlobId::new();
|
||||||
|
let blob_data = BlobData::Memory(bytes);
|
||||||
|
BlobImpl {
|
||||||
|
blob_id,
|
||||||
|
type_string,
|
||||||
|
blob_data,
|
||||||
|
slices: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct file-backed BlobImpl from File ID
|
||||||
|
pub fn new_from_file(file_id: Uuid, name: PathBuf, size: u64, type_string: String) -> BlobImpl {
|
||||||
|
let blob_id = BlobId::new();
|
||||||
|
let blob_data = BlobData::File(FileBlob {
|
||||||
|
id: file_id,
|
||||||
|
name: Some(name),
|
||||||
|
cache: RefCell::new(None),
|
||||||
|
size: size,
|
||||||
|
});
|
||||||
|
BlobImpl {
|
||||||
|
blob_id,
|
||||||
|
type_string,
|
||||||
|
blob_data,
|
||||||
|
slices: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a BlobImpl from a slice of a parent.
|
||||||
|
pub fn new_sliced(rel_pos: RelativePos, parent: BlobId, type_string: String) -> BlobImpl {
|
||||||
|
let blob_id = BlobId::new();
|
||||||
|
let blob_data = BlobData::Sliced(parent, rel_pos);
|
||||||
|
BlobImpl {
|
||||||
|
blob_id,
|
||||||
|
type_string,
|
||||||
|
blob_data,
|
||||||
|
slices: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a clone of the blob-id
|
||||||
|
pub fn blob_id(&self) -> BlobId {
|
||||||
|
self.blob_id.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a clone of the type-string
|
||||||
|
pub fn type_string(&self) -> String {
|
||||||
|
self.type_string.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a mutable ref to the data
|
||||||
|
pub fn blob_data(&self) -> &BlobData {
|
||||||
|
&self.blob_data
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a mutable ref to the data
|
||||||
|
pub fn blob_data_mut(&mut self) -> &mut BlobData {
|
||||||
|
&mut self.blob_data
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,3 +15,6 @@
|
||||||
[Opening a blob URL in a new window by clicking an <a> tag works immediately before revoking the URL.]
|
[Opening a blob URL in a new window by clicking an <a> tag works immediately before revoking the URL.]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[Fetching a blob URL immediately before revoking it works in <script> tags.]
|
||||||
|
expected: TIMEOUT
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
[Revoke blob URL after creating Request, will fetch]
|
[Revoke blob URL after creating Request, will fetch]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[Revoke blob URL after calling fetch, fetch should succeed]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
||||||
[url-with-fetch.any.html]
|
[url-with-fetch.any.html]
|
||||||
[Revoke blob URL after creating Request, will fetch]
|
[Revoke blob URL after creating Request, will fetch]
|
||||||
|
|
|
@ -358970,9 +358970,15 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.html": [
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.window.js": [
|
||||||
[
|
[
|
||||||
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.html",
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.window.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob_array.window.js": [
|
||||||
|
[
|
||||||
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob_array.window.html",
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -653472,8 +653478,12 @@
|
||||||
"995edac8da9d95ac6f151863b5cd48994941a347",
|
"995edac8da9d95ac6f151863b5cd48994941a347",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.html": [
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob.window.js": [
|
||||||
"6b1abf5ef8d30c2494effac489db79732d0c12d4",
|
"490e78165de820d31f25cd3f09416a8cbf1b1c66",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
|
"html/infrastructure/safe-passing-of-structured-data/structured_clone_blob_array.window.js": [
|
||||||
|
"b976d5b212652bf763b4a6039a70c26758c84ccf",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html": [
|
"html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html": [
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Safe passing of structured data - Blob</title>
|
|
||||||
<script src="/resources/testharness.js"></script>
|
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script>
|
|
||||||
async_test(function(t) {
|
|
||||||
var blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type:"text/plain"});
|
|
||||||
window.addEventListener("message", this.step_func(function(msg) {
|
|
||||||
assert_true(msg.data instanceof Blob);
|
|
||||||
assert_equals(msg.data.size, blob.size);
|
|
||||||
assert_equals(msg.data.type, blob.type);
|
|
||||||
var cloned_content, original_content;
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.addEventListener("loadend", this.step_func(function() {
|
|
||||||
original_content = reader.result;
|
|
||||||
var reader2 = new FileReader();
|
|
||||||
reader2.addEventListener("loadend", this.step_func_done(function() {
|
|
||||||
cloned_content = reader2.result;
|
|
||||||
assert_equals(typeof cloned_content, typeof original_content);
|
|
||||||
assert_equals(cloned_content, original_content);
|
|
||||||
}));
|
|
||||||
reader2.readAsText(msg.data);
|
|
||||||
}));
|
|
||||||
reader.readAsText(blob);
|
|
||||||
}), false);
|
|
||||||
window.postMessage(blob, '*');
|
|
||||||
}, "Cloning a Blob into the same realm");
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
async_test(function(t) {
|
||||||
|
var blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type:"text/plain"});
|
||||||
|
onmessage = t.step_func(function(msg) {
|
||||||
|
assert_true(msg.data instanceof Blob);
|
||||||
|
assert_equals(msg.data.size, blob.size);
|
||||||
|
assert_equals(msg.data.type, blob.type);
|
||||||
|
var cloned_content, original_content;
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.addEventListener("loadend", t.step_func(function() {
|
||||||
|
original_content = reader.result;
|
||||||
|
var reader2 = new FileReader();
|
||||||
|
reader2.addEventListener("loadend", t.step_func_done(function() {
|
||||||
|
cloned_content = reader2.result;
|
||||||
|
assert_equals(typeof cloned_content, typeof original_content);
|
||||||
|
assert_equals(cloned_content, original_content);
|
||||||
|
}));
|
||||||
|
reader2.readAsText(msg.data);
|
||||||
|
}));
|
||||||
|
reader.readAsText(blob);
|
||||||
|
});
|
||||||
|
postMessage(blob, '*');
|
||||||
|
}, "Cloning a blob into the same realm");
|
|
@ -0,0 +1,25 @@
|
||||||
|
async_test(function(t) {
|
||||||
|
var blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type:"text/plain"});
|
||||||
|
var another_blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type:"text/plain"});
|
||||||
|
onmessage = t.step_func(function(msg) {
|
||||||
|
assert_true(msg.data instanceof Array);
|
||||||
|
assert_equals(msg.data.length, 2);
|
||||||
|
msg.data.forEach((function(blob, index) {
|
||||||
|
assert_true(blob instanceof Blob);
|
||||||
|
var cloned_content, original_content;
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.addEventListener("loadend", t.step_func(function() {
|
||||||
|
original_content = reader.result;
|
||||||
|
var reader2 = new FileReader();
|
||||||
|
reader2.addEventListener("loadend", t.step_func_done(function() {
|
||||||
|
cloned_content = reader2.result;
|
||||||
|
assert_equals(typeof cloned_content, typeof original_content);
|
||||||
|
assert_equals(cloned_content, original_content);
|
||||||
|
}));
|
||||||
|
reader2.readAsText(msg.data[index]);
|
||||||
|
}));
|
||||||
|
reader.readAsText(blob);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
postMessage([blob, another_blob], '*');
|
||||||
|
}, "Cloning an array of blobs into the same realm");
|
Loading…
Add table
Add a link
Reference in a new issue