正 文:
Gecko是一款强大的浏览器内核,著名的Firefox浏览器就是基于 Gecko 核心的。有了 GeckoFX,我们就可以用C#开发一款和 firefox 同样内核的浏览器了。
飘易使用的C#封装的 GeckoFX 版本为 GeckoFX 1.9.1.0。
闲话少说,直入主题,如何清空 Gecko浏览器产生的 cookies 呢? 直接使用 Skybound 工作室编译好的 Skybound.Gecko.dll 是不行的,因为源码中根本没有封装cookie相关的操作函数。我们需要重新编译 GeckoFX 的源码。
具体方法如下:
打开
Xpcom.cs(红色的代码是新增加的):
//Initialize a static variable for the cookie manager
static nsICookieManager CookieMan;public static void Initialize()
{
Initialize(null);
InitializeExtras(); }
static void InitializeExtras()
{
//Initialize the cookie manager
CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1");
CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan);
}public static void Initialize(string binDirectory)
{
.....
InitializeExtras();}
public static void DeleteAllCookies()
{
CookieMan.removeAll();
} 修改好 Xpcom.cs 后重新编译生成.dll库文件,然后程序里调用新编译过的 Skybound.Gecko.dll库文件。如何调用进行清空cookie?直接在程序中需要清空cookie的地方使用语句:
Xpcom.DeleteAllCookies();就可以了。
在编译dll的过程中,可能发生的错误以及解决方法:
1,
nsICookieManager 错误:“找不到类型或命名空间名称“nsICookieManager”(是否缺少 using 指令或程序集引用?)”。
这是由于在接口文件中没有定义 nsICookieManager 接口导致。解决方法:打开 nsInterfaces.cs ,在里面添加该接口(红色代码为新增的):
[Guid("00000000-0000-0000-c000-000000000046"), ComImport]
public interface nsISupports
{
object QueryInterface(ref Guid iid);
int AddRef();
int Release();
}
[Guid("AAAB6710-0F2C-11d5-A53B-0010A401EB10"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsICookieManager
{
void removeAll();
void remove(string aDomain, string aName, string aPath, bool aBlocked);
}2,
nsIDOMNSElement 错误:“找不到类型或命名空间名称“nsIDOMNSElement”(是否缺少 using 指令或程序集引用?)”
这是由于debug的版本不对,解决方法:工程属性-->生成-->配置-->选择 Debug 1.9 或 Release 即可。
这里也有一篇其他网友写的“曲线救国”的清空cookies的方式:
geckofx使用之初步探索:cookies.sqlite,飘易不推荐。
使用 geckofx 控件需要 xulrunner 运行环境,xulrunner下载地址:
http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/xulrunner介绍:
https://developer.mozilla.org/cn/XULRunner里面有好几个版本,因为 GecKoFX readme 里说 GeckoFX now works best with XULRunner 1.9.1 (Firefox 3.5),所以
飘易下载的是 XULRunner 1.9.1.19 版本。
Geckofx论坛:
http://geckofx.org/ Google code:
http://code.google.com/p/geckofx/补充:
GeckoFX Readme英文说明:
--------------------------------------
GeckoFX is a .NET wrapper around XULRunner, a runtime based on the same source
code as Firefox. You can add the control to your windows forms app and use it much the
same way as System.Windows.Forms.WebBrowser.
Since GeckoFX is a wrapper, you need to have the XULRunner runtime somewhere on your
development system (and redistribute it with your application). GeckoFX now works best
with XULRunner 1.9.1 (Firefox 3.5).
(1) Download XULRunner 1.9.1 from:
http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.1.19/runtimes/xulrunner-1.9.1.19.en-US.win32.zip
(2) In your application startup code, call:
Skybound.Gecko.Xpcom.Initialize(xulrunnerPath);
where "xulrunnerPath" is the full path to the location where you extracted the "xulrunner" directory
(containing xul.dll, xpcom.dll, etc).
(3) OPTIONAL: Specify a profile directory by setting Xpcom.ProfileDirectory.
(4) OPTIONAL: There are some files included with XULRunner which GeckoFX doesn't need. You may
safely delete them:
AccessibleMarshal.dll
dependentlibs.list
mozctl.dll
mozctlx.dll
java*.*
*.ini
*.txt
*.exe
(5) OPTIONAL: XULRunner does not support about:config out of the box. If you want to provide
access to this configuration page, copy the files from the "chrome" directory that came with
GeckoFX into the "chrome" directory in your XULRunner path.
The files that need to be copied are "geckofx.jar" and "geckofx.manifest".
--------------------------------------