Back to index

lightning-sunbird  0.9+nobinonly
nsQABrowserModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Radha Kulkarni (radha@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsIModule.h"
00040 #include "nsIGenericFactory.h"
00041 #include "nsIComponentManager.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsIComponentRegistrar.h"
00044 
00045 #include "nsQABrowserCID.h"
00046 #include "nsQABrowserView.h"
00047 #include "nsQABrowserUIGlue.h"
00048 #include "nsQABrowserChrome.h"
00049 
00050 // Factory Constructors
00051 
00052 NS_GENERIC_FACTORY_CONSTRUCTOR(nsQABrowserView)
00053 NS_GENERIC_FACTORY_CONSTRUCTOR(nsQABrowserUIGlue)
00054 NS_GENERIC_FACTORY_CONSTRUCTOR(nsQABrowserChrome)
00055 
00056 // Component Table
00057 
00058 
00059 
00060 static NS_DEFINE_CID(kBrowserViewCID, NS_QABROWSERVIEW_CID);
00061 static NS_DEFINE_CID(kBrowserUIGlueCID, NS_QABROWSERUIGLUE_CID);
00062 static NS_DEFINE_CID(kBrowserChromeCID, NS_QABROWSERCHROME_CID);
00063 
00064 static const nsModuleComponentInfo gQAEmbeddingModuleViewInfo[] =
00065 {
00066    { "QA_BrowserView Component", NS_QABROWSERVIEW_CID, 
00067      NS_QABROWSERVIEW_CONTRACTID, nsQABrowserViewConstructor }
00068 };
00069 
00070 static const nsModuleComponentInfo gQAEmbeddingModuleUIInfo[] =
00071 {
00072    { "QA_BrowserUIGlue Component", NS_QABROWSERUIGLUE_CID,
00073      NS_QABROWSERUIGLUE_CONTRACTID, nsQABrowserUIGlueConstructor }
00074 };
00075 
00076 static const nsModuleComponentInfo gQAEmbeddingModuleChromeInfo[] =
00077 {
00078    { "QA_BrowserChrome Component", NS_QABROWSERCHROME_CID,
00079      NS_QABROWSERCHROME_CONTRACTID, nsQABrowserChromeConstructor }
00080 };
00081 
00082 nsresult
00083 RegisterComponents()
00084 {
00085 
00086   nsresult rv=NS_OK;
00087   nsIGenericFactory* fact;
00088 
00089   // Register the factory for all supporting interfaces. 
00090   nsCOMPtr<nsIComponentRegistrar> registrar;
00091   rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
00092   if (NS_FAILED(rv))
00093     return rv;
00094 
00095   // Register nsQABrowserView
00096   rv = NS_NewGenericFactory(&fact, gQAEmbeddingModuleViewInfo);
00097   rv = registrar->RegisterFactory(kBrowserViewCID,
00098                                   "QA Embedding BrowserView",
00099                                   NS_QABROWSERVIEW_CONTRACTID,
00100                                   fact);
00101   NS_RELEASE(fact);
00102 
00103   //Register nsQABrowserUIGlue
00104   rv = NS_NewGenericFactory(&fact, gQAEmbeddingModuleUIInfo);
00105 
00106   rv = registrar->RegisterFactory(kBrowserUIGlueCID,
00107                                   "QA Embedding BrowserUIGlue",
00108                                   NS_QABROWSERUIGLUE_CONTRACTID,
00109                                   fact);
00110   NS_RELEASE(fact);
00111 
00112   //Register nsQABrowserChrome
00113   rv = NS_NewGenericFactory(&fact, gQAEmbeddingModuleChromeInfo);
00114 
00115   rv = registrar->RegisterFactory(kBrowserChromeCID,
00116                                   "QA Embedding BrowserChrome",
00117                                   NS_QABROWSERCHROME_CONTRACTID,
00118                                   fact);
00119   NS_RELEASE(fact);
00120   return rv;
00121 
00122 }
00123 
00124 
00125 
00126 
00127 #if 0
00128 nsresult
00129 NSRegisterSelf(nsISupports* aServMgr, const char* aPath)
00130 {
00131   nsresult rv;
00132   nsCOMPtr<nsIComponentManagerObsolete> compMgr =
00133            do_GetService(kComponentManagerCID, aServMgr, &rv);
00134   if (NS_FAILED(rv)) return rv;
00135 
00136   rv = compMgr->RegisterComponent(kBrowserViewCID,
00137                                   "QA Embedding BrowserView",
00138                                   NS_QABROWSERVIEW_CONTRACTID,
00139                                   aPath, PR_TRUE, PR_TRUE);
00140   rv = compMgr->RegisterComponent(kBrowserUIGlueCID,
00141                                   "QA Embedding BrowserUIGlue",
00142                                   NS_QABROWSERUIGLUE_CONTRACTID,
00143                                   aPath, PR_TRUE, PR_TRUE);
00144 
00145   return rv;
00146 
00147 }
00148 
00149 nsresult
00150 NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
00151 {
00152   nsresult rv;
00153   nsCOMPtr<nsIComponentManagerObsolete> compMgr =
00154          do_GetService(kComponentManagerCID, aServMgr, &rv);
00155   if (NS_FAILED(rv)) return rv;
00156 
00157   //rv = compMgr->UnregisterComponent(kRDFDataSourceCID, aPath);
00158 
00159   rv = compMgr->UnregisterComponent(kBrowserViewCID, aPath);
00160   rv = compMgr->UnregisterComponent(kBrowserUIGlueCID, aPath);
00161                             
00162   return rv;
00163 }
00164 #endif  /* 0 */
00165 
00166 
00167 
00168 // NSGetModule implementation.
00169 
00170 
00171 #if 0
00172 
00173 NS_IMPL_NSGETMODULE(Mozilla_Embedding_Component, gQAEmbeddingModuleInfo)
00174 
00175 nsresult
00176 NSGetFactory(nsISupports* aServMgr,
00177              const nsCID &aClass,
00178              const char* aClassName,
00179              const char* aContractID,
00180              nsIFactory **aFactory)
00181 {
00182   nsresult rv=NS_OK;
00183   nsIGenericFactory* fact;
00184  // if (aClass.Equals(kBrowserViewCID))
00185     rv = NS_NewGenericFactory(&fact, gQAEmbeddingModuleInfo);
00186  // else if (aClass.Equals(kBrowserUIGlueCID))
00187  //   rv = NS_NewGenericFactory(&fact, NS_NewQABrowserUIGlueFactory);
00188  //   rv = NS_ERROR_FAILURE;
00189 
00190   if (NS_SUCCEEDED(rv))
00191     *aFactory = fact;
00192 
00193 #ifdef DEBUG_radha
00194   printf("nsQABrowserComponent NSGetFactory!\n");
00195 #endif
00196   return rv;
00197 }
00198 
00199 #endif