3,245
社区成员
发帖
与我相关
我的任务
分享
my_xpcom.addObserver(my_observer, "myTopicID", false);
register: function()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mozilla.org/observer-service;1";
//const cid = "@yoursite.com/MyXPCOM1;1";
var observerService = Components.classes[cid].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "myTopicID", false);
},
nsresult
nsWebShellWindow::NotifyObservers( const nsString &aTopic, const nsString &someData ) {
nsresult rv = NS_OK;
// Get observer service.
nsIObserverService *svc = 0;
rv = nsServiceManager::GetService( "@mozilla.org/observer-service;1",
NS_GET_IID(nsIObserverService),
(nsISupports**)&svc );
if ( NS_SUCCEEDED( rv ) && svc ) {
// Notify observers as instructed; the subject is "this" web shell window.
nsCAutoString topic; topic.Assign(prefix);
topic.Append(";");
topic.AppendWithConversion(aTopic);
rv = svc->NotifyObservers( (nsIWebShellWindow*)this, topic.get(), someData.get() );
// Release the service.
nsServiceManager::ReleaseService( "@mozilla.org/observer-service;1", svc );
} else {
}
return rv;
}