root/lang/pascal/GeckoSDK/nsXULAppAPI.pas @ 4182

Revision 4182, 11.3 kB (checked in by plus7, 5 years ago)

lang/pascal/GeckoSDK/nsXULAppAPI.pas: added lisence block

  • Property svn:executable set to *
Line 
1(* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is mozilla.org.
15 *
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corpotation.
18 * Portions created by the Initial Developer are Copyright (C) 1998
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *   NOSE Takafumi <ahya365@gmail.com>
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** *)
37unit nsXULAppAPI;
38
39interface
40
41uses
42  nsXPCOM, nsGeckoStrings, nsConsts, nsTypes, SysUtils;
43 
44  function XRE_Startup: Longword;
45  function XRE_Shutdown: Longword;
46const
47(* *
48 * Indicates whether or not the profile migrator service may be
49 * invoked at startup when creating a profile.
50 *)
51  NS_XRE_ENABLE_PROFILE_MIGRATOR = (1 shl 1);
52
53(* *
54 * Indicates whether or not the extension manager service should be
55 * initialized at startup.
56 *)
57  NS_XRE_ENABLE_EXTENSION_MANAGER = (1 shl 2);
58
59(* *
60 * Indicates whether or not to use Breakpad crash reporting.
61 *)
62  NS_XRE_ENABLE_CRASH_REPORTER = (1 shl 3);
63
64(* *
65 * The contract id for the nsIXULAppInfo service.
66 *)
67  XULAPPINFO_SERVICE_CONTRACTID = '@mozilla.org/xre/app-info;1';
68
69(* *
70 * A directory service key which provides the platform-correct "application
71 * data" directory as follows, where $name and $vendor are as defined above and
72 * $vendor is optional:
73 *
74 * Windows:
75 *   HOME = Documents and Settings\$USER\Application Data
76 *   UAppData = $HOME[\$vendor]\$name
77 *
78 * Unix:
79 *   HOME = ~
80 *   UAppData = $HOME/.[$vendor/]$name
81 *
82 * Mac:
83 *   HOME = ~
84 *   UAppData = $HOME/Library/Application Support/$name
85 *
86 * Note that the "profile" member above will change the value of UAppData as
87 * follows:
88 *
89 * Windows:
90 *   UAppData = $HOME\$profile
91 *
92 * Unix:
93 *   UAppData = $HOME/.$profile
94 *
95 * Mac:
96 *   UAppData = $HOME/Library/Application Support/$profile
97 *)
98  XRE_USER_APP_DATA_DIR = 'UAppData';
99
100(* *
101 * A directory service key which provides a list of all enabled extension
102 * directories. The list includes compatible platform-specific extension
103 * subdirectories.
104 *
105 * @note The directory list will have no members when the application is
106 *       launched in safe mode.
107 *)
108  XRE_EXTENSIONS_DIR_LIST = 'XREExtDL';
109
110(* *
111 * A directory service key which provides the executable file used to
112 * launch the current process.  This is the same value returned by the
113 * XRE_GetBinaryPath function defined below.
114 *)
115  XRE_EXECUTABLE_FILE = 'XREExeF';
116
117(* *
118 * A directory service key which specifies the profile
119 * directory. Unlike the NS_APP_USER_PROFILE_50_DIR key, this key may
120 * be available when the profile hasn't been 'started', or after is
121 * has been shut down. If the application is running without a
122 * profile, such as when showing the profile manager UI, this key will
123 * not be available. This key is provided by the XUL apprunner or by
124 * the aAppDirProvider object passed to XRE_InitEmbedding.
125 *)
126  NS_APP_PROFILE_DIR_STARTUP = 'ProfDS';
127
128(* *
129 * A directory service key which specifies the profile
130 * directory. Unlike the NS_APP_USER_PROFILE_LOCAL_50_DIR key, this key may
131 * be available when the profile hasn't been 'started', or after is
132 * has been shut down. If the application is running without a
133 * profile, such as when showing the profile manager UI, this key will
134 * not be available. This key is provided by the XUL apprunner or by
135 * the aAppDirProvider object passed to XRE_InitEmbedding.
136 *)
137  NS_APP_PROFILE_LOCAL_DIR_STARTUP = 'ProfLDS';
138type
139  nsStaticModuleInfo = Pointer;
140(*
141        XRE_InitEmbedding, (nsILocalFile *aLibXULDirectory,
142                            nsILocalFile *aAppDirectory,
143                            nsIDirectoryServiceProvider *aAppDirProvider,
144                            nsStaticModuleInfo const *aStaticComponents,
145                            PRUint32 aStaticComponentCount)
146*)
147  XRE_InitEmbeddingFunc = function(
148                            aLibXULDirectory:nsILocalFile;
149                            aAppDirectory:nsILocalFile;
150                            aAppDirProvider:nsIDirectoryServiceProvider;
151                            aStaticComponents:nsStaticModuleInfo;
152                            aStaticComponentCount:PRUint32
153                          ):Integer; cdecl;
154  XRE_TermEmbeddingFunc = procedure(); cdecl;
155(**
156 * Application-specific data needed to start the apprunner.
157 *
158 * @status FROZEN - This API is stable. Additional fields may be added to the
159 *                  end of the structure in the future. Runtime detection
160 *                  of the version of nsXREAppData can be determined by
161 *                  examining the 'size' field.
162 *
163 * @note When this structure is allocated and manipulated by XRE_CreateAppData,
164 *       string fields will be allocated with NS_Alloc, and interface pointers
165 *       are strong references.
166 *)
167  TXREAppData = record
168  (**
169   * This should be set to sizeof(nsXREAppData). This structure may be
170   * extended in future releases, and this ensures that binary compatibility
171   * is maintained.
172   *)
173    size: PRUint32;
174  (**
175   * The directory of the application to be run. May be null if the
176   * xulrunner and the app are installed into the same directory.
177   *)
178    directory:nsILocalFile;
179  (**
180   * The name of the application vendor. This must be ASCII, and is normally
181   * mixed-case, e.g. 'Mozilla'. Optional (may be null), but highly
182   * recommended. Must not be the empty string.
183   *)
184    vendor:PChar;
185  (**
186   * The name of the application. This must be ASCII, and is normally
187   * mixed-case, e.g. 'Firefox'. Required (must not be null or an empty
188   * string).
189   *)
190    name:PChar;
191  (**
192   * The major version, e.g. '0.8.0+'. Optional (may be null), but
193   * required for advanced application features such as the extension
194   * manager and update service. Must not be the empty string.
195   *)
196    version:PChar;
197  (**
198   * The application's build identifier, e.g. '2004051604'
199   *)
200    buildID:PChar;
201  (**
202   * The application's UUID. Used by the extension manager to determine
203   * compatible extensions. Optional, but required for advanced application
204   * features such as the extension manager and update service.
205   *
206   * This has traditionally been in the form
207   * '{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}' but for new applications
208   * a more readable form is encouraged: 'appname@vendor.tld'. Only
209   * the following characters are allowed: a-z A-Z 0-9 - . @ _ { } *
210   *)
211    ID:PChar;
212
213  (**
214   * The copyright information to print for the -h commandline flag,
215   * e.g. 'Copyright (c) 2003 mozilla.org'.
216   *)
217    copyright:PChar;
218
219  (**
220   * Combination of NS_XRE_ prefixed flags (defined below).
221   *)
222    flags:PRUint32;
223
224  (**
225   * The location of the XRE. XRE_main may not be able to figure this out
226   * programatically.
227   *)
228    xreDirectory:nsILocalFile;
229
230  (**
231   * The minimum/maximum compatible XRE version.
232   *)
233    minVersion:PChar;
234    maxVersion:PChar;
235
236  (**
237   * The server URL to send crash reports to.
238   *)
239    crashReporterURL:PChar;
240
241  (**
242   * The profile directory that will be used. Optional (may be null). Must not
243   * be the empty string, must be ASCII. The path is split into components
244   * along the path separator characters '/' and '\'.
245   *
246   * The application data directory ('UAppData', see below) is normally
247   * composed as follows, where $HOME is platform-specific:
248   *
249   *   UAppData = $HOME[/$vendor]/$name
250   *
251   * If present, the 'profile' string will be used instead of the combination of
252   * vendor and name as follows:
253   *
254   *   UAppData = $HOME/$profile
255   *)
256    profile:PChar;
257  end;
258  XULRunnerFunctions = record
259   
260  end;
261implementation
262
263var
264  xulFunc:XULRunnerFunctions;
265  xulLib:HMODULE;
266
267function XRE_Startup: Longword;
268begin
269(*
270nsresult rv;
271    // Find the GRE (libxul). We are only using frozen interfaces, so we
272    // should be compatible all the way up to (but not including) mozilla 2.0
273    static const GREVersionRange vr = {
274        "1.8a1",
275        PR_TRUE,
276        "2.0",
277        PR_FALSE
278    };
279
280    char xpcomPath[_MAX_PATH];
281    rv = GRE_GetGREPathWithProperties(&vr, 1, nsnull, 0,
282                                      xpcomPath, sizeof(xpcomPath));
283    if (NS_FAILED(rv))
284        return 1;
285    char *lastslash = ns_strrpbrk(xpcomPath, "/\\");
286    if (!lastslash)
287        return 2;
288
289    rv = XPCOMGlueStartup(xpcomPath);
290    if (NS_FAILED(rv))
291        return 3;
292
293    *lastslash = '\0';
294
295    char xulPath[_MAX_PATH];
296    _snprintf(xulPath, sizeof(xulPath), "%s\\xul.dll", xpcomPath);
297    xulPath[sizeof(xulPath) - 1] = '\0';
298
299    HINSTANCE xulModule = LoadLibraryEx(xulPath, NULL, 0);
300    if (!xulModule)
301        return 4;
302
303    char temp[_MAX_PATH];
304    GetModuleFileName(xulModule, temp, sizeof(temp));
305
306    XRE_InitEmbedding =
307        (XRE_InitEmbeddingType) GetProcAddress(xulModule, "XRE_InitEmbedding");
308    if (!XRE_InitEmbedding) {
309       fprintf(stderr, "Error: %i\n", GetLastError());
310       return 5;
311    }
312
313    XRE_TermEmbedding =
314        (XRE_TermEmbeddingType) GetProcAddress(xulModule,  "XRE_TermEmbedding");
315    if (!XRE_TermEmbedding) {
316        fprintf(stderr, "Error: %i\n", GetLastError());
317        return 5;
318    }
319
320    // Scope all the XPCOM stuff
321    {
322        nsCOMPtr<nsILocalFile> xuldir;
323        rv = NS_NewNativeLocalFile(nsCString(xpcomPath), PR_FALSE,
324                                   getter_AddRefs(xuldir));
325        if (NS_FAILED(rv))
326            return 6;
327
328        char self[_MAX_PATH];
329                HINSTANCE hInstanceApp = NULL;
330                hInstanceApp = GetModuleHandle(NULL);
331        GetModuleFileName(hInstanceApp, self, sizeof(self));
332        lastslash = ns_strrpbrk(xpcomPath, "/\\");
333        if (!lastslash)
334            return 7;
335
336        *lastslash = '\0';
337
338        nsCOMPtr<nsILocalFile> appdir;
339        rv = NS_NewNativeLocalFile(nsCString(self), PR_FALSE,
340                                   getter_AddRefs(appdir));
341        if (NS_FAILED(rv))
342            return 8;
343
344        rv = XRE_InitEmbedding(xuldir, appdir, nsnull, nsnull, 0);
345        if (NS_FAILED(rv))
346            return 9;
347        }
348        return rv;
349*)
350end;
351
352function XRE_Shutdown: Longword;
353begin
354
355end;
356
357end.
Note: See TracBrowser for help on using the browser.