Gecko清除缓存历史记录和Cookie

6

救命啊!我使用的是 GeckoFx-Windows-10.0-0.6 作为浏览器,以及 xulrunner-10.0.en-US.win32。(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个回答

6
清除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();
    }

可能是因为安全等原因,在运行时被拒绝访问缓存。 这意味着您需要找到一种方法,在程序关闭后删除这些文件夹等。 可以创建另一个应用程序来处理它。


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());

错误 System.NotImplementedException: 'The method or operation is not implemented.'Gecko.Cache.CacheService.Clear(new CacheStoragePolicy()); - Dũng IT
你确定你正在使用的是 GeckoFX 29 吗?这个问题早已被解答,现在很难提供任何有价值的输入。 - dimitrisk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接