Bug 801318 Override the UA string for Moodle to get the rich text editor rather than plain textareas (Port Bug 799502) branch safe patch. r=IanN r=NeilAway a=Callek
authorPhilip Chee <philip.chee@gmail.com>
Sun, 14 Oct 2012 01:45:30 +0800
changeset 13497 be7a76ff160895a83c5d8062e6306df3fd11ca42
parent 13496 afcebf68edf6b6ed9584b51c320ed65eade8694e
child 13498 33330479abf8ab35ddb0f096f88aab28f932f95c
push idunknown
push userunknown
push dateunknown
reviewersIanN, NeilAway, Callek
bugs801318, 799502
Bug 801318 Override the UA string for Moodle to get the rich text editor rather than plain textareas (Port Bug 799502) branch safe patch. r=IanN r=NeilAway a=Callek
suite/browser/browser-prefs.js
suite/common/src/nsSuiteGlue.js
--- a/suite/browser/browser-prefs.js
+++ b/suite/browser/browser-prefs.js
@@ -27,20 +27,22 @@ pref("general.startup.addressbook",     
 pref("general.open_location.last_url",      "");
 pref("general.open_location.last_window_choice", 0);
 
 pref("general.smoothScroll", false);
 pref("general.autoScroll", true);
 
 pref("general.useragent.compatMode.firefox", true);
 
-// Send aol.com the legacy build date instead of the version number in the UA's
-// Gecko token as a temporary measure against bug 778408 (mail.aol.com defaults
-// to basic web UI when accessed with a user agent without Gecko/20100101).
-pref("general.useragent.override.aol.com", "Gecko/[^ ]*#Gecko/20100101");
+// site-specific User Agent settings. Example:
+//   To send aol.com the legacy build date instead of the version number in
+//   the UA's Gecko token because mail.aol.com defaults to basic web UI when
+//   accessed with a user agent without Gecko/20100101.
+//   pref("general.useragent.override.aol.com", "Gecko/[^ ]*#Gecko/20100101");
+pref("general.useragent.complexOverride.moodle", true); // bug 797703
 
 // 0 = blank, 1 = home (browser.startup.homepage), 2 = last visited page, 3 = resume previous browser session
 pref("browser.startup.page",                1);
 pref("browser.startup.homepage",	   "chrome://navigator-region/locale/region.properties");
 pref("browser.startup.homepage.count", 1);
 
 pref("browser.warnOnQuit", true);
 pref("browser.warnOnRestart", true);
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -305,17 +305,37 @@ SuiteGlue.prototype = {
 
     if (Services.prefs.prefHasUserValue("privacy.sanitize.didShutdownSanitize")) {
       Services.prefs.clearUserPref("privacy.sanitize.didShutdownSanitize");
       // We need to persist this preference change, since we want to
       // check it at next app start even if the browser exits abruptly
       Services.prefs.savePrefFile(null);
     }
 
+    this._setUpUserAgentOverrides();
+  },
+
+  _setUpUserAgentOverrides: function ()
+  {
     UserAgentOverrides.init();
+
+    function addMoodleOverride(aHttpChannel, aOriginalUA)
+    {
+      var cookies;
+      try {
+        cookies = aHttpChannel.getRequestHeader("Cookie");
+      } catch (e) { /* no cookie sent */ }
+
+      if (cookies && cookies.indexOf("MoodleSession") > -1)
+        return aOriginalUA.replace(/Gecko\/[^ ]*/, "Gecko/20100101");
+      return null;
+    }
+
+    if (Services.prefs.getBoolPref("general.useragent.complexOverride.moodle"))
+      UserAgentOverrides.addComplexOverride(addMoodleOverride);
   },
 
   // Browser startup complete. All initial windows have opened.
   _onBrowserStartup: function(aWindow)
   {
     if (Services.prefs.getBoolPref("plugins.update.notifyUser"))
       this._showPluginUpdatePage(aWindow);