f3f059caa1501c3df400322eb730f96e6ff0d3dc
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / gtk / WebKitWebView.h
1 /*
2  * Copyright (C) 2007 Holger Hans Peter Freyther
3  * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com>
4  * Copyright (C) 2008 Collabora Ltd.
5  * Copyright (C) 2011 Igalia S.L.
6  * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
25 #error "Only <webkit2/webkit2.h> can be included directly."
26 #endif
27
28 #ifndef WebKitWebView_h
29 #define WebKitWebView_h
30
31 #include <JavaScriptCore/JSBase.h>
32 #include <webkit2/WebKitAuthenticationRequest.h>
33 #include <webkit2/WebKitBackForwardList.h>
34 #include <webkit2/WebKitDefines.h>
35 #include <webkit2/WebKitFileChooserRequest.h>
36 #include <webkit2/WebKitFindController.h>
37 #include <webkit2/WebKitFormSubmissionRequest.h>
38 #include <webkit2/WebKitForwardDeclarations.h>
39 #include <webkit2/WebKitHitTestResult.h>
40 #include <webkit2/WebKitJavascriptResult.h>
41 #include <webkit2/WebKitNavigationAction.h>
42 #include <webkit2/WebKitPermissionRequest.h>
43 #include <webkit2/WebKitPolicyDecision.h>
44 #include <webkit2/WebKitScriptDialog.h>
45 #include <webkit2/WebKitSettings.h>
46 #include <webkit2/WebKitURIRequest.h>
47 #include <webkit2/WebKitUserContentManager.h>
48 #include <webkit2/WebKitWebContext.h>
49 #include <webkit2/WebKitWebInspector.h>
50 #include <webkit2/WebKitWebResource.h>
51 #include <webkit2/WebKitWebViewBase.h>
52 #include <webkit2/WebKitWindowProperties.h>
53
54 G_BEGIN_DECLS
55
56 #define WEBKIT_TYPE_WEB_VIEW            (webkit_web_view_get_type())
57 #define WEBKIT_WEB_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView))
58 #define WEBKIT_IS_WEB_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW))
59 #define WEBKIT_WEB_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
60 #define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_VIEW))
61 #define WEBKIT_WEB_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
62
63 typedef struct _WebKitWebViewClass WebKitWebViewClass;
64 typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate;
65
66 /**
67  * WebKitPolicyDecisionType:
68  * @WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: This type of policy decision
69  *   is requested when WebKit is about to navigate to a new page in either the
70  *   main frame or a subframe. Acceptable policy decisions are either
71  *   webkit_policy_decision_use() or webkit_policy_decision_ignore(). This
72  *   type of policy decision is always a #WebKitNavigationPolicyDecision.
73  * @WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION: This type of policy decision
74  *   is requested when WebKit is about to create a new window. Acceptable policy
75  *   decisions are either webkit_policy_decision_use() or
76  *   webkit_policy_decision_ignore(). This type of policy decision is always
77  *   a #WebKitNavigationPolicyDecision. These decisions are useful for implementing
78  *   special actions for new windows, such as forcing the new window to open
79  *   in a tab when a keyboard modifier is active or handling a special
80  *   target attribute on &lt;a&gt; elements.
81  * @WEBKIT_POLICY_DECISION_TYPE_RESPONSE: This type of decision is used when WebKit has
82  *   received a response for a network resource and is about to start the load.
83  *   Note that these resources include all subresources of a page such as images
84  *   and stylesheets as well as main documents. Appropriate policy responses to
85  *   this decision are webkit_policy_decision_use(), webkit_policy_decision_ignore(),
86  *   or webkit_policy_decision_download(). This type of policy decision is always
87  *   a #WebKitResponsePolicyDecision. This decision is useful for forcing
88  *   some types of resources to be downloaded rather than rendered in the WebView
89  *   or to block the transfer of resources entirely.
90  *
91  * Enum values used for determining the type of a policy decision during
92  * #WebKitWebView::decide-policy.
93  */
94 typedef enum {
95     WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION,
96     WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION,
97     WEBKIT_POLICY_DECISION_TYPE_RESPONSE,
98 } WebKitPolicyDecisionType;
99
100 /**
101  * WebKitLoadEvent:
102  * @WEBKIT_LOAD_STARTED: A new load request has been made.
103  * No data has been received yet, empty structures have
104  * been allocated to perform the load; the load may still
105  * fail due to transport issues such as not being able to
106  * resolve a name, or connect to a port.
107  * @WEBKIT_LOAD_REDIRECTED: A provisional data source received
108  * a server redirect.
109  * @WEBKIT_LOAD_COMMITTED: The content started arriving for a page load.
110  * The necessary transport requirements are stabilished, and the
111  * load is being performed.
112  * @WEBKIT_LOAD_FINISHED: Load completed. All resources are done loading
113  * or there was an error during the load operation.
114  *
115  * Enum values used to denote the different events that happen during a
116  * #WebKitWebView load operation.
117  */
118 typedef enum {
119     WEBKIT_LOAD_STARTED,
120     WEBKIT_LOAD_REDIRECTED,
121     WEBKIT_LOAD_COMMITTED,
122     WEBKIT_LOAD_FINISHED
123 } WebKitLoadEvent;
124
125 /**
126  * WebKitSaveMode:
127  * @WEBKIT_SAVE_MODE_MHTML: Save the current page using the MHTML format.
128  *
129  * Enum values to specify the different ways in which a #WebKitWebView
130  * can save its current web page into a self-contained file.
131  */
132 typedef enum {
133     WEBKIT_SAVE_MODE_MHTML
134 } WebKitSaveMode;
135
136 /**
137  * WebKitInsecureContentEvent:
138  * @WEBKIT_INSECURE_CONTENT_RUN: Insecure content has been detected by
139  * trying to execute any kind of logic (e.g. a script) from an
140  * untrusted source.
141  * @WEBKIT_INSECURE_CONTENT_DISPLAYED: Insecure content has been
142  * detected by trying to display any kind of resource (e.g. an image)
143  * from an untrusted source.
144  *
145  * Enum values used to denote the different events which can trigger
146  * the detection of insecure content.
147  */
148 typedef enum {
149     WEBKIT_INSECURE_CONTENT_RUN,
150     WEBKIT_INSECURE_CONTENT_DISPLAYED
151 } WebKitInsecureContentEvent;
152
153 /**
154  * WebKitSnapshotOptions:
155  * @WEBKIT_SNAPSHOT_OPTIONS_NONE: Do not include any special options.
156  * @WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING: Whether to include in the
157  * snapshot the highlight of the selected content.
158  *
159  * Enum values used to specify options when taking a snapshot
160  * from a #WebKitWebView.
161  */
162 typedef enum {
163   WEBKIT_SNAPSHOT_OPTIONS_NONE = 0,
164   WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING = 1 << 0,
165 } WebKitSnapshotOptions;
166
167 /**
168  * WebKitSnapshotRegion:
169  * @WEBKIT_SNAPSHOT_REGION_VISIBLE: Specifies a snapshot only for the area that is
170  * visible in the webview
171  * @WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT: A snapshot of the entire document.
172  *
173  * Enum values used to specify the region from which to get a #WebKitWebView
174  * snapshot
175  */
176 typedef enum {
177   WEBKIT_SNAPSHOT_REGION_VISIBLE = 0,
178   WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
179 } WebKitSnapshotRegion;
180
181 struct _WebKitWebView {
182     WebKitWebViewBase parent;
183
184     /*< private >*/
185     WebKitWebViewPrivate *priv;
186 };
187
188 struct _WebKitWebViewClass {
189     WebKitWebViewBaseClass parent;
190
191     void       (* load_changed)                (WebKitWebView               *web_view,
192                                                 WebKitLoadEvent              load_event);
193     gboolean   (* load_failed)                 (WebKitWebView               *web_view,
194                                                 WebKitLoadEvent              load_event,
195                                                 const gchar                 *failing_uri,
196                                                 GError                      *error);
197
198     GtkWidget *(* create)                      (WebKitWebView               *web_view,
199                                                 WebKitNavigationAction      *navigation_action);
200     void       (* ready_to_show)               (WebKitWebView               *web_view);
201     void       (* run_as_modal)                (WebKitWebView               *web_view);
202     void       (* close)                       (WebKitWebView               *web_view);
203
204     gboolean   (* script_dialog)               (WebKitWebView               *web_view,
205                                                 WebKitScriptDialog          *dialog)  ;
206
207     gboolean   (* decide_policy)               (WebKitWebView               *web_view,
208                                                 WebKitPolicyDecision        *decision,
209                                                 WebKitPolicyDecisionType     type);
210     gboolean   (* permission_request)          (WebKitWebView               *web_view,
211                                                 WebKitPermissionRequest     *permission_request);
212     void       (* mouse_target_changed)        (WebKitWebView               *web_view,
213                                                 WebKitHitTestResult         *hit_test_result,
214                                                 guint                        modifiers);
215     gboolean   (* print)                       (WebKitWebView               *web_view,
216                                                 WebKitPrintOperation        *print_operation);
217     void       (* resource_load_started)       (WebKitWebView               *web_view,
218                                                 WebKitWebResource           *resource,
219                                                 WebKitURIRequest            *request);
220     gboolean   (* enter_fullscreen)            (WebKitWebView               *web_view);
221     gboolean   (* leave_fullscreen)            (WebKitWebView               *web_view);
222     gboolean   (* run_file_chooser)            (WebKitWebView               *web_view,
223                                                 WebKitFileChooserRequest    *request);
224     gboolean   (* context_menu)                (WebKitWebView               *web_view,
225                                                 WebKitContextMenu           *context_menu,
226                                                 GdkEvent                    *event,
227                                                 WebKitHitTestResult         *hit_test_result);
228     void       (* context_menu_dismissed)      (WebKitWebView               *web_view);
229     void       (* submit_form)                 (WebKitWebView               *web_view,
230                                                 WebKitFormSubmissionRequest *request);
231     void       (* insecure_content_detected)   (WebKitWebView               *web_view,
232                                                 WebKitInsecureContentEvent   event);
233     gboolean   (* web_process_crashed)         (WebKitWebView               *web_view);
234
235     gboolean   (* authenticate)                (WebKitWebView               *web_view,
236                                                 WebKitAuthenticationRequest *request);
237     gboolean   (* load_failed_with_tls_errors) (WebKitWebView               *web_view,
238                                                 const gchar                 *failing_uri,
239                                                 GTlsCertificate             *certificate,
240                                                 GTlsCertificateFlags         errors);
241     void (*_webkit_reserved0) (void);
242     void (*_webkit_reserved1) (void);
243     void (*_webkit_reserved2) (void);
244     void (*_webkit_reserved3) (void);
245     void (*_webkit_reserved4) (void);
246     void (*_webkit_reserved5) (void);
247 };
248
249 WEBKIT_API GType
250 webkit_web_view_get_type                             (void);
251
252 WEBKIT_API GtkWidget *
253 webkit_web_view_new                                  (void);
254
255 WEBKIT_API GtkWidget *
256 webkit_web_view_new_with_context                     (WebKitWebContext          *context);
257
258 WEBKIT_API GtkWidget *
259 webkit_web_view_new_with_settings                    (WebKitSettings            *settings);
260
261 WEBKIT_API GtkWidget *
262 webkit_web_view_new_with_related_view                (WebKitWebView             *web_view);
263
264 WEBKIT_API GtkWidget *
265 webkit_web_view_new_with_user_content_manager        (WebKitUserContentManager  *user_content_manager);
266
267 WEBKIT_API WebKitWebContext *
268 webkit_web_view_get_context                          (WebKitWebView             *web_view);
269
270 WEBKIT_API void
271 webkit_web_view_load_uri                             (WebKitWebView             *web_view,
272                                                       const gchar               *uri);
273
274 WEBKIT_API void
275 webkit_web_view_load_html                            (WebKitWebView             *web_view,
276                                                       const gchar               *content,
277                                                       const gchar               *base_uri);
278 WEBKIT_API void
279 webkit_web_view_load_alternate_html                  (WebKitWebView             *web_view,
280                                                       const gchar               *content,
281                                                       const gchar               *content_uri,
282                                                       const gchar               *base_uri);
283 WEBKIT_API void
284 webkit_web_view_load_plain_text                      (WebKitWebView             *web_view,
285                                                       const gchar               *plain_text);
286
287 WEBKIT_API void
288 webkit_web_view_load_bytes                           (WebKitWebView             *web_view,
289                                                       GBytes                    *bytes,
290                                                       const gchar               *mime_type,
291                                                       const gchar               *encoding,
292                                                       const gchar               *base_uri);
293
294 WEBKIT_API void
295 webkit_web_view_load_request                         (WebKitWebView             *web_view,
296                                                       WebKitURIRequest          *request);
297
298 WEBKIT_API void
299 webkit_web_view_stop_loading                         (WebKitWebView             *web_view);
300
301 WEBKIT_API gboolean
302 webkit_web_view_is_loading                           (WebKitWebView             *web_view);
303
304 WEBKIT_API guint64
305 webkit_web_view_get_page_id                          (WebKitWebView             *web_view);
306
307 WEBKIT_API const gchar *
308 webkit_web_view_get_title                            (WebKitWebView             *web_view);
309
310 WEBKIT_API void
311 webkit_web_view_reload                               (WebKitWebView             *web_view);
312
313 WEBKIT_API void
314 webkit_web_view_reload_bypass_cache                  (WebKitWebView             *web_view);
315
316 WEBKIT_API gdouble
317 webkit_web_view_get_estimated_load_progress          (WebKitWebView             *web_view);
318
319 WEBKIT_API void
320 webkit_web_view_go_back                              (WebKitWebView             *web_view);
321
322 WEBKIT_API gboolean
323 webkit_web_view_can_go_back                          (WebKitWebView             *web_view);
324
325 WEBKIT_API void
326 webkit_web_view_go_forward                           (WebKitWebView             *web_view);
327
328 WEBKIT_API gboolean
329 webkit_web_view_can_go_forward                       (WebKitWebView             *web_view);
330
331 WEBKIT_API WebKitBackForwardList *
332 webkit_web_view_get_back_forward_list                (WebKitWebView             *web_view);
333
334 WEBKIT_API void
335 webkit_web_view_go_to_back_forward_list_item         (WebKitWebView             *web_view,
336                                                       WebKitBackForwardListItem *list_item);
337 WEBKIT_API const gchar *
338 webkit_web_view_get_uri                              (WebKitWebView             *web_view);
339
340 WEBKIT_API cairo_surface_t *
341 webkit_web_view_get_favicon                          (WebKitWebView             *web_view);
342
343 WEBKIT_API const gchar *
344 webkit_web_view_get_custom_charset                   (WebKitWebView             *web_view);
345
346 WEBKIT_API void
347 webkit_web_view_set_custom_charset                   (WebKitWebView             *web_view,
348                                                       const gchar               *charset);
349
350 WEBKIT_API void
351 webkit_web_view_set_settings                         (WebKitWebView             *web_view,
352                                                       WebKitSettings            *settings);
353
354 WEBKIT_API WebKitSettings *
355 webkit_web_view_get_settings                         (WebKitWebView             *web_view);
356
357 WEBKIT_API WebKitWindowProperties *
358 webkit_web_view_get_window_properties                (WebKitWebView             *web_view);
359
360 WEBKIT_API void
361 webkit_web_view_set_zoom_level                       (WebKitWebView             *web_view,
362                                                       gdouble                    zoom_level);
363 WEBKIT_API gdouble
364 webkit_web_view_get_zoom_level                       (WebKitWebView             *web_view);
365
366 WEBKIT_API void
367 webkit_web_view_can_execute_editing_command          (WebKitWebView             *web_view,
368                                                       const gchar               *command,
369                                                       GCancellable              *cancellable,
370                                                       GAsyncReadyCallback        callback,
371                                                       gpointer                   user_data);
372
373 WEBKIT_API gboolean
374 webkit_web_view_can_execute_editing_command_finish   (WebKitWebView             *web_view,
375                                                       GAsyncResult              *result,
376                                                       GError                   **error);
377
378 WEBKIT_API void
379 webkit_web_view_execute_editing_command              (WebKitWebView             *web_view,
380                                                       const gchar               *command);
381
382 WEBKIT_API WebKitFindController *
383 webkit_web_view_get_find_controller                  (WebKitWebView             *web_view);
384
385 WEBKIT_API JSGlobalContextRef
386 webkit_web_view_get_javascript_global_context        (WebKitWebView             *web_view);
387
388 WEBKIT_API void
389 webkit_web_view_run_javascript                       (WebKitWebView             *web_view,
390                                                       const gchar               *script,
391                                                       GCancellable              *cancellable,
392                                                       GAsyncReadyCallback        callback,
393                                                       gpointer                   user_data);
394 WEBKIT_API WebKitJavascriptResult *
395 webkit_web_view_run_javascript_finish                (WebKitWebView             *web_view,
396                                                       GAsyncResult              *result,
397                                                       GError                   **error);
398
399 WEBKIT_API void
400 webkit_web_view_run_javascript_from_gresource        (WebKitWebView             *web_view,
401                                                       const gchar               *resource,
402                                                       GCancellable              *cancellable,
403                                                       GAsyncReadyCallback        callback,
404                                                       gpointer                   user_data);
405
406 WEBKIT_API WebKitJavascriptResult *
407 webkit_web_view_run_javascript_from_gresource_finish (WebKitWebView             *web_view,
408                                                       GAsyncResult              *result,
409                                                       GError                   **error);
410
411 WEBKIT_API WebKitWebResource *
412 webkit_web_view_get_main_resource                    (WebKitWebView             *web_view);
413
414 WEBKIT_API WebKitWebInspector *
415 webkit_web_view_get_inspector                        (WebKitWebView             *web_view);
416
417 WEBKIT_API gboolean
418 webkit_web_view_can_show_mime_type                   (WebKitWebView             *web_view,
419                                                       const gchar               *mime_type);
420
421 WEBKIT_API void
422 webkit_web_view_save                                 (WebKitWebView             *web_view,
423                                                       WebKitSaveMode             save_mode,
424                                                       GCancellable              *cancellable,
425                                                       GAsyncReadyCallback        callback,
426                                                       gpointer                   user_data);
427
428 WEBKIT_API GInputStream *
429 webkit_web_view_save_finish                          (WebKitWebView             *web_view,
430                                                       GAsyncResult              *result,
431                                                       GError                   **error);
432
433 WEBKIT_API void
434 webkit_web_view_save_to_file                         (WebKitWebView             *web_view,
435                                                       GFile                     *file,
436                                                       WebKitSaveMode             save_mode,
437                                                       GCancellable              *cancellable,
438                                                       GAsyncReadyCallback        callback,
439                                                       gpointer                   user_data);
440
441 WEBKIT_API gboolean
442 webkit_web_view_save_to_file_finish                  (WebKitWebView             *web_view,
443                                                       GAsyncResult              *result,
444                                                       GError                   **error);
445
446 WEBKIT_API WebKitDownload *
447 webkit_web_view_download_uri                         (WebKitWebView             *web_view,
448                                                       const char                *uri);
449
450 WEBKIT_API gboolean
451 webkit_web_view_get_tls_info                         (WebKitWebView             *web_view,
452                                                       GTlsCertificate          **certificate,
453                                                       GTlsCertificateFlags      *errors);
454 WEBKIT_API void
455 webkit_web_view_get_snapshot                         (WebKitWebView             *web_view,
456                                                       WebKitSnapshotRegion       region,
457                                                       WebKitSnapshotOptions      options,
458                                                       GCancellable              *cancellable,
459                                                       GAsyncReadyCallback        callback,
460                                                       gpointer                   user_data);
461
462 WEBKIT_API cairo_surface_t *
463 webkit_web_view_get_snapshot_finish                  (WebKitWebView             *web_view,
464                                                       GAsyncResult              *result,
465                                                       GError                   **error);
466
467 WEBKIT_API WebKitUserContentManager *
468 webkit_web_view_get_user_content_manager             (WebKitWebView             *web_view);
469
470 G_END_DECLS
471
472 #endif