Closed
Bug 647653
Opened 15 years ago
Closed 14 years ago
It should be possible to create nsIDOMBlob in JavaScript XPCOM components
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla8
People
(Reporter: j, Assigned: khuey)
Details
(Keywords: dev-doc-complete, Whiteboard: fixed-in-bs)
Attachments
(2 files)
|
4.45 KB,
application/x-javascript
|
Details | |
|
11.90 KB,
patch
|
mrbkap
:
review+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0
Build Identifier:
It would be nice to be able to return nsIDOMBlob objects or implement nsIDOMBlob inside a custom xpcom element for an extension to make files/data available inside the DOM. i.e. like this:
f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
f.initWithPath(..);
f.QueryInterface(Ci.nsIDOMBlob)
Right now there is no way to create an nsIDOMBlob from an nsILocalFile.
Trying to implement a Javascript XPCOM element with nsIDOMBlob interface was also seams to be impossbile since i.e nsIPartialFileInputStream is not abailable:
Cc["@mozilla.org/network/partial-file-input-stream;1"]
.createInstance(Ci.nsIPartialFileInputStream);
Its is also not quite clear how one could add a moz-filedata: url to implement
getInternalUrl in Kavascript.
Reproducible: Always
| Reporter | ||
Comment 1•14 years ago
|
||
ongoing attempt to implement nsIDOMBlob in a JavaScript component,
it does not seam to call my getInternalUrl function.
[Exception... "Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIDOMFileReader.readAsBinaryString]" nsresult: "0x804b000a (NS_ERROR_MALFORMED_URI)"]
even if getInternalUrl would be called, it does not seam to be possible to add url to
nsFileDataProtocolHandler from Javascript,
namely calling:
nsFileDataProtocolHandler::AddFileDataEntry(url, this, aPrincipal);
| Reporter | ||
Comment 2•14 years ago
|
||
Is this a dupe of bug 607114?
| Assignee | ||
Comment 4•14 years ago
|
||
Yes, accept Bug 607114 would have nicer syntax :-)
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
| Assignee | ||
Comment 5•14 years ago
|
||
We didn't do this for components ... maybe we should.
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---
| Assignee | ||
Comment 6•14 years ago
|
||
This shouldn't be too hard to do, but I don't know if I should be adding the code to nsXPConnect::InitClasses, nsXPConnect::InitClassesWithNewWrappedGlobal, or both.
Blake?
Comment 7•14 years ago
|
||
On IRC, I floated the idea of just using a contract ID for this. But as that would be awkward, the answer to Kyle's question is that you need to add it to both.
You do need to be a little careful that you don't add it to Windows or ChromeWindows, though... I can't think of a clean way of doing that off the top of my head without checking the JSClass's name field :-/
Another option that might be cleaner would be to figure out a way to add the constructor in mozJSComponentLoader, the way that we add atob and dump to components' global objects.
| Reporter | ||
Comment 8•14 years ago
|
||
Was any decision made how to move this forward?
| Assignee | ||
Comment 9•14 years ago
|
||
(In reply to comment #8)
> Was any decision made how to move this forward?
Yeah, it should be pretty straightforward to add a constructor to the JS component loader. I just need to sit down and do it.
| Assignee | ||
Comment 10•14 years ago
|
||
Comment 11•14 years ago
|
||
Comment on attachment 542950 [details] [diff] [review]
Patch
Review of attachment 542950 [details] [diff] [review]:
-----------------------------------------------------------------
::: js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ +260,5 @@
> + return JS_FALSE;
> + }
> +
> + nsCOMPtr<nsIXPConnect> xpc =
> + do_GetService(kXPConnectServiceContractID, &rv);
Why not use nsXPConnect::GetXPConnect()?
@@ +272,5 @@
> + XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
> + return JS_FALSE;
> + }
> +
> + JSObject* glob = JS_GetGlobalForObject(cx, scope);
You can just use JS_GetGlobalForScopeChain here.
@@ +278,5 @@
> + nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
> + jsval retval;
> + rv = xpc->WrapNativeToJSVal(cx, glob, native, nsnull,
> + &NS_GET_IID(nsISupports),
> + PR_FALSE, &retval, nsnull);
It looks like your passing PR_FALSE for aAllowWrapping. I think that should be PR_TRUE.
Attachment #542950 -
Flags: review?(mrbkap) → review+
| Assignee | ||
Comment 12•14 years ago
|
||
(In reply to comment #11)
> Comment on attachment 542950 [details] [diff] [review] [review]
> Patch
>
> Review of attachment 542950 [details] [diff] [review] [review]:
> -----------------------------------------------------------------
>
> ::: js/src/xpconnect/loader/mozJSComponentLoader.cpp
> @@ +260,5 @@
> > + return JS_FALSE;
> > + }
> > +
> > + nsCOMPtr<nsIXPConnect> xpc =
> > + do_GetService(kXPConnectServiceContractID, &rv);
>
> Why not use nsXPConnect::GetXPConnect()?
Oh hey, that's neat.
> @@ +272,5 @@
> > + XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
> > + return JS_FALSE;
> > + }
> > +
> > + JSObject* glob = JS_GetGlobalForObject(cx, scope);
>
> You can just use JS_GetGlobalForScopeChain here.
That's neat too.
> @@ +278,5 @@
> > + nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
> > + jsval retval;
> > + rv = xpc->WrapNativeToJSVal(cx, glob, native, nsnull,
> > + &NS_GET_IID(nsISupports),
> > + PR_FALSE, &retval, nsnull);
>
> It looks like your passing PR_FALSE for aAllowWrapping. I think that should
> be PR_TRUE.
ok.
| Assignee | ||
Comment 13•14 years ago
|
||
Whiteboard: fixed-in-bs
| Assignee | ||
Comment 14•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago → 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
| Assignee | ||
Updated•14 years ago
|
Keywords: dev-doc-needed
Comment 15•14 years ago
|
||
Am I correct that the change here is that you can now do "new File" in chrome code to create a DOM File object?
| Assignee | ||
Comment 16•14 years ago
|
||
You can do new File in component scopes to create a DOM File object. This has worked in chrome window scopes previously.
Comment 17•14 years ago
|
||
Documentation updated:
https://developer.mozilla.org/en/DOM/File#Gecko_notes
https://developer.mozilla.org/en/Extensions/Using_the_DOM_File_API_in_chrome_code#Notes
Also mentioned on Firefox 8 for developers.
Keywords: dev-doc-needed → dev-doc-complete
Comment 18•12 years ago
|
||
So how do you create an nsIDOMBlob object...?
Something like Cc["@mozilla.org/files/blob;1"].createInstance(Ci.nsIDOMBlob, [oFileBody], { type: "text/xml"});?
Thanks.
| Assignee | ||
Comment 19•12 years ago
|
||
new Blob(arguments);
Comment 20•12 years ago
|
||
Are you sure...?
I'm pretty sure I have to use XPCOM stuff...
[21:22:41.674] ReferenceError: Blob is not defined @ resource://gre/modules/XPIProvider.jsm -> jar:file:///Users/main/Library/Application%20Support/Firefox/Profiles/xfm2tq4r.default/extensions/jid0-AaE9xBnbY78IjyBB6jwVpaKiyKQ@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid0-aae9xbnby78ijybb6jwvpakiykq-at-jetpack/s12chung/lib/main.js:32
Comment 21•12 years ago
|
||
funny. someone just answered it on stackoverflow: http://stackoverflow.com/questions/19780396/use-blob-on-firefox-add-on
thanks for getting back so quickly though :). happy monday.
| Assignee | ||
Comment 22•12 years ago
|
||
Oh ... that's some weird SDK thing then.
You need to log in
before you can comment on or make changes to this bug.
Description
•