// This method gets called on application startup
NS_IMETHODIMP nsAccessProxy::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) 
{
  static PRBool accessProxyInstalled;

  nsresult rv = NS_OK;
  nsDependentCString aTopicString(aTopic);

  if (accessProxyInstalled && aTopicString.EqualsLiteral(NS_XPCOM_SHUTDOWN_OBSERVER_ID))
    return Release();

  if (!accessProxyInstalled && aTopicString.EqualsLiteral(APPSTARTUP_CATEGORY)) {
    accessProxyInstalled = PR_TRUE; // Set to TRUE even for failure cases - we don't want to try more than once
    nsCOMPtr<nsIWebProgress> progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID));
    rv = NS_ERROR_FAILURE;
    if (progress) {
      rv = progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
                                         nsIWebProgress::NOTIFY_STATE_DOCUMENT);
      if (NS_SUCCEEDED(rv))
        AddRef();
    }
     // install xpcom shutdown observer
    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
      if (NS_SUCCEEDED(rv)) 
        rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
    }
  }
  return rv;
}
nsresult
nsClientAuthRememberService::Init()
{
  if (!mSettingsTable.Init())
    return NS_ERROR_OUT_OF_MEMORY;

  nsCOMPtr<nsIProxyObjectManager> proxyman(do_GetService(NS_XPCOMPROXY_CONTRACTID));
  if (!proxyman)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1"));
  nsCOMPtr<nsIObserverService> proxiedObserver;

  NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                       NS_GET_IID(nsIObserverService),
                       observerService,
                       NS_PROXY_SYNC,
                       getter_AddRefs(proxiedObserver));

  if (proxiedObserver) {
    proxiedObserver->AddObserver(this, "profile-before-change", PR_TRUE);
  }

  return NS_OK;
}
Exemplo n.º 3
0
void CnsIObserServ::EnumerateObserversTest(int displayType)
{
	PRInt32 i=0;
	nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1",&rv));
	nsCOMPtr<nsISimpleEnumerator> simpleEnum;

	QAOutput("\n nsIObserverService::EnumerateObserversTest().");
	if (!observerService) 
	{
		QAOutput("Can't get nsIObserverService object. Tests fail.");
		return;
	}

	for (i=0; i<10; i++)
	{
		// need to handle Simple Enumerator

		rv = observerService->EnumerateObservers(ObserverTable[i].theTopic, 
												 getter_AddRefs(simpleEnum));

		RvTestResult(rv, "EnumerateObserversTest() test", displayType);
		RvTestResultDlg(rv, "EnumerateObserversTest() test");
		if (!simpleEnum)
		{
			QAOutput("Didn't get SimpleEnumerator object. Tests fail.");
			return;
		}

		nsCOMPtr<nsIObserver> observer;
		PRBool theLoop = PR_TRUE;
		PRBool bLoop = PR_TRUE;

		while( NS_SUCCEEDED(simpleEnum->HasMoreElements(&theLoop)) && bLoop) 
		{
			simpleEnum->GetNext(getter_AddRefs(observer));

			if (!observer)
			{
				QAOutput("Didn't get the observer object. Tests fail.");
				return;
			}
			rv = observer->Observe(observer, ObserverTable[i].theTopic, 0);
			RvTestResult(rv, "nsIObserver() test", 1);	
			RvTestResultDlg(rv, "nsIObserver() test");
			
			// compare 'this' with observer object
			if( this == NS_REINTERPRET_CAST(CnsIObserServ*,NS_REINTERPRET_CAST(void*, observer.get())))
			{
				QAOutput("observers match. Test passes.");
				bLoop = PR_FALSE;
			}
			else
				QAOutput("observers don't match. Test fails.");
		}
	}
Exemplo n.º 4
0
nsresult TimerThread::Init()
{
  if (mInitialized) {
    if (!mThread)
      return NS_ERROR_FAILURE;

    return NS_OK;
  }

  if (PR_AtomicSet(&mInitInProgress, 1) == 0) {
    nsresult rv;

    mEventQueueService = do_GetService("@mozilla.org/event-queue-service;1", &rv);
    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsIObserverService> observerService
        (do_GetService("@mozilla.org/observer-service;1", &rv));

      if (NS_SUCCEEDED(rv)) {
        // We hold on to mThread to keep the thread alive.
        rv = NS_NewThread(getter_AddRefs(mThread),
                          NS_STATIC_CAST(nsIRunnable*, this),
                          0,
                          PR_JOINABLE_THREAD,
                          PR_PRIORITY_NORMAL,
                          PR_GLOBAL_THREAD);

        if (NS_FAILED(rv)) {
          mThread = nsnull;
        }
        else {
          // We'll be released at xpcom shutdown
          observerService->AddObserver(this, "sleep_notification", PR_FALSE);
          observerService->AddObserver(this, "wake_notification", PR_FALSE);
        }
      }
    }

    PR_Lock(mLock);
    mInitialized = PR_TRUE;
    PR_NotifyAllCondVar(mCondVar);
    PR_Unlock(mLock);
  }
Exemplo n.º 5
0
void CnsIObserServ::NotifyObserversTest(int displayType)
{
	PRInt32 i;
	nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));

	QAOutput("\n nsIObserverService::NotifyObserversTest().");

	if (!observerService) 
	{
		QAOutput("Can't get nsIObserverService object. Tests fail.");
		return;
	}

	for (i=0; i<10; i++)
	{
		FormatAndPrintOutput("The notified observer = ", ObserverTable[i].theTopic, 1);
		rv = observerService->NotifyObservers(nsnull, ObserverTable[i].theTopic, 0);
		RvTestResult(rv, "NotifyObservers() test", displayType);
		RvTestResultDlg(rv, "NotifyObservers() test");
	}
}
Exemplo n.º 6
0
void CnsIObserServ::RemoveObserversTest(int displayType)
{
	int i;

	nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));

	QAOutput("\n nsIObserverService::RemoveObserversTest().");
	if (!observerService) 
	{
		QAOutput("Can't get nsIObserverService object. Tests fail.");
		return;
	}

	for (i=0; i<10; i++)
	{
		rv = observerService->RemoveObserver(this, ObserverTable[i].theTopic);
		FormatAndPrintOutput("The observer to be removed = ", ObserverTable[i].theTopic, 1);	
		RvTestResult(rv, "RemoveObservers() test", displayType);
		RvTestResultDlg(rv, "RemoveObservers() test");
	}
}
NS_IMETHODIMP
nsStatusBarBiffManager::OnItemIntPropertyChanged(nsIRDFResource *item, nsIAtom *property, PRInt32 oldValue, PRInt32 newValue)
{
  if (kBiffStateAtom == property && mCurrentBiffState != newValue) {
    // if we got new mail, attempt to play a sound.
    // if we fail along the way, don't return.
    // we still need to update the UI.    
    if (newValue == nsIMsgFolder::nsMsgBiffState_NewMail) {
      // if we fail to play the biff sound, keep going.
      (void)PlayBiffSound();
    }
    mCurrentBiffState = newValue;

    // don't care if notification fails
    nsCOMPtr<nsIObserverService>
      observerService(do_GetService("@mozilla.org/observer-service;1"));
      
    if (observerService)
      observerService->NotifyObservers(this, "mail:biff-state-changed", nsnull);
  }
  return NS_OK;
}
Exemplo n.º 8
0
NS_IMETHODIMP
nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
    nsresult rv = NS_OK ;

    if (!strcmp(aTopic, "profile-after-change"))
        return InitializeMAPISupport();

    if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
        return ShutdownMAPISupport();

    nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
    if (NS_FAILED(rv)) return rv;
 
    rv = observerService->AddObserver(this,"profile-after-change", PR_FALSE);
    if (NS_FAILED(rv)) return rv;

    rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
    if (NS_FAILED(rv))  return rv;

    return rv;
}
Exemplo n.º 9
0
NS_IMETHODIMP
nsPalmSyncSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
    nsresult rv = NS_OK ;

    // If nsIAppStartupNotifer tells us the app is starting up, then register
    // our observer topics and return.
    if (!strcmp(aTopic, "app-startup"))
    {
      nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
      NS_ENSURE_SUCCESS(rv, rv);
 
      rv = observerService->AddObserver(this,"profile-after-change", PR_FALSE);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = observerService->AddObserver(this, "em-action-requested", PR_FALSE);
      NS_ENSURE_SUCCESS(rv, rv);      

      rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
    }
    // otherwise, take the appropriate action based on the topic
    else if (!strcmp(aTopic, "profile-after-change"))
    {
#ifdef MOZ_THUNDERBIRD
        // we can't call installPalmSync in app-startup because the extension manager hasn't been initialized yet. 
        // so we need to wait until the profile-after-change notification has fired. 
        rv = LaunchPalmSyncInstallExe(); 
#endif
        rv |= InitializePalmSyncSupport();
    } 
    else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
        rv = ShutdownPalmSyncSupport();
#ifdef MOZ_THUNDERBIRD
    else if (aSubject && !strcmp(aTopic, "em-action-requested") && !nsCRT::strcmp(aData, NS_LITERAL_STRING("item-uninstalled").get()))
    {
        // make sure the subject is our extension.
        nsCOMPtr<nsIUpdateItem> updateItem (do_QueryInterface(aSubject, &rv));
        NS_ENSURE_SUCCESS(rv, rv);

        nsAutoString extensionName;
        updateItem->GetId(extensionName);

        if (extensionName.EqualsLiteral(EXTENSION_ID))
        {
            nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
            NS_ENSURE_SUCCESS(rv,rv);
           
            // clear the conduit pref so we'll re-run PalmSyncInstall.exe the next time the extension is installed.
            rv = prefBranch->ClearUserPref(PREF_CONDUIT_REGISTERED); 

            nsCOMPtr<nsILocalFile> palmSyncInstall;
            rv = GetPalmSyncInstall(getter_AddRefs(palmSyncInstall));
            NS_ENSURE_SUCCESS(rv, rv);

            nsCAutoString nativePath;
            palmSyncInstall->GetNativePath(nativePath);
        
            LONG r = (LONG) ::ShellExecuteA( NULL, NULL, nativePath.get(), "/u", NULL, SW_SHOWNORMAL);  // silent uninstall
        }
    }
#endif

    return rv;
}