1 /*
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 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include "config.h"
25 #include "webkitwebsettings.h"
26
27 #include "webkitprivate.h"
28 #include "webkitversion.h"
29
30 #include "CString.h"
31 #include "FileSystem.h"
32 #include "PluginDatabase.h"
33 #include "Language.h"
34 #include "PlatformString.h"
35
36 #include <glib/gi18n-lib.h>
37 #if PLATFORM(UNIX)
38 #include <sys/utsname.h>
39 #endif
40
41 /**
42 * SECTION:webkitwebsettings
43 * @short_description: Control the behaviour of a #WebKitWebView
44 *
45 * #WebKitWebSettings can be applied to a #WebKitWebView to control
46 * the to be used text encoding, color, font sizes, printing mode,
47 * script support, loading of images and various other things.
48 *
49 * <informalexample><programlisting>
50 * /<!-- -->* Create a new websettings and disable java script *<!-- -->/
51 * WebKitWebSettings *settings = webkit_web_settings_new ();
52 * g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);
53 *
54 * /<!-- -->* Apply the result *<!-- -->/
55 * webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
56 * </programlisting></informalexample>
57 */
58
59 using namespace WebCore;
60
61 G_DEFINE_TYPE(WebKitWebSettings, webkit_web_settings, G_TYPE_OBJECT)
62
63 struct _WebKitWebSettingsPrivate {
64 gchar* default_encoding;
65 gchar* cursive_font_family;
66 gchar* default_font_family;
67 gchar* fantasy_font_family;
68 gchar* monospace_font_family;
69 gchar* sans_serif_font_family;
70 gchar* serif_font_family;
71 guint default_font_size;
72 guint default_monospace_font_size;
73 guint minimum_font_size;
74 guint minimum_logical_font_size;
75 gboolean enforce_96_dpi;
76 gboolean auto_load_images;
77 gboolean auto_shrink_images;
78 gboolean print_backgrounds;
79 gboolean enable_scripts;
80 gboolean enable_plugins;
81 gboolean resizable_text_areas;
82 gchar* user_stylesheet_uri;
83 gfloat zoom_step;
84 gboolean enable_developer_extras;
85 gboolean enable_private_browsing;
86 gboolean enable_spell_checking;
87 gchar* spell_checking_languages;
88 GSList* spell_checking_languages_list;
89 gboolean enable_caret_browsing;
90 gboolean enable_html5_database;
91 gboolean enable_html5_local_storage;
92 gboolean enable_xss_auditor;
93 gchar* user_agent;
94 gboolean javascript_can_open_windows_automatically;
95 gboolean enable_offline_web_application_cache;
96 };
97
98 #define WEBKIT_WEB_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate))
99
100 enum {
101 PROP_0,
102
103 PROP_DEFAULT_ENCODING,
104 PROP_CURSIVE_FONT_FAMILY,
105 PROP_DEFAULT_FONT_FAMILY,
106 PROP_FANTASY_FONT_FAMILY,
107 PROP_MONOSPACE_FONT_FAMILY,
108 PROP_SANS_SERIF_FONT_FAMILY,
109 PROP_SERIF_FONT_FAMILY,
110 PROP_DEFAULT_FONT_SIZE,
111 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
112 PROP_MINIMUM_FONT_SIZE,
113 PROP_MINIMUM_LOGICAL_FONT_SIZE,
114 PROP_ENFORCE_96_DPI,
115 PROP_AUTO_LOAD_IMAGES,
116 PROP_AUTO_SHRINK_IMAGES,
117 PROP_PRINT_BACKGROUNDS,
118 PROP_ENABLE_SCRIPTS,
119 PROP_ENABLE_PLUGINS,
120 PROP_RESIZABLE_TEXT_AREAS,
121 PROP_USER_STYLESHEET_URI,
122 PROP_ZOOM_STEP,
123 PROP_ENABLE_DEVELOPER_EXTRAS,
124 PROP_ENABLE_PRIVATE_BROWSING,
125 PROP_ENABLE_SPELL_CHECKING,
126 PROP_SPELL_CHECKING_LANGUAGES,
127 PROP_ENABLE_CARET_BROWSING,
128 PROP_ENABLE_HTML5_DATABASE,
129 PROP_ENABLE_HTML5_LOCAL_STORAGE,
130 PROP_ENABLE_XSS_AUDITOR,
131 PROP_USER_AGENT,
132 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
133 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE
134 };
135
136 // Create a default user agent string
137 // This is a liberal interpretation of http://www.mozilla.org/build/revised-user-agent-strings.html
138 // See also http://developer.apple.com/internet/safari/faq.html#anchor2
webkit_get_user_agent()139 static String webkit_get_user_agent()
140 {
141 gchar* platform;
142 gchar* osVersion;
143
144 #if PLATFORM(X11)
145 platform = g_strdup("X11");
146 #elif PLATFORM(WIN_OS)
147 platform = g_strdup("Windows");
148 #elif PLATFORM(MAC)
149 platform = g_strdup("Macintosh");
150 #elif defined(GDK_WINDOWING_DIRECTFB)
151 platform = g_strdup("DirectFB");
152 #else
153 platform = g_strdup("Unknown");
154 #endif
155
156 // FIXME: platform/version detection can be shared.
157 #if PLATFORM(DARWIN)
158
159 #if PLATFORM(X86)
160 osVersion = g_strdup("Intel Mac OS X");
161 #else
162 osVersion = g_strdup("PPC Mac OS X");
163 #endif
164
165 #elif PLATFORM(UNIX)
166 struct utsname name;
167 if (uname(&name) != -1)
168 osVersion = g_strdup_printf("%s %s", name.sysname, name.machine);
169 else
170 osVersion = g_strdup("Unknown");
171
172 #elif PLATFORM(WIN_OS)
173 // FIXME: Compute the Windows version
174 osVersion = g_strdup("Windows");
175
176 #else
177 osVersion = g_strdup("Unknown");
178 #endif
179
180 // We mention Safari since many broken sites check for it (OmniWeb does this too)
181 // We re-use the WebKit version, though it doesn't seem to matter much in practice
182
183 DEFINE_STATIC_LOCAL(const String, uaVersion, (String::format("%d.%d+", WEBKIT_USER_AGENT_MAJOR_VERSION, WEBKIT_USER_AGENT_MINOR_VERSION)));
184 DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (%s; U; %s; %s) AppleWebKit/%s (KHTML, like Gecko) Safari/%s",
185 platform, osVersion, defaultLanguage().utf8().data(), uaVersion.utf8().data(), uaVersion.utf8().data())));
186
187 g_free(osVersion);
188 g_free(platform);
189
190 return staticUA;
191 }
192
193 static void webkit_web_settings_finalize(GObject* object);
194
195 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
196
197 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);
198
webkit_web_settings_class_init(WebKitWebSettingsClass * klass)199 static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass)
200 {
201 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
202 gobject_class->finalize = webkit_web_settings_finalize;
203 gobject_class->set_property = webkit_web_settings_set_property;
204 gobject_class->get_property = webkit_web_settings_get_property;
205
206 webkit_init();
207
208 GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT);
209
210 g_object_class_install_property(gobject_class,
211 PROP_DEFAULT_ENCODING,
212 g_param_spec_string(
213 "default-encoding",
214 _("Default Encoding"),
215 _("The default encoding used to display text."),
216 "iso-8859-1",
217 flags));
218
219 g_object_class_install_property(gobject_class,
220 PROP_CURSIVE_FONT_FAMILY,
221 g_param_spec_string(
222 "cursive-font-family",
223 _("Cursive Font Family"),
224 _("The default Cursive font family used to display text."),
225 "serif",
226 flags));
227
228 g_object_class_install_property(gobject_class,
229 PROP_DEFAULT_FONT_FAMILY,
230 g_param_spec_string(
231 "default-font-family",
232 _("Default Font Family"),
233 _("The default font family used to display text."),
234 "sans-serif",
235 flags));
236
237 g_object_class_install_property(gobject_class,
238 PROP_FANTASY_FONT_FAMILY,
239 g_param_spec_string(
240 "fantasy-font-family",
241 _("Fantasy Font Family"),
242 _("The default Fantasy font family used to display text."),
243 "serif",
244 flags));
245
246 g_object_class_install_property(gobject_class,
247 PROP_MONOSPACE_FONT_FAMILY,
248 g_param_spec_string(
249 "monospace-font-family",
250 _("Monospace Font Family"),
251 _("The default font family used to display monospace text."),
252 "monospace",
253 flags));
254
255 g_object_class_install_property(gobject_class,
256 PROP_SANS_SERIF_FONT_FAMILY,
257 g_param_spec_string(
258 "sans-serif-font-family",
259 _("Sans Serif Font Family"),
260 _("The default Sans Serif font family used to display text."),
261 "sans-serif",
262 flags));
263
264 g_object_class_install_property(gobject_class,
265 PROP_SERIF_FONT_FAMILY,
266 g_param_spec_string(
267 "serif-font-family",
268 _("Serif Font Family"),
269 _("The default Serif font family used to display text."),
270 "serif",
271 flags));
272
273 g_object_class_install_property(gobject_class,
274 PROP_DEFAULT_FONT_SIZE,
275 g_param_spec_int(
276 "default-font-size",
277 _("Default Font Size"),
278 _("The default font size used to display text."),
279 5, G_MAXINT, 12,
280 flags));
281
282 g_object_class_install_property(gobject_class,
283 PROP_DEFAULT_MONOSPACE_FONT_SIZE,
284 g_param_spec_int(
285 "default-monospace-font-size",
286 _("Default Monospace Font Size"),
287 _("The default font size used to display monospace text."),
288 5, G_MAXINT, 10,
289 flags));
290
291 g_object_class_install_property(gobject_class,
292 PROP_MINIMUM_FONT_SIZE,
293 g_param_spec_int(
294 "minimum-font-size",
295 _("Minimum Font Size"),
296 _("The minimum font size used to display text."),
297 1, G_MAXINT, 5,
298 flags));
299
300 g_object_class_install_property(gobject_class,
301 PROP_MINIMUM_LOGICAL_FONT_SIZE,
302 g_param_spec_int(
303 "minimum-logical-font-size",
304 _("Minimum Logical Font Size"),
305 _("The minimum logical font size used to display text."),
306 1, G_MAXINT, 5,
307 flags));
308
309 /**
310 * WebKitWebSettings:enforce-96-dpi:
311 *
312 * Enforce a resolution of 96 DPI. This is meant for compatibility
313 * with web pages which cope badly with different screen resolutions
314 * and for automated testing.
315 * Web browsers and applications that typically display arbitrary
316 * content from the web should provide a preference for this.
317 *
318 * Since: 1.0.3
319 */
320 g_object_class_install_property(gobject_class,
321 PROP_ENFORCE_96_DPI,
322 g_param_spec_boolean(
323 "enforce-96-dpi",
324 _("Enforce 96 DPI"),
325 _("Enforce a resolution of 96 DPI"),
326 FALSE,
327 flags));
328
329 g_object_class_install_property(gobject_class,
330 PROP_AUTO_LOAD_IMAGES,
331 g_param_spec_boolean(
332 "auto-load-images",
333 _("Auto Load Images"),
334 _("Load images automatically."),
335 TRUE,
336 flags));
337
338 g_object_class_install_property(gobject_class,
339 PROP_AUTO_SHRINK_IMAGES,
340 g_param_spec_boolean(
341 "auto-shrink-images",
342 _("Auto Shrink Images"),
343 _("Automatically shrink standalone images to fit."),
344 TRUE,
345 flags));
346
347 g_object_class_install_property(gobject_class,
348 PROP_PRINT_BACKGROUNDS,
349 g_param_spec_boolean(
350 "print-backgrounds",
351 _("Print Backgrounds"),
352 _("Whether background images should be printed."),
353 TRUE,
354 flags));
355
356 g_object_class_install_property(gobject_class,
357 PROP_ENABLE_SCRIPTS,
358 g_param_spec_boolean(
359 "enable-scripts",
360 _("Enable Scripts"),
361 _("Enable embedded scripting languages."),
362 TRUE,
363 flags));
364
365 g_object_class_install_property(gobject_class,
366 PROP_ENABLE_PLUGINS,
367 g_param_spec_boolean(
368 "enable-plugins",
369 _("Enable Plugins"),
370 _("Enable embedded plugin objects."),
371 TRUE,
372 flags));
373
374 g_object_class_install_property(gobject_class,
375 PROP_RESIZABLE_TEXT_AREAS,
376 g_param_spec_boolean(
377 "resizable-text-areas",
378 _("Resizable Text Areas"),
379 _("Whether text areas are resizable."),
380 TRUE,
381 flags));
382
383 g_object_class_install_property(gobject_class,
384 PROP_USER_STYLESHEET_URI,
385 g_param_spec_string("user-stylesheet-uri",
386 _("User Stylesheet URI"),
387 _("The URI of a stylesheet that is applied to every page."),
388 0,
389 flags));
390
391 /**
392 * WebKitWebSettings:zoom-step:
393 *
394 * The value by which the zoom level is changed when zooming in or out.
395 *
396 * Since: 1.0.1
397 */
398 g_object_class_install_property(gobject_class,
399 PROP_ZOOM_STEP,
400 g_param_spec_float(
401 "zoom-step",
402 _("Zoom Stepping Value"),
403 _("The value by which the zoom level is changed when zooming in or out."),
404 0.0f, G_MAXFLOAT, 0.1f,
405 flags));
406
407 /**
408 * WebKitWebSettings:enable-developer-extras:
409 *
410 * Whether developer extensions should be enabled. This enables,
411 * for now, the Web Inspector, which can be controlled using the
412 * #WebKitWebInspector instance held by the #WebKitWebView this
413 * setting is enabled for.
414 *
415 * Since: 1.0.3
416 */
417 g_object_class_install_property(gobject_class,
418 PROP_ENABLE_DEVELOPER_EXTRAS,
419 g_param_spec_boolean(
420 "enable-developer-extras",
421 _("Enable Developer Extras"),
422 _("Enables special extensions that help developers"),
423 FALSE,
424 flags));
425
426 /**
427 * WebKitWebSettings:enable-private-browsing:
428 *
429 * Whether to enable private browsing mode. Private browsing mode prevents
430 * WebKit from updating the global history and storing any session
431 * information e.g., on-disk cache, as well as suppressing any messages
432 * from being printed into the (javascript) console.
433 *
434 * This is currently experimental for WebKitGtk.
435 *
436 * Since 1.1.2
437 */
438 g_object_class_install_property(gobject_class,
439 PROP_ENABLE_PRIVATE_BROWSING,
440 g_param_spec_boolean(
441 "enable-private-browsing",
442 _("Enable Private Browsing"),
443 _("Enables private browsing mode"),
444 FALSE,
445 flags));
446
447 /**
448 * WebKitWebSettings:enable-spell-checking:
449 *
450 * Whether to enable spell checking while typing.
451 *
452 * Since 1.1.6
453 */
454 g_object_class_install_property(gobject_class,
455 PROP_ENABLE_SPELL_CHECKING,
456 g_param_spec_boolean(
457 "enable-spell-checking",
458 _("Enable Spell Checking"),
459 _("Enables spell checking while typing"),
460 FALSE,
461 flags));
462
463 /**
464 * WebKitWebSettings:spell-checking-languages:
465 *
466 * The languages to be used for spell checking, separated by commas.
467 *
468 * The locale string typically is in the form lang_COUNTRY, where lang
469 * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code.
470 * For instance, sv_FI for Swedish as written in Finland or pt_BR
471 * for Portuguese as written in Brazil.
472 *
473 * If no value is specified then the value returned by
474 * gtk_get_default_language will be used.
475 *
476 * Since 1.1.6
477 */
478 g_object_class_install_property(gobject_class,
479 PROP_SPELL_CHECKING_LANGUAGES,
480 g_param_spec_string(
481 "spell-checking-languages",
482 _("Languages to use for spell checking"),
483 _("Comma separated list of languages to use for spell checking"),
484 0,
485 flags));
486
487 /**
488 * WebKitWebSettings:enable-caret-browsing:
489 *
490 * Whether to enable caret browsing mode.
491 *
492 * Since 1.1.6
493 */
494 g_object_class_install_property(gobject_class,
495 PROP_ENABLE_CARET_BROWSING,
496 g_param_spec_boolean("enable-caret-browsing",
497 _("Enable Caret Browsing"),
498 _("Whether to enable accesibility enhanced keyboard navigation"),
499 FALSE,
500 flags));
501 /**
502 * WebKitWebSettings:enable-html5-database:
503 *
504 * Whether to enable HTML5 client-side SQL database support. Client-side
505 * SQL database allows web pages to store structured data and be able to
506 * use SQL to manipulate that data asynchronously.
507 *
508 * Since 1.1.8
509 */
510 g_object_class_install_property(gobject_class,
511 PROP_ENABLE_HTML5_DATABASE,
512 g_param_spec_boolean("enable-html5-database",
513 _("Enable HTML5 Database"),
514 _("Whether to enable HTML5 database support"),
515 TRUE,
516 flags));
517
518 /**
519 * WebKitWebSettings:enable-html5-local-storage:
520 *
521 * Whether to enable HTML5 localStorage support. localStorage provides
522 * simple synchronous storage access.
523 *
524 * Since 1.1.8
525 */
526 g_object_class_install_property(gobject_class,
527 PROP_ENABLE_HTML5_LOCAL_STORAGE,
528 g_param_spec_boolean("enable-html5-local-storage",
529 _("Enable HTML5 Local Storage"),
530 _("Whether to enable HTML5 Local Storage support"),
531 TRUE,
532 flags));
533 /**
534 * WebKitWebSettings:enable-xss-auditor
535 *
536 * Whether to enable the XSS Auditor. This feature filters some kinds of
537 * reflective XSS attacks on vulnerable web sites.
538 *
539 * Since 1.1.11
540 */
541 g_object_class_install_property(gobject_class,
542 PROP_ENABLE_XSS_AUDITOR,
543 g_param_spec_boolean("enable-xss-auditor",
544 _("Enable XSS Auditor"),
545 _("Whether to enable teh XSS auditor"),
546 TRUE,
547 flags));
548
549 /**
550 * WebKitWebSettings:user-agent:
551 *
552 * The User-Agent string used by WebKitGtk.
553 *
554 * This will return a default User-Agent string if a custom string wasn't
555 * provided by the application. Setting this property to a NULL value or
556 * an empty string will result in the User-Agent string being reset to the
557 * default value.
558 *
559 * Since: 1.1.11
560 */
561 g_object_class_install_property(gobject_class, PROP_USER_AGENT,
562 g_param_spec_string("user-agent",
563 _("User Agent"),
564 _("The User-Agent string used by WebKitGtk"),
565 webkit_get_user_agent().utf8().data(),
566 flags));
567
568 /**
569 * WebKitWebSettings:javascript-can-open-windows-automatically
570 *
571 * Whether JavaScript can open popup windows automatically without user
572 * intervention.
573 *
574 * Since 1.1.11
575 */
576 g_object_class_install_property(gobject_class,
577 PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY,
578 g_param_spec_boolean("javascript-can-open-windows-automatically",
579 _("JavaScript can open windows automatically"),
580 _("Whether JavaScript can open windows automatically"),
581 FALSE,
582 flags));
583 /**
584 * WebKitWebSettings:enable-offline-web-application-cache
585 *
586 * Whether to enable HTML5 offline web application cache support. Offline
587 * Web Application Cache ensures web applications are available even when
588 * the user is not connected to the network.
589 *
590 * Since 1.1.13
591 */
592 g_object_class_install_property(gobject_class,
593 PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE,
594 g_param_spec_boolean("enable-offline-web-application-cache",
595 _("Enable offline web application cache"),
596 _("Whether to enable offline web application cache"),
597 TRUE,
598 flags));
599
600
601
602 g_type_class_add_private(klass, sizeof(WebKitWebSettingsPrivate));
603 }
604
webkit_web_settings_init(WebKitWebSettings * web_settings)605 static void webkit_web_settings_init(WebKitWebSettings* web_settings)
606 {
607 web_settings->priv = WEBKIT_WEB_SETTINGS_GET_PRIVATE(web_settings);
608 }
609
free_spell_checking_language(gpointer data,gpointer user_data)610 static void free_spell_checking_language(gpointer data, gpointer user_data)
611 {
612 SpellLanguage* language = static_cast<SpellLanguage*>(data);
613 if (language->config) {
614 if (language->speller)
615 enchant_broker_free_dict(language->config, language->speller);
616
617 enchant_broker_free(language->config);
618 }
619 g_slice_free(SpellLanguage, language);
620 }
621
webkit_web_settings_finalize(GObject * object)622 static void webkit_web_settings_finalize(GObject* object)
623 {
624 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
625 WebKitWebSettingsPrivate* priv = web_settings->priv;
626
627 g_free(priv->default_encoding);
628 g_free(priv->cursive_font_family);
629 g_free(priv->default_font_family);
630 g_free(priv->fantasy_font_family);
631 g_free(priv->monospace_font_family);
632 g_free(priv->sans_serif_font_family);
633 g_free(priv->serif_font_family);
634 g_free(priv->user_stylesheet_uri);
635 g_free(priv->spell_checking_languages);
636
637 g_slist_foreach(priv->spell_checking_languages_list, free_spell_checking_language, NULL);
638 g_slist_free(priv->spell_checking_languages_list);
639
640 g_free(priv->user_agent);
641
642 G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object);
643 }
644
webkit_web_settings_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)645 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
646 {
647 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
648 WebKitWebSettingsPrivate* priv = web_settings->priv;
649 SpellLanguage* lang;
650 GSList* spellLanguages = NULL;
651
652 switch(prop_id) {
653 case PROP_DEFAULT_ENCODING:
654 g_free(priv->default_encoding);
655 priv->default_encoding = g_strdup(g_value_get_string(value));
656 break;
657 case PROP_CURSIVE_FONT_FAMILY:
658 g_free(priv->cursive_font_family);
659 priv->cursive_font_family = g_strdup(g_value_get_string(value));
660 break;
661 case PROP_DEFAULT_FONT_FAMILY:
662 g_free(priv->default_font_family);
663 priv->default_font_family = g_strdup(g_value_get_string(value));
664 break;
665 case PROP_FANTASY_FONT_FAMILY:
666 g_free(priv->fantasy_font_family);
667 priv->fantasy_font_family = g_strdup(g_value_get_string(value));
668 break;
669 case PROP_MONOSPACE_FONT_FAMILY:
670 g_free(priv->monospace_font_family);
671 priv->monospace_font_family = g_strdup(g_value_get_string(value));
672 break;
673 case PROP_SANS_SERIF_FONT_FAMILY:
674 g_free(priv->sans_serif_font_family);
675 priv->sans_serif_font_family = g_strdup(g_value_get_string(value));
676 break;
677 case PROP_SERIF_FONT_FAMILY:
678 g_free(priv->serif_font_family);
679 priv->serif_font_family = g_strdup(g_value_get_string(value));
680 break;
681 case PROP_DEFAULT_FONT_SIZE:
682 priv->default_font_size = g_value_get_int(value);
683 break;
684 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
685 priv->default_monospace_font_size = g_value_get_int(value);
686 break;
687 case PROP_MINIMUM_FONT_SIZE:
688 priv->minimum_font_size = g_value_get_int(value);
689 break;
690 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
691 priv->minimum_logical_font_size = g_value_get_int(value);
692 break;
693 case PROP_ENFORCE_96_DPI:
694 priv->enforce_96_dpi = g_value_get_boolean(value);
695 break;
696 case PROP_AUTO_LOAD_IMAGES:
697 priv->auto_load_images = g_value_get_boolean(value);
698 break;
699 case PROP_AUTO_SHRINK_IMAGES:
700 priv->auto_shrink_images = g_value_get_boolean(value);
701 break;
702 case PROP_PRINT_BACKGROUNDS:
703 priv->print_backgrounds = g_value_get_boolean(value);
704 break;
705 case PROP_ENABLE_SCRIPTS:
706 priv->enable_scripts = g_value_get_boolean(value);
707 break;
708 case PROP_ENABLE_PLUGINS:
709 priv->enable_plugins = g_value_get_boolean(value);
710 break;
711 case PROP_RESIZABLE_TEXT_AREAS:
712 priv->resizable_text_areas = g_value_get_boolean(value);
713 break;
714 case PROP_USER_STYLESHEET_URI:
715 g_free(priv->user_stylesheet_uri);
716 priv->user_stylesheet_uri = g_strdup(g_value_get_string(value));
717 break;
718 case PROP_ZOOM_STEP:
719 priv->zoom_step = g_value_get_float(value);
720 break;
721 case PROP_ENABLE_DEVELOPER_EXTRAS:
722 priv->enable_developer_extras = g_value_get_boolean(value);
723 break;
724 case PROP_ENABLE_PRIVATE_BROWSING:
725 priv->enable_private_browsing = g_value_get_boolean(value);
726 break;
727 case PROP_ENABLE_CARET_BROWSING:
728 priv->enable_caret_browsing = g_value_get_boolean(value);
729 break;
730 case PROP_ENABLE_HTML5_DATABASE:
731 priv->enable_html5_database = g_value_get_boolean(value);
732 break;
733 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
734 priv->enable_html5_local_storage = g_value_get_boolean(value);
735 break;
736 case PROP_ENABLE_SPELL_CHECKING:
737 priv->enable_spell_checking = g_value_get_boolean(value);
738 break;
739 case PROP_SPELL_CHECKING_LANGUAGES:
740 priv->spell_checking_languages = g_strdup(g_value_get_string(value));
741
742 if (priv->spell_checking_languages) {
743 char** langs = g_strsplit(priv->spell_checking_languages, ",", -1);
744 for (int i = 0; langs[i]; i++) {
745 lang = g_slice_new0(SpellLanguage);
746 lang->config = enchant_broker_init();
747 lang->speller = enchant_broker_request_dict(lang->config, langs[i]);
748
749 spellLanguages = g_slist_append(spellLanguages, lang);
750 }
751
752 g_strfreev(langs);
753 } else {
754 const char* language = pango_language_to_string(gtk_get_default_language());
755
756 lang = g_slice_new0(SpellLanguage);
757 lang->config = enchant_broker_init();
758 lang->speller = enchant_broker_request_dict(lang->config, language);
759
760 spellLanguages = g_slist_append(spellLanguages, lang);
761 }
762 g_slist_foreach(priv->spell_checking_languages_list, free_spell_checking_language, NULL);
763 g_slist_free(priv->spell_checking_languages_list);
764 priv->spell_checking_languages_list = spellLanguages;
765 break;
766 case PROP_ENABLE_XSS_AUDITOR:
767 priv->enable_xss_auditor = g_value_get_boolean(value);
768 break;
769 case PROP_USER_AGENT:
770 g_free(priv->user_agent);
771 if (!g_value_get_string(value) || !strlen(g_value_get_string(value)))
772 priv->user_agent = g_strdup(webkit_get_user_agent().utf8().data());
773 else
774 priv->user_agent = g_strdup(g_value_get_string(value));
775 break;
776 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
777 priv->javascript_can_open_windows_automatically = g_value_get_boolean(value);
778 break;
779 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
780 priv->enable_offline_web_application_cache = g_value_get_boolean(value);
781 break;
782 default:
783 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
784 break;
785 }
786 }
787
webkit_web_settings_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)788 static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
789 {
790 WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object);
791 WebKitWebSettingsPrivate* priv = web_settings->priv;
792
793 switch (prop_id) {
794 case PROP_DEFAULT_ENCODING:
795 g_value_set_string(value, priv->default_encoding);
796 break;
797 case PROP_CURSIVE_FONT_FAMILY:
798 g_value_set_string(value, priv->cursive_font_family);
799 break;
800 case PROP_DEFAULT_FONT_FAMILY:
801 g_value_set_string(value, priv->default_font_family);
802 break;
803 case PROP_FANTASY_FONT_FAMILY:
804 g_value_set_string(value, priv->fantasy_font_family);
805 break;
806 case PROP_MONOSPACE_FONT_FAMILY:
807 g_value_set_string(value, priv->monospace_font_family);
808 break;
809 case PROP_SANS_SERIF_FONT_FAMILY:
810 g_value_set_string(value, priv->sans_serif_font_family);
811 break;
812 case PROP_SERIF_FONT_FAMILY:
813 g_value_set_string(value, priv->serif_font_family);
814 break;
815 case PROP_DEFAULT_FONT_SIZE:
816 g_value_set_int(value, priv->default_font_size);
817 break;
818 case PROP_DEFAULT_MONOSPACE_FONT_SIZE:
819 g_value_set_int(value, priv->default_monospace_font_size);
820 break;
821 case PROP_MINIMUM_FONT_SIZE:
822 g_value_set_int(value, priv->minimum_font_size);
823 break;
824 case PROP_MINIMUM_LOGICAL_FONT_SIZE:
825 g_value_set_int(value, priv->minimum_logical_font_size);
826 break;
827 case PROP_ENFORCE_96_DPI:
828 g_value_set_boolean(value, priv->enforce_96_dpi);
829 break;
830 case PROP_AUTO_LOAD_IMAGES:
831 g_value_set_boolean(value, priv->auto_load_images);
832 break;
833 case PROP_AUTO_SHRINK_IMAGES:
834 g_value_set_boolean(value, priv->auto_shrink_images);
835 break;
836 case PROP_PRINT_BACKGROUNDS:
837 g_value_set_boolean(value, priv->print_backgrounds);
838 break;
839 case PROP_ENABLE_SCRIPTS:
840 g_value_set_boolean(value, priv->enable_scripts);
841 break;
842 case PROP_ENABLE_PLUGINS:
843 g_value_set_boolean(value, priv->enable_plugins);
844 break;
845 case PROP_RESIZABLE_TEXT_AREAS:
846 g_value_set_boolean(value, priv->resizable_text_areas);
847 break;
848 case PROP_USER_STYLESHEET_URI:
849 g_value_set_string(value, priv->user_stylesheet_uri);
850 break;
851 case PROP_ZOOM_STEP:
852 g_value_set_float(value, priv->zoom_step);
853 break;
854 case PROP_ENABLE_DEVELOPER_EXTRAS:
855 g_value_set_boolean(value, priv->enable_developer_extras);
856 break;
857 case PROP_ENABLE_PRIVATE_BROWSING:
858 g_value_set_boolean(value, priv->enable_private_browsing);
859 break;
860 case PROP_ENABLE_CARET_BROWSING:
861 g_value_set_boolean(value, priv->enable_caret_browsing);
862 break;
863 case PROP_ENABLE_HTML5_DATABASE:
864 g_value_set_boolean(value, priv->enable_html5_database);
865 break;
866 case PROP_ENABLE_HTML5_LOCAL_STORAGE:
867 g_value_set_boolean(value, priv->enable_html5_local_storage);
868 break;
869 case PROP_ENABLE_SPELL_CHECKING:
870 g_value_set_boolean(value, priv->enable_spell_checking);
871 break;
872 case PROP_SPELL_CHECKING_LANGUAGES:
873 g_value_set_string(value, priv->spell_checking_languages);
874 break;
875 case PROP_ENABLE_XSS_AUDITOR:
876 g_value_set_boolean(value, priv->enable_xss_auditor);
877 break;
878 case PROP_USER_AGENT:
879 g_value_set_string(value, priv->user_agent);
880 break;
881 case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY:
882 g_value_set_boolean(value, priv->javascript_can_open_windows_automatically);
883 break;
884 case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE:
885 g_value_set_boolean(value, priv->enable_offline_web_application_cache);
886 break;
887 default:
888 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
889 break;
890 }
891 }
892
893 /**
894 * webkit_web_settings_new:
895 *
896 * Creates a new #WebKitWebSettings instance with default values. It must
897 * be manually attached to a WebView.
898 *
899 * Returns: a new #WebKitWebSettings instance
900 **/
webkit_web_settings_new()901 WebKitWebSettings* webkit_web_settings_new()
902 {
903 return WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, NULL));
904 }
905
906 /**
907 * webkit_web_settings_copy:
908 *
909 * Copies an existing #WebKitWebSettings instance.
910 *
911 * Returns: a new #WebKitWebSettings instance
912 **/
webkit_web_settings_copy(WebKitWebSettings * web_settings)913 WebKitWebSettings* webkit_web_settings_copy(WebKitWebSettings* web_settings)
914 {
915 WebKitWebSettingsPrivate* priv = web_settings->priv;
916
917 WebKitWebSettings* copy = WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS,
918 "default-encoding", priv->default_encoding,
919 "cursive-font-family", priv->cursive_font_family,
920 "default-font-family", priv->default_font_family,
921 "fantasy-font-family", priv->fantasy_font_family,
922 "monospace-font-family", priv->monospace_font_family,
923 "sans-serif-font-family", priv->sans_serif_font_family,
924 "serif-font-family", priv->serif_font_family,
925 "default-font-size", priv->default_font_size,
926 "default-monospace-font-size", priv->default_monospace_font_size,
927 "minimum-font-size", priv->minimum_font_size,
928 "minimum-logical-font-size", priv->minimum_logical_font_size,
929 "auto-load-images", priv->auto_load_images,
930 "auto-shrink-images", priv->auto_shrink_images,
931 "print-backgrounds", priv->print_backgrounds,
932 "enable-scripts", priv->enable_scripts,
933 "enable-plugins", priv->enable_plugins,
934 "resizable-text-areas", priv->resizable_text_areas,
935 "user-stylesheet-uri", priv->user_stylesheet_uri,
936 "zoom-step", priv->zoom_step,
937 "enable-developer-extras", priv->enable_developer_extras,
938 "enable-private-browsing", priv->enable_private_browsing,
939 "enable-spell-checking", priv->enable_spell_checking,
940 "spell-checking-languages", priv->spell_checking_languages,
941 "spell-checking-languages-list", priv->spell_checking_languages_list,
942 "enable-caret-browsing", priv->enable_caret_browsing,
943 "enable-html5-database", priv->enable_html5_database,
944 "enable-html5-local-storage", priv->enable_html5_local_storage,
945 "enable-xss-auditor", priv->enable_xss_auditor,
946 "user-agent", webkit_web_settings_get_user_agent(web_settings),
947 "javascript-can-open-windows-automatically", priv->javascript_can_open_windows_automatically,
948 "enable-offline-web-application-cache", priv->enable_offline_web_application_cache,
949 NULL));
950
951 return copy;
952 }
953
954 /**
955 * webkit_web_settings_add_extra_plugin_directory:
956 * @web_view: a #WebKitWebView
957 * @directory: the directory to add
958 *
959 * Adds the @directory to paths where @web_view will search for plugins.
960 *
961 * Since: 1.0.3
962 */
webkit_web_settings_add_extra_plugin_directory(WebKitWebView * webView,const gchar * directory)963 void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* webView, const gchar* directory)
964 {
965 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
966
967 PluginDatabase::installedPlugins()->addExtraPluginDirectory(filenameToString(directory));
968 }
969
970 /**
971 * webkit_web_settings_get_spell_languages:
972 * @web_view: a #WebKitWebView
973 *
974 * Internal use only. Retrieves a GSList of SpellLanguages from the
975 * #WebKitWebSettings of @web_view.
976 *
977 * Since: 1.1.6
978 */
webkit_web_settings_get_spell_languages(WebKitWebView * web_view)979 GSList* webkit_web_settings_get_spell_languages(WebKitWebView *web_view)
980 {
981 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(web_view), 0);
982
983 WebKitWebSettings* settings = webkit_web_view_get_settings(web_view);
984 WebKitWebSettingsPrivate* priv = settings->priv;
985 GSList* list = priv->spell_checking_languages_list;
986
987 return list;
988 }
989
990 /**
991 * webkit_web_settings_get_user_agent:
992 * @web_settings: a #WebKitWebSettings
993 *
994 * Returns the User-Agent string currently used by the web view(s) associated
995 * with the @web_settings.
996 *
997 * Since: 1.1.11
998 */
webkit_web_settings_get_user_agent(WebKitWebSettings * webSettings)999 G_CONST_RETURN gchar* webkit_web_settings_get_user_agent(WebKitWebSettings* webSettings)
1000 {
1001 g_return_val_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings), NULL);
1002
1003 WebKitWebSettingsPrivate* priv = webSettings->priv;
1004
1005 return priv->user_agent;
1006 }
1007