Back to index

lightning-sunbird  0.9+nobinonly
mozJSLoaderConstructors.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1999
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributors:
00025  *   Mike Shaver <shaver@zeroknowledge.com>
00026  *   John Bandhauer <jband@netscape.com>
00027  *   IBM Corp.
00028  *   Robert Ginda <rginda@netscape.com>
00029  *
00030  * Alternatively, the contents of this file may be used under the terms of
00031  * either of the GNU General Public License Version 2 or later (the "GPL"),
00032  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00033  * in which case the provisions of the GPL or the LGPL are applicable instead
00034  * of those above. If you wish to allow use of your version of this file only
00035  * under the terms of either the GPL or the LGPL, and not to allow others to
00036  * use your version of this file under the terms of the MPL, indicate your
00037  * decision by deleting the provisions above and replace them with the notice
00038  * and other provisions required by the GPL or the LGPL. If you do not delete
00039  * the provisions above, a recipient may use your version of this file under
00040  * the terms of any one of the MPL, the GPL or the LGPL.
00041  *
00042  * ***** END LICENSE BLOCK ***** */
00043 
00044 #ifdef XPCONNECT_STANDALONE
00045 #define NO_SUBSCRIPT_LOADER
00046 #endif
00047 
00048 #include "nsIGenericFactory.h"
00049 #include "nsICategoryManager.h"
00050 #include "mozJSComponentLoader.h"
00051 
00052 #ifndef NO_SUBSCRIPT_LOADER
00053 #include "mozJSSubScriptLoader.h"
00054 const char mozJSSubScriptLoadContractID[] = "@mozilla.org/moz/jssubscript-loader;1";
00055 #endif
00056 
00057 static NS_METHOD
00058 RegisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
00059                  const char *registryLocation, const char *componentType,
00060                  const nsModuleComponentInfo *info)
00061 {
00062     nsresult rv;
00063     nsCOMPtr<nsICategoryManager> catman =
00064         do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
00065     if (NS_FAILED(rv)) return rv;
00066     nsXPIDLCString previous;
00067     return catman->AddCategoryEntry("component-loader",
00068                                     MOZJSCOMPONENTLOADER_TYPE_NAME,
00069                                     MOZJSCOMPONENTLOADER_CONTRACTID,
00070                                     PR_TRUE, PR_TRUE, getter_Copies(previous));
00071 }
00072 
00073 static NS_METHOD
00074 UnregisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
00075                    const char *registryLocation,
00076                    const nsModuleComponentInfo *info)
00077 {
00078     nsresult rv;
00079     nsCOMPtr<nsICategoryManager> catman =
00080         do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
00081     if (NS_FAILED(rv)) return rv;
00082     nsXPIDLCString jsLoader;
00083     rv = catman->GetCategoryEntry("component-loader",
00084                                   MOZJSCOMPONENTLOADER_TYPE_NAME,
00085                                   getter_Copies(jsLoader));
00086     if (NS_FAILED(rv)) return rv;
00087 
00088     // only unregister if we're the current JS component loader
00089     if (!strcmp(jsLoader, MOZJSCOMPONENTLOADER_CONTRACTID)) {
00090         return catman->DeleteCategoryEntry("component-loader",
00091                                            MOZJSCOMPONENTLOADER_TYPE_NAME,
00092                                            PR_TRUE);
00093     }
00094     return NS_OK;
00095 }
00096 
00097 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSComponentLoader)
00098 
00099 #ifndef NO_SUBSCRIPT_LOADER
00100 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader)
00101 #endif