I want to send a message from C++ to Javascript. I have read that I could use the observer service.

When I try, Firefox freezes.

This is my code:

Javascript:

var observer = new function(){
        var observerService;
        
        this.init = function(){
observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
                this.register();
        };
        
        this.destroy = function(){
                observerService = null;
                this.unregister();
        }
        
        this.observe = function(subject, topic, data){
                //alert("Subject: " + subject);
                alert("Topic: " + topic);
                alert("Data: " + data);
        };
        
        this.register = function(){
                observerService.addObserver(this, "JHandlerCallback", false);
        };
        
        this.unregister = function(){
                observerService.removeObserver(this, "JHandlerCallback");
        };
};

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

observer.init();


C++:

nsCOMPtr<nsIServiceManager> serviceManager;
nsCOMPtr<nsIObserverService> observerService;

NS_GetServiceManager(getter_AddRefs(serviceManager));

serviceManager->GetServiceByContractID("@mozilla.org/observer-service;1", NS_GET_IID(nsIObserverService), getter_AddRefs(observerService));

observerService->NotifyObservers(NULL, "JHandlerCallback", (PRUnichar*)"test");


I have tried calling the observer from javascript, even with a setTimeout and it worked.
Why doesn't it work from C++?
Sorry for asking so much questions, but I really can't find what I'm doing wrong.
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to