2 function webdeveloper_getCookies(host
, path
, sort
)
4 var cookies
= new Array();
10 var cookieEnumeration
= Components
.classes
["@mozilla.org/cookiemanager;1"].getService(Components
.interfaces
.nsICookieManager
).enumerator
;
11 var cookieHost
= null;
12 var cookiePath
= null;
14 // Loop through the cookies
15 while(cookieEnumeration
.hasMoreElements())
17 cookie
= cookieEnumeration
.getNext().QueryInterface(Components
.interfaces
.nsICookie
);
19 cookieHost
= cookie
.host
;
20 cookiePath
= cookie
.path
;
22 // If there is a host and path for this cookie
23 if(cookieHost
&& cookiePath
)
25 // If the cookie host starts with '.'
26 if(cookieHost
.charAt(0) == ".")
28 cookieHost
= cookieHost
.substring(1);
31 // If the host and cookie host and path and cookie path match
32 if((host
== cookieHost
|| host
.indexOf("." + cookieHost
) != -1) && (path
== cookiePath
|| path
.indexOf(cookiePath
) == 0))
42 cookies
.sort(webdeveloper_sortCookies
);
50 function webdeveloper_sortCookies(cookieOne
, cookieTwo
)
52 // If cookie one and cookie two are set
53 if(cookieOne
&& cookieTwo
)
55 var cookieOneHost
= cookieOne
.host
;
56 var cookieOneName
= cookieOne
.name
;
57 var cookieTwoHost
= cookieTwo
.host
;
58 var cookieTwoName
= cookieTwo
.name
;
60 // If the cookies are equal
61 if(cookieOneHost
== cookieTwoHost
&& cookieOneName
== cookieTwoName
)
65 else if(cookieOneHost
< cookieTwoHost
|| (cookieOneHost
== cookieTwoHost
&& cookieOneName
< cookieTwoName
))