Bug 521956 (pt2) - nsUpdateService, nsExtensionManager.js.in and, nsBlocklistService include badCertHandler.js (reduce file sizes by using a jsm). r=dtownsend
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 13 Oct 2009 12:45:20 -0700
changeset 33805 861604a73c026fe476c4c3330a33d8e918402af3
parent 33804 bcf17cac43988d77aec29ad48ed2ef9afcbef78d
child 33806 c81b1a445426d054e6289e079a1ae03fa4d61109
push id9696
push userrstrong@mozilla.com
push dateTue, 13 Oct 2009 19:45:40 +0000
treeherdermozilla-central@861604a73c02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs521956
milestone1.9.3a1pre
Bug 521956 (pt2) - nsUpdateService, nsExtensionManager.js.in and, nsBlocklistService include badCertHandler.js (reduce file sizes by using a jsm). r=dtownsend
toolkit/mozapps/Makefile.in
toolkit/mozapps/extensions/src/nsBlocklistService.js
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
toolkit/mozapps/shared/Makefile.in
toolkit/mozapps/shared/src/CertUtils.jsm
toolkit/mozapps/shared/src/Makefile.in
toolkit/mozapps/update/src/nsUpdateService.js.in
--- a/toolkit/mozapps/Makefile.in
+++ b/toolkit/mozapps/Makefile.in
@@ -38,11 +38,11 @@
 
 DEPTH   = ../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH   = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
-DIRS = downloads extensions update xpinstall plugins handling
+DIRS = downloads extensions update xpinstall plugins handling shared
 
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/mozapps/extensions/src/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/src/nsBlocklistService.js
@@ -86,17 +86,21 @@ var gConsole = null;
 var gVersionChecker = null;
 var gLoggingEnabled = null;
 var gABI = null;
 var gOSVersion = null;
 var gBlocklistEnabled = true;
 var gBlocklistLevel = DEFAULT_LEVEL;
 
 // shared code for suppressing bad cert dialogs
-#include ../../shared/src/badCertHandler.js
+XPCOMUtils.defineLazyGetter(this, "gCertUtils", function() {
+  let temp = { };
+  Components.utils.import("resource://gre/modules/CertUtils.jsm", temp);
+  return temp;
+});
 
 /**
  * Logs a string to the error console.
  * @param   string
  *          The string to write to the error console..
  */
 function LOG(string) {
   if (gLoggingEnabled) {
@@ -508,17 +512,17 @@ Blocklist.prototype = {
       LOG("Blocklist::notify: There was an error creating the blocklist URI\r\n" +
           "for: " + dsURI + ", error: " + e);
       return;
     }
 
     var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
                   createInstance(Ci.nsIXMLHttpRequest);
     request.open("GET", uri.spec, true);
-    request.channel.notificationCallbacks = new BadCertHandler();
+    request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
     request.overrideMimeType("text/xml");
     request.setRequestHeader("Cache-Control", "no-cache");
     request.QueryInterface(Components.interfaces.nsIJSXMLHttpRequest);
 
     var self = this;
     request.onerror = function(event) { self.onXMLError(event); };
     request.onload  = function(event) { self.onXMLLoad(event);  };
     request.send(null);
@@ -527,17 +531,17 @@ Blocklist.prototype = {
     // make sure we have loaded it.
     if (!this._addonEntries)
       this._loadBlocklist();
   },
 
   onXMLLoad: function(aEvent) {
     var request = aEvent.target;
     try {
-      checkCert(request.channel);
+      gCertUtils.checkCert(request.channel);
     }
     catch (e) {
       LOG("Blocklist::onXMLLoad: " + e);
       return;
     }
     var responseXML = request.responseXML;
     if (!responseXML || responseXML.documentElement.namespaceURI == XMLURI_PARSE_ERROR ||
         (request.status != 200 && request.status != 0)) {
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -207,17 +207,21 @@ var gManifestNeedsFlush   = false;
 var gDefaultTheme         = "classic/1.0";
 
 /**
  * Valid GUIDs fit this pattern.
  */
 var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i;
 
 // shared code for suppressing bad cert dialogs
-#include ../../shared/src/badCertHandler.js
+XPCOMUtils.defineLazyGetter(this, "gCertUtils", function() {
+  let temp = { };
+  Components.utils.import("resource://gre/modules/CertUtils.jsm", temp);
+  return temp;
+});
 
 /**
  * Creates a Version Checker object.
  * @returns A handle to the global Version Checker service.
  */
 function getVersionChecker() {
   if (!gVersionChecker) {
     gVersionChecker = Cc["@mozilla.org/xpcom/version-comparator;1"].
@@ -6043,30 +6047,30 @@ RDFItemUpdater.prototype = {
     }
 
     LOG("RDFItemUpdater:checkForUpdates sending a request to server for: " +
         uri.spec + ", item = " + aItem.objectSource);
 
     var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
                   createInstance(Ci.nsIXMLHttpRequest);
     request.open("GET", uri.spec, true);
-    request.channel.notificationCallbacks = new BadCertHandler();
+    request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
     request.overrideMimeType("text/xml");
     request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
 
     var self = this;
     request.onerror     = function(event) { self.onXMLError(event, aItem);    };
     request.onload      = function(event) { self.onXMLLoad(event, aItem);     };
     request.send(null);
   },
 
   onXMLLoad: function RDFItemUpdater_onXMLLoad(aEvent, aItem) {
     var request = aEvent.target;
     try {
-      checkCert(request.channel);
+      gCertUtils.checkCert(request.channel);
     }
     catch (e) {
       // This may be overly restrictive in two cases: corporate installations
       // with a corporate update server using an in-house CA cert (installed
       // but not "built-in") and lone developers hosting their updates on a
       // site with a self-signed cert (permanently accepted, otherwise the
       // BadCertHandler would prevent getting this far). Update checks will
       // fail in both these scenarios.
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/shared/Makefile.in
@@ -0,0 +1,47 @@
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is Toolkit Shared code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Corporation.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Robert Strong <robert.bugzilla@gmail.com> (Original Author)
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+DIRS = src
+
+include $(topsrcdir)/config/rules.mk
--- a/toolkit/mozapps/shared/src/CertUtils.jsm
+++ b/toolkit/mozapps/shared/src/CertUtils.jsm
@@ -33,16 +33,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #endif
+EXPORTED_SYMBOLS = [ "BadCertHandler", "checkCert" ];
 
 /**
  * Only allow built-in certs for HTTPS connections.  See bug 340198.
  */
 function checkCert(channel) {
   if (!channel.originalURI.schemeIs("https"))  // bypass
     return;
 
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/shared/src/Makefile.in
@@ -0,0 +1,56 @@
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is Toolkit Shared code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Corporation.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Robert Strong <robert.bugzilla@gmail.com> (Original Author)
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH   = ../../../..
+topsrcdir = @top_srcdir@
+srcdir    = @srcdir@
+VPATH   = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE = toolkitShared
+
+EXTRA_JS_MODULES = \
+  CertUtils.jsm \
+  $(NULL)
+
+EXTRA_PP_JS_MODULES = \
+  CertUtils.jsm \
+  $(NULL)
+
+include $(topsrcdir)/config/rules.mk
+
--- a/toolkit/mozapps/update/src/nsUpdateService.js.in
+++ b/toolkit/mozapps/update/src/nsUpdateService.js.in
@@ -124,19 +124,16 @@ const DOWNLOAD_CHUNK_SIZE           = 30
 const DOWNLOAD_BACKGROUND_INTERVAL  = 600;    // seconds
 const DOWNLOAD_FOREGROUND_INTERVAL  = 0;
 
 const UPDATE_WINDOW_NAME      = "Update:Wizard";
 
 var gLocale     = null;
 var gCanUpdate  = null;
 
-// shared code for suppressing bad cert dialogs
-#include ../../shared/src/badCertHandler.js
-
 #endif /* MOZ_UPDATER */
 
 XPCOMUtils.defineLazyServiceGetter(this, "gPref",
                                    "@mozilla.org/preferences-service;1",
                                    "nsIPrefBranch2");
 /**
  * Gets a preference value, handling the case where there is no default.
  * @param   func
@@ -194,16 +191,23 @@ function LOG(module, string) {
 function getObserverService()
 {
   return Cc["@mozilla.org/observer-service;1"].
          getService(Ci.nsIObserverService);
 }
 
 #ifdef MOZ_UPDATER
 
+// shared code for suppressing bad cert dialogs
+XPCOMUtils.defineLazyGetter(this, "gCertUtils", function() {
+  let temp = { };
+  Components.utils.import("resource://gre/modules/CertUtils.jsm", temp);
+  return temp;
+});
+
 XPCOMUtils.defineLazyGetter(this, "gApp", function() {
   return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).
          QueryInterface(Ci.nsIXULRuntime);
 });
 
 XPCOMUtils.defineLazyGetter(this, "gABI", function() {
   let abi = null;
   try {
@@ -2120,17 +2124,17 @@ Checker.prototype = {
 
     var url = this.getUpdateURL(force);
     if (!url || (!this.enabled && !force))
       return;
 
     this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
                     createInstance(Ci.nsIXMLHttpRequest);
     this._request.open("GET", url, true);
-    this._request.channel.notificationCallbacks = new BadCertHandler();
+    this._request.channel.notificationCallbacks = new gCertUtils.BadCertHandler();
     this._request.overrideMimeType("text/xml");
     this._request.setRequestHeader("Cache-Control", "no-cache");
 
     var self = this;
     this._request.onerror     = function(event) { self.onError(event);    };
     this._request.onload      = function(event) { self.onLoad(event);     };
     this._request.onprogress  = function(event) { self.onProgress(event); };
 
@@ -2208,17 +2212,17 @@ Checker.prototype = {
    * The XMLHttpRequest succeeded and the document was loaded.
    * @param   event
    *          The nsIDOMEvent for the load
    */
   onLoad: function UC_onLoad(event) {
     LOG("Checker", "onLoad - request completed downloading document");
 
     try {
-      checkCert(this._request.channel);
+      gCertUtils.checkCert(this._request.channel);
       // Analyze the resulting DOM and determine the set of updates to install
       var updates = this._updates;
 
       LOG("Checker", "onLoad - number of updates available: " + updates.length);
 
       // ... and tell the Update Service about what we discovered.
       this._callback.onCheckComplete(event.target, updates, updates.length);
     }