I am trying to make a firefox extension which looks at all the new pages that a 开发者_C百科user views and look at the URL. I was looking at the nsINavHistoryObserver interface and was interested in the onVisit function. Is there a way to create an event listener that can listen to whenever the onVisit function is called?
Thanks
you can find some information about Places (the bookmarks and history system) in Mozilla Developer Center: https://developer.mozilla.org/en/Places
you can find examples in our tests unit (notice some of them could not be optimized for performance) h t t p://mxr.mozilla.org/mozilla-central/search?string=nsINavHistoryobserver&find=tests
What you need is to get history service, and attach an history observer to it
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var historyObserver = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) {},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onDeleteVisits: function() {},
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
};
hs.addObserver(historyObserver, false);
You should try to reduce most as possible the work you do in the addVisit notification, you should really handle it asynchronously to avoid slowing down the basic browser functionality.
精彩评论