Global functions: WebKitGTK+ Reference Manual

## Global functions Global functions — Global functions controlling WebKit |

## Functions

SoupSession * | webkit_get_default_session ()
guint64 | webkit_get_default_web_database_quota ()
const gchar * | webkit_get_web_database_directory_path ()
WebKitWebPluginDatabase * | webkit_get_web_plugin_database ()
void | webkit_remove_all_web_databases ()
void | webkit_set_default_web_database_quota ()
void | webkit_set_web_database_directory_path ()
WebKitFaviconDatabase * | webkit_get_favicon_database ()
WebKitIconDatabase * | webkit_get_icon_database ()
GObject * | webkit_get_text_checker ()
void | webkit_set_text_checker ()
const gchar * | webkit_application_cache_get_database_directory_path ()
unsigned long long | webkit_application_cache_get_maximum_size ()
void | webkit_application_cache_set_maximum_size ()
WebKitCacheModel | webkit_get_cache_model ()
void | webkit_set_cache_model ()
WebKitContextMenuAction | webkit_context_menu_item_get_action ()
void | webkit_set_security_policy_for_uri_scheme ()
WebKitSecurityPolicy | webkit_get_security_policy_for_uri_scheme ()

## Types and Values

enum | WebKitCacheModel
enum | WebKitContextMenuAction
enum | WebKitSecurityPolicy

## Description

WebKit manages many resources which are not related to specific views. These functions relate to cross-view limits, such as cache sizes, database quotas, and the HTTP session management.

## Functions

### webkit_get_default_session ()

    SoupSession *
    webkit_get_default_session (void);

Retrieves the default SoupSession used by all web views. Note that the session features are added by WebKit on demand, so if you insert your own SoupCookieJar before any network traffic occurs, WebKit will use it instead of the default.

#### Returns

the default SoupSession.

[transfer none]

Since: 1.1.1

### webkit_get_default_web_database_quota ()

    guint64
    webkit_get_default_web_database_quota (void);

Returns the default quota for Web Database databases. By default this value is 5MB.

#### Returns

the current default database quota in bytes

Since: 1.1.14

### webkit_get_web_database_directory_path ()

    const gchar *
    webkit_get_web_database_directory_path
                                   (void);

Returns the current path to the directory WebKit will write Web Database and Indexed Database databases. By default this path will be in the user data directory.

#### Returns

the current database directory path in the filesystem encoding

Since: 1.1.14

### webkit_get_web_plugin_database ()

    WebKitWebPluginDatabase *
    webkit_get_web_plugin_database (void);

Returns the current WebKitWebPluginDatabase with information about all the plugins WebKit knows about in this instance.

#### Returns

the current WebKitWebPluginDatabase.

[transfer none]

Since: 1.3.8

### webkit_remove_all_web_databases ()

    void
    webkit_remove_all_web_databases (void);

Removes all web databases from the current database directory path.

Since: 1.1.14

### webkit_set_default_web_database_quota ()

    void
    webkit_set_default_web_database_quota (guint64 defaultQuota);

Sets the default quota for Web Database databases.

#### Parameters

defaultQuota | the new default database quota |

Since: 1.1.14

### webkit_set_web_database_directory_path ()

    void
    webkit_set_web_database_directory_path
                                   (const gchar *path);

Sets the current path to the directory WebKit will write Web Database and Indexed Database databases.

#### Parameters

path | the new database directory path in the filesystem encoding |

Since: 1.1.14

### webkit_get_favicon_database ()

    WebKitFaviconDatabase *
    webkit_get_favicon_database (void);

Returns the WebKitFaviconDatabase providing access to website icons.

#### Returns

the current WebKitFaviconDatabase.

[transfer none]

Since: 1.8

### webkit_get_icon_database ()

    WebKitIconDatabase *
    webkit_get_icon_database (void);

`webkit_get_icon_database` has been deprecated since version 1.8 and should not be used in newly-written code.

Use `webkit_get_favicon_database()` instead

Returns the WebKitIconDatabase providing access to website icons.

#### Returns

the current WebKitIconDatabase.

[transfer none]

Since: 1.3.13

### webkit_get_text_checker ()

    GObject *
    webkit_get_text_checker (void);

#### Returns

the WebKitSpellChecker used by WebKit, or `NULL` if spell checking is not enabled.

[transfer none]

Since: 1.5.1

### webkit_set_text_checker ()

    void
    webkit_set_text_checker (GObject *checker);

Sets `checker` as the spell checker to be used by WebKit. The API accepts GObject since in the future we might accept objects implementing multiple interfaces (for example, spell checking and grammar checking).

#### Parameters

checker | a WebKitSpellChecker or `NULL` |

Since: 1.5.1

### webkit_application_cache_get_database_directory_path ()

    const gchar *
    webkit_application_cache_get_database_directory_path
                                   (void);

Returns the path to the directory WebKit will write web application cache databases to. By default this path is set to $XDG_CACHE_HOME/webkitgtk/applications and cannot be modified.

#### Returns

the application cache database directory path

Since: 1.3.13

### webkit_application_cache_get_maximum_size ()

    unsigned long long
    webkit_application_cache_get_maximum_size
                                   (void);

Returns the maximum size of the cache storage. By default it is set to UINT_MAX i.e. no quota.

#### Returns

the current application cache maximum storage size

Since: 1.3.13

### webkit_application_cache_set_maximum_size ()

    void
    webkit_application_cache_set_maximum_size
                                   (unsigned long long  size);

Sets new application cache maximum storage size. Changing the application cache storage size will clear the cache and rebuild cache storage.

#### Parameters

size | the new web application cache maximum storage size |

Since: 1.3.13

### webkit_get_cache_model ()

    WebKitCacheModel
    webkit_get_cache_model (void);

Returns the current cache model. For more information about this value check the documentation of the function `webkit_set_cache_model()`.

#### Returns

the current WebKitCacheModel

Since: 1.1.18

### webkit_set_cache_model ()

    void
    webkit_set_cache_model (WebKitCacheModel cache_model);

Specifies a usage model for WebViews, which WebKit will use to determine its caching behavior. All web views follow the cache model. This cache model determines the RAM and disk space to use for caching previously viewed content .

Research indicates that users tend to browse within clusters of documents that hold resources in common, and to revisit previously visited documents. WebKit and the frameworks below it include built-in caches that take advantage of these patterns, substantially improving document load speed in browsing situations. The WebKit cache model controls the behaviors of all of these caches, including various WebCore caches.

Browsers can improve document load speed substantially by specifying WEBKIT_CACHE_MODEL_WEB_BROWSER. Applications without a browsing interface can reduce memory usage substantially by specifying WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER. Default value is WEBKIT_CACHE_MODEL_WEB_BROWSER.

#### Parameters

cache_model | a WebKitCacheModel |

Since: 1.1.18

### webkit_context_menu_item_get_action ()

    WebKitContextMenuAction
    webkit_context_menu_item_get_action (GtkMenuItem *item);

Returns the WebKitContextMenuAction of the given `item` . This function can be used to determine the items present in the default context menu. In order to inspect the default context menu, you should connect to “context-menu” signal.

Example 1. Inspecting the default context menu

    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
    static gboolean context_menu_cb (WebKitWebView       *webView,
                                     GtkWidget           *default_menu,
                                     WebKitHitTestResult *hit_test_result,
                                     gboolean             triggered_with_keyboard,
                                     gpointer             user_data)
    {
        GList *items = gtk_container_get_children (GTK_CONTAINER (default_menu));
        GList *l;
        GtkAction *action;
        GtkWidget *sub_menu;

        for (l = items; l; l = g_list_next (l)) {
            GtkMenuItem *item = (GtkMenuItem *)l->data;

            if (GTK_IS_SEPARATOR_MENU_ITEM (item)) {
                /* It's  separator, do nothing */
                continue;
            }

            switch (webkit_context_menu_item_get_action (item)) {
            case WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION:
                /* No action for this item */
                break;
            /* Don't allow to ope links from context menu */
            case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK:
            case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW:
                action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
                gtk_action_set_sensitive (action, FALSE);
                break;
            default:
                break;
            }

            sub_menu = gtk_menu_item_get_submenu (item);
            if (sub_menu) {
                GtkWidget *menu_item;

                /* Add custom action to submenu */
                action = gtk_action_new ("CustomItemName", "Custom Action", NULL, NULL);
                g_signal_connect (action, "activate", G_CALLBACK (custom_menu_item_activated), NULL);

                menu_item = gtk_action_create_menu_item (action);
                g_object_unref (action);
                gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
                gtk_widget_show (menu_item);
            }
        }

        g_list_free(items);
    }

Note that you can get the GtkAction of any item in the default context menu with `gtk_activatable_get_related_action()`.

#### Parameters

item | a GtkMenuItem of the default context menu |

#### Returns

the WebKitContextMenuAction of the given `item`

Since: 1.10

### webkit_set_security_policy_for_uri_scheme ()

    void
    webkit_set_security_policy_for_uri_scheme
                                   (const gchar *scheme,
                                    WebKitSecurityPolicy policy);

Set the security policy for the given URI scheme.

#### Parameters

scheme | a URI scheme |
policy | a WebKitSecurityPolicy |

Since: 2.0

### webkit_get_security_policy_for_uri_scheme ()

    WebKitSecurityPolicy
    webkit_get_security_policy_for_uri_scheme
                                   (const gchar *scheme);

Get the security policy for the given URI scheme.

#### Parameters

scheme | a URI scheme |

#### Returns

a WebKitSecurityPolicy

Since: 2.0

## Types and Values

### enum WebKitCacheModel

Enum values used for determining the webview cache model.

#### Members

WEBKIT_CACHE_MODEL_DEFAULT | The default cache model. This is WEBKIT_CACHE_MODEL_WEB_BROWSER. |
WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER | Disable 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. |
WEBKIT_CACHE_MODEL_WEB_BROWSER | Improve document load speed substantially by caching a very large number of resources and previously viewed content. |
WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER | A cache model optimized for viewing a series of local files -- for example, a documentation viewer or a website designer. WebKit will cache a moderate number of resources. |

### enum WebKitContextMenuAction

Enum values used to denote actions of items in the default context menu.

#### Members

WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION | No action, used by separator menu items. |
WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK | Open current link. |
WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW | Open current link in a new window. |
WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK | Download link destination. |
WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD | Copy link location to the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW | Open current image in a new window. |
WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK | Download current image. |
WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD | Copy current image to the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD | Copy curent image location to the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_OPEN_FRAME_IN_NEW_WINDOW | Open current frame in a new window. |
WEBKIT_CONTEXT_MENU_ACTION_GO_BACK | Load the previous history item. |
WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD | Load the next history item. |
WEBKIT_CONTEXT_MENU_ACTION_STOP | Stop any ongoing loading operation. |
WEBKIT_CONTEXT_MENU_ACTION_RELOAD | Reload the conents of current view. |
WEBKIT_CONTEXT_MENU_ACTION_COPY | Copy current selection the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_CUT | Cut current selection to the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_PASTE | Paste clipboard contents. |
WEBKIT_CONTEXT_MENU_ACTION_DELETE | Delete current selection. |
WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL | Select all text. |
WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS | Input methods menu. |
WEBKIT_CONTEXT_MENU_ACTION_UNICODE | Unicode menu. |
WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS | Guess spelling. |
WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND | No guesses found. |
WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING | Ignore spelling. |
WEBKIT_CONTEXT_MENU_ACTION_LEARN_SPELLING | Learn spelling. |
WEBKIT_CONTEXT_MENU_ACTION_IGNORE_GRAMMAR | Ignore grammar. |
WEBKIT_CONTEXT_MENU_ACTION_FONT_MENU | Font menu. |
WEBKIT_CONTEXT_MENU_ACTION_BOLD | Bold. |
WEBKIT_CONTEXT_MENU_ACTION_ITALIC | Italic. |
WEBKIT_CONTEXT_MENU_ACTION_UNDERLINE | Underline. |
WEBKIT_CONTEXT_MENU_ACTION_OUTLINE | Outline. |
WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT | Open current element in the inspector. |
WEBKIT_CONTEXT_MENU_ACTION_OPEN_MEDIA_IN_NEW_WINDOW | Open current media element in a new window. |
WEBKIT_CONTEXT_MENU_ACTION_COPY_MEDIA_LINK_TO_CLIPBOARD | Copy media link location in to the clipboard. |
WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS | Enable or disable media controls. |
WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP | Enable or disable media loop. |
WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN | Show current video element in fullscreen mode. |
WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY_PAUSE | Play or pause current media element. |
WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE | Mute current media element. |

Since: 1.10

### enum WebKitSecurityPolicy

Flags used to represent the security policy of a URI scheme.

#### Members

WEBKIT_SECURITY_POLICY_LOCAL | Local URI scheme, other non-local pages cannot link to or access URIs of this scheme. |
WEBKIT_SECURITY_POLICY_NO_ACCESS_TO_OTHER_SCHEME | Pages loaded with this URI scheme cannot access pages loaded with any other URI scheme. |
WEBKIT_SECURITY_POLICY_DISPLAY_ISOLATED | Pages cannot display these URIs unless they are from the same scheme. |
WEBKIT_SECURITY_POLICY_SECURE | Secure URI scheme, doesn't generate mixed content warnings when included by an HTTPS page. |
WEBKIT_SECURITY_POLICY_CORS_ENABLED | URI scheme that can be sent CORS (Cross-origin resource sharing) requests. See W3C CORS specification http://www.w3.org/TR/cors/. |
WEBKIT_SECURITY_POLICY_EMPTY_DOCUMENT | Strictly empty documents allowed to commit synchronously. |

Since: 2.0