在Go cgo中更改WebKitWebSettings

huangapple go评论83阅读模式
英文:

Change WebKitWebSettings in Go cgo

问题

我正在使用go-webkit,并且我有一个webkitsettings的实例,我该如何更改设置?

我正在尝试像这样做:

main.go

webview := webkit.NewWebView()
settings := webview.GetSettings()
settings.SetEnableJavascript(false)
webview.SetSettings(settings)

go-webkit
来自https://github.com/mattn/go-webkit/blob/master/webkit/webkit.go#L370的代码片段

type WebSettings struct {
        glib.GObject
}

func (settings *WebSettings) SetEnableJavascript (flag bool) {
//我尝试了各种方法
//C.g_object_set?
}
func (v *WebView) SetSettings(settings *WebSettings) {
        C.webkit_web_view_set_settings(v.getWebView(), C.to_WebKitWebSettings(settings.Object));
}
func (v *WebView) GetSettings() *WebSettings {
        return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_view_get_settings(v.getWebView()))}}
}
func NewWebSettings() *WebSettings {
        return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_settings_new())}}

}

Webkit API: 1.0
http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html

/* 创建一个新的websettings并禁用JavaScript */
WebKitWebSettings *settings = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);

/* 应用结果 */
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
英文:

I'm using go-webkit and I have a instance of webkitsettings, how can I change the settings?

I'm trying to do something like this

main.go

webview := webkit.NewWebView()
settings := webview.GetSettings()
settings.SetEnableJavascript(false)
webview.SetSettings(settings)

go-webkit
Snippet from https://github.com/mattn/go-webkit/blob/master/webkit/webkit.go#L370

type WebSettings struct {
        glib.GObject
}

func (settings *WebSettings) SetEnableJavascript (flag bool) {
//I tried various ways
//C.g_object_set?
}
func (v *WebView) SetSettings(settings *WebSettings) {
        C.webkit_web_view_set_settings(v.getWebView(), C.to_WebKitWebSettings(settings.Object));
}
func (v *WebView) GetSettings() *WebSettings {
        return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_view_get_settings(v.getWebView()))}}
}
func NewWebSettings() *WebSettings {
        return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_settings_new())}}

}

Webkit API: 1.0
http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html

/* Create a new websettings and disable java script */
WebKitWebSettings *settings = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);

/* Apply the result */
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);

答案1

得分: 1

WebSettings嵌入了glib.GObject,而glib.GObject实现了Set方法(参见godoc)。

所以在你的情况下,g_object_set应该翻译为settings.GObject.Set,或者由于GObject的方法集被导出到WebSettings,你可以简单地执行以下操作:

settings.Set("enable-scripts", false)
英文:

WebSettings embeds glib.GObject which in turn implements the Set method (see godoc).

So g_object_set should translate in your case to settings.GObject.Set or, as the method set
of GObject is exported to WebSettings, you can simply do

settings.Set("enable-scripts", false)

huangapple
  • 本文由 发表于 2014年1月13日 22:31:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/21093725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定