在XULRunner中获得Cookie

最近在看browser嵌入,找到XULRunner,
http://developer.mozilla.org/cn/docs/%E5%88%9B%E5%BB%BA_XPCOM_%E7%BB%84%E4%BB%B6:%E4%BD%BF%E7%94%A8_XPCOM_%E7%BB%84%E4%BB%B6
创建 XPCOM 组件:使用 XPCOM 组件

http://developer.mozilla.org/en/docs/nsICookieManager
nsICookieManager

如何获得Cookie?
http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg37871.html


Well I got it working, I think I was passing in the wrong ID. Here is the code if anyone else has this problem.

nsIServiceManager serviceManager = Mozilla.getInstance().getServiceManager();
nsICookieManager cookieManager = (nsICookieManager) serviceManager.getServiceByContractID("@mozilla.org/cookiemanager;1", nsICookieManager.NS_ICOOKIEMANAGER_IID);

nsISimpleEnumerator cookieEnumerator = cookieManager.getEnumerator();

while (cookieEnumerator.hasMoreElements()) {
// Not sure how to get the nsICookie Object. 400
nsICookie cookie = (nsICookie)cookieEnumerator.getNext().queryInterface(nsICookie.NS_ICOOKIE_IID);
System.out.println(cookie.getName());
System.out.println(cookie.getHost());
}

If anyone has a place to gather more information for using the JavaXPCOM other than the XUL Planet site I would love to know.

猜你喜欢

转载自ljl-xyf.iteye.com/blog/1491288