Initial checkin of Silentdownload. This does not hook it up to the build

system.
This commit is contained in:
dougt%netscape.com 1999-01-14 01:47:16 +00:00
Родитель 36083e9211
Коммит 581c3f6e74
10 изменённых файлов: 3341 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,16 @@
interface SilentDownload
{
/* IID: { 0x8648c1e0, 0x938b, 0x11d2, \
{ 0xb0, 0xdd, 0x0, 0x80, 0x5f, 0x8a, 0x88, 0x51 }} */
attribute long ByteRange;
attribute long Interval;
void Startup();
void Shutdown();
void Add(in SilentDownloadTask task);
void Remove(in SilentDownloadTask task);
SilentDownloadTask Find(in wstring id);
};

Просмотреть файл

@ -0,0 +1,38 @@
interface SilentDownloadTask
{
/* IID: { 0x8648c1e0, 0x938b, 0x11d2, \
{ 0xb0, 0xdd, 0x0, 0x80, 0x5f, 0x8a, 0x88, 0x50 }} */
const int SDL_NOT_INITED = -2;
const int SDL_NOT_ADDED = -1;
const int SDL_STARTED = 0;
const int SDL_SUSPENDED = 1;
const int SDL_COMPLETED = 2;
const int SDL_DOWNLOADING_NOW = 3;
const int SDL_ERROR = 4;
readonly attribute wstring id;
readonly attribute wstring url;
readonly attribute wstring script;
attribute long state;
attribute wstring errorMsg;
attribute long nextByte;
readonly attribute wstring outFile;
void SilentDownloadTask();
void Init(in wstring id, in wstring url, in wstring script);
void Remove();
void Suspend();
void Resume();
void DownloadNow();
void DownloadSelf(in long range);
};

79
silentdl/makefile.win Normal file
Просмотреть файл

@ -0,0 +1,79 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
MODULE=silentdl
DLL=.\$(OBJDIR)\$(MODULE).dll
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LINCS= \
-I$(XPDIST)\public\js \
-I$(XPDIST)\public\netlib \
-I$(XPDIST)\public\network \
-I$(XPDIST)\public\dom \
-I$(XPDIST)\public\xpcom \
-I$(XPDIST)\public\util \
-I$(XPDIST)\public\nspr2 \
-I$(XPDIST)\public\pref \
-I$(XPDIST)\public\raptor \
$(NULL)
LLIBS = \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\xppref32.lib \
$(DIST)\lib\xplib.lib \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\jsdombase_s.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(LIBNSPR) \
$(DIST)\lib\libplc21.lib \
$(NULL)
OBJS = \
.\$(OBJDIR)\nsJSSilentDownload.obj \
.\$(OBJDIR)\nsJSSilentDownloadTask.obj \
.\$(OBJDIR)\nsSilentDownload.obj \
$(NULL)
EXPORTS= \
nsIDOMSilentDownload.h \
nsIDOMSilentDownloadTask.h \
nsSilentDownload.h
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(MODULE).lib
rm -f $(DIST)\bin\$(MODULE).dll

Просмотреть файл

@ -0,0 +1,84 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMSilentDownload_h__
#define nsIDOMSilentDownload_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMSilentDownloadTask;
#define NS_IDOMSILENTDOWNLOAD_IID \
{ 0x8648c1e0, 0x938b, 0x11d2, \
{ 0xb0, 0xdd, 0x0, 0x80, 0x5f, 0x8a, 0x88, 0x51 }}
class nsIDOMSilentDownload : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMSILENTDOWNLOAD_IID; return iid; }
NS_IMETHOD GetByteRange(PRInt32* aByteRange)=0;
NS_IMETHOD SetByteRange(PRInt32 aByteRange)=0;
NS_IMETHOD GetInterval(PRInt32* aInterval)=0;
NS_IMETHOD SetInterval(PRInt32 aInterval)=0;
NS_IMETHOD Startup()=0;
NS_IMETHOD Shutdown()=0;
NS_IMETHOD Add(nsIDOMSilentDownloadTask* aTask)=0;
NS_IMETHOD Remove(nsIDOMSilentDownloadTask* aTask)=0;
NS_IMETHOD Find(const nsString& aId, nsIDOMSilentDownloadTask** aReturn)=0;
};
#define NS_DECL_IDOMSILENTDOWNLOAD \
NS_IMETHOD GetByteRange(PRInt32* aByteRange); \
NS_IMETHOD SetByteRange(PRInt32 aByteRange); \
NS_IMETHOD GetInterval(PRInt32* aInterval); \
NS_IMETHOD SetInterval(PRInt32 aInterval); \
NS_IMETHOD Startup(); \
NS_IMETHOD Shutdown(); \
NS_IMETHOD Add(nsIDOMSilentDownloadTask* aTask); \
NS_IMETHOD Remove(nsIDOMSilentDownloadTask* aTask); \
NS_IMETHOD Find(const nsString& aId, nsIDOMSilentDownloadTask** aReturn); \
#define NS_FORWARD_IDOMSILENTDOWNLOAD(_to) \
NS_IMETHOD GetByteRange(PRInt32* aByteRange) { return _to##GetByteRange(aByteRange); } \
NS_IMETHOD SetByteRange(PRInt32 aByteRange) { return _to##SetByteRange(aByteRange); } \
NS_IMETHOD GetInterval(PRInt32* aInterval) { return _to##GetInterval(aInterval); } \
NS_IMETHOD SetInterval(PRInt32 aInterval) { return _to##SetInterval(aInterval); } \
NS_IMETHOD Startup() { return _to##Startup(); } \
NS_IMETHOD Shutdown() { return _to##Shutdown(); } \
NS_IMETHOD Add(nsIDOMSilentDownloadTask* aTask) { return _to##Add(aTask); } \
NS_IMETHOD Remove(nsIDOMSilentDownloadTask* aTask) { return _to##Remove(aTask); } \
NS_IMETHOD Find(const nsString& aId, nsIDOMSilentDownloadTask** aReturn) { return _to##Find(aId, aReturn); } \
extern nsresult NS_InitSilentDownloadClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptSilentDownload(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMSilentDownload_h__

Просмотреть файл

@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMSilentDownloadTask_h__
#define nsIDOMSilentDownloadTask_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#define NS_IDOMSILENTDOWNLOADTASK_IID \
{ 0x8648c1e0, 0x938b, 0x11d2, \
{ 0xb0, 0xdd, 0x0, 0x80, 0x5f, 0x8a, 0x88, 0x50 }}
class nsIDOMSilentDownloadTask : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMSILENTDOWNLOADTASK_IID; return iid; }
enum {
SDL_NOT_INITED = -2,
SDL_NOT_ADDED = -1,
SDL_STARTED = 0,
SDL_SUSPENDED = 1,
SDL_COMPLETED = 2,
SDL_DOWNLOADING_NOW = 3,
SDL_ERROR = 4
};
NS_IMETHOD GetId(nsString& aId)=0;
NS_IMETHOD GetUrl(nsString& aUrl)=0;
NS_IMETHOD GetScript(nsString& aScript)=0;
NS_IMETHOD GetState(PRInt32* aState)=0;
NS_IMETHOD SetState(PRInt32 aState)=0;
NS_IMETHOD GetErrorMsg(nsString& aErrorMsg)=0;
NS_IMETHOD SetErrorMsg(const nsString& aErrorMsg)=0;
NS_IMETHOD GetNextByte(PRInt32* aNextByte)=0;
NS_IMETHOD SetNextByte(PRInt32 aNextByte)=0;
NS_IMETHOD GetOutFile(nsString& aOutFile)=0;
NS_IMETHOD Init(const nsString& aId, const nsString& aUrl, const nsString& aScript)=0;
NS_IMETHOD Remove()=0;
NS_IMETHOD Suspend()=0;
NS_IMETHOD Resume()=0;
NS_IMETHOD DownloadNow()=0;
NS_IMETHOD DownloadSelf(PRInt32 aRange)=0;
};
#define NS_DECL_IDOMSILENTDOWNLOADTASK \
NS_IMETHOD GetId(nsString& aId); \
NS_IMETHOD GetUrl(nsString& aUrl); \
NS_IMETHOD GetScript(nsString& aScript); \
NS_IMETHOD GetState(PRInt32* aState); \
NS_IMETHOD SetState(PRInt32 aState); \
NS_IMETHOD GetErrorMsg(nsString& aErrorMsg); \
NS_IMETHOD SetErrorMsg(const nsString& aErrorMsg); \
NS_IMETHOD GetNextByte(PRInt32* aNextByte); \
NS_IMETHOD SetNextByte(PRInt32 aNextByte); \
NS_IMETHOD GetOutFile(nsString& aOutFile); \
NS_IMETHOD Init(const nsString& aId, const nsString& aUrl, const nsString& aScript); \
NS_IMETHOD Remove(); \
NS_IMETHOD Suspend(); \
NS_IMETHOD Resume(); \
NS_IMETHOD DownloadNow(); \
NS_IMETHOD DownloadSelf(PRInt32 aRange); \
#define NS_FORWARD_IDOMSILENTDOWNLOADTASK(_to) \
NS_IMETHOD GetId(nsString& aId) { return _to##GetId(aId); } \
NS_IMETHOD GetUrl(nsString& aUrl) { return _to##GetUrl(aUrl); } \
NS_IMETHOD GetScript(nsString& aScript) { return _to##GetScript(aScript); } \
NS_IMETHOD GetState(PRInt32* aState) { return _to##GetState(aState); } \
NS_IMETHOD SetState(PRInt32 aState) { return _to##SetState(aState); } \
NS_IMETHOD GetErrorMsg(nsString& aErrorMsg) { return _to##GetErrorMsg(aErrorMsg); } \
NS_IMETHOD SetErrorMsg(const nsString& aErrorMsg) { return _to##SetErrorMsg(aErrorMsg); } \
NS_IMETHOD GetNextByte(PRInt32* aNextByte) { return _to##GetNextByte(aNextByte); } \
NS_IMETHOD SetNextByte(PRInt32 aNextByte) { return _to##SetNextByte(aNextByte); } \
NS_IMETHOD GetOutFile(nsString& aOutFile) { return _to##GetOutFile(aOutFile); } \
NS_IMETHOD Init(const nsString& aId, const nsString& aUrl, const nsString& aScript) { return _to##Init(aId, aUrl, aScript); } \
NS_IMETHOD Remove() { return _to##Remove(); } \
NS_IMETHOD Suspend() { return _to##Suspend(); } \
NS_IMETHOD Resume() { return _to##Resume(); } \
NS_IMETHOD DownloadNow() { return _to##DownloadNow(); } \
NS_IMETHOD DownloadSelf(PRInt32 aRange) { return _to##DownloadSelf(aRange); } \
extern nsresult NS_InitSilentDownloadTaskClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptSilentDownloadTask(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMSilentDownloadTask_h__

Просмотреть файл

@ -0,0 +1,524 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMSilentDownload.h"
#include "nsIDOMSilentDownloadTask.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kISilentDownloadIID, NS_IDOMSILENTDOWNLOAD_IID);
static NS_DEFINE_IID(kISilentDownloadTaskIID, NS_IDOMSILENTDOWNLOADTASK_IID);
NS_DEF_PTR(nsIDOMSilentDownload);
NS_DEF_PTR(nsIDOMSilentDownloadTask);
//
// SilentDownload property ids
//
enum SilentDownload_slots {
SILENTDOWNLOAD_BYTERANGE = -1,
SILENTDOWNLOAD_INTERVAL = -2
};
/***********************************************************************/
//
// SilentDownload Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetSilentDownloadProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSilentDownload *a = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case SILENTDOWNLOAD_BYTERANGE:
{
PRInt32 prop;
if (NS_OK == a->GetByteRange(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOAD_INTERVAL:
{
PRInt32 prop;
if (NS_OK == a->GetInterval(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// SilentDownload Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetSilentDownloadProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSilentDownload *a = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case SILENTDOWNLOAD_BYTERANGE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetByteRange(prop);
break;
}
case SILENTDOWNLOAD_INTERVAL:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetInterval(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// SilentDownload finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeSilentDownload(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// SilentDownload enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateSilentDownload(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// SilentDownload resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveSilentDownload(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Startup
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadStartup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownload *nativeThis = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Startup()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Startup requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Shutdown
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadShutdown(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownload *nativeThis = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Shutdown()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Shutdown requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Add
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadAdd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownload *nativeThis = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMSilentDownloadTaskPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kISilentDownloadTaskIID,
"SilentDownloadTask",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->Add(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Add requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Remove
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownload *nativeThis = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMSilentDownloadTaskPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kISilentDownloadTaskIID,
"SilentDownloadTask",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->Remove(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Remove requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Find
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadFind(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownload *nativeThis = (nsIDOMSilentDownload*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMSilentDownloadTask* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->Find(b0, &nativeRet)) {
return JS_FALSE;
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
else {
JS_ReportError(cx, "Function Find requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for SilentDownload
//
JSClass SilentDownloadClass = {
"SilentDownload",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetSilentDownloadProperty,
SetSilentDownloadProperty,
EnumerateSilentDownload,
ResolveSilentDownload,
JS_ConvertStub,
FinalizeSilentDownload
};
//
// SilentDownload class properties
//
static JSPropertySpec SilentDownloadProperties[] =
{
{"ByteRange", SILENTDOWNLOAD_BYTERANGE, JSPROP_ENUMERATE},
{"Interval", SILENTDOWNLOAD_INTERVAL, JSPROP_ENUMERATE},
{0}
};
//
// SilentDownload class methods
//
static JSFunctionSpec SilentDownloadMethods[] =
{
{"Startup", SilentDownloadStartup, 0},
{"Shutdown", SilentDownloadShutdown, 0},
{"Add", SilentDownloadAdd, 1},
{"Remove", SilentDownloadRemove, 1},
{"Find", SilentDownloadFind, 1},
{0}
};
//
// SilentDownload constructor
//
PR_STATIC_CALLBACK(JSBool)
SilentDownload(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// SilentDownload class initialization
//
nsresult NS_InitSilentDownloadClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "SilentDownload", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&SilentDownloadClass, // JSClass
SilentDownload, // JSNative ctor
0, // ctor args
SilentDownloadProperties, // proto props
SilentDownloadMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new SilentDownload JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptSilentDownload(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptSilentDownload");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMSilentDownload *aSilentDownload;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitSilentDownloadClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kISilentDownloadIID, (void **)&aSilentDownload);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &SilentDownloadClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSilentDownload);
}
else {
NS_RELEASE(aSilentDownload);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,690 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMSilentDownloadTask.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kISilentDownloadTaskIID, NS_IDOMSILENTDOWNLOADTASK_IID);
NS_DEF_PTR(nsIDOMSilentDownloadTask);
//
// SilentDownloadTask property ids
//
enum SilentDownloadTask_slots {
SILENTDOWNLOADTASK_ID = -1,
SILENTDOWNLOADTASK_URL = -2,
SILENTDOWNLOADTASK_SCRIPT = -3,
SILENTDOWNLOADTASK_STATE = -4,
SILENTDOWNLOADTASK_ERRORMSG = -5,
SILENTDOWNLOADTASK_NEXTBYTE = -6,
SILENTDOWNLOADTASK_OUTFILE = -7
};
/***********************************************************************/
//
// SilentDownloadTask Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetSilentDownloadTaskProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSilentDownloadTask *a = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case SILENTDOWNLOADTASK_ID:
{
nsAutoString prop;
if (NS_OK == a->GetId(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_URL:
{
nsAutoString prop;
if (NS_OK == a->GetUrl(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_SCRIPT:
{
nsAutoString prop;
if (NS_OK == a->GetScript(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_STATE:
{
PRInt32 prop;
if (NS_OK == a->GetState(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_ERRORMSG:
{
nsAutoString prop;
if (NS_OK == a->GetErrorMsg(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_NEXTBYTE:
{
PRInt32 prop;
if (NS_OK == a->GetNextByte(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case SILENTDOWNLOADTASK_OUTFILE:
{
nsAutoString prop;
if (NS_OK == a->GetOutFile(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// SilentDownloadTask Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetSilentDownloadTaskProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSilentDownloadTask *a = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case SILENTDOWNLOADTASK_STATE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetState(prop);
break;
}
case SILENTDOWNLOADTASK_ERRORMSG:
{
nsAutoString prop;
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
a->SetErrorMsg(prop);
break;
}
case SILENTDOWNLOADTASK_NEXTBYTE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetNextByte(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// SilentDownloadTask finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeSilentDownloadTask(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// SilentDownloadTask enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateSilentDownloadTask(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// SilentDownloadTask resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveSilentDownloadTask(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Init
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
if (NS_OK != nativeThis->Init(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Init requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Remove
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Remove()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Remove requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Suspend
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskSuspend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Suspend()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Suspend requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Resume
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskResume(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Resume()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Resume requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method DownloadNow
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskDownloadNow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->DownloadNow()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function DownloadNow requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method DownloadSelf
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTaskDownloadSelf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSilentDownloadTask *nativeThis = (nsIDOMSilentDownloadTask*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->DownloadSelf(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function DownloadSelf requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for SilentDownloadTask
//
JSClass SilentDownloadTaskClass = {
"SilentDownloadTask",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetSilentDownloadTaskProperty,
SetSilentDownloadTaskProperty,
EnumerateSilentDownloadTask,
ResolveSilentDownloadTask,
JS_ConvertStub,
FinalizeSilentDownloadTask
};
//
// SilentDownloadTask class properties
//
static JSPropertySpec SilentDownloadTaskProperties[] =
{
{"id", SILENTDOWNLOADTASK_ID, JSPROP_ENUMERATE | JSPROP_READONLY},
{"url", SILENTDOWNLOADTASK_URL, JSPROP_ENUMERATE | JSPROP_READONLY},
{"script", SILENTDOWNLOADTASK_SCRIPT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"state", SILENTDOWNLOADTASK_STATE, JSPROP_ENUMERATE},
{"errorMsg", SILENTDOWNLOADTASK_ERRORMSG, JSPROP_ENUMERATE},
{"nextByte", SILENTDOWNLOADTASK_NEXTBYTE, JSPROP_ENUMERATE},
{"outFile", SILENTDOWNLOADTASK_OUTFILE, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// SilentDownloadTask class methods
//
static JSFunctionSpec SilentDownloadTaskMethods[] =
{
{"Init", SilentDownloadTaskInit, 3},
{"Remove", SilentDownloadTaskRemove, 0},
{"Suspend", SilentDownloadTaskSuspend, 0},
{"Resume", SilentDownloadTaskResume, 0},
{"DownloadNow", SilentDownloadTaskDownloadNow, 0},
{"DownloadSelf", SilentDownloadTaskDownloadSelf, 1},
{0}
};
//
// SilentDownloadTask constructor
//
PR_STATIC_CALLBACK(JSBool)
SilentDownloadTask(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMSilentDownloadTask *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMSilentDownloadTaskIID, NS_IDOMSILENTDOWNLOADTASK_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("SilentDownloadTask", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMSilentDownloadTaskIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// SilentDownloadTask class initialization
//
nsresult NS_InitSilentDownloadTaskClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "SilentDownloadTask", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&SilentDownloadTaskClass, // JSClass
SilentDownloadTask, // JSNative ctor
0, // ctor args
SilentDownloadTaskProperties, // proto props
SilentDownloadTaskMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "SilentDownloadTask", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_NOT_INITED);
JS_SetProperty(jscontext, constructor, "SDL_NOT_INITED", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_NOT_ADDED);
JS_SetProperty(jscontext, constructor, "SDL_NOT_ADDED", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_STARTED);
JS_SetProperty(jscontext, constructor, "SDL_STARTED", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_SUSPENDED);
JS_SetProperty(jscontext, constructor, "SDL_SUSPENDED", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_COMPLETED);
JS_SetProperty(jscontext, constructor, "SDL_COMPLETED", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_DOWNLOADING_NOW);
JS_SetProperty(jscontext, constructor, "SDL_DOWNLOADING_NOW", &vp);
vp = INT_TO_JSVAL(nsIDOMSilentDownloadTask::SDL_ERROR);
JS_SetProperty(jscontext, constructor, "SDL_ERROR", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new SilentDownloadTask JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptSilentDownloadTask(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptSilentDownloadTask");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMSilentDownloadTask *aSilentDownloadTask;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitSilentDownloadTaskClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kISilentDownloadTaskIID, (void **)&aSilentDownloadTask);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &SilentDownloadTaskClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSilentDownloadTask);
}
else {
NS_RELEASE(aSilentDownloadTask);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,38 @@
#ifndef nsSilentDownload_h___
#define nsSilentDownload_h___
/* need to generate real CIDs! */
#define NS_SilentDownload_CID \
{ /* 5196e6a0-938b-11d2-b0dd-00805f8a8851 */ \
0x5196e6a0, \
0x938b, \
0x11d2, \
{0xb0, 0xdd, 0x00, 0x80, 0x5f, 0x8a, 0x88, 0x51} \
};
#define NS_SilentDownloadTask_CID \
{ /* 5196e6a0-938b-11d2-b0dd-00805f8a8851 */ \
0x5196e6a0, \
0x938b, \
0x11d2, \
{0xb0, 0xdd, 0x00, 0x80, 0x5f, 0x8a, 0x88, 0x52} \
};
#define NS_SilentDownloadFactory_CID \
{ /* 5196e6a0-938b-11d2-b0dd-00805f8a8851 */ \
0x5196e6a0, \
0x938b, \
0x11d2, \
{0xb0, 0xdd, 0x00, 0x80, 0x5f, 0x8a, 0x88, 0x53} \
};
#define NS_SilentDownloadTaskFactory_CID \
{ /* 5196e6a0-938b-11d2-b0dd-00805f8a8851 */ \
0x5196e6a0, \
0x938b, \
0x11d2, \
{0xb0, 0xdd, 0x00, 0x80, 0x5f, 0x8a, 0x88, 0x54} \
};
#endif /* nsSilentDownload_h___ */

Просмотреть файл

@ -0,0 +1,254 @@
#ifndef nsSilentDownloadPrivate_h___
#define nsSilentDownloadPrivate_h___
#include "nsSilentDownload.h"
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsINetService.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIStreamListener.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIDOMSilentDownload.h"
#include "nsIDOMSilentDownloadTask.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "prio.h"
////////////////////////////////////////////////////////////////////////////////
// DLL Entry Points:
////////////////////////////////////////////////////////////////////////////////
extern "C" NS_EXPORT nsresult
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory);
extern "C" NS_EXPORT PRBool
NSCanUnload(void);
extern "C" NS_EXPORT nsresult
NSRegisterSelf(const char *path);
extern "C" NS_EXPORT nsresult
NSUnregisterSelf(const char *path);
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadListener:
////////////////////////////////////////////////////////////////////////////////
class nsSilentDownloadListener : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
nsSilentDownloadListener();
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 Progress, PRUint32 ProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg);
NS_METHOD SetSilentDownloadInfo(nsIDOMSilentDownloadTask* con);
protected:
~nsSilentDownloadListener();
private:
//
nsIDOMSilentDownloadTask* mSilentDownloadTask;
PRFileDesc *mOutFileDesc;
};
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadTask:
////////////////////////////////////////////////////////////////////////////////
class nsSilentDownloadTask : public nsIScriptObjectOwner, public nsIDOMSilentDownloadTask
{
public:
nsSilentDownloadTask();
~nsSilentDownloadTask();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD Init(const nsString& aId, const nsString& aUrl, const nsString& aScript);
NS_IMETHOD GetId(nsString& aId);
NS_IMETHOD GetUrl(nsString& aUrl);
NS_IMETHOD GetScript(nsString& aScript);
NS_IMETHOD GetOutFile(nsString& aOutFile);
NS_IMETHOD GetState(PRInt32* aState);
NS_IMETHOD SetState(PRInt32 aState);
NS_IMETHOD GetErrorMsg(nsString& aErrorMsg);
NS_IMETHOD SetErrorMsg(const nsString& aErrorMsg);
NS_IMETHOD GetNextByte(PRInt32* aStart_byte);
NS_IMETHOD SetNextByte(PRInt32 aStart_byte);
NS_IMETHOD Remove();
NS_IMETHOD Suspend();
NS_IMETHOD Resume();
NS_IMETHOD DownloadNow();
NS_IMETHOD DownloadSelf(PRInt32 aRange);
private:
void LoadScript(void);
nsString mId; /* User ID */
nsString mUrl; /* What to Download */
nsString mScript; /* What controls the download */
PRInt32 mFile_size; /* How big is the download */
nsString mErrorMsg; /* Human readable error message */
nsString mOutFile; /* Where on the users system file is stored */
PRInt32 mState; /* State of task */
PRInt32 mNextByte; /* The start byte in the file where will will start downloading */
nsSilentDownloadListener *mListener;
nsIBrowserWindow *mWindow;
nsIWebShell *mWebShell;
void *mScriptObject;
};
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadManager:
////////////////////////////////////////////////////////////////////////////////
typedef struct _SDL_TaskList SDL_TaskList;
typedef struct _SDL_TaskList
{
nsIDOMSilentDownloadTask *task;
SDL_TaskList *next;
} SDL_TaskList;
class nsSilentDownloadManager : public nsIScriptObjectOwner, public nsIDOMSilentDownload, public nsITimerCallback
{
public:
nsSilentDownloadManager();
~nsSilentDownloadManager();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD GetByteRange(PRInt32* aByterange);
NS_IMETHOD SetByteRange(PRInt32 aByterange);
NS_IMETHOD GetInterval(PRInt32* aInterval);
NS_IMETHOD SetInterval(PRInt32 aInterval);
NS_IMETHOD Remove(nsIDOMSilentDownloadTask* aTask);
NS_IMETHOD Add(nsIDOMSilentDownloadTask* aTask);
NS_IMETHOD Find(const nsString& aId, nsIDOMSilentDownloadTask** aReturn);
NS_IMETHOD Startup();
NS_IMETHOD Shutdown();
protected:
// nsITimerCallback Interface
virtual void Notify(nsITimer *timer);
private:
nsresult StoreAllTasks(void);
nsresult LoadAllTasks(void);
void *mScriptObject;
};
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadManagerFactory:
////////////////////////////////////////////////////////////////////////////////
class nsSilentDownloadManagerFactory : public nsIFactory
{
public:
nsSilentDownloadManagerFactory();
~nsSilentDownloadManagerFactory();
PRBool CanUnload(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadTaskFactory:
////////////////////////////////////////////////////////////////////////////////
class nsSilentDownloadTaskFactory : public nsIFactory
{
public:
nsSilentDownloadTaskFactory();
~nsSilentDownloadTaskFactory();
PRBool CanUnload(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
////////////////////////////////////////////////////////////////////////////////
// nsSilentDownloadNameSet:
////////////////////////////////////////////////////////////////////////////////
class nsSilentDownloadNameSet : public nsIScriptExternalNameSet
{
public:
nsSilentDownloadNameSet();
~nsSilentDownloadNameSet();
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext);
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext);
};
#endif