2011-08-15 20:40:38 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
#include "File.h"
|
|
|
|
|
|
|
|
#include "nsIDOMFile.h"
|
2012-03-24 04:33:59 -07:00
|
|
|
#include "nsDOMBlobBuilder.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
#include "jsapi.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsfriendapi.h"
|
2011-08-15 20:40:38 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
|
|
|
#include "Exceptions.h"
|
|
|
|
#include "WorkerInlines.h"
|
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
|
|
|
|
#define PROPERTY_FLAGS \
|
2012-02-13 00:02:21 -08:00
|
|
|
(JSPROP_ENUMERATE | JSPROP_SHARED)
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
USING_WORKERS_NAMESPACE
|
|
|
|
|
2012-04-24 16:50:00 -07:00
|
|
|
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Blob
|
|
|
|
{
|
|
|
|
// Blob should never be instantiated.
|
|
|
|
Blob();
|
|
|
|
~Blob();
|
|
|
|
|
|
|
|
static JSClass sClass;
|
|
|
|
static JSPropertySpec sProperties[];
|
|
|
|
static JSFunctionSpec sFunctions[];
|
|
|
|
|
|
|
|
public:
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj)
|
|
|
|
{
|
|
|
|
return JS_InitClass(aCx, aObj, NULL, &sClass, Construct, 0, sProperties,
|
|
|
|
sFunctions, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
Create(JSContext* aCx, nsIDOMBlob* aBlob)
|
|
|
|
{
|
|
|
|
JS_ASSERT(SameCOMIdentity(static_cast<nsISupports*>(aBlob), aBlob));
|
|
|
|
|
|
|
|
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
|
|
|
|
if (obj) {
|
2012-02-05 12:07:23 -08:00
|
|
|
JS_SetPrivate(obj, aBlob);
|
2011-08-15 20:40:38 -07:00
|
|
|
NS_ADDREF(aBlob);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIDOMBlob*
|
2012-02-05 12:07:23 -08:00
|
|
|
GetPrivate(JSObject* aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
static nsIDOMBlob*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
|
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
nsIDOMBlob* blob = GetPrivate(aObj);
|
2012-02-03 10:00:08 -08:00
|
|
|
if (blob) {
|
|
|
|
return blob;
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
|
|
|
|
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
|
2012-02-03 16:54:57 -08:00
|
|
|
JS_GetClass(aObj)->name);
|
2011-08-15 20:40:38 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:33:59 -07:00
|
|
|
static nsIDOMBlob*
|
|
|
|
Unwrap(JSContext* aCx, JSObject* aObj)
|
|
|
|
{
|
|
|
|
return GetPrivate(aObj);
|
|
|
|
}
|
|
|
|
|
2011-08-15 20:40:38 -07:00
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
2013-01-17 12:17:33 -08:00
|
|
|
nsRefPtr<nsDOMMultipartFile> file = new nsDOMMultipartFile();
|
2012-12-11 13:21:03 -08:00
|
|
|
nsresult rv = file->InitBlob(aCx, aArgc, JS_ARGV(aCx, aVp), Unwrap);
|
2012-03-24 04:33:59 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-04-24 16:50:00 -07:00
|
|
|
ThrowDOMExceptionForNSResult(aCx, rv);
|
2012-03-24 04:33:59 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* obj = file::CreateBlob(aCx, file);
|
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(obj));
|
|
|
|
return true;
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
2012-02-03 16:54:57 -08:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == &sClass);
|
2011-08-15 20:40:38 -07:00
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
nsIDOMBlob* blob = GetPrivate(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
NS_IF_RELEASE(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
GetSize(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
nsIDOMBlob* blob = GetInstancePrivate(aCx, aObj, "size");
|
|
|
|
if (!blob) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t size;
|
2011-08-15 20:40:38 -07:00
|
|
|
if (NS_FAILED(blob->GetSize(&size))) {
|
2012-04-24 16:50:00 -07:00
|
|
|
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
|
|
|
|
return false;
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
2012-08-01 17:59:47 -07:00
|
|
|
aVp.set(JS_NumberValue(double(size)));
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
GetType(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
nsIDOMBlob* blob = GetInstancePrivate(aCx, aObj, "type");
|
|
|
|
if (!blob) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
if (NS_FAILED(blob->GetType(type))) {
|
2012-04-24 16:50:00 -07:00
|
|
|
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
|
|
|
|
return false;
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSString* jsType = JS_NewUCStringCopyN(aCx, type.get(), type.Length());
|
|
|
|
if (!jsType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
aVp.set(STRING_TO_JSVAL(jsType));
|
2011-08-15 20:40:38 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Slice(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
|
2011-12-01 13:30:28 -08:00
|
|
|
if (!obj) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-15 20:40:38 -07:00
|
|
|
|
2012-02-16 02:22:25 -08:00
|
|
|
nsIDOMBlob* blob = GetInstancePrivate(aCx, obj, "slice");
|
2011-08-15 20:40:38 -07:00
|
|
|
if (!blob) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double start = 0, end = 0;
|
2011-08-15 20:40:38 -07:00
|
|
|
JSString* jsContentType = JS_GetEmptyString(JS_GetRuntime(aCx));
|
|
|
|
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "/IIS", &start,
|
|
|
|
&end, &jsContentType)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString contentType;
|
|
|
|
if (!contentType.init(aCx, jsContentType)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t optionalArgc = aArgc;
|
2011-08-15 20:40:38 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> rtnBlob;
|
2012-08-22 08:56:38 -07:00
|
|
|
if (NS_FAILED(blob->Slice(static_cast<uint64_t>(start),
|
|
|
|
static_cast<uint64_t>(end),
|
2012-02-16 02:22:25 -08:00
|
|
|
contentType, optionalArgc,
|
|
|
|
getter_AddRefs(rtnBlob)))) {
|
2012-04-24 16:50:00 -07:00
|
|
|
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
|
2011-08-15 20:40:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* rtnObj = file::CreateBlob(aCx, rtnBlob);
|
|
|
|
if (!rtnObj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_SET_RVAL(aCx, aVp, OBJECT_TO_JSVAL(rtnObj));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JSClass Blob::sClass = {
|
|
|
|
"Blob",
|
|
|
|
JSCLASS_HAS_PRIVATE,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
2012-03-19 07:27:58 -07:00
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize
|
2011-08-15 20:40:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSPropertySpec Blob::sProperties[] = {
|
2012-08-07 22:26:18 -07:00
|
|
|
{ "size", 0, PROPERTY_FLAGS, JSOP_WRAPPER(GetSize), JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
|
|
|
|
{ "type", 0, PROPERTY_FLAGS, JSOP_WRAPPER(GetType), JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
|
|
|
|
{ 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER }
|
2011-08-15 20:40:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSFunctionSpec Blob::sFunctions[] = {
|
2012-02-16 02:22:25 -08:00
|
|
|
JS_FN("slice", Slice, 1, JSPROP_ENUMERATE),
|
2011-08-15 20:40:38 -07:00
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
class File : public Blob
|
|
|
|
{
|
|
|
|
// File should never be instantiated.
|
|
|
|
File();
|
|
|
|
~File();
|
|
|
|
|
|
|
|
static JSClass sClass;
|
|
|
|
static JSPropertySpec sProperties[];
|
|
|
|
|
|
|
|
public:
|
|
|
|
static JSObject*
|
|
|
|
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto)
|
|
|
|
{
|
|
|
|
return JS_InitClass(aCx, aObj, aParentProto, &sClass, Construct, 0,
|
|
|
|
sProperties, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
Create(JSContext* aCx, nsIDOMFile* aFile)
|
|
|
|
{
|
|
|
|
JS_ASSERT(SameCOMIdentity(static_cast<nsISupports*>(aFile), aFile));
|
|
|
|
|
|
|
|
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
|
|
|
|
if (obj) {
|
2012-02-05 12:07:23 -08:00
|
|
|
JS_SetPrivate(obj, aFile);
|
2011-08-15 20:40:38 -07:00
|
|
|
NS_ADDREF(aFile);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIDOMFile*
|
2012-02-05 12:07:23 -08:00
|
|
|
GetPrivate(JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
if (aObj) {
|
2012-02-03 16:54:57 -08:00
|
|
|
JSClass* classPtr = JS_GetClass(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
if (classPtr == &sClass) {
|
2012-02-05 12:07:23 -08:00
|
|
|
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aObj));
|
2011-08-15 20:40:38 -07:00
|
|
|
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(priv);
|
|
|
|
JS_ASSERT_IF(priv, file);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSClass*
|
|
|
|
Class()
|
|
|
|
{
|
|
|
|
return &sClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static nsIDOMFile*
|
|
|
|
GetInstancePrivate(JSContext* aCx, JSObject* aObj, const char* aFunctionName)
|
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
nsIDOMFile* file = GetPrivate(aObj);
|
2012-02-03 10:00:08 -08:00
|
|
|
if (file) {
|
|
|
|
return file;
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
|
|
|
|
JSMSG_INCOMPATIBLE_PROTO, sClass.name, aFunctionName,
|
2012-02-03 16:54:57 -08:00
|
|
|
JS_GetClass(aObj)->name);
|
2011-08-15 20:40:38 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_WRONG_CONSTRUCTOR,
|
|
|
|
sClass.name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
Finalize(JSFreeOp* aFop, JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
2012-02-03 16:54:57 -08:00
|
|
|
JS_ASSERT(JS_GetClass(aObj) == &sClass);
|
2011-08-15 20:40:38 -07:00
|
|
|
|
2012-02-05 12:07:23 -08:00
|
|
|
nsIDOMFile* file = GetPrivate(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
NS_IF_RELEASE(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
GetMozFullPath(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
nsIDOMFile* file = GetInstancePrivate(aCx, aObj, "mozFullPath");
|
|
|
|
if (!file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString fullPath;
|
|
|
|
|
|
|
|
if (GetWorkerPrivateFromContext(aCx)->UsesSystemPrincipal() &&
|
|
|
|
NS_FAILED(file->GetMozFullPathInternal(fullPath))) {
|
2012-04-24 16:50:00 -07:00
|
|
|
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
|
2011-08-15 20:40:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* jsFullPath = JS_NewUCStringCopyN(aCx, fullPath.get(),
|
|
|
|
fullPath.Length());
|
|
|
|
if (!jsFullPath) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
aVp.set(STRING_TO_JSVAL(jsFullPath));
|
2011-08-15 20:40:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
GetName(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
nsIDOMFile* file = GetInstancePrivate(aCx, aObj, "name");
|
|
|
|
if (!file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString name;
|
|
|
|
if (NS_FAILED(file->GetName(name))) {
|
|
|
|
name.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* jsName = JS_NewUCStringCopyN(aCx, name.get(), name.Length());
|
|
|
|
if (!jsName) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
aVp.set(STRING_TO_JSVAL(jsName));
|
2011-08-15 20:40:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-04 07:19:00 -08:00
|
|
|
|
|
|
|
static JSBool
|
|
|
|
GetLastModifiedDate(JSContext* aCx, JSHandleObject aObj, JSHandleId aIdval, JSMutableHandleValue aVp)
|
|
|
|
{
|
|
|
|
nsIDOMFile* file = GetInstancePrivate(aCx, aObj, "lastModifiedDate");
|
|
|
|
if (!file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value value;
|
|
|
|
if (NS_FAILED(file->GetLastModifiedDate(aCx, &value))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aVp.set(value);
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-15 20:40:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSClass File::sClass = {
|
|
|
|
"File",
|
|
|
|
JSCLASS_HAS_PRIVATE,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
2012-03-19 07:27:58 -07:00
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize
|
2011-08-15 20:40:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JSPropertySpec File::sProperties[] = {
|
2012-08-07 22:26:18 -07:00
|
|
|
{ "name", 0, PROPERTY_FLAGS, JSOP_WRAPPER(GetName),
|
|
|
|
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
|
2012-11-04 07:19:00 -08:00
|
|
|
{ "lastModifiedDate", 0, PROPERTY_FLAGS, JSOP_WRAPPER(GetLastModifiedDate),
|
|
|
|
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
|
2012-08-07 22:26:18 -07:00
|
|
|
{ "mozFullPath", 0, PROPERTY_FLAGS, JSOP_WRAPPER(GetMozFullPath),
|
|
|
|
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
|
|
|
|
{ 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER }
|
2011-08-15 20:40:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsIDOMBlob*
|
2012-02-05 12:07:23 -08:00
|
|
|
Blob::GetPrivate(JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
|
|
|
if (aObj) {
|
2012-02-03 16:54:57 -08:00
|
|
|
JSClass* classPtr = JS_GetClass(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
if (classPtr == &sClass || classPtr == File::Class()) {
|
2012-02-05 12:07:23 -08:00
|
|
|
nsISupports* priv = static_cast<nsISupports*>(JS_GetPrivate(aObj));
|
2011-08-15 20:40:38 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(priv);
|
|
|
|
JS_ASSERT_IF(priv, blob);
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
namespace file {
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
CreateBlob(JSContext* aCx, nsIDOMBlob* aBlob)
|
|
|
|
{
|
|
|
|
return Blob::Create(aCx, aBlob);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InitClasses(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
JSObject* blobProto = Blob::InitClass(aCx, aGlobal);
|
|
|
|
return blobProto && File::InitClass(aCx, aGlobal, blobProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMBlob*
|
2012-02-05 12:07:23 -08:00
|
|
|
GetDOMBlobFromJSObject(JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
return Blob::GetPrivate(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
CreateFile(JSContext* aCx, nsIDOMFile* aFile)
|
|
|
|
{
|
|
|
|
return File::Create(aCx, aFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMFile*
|
2012-02-05 12:07:23 -08:00
|
|
|
GetDOMFileFromJSObject(JSObject* aObj)
|
2011-08-15 20:40:38 -07:00
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
return File::GetPrivate(aObj);
|
2011-08-15 20:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace file
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|