【问题标题】:gecko clear cache history & cookies壁虎清除缓存历史记录和cookies
【发布时间】:2012-11-10 20:57:09
【问题描述】:

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

我发现Gecko.CookieManager.RemoveAll(); 上的 cookie 有多清晰

缓存、临时文件和历史记录有多清晰?!

当我初始化 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?

【问题讨论】:

    标签: c# cookies gecko


    【解决方案1】:

    不管它的价值是什么,因为我为此看了一段时间,在 GeckoFX 29 上,至少历史遵循相同的模式:

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

    For Cache 不确定是不是正确的方法:

    // 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());
    • 您确定您使用的是 GeckoFX 29 吗?很久以前就回答了这个问题,目前很难提供任何有价值的意见。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      相关资源
      最近更新 更多