1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *      John Reimer <terminal.node@gmail.com>
12  *******************************************************************************/
13 module org.eclipse.swt.browser.HelperAppLauncherDialogFactory;
14 
15 import java.lang.all;
16 
17 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM;
18 
19 import org.eclipse.swt.internal.mozilla.Common;
20 import org.eclipse.swt.internal.mozilla.nsID;
21 import org.eclipse.swt.internal.mozilla.nsIFactory;
22 import org.eclipse.swt.internal.mozilla.nsISupports;
23 
24 import org.eclipse.swt.browser.HelperAppLauncherDialog;
25 import org.eclipse.swt.browser.HelperAppLauncherDialog_1_9;
26 
27 class HelperAppLauncherDialogFactory : nsIFactory {
28     int refCount = 0;
29     bool isPre_1_9 = true;
30 
31 
32 this () {
33 }
34 
35 extern(System)
36 nsrefcnt AddRef () {
37     refCount++;
38     return refCount;
39 }
40 
41 extern(System)
42 nsresult QueryInterface (in nsID* riid, void** ppvObject) {
43     if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
44     
45     if (*riid == nsISupports.IID) {
46         *ppvObject = cast(void*)cast(nsISupports)this;
47         AddRef ();
48         return XPCOM.NS_OK;
49     }
50     if (*riid == nsIFactory.IID) {
51         *ppvObject = cast(void*)cast(nsIFactory)this;
52         AddRef ();
53         return XPCOM.NS_OK;
54     }
55     
56     *ppvObject = null;
57     return XPCOM.NS_ERROR_NO_INTERFACE;
58 }
59 
60 extern(System)
61 nsrefcnt Release () {
62     refCount--;
63     if (refCount is 0) return 0;
64     return refCount;
65 }
66 
67 /* nsIFactory */
68 
69 extern(System)
70 nsresult CreateInstance (nsISupports aOuter, nsID* iid, void** result) { 
71     if (isPre_1_9) {
72         if (result is null) 
73             return XPCOM.NS_ERROR_INVALID_ARG;
74         auto helperAppLauncherDialog = new HelperAppLauncherDialog;
75         nsresult rv = helperAppLauncherDialog.QueryInterface( iid, result );
76         if (XPCOM.NS_FAILED(rv)) {
77             *result = null;
78             delete helperAppLauncherDialog;
79         } else {
80             if (result is null) 
81                 return XPCOM.NS_ERROR_INVALID_ARG;
82             auto helperAppLauncherDialog19 = new HelperAppLauncherDialog_1_9;
83             rv = helperAppLauncherDialog19.QueryInterface( iid, result );
84             if (XPCOM.NS_FAILED(rv)) {
85                 *result = null;
86                 delete helperAppLauncherDialog19;
87             }
88             return rv;
89         }
90     }
91 
92     return XPCOM.NS_OK; // Not sure about this
93 }
94 
95 extern(System)
96 nsresult LockFactory (PRBool lock) {
97     return XPCOM.NS_OK;
98 }
99 }