-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
executable file
·122 lines (100 loc) · 4.82 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package webkit
// #include <webkit2/webkit2.h>
import "C"
// Context manages aspects common to all WebViews.
type Context struct {
context *C.WebKitWebContext
}
// NewContext creates a new WebContext.
func NewContext() *Context {
return &Context{C.webkit_web_context_new()}
}
// NewDefaultContext returns the default WebContext.
func NewDefaultContext() *Context {
return &Context{C.webkit_web_context_get_default()}
}
// ----------------------------------------------------------------------------------------------------
// ClearCache clears all resources currently cached.
func (c *Context) ClearCache() {
C.webkit_web_context_clear_cache(c.context)
}
// ----------------------------------------------------------------------------------------------------
// CacheModel describes the caching behavior.
type CacheModel int
const (
// DocumentViewerCacheModel disables the cache completely, which substantially reduces memory
// usage. Useful for applications that only access a single local file, with no navigation to
// other pages. No remote resources will be cached.
DocumentViewerCacheModel CacheModel = iota
// WebBrowserCacheModel improves document load speed substantially by caching a very large number
// of resources and previously viewed content.
WebBrowserCacheModel
// DocumentBrowserCacheModel is a cache model optimized for viewing a series of local files, e.g.
// a documentation viewer or a website designer. WebKit will cache a moderate number of resources.
DocumentBrowserCacheModel
)
// GetCacheModel returns the current cache model.
func (c *Context) GetCacheModel() CacheModel {
return CacheModel(C.int(C.webkit_web_context_get_cache_model(c.context)))
}
// SetCacheModel sets the current cache model.
func (c *Context) SetCacheModel(model CacheModel) {
C.webkit_web_context_set_cache_model(c.context, C.WebKitCacheModel(model))
}
// ----------------------------------------------------------------------------------------------------
// ProcessModel describes the process behavior.
type ProcessModel int
const (
// SharedProcessModel uses a single process to perform content rendering. The process is shared
// among all the WebKitWebView instances created by the application: if the process hangs or
// crashes all the web views in the application will be affected. This is the default process
// model, and it should suffice for most cases.
SharedProcessModel ProcessModel = iota
// MultipleProcessModel uses one process for each WebKitWebView, while still allowing for some
// of them to share a process in certain situations. The main advantage of this process model
// is that the rendering process for a web view can crash while the rest of the views keep working
// normally. This process model is indicated for applications which may use a number of web views
// and the content of in each must not interfere with the rest — for example a full-fledged web
// browser with support for multiple tabs.
MultipleProcessModel
)
// GetProcessModel returns the current process model.
func (c *Context) GetProcessModel() ProcessModel {
return ProcessModel(C.int(C.webkit_web_context_get_process_model(c.context)))
}
// SetProcessModel sets the current process model.
func (c *Context) SetProcessModel(model ProcessModel) {
C.webkit_web_context_set_process_model(c.context, C.WebKitProcessModel(model))
}
// ----------------------------------------------------------------------------------------------------
// TLSErrorsPolicy describes how tls errors are handled.
type TLSErrorsPolicy int
const (
// IgnoreTLSErrorsPolicy ignores TLS errors
IgnoreTLSErrorsPolicy TLSErrorsPolicy = iota
// FailTLSErrorsPolicy ensures that TLS errors will emit “load-failed-with-tls-errors” and, if
// the signal is handled, finish the load. In case the signal is not handled, “load-failed” is
// emitted before the load finishes.
FailTLSErrorsPolicy
)
// GetTLSErrorsPolicy returns the current tls errors policy.
func (c *Context) GetTLSErrorsPolicy() TLSErrorsPolicy {
return TLSErrorsPolicy(C.int(C.webkit_web_context_get_tls_errors_policy(c.context)))
}
// SetTLSErrorsPolicy sets the current tls errors policy.
func (c *Context) SetTLSErrorsPolicy(policy TLSErrorsPolicy) {
C.webkit_web_context_set_tls_errors_policy(c.context, C.WebKitTLSErrorsPolicy(policy))
}