Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement file related functionalities in htmlinputelement and related #11225
Conversation
highfive
commented
May 17, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
May 17, 2016
|
@Manishearth yet another piece of code :P |
| (Ok(epoch), Some(filename)) => Some((id, Path::new(filename).to_path_buf(), epoch)), | ||
| (Ok(epoch), Some(filename)) => { | ||
| let filename_path = Path::new(filename); | ||
| let mime = guess_mime_type_opt(filename_path); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
izgzhen
May 19, 2016
Author
Contributor
https://w3c.github.io/FileAPI/#dfn-type it said that:
User agents can also determine the type of a Blob, especially if the byte sequence is from an on-disk file
And also, I can't image other source of type instead of determining it at the time of reading.
| DOMString::from("") | ||
| let default = DOMString::from(""); | ||
| match *self.filelist.borrow() { | ||
| Some(ref fl) => match fl.Item(0) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
izgzhen
May 19, 2016
Author
Contributor
Ahhh it my fault. I thought the comment doesn't mean fakepath as it is .... http://www.w3.org/TR/html5/forms.html#dom-input-value-filename
|
|
24ccc71
to
38832c2
|
|
| pub filename: PathBuf, | ||
| pub modified: u64, | ||
| // https://w3c.github.io/FileAPI/#dfn-type | ||
| pub type_string: Option<String>, |
This comment has been minimized.
This comment has been minimized.
Manishearth
May 20, 2016
Member
No need for an option, type is "" if there is no type (according to the spec)
| let slice = DataSlice::empty(); | ||
|
|
||
| let global = GlobalRef::Window(window); | ||
| // XXX: as i64? looks like DOM codegen and std::fs don't agree on this type |
This comment has been minimized.
This comment has been minimized.
Manishearth
May 20, 2016
•
Member
It's only one bit of difference in capacity. Though I'm not sure why the DOM has a signed long long there (bug?)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
On the spec? Sure. https://github.com/whatwg/html. Might be worth investigating what the type is in the kernel first and whether a negative mtime is useful.
This comment has been minimized.
This comment has been minimized.
izgzhen
May 21, 2016
Author
Contributor
Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx
Linux: http://stackoverflow.com/questions/471248/what-is-ultimately-a-time-t-typedef-to
Ok, maybe we should left this as it is :(
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
Seems like it won't matter since Date breaks down at i64::max_value anyway. If the cast breaks anything, it will be a billion years from now :p
This comment has been minimized.
This comment has been minimized.
| pub fn new(window: &Window, files: Vec<JS<File>>) -> Root<FileList> { | ||
| reflect_dom_object(box FileList::new_inherited(files), GlobalRef::Window(window), FileListBinding::Wrap) | ||
| pub fn new(window: &Window, files: Vec<Root<File>>) -> Root<FileList> { | ||
| reflect_dom_object(box FileList::new_inherited(files.iter().map(|r| JS::from_rooted(&r)).collect()), |
This comment has been minimized.
This comment has been minimized.
Manishearth
May 20, 2016
Member
The rooting here seems sketchy; but I think it should work. @nox, sanity-check?
This comment has been minimized.
This comment has been minimized.
| match *self.filelist.borrow() { | ||
| Some(ref fl) => match fl.Item(0) { | ||
| Some(ref f) => { | ||
| path.push_str("C:\\fakepath\\"); |
This comment has been minimized.
This comment has been minimized.
Manishearth
May 20, 2016
Member
Interestingly, firefox doesn't seem to follow this. But we'll implement the spec and perhaps file a firefox or spec bug later.
| @@ -81,7 +86,7 @@ pub struct HTMLInputElement { | |||
| // https://html.spec.whatwg.org/multipage/#concept-input-value-dirty-flag | |||
| value_dirty: Cell<bool>, | |||
|
|
|||
| // TODO: selected files for file input | |||
| filelist: DOMRefCell<Option<JS<FileList>>>, | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 20, 2016
Member
Not sure if this needs to be Option in the first place, really. Helps avoid unnecessary heap allocation, but there may be more holistic solutions for this.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
The Option lets us avoid allocating extra JavaScript objects in this specific case. A more holistic/general solution would have some form of reflector lazy loading so that JS isn't hit as much. We have discussed this in the past though there isn't anything concrete yet. But I'd prefer a general solution over a bunch of specific ones.
This comment has been minimized.
This comment has been minimized.
izgzhen
May 21, 2016
•
Author
Contributor
Having read doc on MutNullableHeap which says that it is safer. I mimicked the other fields in HTMLInputElement so I initially wrote the wrapper as DOMRefCell. MutNullableHeap looks like a primitive interface provided by jsapi.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
Oh, I see, it's an option because not all text inputs are file inputs, my bad.
Yeah, just use mutnullableheap here. It's not a primitive interface, but it's basically RefCell<Option<T>> where T is JS<U>. It's using DOMRefCell above because TextInput isn't a JS thing.
| let msg = FileManagerThreadMsg::SelectFiles(chan); | ||
| let _ = filemanager.send(msg).unwrap(); | ||
|
|
||
| match recv.recv().unwrap() { |
This comment has been minimized.
This comment has been minimized.
| Err(err) => panic!("Input file select error: {:?}", err) | ||
| }; | ||
| } else { | ||
| let (chan, recv) = ipc::channel().unwrap(); |
This comment has been minimized.
This comment has been minimized.
38832c2
to
bfd1c45
| } | ||
| }, | ||
| // XXX: I don't think we should panic here, but how to handle better? | ||
| Err(err) => panic!("Input file select error: {:?}", err) |
This comment has been minimized.
This comment has been minimized.
izgzhen
May 20, 2016
Author
Contributor
@Manishearth don't know how to handle this properly without panicking ... any suggestion?
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
Treat it as if no files were selected. This will probably happen if file upload was canceled.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 21, 2016
Member
Actually, treat it as a cancel. The difference is that as a cancel, the existing file list will not be cleared.
This comment has been minimized.
This comment has been minimized.
izgzhen
May 21, 2016
Author
Contributor
Good. I didn't see spec mentioning error handling so I am wondering if this is the so-called "implementation details"
This comment has been minimized.
This comment has been minimized.
bfd1c45
to
6e74884
|
@bors-servo delegate+ r=me after you remove that comment on the cast (feel free to replace it with a non-xxx comment explaining that the cast is okay) |
|
|
Changes include: - Implement file selection and other DOM behaviours in htmlinputelement - Integrate IpcSender<FileManagerThreadMsg> into ResourceThreads - Improve filemanager_thread, including adding type_string field to SelectedFile - Improve interfaces in FileList/File/Blob to accommodate the above changes
6e74884
to
dd590d0
|
@bors-servo r=Manishearth |
|
|
Implement file related functionalities in htmlinputelement and related - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy --faster` does not report any errors - [x] These changes is related to #11131 - [x] These changes do not require tests because it is a partial implementation 1. Improve the `filemanager_thread` by adding type string and create `SelectedFile` 2. Fill several gaps in `htmlinputelement` implementation related to file type 3. Improve the `File` interface to accommodate the above changes 4. Integrate changes introduced by PR #11189 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11225) <!-- Reviewable:end -->
|
|
izgzhen commentedMay 17, 2016
•
edited
./mach build -ddoes not report any errors./mach test-tidy --fasterdoes not report any errorsMajor changes
filemanager_threadby adding type string and createSelectedFilehtmlinputelementimplementation related to file typeFileinterface to accommodate the above changesThis change is