comparison dwt/browser/DownloadFactory_1_8.d @ 125:5583f8eeee6c

Synced mozilla with dwt-linux
author Jacob Carlborg <doob@me.com>
date Fri, 16 Jan 2009 12:49:08 +0100
parents d8635bb48c7c
children
comparison
equal deleted inserted replaced
124:540fa4e9974a 125:5583f8eeee6c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation and others. 2 * Copyright (c) 2003, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * John Reimer <terminal.node@gmail.com>
10 *******************************************************************************/ 12 *******************************************************************************/
11 module dwt.browser.DownloadFactory_1_8; 13 module dwt.browser.DownloadFactory_1_8;
12 14
13 import dwt.dwthelper.utils; 15 import dwt.dwthelper.utils;
14 16
15 import dwt.internal.C; 17 //import dwt.internal.C;
16 import dwt.internal.mozilla.XPCOM; 18 import XPCOM = dwt.internal.mozilla.XPCOM;
17 import dwt.internal.mozilla.XPCOMObject; 19 import dwt.internal.mozilla.Common;
20 //import dwt.internal.mozilla.XPCOMObject;
18 import dwt.internal.mozilla.nsID; 21 import dwt.internal.mozilla.nsID;
19 import dwt.internal.mozilla.nsIFactory; 22 import dwt.internal.mozilla.nsIFactory;
20 import dwt.internal.mozilla.nsISupports; 23 import dwt.internal.mozilla.nsISupports;
24 import dwt.browser.Download_1_8;
21 25
22 class DownloadFactory_1_8 { 26 class DownloadFactory_1_8 : nsIFactory {
23 XPCOMObject supports; 27 //XPCOMObject supports;
24 XPCOMObject factory; 28 //XPCOMObject factory;
25 int refCount = 0; 29 int refCount = 0;
26 30
27 this () { 31 this () {
28 createCOMInterfaces (); 32 //createCOMInterfaces ();
29 } 33 }
30 34
31 int AddRef () { 35 extern(System)
36 nsrefcnt AddRef () {
32 refCount++; 37 refCount++;
33 return refCount; 38 return refCount;
34 } 39 }
35 40
36 void createCOMInterfaces () { 41 extern(System)
37 /* Create each of the interfaces that this object implements */ 42 nsresult QueryInterface (nsIID* riid, void** ppvObject) {
38 supports = new XPCOMObject (new int[] {2, 0, 0}) { 43 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
39 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 44 //nsID guid = new nsID ();
40 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} 45 //XPCOM.memmove (guid, riid, nsID.sizeof);
41 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
42 };
43 46
44 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { 47 if (*riid == nsISupports.IID) {
45 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 48 *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 (cast(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 (); 49 AddRef ();
76 return XPCOM.NS_OK; 50 return XPCOM.NS_OK;
77 } 51 }
78 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { 52 if (*riid == nsIFactory.IID) {
79 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); 53 *ppvObject = cast(void*)cast(nsIFactory)this;
80 AddRef (); 54 AddRef ();
81 return XPCOM.NS_OK; 55 return XPCOM.NS_OK;
82 } 56 }
83 57
84 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); 58 *ppvObject = null;
85 return XPCOM.NS_ERROR_NO_INTERFACE; 59 return XPCOM.NS_ERROR_NO_INTERFACE;
86 } 60 }
87 61
88 int Release () { 62 extern(System)
63 nsrefcnt Release () {
89 refCount--; 64 refCount--;
90 if (refCount is 0) disposeCOMInterfaces (); 65 //if (refCount is 0) disposeCOMInterfaces ();
91 return refCount; 66 return refCount;
92 } 67 }
93 68
94 /* nsIFactory */ 69 /* nsIFactory */
95 70
96 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { 71 extern(System)
97 Download_1_8 download = new Download_1_8 (); 72 nsresult CreateInstance (nsISupports aOuter, nsIID* iid, void** result) {
98 download.AddRef (); 73 if (result is null)
99 XPCOM.memmove (result, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); 74 return XPCOM.NS_ERROR_INVALID_ARG;
100 return XPCOM.NS_OK; 75 auto download = new Download_1_8;
76 nsresult rv = download.QueryInterface( iid, result );
77 if (XPCOM.NS_FAILED(rv)) {
78 *result = null;
79 delete download;
80 }
81 return rv;
101 } 82 }
102 83
103 int LockFactory (int lock) { 84 extern(System)
85 nsresult LockFactory (PRBool lock) {
104 return XPCOM.NS_OK; 86 return XPCOM.NS_OK;
105 } 87 }
106 } 88 }