From 08994fba05fae8d257e13fea689423966b8afa08 Mon Sep 17 00:00:00 2001
From: Robert Story <rstory@localhost>
Date: Mon, 4 Jun 2012 15:55:16 -0400
Subject: [PATCH 20/25] XULRUNNER add DNSSEC preferences to browser

---
 browser/components/preferences/advanced.xul          | 20 ++++++++++++++++++++
 .../en-US/chrome/browser/preferences/advanced.dtd    | 10 ++++++++++
 layout/base/nsPresContext.cpp                        | 17 +++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/browser/components/preferences/advanced.xul b/browser/components/preferences/advanced.xul
index ad07e28..af8f3ec 100644
--- a/browser/components/preferences/advanced.xul
+++ b/browser/components/preferences/advanced.xul
@@ -97,6 +97,9 @@
       <preference id="security.disable_button.openDeviceManager"
                   name="security.disable_button.openDeviceManager"
                   type="bool"/>
+      <preference id="security.dnssec.dnssecBehavior"
+                  name="security.dnssec.dnssecBehavior"
+                  type="int"/>
     </preferences>
     
 #ifdef HAVE_SHELL_SERVICE
@@ -114,6 +117,7 @@
         <tab id="networkTab" label="&networkTab.label;" helpTopic="prefs-advanced-network"/>
         <tab id="updateTab" label="&updateTab.label;"  helpTopic="prefs-advanced-update"/>
         <tab id="encryptionTab" label="&encryptionTab.label;" helpTopic="prefs-advanced-encryption"/>
+        <tab id="dnssecTab" label="&dnssecTab.label;" helpTopic="prefs-advanced-dnssec"/>
       </tabs>
 
       <tabpanels flex="1">
@@ -408,6 +412,22 @@
           </groupbox>
         </tabpanel>
 
+        <tabpanel orient="vertical">
+          <groupbox>
+            <caption label="&dnsSecurity.label;"/>
+            <description>&dnssec.description;</description>
+           <radiogroup id="networkDnssecBehaviour"
+                       preference="security.dnssec.dnssecBehavior">
+             <radio value="2" label="&allDNSSecure.label;"
+                    accesskey="&allDNSSecure.accesskey;"/>
+             <radio value="1" label="&neverDNSSecure.label;"
+                    accesskey="&neverDNSSecure.accesskey;"/>
+             <radio value="0" label="&possibleDNSSecure.label;"
+                    accesskey="&possibleDNSSecure.accesskey;" selected="true"/>
+           </radiogroup>
+          </groupbox>
+        </tabpanel>
+
       </tabpanels>
     </tabbox>
   </prefpane>
diff --git a/browser/locales/en-US/chrome/browser/preferences/advanced.dtd b/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
index 5eddbb7..6442f54 100644
--- a/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
+++ b/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
@@ -120,3 +120,13 @@
 <!ENTITY verify2.accesskey               "V">
 <!ENTITY viewSecurityDevices.label       "Security Devices">
 <!ENTITY viewSecurityDevices.accesskey   "y">
+
+<!ENTITY dnssecTab.label                "DNS Security">
+<!ENTITY dnssec.description             "DNS Security Policy is currently set at the system level (e.g. /etc/dnsval.conf) and this option specifies if the configured DNS Security policy should be enforced.">
+<!ENTITY dnsSecurity.label              "DNS Security Policy">
+<!ENTITY neverDNSSecure.label           "Ignore DNS security">
+<!ENTITY neverDNSSecure.accesskey       "N">
+<!ENTITY possibleDNSSecure.label        "Enforce DNS Security System Policy">
+<!ENTITY possibleDNSSecure.accesskey    "E">
+<!ENTITY allDNSSecure.label             "Require all DNS lookups to be secure">
+<!ENTITY allDNSSecure.accesskey         "A">
diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
index cfac149..df1fbe5 100644
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -36,6 +36,8 @@
 #include "nsIWeakReferenceUtils.h"
 #include "nsCSSRendering.h"
 #include "prprf.h"
+#include "prnetdb.h"
+#include "nsContentPolicyUtils.h"
 #include "nsAutoPtr.h"
 #include "nsEventStateManager.h"
 #include "nsThreadUtils.h"
@@ -293,6 +295,11 @@ nsPresContext::~nsPresContext()
   Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
                                   "image.animation_mode",
                                   this);
+#ifdef MOZ_DNSSEC
+  Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
+                                  "security.dnssec.dnssecBehavior",
+                                  this);
+#endif
 #ifdef IBMBIDI
   Preferences::UnregisterCallback(nsPresContext::PrefChangedCallback,
                                   "bidi.",
@@ -783,6 +790,11 @@ nsPresContext::GetUserPreferences()
   // prescontext or we are being called from UpdateAfterPreferencesChanged()
   // which triggers a reflow anyway.
   SetBidi(bidiOptions, false);
+
+#ifdef MOZ_DNSSEC
+  PR_set_dnssec_validate_policy(Preferences::GetInt("security.dnssec.dnssecBehavior"));
+#endif /* MOZ_DNSSEC */
+
 }
 
 void
@@ -981,6 +993,11 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext)
   Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
                                 "image.animation_mode",
                                 this);
+#ifdef MOZ_DNSSEC
+  Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
+                                 "security.dnssec.dnssecBehavior",
+                                 this);
+#endif
 #ifdef IBMBIDI
   Preferences::RegisterCallback(nsPresContext::PrefChangedCallback,
                                 "bidi.",
-- 
1.7.11.7

