ビルドしても使えない
Safariがインストールされていると、Safariに付属のWebKit.dllが登録済み*1になっていて、ビルドしたWebKitは使えない。SafariのWebKit.dllならCOMライブラリとして参照設定すると使える。苦労してWebKitビルドしなくて良かったんじゃ…。orz
とりあえずExcel-VBA、C#でも参照できることを確認した。C#では以下のような簡単なプログラムを書いて確認した。
public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region Win32API [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); #endregion private WebKit.WebViewClass webView; private void Form1_Resize(object sender, EventArgs e) { if (webView != null) { SetWindowPos( new IntPtr(webView.viewWindow()), 0, 0, 0, this.ClientSize.Width, this.ClientSize.Height, 0); } } private void Form1_Activated(object sender, EventArgs e) { this.Activated -= Form1_Activated; webView = new WebKit.WebViewClass(); webView.setHostWindow(Handle.ToInt32()); WebKit.tagRECT rect; rect.left = rect.top = rect.bottom = rect.right = 0; webView.initWithFrame(rect, null, null); Form1_Resize(this, EventArgs.Empty); WebKit.IWebFrame frame = webView.mainFrame(); WebKit.IWebURLRequest req = new WebKit.WebURLRequestClass(); req.initWithURL("http://...../cgi-bin/printenv.pl", WebKit._WebURLRequestCachePolicy.WebURLRequestUseProtocolCachePolicy, 60); frame.loadRequest(req); } }
さあて明日はEclipseだ。COMでいけるのでIEBrowserをProgIdやら付随するイベントをWebKitのものと変えてやれば同じアーキテクチャでいけそうだ(Windowsに限っては)。
WebKitとSafariでは微妙にUSER-AGENTが違う。SafariはバージョンとSafariであることが末尾に加えられるようだ。
*1:ちがうちがう。自分でregsvr32しただけの話