2 * Copyright (C) 2008 Christian Dywan <christian@imendio.com>
3 * Copyright (C) 2008 Nuanti Ltd.
4 * Copyright (C) 2008 Collabora Ltd.
5 * Copyright (C) 2008 Holger Hans Peter Freyther
6 * Copyright (C) 2009 Jan Michael Alonzo
7 * Copyright (C) 2009 Movial Creative Technologies Inc.
8 * Copyright (C) 2009 Igalia S.L.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
27 #include "webkitwebsettings.h"
29 #include "EditingBehavior.h"
30 #include "FileSystem.h"
32 #include "PluginDatabase.h"
33 #include "webkitenumtypes.h"
34 #include "webkitglobalsprivate.h"
35 #include "webkitversion.h"
36 #include "webkitwebsettingsprivate.h"
37 #include <wtf/text/CString.h>
38 #include <wtf/text/StringConcatenate.h>
39 #include <glib/gi18n-lib.h>
42 #include <sys/utsname.h>
46 * SECTION:webkitwebsettings
47 * @short_description: Control the behaviour of a #WebKitWebView
49 * #WebKitWebSettings can be applied to a #WebKitWebView to control text encoding,
50 * color, font sizes, printing mode, script support, loading of images and various other things.
51 * After creation, a #WebKitWebSettings object contains default settings.
53 * <informalexample><programlisting>
54 * /<!-- -->* Create a new websettings and disable java script *<!-- -->/
55 * WebKitWebSettings *settings = webkit_web_settings_new ();
56 * g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);
58 * /<!-- -->* Apply the result *<!-- -->/
59 * webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
60 * </programlisting></informalexample>
63 using namespace WebCore;
65 G_DEFINE_TYPE(WebKitWebSettings, webkit_web_settings, G_TYPE_OBJECT)
67 struct _WebKitWebSettingsPrivate {
68 gchar* default_encoding;
69 gchar* cursive_font_family;
70 gchar* default_font_family;
71 gchar* fantasy_font_family;
72 gchar* monospace_font_family;
73 gchar* sans_serif_font_family;
74 gchar* serif_font_family;
75 guint default_font_size;
76 guint default_monospace_font_size;
77 guint minimum_font_size;
78 guint minimum_logical_font_size;
79 gboolean enforce_96_dpi;
80 gboolean auto_load_images;
81 gboolean auto_shrink_images;
82 gboolean print_backgrounds;
83 gboolean enable_scripts;
84 gboolean enable_plugins;
85 gboolean resizable_text_areas;
86 gchar* user_stylesheet_uri;
88 gboolean enable_developer_extras;
89 gboolean enable_private_browsing;
90 gboolean enable_spell_checking;
91 gchar* spell_checking_languages;
92 gboolean enable_caret_browsing;
93 gboolean enable_html5_database;
94 gboolean enable_html5_local_storage;
95 gboolean enable_xss_auditor;
96 gboolean enable_spatial_navigation;
97 gboolean enable_frame_flattening;
99 gboolean javascript_can_open_windows_automatically;
100 gboolean javascript_can_access_clipboard;
101 gboolean enable_offline_web_application_cache;
102 WebKitEditingBehavior editing_behavior;
103 gboolean enable_universal_access_from_file_uris;
104 gboolean enable_file_access_from_file_uris;
105 gboolean enable_dom_paste;
106 gboolean tab_key_cycles_through_elements;
107 gboolean enable_default_context_menu;
108 gboolean enable_site_specific_quirks;
109 gboolean enable_page_cache;
110 gboolean auto_resize_window;
111 gboolean enable_java_applet;
112 gboolean enable_hyperlink_auditing;
113 gboolean enable_fullscreen;
116 #define WEBKIT_WEB_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate))
121 PROP_DEFAULT_ENCODING,
122 PROP_CURSIVE_FONT_FAMILY,
123 PROP_DEFAULT_FONT_FAMILY,
124 PROP_FANTASY_FONT_FAMILY,
125 PROP_MONOSPACE_FONT_FAMILY,
126 PROP_SANS_SERIF_FONT_FAMILY,
127 PROP_SERIF_FONT_FAMILY,
128 PROP_DEFAULT_FONT_SIZE,
129 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
130 PROP_MINIMUM_FONT_SIZE,
131 PROP_MINIMUM_LOGICAL_FONT_SIZE,
133 PROP_AUTO_LOAD_IMAGES,
134 PROP_AUTO_SHRINK_IMAGES,
135 PROP_PRINT_BACKGROUNDS,
138 PROP_RESIZABLE_TEXT_AREAS,
139 PROP_USER_STYLESHEET_URI,
141 PROP_ENABLE_DEVELOPER_EXTRAS,
142 PROP_ENABLE_PRIVATE_BROWSING,
143 PROP_ENABLE_SPELL_CHECKING,
144 PROP_SPELL_CHECKING_LANGUAGES,
145 PROP_ENABLE_CARET_BROWSING,
146 PROP_ENABLE_HTML5_DATABASE,
147 PROP_ENABLE_HTML5_LOCAL_STORAGE,
148 PROP_ENABLE_XSS_AUDITOR,
149 PROP_ENABLE_SPATIAL_NAVIGATION,
150 PROP_ENABLE_FRAME_FLATTENING,
152 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
153 PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD,
154 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE,
155 PROP_EDITING_BEHAVIOR,
156 PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS,
157 PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS,
158 PROP_ENABLE_DOM_PASTE,
159 PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS,
160 PROP_ENABLE_DEFAULT_CONTEXT_MENU,
161 PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
162 PROP_ENABLE_PAGE_CACHE,
163 PROP_AUTO_RESIZE_WINDOW,
164 PROP_ENABLE_JAVA_APPLET,
165 PROP_ENABLE_HYPERLINK_AUDITING,
166 PROP_ENABLE_FULLSCREEN
169 // Create a default user agent string
170 // This is a liberal interpretation of http://www.mozilla.org/build/revised-user-agent-strings.html
171 // See also http://developer.apple.com/internet/safari/faq.html#anchor2
172 static String webkitPlatform()
175 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("X11")));
177 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Windows")));
179 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Macintosh")));
180 #elif defined(GDK_WINDOWING_DIRECTFB)
181 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("DirectFB")));
183 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Unknown")));
189 static String webkitOSVersion()
191 // FIXME: platform/version detection can be shared.
195 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Intel Mac OS X")));
197 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("PPC Mac OS X")));
201 DEFINE_STATIC_LOCAL(String, uaOSVersion, (String()));
203 if (!uaOSVersion.isEmpty())
207 if (uname(&name) != -1)
208 uaOSVersion = makeString(name.sysname, ' ', name.machine);
210 uaOSVersion = String("Unknown");
212 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Windows")));
214 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Unknown")));
220 String webkitUserAgent()
222 // We mention Safari since many broken sites check for it (OmniWeb does this too)
223 // We re-use the WebKit version, though it doesn't seem to matter much in practice
225 DEFINE_STATIC_LOCAL(const String, uaVersion, (makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.', String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+')));
226 DEFINE_STATIC_LOCAL(const String, staticUA, (makeString("Mozilla/5.0 (", webkitPlatform(), "; U; ", webkitOSVersion(), "; ", defaultLanguage(), ") AppleWebKit/", uaVersion) +
227 makeString(" (KHTML, like Gecko) Version/5.0 Safari/", uaVersion)));
232 static void webkit_web_settings_finalize(GObject* object);
234 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
236 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
238 static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass)
240 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
241 gobject_class->finalize = webkit_web_settings_finalize;
242 gobject_class->set_property = webkit_web_settings_set_property;
243 gobject_class->get_property = webkit_web_settings_get_property;
247 GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
249 g_object_class_install_property(gobject_class,
250 PROP_DEFAULT_ENCODING,
253 _("Default Encoding"),
254 _("The default encoding used to display text."),
258 g_object_class_install_property(gobject_class,
259 PROP_CURSIVE_FONT_FAMILY,
261 "cursive-font-family",
262 _("Cursive Font Family"),
263 _("The default Cursive font family used to display text."),
267 g_object_class_install_property(gobject_class,
268 PROP_DEFAULT_FONT_FAMILY,
270 "default-font-family",
271 _("Default Font Family"),
272 _("The default font family used to display text."),
276 g_object_class_install_property(gobject_class,
277 PROP_FANTASY_FONT_FAMILY,
279 "fantasy-font-family",
280 _("Fantasy Font Family"),
281 _("The default Fantasy font family used to display text."),
285 g_object_class_install_property(gobject_class,
286 PROP_MONOSPACE_FONT_FAMILY,
288 "monospace-font-family",
289 _("Monospace Font Family"),
290 _("The default font family used to display monospace text."),
294 g_object_class_install_property(gobject_class,
295 PROP_SANS_SERIF_FONT_FAMILY,
297 "sans-serif-font-family",
298 _("Sans Serif Font Family"),
299 _("The default Sans Serif font family used to display text."),
303 g_object_class_install_property(gobject_class,
304 PROP_SERIF_FONT_FAMILY,
307 _("Serif Font Family"),
308 _("The default Serif font family used to display text."),
312 g_object_class_install_property(gobject_class,
313 PROP_DEFAULT_FONT_SIZE,
316 _("Default Font Size"),
317 _("The default font size used to display text."),
321 g_object_class_install_property(gobject_class,
322 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
324 "default-monospace-font-size",
325 _("Default Monospace Font Size"),
326 _("The default font size used to display monospace text."),
330 g_object_class_install_property(gobject_class,
331 PROP_MINIMUM_FONT_SIZE,
334 _("Minimum Font Size"),
335 _("The minimum font size used to display text."),
339 g_object_class_install_property(gobject_class,
340 PROP_MINIMUM_LOGICAL_FONT_SIZE,
342 "minimum-logical-font-size",
343 _("Minimum Logical Font Size"),
344 _("The minimum logical font size used to display text."),
349 * WebKitWebSettings:enforce-96-dpi:
351 * Enforce a resolution of 96 DPI. This is meant for compatibility
352 * with web pages which cope badly with different screen resolutions
353 * and for automated testing.
354 * Web browsers and applications that typically display arbitrary
355 * content from the web should provide a preference for this.
359 g_object_class_install_property(gobject_class,
361 g_param_spec_boolean(
364 _("Enforce a resolution of 96 DPI"),
368 g_object_class_install_property(gobject_class,
369 PROP_AUTO_LOAD_IMAGES,
370 g_param_spec_boolean(
372 _("Auto Load Images"),
373 _("Load images automatically."),
377 g_object_class_install_property(gobject_class,
378 PROP_AUTO_SHRINK_IMAGES,
379 g_param_spec_boolean(
380 "auto-shrink-images",
381 _("Auto Shrink Images"),
382 _("Automatically shrink standalone images to fit."),
386 g_object_class_install_property(gobject_class,
387 PROP_PRINT_BACKGROUNDS,
388 g_param_spec_boolean(
390 _("Print Backgrounds"),
391 _("Whether background images should be printed."),
395 g_object_class_install_property(gobject_class,
397 g_param_spec_boolean(
400 _("Enable embedded scripting languages."),
404 g_object_class_install_property(gobject_class,
406 g_param_spec_boolean(
409 _("Enable embedded plugin objects."),
413 g_object_class_install_property(gobject_class,
414 PROP_RESIZABLE_TEXT_AREAS,
415 g_param_spec_boolean(
416 "resizable-text-areas",
417 _("Resizable Text Areas"),
418 _("Whether text areas are resizable."),
422 g_object_class_install_property(gobject_class,
423 PROP_USER_STYLESHEET_URI,
424 g_param_spec_string("user-stylesheet-uri",
425 _("User Stylesheet URI"),
426 _("The URI of a stylesheet that is applied to every page."),
431 * WebKitWebSettings:zoom-step:
433 * The value by which the zoom level is changed when zooming in or out.
437 g_object_class_install_property(gobject_class,
441 _("Zoom Stepping Value"),
442 _("The value by which the zoom level is changed when zooming in or out."),
443 0.0f, G_MAXFLOAT, 0.1f,
447 * WebKitWebSettings:enable-developer-extras:
449 * Whether developer extensions should be enabled. This enables,
450 * for now, the Web Inspector, which can be controlled using the
451 * #WebKitWebInspector instance held by the #WebKitWebView this
452 * setting is enabled for.
456 g_object_class_install_property(gobject_class,
457 PROP_ENABLE_DEVELOPER_EXTRAS,
458 g_param_spec_boolean(
459 "enable-developer-extras",
460 _("Enable Developer Extras"),
461 _("Enables special extensions that help developers"),
466 * WebKitWebSettings:enable-private-browsing:
468 * Whether to enable private browsing mode. Private browsing mode prevents
469 * WebKit from updating the global history and storing any session
470 * information e.g., on-disk cache, as well as suppressing any messages
471 * from being printed into the (javascript) console.
473 * This is currently experimental for WebKitGtk.
477 g_object_class_install_property(gobject_class,
478 PROP_ENABLE_PRIVATE_BROWSING,
479 g_param_spec_boolean(
480 "enable-private-browsing",
481 _("Enable Private Browsing"),
482 _("Enables private browsing mode"),
487 * WebKitWebSettings:enable-spell-checking:
489 * Whether to enable spell checking while typing.
493 g_object_class_install_property(gobject_class,
494 PROP_ENABLE_SPELL_CHECKING,
495 g_param_spec_boolean(
496 "enable-spell-checking",
497 _("Enable Spell Checking"),
498 _("Enables spell checking while typing"),
503 * WebKitWebSettings:spell-checking-languages:
505 * The languages to be used for spell checking, separated by commas.
507 * The locale string typically is in the form lang_COUNTRY, where lang
508 * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
509 * For instance, sv_FI for Swedish as written in Finland or pt_BR
510 * for Portuguese as written in Brazil.
512 * If no value is specified then the value returned by
513 * gtk_get_default_language will be used.
517 g_object_class_install_property(gobject_class,
518 PROP_SPELL_CHECKING_LANGUAGES,
520 "spell-checking-languages",
521 _("Languages to use for spell checking"),
522 _("Comma separated list of languages to use for spell checking"),
527 * WebKitWebSettings:enable-caret-browsing:
529 * Whether to enable caret browsing mode.
533 g_object_class_install_property(gobject_class,
534 PROP_ENABLE_CARET_BROWSING,
535 g_param_spec_boolean("enable-caret-browsing",
536 _("Enable Caret Browsing"),
537 _("Whether to enable accessibility enhanced keyboard navigation"),
541 * WebKitWebSettings:enable-html5-database:
543 * Whether to enable HTML5 client-side SQL database support. Client-side
544 * SQL database allows web pages to store structured data and be able to
545 * use SQL to manipulate that data asynchronously.
549 g_object_class_install_property(gobject_class,
550 PROP_ENABLE_HTML5_DATABASE,
551 g_param_spec_boolean("enable-html5-database",
552 _("Enable HTML5 Database"),
553 _("Whether to enable HTML5 database support"),
558 * WebKitWebSettings:enable-html5-local-storage:
560 * Whether to enable HTML5 localStorage support. localStorage provides
561 * simple synchronous storage access.
565 g_object_class_install_property(gobject_class,
566 PROP_ENABLE_HTML5_LOCAL_STORAGE,
567 g_param_spec_boolean("enable-html5-local-storage",
568 _("Enable HTML5 Local Storage"),
569 _("Whether to enable HTML5 Local Storage support"),
573 * WebKitWebSettings:enable-xss-auditor
575 * Whether to enable the XSS Auditor. This feature filters some kinds of
576 * reflective XSS attacks on vulnerable web sites.
580 g_object_class_install_property(gobject_class,
581 PROP_ENABLE_XSS_AUDITOR,
582 g_param_spec_boolean("enable-xss-auditor",
583 _("Enable XSS Auditor"),
584 _("Whether to enable the XSS auditor"),
588 * WebKitWebSettings:enable-spatial-navigation
590 * Whether to enable the Spatial Navigation. This feature consists in the ability
591 * to navigate between focusable elements in a Web page, such as hyperlinks and
592 * form controls, by using Left, Right, Up and Down arrow keys. For example, if
593 * an user presses the Right key, heuristics determine whether there is an element
594 * he might be trying to reach towards the right, and if there are multiple elements,
595 * which element he probably wants.
599 g_object_class_install_property(gobject_class,
600 PROP_ENABLE_SPATIAL_NAVIGATION,
601 g_param_spec_boolean("enable-spatial-navigation",
602 _("Enable Spatial Navigation"),
603 _("Whether to enable Spatial Navigation"),
607 * WebKitWebSettings:enable-frame-flattening
609 * Whether to enable the Frame Flattening. With this setting each subframe is expanded
610 * to its contents, which will flatten all the frames to become one scrollable page.
611 * On touch devices, it is desired to not have any scrollable sub parts of the page as
612 * it results in a confusing user experience, with scrolling sometimes scrolling sub parts
613 * and at other times scrolling the page itself. For this reason iframes and framesets are
614 * barely usable on touch devices.
618 g_object_class_install_property(gobject_class,
619 PROP_ENABLE_FRAME_FLATTENING,
620 g_param_spec_boolean("enable-frame-flattening",
621 _("Enable Frame Flattening"),
622 _("Whether to enable Frame Flattening"),
626 * WebKitWebSettings:user-agent:
628 * The User-Agent string used by WebKitGtk.
630 * This will return a default User-Agent string if a custom string wasn't
631 * provided by the application. Setting this property to a NULL value or
632 * an empty string will result in the User-Agent string being reset to the
637 g_object_class_install_property(gobject_class, PROP_USER_AGENT,
638 g_param_spec_string("user-agent",
640 _("The User-Agent string used by WebKitGtk"),
641 webkitUserAgent().utf8().data(),
645 * WebKitWebSettings:javascript-can-open-windows-automatically
647 * Whether JavaScript can open popup windows automatically without user
652 g_object_class_install_property(gobject_class,
653 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
654 g_param_spec_boolean("javascript-can-open-windows-automatically",
655 _("JavaScript can open windows automatically"),
656 _("Whether JavaScript can open windows automatically"),
661 * WebKitWebSettings:javascript-can-access-clipboard
663 * Whether JavaScript can access Clipboard.
667 g_object_class_install_property(gobject_class,
668 PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD,
669 g_param_spec_boolean("javascript-can-access-clipboard",
670 _("JavaScript can access Clipboard"),
671 _("Whether JavaScript can access Clipboard"),
676 * WebKitWebSettings:enable-offline-web-application-cache
678 * Whether to enable HTML5 offline web application cache support. Offline
679 * Web Application Cache ensures web applications are available even when
680 * the user is not connected to the network.
684 g_object_class_install_property(gobject_class,
685 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE,
686 g_param_spec_boolean("enable-offline-web-application-cache",
687 _("Enable offline web application cache"),
688 _("Whether to enable offline web application cache"),
694 * WebKitWebSettings:editing-behavior
696 * This setting controls various editing behaviors that differ
697 * between platforms and that have been combined in two groups,
698 * 'Mac' and 'Windows'. Some examples:
700 * 1) Clicking below the last line of an editable area puts the
701 * caret at the end of the last line on Mac, but in the middle of
702 * the last line on Windows.
704 * 2) Pushing down the arrow key on the last line puts the caret
705 * at the end of the last line on Mac, but does nothing on
706 * Windows. A similar case exists on the top line.
710 g_object_class_install_property(gobject_class,
711 PROP_EDITING_BEHAVIOR,
712 g_param_spec_enum("editing-behavior",
713 _("Editing behavior"),
714 _("The behavior mode to use in editing mode"),
715 WEBKIT_TYPE_EDITING_BEHAVIOR,
716 WEBKIT_EDITING_BEHAVIOR_UNIX,
720 * WebKitWebSettings:enable-universal-access-from-file-uris
722 * Whether to allow files loaded through file:// URIs universal access to
727 g_object_class_install_property(gobject_class,
728 PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS,
729 g_param_spec_boolean("enable-universal-access-from-file-uris",
730 _("Enable universal access from file URIs"),
731 _("Whether to allow universal access from file URIs"),
736 * WebKitWebSettings:enable-dom-paste
738 * Whether to enable DOM paste. If set to %TRUE, document.execCommand("Paste")
739 * will correctly execute and paste content of the clipboard.
743 g_object_class_install_property(gobject_class,
744 PROP_ENABLE_DOM_PASTE,
745 g_param_spec_boolean("enable-dom-paste",
746 _("Enable DOM paste"),
747 _("Whether to enable DOM paste"),
751 * WebKitWebSettings:tab-key-cycles-through-elements:
753 * Whether the tab key cycles through elements on the page.
755 * If @flag is %TRUE, pressing the tab key will focus the next element in
756 * the @web_view. If @flag is %FALSE, the @web_view will interpret tab
757 * key presses as normal key presses. If the selected element is editable, the
758 * tab key will cause the insertion of a tab character.
762 g_object_class_install_property(gobject_class,
763 PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS,
764 g_param_spec_boolean("tab-key-cycles-through-elements",
765 _("Tab key cycles through elements"),
766 _("Whether the tab key cycles through elements on the page."),
771 * WebKitWebSettings:enable-default-context-menu:
773 * Whether right-clicks should be handled automatically to create,
774 * and display the context menu. Turning this off will make
775 * WebKitGTK+ not emit the populate-popup signal. Notice that the
776 * default button press event handler may still handle right
777 * clicks for other reasons, such as in-page context menus, or
778 * right-clicks that are handled by the page itself.
782 g_object_class_install_property(gobject_class,
783 PROP_ENABLE_DEFAULT_CONTEXT_MENU,
784 g_param_spec_boolean(
785 "enable-default-context-menu",
786 _("Enable Default Context Menu"),
787 _("Enables the handling of right-clicks for the creation of the default context menu"),
792 * WebKitWebSettings::enable-site-specific-quirks
794 * Whether to turn on site-specific hacks. Turning this on will
795 * tell WebKitGTK+ to use some site-specific workarounds for
796 * better web compatibility. For example, older versions of
797 * MediaWiki will incorrectly send WebKit a css file with KHTML
798 * workarounds. By turning on site-specific quirks, WebKit will
799 * special-case this and other cases to make the sites work.
803 g_object_class_install_property(gobject_class,
804 PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
805 g_param_spec_boolean(
806 "enable-site-specific-quirks",
807 _("Enable Site Specific Quirks"),
808 _("Enables the site-specific compatibility workarounds"),
813 * WebKitWebSettings:enable-page-cache:
815 * Enable or disable the page cache. Disabling the page cache is
816 * generally only useful for special circumstances like low-memory
817 * scenarios or special purpose applications like static HTML
818 * viewers. This setting only controls the Page Cache, this cache
819 * is different than the disk-based or memory-based traditional
820 * resource caches, its point is to make going back and forth
821 * between pages much faster. For details about the different types
822 * of caches and their purposes see:
823 * http://webkit.org/blog/427/webkit-page-cache-i-the-basics/
827 g_object_class_install_property(gobject_class,
828 PROP_ENABLE_PAGE_CACHE,
829 g_param_spec_boolean("enable-page-cache",
830 _("Enable page cache"),
831 _("Whether the page cache should be used"),
836 * WebKitWebSettings:auto-resize-window:
838 * Web pages can request to modify the size and position of the
839 * window containing the #WebKitWebView through various DOM methods
840 * (resizeTo, moveTo, resizeBy, moveBy). By default WebKit will not
841 * honor this requests, but you can set this property to %TRUE if
842 * you'd like it to do so. If you wish to handle this manually, you
843 * can connect to the notify signal for the
844 * #WebKitWebWindowFeatures of your #WebKitWebView.
848 g_object_class_install_property(gobject_class,
849 PROP_AUTO_RESIZE_WINDOW,
850 g_param_spec_boolean("auto-resize-window",
851 _("Auto Resize Window"),
852 _("Automatically resize the toplevel window when a page requests it"),
857 * WebKitWebSettings:enable-file-access-from-file-uris:
859 * Boolean property to control file access for file:// URIs. If this
860 * option is enabled every file:// will have its own security unique domain.
864 g_object_class_install_property(gobject_class,
865 PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS,
866 g_param_spec_boolean("enable-file-access-from-file-uris",
867 "Enable file access from file URIs",
868 "Controls file access for file:// URIs.",
873 * WebKitWebSettings:enable-java-applet:
875 * Enable or disable support for the Java <applet> tag. Keep in
876 * mind that Java content can be still shown in the page through
877 * <object> or <embed>, which are the preferred tags for this task.
881 g_object_class_install_property(gobject_class,
882 PROP_ENABLE_JAVA_APPLET,
883 g_param_spec_boolean("enable-java-applet",
884 _("Enable Java Applet"),
885 _("Whether Java Applet support through <applet> should be enabled"),
890 * WebKitWebSettings:enable-hyperlink-auditing:
892 * Enable or disable support for <a ping>.
896 g_object_class_install_property(gobject_class,
897 PROP_ENABLE_HYPERLINK_AUDITING,
898 g_param_spec_boolean("enable-hyperlink-auditing",
899 _("Enable Hyperlink Auditing"),
900 _("Whether <a ping> should be able to send pings"),
904 /* Undocumented for now */
905 g_object_class_install_property(gobject_class,
906 PROP_ENABLE_FULLSCREEN,
907 g_param_spec_boolean("enable-fullscreen",
908 _("Enable Fullscreen"),
909 _("Whether the Mozilla style API should be enabled."),
913 g_type_class_add_private(klass, sizeof(WebKitWebSettingsPrivate));
916 static void webkit_web_settings_init(WebKitWebSettings* web_settings)
918 web_settings->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_settings, WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate);
921 static void webkit_web_settings_finalize(GObject* object)
923 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
924 WebKitWebSettingsPrivate* priv = web_settings->priv;
926 g_free(priv->default_encoding);
927 g_free(priv->cursive_font_family);
928 g_free(priv->default_font_family);
929 g_free(priv->fantasy_font_family);
930 g_free(priv->monospace_font_family);
931 g_free(priv->sans_serif_font_family);
932 g_free(priv->serif_font_family);
933 g_free(priv->user_stylesheet_uri);
934 g_free(priv->spell_checking_languages);
936 g_free(priv->user_agent);
938 G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object);
941 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
943 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
944 WebKitWebSettingsPrivate* priv = web_settings->priv;
947 case PROP_DEFAULT_ENCODING:
948 g_free(priv->default_encoding);
949 priv->default_encoding = g_strdup(g_value_get_string(value));
951 case PROP_CURSIVE_FONT_FAMILY:
952 g_free(priv->cursive_font_family);
953 priv->cursive_font_family = g_strdup(g_value_get_string(value));
955 case PROP_DEFAULT_FONT_FAMILY:
956 g_free(priv->default_font_family);
957 priv->default_font_family = g_strdup(g_value_get_string(value));
959 case PROP_FANTASY_FONT_FAMILY:
960 g_free(priv->fantasy_font_family);
961 priv->fantasy_font_family = g_strdup(g_value_get_string(value));
963 case PROP_MONOSPACE_FONT_FAMILY:
964 g_free(priv->monospace_font_family);
965 priv->monospace_font_family = g_strdup(g_value_get_string(value));
967 case PROP_SANS_SERIF_FONT_FAMILY:
968 g_free(priv->sans_serif_font_family);
969 priv->sans_serif_font_family = g_strdup(g_value_get_string(value));
971 case PROP_SERIF_FONT_FAMILY:
972 g_free(priv->serif_font_family);
973 priv->serif_font_family = g_strdup(g_value_get_string(value));
975 case PROP_DEFAULT_FONT_SIZE:
976 priv->default_font_size = g_value_get_int(value);
978 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
979 priv->default_monospace_font_size = g_value_get_int(value);
981 case PROP_MINIMUM_FONT_SIZE:
982 priv->minimum_font_size = g_value_get_int(value);
984 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
985 priv->minimum_logical_font_size = g_value_get_int(value);
987 case PROP_ENFORCE_96_DPI:
988 priv->enforce_96_dpi = g_value_get_boolean(value);
990 case PROP_AUTO_LOAD_IMAGES:
991 priv->auto_load_images = g_value_get_boolean(value);
993 case PROP_AUTO_SHRINK_IMAGES:
994 priv->auto_shrink_images = g_value_get_boolean(value);
996 case PROP_PRINT_BACKGROUNDS:
997 priv->print_backgrounds = g_value_get_boolean(value);
999 case PROP_ENABLE_SCRIPTS:
1000 priv->enable_scripts = g_value_get_boolean(value);
1002 case PROP_ENABLE_PLUGINS:
1003 priv->enable_plugins = g_value_get_boolean(value);
1005 case PROP_RESIZABLE_TEXT_AREAS:
1006 priv->resizable_text_areas = g_value_get_boolean(value);
1008 case PROP_USER_STYLESHEET_URI:
1009 g_free(priv->user_stylesheet_uri);
1010 priv->user_stylesheet_uri = g_strdup(g_value_get_string(value));
1012 case PROP_ZOOM_STEP:
1013 priv->zoom_step = g_value_get_float(value);
1015 case PROP_ENABLE_DEVELOPER_EXTRAS:
1016 priv->enable_developer_extras = g_value_get_boolean(value);
1018 case PROP_ENABLE_PRIVATE_BROWSING:
1019 priv->enable_private_browsing = g_value_get_boolean(value);
1021 case PROP_ENABLE_CARET_BROWSING:
1022 priv->enable_caret_browsing = g_value_get_boolean(value);
1024 case PROP_ENABLE_HTML5_DATABASE:
1025 priv->enable_html5_database = g_value_get_boolean(value);
1027 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
1028 priv->enable_html5_local_storage = g_value_get_boolean(value);
1030 case PROP_ENABLE_SPELL_CHECKING:
1031 priv->enable_spell_checking = g_value_get_boolean(value);
1033 case PROP_SPELL_CHECKING_LANGUAGES:
1034 g_free(priv->spell_checking_languages);
1035 priv->spell_checking_languages = g_strdup(g_value_get_string(value));
1037 case PROP_ENABLE_XSS_AUDITOR:
1038 priv->enable_xss_auditor = g_value_get_boolean(value);
1040 case PROP_ENABLE_SPATIAL_NAVIGATION:
1041 priv->enable_spatial_navigation = g_value_get_boolean(value);
1043 case PROP_ENABLE_FRAME_FLATTENING:
1044 priv->enable_frame_flattening = g_value_get_boolean(value);
1046 case PROP_USER_AGENT:
1047 g_free(priv->user_agent);
1048 if (!g_value_get_string(value) || !strlen(g_value_get_string(value)))
1049 priv->user_agent = g_strdup(webkitUserAgent().utf8().data());
1051 priv->user_agent = g_strdup(g_value_get_string(value));
1053 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
1054 priv->javascript_can_open_windows_automatically = g_value_get_boolean(value);
1056 case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
1057 priv->javascript_can_access_clipboard = g_value_get_boolean(value);
1059 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
1060 priv->enable_offline_web_application_cache = g_value_get_boolean(value);
1062 case PROP_EDITING_BEHAVIOR:
1063 priv->editing_behavior = static_cast<WebKitEditingBehavior>(g_value_get_enum(value));
1065 case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS:
1066 priv->enable_universal_access_from_file_uris = g_value_get_boolean(value);
1068 case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS:
1069 priv->enable_file_access_from_file_uris = g_value_get_boolean(value);
1071 case PROP_ENABLE_DOM_PASTE:
1072 priv->enable_dom_paste = g_value_get_boolean(value);
1074 case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS:
1075 priv->tab_key_cycles_through_elements = g_value_get_boolean(value);
1077 case PROP_ENABLE_DEFAULT_CONTEXT_MENU:
1078 priv->enable_default_context_menu = g_value_get_boolean(value);
1080 case PROP_ENABLE_SITE_SPECIFIC_QUIRKS:
1081 priv->enable_site_specific_quirks = g_value_get_boolean(value);
1083 case PROP_ENABLE_PAGE_CACHE:
1084 priv->enable_page_cache = g_value_get_boolean(value);
1086 case PROP_AUTO_RESIZE_WINDOW:
1087 priv->auto_resize_window = g_value_get_boolean(value);
1089 case PROP_ENABLE_JAVA_APPLET:
1090 priv->enable_java_applet = g_value_get_boolean(value);
1092 case PROP_ENABLE_HYPERLINK_AUDITING:
1093 priv->enable_hyperlink_auditing = g_value_get_boolean(value);
1095 case PROP_ENABLE_FULLSCREEN:
1096 priv->enable_fullscreen = g_value_get_boolean(value);
1099 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1104 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
1106 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
1107 WebKitWebSettingsPrivate* priv = web_settings->priv;
1110 case PROP_DEFAULT_ENCODING:
1111 g_value_set_string(value, priv->default_encoding);
1113 case PROP_CURSIVE_FONT_FAMILY:
1114 g_value_set_string(value, priv->cursive_font_family);
1116 case PROP_DEFAULT_FONT_FAMILY:
1117 g_value_set_string(value, priv->default_font_family);
1119 case PROP_FANTASY_FONT_FAMILY:
1120 g_value_set_string(value, priv->fantasy_font_family);
1122 case PROP_MONOSPACE_FONT_FAMILY:
1123 g_value_set_string(value, priv->monospace_font_family);
1125 case PROP_SANS_SERIF_FONT_FAMILY:
1126 g_value_set_string(value, priv->sans_serif_font_family);
1128 case PROP_SERIF_FONT_FAMILY:
1129 g_value_set_string(value, priv->serif_font_family);
1131 case PROP_DEFAULT_FONT_SIZE:
1132 g_value_set_int(value, priv->default_font_size);
1134 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
1135 g_value_set_int(value, priv->default_monospace_font_size);
1137 case PROP_MINIMUM_FONT_SIZE:
1138 g_value_set_int(value, priv->minimum_font_size);
1140 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
1141 g_value_set_int(value, priv->minimum_logical_font_size);
1143 case PROP_ENFORCE_96_DPI:
1144 g_value_set_boolean(value, priv->enforce_96_dpi);
1146 case PROP_AUTO_LOAD_IMAGES:
1147 g_value_set_boolean(value, priv->auto_load_images);
1149 case PROP_AUTO_SHRINK_IMAGES:
1150 g_value_set_boolean(value, priv->auto_shrink_images);
1152 case PROP_PRINT_BACKGROUNDS:
1153 g_value_set_boolean(value, priv->print_backgrounds);
1155 case PROP_ENABLE_SCRIPTS:
1156 g_value_set_boolean(value, priv->enable_scripts);
1158 case PROP_ENABLE_PLUGINS:
1159 g_value_set_boolean(value, priv->enable_plugins);
1161 case PROP_RESIZABLE_TEXT_AREAS:
1162 g_value_set_boolean(value, priv->resizable_text_areas);
1164 case PROP_USER_STYLESHEET_URI:
1165 g_value_set_string(value, priv->user_stylesheet_uri);
1167 case PROP_ZOOM_STEP:
1168 g_value_set_float(value, priv->zoom_step);
1170 case PROP_ENABLE_DEVELOPER_EXTRAS:
1171 g_value_set_boolean(value, priv->enable_developer_extras);
1173 case PROP_ENABLE_PRIVATE_BROWSING:
1174 g_value_set_boolean(value, priv->enable_private_browsing);
1176 case PROP_ENABLE_CARET_BROWSING:
1177 g_value_set_boolean(value, priv->enable_caret_browsing);
1179 case PROP_ENABLE_HTML5_DATABASE:
1180 g_value_set_boolean(value, priv->enable_html5_database);
1182 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
1183 g_value_set_boolean(value, priv->enable_html5_local_storage);
1185 case PROP_ENABLE_SPELL_CHECKING:
1186 g_value_set_boolean(value, priv->enable_spell_checking);
1188 case PROP_SPELL_CHECKING_LANGUAGES:
1189 g_value_set_string(value, priv->spell_checking_languages);
1191 case PROP_ENABLE_XSS_AUDITOR:
1192 g_value_set_boolean(value, priv->enable_xss_auditor);
1194 case PROP_ENABLE_SPATIAL_NAVIGATION:
1195 g_value_set_boolean(value, priv->enable_spatial_navigation);
1197 case PROP_ENABLE_FRAME_FLATTENING:
1198 g_value_set_boolean(value, priv->enable_frame_flattening);
1200 case PROP_USER_AGENT:
1201 g_value_set_string(value, priv->user_agent);
1203 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
1204 g_value_set_boolean(value, priv->javascript_can_open_windows_automatically);
1206 case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
1207 g_value_set_boolean(value, priv->javascript_can_access_clipboard);
1209 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
1210 g_value_set_boolean(value, priv->enable_offline_web_application_cache);
1212 case PROP_EDITING_BEHAVIOR:
1213 g_value_set_enum(value, priv->editing_behavior);
1215 case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS:
1216 g_value_set_boolean(value, priv->enable_universal_access_from_file_uris);
1218 case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS:
1219 g_value_set_boolean(value, priv->enable_file_access_from_file_uris);
1221 case PROP_ENABLE_DOM_PASTE:
1222 g_value_set_boolean(value, priv->enable_dom_paste);
1224 case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS:
1225 g_value_set_boolean(value, priv->tab_key_cycles_through_elements);
1227 case PROP_ENABLE_DEFAULT_CONTEXT_MENU:
1228 g_value_set_boolean(value, priv->enable_default_context_menu);
1230 case PROP_ENABLE_SITE_SPECIFIC_QUIRKS:
1231 g_value_set_boolean(value, priv->enable_site_specific_quirks);
1233 case PROP_ENABLE_PAGE_CACHE:
1234 g_value_set_boolean(value, priv->enable_page_cache);
1236 case PROP_AUTO_RESIZE_WINDOW:
1237 g_value_set_boolean(value, priv->auto_resize_window);
1239 case PROP_ENABLE_JAVA_APPLET:
1240 g_value_set_boolean(value, priv->enable_java_applet);
1242 case PROP_ENABLE_HYPERLINK_AUDITING:
1243 g_value_set_boolean(value, priv->enable_hyperlink_auditing);
1245 case PROP_ENABLE_FULLSCREEN:
1246 g_value_set_boolean(value, priv->enable_fullscreen);
1249 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1255 * webkit_web_settings_new:
1257 * Creates a new #WebKitWebSettings instance with default values. It must
1258 * be manually attached to a WebView.
1260 * Returns: a new #WebKitWebSettings instance
1262 WebKitWebSettings* webkit_web_settings_new()
1264 return WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, NULL));
1268 * webkit_web_settings_copy:
1270 * Copies an existing #WebKitWebSettings instance.
1272 * Returns: (transfer full): a new #WebKitWebSettings instance
1274 WebKitWebSettings* webkit_web_settings_copy(WebKitWebSettings* web_settings)
1276 WebKitWebSettingsPrivate* priv = web_settings->priv;
1278 WebKitWebSettings* copy = WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS,
1279 "default-encoding", priv->default_encoding,
1280 "cursive-font-family", priv->cursive_font_family,
1281 "default-font-family", priv->default_font_family,
1282 "fantasy-font-family", priv->fantasy_font_family,
1283 "monospace-font-family", priv->monospace_font_family,
1284 "sans-serif-font-family", priv->sans_serif_font_family,
1285 "serif-font-family", priv->serif_font_family,
1286 "default-font-size", priv->default_font_size,
1287 "default-monospace-font-size", priv->default_monospace_font_size,
1288 "minimum-font-size", priv->minimum_font_size,
1289 "minimum-logical-font-size", priv->minimum_logical_font_size,
1290 "auto-load-images", priv->auto_load_images,
1291 "auto-shrink-images", priv->auto_shrink_images,
1292 "print-backgrounds", priv->print_backgrounds,
1293 "enable-scripts", priv->enable_scripts,
1294 "enable-plugins", priv->enable_plugins,
1295 "resizable-text-areas", priv->resizable_text_areas,
1296 "user-stylesheet-uri", priv->user_stylesheet_uri,
1297 "zoom-step", priv->zoom_step,
1298 "enable-developer-extras", priv->enable_developer_extras,
1299 "enable-private-browsing", priv->enable_private_browsing,
1300 "enable-spell-checking", priv->enable_spell_checking,
1301 "spell-checking-languages", priv->spell_checking_languages,
1302 "enable-caret-browsing", priv->enable_caret_browsing,
1303 "enable-html5-database", priv->enable_html5_database,
1304 "enable-html5-local-storage", priv->enable_html5_local_storage,
1305 "enable-xss-auditor", priv->enable_xss_auditor,
1306 "enable-spatial-navigation", priv->enable_spatial_navigation,
1307 "enable-frame-flattening", priv->enable_frame_flattening,
1308 "user-agent", webkit_web_settings_get_user_agent(web_settings),
1309 "javascript-can-open-windows-automatically", priv->javascript_can_open_windows_automatically,
1310 "javascript-can-access-clipboard", priv->javascript_can_access_clipboard,
1311 "enable-offline-web-application-cache", priv->enable_offline_web_application_cache,
1312 "editing-behavior", priv->editing_behavior,
1313 "enable-universal-access-from-file-uris", priv->enable_universal_access_from_file_uris,
1314 "enable-file-access-from-file-uris", priv->enable_file_access_from_file_uris,
1315 "enable-dom-paste", priv->enable_dom_paste,
1316 "tab-key-cycles-through-elements", priv->tab_key_cycles_through_elements,
1317 "enable-default-context-menu", priv->enable_default_context_menu,
1318 "enable-site-specific-quirks", priv->enable_site_specific_quirks,
1319 "enable-page-cache", priv->enable_page_cache,
1320 "auto-resize-window", priv->auto_resize_window,
1321 "enable-java-applet", priv->enable_java_applet,
1322 "enable-hyperlink-auditing", priv->enable_hyperlink_auditing,
1323 "enable-fullscreen", priv->enable_fullscreen,
1330 * webkit_web_settings_add_extra_plugin_directory:
1331 * @web_view: a #WebKitWebView
1332 * @directory: the directory to add
1334 * Adds the @directory to paths where @web_view will search for plugins.
1338 void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* webView, const gchar* directory)
1340 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1342 PluginDatabase::installedPlugins()->addExtraPluginDirectory(filenameToString(directory));
1346 * webkit_web_settings_get_user_agent:
1347 * @web_settings: a #WebKitWebSettings
1349 * Returns the User-Agent string currently used by the web view(s) associated
1350 * with the @web_settings.
1354 G_CONST_RETURN gchar* webkit_web_settings_get_user_agent(WebKitWebSettings* webSettings)
1356 g_return_val_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings), NULL);
1358 WebKitWebSettingsPrivate* priv = webSettings->priv;
1360 return priv->user_agent;
1365 WebCore::EditingBehaviorType core(WebKitEditingBehavior type)
1367 return (WebCore::EditingBehaviorType)type;