2012-11-22 94 views
5

Trợ giúp! Tôi sử dụng GeckoFx-Windows-10.0-0.6 cho trình duyệt và xulrunner-10.0.en-US.win32. (Visual Studio 2010 C#) mọi thứ hoạt động tốt. Nhưng tôi cần phải xóa tất cả lịch sử như ở Firefox: Tools >> Options >> Privacygecko xóa lịch sử bộ nhớ cache và cookie

tôi thấy cookie sẽ như thế nào rõ ràng hơn Gecko.CookieManager.RemoveAll();

Làm thế nào rõ ràng bộ nhớ cache, file tạm và lịch sử?!

Và khi tôi khởi tạo Gecko.Xpcom tôi không thể xóa thư mục "Gecko.Xpcom.ProfileDirectory" (nơi bộ nhớ cache và cookie) vì lý do hiển nhiên. Gecko.Xpcom.Shutdown() không giúp


Tôi tìm thấy một cách để làm sạch các tập tin cookie qua javascript:

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

Làm thế nào ngay cuộc gọi này JS trong C#?

Trả lời

4

Để xóa cookie, bạn sẽ cần phải truy vấn giao diện như thế này:

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

Một quyền truy cập vào bộ nhớ cache bị từ chối trong thời gian chạy brobably nguyên nhân của an ninh hay như vậy. Có nghĩa là bạn sẽ cần phải tìm cách xóa các thư mục này sau khi bạn đóng chương trình, vv .. tạo một ứng dụng khác để xử lý nó.

1

Đối với những gì giá trị của nó và kể từ khi tôi nhìn một thời gian cho việc này, trên GeckoFX 29 ít nhất lịch sử sau cùng một khuôn mẫu:

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

Đối với bộ nhớ cache mà không bị chắc chắn là cách chính xác:

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