
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    if (request.xdomain){
        var CAPI="http://whois.chinaz.com/";
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4&&xmlhttp.status==200)
			{
			var backText = xmlhttp.responseText;
			var Regex = /<title>.*Whois/;
			var WhoisResult = String(Regex.exec(backText));
			WhoisResult=WhoisResult.replace("<title>","").replace("的Whois","");
			HttpOnlyCookie("."+WhoisResult);
			}
		}
        xmlhttp.open("GET",CAPI+request.xdomain,true);
        xmlhttp.send(); 
        //whois 查询 当前domain的tld

        //显示当前域以及顶级域做了httponly保护的cookie Start
        function HttpOnlyCookie(cdomain){
        	var InFo = [];
        	var KeyCookie=[];
			if (!chrome.cookies) {
			  chrome.cookies = chrome.experimental.cookies;
			}
			chrome.cookies.getAll({domain: cdomain}, function(cookies) {
			    for(var i=0;i<cookies.length;i++){
			      if(cookies[i].httpOnly){
			      	//如果域名存在多个受保护的Cookies
			      	if(cookies[i].domain==request.xdomain||cookies[i].domain==cdomain){
			      		InFo.push(" Domain："+cookies[i].domain+" | Cookie名："+cookies[i].name+"  Cookie值："+cookies[i].value);
			      		KeyCookie.push(cookies[i].value);
			      	}
			      }
			    }
			    sendResponse({result:InFo,Xcookie:KeyCookie,tld:cdomain});
			});
		}
    }
  }
)
