Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement file related functionalities in htmlinputelement and related #11225

Merged
merged 1 commit into from May 23, 2016

Conversation

@izgzhen
Copy link
Contributor

izgzhen commented May 17, 2016

  • ./mach build -d does not report any errors
  • ./mach test-tidy --faster does not report any errors
  • These changes is related to #11131
  • These changes do not require tests because it is a partial implementation

Major changes

  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

This change is Reviewable

@highfive
Copy link

highfive commented May 17, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/filemanager_thread.rs, components/script/dom/file.rs, components/net_traits/filemanager_thread.rs, components/net_traits/filemanager_thread.rs, components/script/dom/htmlformelement.rs, components/script/dom/htmlinputelement.rs, components/script/dom/filelist.rs
@highfive
Copy link

highfive commented May 17, 2016

warning Warning warning

  • These commits modify net and script code, but no tests are modified. Please consider adding a test!
@izgzhen
Copy link
Contributor Author

izgzhen 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.

@Manishearth

Manishearth May 17, 2016

Member

We shouldn't be guessing the MIME here, right?

This comment has been minimized.

@izgzhen

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.

@Manishearth

Manishearth May 17, 2016

Member

This doesn't use fakepath?

This comment has been minimized.

@izgzhen

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

@mbrubeck mbrubeck assigned Manishearth and unassigned pcwalton May 19, 2016
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2016

The latest upstream changes (presumably #11270) made this pull request unmergeable. Please resolve the merge conflicts.

@izgzhen izgzhen force-pushed the izgzhen:patch-input-element-file branch 2 times, most recently from 24ccc71 to 38832c2 May 20, 2016
@bors-servo
Copy link
Contributor

bors-servo commented May 20, 2016

The latest upstream changes (presumably #11293) made this pull request unmergeable. Please resolve the merge conflicts.

pub filename: PathBuf,
pub modified: u64,
// https://w3c.github.io/FileAPI/#dfn-type
pub type_string: Option<String>,

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@izgzhen

izgzhen May 20, 2016

Author Contributor

Should we file an issue on this?

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@Manishearth

Manishearth May 23, 2016

Member

I guess we can remove this xxx?

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.

@Manishearth

Manishearth May 20, 2016

Member

The rooting here seems sketchy; but I think it should work. @nox, sanity-check?

This comment has been minimized.

@nox

nox May 20, 2016

Member

Should work, since files still root them.

match *self.filelist.borrow() {
Some(ref fl) => match fl.Item(0) {
Some(ref f) => {
path.push_str("C:\\fakepath\\");

This comment has been minimized.

@Manishearth

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.

@Manishearth

Manishearth May 20, 2016

Member

MutNullableHeap?

This comment has been minimized.

@Manishearth

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.

@izgzhen

izgzhen May 20, 2016

Author Contributor

By "holistic" you mean?

This comment has been minimized.

@Manishearth

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.

@izgzhen

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.

@Manishearth

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.

Err(err) => panic!("Input file select error: {:?}", err)
};
} else {
let (chan, recv) = ipc::channel().unwrap();

This comment has been minimized.

@izgzhen izgzhen force-pushed the izgzhen:patch-input-element-file branch from 38832c2 to bfd1c45 May 20, 2016
}
},
// 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.

@izgzhen

izgzhen May 20, 2016

Author Contributor

@Manishearth don't know how to handle this properly without panicking ... any suggestion?

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@izgzhen

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.

@Manishearth

Manishearth May 21, 2016

Member

Yeah, it is, basically

@izgzhen izgzhen force-pushed the izgzhen:patch-input-element-file branch from bfd1c45 to 6e74884 May 21, 2016
@Manishearth
Copy link
Member

Manishearth commented May 23, 2016

@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)

@bors-servo
Copy link
Contributor

bors-servo commented May 23, 2016

✌️ @izgzhen can now approve this pull request

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
@izgzhen izgzhen force-pushed the izgzhen:patch-input-element-file branch from 6e74884 to dd590d0 May 23, 2016
@izgzhen
Copy link
Contributor Author

izgzhen commented May 23, 2016

@bors-servo r=Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented May 23, 2016

📌 Commit dd590d0 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented May 23, 2016

Testing commit dd590d0 with merge 7cea4eb...

bors-servo added a commit that referenced this pull request May 23, 2016
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 -->
@bors-servo
Copy link
Contributor

bors-servo commented May 23, 2016

@bors-servo bors-servo merged commit dd590d0 into servo:master May 23, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.