1/*
2 * Copyright (C) 2011 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
21#error "Only <webkit2/webkit2.h> can be included directly."
22#endif
23
24#ifndef WebKitWebContext_h
25#define WebKitWebContext_h
26
27#include <glib-object.h>
28#include <webkit2/WebKitCertificateInfo.h>
29#include <webkit2/WebKitCookieManager.h>
30#include <webkit2/WebKitDefines.h>
31#include <webkit2/WebKitDownload.h>
32#include <webkit2/WebKitFaviconDatabase.h>
33#include <webkit2/WebKitSecurityManager.h>
34#include <webkit2/WebKitURISchemeRequest.h>
35
36G_BEGIN_DECLS
37
38#define WEBKIT_TYPE_WEB_CONTEXT            (webkit_web_context_get_type())
39#define WEBKIT_WEB_CONTEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContext))
40#define WEBKIT_WEB_CONTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextClass))
41#define WEBKIT_IS_WEB_CONTEXT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_CONTEXT))
42#define WEBKIT_IS_WEB_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_CONTEXT))
43#define WEBKIT_WEB_CONTEXT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextClass))
44
45/**
46 * WebKitCacheModel:
47 * @WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: Disable the cache completely, which
48 *   substantially reduces memory usage. Useful for applications that only
49 *   access a single local file, with no navigation to other pages. No remote
50 *   resources will be cached.
51 * @WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: A cache model optimized for viewing
52 *   a series of local files -- for example, a documentation viewer or a website
53 *   designer. WebKit will cache a moderate number of resources.
54 * @WEBKIT_CACHE_MODEL_WEB_BROWSER: Improve document load speed substantially
55 *   by caching a very large number of resources and previously viewed content.
56 *
57 * Enum values used for determining the #WebKitWebContext cache model.
58 */
59typedef enum {
60    WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER,
61    WEBKIT_CACHE_MODEL_WEB_BROWSER,
62    WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER
63} WebKitCacheModel;
64
65/**
66 * WebKitProcessModel:
67 * @WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS: Use a single process to
68 *   perform content rendering. The process is shared among all the
69 *   #WebKitWebView instances created by the application: if the process
70 *   hangs or crashes all the web views in the application will be affected.
71 *   This is the default process model, and it should suffice for most cases.
72 * @WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES: Use one process
73 *   for each #WebKitWebView, while still allowing for some of them to
74 *   share a process in certain situations. The main advantage
75 *   of this process model is that the rendering process for a web view
76 *   can crash while the rest of the views keep working normally. This
77 *   process model is indicated for applications which may use a number
78 *   of web views and the content of in each must not interfere with the
79 *   rest — for example a full-fledged web browser with support for
80 *   multiple tabs.
81 *
82 * Enum values used for determining the #WebKitWebContext process model.
83 *
84 * Since: 2.4
85 */
86typedef enum {
87    WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS,
88    WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES,
89} WebKitProcessModel;
90
91/**
92 * WebKitTLSErrorsPolicy:
93 * @WEBKIT_TLS_ERRORS_POLICY_IGNORE: Ignore TLS errors.
94 * @WEBKIT_TLS_ERRORS_POLICY_FAIL: TLS errors will emit
95 *   #WebKitWebView::load-failed-with-tls-errors and, if the signal is handled,
96 *   finish the load. In case the signal is not handled,
97 *   #WebKitWebView::load-failed is emitted before the load finishes.
98 *
99 * Enum values used to denote the TLS errors policy.
100 */
101typedef enum {
102    WEBKIT_TLS_ERRORS_POLICY_IGNORE,
103    WEBKIT_TLS_ERRORS_POLICY_FAIL
104} WebKitTLSErrorsPolicy;
105
106/**
107 * WebKitURISchemeRequestCallback:
108 * @request: the #WebKitURISchemeRequest
109 * @user_data: user data passed to the callback
110 *
111 * Type definition for a function that will be called back when an URI request is
112 * made for a user registered URI scheme.
113 */
114typedef void (* WebKitURISchemeRequestCallback) (WebKitURISchemeRequest *request,
115                                                 gpointer                user_data);
116
117typedef struct _WebKitWebContext        WebKitWebContext;
118typedef struct _WebKitWebContextClass   WebKitWebContextClass;
119typedef struct _WebKitWebContextPrivate WebKitWebContextPrivate;
120
121struct _WebKitWebContext {
122    GObject parent;
123
124    /*< private >*/
125    WebKitWebContextPrivate *priv;
126};
127
128struct _WebKitWebContextClass {
129    GObjectClass parent;
130
131    void (*_webkit_reserved0) (void);
132    void (*_webkit_reserved1) (void);
133    void (*_webkit_reserved2) (void);
134    void (*_webkit_reserved3) (void);
135    void (*_webkit_reserved4) (void);
136    void (*_webkit_reserved5) (void);
137    void (*_webkit_reserved6) (void);
138    void (*_webkit_reserved7) (void);
139};
140
141WEBKIT_API GType
142webkit_web_context_get_type                         (void);
143
144WEBKIT_API WebKitWebContext *
145webkit_web_context_get_default                      (void);
146
147WEBKIT_API void
148webkit_web_context_set_cache_model                  (WebKitWebContext              *context,
149                                                     WebKitCacheModel               cache_model);
150WEBKIT_API WebKitCacheModel
151webkit_web_context_get_cache_model                  (WebKitWebContext              *context);
152
153WEBKIT_API void
154webkit_web_context_clear_cache                      (WebKitWebContext              *context);
155
156WEBKIT_API WebKitDownload *
157webkit_web_context_download_uri                     (WebKitWebContext              *context,
158                                                     const gchar                   *uri);
159
160WEBKIT_API WebKitCookieManager *
161webkit_web_context_get_cookie_manager               (WebKitWebContext              *context);
162
163WEBKIT_API WebKitFaviconDatabase *
164webkit_web_context_get_favicon_database             (WebKitWebContext              *context);
165
166WEBKIT_API void
167webkit_web_context_set_favicon_database_directory   (WebKitWebContext              *context,
168                                                     const gchar                   *path);
169WEBKIT_API const gchar *
170webkit_web_context_get_favicon_database_directory   (WebKitWebContext              *context);
171
172WEBKIT_API WebKitSecurityManager *
173webkit_web_context_get_security_manager             (WebKitWebContext              *context);
174
175WEBKIT_API void
176webkit_web_context_set_additional_plugins_directory (WebKitWebContext              *context,
177                                                     const gchar                   *directory);
178
179WEBKIT_API void
180webkit_web_context_get_plugins                      (WebKitWebContext              *context,
181                                                     GCancellable                  *cancellable,
182                                                     GAsyncReadyCallback            callback,
183                                                     gpointer                       user_data);
184
185WEBKIT_API GList *
186webkit_web_context_get_plugins_finish               (WebKitWebContext              *context,
187                                                     GAsyncResult                  *result,
188                                                     GError                       **error);
189WEBKIT_API void
190webkit_web_context_register_uri_scheme              (WebKitWebContext              *context,
191                                                     const gchar                   *scheme,
192                                                     WebKitURISchemeRequestCallback callback,
193                                                     gpointer                       user_data,
194                                                     GDestroyNotify                 user_data_destroy_func);
195
196WEBKIT_API gboolean
197webkit_web_context_get_spell_checking_enabled       (WebKitWebContext              *context);
198
199WEBKIT_API void
200webkit_web_context_set_spell_checking_enabled       (WebKitWebContext              *context,
201                                                     gboolean                       enabled);
202WEBKIT_API const gchar * const *
203webkit_web_context_get_spell_checking_languages     (WebKitWebContext              *context);
204
205WEBKIT_API void
206webkit_web_context_set_spell_checking_languages     (WebKitWebContext              *context,
207                                                     const gchar * const           *languages);
208
209WEBKIT_API void
210webkit_web_context_set_preferred_languages          (WebKitWebContext              *context,
211                                                     const gchar * const           *languages);
212
213WEBKIT_API void
214webkit_web_context_set_tls_errors_policy            (WebKitWebContext              *context,
215                                                     WebKitTLSErrorsPolicy          policy);
216
217WEBKIT_API WebKitTLSErrorsPolicy
218webkit_web_context_get_tls_errors_policy            (WebKitWebContext              *context);
219
220WEBKIT_API void
221webkit_web_context_set_web_extensions_directory     (WebKitWebContext              *context,
222                                                     const gchar                   *directory);
223
224WEBKIT_API void
225webkit_web_context_set_web_extensions_initialization_user_data
226                                                    (WebKitWebContext              *context,
227                                                     GVariant                      *user_data);
228
229WEBKIT_API void
230webkit_web_context_prefetch_dns                     (WebKitWebContext              *context,
231                                                     const gchar                   *hostname);
232
233WEBKIT_API void
234webkit_web_context_set_disk_cache_directory         (WebKitWebContext              *context,
235                                                     const gchar                   *directory);
236
237WEBKIT_API void
238webkit_web_context_allow_tls_certificate_for_host   (WebKitWebContext              *context,
239                                                     WebKitCertificateInfo         *info,
240                                                     const gchar                   *host);
241
242WEBKIT_API void
243webkit_web_context_set_process_model                (WebKitWebContext              *context,
244                                                     WebKitProcessModel             process_model);
245
246WEBKIT_API WebKitProcessModel
247webkit_web_context_get_process_model                (WebKitWebContext              *context);
248
249G_END_DECLS
250
251#endif
252