gecko clear cache history&饼干

时间:2012-11-22 12:47:22

标签: c# cookies gecko

帮助!我对浏览器和 xulrunner-10.0.en-US.win32 使用 GeckoFx-Windows-10.0-0.6 。 (Visual Studio 2010 c#)一切正常。但我需要清除所有历史记录,如Firefox:  工具>>选项>>隐私

我发现cookie在Gecko.CookieManager.RemoveAll();

上有多清晰

如何清除缓存,临时文件和历史记录?!

当我初始化Gecko.Xpcom时,由于显而易见的原因,我无法清除文件夹"Gecko.Xpcom.ProfileDirectory"(缓存和cookie)。 Gecko.Xpcom.Shutdown()无效


我找到了一种通过javascript清理Cookie的方法:

var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfa‌​ces.nsICookieManager); cookieManager.removeAll();

如何在C#中调用这个JS?

2 个答案:

答案 0 :(得分:4)

要清除Cookie,您需要查询以下界面:

    if (MessageBox.Show("Do you want to delete cookies?", "About to delete all cookies", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
    {
        nsICookieManager CookieMan;
        CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1");
        CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan);
        CookieMan.RemoveAll();
    }

在运行时期间,由于安全性等原因导致对缓存的访问被拒绝。 这意味着您需要在程序关闭后找到删除这些文件夹的方法等。 创建另一个应用程序来处理它。

答案 1 :(得分:2)

为了它的价值而且我看了一段时间,在GeckoFX 29上,至少历史遵循相同的模式:

nsIBrowserHistory historyMan = Xpcom.GetService<nsIBrowserHistory>(Gecko.Contracts.NavHistoryService);
historyMan = Xpcom.QueryInterface<nsIBrowserHistory>(historyMan);
historyMan.RemoveAllPages();

对于缓存而不确定是否正确:

// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/imgICache
Gecko.Cache.ImageCache.ClearCache(true);
Gecko.Cache.ImageCache.ClearCache(false);
// Defaults to all devices(0) - https://bitbucket.org/geckofx/geckofx-9.0/issue/7/idl-translation-bug-for-enums
Gecko.Cache.CacheService.Clear(new CacheStoragePolicy());