Пример #1
0
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
  : mMutex("mozilla::MediaEngineWebRTC"),
    mVoiceEngine(nullptr),
    mAudioInput(nullptr),
    mFullDuplex(aPrefs.mFullDuplex),
    mExtendedFilter(aPrefs.mExtendedFilter),
    mDelayAgnostic(aPrefs.mDelayAgnostic),
    mHasTabVideoSource(false)
{
#ifndef MOZ_B2G_CAMERA
  nsCOMPtr<nsIComponentRegistrar> compMgr;
  NS_GetComponentRegistrar(getter_AddRefs(compMgr));
  if (compMgr) {
    compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
  }
#else
#ifdef MOZ_WIDGET_GONK
  AsyncLatencyLogger::Get()->AddRef();
#endif
#endif
  // XXX
  gFarendObserver = new AudioOutputObserver();

  camera::GetChildAndCall(
    &camera::CamerasChild::AddDeviceChangeCallback,
    this);
}
Пример #2
0
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
    : mMutex("mozilla::MediaEngineWebRTC")
    , mScreenEngine(nullptr)
    , mBrowserEngine(nullptr)
    , mWinEngine(nullptr)
    , mAppEngine(nullptr)
    , mVideoEngine(nullptr)
    , mVoiceEngine(nullptr)
    , mVideoEngineInit(false)
    , mAudioEngineInit(false)
    , mScreenEngineInit(false)
    , mBrowserEngineInit(false)
    , mAppEngineInit(false)
{
#ifndef MOZ_B2G_CAMERA
  nsCOMPtr<nsIComponentRegistrar> compMgr;
  NS_GetComponentRegistrar(getter_AddRefs(compMgr));
  if (compMgr) {
    compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
  }
#else
  AsyncLatencyLogger::Get()->AddRef();
#endif
  // XXX
  gFarendObserver = new AudioOutputObserver();

  NS_NewNamedThread("AudioGUM", getter_AddRefs(mThread));
  MOZ_ASSERT(mThread);
}
nsresult
nsGlobalHistory2Adapter::Init()
{
  nsresult rv;

  nsCOMPtr<nsIComponentRegistrar> compReg;
  rv = NS_GetComponentRegistrar(getter_AddRefs(compReg));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCID *cid;
  rv = compReg->ContractIDToCID(NS_GLOBALHISTORY2_CONTRACTID, &cid);
  if (NS_FAILED(rv)) {
    rv = NS_ERROR_FACTORY_NOT_REGISTERED;
    return rv;
  }

  if (cid->Equals(nsGlobalHistoryAdapter::GetCID())) {
    rv = NS_ERROR_FACTORY_NOT_REGISTERED;
    return rv;
  }

  NS_WARNING("Using nsIGlobalHistory->nsIGlobalHistory2 adapter.");
  mHistory = do_GetService(NS_GLOBALHISTORY2_CONTRACTID, &rv);
  return rv;
}
/////////////////////////////////////////////////////
// nsIStreamConverterService methods
NS_IMETHODIMP
nsStreamConverterService::CanConvert(const char* aFromType,
                                     const char* aToType,
                                     bool* _retval) {
    nsCOMPtr<nsIComponentRegistrar> reg;
    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(reg));
    if (NS_FAILED(rv))
        return rv;

    nsAutoCString contractID;
    contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from=");
    contractID.Append(aFromType);
    contractID.AppendLiteral("&to=");
    contractID.Append(aToType);

    // See if we have a direct match
    rv = reg->IsContractIDRegistered(contractID.get(), _retval);
    if (NS_FAILED(rv))
        return rv;
    if (*_retval)
        return NS_OK;

    // Otherwise try the graph.
    rv = BuildGraph();
    if (NS_FAILED(rv))
        return rv;

    nsTArray<nsCString> *converterChain = nullptr;
    rv = FindConverter(contractID.get(), &converterChain);
    *_retval = NS_SUCCEEDED(rv);

    delete converterChain;
    return NS_OK;
}
Пример #5
0
//static
nsJSCID*
nsJSCID::NewID(const char* str)
{
    if (!str) {
        NS_ERROR("no string");
        return nsnull;
    }

    nsJSCID* idObj = new nsJSCID();
    if (idObj) {
        bool success = false;
        NS_ADDREF(idObj);

        if (str[0] == '{') {
            if (NS_SUCCEEDED(idObj->Initialize(str)))
                success = true;
        } else {
            nsCOMPtr<nsIComponentRegistrar> registrar;
            NS_GetComponentRegistrar(getter_AddRefs(registrar));
            if (registrar) {
                nsCID *cid;
                if (NS_SUCCEEDED(registrar->ContractIDToCID(str, &cid))) {
                    success = idObj->mDetails.InitWithName(*cid, str);
                    nsMemory::Free(cid);
                }
            }
        }
        if (!success)
            NS_RELEASE(idObj);
    }
    return idObj;
}
Пример #6
0
// Initialization
nsresult BrowserWindow::RegisterComponents ()
{
	PRINT("BrowserWindow::RegisterComponents\n");
	nsCOMPtr<nsIComponentRegistrar> compReg;
	nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(compReg));
	NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFactory> componentFactory;
    rv = NS_NewSecurityWarningServiceFactory(getter_AddRefs(componentFactory));
    if (NS_SUCCEEDED(rv)) {
		compReg->RegisterFactory(kSECURITYWARNINGSDIALOGS_CID,
                                 SECURITYWARNINGSDIALOGS_CLASSNAME,
                                 NS_SECURITYWARNINGDIALOGS_CONTRACTID,
                                 componentFactory);
	}

    rv = NS_NewPromptServiceFactory(getter_AddRefs(componentFactory), this);
    if (NS_SUCCEEDED(rv)) {
        compReg->RegisterFactory(kPROMPTSERVICE_CID,
                                 PROMPTSERVICE_CLASSNAME,
                                 NS_PROMPTSERVICE_CONTRACTID,
                                 componentFactory);
	}

	return NS_OK;
}
Пример #7
0
/* static */
nsresult
EmbedPrivate::RegisterAppComponents(void)
{
  nsCOMPtr<nsIComponentRegistrar> cr;
  nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIComponentManager> cm;
  rv = NS_GetComponentManager (getter_AddRefs (cm));
  NS_ENSURE_SUCCESS (rv, rv);

  for (int i = 0; i < sNumAppComps; ++i) {
    nsCOMPtr<nsIGenericFactory> componentFactory;
    rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
                              &(sAppComps[i]));
    if (NS_FAILED(rv)) {
      NS_WARNING("Unable to create factory for component");
      continue;  // don't abort registering other components
    }

    rv = cr->RegisterFactory(sAppComps[i].mCID, sAppComps[i].mDescription,
                             sAppComps[i].mContractID, componentFactory);
    NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component");

    // Call the registration hook of the component, if any
    if (sAppComps[i].mRegisterSelfProc) {
      rv = sAppComps[i].mRegisterSelfProc(cm, nsnull, nsnull, nsnull,
                                          &(sAppComps[i]));
      NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to self-register component");
    }
  }

  return rv;
}
bool RegisterProtocol(const wxString &scheme, wxProtocolHandler *handler) {
    nsresult res;
    ns_smartptr<nsIComponentRegistrar> comp_reg;
    ns_smartptr<nsIServiceManager> service_mgr;
    ns_smartptr<nsIFactory> protocol_handler_factory;

    res = NS_GetComponentRegistrar(&comp_reg.p);
    if (NS_FAILED(res))
        return false;

    // XXX: Memory leak?
    wxString *contractID = new wxString(wxT(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX) + scheme);
    wxString *className = new wxString(wxT("WebConnect Protocol - ") + scheme);
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return false;
    
    ns_smartptr<nsIUUIDGenerator> uuid_generator(nsCreateInstance("@mozilla.org/uuid-generator;1"));
    // Generate a new UUID.
    nsCID *protocol_cid;
    res = uuid_generator->GenerateUUID(&protocol_cid);
    if (NS_FAILED(res))
        return false;

    // Create a factory.
    CreateProtocolHandlerFactory(scheme, handler, &protocol_handler_factory.p);
    res = comp_reg->RegisterFactory(*protocol_cid,
                                    className->ToAscii(),
                                    contractID->ToAscii(),
                                    protocol_handler_factory);

    return true;
}
Пример #9
0
MediaEngineWebRTC::MediaEngineWebRTC()
  : mMutex("mozilla::MediaEngineWebRTC")
  , mVideoEngine(nullptr)
  , mVoiceEngine(nullptr)
  , mVideoEngineInit(false)
  , mAudioEngineInit(false)
  , mHasTabVideoSource(false)
{
  nsCOMPtr<nsIComponentRegistrar> compMgr;
  NS_GetComponentRegistrar(getter_AddRefs(compMgr));
  if (compMgr) {
    compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
  }
}
Пример #10
0
JSObject* GetComponentObject(JSContext* cx) {
  nsCOMPtr<nsISupports> abp = do_CreateInstance(ADBLOCKPLUS_CONTRACTID);
  if (abp == nsnull) {
    // Maybe the component isn't registered yet? Try registering it.
    nsresult rv;

    nsCOMPtr<nsIComponentRegistrar> compReg;
    rv = NS_GetComponentRegistrar(getter_AddRefs(compReg));
    if (NS_FAILED(rv) || compReg == nsnull) {
      JS_ReportError(cx, "Adblock Plus: Failed to retrieve component registrar - wrong Gecko version?");
      return nsnull;
    }

    nsCOMPtr<nsIProperties> dirService = do_GetService("@mozilla.org/file/directory_service;1");
    if (dirService == nsnull) {
      JS_ReportError(cx, "Adblock Plus: Failed to retrieve directory service - wrong Gecko version?");
      return nsnull;
    }

    nsCOMPtr<nsILocalFile> compFile;
    rv = dirService->Get(NS_XPCOM_COMPONENT_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(compFile));
    if (NS_FAILED(rv)) {
      JS_ReportError(cx, "Adblock Plus: Failed to retrieve components directory");
      return nsnull;
    }

    compFile->AppendRelativePath(NS_LITERAL_STRING("AdblockPlus.js"));
    rv = compReg->AutoRegister(compFile);
    if (NS_FAILED(rv)) {
      JS_ReportError(cx, "Adblock Plus: Failed to register AdblockPlus.js");
      return nsnull;
    }

    abp = do_CreateInstance(ADBLOCKPLUS_CONTRACTID);
  }
  if (abp == nsnull) {
    JS_ReportError(cx, "Adblock Plus: Failed to retrieve Adblock Plus component");
    return nsnull;
  }

  JSObject* jsObject = UnwrapJSObject(abp);
  if (jsObject == nsnull) {
    JS_ReportError(cx, "Adblock Plus: Failed extracting JavaScript object from Adblock Plus component");
    return nsnull;
  }

  return jsObject;
}
Пример #11
0
extern "C" NS_EXPORT nsresult
JSJ_RegisterLiveConnectFactory()
{
    nsCOMPtr<nsIComponentRegistrar> registrar;
    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
    if (NS_FAILED(rv))
        return rv;
      
    nsCOMPtr<nsIFactory> factory = new nsCLiveconnectFactory;
    if (factory) {
        return registrar->RegisterFactory(kCLiveconnectCID, "LiveConnect",
                                          "@mozilla.org/liveconnect/liveconnect;1",
                                          factory);
    }
    return NS_ERROR_OUT_OF_MEMORY;
}
int Init_nsUnknownContentTypeHandler_Factory( ) {
	nsresult rv;

	// create a generic factory for UnkHandler
	nsCOMPtr<nsIGenericFactory> factory;
	rv = NS_NewGenericFactory( getter_AddRefs(factory), info );
	if (NS_FAILED(rv))
		return rv;

	// register this factory with the component registrar.
	nsCOMPtr<nsIComponentRegistrar> registrar;
	rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
	if (NS_FAILED(rv))
		return rv;
	rv = registrar->RegisterFactory( kCID, "nsUnknownContentTypeHandler", NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, factory);
	return NS_OK;
	}
Пример #13
0
extern "C" NS_EXPORT jobject JNICALL
XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject)
{
  // Call XPCOM method
  nsCOMPtr<nsIComponentRegistrar> cr;
  nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));

  if (NS_SUCCEEDED(rv)) {
    jobject javaProxy;
    rv = NativeInterfaceToJavaObject(env, cr, NS_GET_IID(nsIComponentRegistrar),
                                     nullptr, &javaProxy);
    if (NS_SUCCEEDED(rv))
      return javaProxy;
  }

  ThrowException(env, rv, "Failure in getComponentRegistrar");
  return nullptr;
}
Пример #14
0
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
  : mMutex("mozilla::MediaEngineWebRTC")
  , mVideoEngine(nullptr)
  , mVoiceEngine(nullptr)
  , mVideoEngineInit(false)
  , mAudioEngineInit(false)
  , mHasTabVideoSource(false)
{
#ifndef MOZ_B2G_CAMERA
  nsCOMPtr<nsIComponentRegistrar> compMgr;
  NS_GetComponentRegistrar(getter_AddRefs(compMgr));
  if (compMgr) {
    compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
  }
#else
  AsyncLatencyLogger::Get()->AddRef();
#endif
  if (aPrefs.mLoadAdapt) {
      mLoadMonitor = new LoadMonitor();
      mLoadMonitor->Init(mLoadMonitor);
  }
}
bool TestContractFirst()
{
  nsCOMPtr<nsIComponentRegistrar> r;
  NS_GetComponentRegistrar(getter_AddRefs(r));

  nsCID* cid = NULL;
  nsresult rv = r->ContractIDToCID("@mozilla.org/RegTestOrderC;1", &cid);
  if (NS_FAILED(rv)) {
    fail("RegTestOrderC: contract not registered");
    return false;
  }

  nsCID goodcid;
  goodcid.Parse("{ada15884-bb89-473c-8b50-dcfbb8447ff4}");

  if (!goodcid.Equals(*cid)) {
    fail("RegTestOrderC: CID doesn't match");
    return false;
  }

  passed("RegTestOrderC");
  return true;
}
nsresult
nsScriptNameSpaceManager::FillHash(nsICategoryManager *aCategoryManager,
                                   const char *aCategory,
                                   nsGlobalNameStruct::nametype aType,
                                   PRBool aPrivilegedOnly)
{
  nsCOMPtr<nsIComponentRegistrar> registrar;
  nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISimpleEnumerator> e;
  rv = aCategoryManager->EnumerateCategory(aCategory, getter_AddRefs(e));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString categoryEntry;
  nsXPIDLCString contractId;
  nsCOMPtr<nsISupports> entry;

  while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) {
    nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));

    if (!category) {
      NS_WARNING("Category entry not an nsISupportsCString!");

      continue;
    }

    rv = category->GetData(categoryEntry);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = aCategoryManager->GetCategoryEntry(aCategory, categoryEntry.get(),
                                            getter_Copies(contractId));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCID *cidPtr;
    rv = registrar->ContractIDToCID(contractId, &cidPtr);

    if (NS_FAILED(rv)) {
      NS_WARNING("Bad contract id registed with the script namespace manager");

      continue;
    }

    // Copy CID onto the stack, so we can free it right away and avoid having
    // to add cleanup code at every exit point from this loop/function.
    nsCID cid = *cidPtr;
    nsMemory::Free(cidPtr);

    if (aType == nsGlobalNameStruct::eTypeExternalConstructor) {
      nsXPIDLCString constructorProto;
      rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
                                              categoryEntry.get(),
                                              getter_Copies(constructorProto));
      if (NS_SUCCEEDED(rv)) {
        nsGlobalNameStruct *s = AddToHash(categoryEntry.get());
        NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

        if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
          s->mAlias = new nsGlobalNameStruct::ConstructorAlias;
          if (!s->mAlias) {
            // Free entry
            NS_ConvertASCIItoUTF16 key(categoryEntry);
            PL_DHashTableOperate(&mGlobalNames,
                                 &key,
                                 PL_DHASH_REMOVE);
            return NS_ERROR_OUT_OF_MEMORY;
          }
          s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias;
          s->mPrivilegedOnly = PR_FALSE;
          s->mAlias->mCID = cid;
          AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName);
          s->mAlias->mProto = nsnull;
        } else {
          NS_WARNING("Global script name not overwritten!");
        }

        continue;
      }
    }

    nsGlobalNameStruct *s = AddToHash(categoryEntry.get());
    NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

    if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
      s->mType = aType;
      s->mCID = cid;
      s->mPrivilegedOnly = aPrivilegedOnly;
    } else {
      NS_WARNING("Global script name not overwritten!");
    }
  }

  return NS_OK;
}
JNIEXPORT void JNICALL 
Java_org_mozilla_webclient_impl_wrapper_1native_WrapperFactoryImpl_nativeAppSetup
(JNIEnv *env, jobject obj, jint nativeContext)
{
    PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, 
           ("WrapperFactoryImpl_nativeAppSetup: entering\n"));
    nsresult rv;
    NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
    
    PR_ASSERT(wcContext);

    nsCOMPtr<nsIComponentRegistrar> cr;
    rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
    if (NS_FAILED(rv)) {
        ::util_ThrowExceptionToJava(env, 
                                    "Failed to create Component Registrar");
        return;
    }

    // appshell
    // XXX startup appshell service?
    // XXX create offscreen window for appshell service?
    // XXX remove X prop from offscreen window?
    
    nsCOMPtr<nsIAppShell> appShell;
    appShell = do_CreateInstance(kAppShellCID);
    if (!appShell) {
        ::util_ThrowExceptionToJava(env, 
                                    "Failed to create AppShell");
        return;
    }
    wcContext->sAppShell = appShell.get();
    NS_ADDREF(wcContext->sAppShell);

    rv = wcContext->sAppShell->Create(0, nsnull);
    PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, 
           ("WrapperFactoryImpl_nativeAppSetup: AppShell create rv: %d\n",
            rv));

    if (NS_FAILED(rv)) {
        ::util_ThrowExceptionToJava(env, 
                                    "Failed to create AppShell");
        return;
    }
    rv = wcContext->sAppShell->Spinup();
    PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, 
           ("WrapperFactoryImpl_nativeAppSetup: AppShell spinup rv: %d\n",
            rv));
    if (NS_FAILED(rv)) {
        ::util_ThrowExceptionToJava(env, 
                                    "Failed to Spinup AppShell");
        return;
    }

    nsCOMPtr<nsIIOService> ioService = do_GetService(kIOServiceCID, &rv);
    
    if (NS_FAILED(rv)) {
        ::util_ThrowExceptionToJava(env, "Can't get IOService.");
        return;
    }
    rv = ioService->SetOffline(PR_FALSE);
    if (NS_FAILED(rv)) {
        ::util_ThrowExceptionToJava(env, "Can't get IOService.");
        return;
    }

    PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, 
           ("WrapperFactoryImpl_nativeAppSetup: exiting\n"));

}
Пример #18
0
static BOOL load_gecko(void)
{
    nsresult nsres;
    nsIObserver *pStartNotif;
    nsIComponentRegistrar *registrar = NULL;
    nsAString path;
    nsIFile *gre_dir;
    PRUnichar gre_path[MAX_PATH];

    static BOOL tried_load = FALSE;

    TRACE("()\n");

    if(tried_load)
        return pCompMgr != NULL;
    tried_load = TRUE;

    if(!load_wine_gecko(gre_path) && !load_mozctl(gre_path) && !load_mozilla(gre_path)) {
        install_wine_gecko();
        if(!load_wine_gecko(gre_path)) {
            MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
            return FALSE;
        }
    }

    NS_StringContainerInit(&path);
    NS_StringSetData(&path, gre_path, PR_UINT32_MAX);
    nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
    NS_StringContainerFinish(&path);
    if(NS_FAILED(nsres)) {
        ERR("NS_NewLocalFile failed: %08lx\n", nsres);
        FreeLibrary(hXPCOM);
        return FALSE;
    }

    nsres = NS_InitXPCOM2(&pServMgr, gre_dir, NULL);
    if(NS_FAILED(nsres)) {
        ERR("NS_InitXPCOM2 failed: %08lx\n", nsres);
        FreeLibrary(hXPCOM);
        return FALSE;
    }

    nsres = nsIServiceManager_QueryInterface(pServMgr, &IID_nsIComponentManager, (void**)&pCompMgr);
    if(NS_FAILED(nsres))
        ERR("Could not get nsIComponentManager: %08lx\n", nsres);

    nsres = NS_GetComponentRegistrar(&registrar);
    if(NS_SUCCEEDED(nsres)) {
        nsres = nsIComponentRegistrar_AutoRegister(registrar, NULL);
        if(NS_FAILED(nsres))
            ERR("AutoRegister(NULL) failed: %08lx\n", nsres);

        nsres = nsIComponentRegistrar_AutoRegister(registrar, gre_dir);
        if(NS_FAILED(nsres))
            ERR("AutoRegister(gre_dir) failed: %08lx\n", nsres);

        init_nsio(pCompMgr, registrar);
    }else {
        ERR("NS_GetComponentRegistrar failed: %08lx\n", nsres);
    }

    nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_APPSTARTUPNOTIFIER_CONTRACTID,
            NULL, &IID_nsIObserver, (void**)&pStartNotif);
    if(NS_SUCCEEDED(nsres)) {
        nsres = nsIObserver_Observe(pStartNotif, NULL, APPSTARTUP_TOPIC, NULL);
        if(NS_FAILED(nsres))
            ERR("Observe failed: %08lx\n", nsres);

        nsIObserver_Release(pStartNotif);
    }else {
        ERR("could not get appstartup-notifier: %08lx\n", nsres);
    }

    set_profile();

    nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_MEMORY_CONTRACTID,
            NULL, &IID_nsIMemory, (void**)&nsmem);
    if(NS_FAILED(nsres))
        ERR("Could not get nsIMemory: %08lx\n", nsres);

    if(registrar) {
        register_nsservice(registrar, pServMgr);
        nsIComponentRegistrar_Release(registrar);
    }

    return TRUE;
}
Пример #19
0
void RegisterAdditionalComponents(){
	//Gecko 1.9
	nsCOMPtr<nsIComponentRegistrar> cr;
	nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
	if(NS_FAILED(rv)) return;

    nsCOMPtr<nsIFactory> psfactory;

    CPromptServiceFactory* p = new CPromptServiceFactory();
	if(!p) return;

    NS_ADDREF(p);
	psfactory = p;

    nsCID cid = NS_PROMPTSERVICE_CID;
    rv = cr->RegisterFactory(cid,
		                     "Prompt Service",
                             "@mozilla.org/embedcomp/prompt-service;1",
                             psfactory);

    nsCOMPtr<nsIFactory> ppsfactory;

    CPrintingPromptServiceFactory* p2 = new CPrintingPromptServiceFactory();
	if(!p2) return;

    NS_ADDREF(p2);
	ppsfactory = p2;

    nsCID cid2 = NS_PRINTINGPROMPTSERVICE_CID;
    rv = cr->RegisterFactory(cid2,
		                     "Printing Prompt Service",
							 "@mozilla.org/embedcomp/printingprompt-service;1",
                             ppsfactory);

    nsCOMPtr<nsIFactory> dntfactory;

    DonutAPIFactory* p3 = new DonutAPIFactory();
	if(!p3) return;

    NS_ADDREF(p3);
	dntfactory = p3;

    nsCID cid3 = DONUTAPI_CID;
    rv = cr->RegisterFactory(cid3,
		                     "Donut XPCOM API Service",
							 "@tnose.net/donut/api-service;1",
                             dntfactory);

    nsCOMPtr<nsIFactory> hlpfactory;

	NS_NewHelperAppLauncherDlgFactory(getter_AddRefs(hlpfactory));
	if(!hlpfactory) return;

	nsCID cid4 = NS_HELPERAPPLAUNCHERDIALOG_CID; 
	rv = cr->RegisterFactory(cid4,
		                     "Helper App Launcher Dialog",
							 "@mozilla.org/helperapplauncherdialog;1",
							 hlpfactory);
 
   //2.0 XRE_AddStaticComponent(&kDefaultPromptModule);
}
Пример #20
0
int
main(int argc, char **argv)
{
    int numberOfThreads = 1;

    if (argc > 1)
        numberOfThreads = atoi(argv[1]);

    NS_InitXPCOM2(nsnull, nsnull, nsnull);

    // Scope code so everything is destroyed before we run call NS_ShutdownXPCOM
    {
        nsCOMPtr<nsIComponentRegistrar> registrar;
        NS_GetComponentRegistrar(getter_AddRefs(registrar));
        registrar->AutoRegister(nsnull);

        RunApartmentTest();

        nsCOMPtr<nsIThread> eventLoopThread;
        NS_NewThread(getter_AddRefs(eventLoopThread));

        nsCOMPtr<nsIRunnable> test = new TestSyncProxyToSelf();
        eventLoopThread->Dispatch(test, NS_DISPATCH_NORMAL);

        PRThread *eventLoopPRThread;
        eventLoopThread->GetPRThread(&eventLoopPRThread);
        PR_ASSERT(eventLoopPRThread);
        
        LOG(("TEST: Spawn Threads:\n"));
        nsCOMArray<nsIThread> threads;
        for (PRInt32 spawn = 0; spawn < numberOfThreads; spawn++)
        {
            test = new ProxyTest(eventLoopPRThread, spawn);

            nsCOMPtr<nsIThread> thread;
            NS_NewThread(getter_AddRefs(thread), test);

            threads.AppendObject(thread);

            LOG(("TEST: \tThread (%d) spawned\n", spawn));

            PR_Sleep( PR_MillisecondsToInterval(250) );
        }

        LOG(("TEST: All Threads Spawned.\n"));
        
        LOG(("TEST: Wait for threads.\n"));
        for (PRInt32 i = 0; i < numberOfThreads; i++)
        {
            LOG(("TEST: Thread (%d) Join...\n", i));
            nsresult rv = threads[i]->Shutdown();
            LOG(("TEST: Thread (%d) Joined. (error: %x).\n", i, rv));
        }

        LOG(("TEST: Shutting down event loop thread\n"));
        eventLoopThread->Shutdown();
    }

    LOG(("TEST: Calling Cleanup.\n"));
    NS_ShutdownXPCOM(nsnull);

    LOG(("TEST: Return zero.\n"));
    return 0;
}
Пример #21
0
nsresult
nsScriptNameSpaceManager::AddCategoryEntryToHash(nsICategoryManager* aCategoryManager,
                                                 const char* aCategory,
                                                 nsISupports* aEntry)
{
  // Get the type from the category name.
  // NOTE: we could have passed the type in FillHash() and guessed it in
  // Observe() but this way, we have only one place to update and this is
  // not performance sensitive.
  nsGlobalNameStruct::nametype type;
  if (strcmp(aCategory, JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY) == 0) {
    type = nsGlobalNameStruct::eTypeExternalConstructor;
  } else if (strcmp(aCategory, JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY) == 0 ||
             strcmp(aCategory, JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY) == 0) {
    type = nsGlobalNameStruct::eTypeProperty;
  } else if (strcmp(aCategory, JAVASCRIPT_NAVIGATOR_PROPERTY_CATEGORY) == 0) {
    type = nsGlobalNameStruct::eTypeNavigatorProperty;
  } else if (strcmp(aCategory, JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY) == 0) {
    type = nsGlobalNameStruct::eTypeStaticNameSet;
  } else if (strcmp(aCategory, JAVASCRIPT_GLOBAL_DYNAMIC_NAMESET_CATEGORY) == 0) {
    type = nsGlobalNameStruct::eTypeDynamicNameSet;
  } else {
    return NS_OK;
  }

  nsCOMPtr<nsISupportsCString> strWrapper = do_QueryInterface(aEntry);

  if (!strWrapper) {
    NS_WARNING("Category entry not an nsISupportsCString!");
    return NS_OK;
  }

  nsCAutoString categoryEntry;
  nsresult rv = strWrapper->GetData(categoryEntry);
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLCString contractId;
  rv = aCategoryManager->GetCategoryEntry(aCategory, categoryEntry.get(),
                                          getter_Copies(contractId));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIComponentRegistrar> registrar;
  rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCID *cidPtr;
  rv = registrar->ContractIDToCID(contractId, &cidPtr);

  if (NS_FAILED(rv)) {
    NS_WARNING("Bad contract id registed with the script namespace manager");
    return NS_OK;
  }

  // Copy CID onto the stack, so we can free it right away and avoid having
  // to add cleanup code at every exit point from this function.
  nsCID cid = *cidPtr;
  nsMemory::Free(cidPtr);

  if (type == nsGlobalNameStruct::eTypeExternalConstructor) {
    nsXPIDLCString constructorProto;
    rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
                                            categoryEntry.get(),
                                            getter_Copies(constructorProto));
    if (NS_SUCCEEDED(rv)) {
      nsGlobalNameStruct *s = AddToHash(&mGlobalNames, categoryEntry.get());
      NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

      if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
        s->mAlias = new nsGlobalNameStruct::ConstructorAlias;
        s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias;
        s->mChromeOnly = false;
        s->mAlias->mCID = cid;
        AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName);
        s->mAlias->mProto = nsnull;
      } else {
        NS_WARNING("Global script name not overwritten!");
      }

      return NS_OK;
    }
  }

  PLDHashTable *table;
  if (type == nsGlobalNameStruct::eTypeNavigatorProperty) {
    table = &mNavigatorNames;
  } else {
    table = &mGlobalNames;
  }

  nsGlobalNameStruct *s = AddToHash(table, categoryEntry.get());
  NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

  if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
    s->mType = type;
    s->mCID = cid;
    s->mChromeOnly =
      strcmp(aCategory, JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY) == 0;
  } else {
    NS_WARNING("Global script name not overwritten!");
  }

  return NS_OK;
}