Mercurial > projects > dwt-linux
comparison dwt/browser/HelperAppLauncherDialog.d @ 352:a3c5f744d03f
Update Browser/Mozilla package to SWT 3.4.1 and bug fixes
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Tue, 04 Nov 2008 21:20:45 -0800 |
parents | 9a4d7706df52 |
children |
comparison
equal
deleted
inserted
replaced
351:f1bb3949939b | 352:a3c5f744d03f |
---|---|
24 import dwt.internal.mozilla.nsEmbedString; | 24 import dwt.internal.mozilla.nsEmbedString; |
25 import dwt.internal.mozilla.nsID; | 25 import dwt.internal.mozilla.nsID; |
26 import dwt.internal.mozilla.nsIHelperAppLauncher; | 26 import dwt.internal.mozilla.nsIHelperAppLauncher; |
27 import dwt.internal.mozilla.nsIHelperAppLauncherDialog; | 27 import dwt.internal.mozilla.nsIHelperAppLauncherDialog; |
28 import dwt.internal.mozilla.nsIHelperAppLauncher_1_8; | 28 import dwt.internal.mozilla.nsIHelperAppLauncher_1_8; |
29 import dwt.internal.mozilla.nsIHelperAppLauncher_1_9; | |
30 import dwt.internal.mozilla.nsISupports; | 29 import dwt.internal.mozilla.nsISupports; |
31 import dwt.internal.mozilla.nsILocalFile; | 30 import dwt.internal.mozilla.nsILocalFile; |
32 import dwt.internal.mozilla.nsStringAPI; | 31 import dwt.internal.mozilla.nsStringAPI; |
33 | 32 |
34 import dwt.browser.Mozilla; | 33 import dwt.browser.Mozilla; |
35 | 34 |
36 import dwt.widgets.FileDialog; | 35 import dwt.widgets.FileDialog; |
37 import dwt.widgets.Shell; | 36 import dwt.widgets.Shell; |
37 | |
38 /** | |
39 * This class implements the HelperAppLauncherDialog interface for mozilla | |
40 * versions 1.4 - 1.8.x. For mozilla versions >= 1.9 this interface is | |
41 * implemented by class HelperAppLauncherDialog_1_9. HelperAppLauncherDialogFactory | |
42 * determines at runtime which of these classes to instantiate. | |
43 */ | |
38 | 44 |
39 class HelperAppLauncherDialog : nsIHelperAppLauncherDialog { | 45 class HelperAppLauncherDialog : nsIHelperAppLauncherDialog { |
40 int refCount = 0; | 46 int refCount = 0; |
41 | 47 |
42 this() { | 48 this() { |
75 * Its reference count is expected to go down to 0 when the download | 81 * Its reference count is expected to go down to 0 when the download |
76 * has completed or when it has been cancelled. E.g. when the user | 82 * has completed or when it has been cancelled. E.g. when the user |
77 * cancels the File Dialog, cancels or closes the Download Dialog | 83 * cancels the File Dialog, cancels or closes the Download Dialog |
78 * and when the Download Dialog goes away after the download is completed. | 84 * and when the Download Dialog goes away after the download is completed. |
79 */ | 85 */ |
80 //if (refCount is 0) disposeCOMInterfaces (); | 86 if (refCount is 0) return 0; |
81 return refCount; | 87 return refCount; |
82 } | 88 } |
83 | 89 |
84 /* nsIHelperAppLauncherDialog */ | 90 /* nsIHelperAppLauncherDialog */ |
85 | 91 |
86 extern(System) | 92 extern(System) |
87 nsresult Show(nsIHelperAppLauncher aLauncher, nsISupports aContext, PRUint32 aReason) { | 93 nsresult Show(nsIHelperAppLauncher aLauncher, nsISupports aContext, PRUint32 aReason) { |
88 /* | 94 /* |
89 * The interface for nsIHelperAppLauncher changed in GRE versions 1.8 and 1.9. Query for | 95 * The interface for nsIHelperAppLauncher changed as of mozilla 1.8. Query the received |
90 * each of these interfaces in turn until one is found. | 96 * nsIHelperAppLauncher for the new interface, and if it is not found then fall back to |
91 */ | 97 * the old interface. |
92 // FIXME: Not sure if this will work because of different versions of | 98 */ |
93 // nsIHelperAppLauncher. Remember to check. -JJR | 99 |
94 nsIHelperAppLauncher_1_9 helperAppLauncher1; | 100 nsISupports supports = cast(nsISupports)aLauncher; |
95 int rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_9.IID, cast(void**)&helperAppLauncher1); | 101 nsIHelperAppLauncher_1_8 helperAppLauncher; |
102 nsresult rc = supports.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher); | |
96 if (rc is 0) { | 103 if (rc is 0) { |
97 // nsIHelperAppLauncher_1_9 helperAppLauncher = new nsIHelperAppLauncher_1_9 (aLauncher); | 104 rc = helperAppLauncher.SaveToDisk (null, 0); |
98 rc = helperAppLauncher1.SaveToDisk (null, 0); | 105 helperAppLauncher.Release (); |
99 helperAppLauncher1.Release (); | |
100 return rc; | 106 return rc; |
101 } | 107 } |
102 | 108 |
103 //result[0] = 0; | 109 /* < 1.8 */ |
104 nsIHelperAppLauncher_1_8 helperAppLauncher2; | |
105 rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher2); | |
106 if (rc is 0) { | |
107 //nsIHelperAppLauncher_1_8 helperAppLauncher = new nsIHelperAppLauncher_1_8 (aLauncher); | |
108 rc = helperAppLauncher2.SaveToDisk (null, 0); | |
109 helperAppLauncher2.Release (); | |
110 return rc; | |
111 } | |
112 | |
113 //nsIHelperAppLauncher helperAppLauncher = new nsIHelperAppLauncher (aLauncher); /* < 1.8 */ | |
114 return aLauncher.SaveToDisk (null, 0); | 110 return aLauncher.SaveToDisk (null, 0); |
111 // no Release for this? -JJR | |
115 } | 112 } |
116 | 113 |
117 extern(System) | 114 extern(System) |
118 nsresult PromptForSaveToFile (nsIHelperAppLauncher aLauncher, nsISupports aWindowContext, PRUnichar* aDefaultFile, PRUnichar* aSuggestedFileExtension, nsILocalFile* _retval) { | 115 nsresult PromptForSaveToFile (nsIHelperAppLauncher aLauncher, nsISupports aWindowContext, PRUnichar* aDefaultFile, PRUnichar* aSuggestedFileExtension, nsILocalFile* _retval) { |
119 bool hasLauncher = false; | 116 bool hasLauncher = false; |
129 */ | 126 */ |
130 /* | 127 /* |
131 * The interface for nsIHelperAppLauncher changed as of mozilla 1.8, so the first | 128 * The interface for nsIHelperAppLauncher changed as of mozilla 1.8, so the first |
132 * argument must be queried for both the old and new nsIHelperAppLauncher interfaces. | 129 * argument must be queried for both the old and new nsIHelperAppLauncher interfaces. |
133 */ | 130 */ |
134 bool using_1_8 = false, using_1_9 = false; | 131 bool using_1_8 = false; |
135 // technically this should have an AddRef? -JJR | 132 nsISupports support = cast(nsISupports)aLauncher; |
136 //nsISupports support = cast(nsISupports)arg0; | 133 |
137 //int /*long*/[] result = new int /*long*/[1]; | |
138 if (aLauncher is null) | 134 if (aLauncher is null) |
139 assert(0); | 135 assert(0); |
140 | |
141 // TODO: D Bindings are locked to the XPCOM interface version provided in | |
142 // dwt/internal/mozilla package; therefore the following version checks | |
143 // are redundant for now. In this case, 1.8 and 1.9 | |
144 // will be bypassed. To get 1.8 and 1.9 working for D, we will | |
145 // have to customize this section a bit or simply remove the references | |
146 // until the default aligns with these versions in later swt updates. | |
147 // For now this should work as is. | |
148 | 136 |
149 nsIHelperAppLauncher_1_8 helperAppLauncher1; | 137 nsIHelperAppLauncher_1_8 helperAppLauncher1; |
150 | 138 int rc = support.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher1); |
151 int rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher1); | 139 if (rc is XPCOM.NS_OK) { |
152 if (rc is 0) { | |
153 using_1_8 = true; | 140 using_1_8 = true; |
154 hasLauncher = true; | 141 hasLauncher = true; |
155 helperAppLauncher1.Release (); | 142 helperAppLauncher1.Release (); |
156 } else { | 143 } else { |
157 nsIHelperAppLauncher_1_9 helperAppLauncher2; | 144 nsIHelperAppLauncher helperAppLauncher; |
158 rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_9.IID, cast(void**)&helperAppLauncher2); | 145 rc = support.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&helperAppLauncher); |
159 if (rc is 0) { | 146 if (rc is XPCOM.NS_OK) { |
160 using_1_9 = true; | |
161 hasLauncher = true; | 147 hasLauncher = true; |
162 helperAppLauncher2.Release; | 148 helperAppLauncher.Release; |
163 } else { | |
164 nsIHelperAppLauncher helperAppLauncher; | |
165 rc = aLauncher.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&helperAppLauncher); | |
166 if (rc is 0) { | |
167 hasLauncher = true; | |
168 helperAppLauncher.Release; | |
169 } | |
170 } | 149 } |
171 } | 150 } |
172 | 151 |
173 /+ | 152 /+ |
174 // In D port, Mozilla version is determined by the bindings used | 153 // In D port, no suppport for version >1.4 yet |
175 if (hasLauncher) { /* >= 1.5 */ | 154 if (hasLauncher) { /* >= 1.5 */ |
176 aDefaultFile = arg2; | 155 aDefaultFile = arg2; |
177 aSuggestedFileExtension = arg3; | 156 aSuggestedFileExtension = arg3; |
178 _retval = arg4; | 157 _retval = arg4; |
179 } else { /* 1.4 */ | 158 } else { /* 1.4 */ |
201 fileDialog.setFilterExtensions (tmp); | 180 fileDialog.setFilterExtensions (tmp); |
202 String name = fileDialog.open (); | 181 String name = fileDialog.open (); |
203 shell.close (); | 182 shell.close (); |
204 if (name is null) { | 183 if (name is null) { |
205 if (hasLauncher) { | 184 if (hasLauncher) { |
206 // not sure if these produce correct interface alignment. Check. -JJR | 185 if (using_1_8) { |
207 if (using_1_8 || using_1_9) { | 186 rc = (cast(nsIHelperAppLauncher_1_8)aLauncher).Cancel (XPCOM.NS_BINDING_ABORTED); |
208 //rc = aLauncher.Cancel (XPCOM.NS_BINDING_ABORTED); | |
209 implMissing(__FILE__,__LINE__); | |
210 } else { | 187 } else { |
211 //nsIHelperAppLauncher launcher = new nsIHelperAppLauncher (arg0); | |
212 rc = aLauncher.Cancel (); | 188 rc = aLauncher.Cancel (); |
213 } | 189 } |
214 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 190 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); |
215 return XPCOM.NS_OK; | 191 return XPCOM.NS_OK; |
216 } | 192 } |
217 return XPCOM.NS_ERROR_FAILURE; | 193 return XPCOM.NS_ERROR_FAILURE; |
218 } | 194 } |
219 scope auto path = new nsEmbedString (name.toString16()); | 195 scope auto path = new nsEmbedString (name.toString16()); |
220 nsILocalFile localFile; | 196 nsILocalFile localFile; |
221 rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile); | 197 rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile); |
222 //path.dispose (); | 198 //path.dispose (); |
223 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 199 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); |
224 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | 200 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER,__FILE__,__LINE__); |
225 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */ | 201 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */ |
226 *_retval = localFile; | 202 *_retval = localFile; |
227 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF); | 203 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF); |
228 return XPCOM.NS_OK; | 204 return XPCOM.NS_OK; |
229 } | 205 } |