Closed
Bug 1159401
Opened 8 years ago
Closed 8 years ago
Make dom::File sane to use from c++
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla41
People
(Reporter: bzbarsky, Assigned: baku)
References
Details
Attachments
(1 file, 3 obsolete files)
204.74 KB,
patch
|
Details | Diff | Splinter Review |
Right now, if I have a dom::File there are some methods that are footguns to call, because they will assert if !IsFile(). We should do one of two possible things here, imo: 1) Remove those asserts, just returns some sort of default values (empty strings, invalid dates, whatever). We may want to rename the class to Blob in that case anyway. 2) Have separate C++ classes for Blob and File, put the relevant methods on File only, have a ToFile() on Blob that asserts IsFile() and returns File* (or returns null if not IsFile(), or something). Either one would be better than what we have right now, where a File in the C++ might just mean Blob. Thoughts?
Assignee | ||
Comment 1•8 years ago
|
||
What about this: instead removing these asserts, we can move them from the FileImpl to the dom::File class. From C++ usually it's better to use FileImpl and leave File just for the JS DOM. What you suggest as section options, is actually FileImpl.
I think doing 1) would be the simplest. I don't see a purpose to these assertions anyway since both Blobs and Files may or may not actually be backed by an OS-file, so whether functions like GetMozFullPath can return a "real value" is independent of if it's a File or a Blob object.
![]() |
Reporter | |
Comment 3•8 years ago
|
||
> we can move them from the FileImpl to the dom::File class That doesn't solve my problem, which is that I have an array of dom::File, some of which are JS File and some of which are JS Blob and the code right now assumes they're all JS File and calls these methods. > From C++ usually it's better to use FileImpl All the stuff around file inputs is working with an array of File. > What you suggest as section options I'm not sure what you mean here....
Comment 4•8 years ago
|
||
2) seems to obviously be the correct design
Assignee | ||
Updated•8 years ago
|
Assignee: nobody → amarchesini
Assignee | ||
Comment 5•8 years ago
|
||
Attachment #8599498 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 6•8 years ago
|
||
Attachment #8599498 -
Attachment is obsolete: true
Attachment #8599498 -
Flags: review?(bzbarsky)
Attachment #8599896 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 7•8 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=4dcccb385511
![]() |
Reporter | |
Comment 8•8 years ago
|
||
Comment on attachment 8599896 [details] [diff] [review] blob.patch > ArchiveRequest::GetFileResult(JSContext* aCx, >+ if (!GetOrCreateDOMReflector(aCx, file, aValue)) { Could probably use ToJSValue here too. This comes up multiple places in the patch. >+Blob::Create(nsISupports* aParent, const nsAString& aContentType, >+ uint64_t aStart, uint64_t aLength) Fix indent? >+ nsCOMPtr<nsIDOMBlob> domBlob = this; >+ nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(domBlob); Should just be able to do_QueryObject(this). But also, can we not just have a protected virtual method to answer the "am I actually a File" question instead of relying on the much slower QI? >+Blob::ToFile() Seems like this could up front check IsFile() and return nullptr if not, then outdent the rest of the logic. >+Blob::GetLastModifiedDate(ErrorResult& aRv) I'm not sure I follow why this is on Blob, not File. It ends up asserting mIsFile, no? And in IDL terms it's on File, not on Blob. >+Blob::GetLastModified(ErrorResult& aRv) Likewise. >+File::Create(nsISupports* aParent, FileImpl* aImpl) Are there any actual consumers that would expect this to return null? If not, can we MOZ_CRASH if !aImpl->IsFile()? I guess there's nsFilePickerProxy, but we could just make that check IsFile() on the FileImpl, right? >+ already_AddRefed<File> ToFile(); This needs some documentation. >+ already_AddRefed<File> ToFile(const nsAString& aName) const; And this. Esp. given how much the differ from each other! >+ static File* >+ Create(nsISupports* aParent, FileImpl* aImpl); Should document the constraints on FileImpl. >+ // File constructor should never be used directly. Use Blob instead. Blob constructor should never be used either. Do you mean use Blob::Create? Or File::Create? Or something else? >+nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aBlob, JSContext* aCx) ... >+ nsRefPtr<Blob> blob = static_cast<Blob*>(aBlob); So I _think_ this is a problem. The issue is that File now multiply-inherits from nsIDOMBlob with your changes: one path via Blob and one path via nsIDOMFile. So if aBlob is actually a File, and that's a pointer to the nsIDOMBlob version that came from nsIDOMFile (which is NOT the canonical nsIDOMBlob* for a File, of course), this cast will do the wrong thing. We need to either QI to nsIDOMBlob in all places where we do casts like this, or get rid of the multiple inheritance by making nsIDOMFile no longer inherit from nsIDOMBlob. I would prefer the latter, I think; it's way less surprising. Might want a comment in the IDL explaining why the inheritance is not there, of course. >+nsFormData::Append(const nsAString& aName, Blob& aBlob, >+ nsRefPtr<Blob> blob = CreateNewFileInstance(aBlob, aFilename); The whole point of CreateNewFileInstance is to return a File. So why are we assigning it into a Blob? We should be assigning into a File, and AddNameFilePair should take a File* for the second arg. And then it won't need the weird ToFile and assert. In fact, you could just leave the old code for it in the header, with aBlob renamed to aFile. >+++ b/dom/events/DataTransfer.cpp >+ File::Create(GetParentObject(), >+ static_cast<FileImpl*>(fileImpl.get())); Why is that static_cast, or the .get() call needed? Seems like you should be able to just pass fileImpl here. >+++ b/dom/filesystem/FileSystemTaskBase.cpp >+ { >+ ErrorResult rv; >+ aFile->GetSize(rv); >+ } We should either SuppressException() or assert that there is no exception or something here. >+ aFile->GetLastModified(rv); Likewise. And maybe document that we're just calling these for the side-effects? Because it looks pretty confusing as it is. > nsFSMultipartFormData::AddNameFilePair(const nsAString& aName, > // Since Bug 1127150, any Blob received from FormData must be a File Can we just leave this function taking a File*? That will make it clearer what's going on, and when that invariant changes the compiler will tell us that we need to change this function accordingly. Same for the other AddNameFilePair impls. >@@ -385,18 +385,19 @@ MmsMessage::GetData(ContentParent* aPare >+ if (rv.Failed()) { > NS_WARNING("Failed to get last modified date!"); rv.SuppressException()? We should consider a followup to rename FileImpl to BlobImpl... r=me with the above nits fixed (esp. the nsIDOM* inheritance thing). Thank you for doing this!
Attachment #8599896 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 9•8 years ago
|
||
> We need to either QI to nsIDOMBlob in all places where we do casts like
> this, or get rid of the multiple inheritance by making nsIDOMFile no longer
> inherit from nsIDOMBlob. I would prefer the latter, I think; it's way less
> surprising. Might want a comment in the IDL explaining why the inheritance
> is not there, of course.
What about if we get rid of nsIDOMFile completely? I see just Firefox OS emulator addon using nsIDOMFile. Do you think it's doable?
Flags: needinfo?(bzbarsky)
![]() |
Reporter | |
Comment 10•8 years ago
|
||
> What about if we get rid of nsIDOMFile completely?
Sounds lovely to me, esp. if we can do it as a followup instead of blocking this patch on it.
Flags: needinfo?(bzbarsky)
Assignee | ||
Comment 11•8 years ago
|
||
It seems that I don't have to include all the members of nsIDOMBlob in nsIDOMFile, but tell me if I'm wrong. https://treeherder.mozilla.org/#/jobs?repo=try&revision=eab217e34c1b
Attachment #8603822 -
Flags: review?(bzbarsky)
![]() |
Reporter | |
Comment 12•8 years ago
|
||
Comment on attachment 8603822 [details] [diff] [review] patch 2 r=me if you mention in the comment that we want to avoid multiple inheritance so we can downcast from nsIDOMBlob to Blob safely.
Attachment #8603822 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 13•8 years ago
|
||
remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/96a3ebfe09d8 remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/4287533203fb
Comment 14•8 years ago
|
||
Backed out for bustage. https://hg.mozilla.org/integration/mozilla-inbound/rev/49678aa590e2 https://treeherder.mozilla.org/logviewer.html#?job_id=9741867&repo=mozilla-inbound
Assignee | ||
Comment 15•8 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/70c63c8546e3 https://hg.mozilla.org/integration/mozilla-inbound/rev/adfee1efb1e1
Comment 16•8 years ago
|
||
The first patch here introduced some -Winconsistent-missing-override build warnings (in clang 3.6+) for nsFormSubmission.cpp -- specifically, for the class "nsFSURLEncoded" methods SupportsIsindexSubmission() & AddIsindex(). (Those methods (and their overriding status) predated this patch. I think the warnings appeared just now because the patch marked a *different* overridding method as 'override', which made the lack-of-override-keyword on these other methods appear 'inconsistent', hence -Winconsistent-missing-override.) Pushed a patch with rs=ehsan (granted in bug 1126447 comment 2): https://hg.mozilla.org/integration/mozilla-inbound/rev/5eec0168c916
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/86efbb9287a4 for b2g build bustage, even after that followup: https://treeherder.mozilla.org/logviewer.html#?job_id=9750973&repo=mozilla-inbound
Flags: needinfo?(amarchesini)
And because I pushed that backout before I had realized there was a followup, here's a backout of the followup: https://hg.mozilla.org/integration/mozilla-inbound/rev/0c80b9af0593
Comment 19•8 years ago
|
||
(When this re-lands, ideally it'd be great to have the 'override' followup just merged into the first patch here, so that every intermediate cset builds cleanly with clang > 3.6.)
Assignee | ||
Comment 20•8 years ago
|
||
https://treeherder.mozilla.org/#/jobs?repo=try&revision=a3bf5ee35d40 single patch.
Attachment #8599896 -
Attachment is obsolete: true
Attachment #8603822 -
Attachment is obsolete: true
Flags: needinfo?(amarchesini)
Assignee | ||
Updated•8 years ago
|
Keywords: checkin-needed
Comment 21•8 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/f1dd5e362984
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/f1dd5e362984
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox41:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
Updated•4 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•