Skip to content

Instantly share code, notes, and snippets.

@brendandahl
Last active July 8, 2016 23:09
Show Gist options
  • Save brendandahl/e0d7b90076f1deb85daead0b75a33981 to your computer and use it in GitHub Desktop.
Save brendandahl/e0d7b90076f1deb85daead0b75a33981 to your computer and use it in GitHub Desktop.
Attempt at adding an observer before XRE_main runs
// in main.cpp
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
class nsBlahObserver final : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
nsBlahObserver() {}
protected:
~nsBlahObserver() {}
};
NS_IMPL_ISUPPORTS(nsBlahObserver, nsIObserver)
NS_IMETHODIMP
nsBlahObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
printf("!!!!!!!!!!!%s\n", aTopic);
return NS_OK;
}
// in main():
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
if (os) {
nsBlahObserver* observer = new nsBlahObserver();;
os->AddObserver(observer, "abc", false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment