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