diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/global.rs | 21 | ||||
-rw-r--r-- | components/script/dom/blob.rs | 134 | ||||
-rw-r--r-- | components/script/dom/dedicatedworkerglobalscope.rs | 4 | ||||
-rw-r--r-- | components/script/dom/file.rs | 26 | ||||
-rw-r--r-- | components/script/dom/filereader.rs | 2 | ||||
-rw-r--r-- | components/script/dom/formdata.rs | 9 | ||||
-rw-r--r-- | components/script/dom/htmlformelement.rs | 14 | ||||
-rw-r--r-- | components/script/dom/testbinding.rs | 12 | ||||
-rw-r--r-- | components/script/dom/websocket.rs | 9 | ||||
-rw-r--r-- | components/script/dom/worker.rs | 4 | ||||
-rw-r--r-- | components/script/dom/workerglobalscope.rs | 18 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 9 |
12 files changed, 183 insertions, 79 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 036c53e67b4..adb94c9d2ca 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -19,7 +19,8 @@ use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment}; use js::jsapi::{JSContext, JSObject, JS_GetClass, MutableHandleValue}; use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use msg::constellation_msg::{PipelineId, PanicMsg}; -use net_traits::{CoreResourceThread, RequestSource}; +use net_traits::filemanager_thread::FileManagerThreadMsg; +use net_traits::{ResourceThreads, CoreResourceThread, RequestSource, IpcSend}; use profile_traits::{mem, time}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_thread::{MainThreadScriptChan, ScriptThread}; @@ -122,19 +123,29 @@ impl<'a> GlobalRef<'a> { } } - /// Get the `CoreResourceThread` for this global scope. - pub fn core_resource_thread(&self) -> CoreResourceThread { + /// Get the `ResourceThreads` for this global scope. + pub fn resource_threads(&self) -> ResourceThreads { match *self { GlobalRef::Window(ref window) => { let doc = window.Document(); let doc = doc.r(); let loader = doc.loader(); - (*loader.resource_thread).clone() + loader.resource_threads().clone() } - GlobalRef::Worker(ref worker) => worker.core_resource_thread().clone(), + GlobalRef::Worker(ref worker) => worker.resource_threads().clone(), } } + /// Get the `CoreResourceThread` for this global scope + pub fn core_resource_thread(&self) -> CoreResourceThread { + self.resource_threads().sender() + } + + /// Get the port to file manager for this global scope + pub fn filemanager_thread(&self) -> IpcSender<FileManagerThreadMsg> { + self.resource_threads().sender() + } + /// Get the worker's id. pub fn get_worker_id(&self) -> Option<WorkerId> { match *self { diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 19fe0f4fdc2..b89aa3b9ac2 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -2,22 +2,26 @@ * 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/. */ +use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::codegen::UnionTypes::BlobOrString; -use dom::bindings::error::Fallible; +use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; use encoding::all::UTF_8; use encoding::types::{EncoderTrap, Encoding}; +use ipc_channel::ipc; +use net_traits::filemanager_thread::FileManagerThreadMsg; use num_traits::ToPrimitive; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; use std::cmp::{max, min}; use std::sync::Arc; +use uuid::Uuid; #[derive(Clone, JSTraceable)] pub struct DataSlice { @@ -62,6 +66,11 @@ impl DataSlice { } } + /// Construct data slice from a vector of bytes + pub fn from_bytes(bytes: Vec<u8>) -> DataSlice { + DataSlice::new(Arc::new(bytes), None, None) + } + /// Construct an empty data slice pub fn empty() -> DataSlice { DataSlice { @@ -83,26 +92,51 @@ impl DataSlice { } +#[derive(Clone, JSTraceable)] +pub enum BlobImpl { + /// File-based, cached backend + File(Uuid, DOMRefCell<Option<DataSlice>>), + /// Memory-based backend + Memory(DataSlice), +} + +impl BlobImpl { + /// Construct memory-backed BlobImpl from DataSlice + pub fn new_from_slice(slice: DataSlice) -> BlobImpl { + BlobImpl::Memory(slice) + } + + /// Construct file-backed BlobImpl from File ID + pub fn new_from_file(file_id: Uuid) -> BlobImpl { + BlobImpl::File(file_id, DOMRefCell::new(None)) + } + + /// Construct empty, memory-backed BlobImpl + pub fn new_from_empty_slice() -> BlobImpl { + BlobImpl::new_from_slice(DataSlice::empty()) + } +} + // https://w3c.github.io/FileAPI/#blob #[dom_struct] pub struct Blob { reflector_: Reflector, #[ignore_heap_size_of = "No clear owner"] - data: DataSlice, + blob_impl: BlobImpl, typeString: String, isClosed_: Cell<bool>, } impl Blob { - pub fn new(global: GlobalRef, slice: DataSlice, typeString: &str) -> Root<Blob> { - let boxed_blob = box Blob::new_inherited(slice, typeString); + pub fn new(global: GlobalRef, blob_impl: BlobImpl, typeString: &str) -> Root<Blob> { + let boxed_blob = box Blob::new_inherited(blob_impl, typeString); reflect_dom_object(boxed_blob, global, BlobBinding::Wrap) } - pub fn new_inherited(slice: DataSlice, typeString: &str) -> Blob { + pub fn new_inherited(blob_impl: BlobImpl, typeString: &str) -> Blob { Blob { reflector_: Reflector::new(), - data: slice, + blob_impl: blob_impl, typeString: typeString.to_owned(), isClosed_: Cell::new(false), } @@ -116,35 +150,81 @@ impl Blob { // TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView let bytes: Vec<u8> = match blobParts { None => Vec::new(), - Some(blobparts) => blob_parts_to_bytes(blobparts), + Some(blobparts) => match blob_parts_to_bytes(blobparts) { + Ok(bytes) => bytes, + Err(_) => return Err(Error::InvalidCharacter), + } }; - let slice = DataSlice::new(Arc::new(bytes), None, None); - Ok(Blob::new(global, slice, &blobPropertyBag.get_typestring())) + let slice = DataSlice::from_bytes(bytes); + Ok(Blob::new(global, BlobImpl::new_from_slice(slice), &blobPropertyBag.get_typestring())) } - pub fn get_data(&self) -> &DataSlice { - &self.data + /// Get a slice to inner data, this might incur synchronous read and caching + pub fn get_slice(&self) -> Result<DataSlice, ()> { + match self.blob_impl { + BlobImpl::File(ref id, ref slice) => { + match *slice.borrow() { + Some(ref s) => Ok(s.clone()), + None => { + let global = self.global(); + let s = read_file(global.r(), id.clone())?; + *slice.borrow_mut() = Some(s.clone()); // Cached + Ok(s) + } + } + } + BlobImpl::Memory(ref s) => Ok(s.clone()) + } + } + + /// Try to get a slice, and if any exception happens, return the empty slice + pub fn get_slice_or_empty(&self) -> DataSlice { + self.get_slice().unwrap_or(DataSlice::empty()) } } -pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Vec<u8> { - blobparts.iter().flat_map(|blobpart| { - match blobpart { - &BlobOrString::String(ref s) => { - UTF_8.encode(s, EncoderTrap::Replace).unwrap() - }, - &BlobOrString::Blob(ref b) => { - b.get_data().get_bytes().to_vec() - }, - } - }).collect::<Vec<u8>>() +fn read_file(global: GlobalRef, id: Uuid) -> Result<DataSlice, ()> { + let file_manager = global.filemanager_thread(); + let (chan, recv) = ipc::channel().map_err(|_|())?; + let _ = file_manager.send(FileManagerThreadMsg::ReadFile(chan, id)); + + let result = match recv.recv() { + Ok(ret) => ret, + Err(e) => { + debug!("File manager thread has problem {:?}", e); + return Err(()) + } + }; + + let bytes = result.map_err(|_|())?; + Ok(DataSlice::from_bytes(bytes)) +} + +/// Extract bytes from BlobParts, used by Blob and File constructor +/// https://w3c.github.io/FileAPI/#constructorBlob +pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Result<Vec<u8>, ()> { + let mut ret = vec![]; + + for blobpart in &blobparts { + match blobpart { + &BlobOrString::String(ref s) => { + let mut bytes = UTF_8.encode(s, EncoderTrap::Replace).map_err(|_|())?; + ret.append(&mut bytes); + }, + &BlobOrString::Blob(ref b) => { + ret.append(&mut b.get_slice_or_empty().bytes.to_vec()); + }, + } + } + + Ok(ret) } impl BlobMethods for Blob { // https://w3c.github.io/FileAPI/#dfn-size fn Size(&self) -> u64 { - self.data.size() + self.get_slice_or_empty().size() } // https://w3c.github.io/FileAPI/#dfn-type @@ -169,9 +249,11 @@ impl BlobMethods for Blob { } } }; + let global = self.global(); - let bytes = self.data.bytes.clone(); - Blob::new(global.r(), DataSlice::new(bytes, start, end), &relativeContentType) + let bytes = self.get_slice_or_empty().bytes.clone(); + let slice = DataSlice::new(bytes, start, end); + Blob::new(global.r(), BlobImpl::new_from_slice(slice), &relativeContentType) } // https://w3c.github.io/FileAPI/#dfn-isClosed @@ -196,6 +278,8 @@ impl BlobMethods for Blob { impl BlobBinding::BlobPropertyBag { + /// Get the normalized inner type string + /// https://w3c.github.io/FileAPI/#dfn-type pub fn get_typestring(&self) -> String { if is_ascii_printable(&self.type_) { self.type_.to_lowercase() diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index d658163c233..3b40313434a 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -28,7 +28,7 @@ use js::jsapi::{JSAutoCompartment, JSContext, RootedValue}; use js::jsval::UndefinedValue; use js::rust::Runtime; use msg::constellation_msg::PipelineId; -use net_traits::{LoadContext, load_whole_resource, CustomResponse}; +use net_traits::{LoadContext, load_whole_resource, CustomResponse, IpcSend}; use rand::random; use script_runtime::ScriptThreadEventCategory::WorkerEvent; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_reports, new_rt_and_cx}; @@ -226,7 +226,7 @@ impl DedicatedWorkerGlobalScope { let roots = RootCollection::new(); let _stack_roots_tls = StackRootTLS::new(&roots); let (url, source) = match load_whole_resource(LoadContext::Script, - &init.core_resource_thread, + &init.resource_threads.sender(), worker_url, &worker_load_origin) { Err(_) => { diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index e8cdf89de54..c0ddd74233f 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -5,15 +5,14 @@ use dom::bindings::codegen::Bindings::FileBinding; use dom::bindings::codegen::Bindings::FileBinding::FileMethods; use dom::bindings::codegen::UnionTypes::BlobOrString; -use dom::bindings::error::Fallible; +use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; -use dom::blob::{Blob, DataSlice, blob_parts_to_bytes}; +use dom::blob::{Blob, BlobImpl, DataSlice, blob_parts_to_bytes}; use dom::window::Window; use net_traits::filemanager_thread::SelectedFile; -use std::sync::Arc; use time; #[dom_struct] @@ -24,10 +23,10 @@ pub struct File { } impl File { - fn new_inherited(slice: DataSlice, name: DOMString, + fn new_inherited(blob_impl: BlobImpl, name: DOMString, modified: Option<i64>, typeString: &str) -> File { File { - blob: Blob::new_inherited(slice, typeString), + blob: Blob::new_inherited(blob_impl, typeString), name: name, // https://w3c.github.io/FileAPI/#dfn-lastModified modified: match modified { @@ -40,9 +39,9 @@ impl File { } } - pub fn new(global: GlobalRef, slice: DataSlice, + pub fn new(global: GlobalRef, blob_impl: BlobImpl, name: DOMString, modified: Option<i64>, typeString: &str) -> Root<File> { - reflect_dom_object(box File::new_inherited(slice, name, modified, typeString), + reflect_dom_object(box File::new_inherited(blob_impl, name, modified, typeString), global, FileBinding::Wrap) } @@ -51,11 +50,9 @@ impl File { pub fn new_from_selected(window: &Window, selected: SelectedFile) -> Root<File> { let name = DOMString::from(selected.filename.to_str().expect("File name encoding error")); - let slice = DataSlice::empty(); - let global = GlobalRef::Window(window); - File::new(global, slice, name, Some(selected.modified as i64), "") + File::new(global, BlobImpl::new_from_file(selected.id), name, Some(selected.modified as i64), "") } // https://w3c.github.io/FileAPI/#file-constructor @@ -64,14 +61,17 @@ impl File { filename: DOMString, filePropertyBag: &FileBinding::FilePropertyBag) -> Fallible<Root<File>> { - let bytes: Vec<u8> = blob_parts_to_bytes(fileBits); + let bytes: Vec<u8> = match blob_parts_to_bytes(fileBits) { + Ok(bytes) => bytes, + Err(_) => return Err(Error::InvalidCharacter), + }; let ref blobPropertyBag = filePropertyBag.parent; let typeString = blobPropertyBag.get_typestring(); - let slice = DataSlice::new(Arc::new(bytes), None, None); + let slice = DataSlice::from_bytes(bytes); let modified = filePropertyBag.lastModified; - Ok(File::new(global, slice, filename, modified, &typeString)) + Ok(File::new(global, BlobImpl::new_from_slice(slice), filename, modified, &typeString)) } pub fn name(&self) -> &DOMString { diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index 58aa1dc1ba3..9e3f4674fa1 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -349,7 +349,7 @@ impl FileReader { self.change_ready_state(FileReaderReadyState::Loading); // Step 4 - let blob_contents = blob.get_data().clone(); + let blob_contents = blob.get_slice_or_empty(); let type_ = blob.Type(); diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index c7521a94365..95b4aae27e2 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -11,7 +11,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; -use dom::blob::Blob; +use dom::blob::{Blob, BlobImpl}; use dom::file::File; use dom::htmlformelement::HTMLFormElement; use std::collections::HashMap; @@ -121,14 +121,15 @@ impl FormDataMethods for FormData { impl FormData { - fn get_file_or_blob(&self, value: &Blob, filename: Option<USVString>) -> Root<Blob> { + fn get_file_or_blob(&self, blob: &Blob, filename: Option<USVString>) -> Root<Blob> { match filename { Some(fname) => { let global = self.global(); let name = DOMString::from(fname.0); - Root::upcast(File::new(global.r(), value.get_data().clone(), name, None, "")) + let slice = blob.get_slice_or_empty(); + Root::upcast(File::new(global.r(), BlobImpl::new_from_slice(slice), name, None, "")) } - None => Root::from_ref(value) + None => Root::from_ref(blob) } } } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 50490ec879f..7f54fc7842b 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -40,6 +40,7 @@ use dom::window::Window; use encoding::EncodingRef; use encoding::all::UTF_8; use encoding::label::encoding_from_whatwg_label; +use encoding::types::DecoderTrap; use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType}; use hyper::method::Method; use msg::constellation_msg::{LoadData, PipelineId}; @@ -47,7 +48,6 @@ use rand::random; use script_thread::{MainThreadScriptMsg, Runnable}; use std::borrow::ToOwned; use std::cell::Cell; -use std::str::from_utf8; use std::sync::mpsc::Sender; use string_cache::Atom; use task_source::dom_manipulation::DOMManipulationTask; @@ -281,7 +281,7 @@ impl HTMLFormElement { let encoding = encoding.unwrap_or(self.pick_encoding()); // Step 3 - let charset = &*encoding.whatwg_name().unwrap(); + let charset = &*encoding.whatwg_name().unwrap_or("UTF-8"); // Step 4 for entry in form_data.iter_mut() { @@ -309,12 +309,18 @@ impl HTMLFormElement { DispositionParam::Filename(Charset::Ext(String::from(charset.clone())), None, f.name().clone().into())); - let content_type = ContentType(f.upcast::<Blob>().Type().parse().unwrap()); + // https://tools.ietf.org/html/rfc7578#section-4.4 + let content_type = ContentType(f.upcast::<Blob>().Type() + .parse().unwrap_or(mime!(Text / Plain))); result.push_str(&*format!("Content-Disposition: {}\r\n{}\r\n\r\n", content_disposition, content_type)); - result.push_str(from_utf8(&f.upcast::<Blob>().get_data().get_bytes()).unwrap()); + let slice = f.upcast::<Blob>().get_slice_or_empty(); + + let decoded = encoding.decode(&slice.get_bytes(), DecoderTrap::Replace) + .expect("Invalid encoding in file"); + result.push_str(&decoded); } } } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 630e5b2acd7..4fe7512ddcc 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -22,7 +22,7 @@ use dom::bindings::num::Finite; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::str::{ByteString, DOMString, USVString}; use dom::bindings::weakref::MutableWeakRef; -use dom::blob::{Blob, DataSlice}; +use dom::blob::{Blob, BlobImpl}; use dom::url::URL; use js::jsapi::{HandleObject, HandleValue, JSContext, JSObject}; use js::jsval::{JSVal, NullValue}; @@ -101,7 +101,7 @@ impl TestBindingMethods for TestBinding { fn EnumAttribute(&self) -> TestEnum { TestEnum::_empty } fn SetEnumAttribute(&self, _: TestEnum) {} fn InterfaceAttribute(&self) -> Root<Blob> { - Blob::new(self.global().r(), DataSlice::empty(), "") + Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "") } fn SetInterfaceAttribute(&self, _: &Blob) {} fn UnionAttribute(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } @@ -179,7 +179,7 @@ impl TestBindingMethods for TestBinding { fn SetAttr_to_automatically_rename(&self, _: DOMString) {} fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(TestEnum::_empty) } fn GetInterfaceAttributeNullable(&self) -> Option<Root<Blob>> { - Some(Blob::new(self.global().r(), DataSlice::empty(), "")) + Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")) } fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {} fn GetInterfaceAttributeWeak(&self) -> Option<Root<URL>> { @@ -230,7 +230,7 @@ impl TestBindingMethods for TestBinding { fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) } fn ReceiveEnum(&self) -> TestEnum { TestEnum::_empty } fn ReceiveInterface(&self) -> Root<Blob> { - Blob::new(self.global().r(), DataSlice::empty(), "") + Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "") } fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() } fn ReceiveObject(&self, _: *mut JSContext) -> *mut JSObject { panic!() } @@ -247,7 +247,7 @@ impl TestBindingMethods for TestBinding { } fn ReceiveSequence(&self) -> Vec<i32> { vec![1] } fn ReceiveInterfaceSequence(&self) -> Vec<Root<Blob>> { - vec![Blob::new(self.global().r(), DataSlice::empty(), "")] + vec![Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")] } fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) } @@ -268,7 +268,7 @@ impl TestBindingMethods for TestBinding { fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) } fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(TestEnum::_empty) } fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> { - Some(Blob::new(self.global().r(), DataSlice::empty(), "")) + Some(Blob::new(self.global().r(), BlobImpl::new_from_empty_slice(), "")) } fn ReceiveNullableObject(&self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() } fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> { diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index c947a587687..84ae5cc7ebd 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -16,7 +16,7 @@ use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString, is_token}; -use dom::blob::{Blob, DataSlice}; +use dom::blob::{Blob, BlobImpl, DataSlice}; use dom::closeevent::CloseEvent; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; @@ -40,7 +40,6 @@ use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; use std::ptr; -use std::sync::Arc; use std::thread; use websocket::client::request::Url; use websocket::header::{Headers, WebSocketProtocol}; @@ -406,7 +405,7 @@ impl WebSocketMethods for WebSocket { if send_data { let mut other_sender = self.sender.borrow_mut(); let my_sender = other_sender.as_mut().unwrap(); - let bytes = blob.get_data().get_bytes().to_vec(); + let bytes = blob.get_slice_or_empty().get_bytes().to_vec(); let _ = my_sender.send(WebSocketDomAction::SendMessage(MessageData::Binary(bytes))); } @@ -592,8 +591,8 @@ impl Runnable for MessageReceivedTask { MessageData::Binary(data) => { match ws.binary_type.get() { BinaryType::Blob => { - let slice = DataSlice::new(Arc::new(data), None, None); - let blob = Blob::new(global.r(), slice, ""); + let slice = DataSlice::from_bytes(data); + let blob = Blob::new(global.r(), BlobImpl::new_from_slice(slice), ""); blob.to_jsval(cx, message.handle_mut()); } BinaryType::Arraybuffer => { diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 0a18125f1bc..7c5eab3b045 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -99,7 +99,7 @@ impl Worker { Err(_) => return Err(Error::Syntax), }; - let core_resource_thread = global.core_resource_thread(); + let resource_threads = global.resource_threads(); let constellation_chan = global.constellation_chan().clone(); let scheduler_chan = global.scheduler_chan().clone(); @@ -134,7 +134,7 @@ impl Worker { }; let init = WorkerGlobalScopeInit { - core_resource_thread: core_resource_thread, + resource_threads: resource_threads, mem_profiler_chan: global.mem_profiler_chan().clone(), time_profiler_chan: global.time_profiler_chan().clone(), to_devtools_sender: global.devtools_chan(), diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 6161b11ccc8..95c476649b8 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -24,7 +24,8 @@ use js::jsapi::{HandleValue, JSContext, JSRuntime, RootedValue}; use js::jsval::UndefinedValue; use js::rust::Runtime; use msg::constellation_msg::{PipelineId, ReferrerPolicy, PanicMsg}; -use net_traits::{LoadContext, CoreResourceThread, load_whole_resource, RequestSource, LoadOrigin, CustomResponseSender}; +use net_traits::{LoadContext, ResourceThreads, load_whole_resource}; +use net_traits::{RequestSource, LoadOrigin, CustomResponseSender, IpcSend}; use profile_traits::{mem, time}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_traits::ScriptMsg as ConstellationMsg; @@ -44,7 +45,7 @@ pub enum WorkerGlobalScopeTypeId { } pub struct WorkerGlobalScopeInit { - pub core_resource_thread: CoreResourceThread, + pub resource_threads: ResourceThreads, pub mem_profiler_chan: mem::ProfilerChan, pub time_profiler_chan: time::ProfilerChan, pub to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>, @@ -67,7 +68,7 @@ pub struct WorkerGlobalScope { runtime: Runtime, next_worker_id: Cell<WorkerId>, #[ignore_heap_size_of = "Defined in std"] - core_resource_thread: CoreResourceThread, + resource_threads: ResourceThreads, location: MutNullableHeap<JS<WorkerLocation>>, navigator: MutNullableHeap<JS<WorkerNavigator>>, console: MutNullableHeap<JS<Console>>, @@ -126,7 +127,7 @@ impl WorkerGlobalScope { worker_url: worker_url, closing: init.closing, runtime: runtime, - core_resource_thread: init.core_resource_thread, + resource_threads: init.resource_threads, location: Default::default(), navigator: Default::default(), console: Default::default(), @@ -204,8 +205,8 @@ impl WorkerGlobalScope { self.closing.load(Ordering::SeqCst) } - pub fn core_resource_thread(&self) -> &CoreResourceThread { - &self.core_resource_thread + pub fn resource_threads(&self) -> &ResourceThreads { + &self.resource_threads } pub fn get_url(&self) -> &Url { @@ -269,7 +270,10 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope { let mut rval = RootedValue::new(self.runtime.cx(), UndefinedValue()); for url in urls { - let (url, source) = match load_whole_resource(LoadContext::Script, &self.core_resource_thread, url, self) { + let (url, source) = match load_whole_resource(LoadContext::Script, + &self.resource_threads.sender(), + url, + self) { Err(_) => return Err(Error::Network), Ok((metadata, bytes)) => { (metadata.final_url, String::from_utf8(bytes).unwrap()) diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 743a06ff5ec..f0294238db8 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -22,7 +22,7 @@ use dom::bindings::js::{Root, RootedReference}; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::str::{ByteString, DOMString, USVString, is_token}; -use dom::blob::{Blob, DataSlice}; +use dom::blob::{Blob, DataSlice, BlobImpl}; use dom::document::DocumentSource; use dom::document::{Document, IsHTMLDocument}; use dom::event::{Event, EventBubbles, EventCancelable}; @@ -1134,8 +1134,8 @@ impl XMLHttpRequest { let mime = self.final_mime_type().as_ref().map(Mime::to_string).unwrap_or("".to_owned()); // Step 3, 4 - let slice = DataSlice::new(Arc::new(self.response.borrow().to_vec()), None, None); - let blob = Blob::new(self.global().r(), slice, &mime); + let slice = DataSlice::from_bytes(self.response.borrow().to_vec()); + let blob = Blob::new(self.global().r(), BlobImpl::new_from_slice(slice), &mime); self.response_blob.set(Some(blob.r())); blob } @@ -1419,13 +1419,12 @@ impl Extractable for BodyInit { Some(DOMString::from("application/x-www-form-urlencoded;charset=UTF-8"))) }, BodyInit::Blob(ref b) => { - let data = b.get_data(); let content_type = if b.Type().as_ref().is_empty() { None } else { Some(b.Type()) }; - (data.get_bytes().to_vec(), content_type) + (b.get_slice_or_empty().get_bytes().to_vec(), content_type) }, } } |