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"
33 #include "PluginDatabase.h"
34 #include "webkitenumtypes.h"
35 #include "webkitglobalsprivate.h"
36 #include "webkitversion.h"
37 #include "webkitwebsettingsprivate.h"
38 #include <wtf/text/CString.h>
39 #include <wtf/text/StringConcatenate.h>
40 #include <glib/gi18n-lib.h>
43 #include <sys/utsname.h>
45 #include "SystemInfo.h"
49 * SECTION:webkitwebsettings
50 * @short_description: Control the behaviour of a #WebKitWebView
52 * #WebKitWebSettings can be applied to a #WebKitWebView to control text encoding,
53 * color, font sizes, printing mode, script support, loading of images and various other things.
54 * After creation, a #WebKitWebSettings object contains default settings.
56 * <informalexample><programlisting>
57 * /<!-- -->* Create a new websettings and disable java script *<!-- -->/
58 * WebKitWebSettings *settings = webkit_web_settings_new ();
59 * g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);
61 * /<!-- -->* Apply the result *<!-- -->/
62 * webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
63 * </programlisting></informalexample>
66 using namespace WebCore;
68 G_DEFINE_TYPE(WebKitWebSettings, webkit_web_settings, G_TYPE_OBJECT)
73 PROP_DEFAULT_ENCODING,
74 PROP_CURSIVE_FONT_FAMILY,
75 PROP_DEFAULT_FONT_FAMILY,
76 PROP_FANTASY_FONT_FAMILY,
77 PROP_MONOSPACE_FONT_FAMILY,
78 PROP_SANS_SERIF_FONT_FAMILY,
79 PROP_SERIF_FONT_FAMILY,
80 PROP_DEFAULT_FONT_SIZE,
81 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
82 PROP_MINIMUM_FONT_SIZE,
83 PROP_MINIMUM_LOGICAL_FONT_SIZE,
85 PROP_AUTO_LOAD_IMAGES,
86 PROP_AUTO_SHRINK_IMAGES,
87 PROP_PRINT_BACKGROUNDS,
90 PROP_RESIZABLE_TEXT_AREAS,
91 PROP_USER_STYLESHEET_URI,
93 PROP_ENABLE_DEVELOPER_EXTRAS,
94 PROP_ENABLE_PRIVATE_BROWSING,
95 PROP_ENABLE_SPELL_CHECKING,
96 PROP_SPELL_CHECKING_LANGUAGES,
97 PROP_ENABLE_CARET_BROWSING,
98 PROP_ENABLE_HTML5_DATABASE,
99 PROP_ENABLE_HTML5_LOCAL_STORAGE,
100 PROP_HTML5_LOCAL_STORAGE_DATABASE_PATH,
101 PROP_ENABLE_XSS_AUDITOR,
102 PROP_ENABLE_SPATIAL_NAVIGATION,
103 PROP_ENABLE_FRAME_FLATTENING,
105 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
106 PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD,
107 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE,
108 PROP_EDITING_BEHAVIOR,
109 PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS,
110 PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS,
111 PROP_ENABLE_DOM_PASTE,
112 PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS,
113 PROP_ENABLE_DEFAULT_CONTEXT_MENU,
114 PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
115 PROP_ENABLE_PAGE_CACHE,
116 PROP_AUTO_RESIZE_WINDOW,
117 PROP_ENABLE_JAVA_APPLET,
118 PROP_ENABLE_HYPERLINK_AUDITING,
119 PROP_ENABLE_FULLSCREEN,
120 PROP_ENABLE_DNS_PREFETCHING,
124 // Create a default user agent string
125 // This is a liberal interpretation of http://www.mozilla.org/build/revised-user-agent-strings.html
126 // See also http://developer.apple.com/internet/safari/faq.html#anchor2
127 static String webkitPlatform()
130 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("X11; ")));
132 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("")));
134 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Macintosh; ")));
135 #elif defined(GDK_WINDOWING_DIRECTFB)
136 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("DirectFB; ")));
138 DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Unknown; ")));
144 static String webkitOSVersion()
146 // FIXME: platform/version detection can be shared.
150 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Intel Mac OS X")));
152 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("PPC Mac OS X")));
156 DEFINE_STATIC_LOCAL(String, uaOSVersion, (String()));
158 if (!uaOSVersion.isEmpty())
162 if (uname(&name) != -1)
163 uaOSVersion = makeString(name.sysname, ' ', name.machine);
165 uaOSVersion = String("Unknown");
167 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (windowsVersionForUAString()));
169 DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Unknown")));
175 static String webkitUserAgent()
177 // We mention Safari since many broken sites check for it (OmniWeb does this too)
178 // We re-use the WebKit version, though it doesn't seem to matter much in practice
180 DEFINE_STATIC_LOCAL(const String, uaVersion, (makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.', String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+')));
181 DEFINE_STATIC_LOCAL(const String, staticUA, (makeString("Mozilla/5.0 (", webkitPlatform(), webkitOSVersion(), ") AppleWebKit/", uaVersion) +
182 makeString(" (KHTML, like Gecko) Version/5.0 Safari/", uaVersion)));
187 static String safariUserAgent()
189 // We mention Safari since many broken sites check for it (OmniWeb does this too)
190 // We re-use the WebKit version, though it doesn't seem to matter much in practice
192 DEFINE_STATIC_LOCAL(const String, uaVersion, (makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.', String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+')));
193 DEFINE_STATIC_LOCAL(const String, staticUA, (makeString("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en_US) AppleWebKit/", uaVersion) +
194 makeString(" (KHTML, like Gecko) Version/5.0.5 Safari/", uaVersion)));
199 static void webkit_web_settings_finalize(GObject* object);
201 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
203 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
205 static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass)
207 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
208 gobject_class->finalize = webkit_web_settings_finalize;
209 gobject_class->set_property = webkit_web_settings_set_property;
210 gobject_class->get_property = webkit_web_settings_get_property;
214 GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
216 g_object_class_install_property(gobject_class,
217 PROP_DEFAULT_ENCODING,
220 _("Default Encoding"),
221 _("The default encoding used to display text."),
225 g_object_class_install_property(gobject_class,
226 PROP_CURSIVE_FONT_FAMILY,
228 "cursive-font-family",
229 _("Cursive Font Family"),
230 _("The default Cursive font family used to display text."),
234 g_object_class_install_property(gobject_class,
235 PROP_DEFAULT_FONT_FAMILY,
237 "default-font-family",
238 _("Default Font Family"),
239 _("The default font family used to display text."),
243 g_object_class_install_property(gobject_class,
244 PROP_FANTASY_FONT_FAMILY,
246 "fantasy-font-family",
247 _("Fantasy Font Family"),
248 _("The default Fantasy font family used to display text."),
252 g_object_class_install_property(gobject_class,
253 PROP_MONOSPACE_FONT_FAMILY,
255 "monospace-font-family",
256 _("Monospace Font Family"),
257 _("The default font family used to display monospace text."),
261 g_object_class_install_property(gobject_class,
262 PROP_SANS_SERIF_FONT_FAMILY,
264 "sans-serif-font-family",
265 _("Sans Serif Font Family"),
266 _("The default Sans Serif font family used to display text."),
270 g_object_class_install_property(gobject_class,
271 PROP_SERIF_FONT_FAMILY,
274 _("Serif Font Family"),
275 _("The default Serif font family used to display text."),
279 g_object_class_install_property(gobject_class,
280 PROP_DEFAULT_FONT_SIZE,
283 _("Default Font Size"),
284 _("The default font size used to display text."),
288 g_object_class_install_property(gobject_class,
289 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
291 "default-monospace-font-size",
292 _("Default Monospace Font Size"),
293 _("The default font size used to display monospace text."),
297 g_object_class_install_property(gobject_class,
298 PROP_MINIMUM_FONT_SIZE,
301 _("Minimum Font Size"),
302 _("The minimum font size used to display text."),
306 g_object_class_install_property(gobject_class,
307 PROP_MINIMUM_LOGICAL_FONT_SIZE,
309 "minimum-logical-font-size",
310 _("Minimum Logical Font Size"),
311 _("The minimum logical font size used to display text."),
316 * WebKitWebSettings:enforce-96-dpi:
318 * Enforce a resolution of 96 DPI. This is meant for compatibility
319 * with web pages which cope badly with different screen resolutions
320 * and for automated testing.
321 * Web browsers and applications that typically display arbitrary
322 * content from the web should provide a preference for this.
326 g_object_class_install_property(gobject_class,
328 g_param_spec_boolean(
331 _("Enforce a resolution of 96 DPI"),
335 g_object_class_install_property(gobject_class,
336 PROP_AUTO_LOAD_IMAGES,
337 g_param_spec_boolean(
339 _("Auto Load Images"),
340 _("Load images automatically."),
344 g_object_class_install_property(gobject_class,
345 PROP_AUTO_SHRINK_IMAGES,
346 g_param_spec_boolean(
347 "auto-shrink-images",
348 _("Auto Shrink Images"),
349 _("Automatically shrink standalone images to fit."),
353 g_object_class_install_property(gobject_class,
354 PROP_PRINT_BACKGROUNDS,
355 g_param_spec_boolean(
357 _("Print Backgrounds"),
358 _("Whether background images should be printed."),
362 g_object_class_install_property(gobject_class,
364 g_param_spec_boolean(
367 _("Enable embedded scripting languages."),
371 g_object_class_install_property(gobject_class,
373 g_param_spec_boolean(
376 _("Enable embedded plugin objects."),
380 g_object_class_install_property(gobject_class,
381 PROP_RESIZABLE_TEXT_AREAS,
382 g_param_spec_boolean(
383 "resizable-text-areas",
384 _("Resizable Text Areas"),
385 _("Whether text areas are resizable."),
389 g_object_class_install_property(gobject_class,
390 PROP_USER_STYLESHEET_URI,
391 g_param_spec_string("user-stylesheet-uri",
392 _("User Stylesheet URI"),
393 _("The URI of a stylesheet that is applied to every page."),
398 * WebKitWebSettings:zoom-step:
400 * The value by which the zoom level is changed when zooming in or out.
404 g_object_class_install_property(gobject_class,
408 _("Zoom Stepping Value"),
409 _("The value by which the zoom level is changed when zooming in or out."),
410 0.0f, G_MAXFLOAT, 0.1f,
414 * WebKitWebSettings:enable-developer-extras:
416 * Whether developer extensions should be enabled. This enables,
417 * for now, the Web Inspector, which can be controlled using the
418 * #WebKitWebInspector instance held by the #WebKitWebView this
419 * setting is enabled for.
423 g_object_class_install_property(gobject_class,
424 PROP_ENABLE_DEVELOPER_EXTRAS,
425 g_param_spec_boolean(
426 "enable-developer-extras",
427 _("Enable Developer Extras"),
428 _("Enables special extensions that help developers"),
433 * WebKitWebSettings:enable-private-browsing:
435 * Whether to enable private browsing mode. Private browsing mode prevents
436 * WebKit from updating the global history and storing any session
437 * information e.g., on-disk cache, as well as suppressing any messages
438 * from being printed into the (javascript) console.
440 * This is currently experimental for WebKitGtk.
444 g_object_class_install_property(gobject_class,
445 PROP_ENABLE_PRIVATE_BROWSING,
446 g_param_spec_boolean(
447 "enable-private-browsing",
448 _("Enable Private Browsing"),
449 _("Enables private browsing mode"),
454 * WebKitWebSettings:enable-spell-checking:
456 * Whether to enable spell checking while typing.
460 g_object_class_install_property(gobject_class,
461 PROP_ENABLE_SPELL_CHECKING,
462 g_param_spec_boolean(
463 "enable-spell-checking",
464 _("Enable Spell Checking"),
465 _("Enables spell checking while typing"),
470 * WebKitWebSettings:spell-checking-languages:
472 * The languages to be used for spell checking, separated by commas.
474 * The locale string typically is in the form lang_COUNTRY, where lang
475 * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
476 * For instance, sv_FI for Swedish as written in Finland or pt_BR
477 * for Portuguese as written in Brazil.
479 * If no value is specified then the value returned by
480 * gtk_get_default_language will be used.
484 g_object_class_install_property(gobject_class,
485 PROP_SPELL_CHECKING_LANGUAGES,
487 "spell-checking-languages",
488 _("Languages to use for spell checking"),
489 _("Comma separated list of languages to use for spell checking"),
494 * WebKitWebSettings:enable-caret-browsing:
496 * Whether to enable caret browsing mode.
500 g_object_class_install_property(gobject_class,
501 PROP_ENABLE_CARET_BROWSING,
502 g_param_spec_boolean("enable-caret-browsing",
503 _("Enable Caret Browsing"),
504 _("Whether to enable accessibility enhanced keyboard navigation"),
508 * WebKitWebSettings:enable-html5-database:
510 * Whether to enable HTML5 client-side SQL database support. Client-side
511 * SQL database allows web pages to store structured data and be able to
512 * use SQL to manipulate that data asynchronously.
516 g_object_class_install_property(gobject_class,
517 PROP_ENABLE_HTML5_DATABASE,
518 g_param_spec_boolean("enable-html5-database",
519 _("Enable HTML5 Database"),
520 _("Whether to enable HTML5 database support"),
525 * WebKitWebSettings:enable-html5-local-storage:
527 * Whether to enable HTML5 localStorage support. localStorage provides
528 * simple synchronous storage access.
532 g_object_class_install_property(gobject_class,
533 PROP_ENABLE_HTML5_LOCAL_STORAGE,
534 g_param_spec_boolean("enable-html5-local-storage",
535 _("Enable HTML5 Local Storage"),
536 _("Whether to enable HTML5 Local Storage support"),
540 * WebKitWebSettings:html5-local-storage-database-path:
542 * Path to store persistent HTML5 localStorage databases, which are enabled by
543 * "enable-html5-local-storage". The default path is $XDG_DATA_HOME/webkit/databases/.
547 GOwnPtr<gchar> localStoragePath(g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL));
548 g_object_class_install_property(gobject_class,
549 PROP_HTML5_LOCAL_STORAGE_DATABASE_PATH,
550 g_param_spec_string("html5-local-storage-database-path",
551 _("Local Storage Database Path"),
552 _("The path to where HTML5 Local Storage databases are stored."),
553 localStoragePath.get(),
556 * WebKitWebSettings:enable-xss-auditor
558 * Whether to enable the XSS Auditor. This feature filters some kinds of
559 * reflective XSS attacks on vulnerable web sites.
563 g_object_class_install_property(gobject_class,
564 PROP_ENABLE_XSS_AUDITOR,
565 g_param_spec_boolean("enable-xss-auditor",
566 _("Enable XSS Auditor"),
567 _("Whether to enable the XSS auditor"),
571 * WebKitWebSettings:enable-spatial-navigation
573 * Whether to enable the Spatial Navigation. This feature consists in the ability
574 * to navigate between focusable elements in a Web page, such as hyperlinks and
575 * form controls, by using Left, Right, Up and Down arrow keys. For example, if
576 * an user presses the Right key, heuristics determine whether there is an element
577 * he might be trying to reach towards the right, and if there are multiple elements,
578 * which element he probably wants.
582 g_object_class_install_property(gobject_class,
583 PROP_ENABLE_SPATIAL_NAVIGATION,
584 g_param_spec_boolean("enable-spatial-navigation",
585 _("Enable Spatial Navigation"),
586 _("Whether to enable Spatial Navigation"),
590 * WebKitWebSettings:enable-frame-flattening
592 * Whether to enable the Frame Flattening. With this setting each subframe is expanded
593 * to its contents, which will flatten all the frames to become one scrollable page.
594 * On touch devices, it is desired to not have any scrollable sub parts of the page as
595 * it results in a confusing user experience, with scrolling sometimes scrolling sub parts
596 * and at other times scrolling the page itself. For this reason iframes and framesets are
597 * barely usable on touch devices.
601 g_object_class_install_property(gobject_class,
602 PROP_ENABLE_FRAME_FLATTENING,
603 g_param_spec_boolean("enable-frame-flattening",
604 _("Enable Frame Flattening"),
605 _("Whether to enable Frame Flattening"),
609 * WebKitWebSettings:user-agent:
611 * The User-Agent string used by WebKitGtk.
613 * This will return a default User-Agent string if a custom string wasn't
614 * provided by the application. Setting this property to a NULL value or
615 * an empty string will result in the User-Agent string being reset to the
620 g_object_class_install_property(gobject_class, PROP_USER_AGENT,
621 g_param_spec_string("user-agent",
623 _("The User-Agent string used by WebKitGtk"),
624 webkitUserAgent().utf8().data(),
628 * WebKitWebSettings:javascript-can-open-windows-automatically
630 * Whether JavaScript can open popup windows automatically without user
635 g_object_class_install_property(gobject_class,
636 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
637 g_param_spec_boolean("javascript-can-open-windows-automatically",
638 _("JavaScript can open windows automatically"),
639 _("Whether JavaScript can open windows automatically"),
644 * WebKitWebSettings:javascript-can-access-clipboard
646 * Whether JavaScript can access Clipboard.
650 g_object_class_install_property(gobject_class,
651 PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD,
652 g_param_spec_boolean("javascript-can-access-clipboard",
653 _("JavaScript can access Clipboard"),
654 _("Whether JavaScript can access Clipboard"),
659 * WebKitWebSettings:enable-offline-web-application-cache
661 * Whether to enable HTML5 offline web application cache support. Offline
662 * Web Application Cache ensures web applications are available even when
663 * the user is not connected to the network.
667 g_object_class_install_property(gobject_class,
668 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE,
669 g_param_spec_boolean("enable-offline-web-application-cache",
670 _("Enable offline web application cache"),
671 _("Whether to enable offline web application cache"),
677 * WebKitWebSettings:editing-behavior
679 * This setting controls various editing behaviors that differ
680 * between platforms and that have been combined in two groups,
681 * 'Mac' and 'Windows'. Some examples:
683 * 1) Clicking below the last line of an editable area puts the
684 * caret at the end of the last line on Mac, but in the middle of
685 * the last line on Windows.
687 * 2) Pushing down the arrow key on the last line puts the caret
688 * at the end of the last line on Mac, but does nothing on
689 * Windows. A similar case exists on the top line.
693 g_object_class_install_property(gobject_class,
694 PROP_EDITING_BEHAVIOR,
695 g_param_spec_enum("editing-behavior",
696 _("Editing behavior"),
697 _("The behavior mode to use in editing mode"),
698 WEBKIT_TYPE_EDITING_BEHAVIOR,
699 WEBKIT_EDITING_BEHAVIOR_UNIX,
703 * WebKitWebSettings:enable-universal-access-from-file-uris
705 * Whether to allow files loaded through file:// URIs universal access to
710 g_object_class_install_property(gobject_class,
711 PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS,
712 g_param_spec_boolean("enable-universal-access-from-file-uris",
713 _("Enable universal access from file URIs"),
714 _("Whether to allow universal access from file URIs"),
719 * WebKitWebSettings:enable-dom-paste
721 * Whether to enable DOM paste. If set to %TRUE, document.execCommand("Paste")
722 * will correctly execute and paste content of the clipboard.
726 g_object_class_install_property(gobject_class,
727 PROP_ENABLE_DOM_PASTE,
728 g_param_spec_boolean("enable-dom-paste",
729 _("Enable DOM paste"),
730 _("Whether to enable DOM paste"),
734 * WebKitWebSettings:tab-key-cycles-through-elements:
736 * Whether the tab key cycles through elements on the page.
738 * If @flag is %TRUE, pressing the tab key will focus the next element in
739 * the @web_view. If @flag is %FALSE, the @web_view will interpret tab
740 * key presses as normal key presses. If the selected element is editable, the
741 * tab key will cause the insertion of a tab character.
745 g_object_class_install_property(gobject_class,
746 PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS,
747 g_param_spec_boolean("tab-key-cycles-through-elements",
748 _("Tab key cycles through elements"),
749 _("Whether the tab key cycles through elements on the page."),
754 * WebKitWebSettings:enable-default-context-menu:
756 * Whether right-clicks should be handled automatically to create,
757 * and display the context menu. Turning this off will make
758 * WebKitGTK+ not emit the populate-popup signal. Notice that the
759 * default button press event handler may still handle right
760 * clicks for other reasons, such as in-page context menus, or
761 * right-clicks that are handled by the page itself.
765 g_object_class_install_property(gobject_class,
766 PROP_ENABLE_DEFAULT_CONTEXT_MENU,
767 g_param_spec_boolean(
768 "enable-default-context-menu",
769 _("Enable Default Context Menu"),
770 _("Enables the handling of right-clicks for the creation of the default context menu"),
775 * WebKitWebSettings::enable-site-specific-quirks
777 * Whether to turn on site-specific hacks. Turning this on will
778 * tell WebKitGTK+ to use some site-specific workarounds for
779 * better web compatibility. For example, older versions of
780 * MediaWiki will incorrectly send WebKit a css file with KHTML
781 * workarounds. By turning on site-specific quirks, WebKit will
782 * special-case this and other cases to make the sites work.
786 g_object_class_install_property(gobject_class,
787 PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
788 g_param_spec_boolean(
789 "enable-site-specific-quirks",
790 _("Enable Site Specific Quirks"),
791 _("Enables the site-specific compatibility workarounds"),
796 * WebKitWebSettings:enable-page-cache:
798 * Enable or disable the page cache. Disabling the page cache is
799 * generally only useful for special circumstances like low-memory
800 * scenarios or special purpose applications like static HTML
801 * viewers. This setting only controls the Page Cache, this cache
802 * is different than the disk-based or memory-based traditional
803 * resource caches, its point is to make going back and forth
804 * between pages much faster. For details about the different types
805 * of caches and their purposes see:
806 * http://webkit.org/blog/427/webkit-page-cache-i-the-basics/
810 g_object_class_install_property(gobject_class,
811 PROP_ENABLE_PAGE_CACHE,
812 g_param_spec_boolean("enable-page-cache",
813 _("Enable page cache"),
814 _("Whether the page cache should be used"),
819 * WebKitWebSettings:auto-resize-window:
821 * Web pages can request to modify the size and position of the
822 * window containing the #WebKitWebView through various DOM methods
823 * (resizeTo, moveTo, resizeBy, moveBy). By default WebKit will not
824 * honor this requests, but you can set this property to %TRUE if
825 * you'd like it to do so. If you wish to handle this manually, you
826 * can connect to the notify signal for the
827 * #WebKitWebWindowFeatures of your #WebKitWebView.
831 g_object_class_install_property(gobject_class,
832 PROP_AUTO_RESIZE_WINDOW,
833 g_param_spec_boolean("auto-resize-window",
834 _("Auto Resize Window"),
835 _("Automatically resize the toplevel window when a page requests it"),
840 * WebKitWebSettings:enable-file-access-from-file-uris:
842 * Boolean property to control file access for file:// URIs. If this
843 * option is enabled every file:// will have its own security unique domain.
847 g_object_class_install_property(gobject_class,
848 PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS,
849 g_param_spec_boolean("enable-file-access-from-file-uris",
850 "Enable file access from file URIs",
851 "Controls file access for file:// URIs.",
856 * WebKitWebSettings:enable-java-applet:
858 * Enable or disable support for the Java <applet> tag. Keep in
859 * mind that Java content can be still shown in the page through
860 * <object> or <embed>, which are the preferred tags for this task.
864 g_object_class_install_property(gobject_class,
865 PROP_ENABLE_JAVA_APPLET,
866 g_param_spec_boolean("enable-java-applet",
867 _("Enable Java Applet"),
868 _("Whether Java Applet support through <applet> should be enabled"),
873 * WebKitWebSettings:enable-hyperlink-auditing:
875 * Enable or disable support for <a ping>.
879 g_object_class_install_property(gobject_class,
880 PROP_ENABLE_HYPERLINK_AUDITING,
881 g_param_spec_boolean("enable-hyperlink-auditing",
882 _("Enable Hyperlink Auditing"),
883 _("Whether <a ping> should be able to send pings"),
887 /* Undocumented for now */
888 g_object_class_install_property(gobject_class,
889 PROP_ENABLE_FULLSCREEN,
890 g_param_spec_boolean("enable-fullscreen",
891 _("Enable Fullscreen"),
892 _("Whether the Mozilla style API should be enabled."),
896 * WebKitWebSettings:enable-webgl:
898 * Enable or disable support for WebGL on pages. WebGL is an experimental
899 * proposal for allowing web pages to use OpenGL ES-like calls directly. The
900 * standard is currently a work-in-progress by the Khronos Group.
904 g_object_class_install_property(gobject_class,
906 g_param_spec_boolean("enable-webgl",
908 _("Whether WebGL content should be rendered"),
913 * WebKitWebSettings:enable-dns-prefetching
915 * Whether webkit prefetches domain names. This is a separate knob from private browsing.
916 * Whether private browsing should set this or not is up for debate, for now it doesn't.
920 g_object_class_install_property(gobject_class,
921 PROP_ENABLE_DNS_PREFETCHING,
922 g_param_spec_boolean("enable-dns-prefetching",
923 _("WebKit prefetches domain names"),
924 _("Whether WebKit prefetches domain names"),
929 static void webkit_web_settings_init(WebKitWebSettings* web_settings)
931 web_settings->priv = new WebKitWebSettingsPrivate;
934 static void webkit_web_settings_finalize(GObject* object)
936 delete WEBKIT_WEB_SETTINGS(object)->priv;
937 G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object);
940 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
942 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
943 WebKitWebSettingsPrivate* priv = web_settings->priv;
946 case PROP_DEFAULT_ENCODING:
947 priv->defaultEncoding = g_value_get_string(value);
949 case PROP_CURSIVE_FONT_FAMILY:
950 priv->cursiveFontFamily = g_value_get_string(value);
952 case PROP_DEFAULT_FONT_FAMILY:
953 priv->defaultFontFamily = g_value_get_string(value);
955 case PROP_FANTASY_FONT_FAMILY:
956 priv->fantasyFontFamily = g_value_get_string(value);
958 case PROP_MONOSPACE_FONT_FAMILY:
959 priv->monospaceFontFamily = g_value_get_string(value);
961 case PROP_SANS_SERIF_FONT_FAMILY:
962 priv->sansSerifFontFamily = g_value_get_string(value);
964 case PROP_SERIF_FONT_FAMILY:
965 priv->serifFontFamily = g_value_get_string(value);
967 case PROP_DEFAULT_FONT_SIZE:
968 priv->defaultFontSize = g_value_get_int(value);
970 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
971 priv->defaultMonospaceFontSize = g_value_get_int(value);
973 case PROP_MINIMUM_FONT_SIZE:
974 priv->minimumFontSize = g_value_get_int(value);
976 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
977 priv->minimumLogicalFontSize = g_value_get_int(value);
979 case PROP_ENFORCE_96_DPI:
980 priv->enforce96DPI = g_value_get_boolean(value);
982 case PROP_AUTO_LOAD_IMAGES:
983 priv->autoLoadImages = g_value_get_boolean(value);
985 case PROP_AUTO_SHRINK_IMAGES:
986 priv->autoShrinkImages = g_value_get_boolean(value);
988 case PROP_PRINT_BACKGROUNDS:
989 priv->printBackgrounds = g_value_get_boolean(value);
991 case PROP_ENABLE_SCRIPTS:
992 priv->enableScripts = g_value_get_boolean(value);
994 case PROP_ENABLE_PLUGINS:
995 priv->enablePlugins = g_value_get_boolean(value);
997 case PROP_RESIZABLE_TEXT_AREAS:
998 priv->resizableTextAreas = g_value_get_boolean(value);
1000 case PROP_USER_STYLESHEET_URI:
1001 priv->userStylesheetURI = g_value_get_string(value);
1003 case PROP_ZOOM_STEP:
1004 priv->zoomStep = g_value_get_float(value);
1006 case PROP_ENABLE_DEVELOPER_EXTRAS:
1007 priv->enableDeveloperExtras = g_value_get_boolean(value);
1009 case PROP_ENABLE_PRIVATE_BROWSING:
1010 priv->enablePrivateBrowsing = g_value_get_boolean(value);
1012 case PROP_ENABLE_CARET_BROWSING:
1013 priv->enableCaretBrowsing = g_value_get_boolean(value);
1015 case PROP_ENABLE_HTML5_DATABASE:
1016 priv->enableHTML5Database = g_value_get_boolean(value);
1018 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
1019 priv->enableHTML5LocalStorage = g_value_get_boolean(value);
1021 case PROP_HTML5_LOCAL_STORAGE_DATABASE_PATH:
1022 priv->html5LocalStorageDatabasePath = g_value_get_string(value);
1024 case PROP_ENABLE_SPELL_CHECKING:
1025 priv->enableSpellChecking = g_value_get_boolean(value);
1027 case PROP_SPELL_CHECKING_LANGUAGES:
1028 priv->spellCheckingLanguages = g_value_get_string(value);
1030 case PROP_ENABLE_XSS_AUDITOR:
1031 priv->enableXSSAuditor = g_value_get_boolean(value);
1033 case PROP_ENABLE_SPATIAL_NAVIGATION:
1034 priv->enableSpatialNavigation = g_value_get_boolean(value);
1036 case PROP_ENABLE_FRAME_FLATTENING:
1037 priv->enableFrameFlattening = g_value_get_boolean(value);
1039 case PROP_USER_AGENT:
1040 if (!g_value_get_string(value) || !strlen(g_value_get_string(value)))
1041 priv->userAgent = webkitUserAgent().utf8();
1043 priv->userAgent = g_value_get_string(value);
1045 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
1046 priv->javascriptCanOpenWindowsAutomatically = g_value_get_boolean(value);
1048 case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
1049 priv->javascriptCanAccessClipboard = g_value_get_boolean(value);
1051 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
1052 priv->enableOfflineWebApplicationCache = g_value_get_boolean(value);
1054 case PROP_EDITING_BEHAVIOR:
1055 priv->editingBehavior = static_cast<WebKitEditingBehavior>(g_value_get_enum(value));
1057 case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS:
1058 priv->enableUniversalAccessFromFileURIs = g_value_get_boolean(value);
1060 case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS:
1061 priv->enableFileAccessFromFileURIs = g_value_get_boolean(value);
1063 case PROP_ENABLE_DOM_PASTE:
1064 priv->enableDOMPaste = g_value_get_boolean(value);
1066 case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS:
1067 priv->tabKeyCyclesThroughElements = g_value_get_boolean(value);
1069 case PROP_ENABLE_DEFAULT_CONTEXT_MENU:
1070 priv->enableDefaultContextMenu = g_value_get_boolean(value);
1072 case PROP_ENABLE_SITE_SPECIFIC_QUIRKS:
1073 priv->enableSiteSpecificQuirks = g_value_get_boolean(value);
1075 case PROP_ENABLE_PAGE_CACHE:
1076 priv->enablePageCache = g_value_get_boolean(value);
1078 case PROP_AUTO_RESIZE_WINDOW:
1079 priv->autoResizeWindow = g_value_get_boolean(value);
1081 case PROP_ENABLE_JAVA_APPLET:
1082 priv->enableJavaApplet = g_value_get_boolean(value);
1084 case PROP_ENABLE_HYPERLINK_AUDITING:
1085 priv->enableHyperlinkAuditing = g_value_get_boolean(value);
1087 case PROP_ENABLE_FULLSCREEN:
1088 priv->enableFullscreen = g_value_get_boolean(value);
1090 case PROP_ENABLE_DNS_PREFETCHING:
1091 priv->enableDNSPrefetching = g_value_get_boolean(value);
1093 case PROP_ENABLE_WEBGL:
1094 priv->enableWebgl = g_value_get_boolean(value);
1097 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1102 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
1104 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
1105 WebKitWebSettingsPrivate* priv = web_settings->priv;
1108 case PROP_DEFAULT_ENCODING:
1109 g_value_set_string(value, priv->defaultEncoding.data());
1111 case PROP_CURSIVE_FONT_FAMILY:
1112 g_value_set_string(value, priv->cursiveFontFamily.data());
1114 case PROP_DEFAULT_FONT_FAMILY:
1115 g_value_set_string(value, priv->defaultFontFamily.data());
1117 case PROP_FANTASY_FONT_FAMILY:
1118 g_value_set_string(value, priv->fantasyFontFamily.data());
1120 case PROP_MONOSPACE_FONT_FAMILY:
1121 g_value_set_string(value, priv->monospaceFontFamily.data());
1123 case PROP_SANS_SERIF_FONT_FAMILY:
1124 g_value_set_string(value, priv->sansSerifFontFamily.data());
1126 case PROP_SERIF_FONT_FAMILY:
1127 g_value_set_string(value, priv->serifFontFamily.data());
1129 case PROP_DEFAULT_FONT_SIZE:
1130 g_value_set_int(value, priv->defaultFontSize);
1132 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
1133 g_value_set_int(value, priv->defaultMonospaceFontSize);
1135 case PROP_MINIMUM_FONT_SIZE:
1136 g_value_set_int(value, priv->minimumFontSize);
1138 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
1139 g_value_set_int(value, priv->minimumLogicalFontSize);
1141 case PROP_ENFORCE_96_DPI:
1142 g_value_set_boolean(value, priv->enforce96DPI);
1144 case PROP_AUTO_LOAD_IMAGES:
1145 g_value_set_boolean(value, priv->autoLoadImages);
1147 case PROP_AUTO_SHRINK_IMAGES:
1148 g_value_set_boolean(value, priv->autoShrinkImages);
1150 case PROP_PRINT_BACKGROUNDS:
1151 g_value_set_boolean(value, priv->printBackgrounds);
1153 case PROP_ENABLE_SCRIPTS:
1154 g_value_set_boolean(value, priv->enableScripts);
1156 case PROP_ENABLE_PLUGINS:
1157 g_value_set_boolean(value, priv->enablePlugins);
1159 case PROP_RESIZABLE_TEXT_AREAS:
1160 g_value_set_boolean(value, priv->resizableTextAreas);
1162 case PROP_USER_STYLESHEET_URI:
1163 g_value_set_string(value, priv->userStylesheetURI.data());
1165 case PROP_ZOOM_STEP:
1166 g_value_set_float(value, priv->zoomStep);
1168 case PROP_ENABLE_DEVELOPER_EXTRAS:
1169 g_value_set_boolean(value, priv->enableDeveloperExtras);
1171 case PROP_ENABLE_PRIVATE_BROWSING:
1172 g_value_set_boolean(value, priv->enablePrivateBrowsing);
1174 case PROP_ENABLE_CARET_BROWSING:
1175 g_value_set_boolean(value, priv->enableCaretBrowsing);
1177 case PROP_ENABLE_HTML5_DATABASE:
1178 g_value_set_boolean(value, priv->enableHTML5Database);
1180 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
1181 g_value_set_boolean(value, priv->enableHTML5LocalStorage);
1183 case PROP_HTML5_LOCAL_STORAGE_DATABASE_PATH:
1184 g_value_set_string(value, priv->html5LocalStorageDatabasePath.data());
1186 case PROP_ENABLE_SPELL_CHECKING:
1187 g_value_set_boolean(value, priv->enableSpellChecking);
1189 case PROP_SPELL_CHECKING_LANGUAGES:
1190 g_value_set_string(value, priv->spellCheckingLanguages.data());
1192 case PROP_ENABLE_XSS_AUDITOR:
1193 g_value_set_boolean(value, priv->enableXSSAuditor);
1195 case PROP_ENABLE_SPATIAL_NAVIGATION:
1196 g_value_set_boolean(value, priv->enableSpatialNavigation);
1198 case PROP_ENABLE_FRAME_FLATTENING:
1199 g_value_set_boolean(value, priv->enableFrameFlattening);
1201 case PROP_USER_AGENT:
1202 g_value_set_string(value, priv->userAgent.data());
1204 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
1205 g_value_set_boolean(value, priv->javascriptCanOpenWindowsAutomatically);
1207 case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD:
1208 g_value_set_boolean(value, priv->javascriptCanAccessClipboard);
1210 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
1211 g_value_set_boolean(value, priv->enableOfflineWebApplicationCache);
1213 case PROP_EDITING_BEHAVIOR:
1214 g_value_set_enum(value, priv->editingBehavior);
1216 case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS:
1217 g_value_set_boolean(value, priv->enableUniversalAccessFromFileURIs);
1219 case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS:
1220 g_value_set_boolean(value, priv->enableFileAccessFromFileURIs);
1222 case PROP_ENABLE_DOM_PASTE:
1223 g_value_set_boolean(value, priv->enableDOMPaste);
1225 case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS:
1226 g_value_set_boolean(value, priv->tabKeyCyclesThroughElements);
1228 case PROP_ENABLE_DEFAULT_CONTEXT_MENU:
1229 g_value_set_boolean(value, priv->enableDefaultContextMenu);
1231 case PROP_ENABLE_SITE_SPECIFIC_QUIRKS:
1232 g_value_set_boolean(value, priv->enableSiteSpecificQuirks);
1234 case PROP_ENABLE_PAGE_CACHE:
1235 g_value_set_boolean(value, priv->enablePageCache);
1237 case PROP_AUTO_RESIZE_WINDOW:
1238 g_value_set_boolean(value, priv->autoResizeWindow);
1240 case PROP_ENABLE_JAVA_APPLET:
1241 g_value_set_boolean(value, priv->enableJavaApplet);
1243 case PROP_ENABLE_HYPERLINK_AUDITING:
1244 g_value_set_boolean(value, priv->enableHyperlinkAuditing);
1246 case PROP_ENABLE_FULLSCREEN:
1247 g_value_set_boolean(value, priv->enableFullscreen);
1249 case PROP_ENABLE_DNS_PREFETCHING:
1250 g_value_set_boolean(value, priv->enableDNSPrefetching);
1252 case PROP_ENABLE_WEBGL:
1253 g_value_set_boolean(value, priv->enableWebgl);
1256 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
1262 * webkit_web_settings_new:
1264 * Creates a new #WebKitWebSettings instance with default values. It must
1265 * be manually attached to a WebView.
1267 * Returns: a new #WebKitWebSettings instance
1269 WebKitWebSettings* webkit_web_settings_new()
1271 return WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, NULL));
1275 * webkit_web_settings_copy:
1276 * @web_settings: a #WebKitWebSettings to copy.
1278 * Copies an existing #WebKitWebSettings instance.
1280 * Returns: (transfer full): a new #WebKitWebSettings instance
1282 WebKitWebSettings* webkit_web_settings_copy(WebKitWebSettings* original)
1284 unsigned numberOfProperties = 0;
1285 GOwnPtr<GParamSpec*> properties(g_object_class_list_properties(
1286 G_OBJECT_CLASS(WEBKIT_WEB_SETTINGS_GET_CLASS(original)), &numberOfProperties));
1287 GOwnPtr<GParameter> parameters(g_new0(GParameter, numberOfProperties));
1289 for (size_t i = 0; i < numberOfProperties; i++) {
1290 GParamSpec* property = properties.get()[i];
1291 GParameter* parameter = parameters.get() + i;
1293 if (!(property->flags & (G_PARAM_CONSTRUCT | G_PARAM_READWRITE)))
1296 parameter->name = property->name;
1297 g_value_init(¶meter->value, property->value_type);
1298 g_object_get_property(G_OBJECT(original), property->name, ¶meter->value);
1301 return WEBKIT_WEB_SETTINGS(g_object_newv(WEBKIT_TYPE_WEB_SETTINGS, numberOfProperties, parameters.get()));
1306 * webkit_web_settings_add_extra_plugin_directory:
1307 * @web_view: a #WebKitWebView
1308 * @directory: the directory to add
1310 * Adds the @directory to paths where @web_view will search for plugins.
1314 void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* webView, const gchar* directory)
1316 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1317 PluginDatabase::installedPlugins()->addExtraPluginDirectory(filenameToString(directory));
1321 * webkit_web_settings_get_user_agent:
1322 * @web_settings: a #WebKitWebSettings
1324 * Returns: the User-Agent string currently used by the web view(s) associated
1325 * with the @web_settings.
1329 const gchar* webkit_web_settings_get_user_agent(WebKitWebSettings* webSettings)
1331 g_return_val_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings), 0);
1332 return webSettings->priv->userAgent.data();
1335 static void initializeDomainsList(HashSet<String>& googleDomains)
1337 // Google search domains.
1338 googleDomains.add("biz");
1339 googleDomains.add("com");
1340 googleDomains.add("net");
1341 googleDomains.add("org");
1342 googleDomains.add("ae");
1343 googleDomains.add("ag");
1344 googleDomains.add("am");
1345 googleDomains.add("at");
1346 googleDomains.add("az");
1347 googleDomains.add("be");
1348 googleDomains.add("bi");
1349 googleDomains.add("ca");
1350 googleDomains.add("cc");
1351 googleDomains.add("cd");
1352 googleDomains.add("cg");
1353 googleDomains.add("ch");
1354 googleDomains.add("cl");
1355 googleDomains.add("com.br");
1356 googleDomains.add("com.do");
1357 googleDomains.add("co.uk");
1358 googleDomains.add("co.kr");
1359 googleDomains.add("co.jp");
1360 googleDomains.add("de");
1361 googleDomains.add("dj");
1362 googleDomains.add("dk");
1363 googleDomains.add("ee");
1364 googleDomains.add("es");
1365 googleDomains.add("fi");
1366 googleDomains.add("fm");
1367 googleDomains.add("fr");
1368 googleDomains.add("gg");
1369 googleDomains.add("gl");
1370 googleDomains.add("gm");
1371 googleDomains.add("gs");
1372 googleDomains.add("hn");
1373 googleDomains.add("hu");
1374 googleDomains.add("ie");
1375 googleDomains.add("it");
1376 googleDomains.add("je");
1377 googleDomains.add("kz");
1378 googleDomains.add("li");
1379 googleDomains.add("lt");
1380 googleDomains.add("lu");
1381 googleDomains.add("lv");
1382 googleDomains.add("ma");
1383 googleDomains.add("ms");
1384 googleDomains.add("mu");
1385 googleDomains.add("mw");
1386 googleDomains.add("nl");
1387 googleDomains.add("no");
1388 googleDomains.add("nu");
1389 googleDomains.add("pl");
1390 googleDomains.add("pn");
1391 googleDomains.add("pt");
1392 googleDomains.add("ru");
1393 googleDomains.add("rw");
1394 googleDomains.add("sh");
1395 googleDomains.add("sk");
1396 googleDomains.add("sm");
1397 googleDomains.add("st");
1398 googleDomains.add("td");
1399 googleDomains.add("tk");
1400 googleDomains.add("tp");
1401 googleDomains.add("tv");
1402 googleDomains.add("us");
1403 googleDomains.add("uz");
1404 googleDomains.add("ws");
1407 static void initializeOtherGoogleDomains(Vector<String>& otherGoogleDomains)
1409 otherGoogleDomains.append("gmail.com");
1410 otherGoogleDomains.append("youtube.com");
1411 otherGoogleDomains.append("gstatic.com");
1412 otherGoogleDomains.append("ytimg.com");
1415 static bool isGoogleDomain(String host)
1417 DEFINE_STATIC_LOCAL(HashSet<String>, googleDomains, ());
1418 DEFINE_STATIC_LOCAL(Vector<String>, otherGoogleDomains, ());
1420 if (googleDomains.isEmpty())
1421 initializeDomainsList(googleDomains);
1423 if (otherGoogleDomains.isEmpty())
1424 initializeOtherGoogleDomains(otherGoogleDomains);
1426 // First check if this is one of the various google.com international domains.
1427 int position = host.find(".google.");
1428 if (position > 0 && googleDomains.contains(host.substring(position + sizeof(".google.") - 1)))
1431 // Then we check the possibility of it being one of the other, .com-only google domains.
1432 for (unsigned int i = 0; i < otherGoogleDomains.size(); i++) {
1433 if (host.endsWith(otherGoogleDomains.at(i)))
1440 static bool isGoogleCalendar(const KURL& url)
1442 if (url.host().find("calendar.google.") == 0
1443 || (url.host().find("google.com") && url.path().startsWith("/calendar")))
1449 static String userAgentForURL(const KURL& url)
1451 // For Google domains, drop the browser's custom User Agent string, and use the
1452 // standard WebKit/Safari one, so they don't give us a broken experience. Calendar
1453 // thinks "Linux WebKit" means mobile.
1454 if (isGoogleCalendar(url))
1455 return safariUserAgent();
1457 if (isGoogleDomain(url.host()))
1458 return webkitUserAgent();
1464 * Private usage only.
1465 * webkitWebSettingsUserAgentForURI:
1466 * @web_settings: the #WebKitWebSettings object to query
1467 * @uri: the URI we want to know the User-Agent for
1469 * Some web sites have been using User-Agent parsing heavily to decide
1470 * the kind of content that is sent to the browser. When
1471 * WebKitWebSettings:enable-site-specific-quirks is enabled WebKitGTK+
1472 * will use its knowledge of sites doing bad things and lie to them by
1473 * sending either the default User-Agent, i.e. not using the one
1474 * specified by the browser in WebKitWebSettings:user-agent, or the
1475 * Safari one (including lying about the underlying operating system).
1477 * This function allows the browser to figure out what User-Agent is
1478 * going to be sent to a particular URI.
1480 * Please note that if WebKitWebSettings:use-site-specific-quirks is
1481 * turned off calling this function is the same as calling
1482 * webkit_web_settings_get_user_agent(), except you have to free the
1485 * Returns: (transfer full): a newly allocated string containing the
1486 * User-Agent that will be sent for the given URI.
1488 char* webkitWebSettingsUserAgentForURI(WebKitWebSettings* webSettings, const char* uri)
1490 if (webSettings->priv->enableSiteSpecificQuirks) {
1491 String userAgentString = userAgentForURL(WebCore::KURL(WebCore::KURL(), String::fromUTF8(uri)));
1492 if (!userAgentString.isEmpty())
1493 return g_strdup(userAgentString.utf8().data());
1496 return g_strdup(webkit_web_settings_get_user_agent(webSettings));
1501 WebCore::EditingBehaviorType core(WebKitEditingBehavior type)
1503 return static_cast<WebCore::EditingBehaviorType>(type);