VirtualBox

Changeset 109067 in vbox


Ignore:
Timestamp:
Apr 24, 2025 10:08:54 AM (4 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168604
Message:

libs/xpcom,Main/glue,++: Bake the automatic re-registration of XPCOM components (in the components directory) into the NS_InitXPCOM2 call to avoid the problem of VBoxXPCOMIPCC.so/dylib being engaged at the end of NS_InitXPCOM2 and unable to re-register if this is done later by the client code. Added a fFlagsInit parameter to indicate whether this auto reg behaviour is required or not and renamed NS_InitXPCOM2 to NS_InitXPCOM2Ex (the latter to prevent confusion). bugref:10896 ticketref:22193

Location:
trunk/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxFB/VBoxFB.cpp

    r106061 r109067  
    153153#if 0
    154154        nsCOMPtr<nsIServiceManager> serviceManager;
    155         rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull);
     155        rc = NS_InitXPCOM2Ex(getter_AddRefs(serviceManager), nsnull, nsnull, NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS_WITH_STATUS);
    156156        if (NS_FAILED(rc))
    157157        {
     
    159159            exit(-1);
    160160        }
    161 
    162         // register our component
    163         nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager);
    164         if (!registrar)
    165         {
    166             printf("Error: could not query nsIComponentRegistrar interface!\n");
    167             exit(-1);
    168         }
    169         registrar->AutoRegister(nsnull);
    170161
    171162        /*
  • trunk/src/VBox/Main/glue/initterm.cpp

    r107362 r109067  
    168168                                  nsIFile **aRetval)
    169169{
    170     nsCOMPtr <nsILocalFile> localFile;
    171     nsresult rv = NS_ERROR_FAILURE;
    172 
    173170    *aRetval = nsnull;
    174171    *aPersistent = PR_TRUE;
    175172
    176     const char *fileLocation = NULL;
    177 
     173    const char *fileLocation;
    178174    if (strcmp(aProp, NS_XPCOM_COMPONENT_REGISTRY_FILE) == 0)
    179175        fileLocation = mCompRegLocation;
     
    187183        return NS_ERROR_FAILURE;
    188184
    189     rv = NS_NewNativeLocalFile(nsEmbedCString(fileLocation),
    190                                PR_TRUE, getter_AddRefs(localFile));
     185    nsCOMPtr<nsILocalFile> localFile;
     186    nsresult rv = NS_NewNativeLocalFile(nsEmbedCString(fileLocation),
     187                                        PR_TRUE, getter_AddRefs(localFile));
    191188    if (NS_FAILED(rv))
    192189        return rv;
     
    705702            break;
    706703
    707         /* Setup the application path for NS_InitXPCOM2. Note that we properly
     704        /* Setup the application path for NS_InitXPCOM2Ex. Note that we properly
    708705         * answer the NS_XPCOM_CURRENT_PROCESS_DIR query in our directory
    709706         * service provider but it seems to be activated after the directory
    710          * service is used for the first time (see the source NS_InitXPCOM2). So
     707         * service is used for the first time (see the source NS_InitXPCOM2Ex). So
    711708         * use the same value here to be on the safe side. */
    712709        nsCOMPtr <nsIFile> appDir;
     
    737734        {
    738735            nsCOMPtr<nsIServiceManager> serviceManager;
    739             hrc = NS_InitXPCOM2(getter_AddRefs(serviceManager), appDir, dsProv);
     736            hrc = NS_InitXPCOM2Ex(getter_AddRefs(serviceManager), appDir, dsProv,
     737                                  NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS_WITH_STATUS);
    740738            if (NS_SUCCEEDED(hrc))
    741739            {
    742                 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager, &hrc);
    743                 if (NS_SUCCEEDED(hrc))
    744                 {
    745                     hrc = registrar->AutoRegister(nsnull);
    746                     if (NS_SUCCEEDED(hrc))
    747                     {
    748                         /* We succeeded, stop probing paths */
    749                         LogFlowFunc(("Succeeded.\n"));
    750                         break;
    751                     }
    752                 }
     740                /* We succeeded, stop probing paths */
     741                LogFlowFunc(("Succeeded.\n"));
     742                break;
    753743            }
    754744        }
  • trunk/src/VBox/Main/testcase/tstVBoxAPIXPCOM.cpp

    r108825 r109067  
    515515    {
    516516        nsCOMPtr<nsIServiceManager> serviceManager;
    517         rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull);
     517        rc = NS_InitXPCOM2Ex(getter_AddRefs(serviceManager), nsnull, nsnull, 0);
    518518        if (NS_FAILED(rc))
    519519        {
     
    521521            return -1;
    522522        }
    523 
    524 #if 0
    525         /*
    526          * Register our components. This step is only necessary if this executable
    527          * implements XPCOM components itself which is not the case for this
    528          * simple example.
    529          */
    530         nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager);
    531         if (!registrar)
    532         {
    533             printf("Error: could not query nsIComponentRegistrar interface!\n");
    534             return -1;
    535         }
    536         registrar->AutoRegister(nsnull);
    537 #endif
    538523
    539524        /*
  • trunk/src/libs/xpcom18a4/VBoxXPCOM.def

    r106061 r109067  
    9393    NS_GetTraceRefcnt
    9494    NS_IsXPCOMInitialized
    95     NS_InitXPCOM2
     95    NS_InitXPCOM2Ex
    9696    NS_MeanAndStdDev
    9797    NS_NewByteInputStream
  • trunk/src/libs/xpcom18a4/ipc/ipcd/test/TestIPC.cpp

    r1 r109067  
    196196    {
    197197        nsCOMPtr<nsIServiceManager> servMan;
    198         NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
     198        NS_InitXPCOM2Ex(getter_AddRefs(servMan), nsnull, nsnull, 0);
    199199        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
    200200        NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
  • trunk/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp

    r107722 r109067  
    212212  // init XPCOM
    213213  nsCOMPtr<nsIServiceManager> servMan;
    214   rv = NS_InitXPCOM2(getter_AddRefs(servMan), directory, provider);
     214  rv = NS_InitXPCOM2Ex(getter_AddRefs(servMan), directory, provider, 0);
    215215  NS_ENSURE_SUCCESS(rv, rv);
    216216
    217   // create Java proxy for service manager returned by NS_InitXPCOM2
     217  // create Java proxy for service manager returned by NS_InitXPCOM2Ex
    218218  return NativeInterfaceToJavaObject(env, servMan, NS_GET_IID(nsIServiceManager),
    219219                                     nsnull, aResult);
  • trunk/src/libs/xpcom18a4/python/src/dllmain.cpp

    r103176 r109067  
    181181                        // not already initialized.
    182182                        // Elsewhere, Mozilla can find it itself (we hope!)
    183                         nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     183                        nsresult rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    184184                        if (NS_FAILED(rv)) {
    185185                                PyErr_SetString(PyExc_RuntimeError, "The XPCOM subsystem could not be initialized");
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h

    r106112 r109067  
    4848#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
    4949#define NS_IsXPCOMInitialized VBoxNsxpNS_IsXPCOMInitialized
    50 #define NS_InitXPCOM2 VBoxNsxpNS_InitXPCOM2
     50#define NS_InitXPCOM2Ex VBoxNsxpNS_InitXPCOM2Ex
    5151#define NS_ShutdownXPCOM VBoxNsxpNS_ShutdownXPCOM
    5252#define NS_NewNativeLocalFile VBoxNsxpNS_NewNativeLocalFile
     
    7676
    7777/**
    78  * Checks whether XPCOM was initialized by a call to NS_InitXPCOM2().
     78 * Checks whether XPCOM was initialized by a call to NS_InitXPCOM2Ex().
    7979 */
    8080extern "C" NS_COM PRBool
     
    109109 *                         <CODE>nsnull</CODE> for the default behaviour.
    110110 *
     111 * @param fInitFlags       NS_INIT_XPCOM_F_XXX values ORed together or zero.
     112 *                         This was added during @bugref{10896} to workaround
     113 *                         the problem that the IPC client component was already
     114 *                         in use by the time NS_InitXPCOM2Ex returns and thus
     115 *                         cannot be auto-re-registered by the client.
     116 *                         (The actual need to trigger auto-reregistration of
     117 *                         components is questionable, though, as it ought only
     118 *                         to be needed after installing a new version,
     119 *                         but we've always done it as part of our COM init glue
     120 *                         code (see Main/glue/initterm.cpp).)
     121 *
    111122 * @see NS_NewLocalFile
    112123 * @see nsILocalFile
     
    120131 */
    121132extern "C" NS_COM nsresult
    122 NS_InitXPCOM2(nsIServiceManager* *result,
    123               nsIFile* binDirectory,
    124               nsIDirectoryServiceProvider* appFileLocationProvider);
     133NS_InitXPCOM2Ex(nsIServiceManager* *result,
     134                nsIFile* binDirectory,
     135                nsIDirectoryServiceProvider* appFileLocationProvider,
     136                PRUint32 fFlags);
     137
     138/** @name NS_INIT_XPCOM_F_XXX - Flags for NS_InitXPCOM2Ex.
     139 * @{ */
     140/** Auto-register components. */
     141#define NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS                1
     142/** Auto-register components and return any failure status.
     143 * @note When using this, always call NS_ShutdownXPCOM(nsnull) on failure
     144 *       (generally a good idea). */
     145#define NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS_WITH_STATUS    2
     146/** @} */
     147
    125148/**
    126149 * Shutdown XPCOM. You must call this method after you are finished
     
    129152 * @status FROZEN
    130153 *
    131  * @param servMgr           The service manager which was returned by NS_InitXPCOM2. 
    132  *                          This will release servMgr.  You may pass null.
     154 * @param servMgr           The service manager which was returned by
     155 *                          NS_InitXPCOM2Ex. This will release servMgr.
     156 *                          You may pass null.
    133157 *
    134158 * @return NS_OK for success;
     
    181205/**
    182206 * Public Method to create an instance of a nsILocalFile.  This function
    183  * may be called prior to NS_InitXPCOM2
     207 * may be called prior to NS_InitXPCOM2Ex.
    184208 *
    185209 * @status FROZEN
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp

    r109065 r109067  
    380380}
    381381
    382 nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
    383                               nsIFile* binDirectory,
    384                               nsIDirectoryServiceProvider* appFileLocationProvider)
     382nsresult NS_COM NS_InitXPCOM2Ex(nsIServiceManager* *result,
     383                                nsIFile* binDirectory,
     384                                nsIDirectoryServiceProvider* appFileLocationProvider,
     385                                PRUint32 fInitFlags)
    385386{
    386387    nsresult rv = NS_OK;
     
    388389    /* Make sure IPRT is initialized. */
    389390    RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
    390     LogFlow(("NS_InitXPCOM2: done RTR3InitDll\n"));
     391    LogFlow(("NS_InitXPCOM2Ex(,%p,%p,%#x): done RTR3InitDll\n", binDirectory, appFileLocationProvider, fInitFlags));
    391392
    392393     // We are not shutting down
     
    438439        nsCOMPtr<nsIFile> xpcomLib;
    439440
    440         PRBool value;
    441441        if (binDirectory)
    442442        {
     443            PRBool value = PR_FALSE;
    443444            rv = binDirectory->IsDirectory(&value);
    444 
    445445            if (NS_SUCCEEDED(rv) && value) {
    446446                gDirectoryService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
     
    448448            }
    449449        }
    450         else {
     450        else
    451451            gDirectoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
    452452                                   NS_GET_IID(nsIFile),
    453453                                   getter_AddRefs(xpcomLib));
    454         }
    455454
    456455        if (xpcomLib) {
     
    524523#endif
    525524
    526     if ( NS_FAILED(rv) || CheckUpdateFile()) {
    527         LogFlow(("NS_InitXPCOM2: rv=%#x or CheckUpdateFile()=>true\n", rv));
     525    PRBool fCheckUpdateFile = PR_FALSE;
     526    if (   NS_FAILED(rv)
     527        || (fInitFlags & (NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS | NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS_WITH_STATUS))
     528        || (fCheckUpdateFile = CheckUpdateFile())) {
     529        LogFlow(("NS_InitXPCOM2Ex: rv=%#x fInitFlags=%#x CheckUpdateFile()=%d --> auto (re-)registering components\n",
     530                 rv, fInitFlags, fCheckUpdateFile)); RT_NOREF_PV(fCheckUpdateFile);
    528531
    529532        // if we find no persistent registry, we will try to autoregister
    530533        // the default components directory.
    531         nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
     534        rv = nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
     535        if (NS_FAILED(rv) && (fInitFlags & NS_INIT_XPCOM_F_AUTO_REGISTER_COMPONENTS_WITH_STATUS)) {
     536            NS_ERROR("gComponentManager->AutoRegister failed!");
     537            return rv;
     538        }
    532539
    533540        // If the application is using a GRE, then,
     
    631638
    632639    // Notify observers of xpcom autoregistration start
    633     LogFlow(("NS_InitXPCOM2: Notifying startup observers (autoreg)\n"));
     640    LogFlow(("NS_InitXPCOM2Ex: Notifying startup observers\n"));
    634641    NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_OBSERVER_ID,
    635642                                  nsnull,
     
    639646    gXPCOMInitialized = PR_TRUE;
    640647#endif
    641     LogFlow(("NS_InitXPCOM2: return NS_OK\n"));
     648    LogFlow(("NS_InitXPCOM2Ex: return NS_OK\n"));
    642649    return NS_OK;
    643650}
  • trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.cpp

    r109066 r109067  
    35783578    {
    35793579        // XPCOM needs initialization.
    3580         rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     3580        rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    35813581    }
    35823582
     
    35983598    {
    35993599        // XPCOM needs initialization.
    3600         nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     3600        nsresult rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    36013601        if (NS_FAILED(rv))
    36023602            return rv;
     
    36293629#else /* !VBOX */
    36303630        // XPCOM needs initialization.
    3631         rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     3631        rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    36323632#endif /* !VBOX */
    36333633    }
     
    36513651    {
    36523652        // XPCOM needs initialization.
    3653         rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     3653        rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    36543654    }
    36553655
     
    36743674    {
    36753675        // XPCOM needs initialization.
    3676         rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
     3676        rv = NS_InitXPCOM2Ex(nsnull, nsnull, nsnull, 0);
    36773677    }
    36783678
  • trunk/src/libs/xpcom18a4/xpcom/io/nsDirectoryServiceDefs.h

    r1 r109067  
    6767/* This location is similar to NS_OS_CURRENT_PROCESS_DIR, however,
    6868 * NS_XPCOM_CURRENT_PROCESS_DIR can be overriden by passing a "bin
    69  * directory" to NS_InitXPCOM2().
     69 * directory" to NS_InitXPCOM2Ex().
    7070 */
    7171#define NS_XPCOM_CURRENT_PROCESS_DIR            "XCurProcD"
  • trunk/src/libs/xpcom18a4/xpcom/tests/TestFactory.cpp

    r1 r109067  
    116116  {
    117117    nsCOMPtr<nsIServiceManager> servMan;
    118     rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
     118    rv = NS_InitXPCOM2Ex(getter_AddRefs(servMan), nsnull, nsnull, 0);
    119119    if (NS_FAILED(rv)) return -1;
    120120    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
  • trunk/src/libs/xpcom18a4/xpcom/tests/nsIFileTest.cpp

    r103458 r109067  
    352352{
    353353    nsCOMPtr<nsIServiceManager> servMan;
    354     NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
     354    NS_InitXPCOM2Ex(getter_AddRefs(servMan), nsnull, nsnull, 0);
    355355    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
    356356    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette