annotate dwt/browser.old/AppFileLocProvider.d @ 288:4ee8c4237614

old branches... commit by mistake
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 18:00:50 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
288
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
1 /*******************************************************************************
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
7 *
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
8 * Contributors:
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
10 * Port to the D programming language:
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
11 * John Reimer <terminal.node@gmail.com>
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
12 *******************************************************************************/
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
13
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
14 module dwt.browser.AppFileLocProvider;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
15
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
16 import dwt.dwthelper.utils;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
17
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
18 import dwt.internal.Compatibility;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
19
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
20 import dwt.internal.mozilla.nsEmbedString;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
21 import dwt.internal.mozilla.nsID;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
22 import dwt.internal.mozilla.nsIDirectoryService;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
23 import dwt.internal.mozilla.nsIFile;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
24 import dwt.internal.mozilla.nsILocalFile;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
25 import dwt.internal.mozilla.nsISupports;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
26
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
27 class AppFileLocProvider : nsISupports, nsIDirectoryServiceProvider2
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
28 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
29 // XPCOMObject supports;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
30 // XPCOMObject directoryServiceProvider;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
31 // XPCOMObject directoryServiceProvider2;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
32 nsrefcnt _refCount = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
33 String mozillaPath, profilePath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
34 String[] pluginDirs;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
35 bool isXULRunner;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
36
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
37 static String SEPARATOR_OS = System.getProperty ("file.separator"); //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
38 static String CHROME_DIR = "chrome"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
39 static String COMPONENTS_DIR = "components"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
40 static String HISTORY_FILE = "history.dat"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
41 static String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
42 static String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
43 static String PLUGINS_DIR = "plugins"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
44 static String USER_PLUGINS_DIR = ".mozilla" + SEPARATOR_OS + "plugins"; //$NON-NLS-1$ //$NON-NLS-2$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
45 static String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
46
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
47 AppFileLocProvider (String path) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
48 mozillaPath = path + SEPARATOR_OS;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
49 createCOMInterfaces ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
50 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
51
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
52 int AddRef ()
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
53 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
54 refCount++;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
55 return refCount;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
56 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
57
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
58 nsresult QueryInterface ( nsIID* riid, void** ppvObject)
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
59 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
60 if (riid is null || ppvObject is null)
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
61 return NS_ERROR_NO_INTERFACE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
62
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
63 if (riid == nsISupports.IID)
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
64 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
65 *ppvObject =cast(void*)cast(nsISupports)this;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
66 AddRef ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
67 return NS_OK;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
68 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
69
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
70 if (riid == nsIDirectoryServiceProvider.IID)
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
71 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
72 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
73 AddRef ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
74 return NS_OK;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
75 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
76
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
77 if (riid == nsDirectoryServiceProvider2.IID) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
78 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
79 AddRef ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
80 return NS_OK;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
81 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
82
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
83 *ppvObject = null;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
84 return NS_ERROR_NO_INTERFACE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
85 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
86
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
87 nsrefcnt Release ()
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
88 {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
89 _refCount--;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
90 if (_refCount is 0)
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
91 return 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
92 return _refCount;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
93 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
94
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
95 void setProfilePath (String path) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
96 profilePath = path;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
97 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
98 int /*long*/[] result = new int /*long*/[1];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
99 nsEmbedString pathString = new nsEmbedString (path);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
100 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
101 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
102 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
103 pathString.dispose ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
104
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
105 nsILocalFile file = new nsILocalFile (result [0]);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
106 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
107 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
108 file.Release ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
109 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
110 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
111
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
112 /* nsIDirectoryServiceProvider2 */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
113
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
114 int getFiles (int /*long*/ prop, int /*long*/ _retval) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
115 int size = XPCOM.strlen (prop);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
116 byte[] bytes = new byte[size];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
117 XPCOM.memmove (bytes, prop, size);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
118 String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes));
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
119 String[] propertyValues = null;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
120
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
121 if (propertyName.equals (XPCOM.NS_APP_PLUGINS_DIR_LIST)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
122 if (pluginDirs is null) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
123 int index = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
124 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
125 int /*long*/ ptr = C.getenv (MozillaDelegate.wcsToMbcs (null, XPCOM.MOZILLA_PLUGIN_PATH, true));
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
126 if (ptr !is 0) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
127 int length = C.strlen (ptr);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
128 byte[] buffer = new byte[length];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
129 C.memmove (buffer, ptr, length);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
130 String value = new String (MozillaDelegate.mbcsToWcs (null, buffer));
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
131 if (value.length () > 0) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
132 String separator = System.getProperty ("path.separator"); // $NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
133 Vector segments = new Vector ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
134 int start, end = -1;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
135 do {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
136 start = end + 1;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
137 end = value.indexOf (separator, start);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
138 String segment;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
139 if (end is -1) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
140 segment = value.substring (start);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
141 } else {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
142 segment = value.substring (start, end);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
143 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
144 if (segment.length () > 0) segments.addElement (segment);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
145 } while (end !is -1);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
146 int segmentsSize = segments.size ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
147 pluginDirs = new String [segmentsSize + 2];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
148 for (index = 0; index < segmentsSize; index++) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
149 pluginDirs[index] = (String)segments.elementAt (index);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
150 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
151 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
152 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
153 if (pluginDirs is null) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
154 pluginDirs = new String[2];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
155 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
156
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
157 /* set the next value to the GRE path + "plugins" */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
158 pluginDirs[index++] = mozillaPath + PLUGINS_DIR;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
159
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
160 /* set the next value to the home directory + "/.mozilla/plugins" */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
161 pluginDirs[index++] = System.getProperty("user.home") + SEPARATOR_OS + USER_PLUGINS_DIR;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
162 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
163 propertyValues = pluginDirs;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
164 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
165
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
166 XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
167 if (propertyValues !is null) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
168 int /*long*/[] result = new int /*long*/[1];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
169 nsISupports[] files = new nsISupports [propertyValues.length];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
170 int index = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
171 for (int i = 0; i < propertyValues.length; i++) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
172 nsEmbedString pathString = new nsEmbedString (propertyValues[i]);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
173 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
174 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
175 /* value appears to be a valid pathname */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
176 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
177 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
178
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
179 nsILocalFile localFile = new nsILocalFile (result[0]);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
180 result[0] = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
181 rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
182 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
183 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
184 localFile.Release ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
185
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
186 nsIFile file = new nsIFile (result[0]);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
187 files[index++] = file;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
188 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
189 pathString.dispose ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
190 result[0] = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
191 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
192
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
193 if (index < propertyValues.length) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
194 /* there were some invalid values so remove the trailing empty array slots */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
195 nsISupports[] temp = new nsISupports [index];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
196 System.arraycopy (files, 0, temp, 0, index);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
197 files = temp;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
198 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
199
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
200 SimpleEnumerator enumerator = new SimpleEnumerator (files);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
201 enumerator.AddRef ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
202 XPCOM.memmove (_retval, new int /*long*/[] {enumerator.getAddress ()}, C.PTR_SIZEOF);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
203 return XPCOM.NS_OK;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
204 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
205
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
206 return XPCOM.NS_ERROR_FAILURE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
207 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
208
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
209 /* nsIDirectoryServiceProvider implementation */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
210
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
211 int getFile(int /*long*/ prop, int /*long*/ persistent, int /*long*/ _retval) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
212 int size = XPCOM.strlen (prop);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
213 byte[] bytes = new byte[size];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
214 XPCOM.memmove (bytes, prop, size);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
215 String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes));
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
216 String propertyValue = null;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
217
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
218 if (propertyName.equals (XPCOM.NS_APP_HISTORY_50_FILE)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
219 propertyValue = profilePath + HISTORY_FILE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
220 } else if (propertyName.equals (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
221 propertyValue = profilePath + MIMETYPES_FILE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
222 } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_FILE)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
223 propertyValue = profilePath + PREFERENCES_FILE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
224 } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
225 propertyValue = profilePath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
226 } else if (propertyName.equals (XPCOM.NS_APP_USER_CHROME_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
227 propertyValue = profilePath + CHROME_DIR;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
228 } else if (propertyName.equals (XPCOM.NS_APP_USER_PROFILE_50_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
229 propertyValue = profilePath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
230 } else if (propertyName.equals (XPCOM.NS_APP_LOCALSTORE_50_FILE)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
231 propertyValue = profilePath + LOCALSTORE_FILE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
232 } else if (propertyName.equals (XPCOM.NS_APP_CACHE_PARENT_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
233 propertyValue = profilePath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
234 } else if (propertyName.equals (XPCOM.NS_OS_HOME_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
235 propertyValue = System.getProperty("user.home"); //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
236 } else if (propertyName.equals (XPCOM.NS_OS_TEMP_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
237 propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
238 } else if (propertyName.equals (XPCOM.NS_GRE_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
239 propertyValue = mozillaPath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
240 } else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
241 propertyValue = mozillaPath + COMPONENTS_DIR;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
242 } else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
243 propertyValue = mozillaPath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
244 } else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
245 propertyValue = mozillaPath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
246 } else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
247 propertyValue = mozillaPath + COMPONENTS_DIR;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
248 } else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
249 propertyValue = mozillaPath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
250 } else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
251 /*
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
252 * Answering a value for this property causes problems in Mozilla versions
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
253 * < 1.7. Unfortunately this property is queried early enough in the
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
254 * Browser creation process that the Mozilla version being used is not
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
255 * yet determined. However it is known if XULRunner is being used or not.
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
256 *
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
257 * For now answer a value for this property iff XULRunner is the GRE.
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
258 * If the range of Mozilla versions supported by the Browser is changed
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
259 * in the future to be >= 1.7 then this value can always be answered.
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
260 */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
261 if (isXULRunner) propertyValue = profilePath;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
262 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
263
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
264 XPCOM.memmove (persistent, new int[] {1}, 4); /* PRBool */
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
265 XPCOM.memmove (_retval, new int /*long*/[] {0}, C.PTR_SIZEOF);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
266 if (propertyValue !is null && propertyValue.length () > 0) {
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
267 int /*long*/[] result = new int /*long*/[1];
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
268 nsEmbedString pathString = new nsEmbedString (propertyValue);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
269 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
270 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
271 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
272 pathString.dispose ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
273
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
274 nsILocalFile localFile = new nsILocalFile (result [0]);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
275 result[0] = 0;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
276 rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
277 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
278 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
279
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
280 XPCOM.memmove (_retval, new int /*long*/[] {result[0]}, C.PTR_SIZEOF);
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
281 localFile.Release ();
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
282 return XPCOM.NS_OK;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
283 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
284
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
285 return XPCOM.NS_ERROR_FAILURE;
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
286 }
4ee8c4237614 old branches... commit by mistake
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
287 }