Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/browser/AppFileLocProvider.d @ 111:b6e9904989ed
Updated to dmd 1.065.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 13 Nov 2010 14:15:51 +0100 |
parents | ea8b884d85f6 |
children | 536e43f63c81 |
rev | line source |
---|---|
25 | 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.AppFileLocProvider; | |
14 | |
48 | 15 version(Tango){ |
25 | 16 import tango.sys.Environment; |
48 | 17 } else { // Phobos |
18 } | |
25 | 19 |
20 import java.lang.all; | |
54 | 21 import java.util.Vector; |
22 | |
25 | 23 import org.eclipse.swt.browser.Mozilla; |
24 import org.eclipse.swt.browser.SimpleEnumerator; | |
25 | |
26 import org.eclipse.swt.internal.Compatibility; | |
27 | |
28 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; | |
29 | |
30 import org.eclipse.swt.internal.mozilla.Common; | |
31 import org.eclipse.swt.internal.mozilla.nsISimpleEnumerator; | |
32 import org.eclipse.swt.internal.mozilla.nsEmbedString; | |
33 import org.eclipse.swt.internal.mozilla.nsID; | |
34 import org.eclipse.swt.internal.mozilla.nsIDirectoryService; | |
35 import org.eclipse.swt.internal.mozilla.nsIFile; | |
36 import org.eclipse.swt.internal.mozilla.nsILocalFile; | |
37 import org.eclipse.swt.internal.mozilla.nsISupports; | |
38 import org.eclipse.swt.internal.mozilla.nsStringAPI; | |
39 | |
40 class AppFileLocProvider : nsIDirectoryServiceProvider2 { | |
41 int refCount = 0; | |
42 String mozillaPath, profilePath; | |
43 String[] pluginDirs; | |
44 bool isXULRunner; | |
45 | |
46 static String SEPARATOR_OS; | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
47 static const String CHROME_DIR = "chrome"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
48 static const String COMPONENTS_DIR = "components"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
49 static const String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
50 static const String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
51 static const String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
52 static const String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ |
25 | 53 static String USER_PLUGINS_DIR; |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
54 static const String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ |
25 | 55 |
56 static this () { | |
57 SEPARATOR_OS = System.getProperty ("file.separator"); | |
58 USER_PLUGINS_DIR = ".mozilla" ~ SEPARATOR_OS ~ "plugins"; | |
59 } | |
60 | |
61 this (String path) { | |
62 mozillaPath = path ~ SEPARATOR_OS; | |
63 } | |
64 | |
65 extern(System) | |
66 nsrefcnt AddRef () { | |
67 refCount++; | |
68 return refCount; | |
69 } | |
70 | |
71 extern(System) | |
54 | 72 nsresult QueryInterface (in cnsID* riid, void** ppvObject) { |
25 | 73 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
74 | |
75 if (*riid == nsISupports.IID) { | |
76 *ppvObject = cast(void*)cast(nsISupports)this; | |
77 AddRef (); | |
78 return XPCOM.NS_OK; | |
79 } | |
80 if (*riid == nsIDirectoryServiceProvider.IID) { | |
81 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this; | |
82 AddRef (); | |
83 return XPCOM.NS_OK; | |
84 } | |
85 if (*riid == nsIDirectoryServiceProvider2.IID) { | |
86 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this; | |
87 AddRef (); | |
88 return XPCOM.NS_OK; | |
89 } | |
90 | |
91 *ppvObject = null; | |
92 return XPCOM.NS_ERROR_NO_INTERFACE; | |
93 } | |
94 | |
95 extern(System) | |
96 nsrefcnt Release () { | |
97 refCount--; | |
98 if (refCount is 0) return 0; | |
99 return refCount; | |
100 } | |
101 | |
102 void setProfilePath (String path) { | |
103 profilePath = path; | |
104 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ | |
105 nsILocalFile file; | |
111 | 106 scope nsEmbedString pathString = new nsEmbedString (toWCharArray(path)); |
25 | 107 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &file); |
108 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
109 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
110 | |
111 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700); | |
112 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
113 file.Release (); | |
114 } | |
115 } | |
116 | |
117 /* nsIDirectoryServiceProvider2 */ | |
118 extern(System) | |
119 nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) { | |
54 | 120 String propertyName = fromStringz(prop)._idup(); |
25 | 121 String[] propertyValues = null; |
122 | |
123 if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) { | |
124 if (pluginDirs is null) { | |
125 int index = 0; | |
126 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ | |
54 | 127 version(Tango){ |
128 String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH); | |
129 } else { // Phobos | |
130 implMissing(__FILE__, __LINE__); | |
131 String value; | |
132 } | |
25 | 133 if (value !is null) { |
134 if (value.length > 0) { | |
54 | 135 String separator = System.getProperty ("path.separator"); // $NON-NLS-1$ |
136 Vector segments = new Vector (); | |
137 int start, end = -1; | |
138 do { | |
139 start = end + 1; | |
140 end = value.indexOf (separator, start); | |
141 String segment; | |
142 if (end is -1) { | |
143 segment = value.substring (start); | |
144 } else { | |
145 segment = value.substring (start, end); | |
146 } | |
147 if (segment.length () > 0) segments.addElement (stringcast(segment)); | |
148 } while (end !is -1); | |
149 int segmentsSize = segments.size (); | |
150 pluginDirs = new String [segmentsSize + 2]; | |
151 for (index = 0; index < segmentsSize; index++) { | |
152 pluginDirs[index] = stringcast(segments.elementAt (index)); | |
153 } | |
25 | 154 } |
155 } | |
156 if (pluginDirs is null) { | |
157 pluginDirs = new String[2]; | |
158 } | |
159 | |
160 /* set the next value to the GRE path + "plugins" */ | |
54 | 161 pluginDirs[ index++ ] = mozillaPath ~ PLUGINS_DIR; |
25 | 162 |
163 /* set the next value to the home directory + "/.mozilla/plugins" */ | |
54 | 164 pluginDirs[ index++ ] = System.getProperty("user.home") ~ SEPARATOR_OS ~ USER_PLUGINS_DIR; |
25 | 165 } |
166 propertyValues = pluginDirs; | |
167 } | |
168 | |
169 *_retval = null; | |
170 //XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
171 if (propertyValues !is null) { | |
172 nsILocalFile localFile; | |
173 nsIFile file; | |
174 nsISupports[] files = new nsISupports [propertyValues.length]; | |
175 int index = 0; | |
176 for (int i = 0; i < propertyValues.length; i++) { | |
177 scope auto pathString = new nsEmbedString (toWCharArray(propertyValues[i])); | |
178 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); | |
179 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { | |
180 /* value appears to be a valid pathname */ | |
181 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
182 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
183 | |
184 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); | |
185 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
186 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
187 localFile.Release (); | |
188 | |
189 files[index++] = cast(nsISupports)file; | |
190 } | |
191 } | |
192 | |
193 if (index < propertyValues.length) { | |
194 /* there were some invalid values so remove the trailing empty array slots */ | |
195 files = files[0..index]; | |
196 } | |
197 | |
198 auto enumerator = new SimpleEnumerator (files); | |
199 enumerator.AddRef (); | |
200 *_retval = cast(nsISimpleEnumerator)enumerator; | |
201 return XPCOM.NS_OK; | |
202 } | |
203 | |
204 return XPCOM.NS_ERROR_FAILURE; | |
205 } | |
206 | |
207 /* nsIDirectoryServiceProvider implementation */ | |
208 extern(System) | |
209 nsresult GetFile(char* prop, PRBool* persistent, nsIFile* _retval) { | |
54 | 210 String propertyName = fromStringz( prop )._idup(); |
25 | 211 String propertyValue = null; |
212 | |
213 if (propertyName == (XPCOM.NS_APP_HISTORY_50_FILE)) { | |
214 propertyValue = profilePath ~ HISTORY_FILE; | |
215 } else if (propertyName == (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { | |
216 propertyValue = profilePath ~ MIMETYPES_FILE; | |
217 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_FILE)) { | |
218 propertyValue = profilePath ~ PREFERENCES_FILE; | |
219 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_DIR)) { | |
220 propertyValue = profilePath; | |
221 } else if (propertyName == (XPCOM.NS_APP_USER_CHROME_DIR)) { | |
222 propertyValue = profilePath ~ CHROME_DIR; | |
223 } else if (propertyName == (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { | |
224 propertyValue = profilePath; | |
225 } else if (propertyName == (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { | |
226 propertyValue = profilePath ~ LOCALSTORE_FILE; | |
227 } else if (propertyName == (XPCOM.NS_APP_CACHE_PARENT_DIR)) { | |
228 propertyValue = profilePath; | |
229 } else if (propertyName == (XPCOM.NS_OS_HOME_DIR)) { | |
230 propertyValue = System.getProperty("user.home"); //$NON-NLS-1$ | |
231 } else if (propertyName == (XPCOM.NS_OS_TEMP_DIR)) { | |
232 propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ | |
233 } else if (propertyName == (XPCOM.NS_GRE_DIR)) { | |
234 propertyValue = mozillaPath; | |
235 } else if (propertyName == (XPCOM.NS_GRE_COMPONENT_DIR)) { | |
236 propertyValue = mozillaPath ~ COMPONENTS_DIR; | |
237 } else if (propertyName == (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { | |
238 propertyValue = mozillaPath; | |
239 } else if (propertyName == (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { | |
240 propertyValue = mozillaPath; | |
241 } else if (propertyName == (XPCOM.NS_XPCOM_COMPONENT_DIR)) { | |
242 propertyValue = mozillaPath ~ COMPONENTS_DIR; | |
243 } else if (propertyName == (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { | |
244 propertyValue = mozillaPath; | |
245 } else if (propertyName == (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { | |
246 /* | |
247 * Answering a value for this property causes problems in Mozilla versions | |
248 * < 1.7. Unfortunately this property is queried early enough in the | |
249 * Browser creation process that the Mozilla version being used is not | |
250 * yet determined. However it is known if XULRunner is being used or not. | |
251 * | |
252 * For now answer a value for this property iff XULRunner is the GRE. | |
253 * If the range of Mozilla versions supported by the Browser is changed | |
254 * in the future to be >= 1.7 then this value can always be answered. | |
255 */ | |
256 if (isXULRunner) propertyValue = profilePath; | |
257 } | |
258 | |
259 *persistent = true; /* PRBool */ | |
260 *_retval = null; | |
261 if (propertyValue !is null && propertyValue.length > 0) { | |
262 nsILocalFile localFile; | |
263 scope auto pathString = new nsEmbedString (propertyValue.toWCharArray()); | |
264 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); | |
265 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
266 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
267 | |
268 nsIFile file; | |
269 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); | |
270 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
271 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
272 | |
273 *_retval = file; | |
274 localFile.Release (); | |
275 return XPCOM.NS_OK; | |
276 } | |
277 | |
278 return XPCOM.NS_ERROR_FAILURE; | |
279 } | |
280 } |