解决nsIWebProgress addProgressListener失败的问题

给nsWebProgress addProgressListener每次都失败,

[quote]
Error: Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIWebProgress.addProgressListener]

[/quote]
在google 一下发现很多人都遇到这个问题,在addProgressListener函
数里面,首先需要从ProgressListener get WeakReference,添加的listener
实际是WeakReference,所以ProgressListener需要实现nsISupportsWeakReference
接口,一个好用的ProgressListener代码如下:

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;

const nsISupports = Ci.nsISupports;
const nsIWebProgressListener = Ci.nsIWebProgressListener;
const nsISupportsWeakReference = Ci.nsISupportsWeakReference;

function ProgressListener(){
};

ProgressListener.prototype = {
	QueryInterface: function(aIID){
		if(aIID.equals(nsIWebProgressListener) ||
		   aIID.equals(nsISupportsWeakReference) ||
		   aIID.equals(nsISupports))
		   return this;
		 throw Cr.NS_NOINTERFACE;
	},
	
	onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus){
	
	},

    onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress){
    
	},
	
	onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage){
		
	},
	
	onSecurityChange: function(aWebProgress,aRequest,aState){
		
	}
};

 

你可能感兴趣的:(prototype,Google)