From 394bcff4aa7b1893686fad9999911c95304a7dec Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 20 Apr 2000 18:16:05 +0000 Subject: [PATCH] bug 33099 r=shaver a=edburns Native code changes: This fix eradicates all occurrences of the following symbols nsComponentManager nsServiceManeger And replaces them with their nsI counterparts. The following ns* classes still are used in webclient, and no plans exist to replace them with nsI counterparts: nsresult nsCOMPtr nsCRT nsnull * nsServiceManager occurrences were replaced with do_GetService(), using a PROGID. * nsComponentManager occurrences were replaced with a call on the global class gComponentManager, declared in the new file ns_globals.h, and defined in WrapperFactoryImpl.cpp. ns_globals.h is included in jni_util.h. See the attachment to bug 33099 for ns_globals.h * Added deallocation code to WindowControlImpl.cpp nativeTerminate. I know it doesn't do much, but it's correct. Java code changes: * Added static method BrowserControlFactory.appTerminate(). This method simply calls the existing BrowserControlImpl.appTerminate(), which calls WrapperFactoryImpl.cpp nativeTerminate(). BrowserControlFactory.appTerminate() is called from EmbeddedMozilla's WindowListener, which gets fired when the user signals she wants the app to terminate. git-svn-id: svn://10.0.0.236/trunk@66563 18797224-902f-48f8-a5cc-f745e15eee43 --- .../webclient/BrowserControlFactory.java | 9 ++- .../webclient/test/EmbeddedMozilla.java | 8 ++- .../webclient/src_moz/NativeEventThread.cpp | 41 ++++++------- .../java/webclient/src_moz/RDFEnumeration.cpp | 13 +++-- .../java/webclient/src_moz/RDFTreeNode.cpp | 13 +++-- .../webclient/src_moz/WrapperFactoryImpl.cpp | 38 +++++++++--- mozilla/java/webclient/src_moz/ns_globals.h | 29 ++++++++++ mozilla/java/webclient/src_moz/rdf_progids.h | 30 ++++++++++ mozilla/java/webclient/src_moz/rdf_util.cpp | 58 ++++++++++--------- mozilla/java/webclient/src_moz/rdf_util.h | 4 -- 10 files changed, 169 insertions(+), 74 deletions(-) create mode 100644 mozilla/java/webclient/src_moz/rdf_progids.h diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlFactory.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlFactory.java index c7bf464f2bb..5b01171be3e 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlFactory.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlFactory.java @@ -43,7 +43,7 @@ import java.io.FileNotFoundException; * This is a static class, it is neven instantiated. * - * @version $Id: BrowserControlFactory.java,v 1.2 2000-03-13 18:41:36 edburns%acm.org Exp $ + * @version $Id: BrowserControlFactory.java,v 1.3 2000-04-20 18:15:36 edburns%acm.org Exp $ * * @see org.mozilla.webclient.test.EmbeddedMozilla @@ -167,6 +167,11 @@ public static void setAppData(String absolutePathToNativeBrowserBinDir) throws F } } +public static void appTerminate() throws Exception +{ + BrowserControlImpl.appTerminate(); +} + public static BrowserControl newBrowserControl() throws InstantiationException, IllegalAccessException, IllegalStateException { if (!appDataHasBeenSet) { @@ -220,7 +225,7 @@ public static void main(String [] args) Assert.setEnabled(true); Log.setApplicationName("BrowserControlFactory"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: BrowserControlFactory.java,v 1.2 2000-03-13 18:41:36 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: BrowserControlFactory.java,v 1.3 2000-04-20 18:15:36 edburns%acm.org Exp $"); BrowserControlCanvas canvas = null; BrowserControl control = null; diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java index 134db982df3..2e3a5668355 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java @@ -38,7 +38,7 @@ import org.mozilla.util.Assert; * This is a test application for using the BrowserControl. * - * @version $Id: EmbeddedMozilla.java,v 1.3 2000-04-06 17:33:33 ashuk%eng.sun.com Exp $ + * @version $Id: EmbeddedMozilla.java,v 1.4 2000-04-20 18:15:42 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -77,6 +77,12 @@ public void DestroyEMWindow(int winNumber) { count--; if (count == 0) { System.out.println("closing application"); + try { + BrowserControlFactory.appTerminate(); + } + catch(Exception e) { + System.out.println("got Exception on exit: " + e.getMessage()); + } System.exit(0); } } diff --git a/mozilla/java/webclient/src_moz/NativeEventThread.cpp b/mozilla/java/webclient/src_moz/NativeEventThread.cpp index 2b7eb3829a7..3e42d9b5ba8 100644 --- a/mozilla/java/webclient/src_moz/NativeEventThread.cpp +++ b/mozilla/java/webclient/src_moz/NativeEventThread.cpp @@ -43,27 +43,22 @@ #include "nsIEventQueueService.h" // for PLEventQueue #include "nsIPref.h" // for preferences #include "nsRepository.h" -#include "nsIServiceManager.h" // for nsServiceManager::GetService +#include "nsIServiceManager.h" // for do_GetService #include "nsISessionHistory.h" // for history #include "nsIThread.h" // for PRThread //nsIWebShell is included in jni_util.h +#include "prlog.h" // for PR_ASSERT + #ifdef XP_UNIX #include #include "gdksuperwin.h" #include "gtkmozarea.h" #endif - - -static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); -static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); - static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - static NS_DEFINE_IID(kISessionHistoryIID, NS_ISESSIONHISTORY_IID); static NS_DEFINE_CID(kSessionHistoryCID, NS_SESSIONHISTORY_CID); @@ -92,7 +87,7 @@ nsresult InitMozillaStuff (WebShellInitContext * arg); // Local data // -static nsISessionHistory *gHistory = nsnull; +nsISessionHistory *gHistory = nsnull; char * errorMessages[] = { "No Error", @@ -331,7 +326,12 @@ static void event_processor_callback(gpointer data, nsresult InitMozillaStuff (WebShellInitContext * initContext) { - nsIEventQueueService * aEventQService = nsnull; + PR_ASSERT(gComponentManager); + + nsCOMPtr + aEventQService = do_GetService(NS_EVENTQUEUESERVICE_PROGID); + + // if we get here, we know that aEventQService is not null. nsresult rv = NS_ERROR_FAILURE; PRBool allowPlugins = PR_FALSE; @@ -346,11 +346,7 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) #endif // Create the Event Queue for the UI thread... - rv = nsServiceManager::GetService(kEventQueueServiceCID, - kIEventQueueServiceIID, - (nsISupports **) &aEventQService); - - if (NS_FAILED(rv)) { + if (!aEventQService) { initContext->initFailCode = kEventQueueError; return rv; } @@ -452,23 +448,20 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) } #endif - nsIPref *prefs; + nsCOMPtr prefs = do_GetService(NS_PREF_PROGID); - rv = nsServiceManager::GetService(kPrefCID, - nsIPref::GetIID(), - (nsISupports **)&prefs); - if (NS_SUCCEEDED(rv)) { - if (nsnull == gHistory) { // only do this once per app. + if (prefs) { + if (nsnull == gComponentManager) { // only do this once per app. prefs->ReadUserPrefs(); } // Set the prefs in the outermost webshell. initContext->webShell->SetPrefs(prefs); - nsServiceManager::ReleaseService(kPrefCID, prefs); } if (nsnull == gHistory) { - rv = nsComponentManager::CreateInstance(kSessionHistoryCID, nsnull, kISessionHistoryIID, - (void**)&gHistory); + rv = gComponentManager->CreateInstance(kSessionHistoryCID, nsnull, + kISessionHistoryIID, + (void**)&gHistory); if (NS_FAILED(rv)) { initContext->initFailCode = kHistoryWebShellError; return rv; diff --git a/mozilla/java/webclient/src_moz/RDFEnumeration.cpp b/mozilla/java/webclient/src_moz/RDFEnumeration.cpp index 604a17f0fe6..9ad7a920d4c 100644 --- a/mozilla/java/webclient/src_moz/RDFEnumeration.cpp +++ b/mozilla/java/webclient/src_moz/RDFEnumeration.cpp @@ -23,11 +23,14 @@ #include "RDFEnumeration.h" #include "rdf_util.h" +#include "rdf_progids.h" #include "jni_util.h" #include "nsIRDFContainer.h" #include "nsIServiceManager.h" +#include "prlog.h" // for PR_ASSERT + // // Local function prototypes // @@ -192,12 +195,14 @@ jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode) } return -1; } + + PR_ASSERT(gComponentManager); // get a container in order to get the enum - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + rv = gComponentManager->CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { if (prLogModuleInfo) { PR_LOG(prLogModuleInfo, 3, diff --git a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp index cfbc7c3cae9..f048132b6dd 100644 --- a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp +++ b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp @@ -23,10 +23,13 @@ #include "RDFTreeNode.h" #include "rdf_util.h" +#include "rdf_progids.h" #include "jni_util.h" #include "nsIServiceManager.h" +#include "prlog.h" // for PR_ASSERT + // // Local function prototypes // @@ -256,11 +259,13 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt return; } + PR_ASSERT(gComponentManager); + // get a container in order to create a child - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + rv = gComponentManager->CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container."); return; diff --git a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp index 6946655f130..c0f5eb05083 100644 --- a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp @@ -63,6 +63,10 @@ static NS_DEFINE_CID(kSessionHistoryCID, NS_SESSIONHISTORY_CID); #endif // XP_PC +// +// file data +// + static nsFileSpec gBinDir; @@ -78,6 +82,16 @@ const char *gImplementedInterfaces[] = { nsnull }; +// +// global data +// + +nsIComponentManager *gComponentManager = nsnull; + +// +// Functions to hook into mozilla +// + extern "C" void NS_SetupRegistry(); extern nsresult NS_AutoregisterComponents(); @@ -85,16 +99,25 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeAppInitialize( JNIEnv *env, jobject obj, jstring verifiedBinDirAbsolutePath) { - JNIEnv * pEnv = env; - jobject jobj = obj; static PRBool gFirstTime = PR_TRUE; + nsresult rv; + if (gFirstTime) { const char *nativePath = (const char *) ::util_GetStringUTFChars(env, verifiedBinDirAbsolutePath); gBinDir = nativePath; + // It is vitally important to call NS_InitXPCOM before calling + // anything else. NS_InitXPCOM(nsnull, &gBinDir); NS_SetupRegistry(); + rv = NS_GetGlobalComponentManager(&gComponentManager); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "NS_GetGlobalComponentManager() failed."); + ::util_ReleaseStringUTFChars(env, verifiedBinDirAbsolutePath, + nativePath); + return; + } prLogModuleInfo = PR_NewLogModule("webclient"); const char *webclientLogFile = PR_GetEnv("WEBCLIENT_LOG_FILE"); if (nsnull != webclientLogFile) { @@ -102,9 +125,9 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeAppInitializ // If this fails, it just goes to stdout/stderr } - nsComponentManager::RegisterComponentLib(kSessionHistoryCID, nsnull, - nsnull, APPSHELL_DLL, - PR_FALSE, PR_FALSE); + gComponentManager->RegisterComponentLib(kSessionHistoryCID, nsnull, + nsnull, APPSHELL_DLL, + PR_FALSE, PR_FALSE); NS_AutoregisterComponents(); gFirstTime = PR_FALSE; ::util_ReleaseStringUTFChars(env, verifiedBinDirAbsolutePath, nativePath); @@ -114,9 +137,10 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeAppInitializ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeTerminate -(JNIEnv *, jobject) +(JNIEnv *env, jobject obj) { - + gComponentManager = nsnull; + gHistory = nsnull; } JNIEXPORT jboolean JNICALL diff --git a/mozilla/java/webclient/src_moz/ns_globals.h b/mozilla/java/webclient/src_moz/ns_globals.h index a590e8a5b8a..b3d4b558b35 100644 --- a/mozilla/java/webclient/src_moz/ns_globals.h +++ b/mozilla/java/webclient/src_moz/ns_globals.h @@ -34,4 +34,33 @@ #include "prlog.h" extern PRLogModuleInfo *prLogModuleInfo; // defined in WrapperFactory.cpp +/** + + * Lifetime: + + * Created using NS_GetGlobalComponentManager in WrapperFactoryImpl.cpp + * nativeAppInitialize(). + + * Set to nsnull in WrapperFactoryImpl.cpp nativeTerminate(). + + */ + +class nsIComponentManager; +extern nsIComponentManager *gComponentManager; // defined in WrapperFactoryImpl.cpp + +/** + + * Lifetime: + + * Lazily created in NativeEventThread.cpp InitMozillaStuff(). + + * Set to nsnull in WrapperFactoryImpl.cpp nativeTerminate(). + + */ + +class nsISessionHistory; +extern nsISessionHistory *gHistory; // defined in NativeEventThread.cpp + + + #endif // ns_globals_h diff --git a/mozilla/java/webclient/src_moz/rdf_progids.h b/mozilla/java/webclient/src_moz/rdf_progids.h new file mode 100644 index 00000000000..3afa89eec62 --- /dev/null +++ b/mozilla/java/webclient/src_moz/rdf_progids.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +#ifndef _rdf_progids_h +#define _rdf_progids_h + +static const char *NS_RDFSERVICE_PROGID = "component://netscape/rdf/rdf-service"; +static const char *NS_CONTAINERUTILS_PROGID = "component://netscape/rdf/container-utils"; +static const char *NS_RDFCONTAINER_PROGID = "component://netscape/rdf/container"; + +#endif diff --git a/mozilla/java/webclient/src_moz/rdf_util.cpp b/mozilla/java/webclient/src_moz/rdf_util.cpp index 3dc24293d3a..7117e02f9ba 100644 --- a/mozilla/java/webclient/src_moz/rdf_util.cpp +++ b/mozilla/java/webclient/src_moz/rdf_util.cpp @@ -21,11 +21,14 @@ */ #include "rdf_util.h" +#include "rdf_progids.h" -#include "ns_globals.h" // for prLogModuleInfo +#include "ns_globals.h" // for prLogModuleInfo and gComponentManager #include "nsIServiceManager.h" +#include "prlog.h" // for PR_ASSERT + static PRBool rdf_inited = PR_FALSE; nsCOMPtr gRDFCU = nsnull; @@ -52,9 +55,7 @@ nsresult rdf_InitRDFUtils() if (nsnull == gBookmarks) { // Get the bookmarks service - rv = nsServiceManager::GetService(NS_IBOOKMARKSSERVICE_PROGID, - NS_GET_IID(nsIBookmarksService), - getter_AddRefs(gBookmarks)); + gBookmarks = do_GetService(NS_BOOKMARKS_SERVICE_PROGID, &rv); if (NS_FAILED(rv)) { return rv; } @@ -71,9 +72,7 @@ nsresult rdf_InitRDFUtils() if (nsnull == gRDF) { // get the RDF service - rv = nsServiceManager::GetService(NS_IRDFSERVICE_PROGID, - NS_GET_IID(nsIRDFService), - getter_AddRefs(gRDF)); + gRDF = do_GetService(NS_RDFSERVICE_PROGID, &rv); if (NS_FAILED(rv)) { return rv; } @@ -81,9 +80,7 @@ nsresult rdf_InitRDFUtils() if (nsnull == gRDFCU) { // get the RDF service - rv = nsServiceManager::GetService(NS_ICONTAINERUTILS_PROGID, - NS_GET_IID(nsIRDFContainerUtils), - getter_AddRefs(gRDFCU)); + gRDFCU = do_GetService(NS_CONTAINERUTILS_PROGID, &rv); if (NS_FAILED(rv)) { return rv; } @@ -184,11 +181,13 @@ void rdf_recursiveResourceTraversal(nsCOMPtr currentResource) } } + PR_ASSERT(gComponentManager); // get a container in order to recurr - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + rv = gComponentManager-> + CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { if (prLogModuleInfo) { PR_LOG(prLogModuleInfo, 3, @@ -261,6 +260,7 @@ void rdf_recursiveResourceTraversal(nsCOMPtr currentResource) } else { // It's a bookmark + printf("BOOKMARK:\n"); rdf_printArcLabels(currentResource); // see if it has a URL target @@ -422,10 +422,12 @@ nsresult rdf_getChildAt(int index, nsIRDFResource *theParent, return NS_OK; } - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + PR_ASSERT(gComponentManager); + + rv = gComponentManager->CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { return rv; } @@ -489,11 +491,11 @@ nsresult rdf_getChildCount(nsIRDFResource *theParent, PRInt32 *count) if (PR_FALSE == result) { return NS_OK; } - - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + PR_ASSERT(gComponentManager); + rv = gComponentManager->CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { return rv; } @@ -534,11 +536,11 @@ nsresult rdf_getIndexOfChild(nsIRDFResource *theParent, if (PR_FALSE == result) { return NS_OK; } - - rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); + PR_ASSERT(gComponentManager); + rv = gComponentManager->CreateInstanceByProgID(NS_RDFCONTAINER_PROGID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); if (NS_FAILED(rv)) { return rv; } diff --git a/mozilla/java/webclient/src_moz/rdf_util.h b/mozilla/java/webclient/src_moz/rdf_util.h index 67c2e64184a..c0dd4b8db09 100644 --- a/mozilla/java/webclient/src_moz/rdf_util.h +++ b/mozilla/java/webclient/src_moz/rdf_util.h @@ -36,10 +36,6 @@ */ -static const char *NS_IRDFSERVICE_PROGID = "component://netscape/rdf/rdf-service"; -static const char *NS_ICONTAINERUTILS_PROGID = "component://netscape/rdf/container-utils"; -static const char *NS_IBOOKMARKSSERVICE_PROGID = "component://netscape/browser/bookmarks-service"; -static const char *NS_IRDFCONTAINER_PROGID = "component://netscape/rdf/container"; static const char *BOOKMARKS_URI = "NC:BookmarksRoot"; extern nsCOMPtr gRDFCU;