Mercurial > projects > dwt-linux
comparison dwt/browser/DownloadFactory.d @ 341:942da4b6558a
Ongoing fixup for compile
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Sun, 26 Oct 2008 21:19:51 -0700 |
parents | 44258e0b6687 |
children | 5abc6f7f7a95 |
comparison
equal
deleted
inserted
replaced
340:3f4a5c7d138f | 341:942da4b6558a |
---|---|
10 *******************************************************************************/ | 10 *******************************************************************************/ |
11 module dwt.browser.DownloadFactory; | 11 module dwt.browser.DownloadFactory; |
12 | 12 |
13 import dwt.dwthelper.utils; | 13 import dwt.dwthelper.utils; |
14 | 14 |
15 import dwt.internal.C; | 15 //import dwt.internal.C; |
16 import dwt.internal.mozilla.XPCOM; | 16 import XPCOM = dwt.internal.mozilla.XPCOM; |
17 import dwt.internal.mozilla.XPCOMObject; | 17 import dwt.internal.mozilla.Common; |
18 //import dwt.internal.mozilla.XPCOMObject; | |
18 import dwt.internal.mozilla.nsID; | 19 import dwt.internal.mozilla.nsID; |
19 import dwt.internal.mozilla.nsIFactory; | 20 import dwt.internal.mozilla.nsIFactory; |
20 import dwt.internal.mozilla.nsISupports; | 21 import dwt.internal.mozilla.nsISupports; |
21 | 22 |
22 class DownloadFactory { | 23 class DownloadFactory : nsIFactory { |
23 XPCOMObject supports; | |
24 XPCOMObject factory; | |
25 int refCount = 0; | 24 int refCount = 0; |
26 | 25 |
27 DownloadFactory () { | 26 this () {} |
28 createCOMInterfaces (); | |
29 } | |
30 | 27 |
31 int AddRef () { | 28 nsrefcnt AddRef () { |
32 refCount++; | 29 refCount++; |
33 return refCount; | 30 return refCount; |
34 } | 31 } |
35 | 32 |
36 void createCOMInterfaces () { | 33 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
37 /* Create each of the interfaces that this object implements */ | 34 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
38 supports = new XPCOMObject (new int[] {2, 0, 0}) { | |
39 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
40 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
41 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
42 }; | |
43 | 35 |
44 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { | 36 if (*riid == nsISupports.IID) { |
45 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 37 *ppvObject = cast(void*)cast(nsISupports)this; |
46 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
47 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
48 public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} | |
49 public int /*long*/ method4 (int /*long*/[] args) {return LockFactory ((int)/*64*/args[0]);} | |
50 }; | |
51 } | |
52 | |
53 void disposeCOMInterfaces () { | |
54 if (supports !is null) { | |
55 supports.dispose (); | |
56 supports = null; | |
57 } | |
58 if (factory !is null) { | |
59 factory.dispose (); | |
60 factory = null; | |
61 } | |
62 } | |
63 | |
64 int /*long*/ getAddress () { | |
65 return factory.getAddress (); | |
66 } | |
67 | |
68 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
69 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
70 nsID guid = new nsID (); | |
71 XPCOM.memmove (guid, riid, nsID.sizeof); | |
72 | |
73 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
74 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
75 AddRef (); | 38 AddRef (); |
76 return XPCOM.NS_OK; | 39 return XPCOM.NS_OK; |
77 } | 40 } |
78 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { | 41 if (*riid == nsIFactory.IID) { |
79 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); | 42 *ppvObject = cast(void*)cast(nsIFactory)this; |
80 AddRef (); | 43 AddRef (); |
81 return XPCOM.NS_OK; | 44 return XPCOM.NS_OK; |
82 } | 45 } |
83 | 46 |
84 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | 47 *ppvObject = null; |
85 return XPCOM.NS_ERROR_NO_INTERFACE; | 48 return XPCOM.NS_ERROR_NO_INTERFACE; |
86 } | 49 } |
87 | 50 |
88 int Release () { | 51 nsrefcnt Release () { |
89 refCount--; | 52 refCount--; |
90 if (refCount is 0) disposeCOMInterfaces (); | 53 //if (refCount is 0) disposeCOMInterfaces (); |
91 return refCount; | 54 return refCount; |
92 } | 55 } |
93 | 56 |
94 /* nsIFactory */ | 57 /* nsIFactory */ |
95 | 58 |
96 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { | 59 nsresult CreateInstance (nsISupports aOuter, nsID* iid, void** result) { |
97 Download download = new Download (); | 60 if (result is null) |
98 download.AddRef (); | 61 return XPCOM.NS_ERROR_INVALID_ARG; |
99 XPCOM.memmove (result, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); | 62 auto download = new Download(); |
100 return XPCOM.NS_OK; | 63 nsresult rv = download.QueryInterface( iid, result ); |
64 if (XPCOM.NS_FAILED(rv)) { | |
65 *result = null; | |
66 delete promptService; | |
67 } | |
68 return rv; | |
101 } | 69 } |
102 | 70 |
103 int LockFactory (int lock) { | 71 nsresult LockFactory (int lock) { |
104 return XPCOM.NS_OK; | 72 return XPCOM.NS_OK; |
105 } | 73 } |
106 } | 74 } |