[webkit-gtk] dns prefetching knob

Marco Peereboom slash at peereboom.us
Tue Mar 8 16:07:24 PST 2011


I created a bug report to add a DNS prefetch knob but I was advised to
also send the patch to the mailing list.

With this knob I can make the web browser I wrote (xxxterm
http://opensource.conformal.com/wiki/XXXTerm ) much snappier on sites
with lots of embedded domain names (news.google.com for example).

The diff is against the 1.2.7 snapshot
http://webkitgtk.org/webkit-1.2.7.tar.gz

Original report:
https://bugs.webkit.org/show_bug.cgi?id=55973

--- WebCore/ChangeLog.orig	Tue Mar  8 16:16:50 2011
+++ WebCore/ChangeLog	Tue Mar  8 16:10:10 2011
@@ -1,3 +1,19 @@
+2011-03-08  Marco Peereboom   <marco at peereboom.u>
+
+        Reviewed no one yet
+
+        Backport code to enable/disable dns prefetching.
+        DNS prefetching is enabled by default.
+        https://bugs.webkit.org/show_bug.cgi?id=28825
+
+        * dom/Document.cpp:
+        (WebCore::Document::initDNSPrefetch): Check settings->dnsPrefetchingEnabled().
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings): Set m_dnsPrefetchingEnabled to true.
+        (WebCore::Settings::setDNSPrefetchingEnabled): Added. Set m_dnsPrefetchingEnabled.
+        * page/Settings.h:
+        (WebCore::Settings::dnsPrefetchingEnabled): Added. Return m_dnsPrefetchingEnabled.
+
 2010-06-21  Philippe Normand  <pnormand at igalia.com>
 
         Reviewed by Xan Lopez.
--- WebCore/dom/Document.cpp.orig	Fri Sep 10 08:20:33 2010
+++ WebCore/dom/Document.cpp	Tue Mar  8 10:16:45 2011
@@ -4639,8 +4639,10 @@ HTMLCanvasElement* Document::getCSSCanvasElement(const
 
 void Document::initDNSPrefetch()
 {
+    Settings* settings = this->settings();
+
     m_haveExplicitlyDisabledDNSPrefetch = false;
-    m_isDNSPrefetchEnabled = securityOrigin()->protocol() == "http";
+    m_isDNSPrefetchEnabled = settings && settings->dnsPrefetchingEnabled() && securityOrigin()->protocol() == "http";
 
     // Inherit DNS prefetch opt-out from parent frame    
     if (Document* parent = parentDocument()) {
--- WebCore/page/Settings.cpp.orig	Fri Sep 10 08:20:33 2010
+++ WebCore/page/Settings.cpp	Tue Mar  8 15:48:38 2011
@@ -128,6 +128,7 @@ Settings::Settings(Page* page)
     , m_webGLEnabled(false)
     , m_loadDeferringEnabled(true)
     , m_tiledBackingStoreEnabled(false)
+    , m_dnsPrefetchingEnabled(true)
 {
     // A Frame may not have been created yet, so we initialize the AtomicString 
     // hash before trying to use it.
@@ -509,6 +510,11 @@ void Settings::setShouldPaintNativeControls(bool shoul
 void Settings::setUsesEncodingDetector(bool usesEncodingDetector)
 {
     m_usesEncodingDetector = usesEncodingDetector;
+}
+
+void Settings::setDNSPrefetchingEnabled(bool dnsPrefetchingEnabled)
+{
+    m_dnsPrefetchingEnabled = dnsPrefetchingEnabled;
 }
 
 void Settings::setAllowScriptsToCloseWindows(bool allowScriptsToCloseWindows)
--- WebCore/page/Settings.h.orig	Fri Sep 10 08:20:33 2010
+++ WebCore/page/Settings.h	Tue Mar  8 10:16:45 2011
@@ -158,6 +158,9 @@ namespace WebCore {
         void setUsesEncodingDetector(bool);
         bool usesEncodingDetector() const { return m_usesEncodingDetector; }
 
+	void setDNSPrefetchingEnabled(bool);
+	bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; }
+
         void setUserStyleSheetLocation(const KURL&);
         const KURL& userStyleSheetLocation() const { return m_userStyleSheetLocation; }
 
@@ -376,6 +379,7 @@ namespace WebCore {
         bool m_webGLEnabled : 1;
         bool m_loadDeferringEnabled : 1;
         bool m_tiledBackingStoreEnabled : 1;
+	bool m_dnsPrefetchingEnabled : 1;
 
 #if USE(SAFARI_THEME)
         static bool gShouldPaintNativeControls;
--- WebKit/gtk/ChangeLog.orig	Tue Mar  8 16:17:18 2011
+++ WebKit/gtk/ChangeLog	Tue Mar  8 16:14:29 2011
@@ -1,3 +1,20 @@
+2011-03-08  Marco Peereboom  <marco at peereboom.us>
+
+        Reviewed no one yet
+
+        Provide a knob to enable/disable DNS prefetching.
+        DNS prefetching is enabled by default.
+        https://bugs.webkit.org/show_bug.cgi?id=28825
+
+        * WebKit/gtk/webkit/webkitwebsettings.cpp:
+        (webkit_web_settings_class_init):
+        (webkit_web_settings_set_property):
+        (webkit_web_settings_get_property):
+        (webkit_web_settings_copy):
+        * webkit/webkitwebview.cpp:
+        (webkit_web_view_update_settings):
+        (webkit_web_view_settings_notify):
+
 2010-06-15  Xan Lopez  <xlopez at igalia.com>
 
         Reviewed by Gustavo Noronha.
--- WebKit/gtk/webkit/webkitwebsettings.cpp.orig	Tue Mar  8 11:35:14 2011
+++ WebKit/gtk/webkit/webkitwebsettings.cpp	Tue Mar  8 16:40:24 2011
@@ -108,6 +108,7 @@ struct _WebKitWebSettingsPrivate {
     gboolean enable_page_cache;
     gboolean auto_resize_window;
     gboolean enable_java_applet;
+    gboolean dns_prefetch;
 };
 
 #define WEBKIT_WEB_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate))
@@ -157,7 +158,8 @@ enum {
     PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
     PROP_ENABLE_PAGE_CACHE,
     PROP_AUTO_RESIZE_WINDOW,
-    PROP_ENABLE_JAVA_APPLET
+    PROP_ENABLE_JAVA_APPLET,
+    PROP_DNS_PREFETCH
 };
 
 // Create a default user agent string
@@ -857,6 +859,21 @@ static void webkit_web_settings_class_init(WebKitWebSe
                                                          TRUE,
                                                          flags));
 
+    /**
+    * WebKitWebSettings:dns-prefetch
+    *
+    * Whether webkit prefetches domain names
+    *
+    * Since: 1.2.8.
+    */
+    g_object_class_install_property(gobject_class,
+                                    PROP_DNS_PREFETCH,
+                                    g_param_spec_boolean("dns-prefetch",
+                                                         _("WebKit prefetches domain names"),
+                                                         _("Whether WebKit prefetches domain names"),
+                                                         TRUE,
+                                                         flags));
+
     g_type_class_add_private(klass, sizeof(WebKitWebSettingsPrivate));
 }
 
@@ -1077,6 +1094,9 @@ static void webkit_web_settings_set_property(GObject* 
     case PROP_ENABLE_JAVA_APPLET:
         priv->enable_java_applet = g_value_get_boolean(value);
         break;
+    case PROP_DNS_PREFETCH:
+        priv->dns_prefetch = g_value_get_boolean(value);
+	break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -1218,6 +1238,9 @@ static void webkit_web_settings_get_property(GObject* 
     case PROP_ENABLE_JAVA_APPLET:
         g_value_set_boolean(value, priv->enable_java_applet);
         break;
+    case PROP_DNS_PREFETCH:
+        g_value_set_boolean(value, priv->dns_prefetch);
+	break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -1291,6 +1314,7 @@ WebKitWebSettings* webkit_web_settings_copy(WebKitWebS
                  "enable-page-cache", priv->enable_page_cache,
                  "auto-resize-window", priv->auto_resize_window,
                  "enable-java-applet", priv->enable_java_applet,
+                 "dns-prefetch", priv->dns_prefetch,
                  NULL));
 
     return copy;
--- WebKit/gtk/webkit/webkitwebview.cpp.orig	Tue Mar  8 11:29:41 2011
+++ WebKit/gtk/webkit/webkitwebview.cpp	Tue Mar  8 12:20:10 2011
@@ -2662,7 +2662,7 @@ static void webkit_web_view_update_settings(WebKitWebV
         javaScriptCanAccessClipboard, enableOfflineWebAppCache,
         enableUniversalAccessFromFileURI, enableFileAccessFromFileURI,
         enableDOMPaste, tabKeyCyclesThroughElements,
-        enableSiteSpecificQuirks, usePageCache, enableJavaApplet;
+        enableSiteSpecificQuirks, usePageCache, enableJavaApplet, dnsPrefetch;
 
     WebKitEditingBehavior editingBehavior;
 
@@ -2699,6 +2699,7 @@ static void webkit_web_view_update_settings(WebKitWebV
                  "enable-site-specific-quirks", &enableSiteSpecificQuirks,
                  "enable-page-cache", &usePageCache,
                  "enable-java-applet", &enableJavaApplet,
+                 "dns-prefetch", &dnsPrefetch,
                  NULL);
 
     settings->setDefaultTextEncodingName(defaultEncoding);
@@ -2734,6 +2735,7 @@ static void webkit_web_view_update_settings(WebKitWebV
     settings->setNeedsSiteSpecificQuirks(enableSiteSpecificQuirks);
     settings->setUsesPageCache(usePageCache);
     settings->setJavaEnabled(enableJavaApplet);
+    settings->setDNSPrefetchingEnabled(dnsPrefetch);
 
     Page* page = core(webView);
     if (page)
@@ -2845,6 +2847,8 @@ static void webkit_web_view_settings_notify(WebKitWebS
         settings->setUsesPageCache(g_value_get_boolean(&value));
     else if (name == g_intern_string("enable-java-applet"))
         settings->setJavaEnabled(g_value_get_boolean(&value));
+    else if (name == g_intern_string("dns-prefetch"))
+        settings->setDNSPrefetchingEnabled(g_value_get_boolean(&value));
     else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name))
         g_warning("Unexpected setting '%s'", name);
     g_value_unset(&value);



More information about the webkit-gtk mailing list