Reputation: 11
WebView wv=new WebView();
wv.load_uri("http://www.twitter.com");
how to allow cookies?
I read
CookieManager.getInstance().setAcceptCookie(true);
But I can not find the right syntax
valac --pkg gtk+-3.0 --pkg webkit2gtk-4.0 wv.vala && ./wv wv.vala:25.2-25.26: error: The name 'getInstance' does not exist in the context of 'WebKit.CookieManager' CookieManager.getInstance().setAcceptCookie(true);
Upvotes: 0
Views: 1167
Reputation: 4114
For Gtk+ 3 and Webkit2Gtk-4.0, cookie acceptance/denial is controlled by the CookieManager which you can retrieve from the Webkit web context data manager.
Using your supplied code:
using Gtk;
using WebKit;
public int main (string[] args) {
Gtk.Window window;
Gtk.init(ref args);
window = new Gtk.Window();
window.destroy.connect(Gtk.main_quit);
WebView wv=new WebView();
wv.get_context().get_cookie_manager ().set_accept_policy(CookieAcceptPolicy.ALWAYS);
window.add(wv);
window.show_all();
//wv.load_uri("http://www.html-kit.com/tools/cookietester");
wv.load_uri("http://www.whatarecookies.com/cookietest.asp");
Gtk.main();
return 0;
}
Verifying CookieAcceptPolicy with the supplied examples,
Setting accept always:
wv.get_context().get_cookie_manager ().set_accept_policy(CookieAcceptPolicy.ALWAYS);
A test site will reply with:
Setting accept never:
wv.get_context().get_cookie_manager ().set_accept_policy(CookieAcceptPolicy.NEVER);
A test site will reply with:
EDIT:
Compile with:
valac --pkg gtk+-3.0 --pkg webkit2gtk-4.0 <your-filename.vala>
Upvotes: 1