Bug 346010 - Decom nsIJAR by merging it into nsIZipReader. r=tglek, sr=bsmedberg
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sun, 07 Mar 2010 22:56:45 +0900
changeset 39049 9dbceefc8c6c68a5777652ea17aebf1ae91cd8a3
parent 39048 48c9e26f70b456e3d3d831badc331e4b2547734b
child 39050 1dcea1cb129d20d946ce7d024698e5c44d865a84
push id11994
push userm_kato@ga2.so-net.ne.jp
push dateSun, 07 Mar 2010 14:01:45 +0000
treeherdermozilla-central@9dbceefc8c6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstglek, bsmedberg
bugs346010
milestone1.9.3a3pre
Bug 346010 - Decom nsIJAR by merging it into nsIZipReader. r=tglek, sr=bsmedberg
caps/src/nsScriptSecurityManager.cpp
modules/libjar/nsIJAR.idl
modules/libjar/nsIZipReader.idl
modules/libjar/nsJAR.cpp
modules/libjar/nsJAR.h
modules/libjar/nsJARChannel.cpp
modules/libjar/objs.mk
modules/libjar/test/chrome/test_bug386153.html
toolkit/mozapps/extensions/nsExtensionManager.js
xpinstall/src/nsXPInstallManager.cpp
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -66,17 +66,16 @@
 #include "nsTextFormatter.h"
 #include "nsIStringBundle.h"
 #include "nsNetUtil.h"
 #include "nsIProperties.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIFile.h"
 #include "nsIFileURL.h"
 #include "nsIZipReader.h"
-#include "nsIJAR.h"
 #include "nsIPluginInstance.h"
 #include "nsIXPConnect.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIPrompt.h"
 #include "nsIWindowWatcher.h"
@@ -2866,19 +2865,17 @@ nsScriptSecurityManager::SetCanEnableCap
         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
         systemCertFile->AppendNative(NS_LITERAL_CSTRING("systemSignature.jar"));
         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
         nsCOMPtr<nsIZipReader> systemCertZip = do_CreateInstance(kZipReaderCID, &rv);
         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
         rv = systemCertZip->Open(systemCertFile);
         if (NS_SUCCEEDED(rv))
         {
-            nsCOMPtr<nsIJAR> systemCertJar(do_QueryInterface(systemCertZip, &rv));
-            if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
-            rv = systemCertJar->GetCertificatePrincipal(nsnull,
+            rv = systemCertZip->GetCertificatePrincipal(nsnull,
                                                         getter_AddRefs(mSystemCertificate));
             if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
         }
     }
 
     //-- Make sure the caller's principal is the system certificate
     PRBool isEqual = PR_FALSE;
     if (mSystemCertificate)
deleted file mode 100644
--- a/modules/libjar/nsIJAR.idl
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** 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 Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Daniel Veditz <dveditz@netscape.com>
- *   Don Bragg <dbragg@netscape.com>
- *   Samir Gehani <sgehani@netscape.com>
- *   Mitch Stoltz <mstoltz@netscape.com>
- *
- * 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 ***** */
-
-#include "nsISupports.idl"
-
-%{C++
-#define NS_JAR_CID                    \
-{ /* 04501DB3-0409-11d3-BCF8-00805F0E1353*/  \
-    0x04501DB3,                              \
-    0x0409,                                  \
-    0x11d3,                                  \
-    {0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
-}
-
-#define NS_JAR_CONTRACTID \
-  "@mozilla.org/libjar;1"
-
-#define NS_IJARFactory_IID                    \
-{ /* 04501DB4-0409-11d3-BCF8-00805F0E1353 */         \
-    0x04501DB4,                                      \
-    0x0409,                                          \
-    0x11d3,                                          \
-    {0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
-}
-
-#define NS_JARFactory_CID                 \
-{ /* 04501DB5-0409-11d3-BCF8-00805F0E1353 */         \
-    0x04501DB5,                                      \
-    0x0409,                                          \
-    0x11d3,                                          \
-    {0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
-}
-%}
-
-interface nsIPrincipal;
-
-[scriptable, uuid(04501DB2-0409-11d3-BCF8-00805F0E1353)]
-interface nsIJAR : nsISupports
-{
-     /**
-     * Returns an object describing the entity which signed 
-     * an entry. parseManifest must be called first. If aEntryName is an
-     * entry in the jar, getInputStream must be called after parseManifest.
-     * If aEntryName is an external file which has meta-information 
-     * stored in the jar, verifyExternalFile (not yet implemented) must 
-     * be called before getPrincipal.
-     */
-    nsIPrincipal getCertificatePrincipal(in string aEntryName);   
-    
-    readonly attribute PRUint32 manifestEntriesCount;
-
-};
-
--- a/modules/libjar/nsIZipReader.idl
+++ b/modules/libjar/nsIZipReader.idl
@@ -42,16 +42,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIUTF8StringEnumerator;
 interface nsIInputStream;
 interface nsIFile;
+interface nsIPrincipal;
 
 [scriptable, uuid(e1c028bc-c478-11da-95a8-00e08161165f)]
 interface nsIZipEntry : nsISupports
 {
     /**
      * The type of compression used for the item.  The possible values and
      * their meanings are defined in the zip file specification at
      * http://www.pkware.com/business_and_developers/developer/appnote/
@@ -85,17 +86,17 @@ interface nsIZipEntry : nsISupports
      * directory foo/ in a zip containing exactly one entry for foo/bar.txt
      * is synthetic.  If the zip file contains an actual entry for a directory,
      * this attribute will be false for the nsIZipEntry for that directory.
      * It is impossible for a file to be synthetic.
      */
     readonly attribute boolean          isSynthetic;
 };
 
-[scriptable, uuid(5cce7f53-23b3-47f8-be05-122c0ba703fd)]
+[scriptable, uuid(27067432-cb21-437e-99d1-f85858522bb1)]
 interface nsIZipReader : nsISupports
 {
     /**
      * Opens a zip file for reading.
      * It is allowed to open with another file, 
      * but it needs to be closed first with close().
      */
     void open(in nsIFile zipFile);
@@ -193,16 +194,28 @@ interface nsIZipReader : nsISupports
     /**
      * Returns an input stream containing the contents of the specified zip
      * entry. If the entry refers to a directory (ends with '/'), a directory stream 
      * is opened, otherwise the contents of the file entry is returned.
      * @param aJarSpec the Spec of the URI for the JAR (only used for directory streams)
      * @param zipEntry the name of the entry to open the stream from
      */
     nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in string zipEntry);
+
+     /**
+     * Returns an object describing the entity which signed 
+     * an entry. parseManifest must be called first. If aEntryName is an
+     * entry in the jar, getInputStream must be called after parseManifest.
+     * If aEntryName is an external file which has meta-information 
+     * stored in the jar, verifyExternalFile (not yet implemented) must 
+     * be called before getPrincipal.
+     */
+    nsIPrincipal getCertificatePrincipal(in string aEntryName);   
+    
+    readonly attribute PRUint32 manifestEntriesCount;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIZipReaderCache
 
 [scriptable, uuid(52c45d86-0cc3-11d4-986e-00c04fa0cf4a)]
 interface nsIZipReaderCache : nsISupports
 {
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -126,17 +126,17 @@ nsJAR::nsJAR(): mManifestData(nsnull, ns
 {
 }
 
 nsJAR::~nsJAR()
 {
   Close();
 }
 
-NS_IMPL_THREADSAFE_QUERY_INTERFACE2(nsJAR, nsIZipReader, nsIJAR)
+NS_IMPL_THREADSAFE_QUERY_INTERFACE1(nsJAR, nsIZipReader)
 NS_IMPL_THREADSAFE_ADDREF(nsJAR)
 
 // Custom Release method works with nsZipReaderCache...
 nsrefcnt nsJAR::Release(void) 
 {
   nsrefcnt count; 
   NS_PRECONDITION(0 != mRefCnt, "dup release"); 
   count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); 
@@ -331,20 +331,16 @@ nsJAR::GetInputStreamWithSpec(const nsAC
     rv = jis->InitFile(this, item);
   }
   if (NS_FAILED(rv)) {
     NS_RELEASE(*result);
   }
   return rv;
 }
 
-//----------------------------------------------
-// nsIJAR implementation
-//----------------------------------------------
-
 NS_IMETHODIMP
 nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal)
 {
   //-- Parameter check
   if (!aPrincipal)
     return NS_ERROR_NULL_POINTER;
   *aPrincipal = nsnull;
 
@@ -1058,17 +1054,17 @@ nsZipReaderCache::~nsZipReaderCache()
 #endif
 }
 
 NS_IMETHODIMP
 nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result)
 {
   NS_ENSURE_ARG_POINTER(zipFile);
   nsresult rv;
-  nsCOMPtr<nsIJAR> antiLockZipGrip;
+  nsCOMPtr<nsIZipReader> antiLockZipGrip;
   nsAutoLock lock(mLock);
 
 #ifdef ZIP_CACHE_HIT_RATE
   mZipCacheLookups++;
 #endif
 
   nsCAutoString path;
   rv = zipFile->GetNativePath(path);
--- a/modules/libjar/nsJAR.h
+++ b/modules/libjar/nsJAR.h
@@ -55,17 +55,16 @@
 #include "nsIComponentManager.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIFile.h"
 #include "nsStringEnumerator.h"
 #include "nsHashtable.h"
 #include "nsAutoLock.h"
 #include "nsIZipReader.h"
-#include "nsIJAR.h"
 #include "nsZipArchive.h"
 #include "nsIPrincipal.h"
 #include "nsISignatureVerifier.h"
 #include "nsIObserverService.h"
 #include "nsWeakReference.h"
 #include "nsIObserver.h"
 
 class nsIInputStream;
@@ -85,34 +84,32 @@ typedef enum
   JAR_NOT_SIGNED          = 7
 } JARManifestStatusType;
 
 /*-------------------------------------------------------------------------
  * Class nsJAR declaration. 
  * nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of 
  * JAR manifest file parsing. 
  *------------------------------------------------------------------------*/
-class nsJAR : public nsIZipReader, public nsIJAR
+class nsJAR : public nsIZipReader
 {
   // Allows nsJARInputStream to call the verification functions
   friend class nsJARInputStream;
 
   public:
 
     nsJAR();
     virtual ~nsJAR();
     
     NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
   
     NS_DECL_ISUPPORTS
 
     NS_DECL_NSIZIPREADER
 
-    NS_DECL_NSIJAR
-
     nsresult GetJarPath(nsACString& aResult);
 
     PRIntervalTime GetReleaseTime() {
         return mReleaseTime;
     }
     
     PRBool IsReleased() {
         return mReleaseTime != PR_INTERVAL_NO_TIMEOUT;
--- a/modules/libjar/nsJARChannel.cpp
+++ b/modules/libjar/nsJARChannel.cpp
@@ -47,17 +47,16 @@
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIViewSourceChannel.h"
 #include "nsChannelProperties.h"
 
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsIFileURL.h"
-#include "nsIJAR.h"
 
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 // the entry for a directory will either be empty (in the case of the
 // top-level directory) or will end with a slash
 #define ENTRY_IS_DIRECTORY(_entry) \
   ((_entry).IsEmpty() || '/' == (_entry).Last())
 
@@ -492,24 +491,18 @@ nsJARChannel::GetOwner(nsISupports **res
     }
 
     //-- Verify signature, if one is present, and set owner accordingly
     nsCOMPtr<nsIZipReader> jarReader;
     mJarInput->GetJarReader(getter_AddRefs(jarReader));
     if (!jarReader)
         return NS_ERROR_NOT_INITIALIZED;
 
-    nsCOMPtr<nsIJAR> jar = do_QueryInterface(jarReader, &rv);
-    if (NS_FAILED(rv)) {
-        NS_ERROR("nsIJAR not supported");
-        return rv;
-    }
-
     nsCOMPtr<nsIPrincipal> cert;
-    rv = jar->GetCertificatePrincipal(mJarEntry.get(), getter_AddRefs(cert));
+    rv = jarReader->GetCertificatePrincipal(mJarEntry.get(), getter_AddRefs(cert));
     if (NS_FAILED(rv)) return rv;
 
     if (cert) {
         nsCAutoString certFingerprint;
         rv = cert->GetFingerprint(certFingerprint);
         if (NS_FAILED(rv)) return rv;
 
         nsCAutoString subjectName;
--- a/modules/libjar/objs.mk
+++ b/modules/libjar/objs.mk
@@ -47,17 +47,16 @@ MODULES_LIBJAR_LCPPSRCS = \
 		$(NULL)
 
 MODULES_LIBJAR_LEXPORTS = \
 		zipstruct.h \
 		$(NULL)
 
 MODULES_LIBJAR_LXPIDLSRCS = \
 		nsIZipReader.idl \
-		nsIJAR.idl \
 		nsIJARChannel.idl \
 		nsIJARURI.idl \
 		nsIJARProtocolHandler.idl \
 		$(NULL)
 
 MODULES_LIBJAR_CPPSRCS := $(addprefix $(topsrcdir)/modules/libjar/, $(MODULES_LIBJAR_LCPPSRCS))
 
 MODULES_LIBJAR_XPIDLSRCS := $(addprefix $(topsrcdir)/modules/libjar/, $(MODULES_LIBJAR_LXPIDLSRCS))
--- a/modules/libjar/test/chrome/test_bug386153.html
+++ b/modules/libjar/test/chrome/test_bug386153.html
@@ -33,17 +33,17 @@ function openZip(path) {
                  getService(Ci.nsIChromeRegistry).
                  convertChromeURL(chromeURI).
                  QueryInterface(Ci.nsIFileURL).
                  file;
 
   var zip = Cc["@mozilla.org/libjar/zip-reader;1"].
             createInstance(Ci.nsIZipReader);
   zip.open(resolved);
-  return zip.QueryInterface(Ci.nsIJAR);
+  return zip;
 }
 
 // Gets the pretty name from the signing cert or null if the zip is unsigned.
 function getSigner(zip) {
   var principal = zip.getCertificatePrincipal(null);
   if (principal && principal.hasCertificate)
     return principal.prettyName;
   return null;
--- a/toolkit/mozapps/extensions/nsExtensionManager.js
+++ b/toolkit/mozapps/extensions/nsExtensionManager.js
@@ -2804,17 +2804,16 @@ ExtensionManager.prototype = {
           // by the user, installing it if necessary. We do this here rather
           // than separately in |_finishOperations| because I don't want to
           // walk these lists multiple times on every startup.
           var item = this._getItemForDroppedFile(entry, location);
           if (item) {
             var prettyName = "";
             try {
               var zipReader = getZipReaderForFile(entry);
-              zipReader.QueryInterface(Ci.nsIJAR);
               var principal = zipReader.getCertificatePrincipal(null);
               if (principal && principal.hasCertificate) {
                 if (verifyZipSigning(zipReader, principal)) {
                   var x509 = principal.certificate;
                   if (x509 instanceof Ci.nsIX509Cert && x509.commonName.length > 0)
                     prettyName = x509.commonName;
                   else
                     prettyName = principal.prettyName;
--- a/xpinstall/src/nsXPInstallManager.cpp
+++ b/xpinstall/src/nsXPInstallManager.cpp
@@ -42,17 +42,16 @@
 #include "plstr.h"
 #include "nsInt64.h"
 
 #include "nsISupports.h"
 #include "nsIServiceManager.h"
 
 #include "nsIURL.h"
 #include "nsIFileURL.h"
-#include "nsIJAR.h"
 
 #include "nsITransport.h"
 #include "nsIOutputStream.h"
 #include "nsNetUtil.h"
 #include "nsIInputStream.h"
 #include "nsIFileStreams.h"
 #include "nsIStreamListener.h"
 #include "nsICryptoHash.h"
@@ -630,23 +629,19 @@ VerifySigning(nsIZipReader* hZip, nsIPri
     if (!aPrincipal)
         return NS_OK;
 
     PRBool hasCert;
     aPrincipal->GetHasCertificate(&hasCert);
     if (!hasCert)
         return NS_ERROR_FAILURE;
 
-    nsCOMPtr<nsIJAR> jar(do_QueryInterface(hZip));
-    if (!jar)
-        return NS_ERROR_FAILURE;
-
     // See if the archive is signed at all first
     nsCOMPtr<nsIPrincipal> principal;
-    nsresult rv = jar->GetCertificatePrincipal(nsnull, getter_AddRefs(principal));
+    nsresult rv = hZip->GetCertificatePrincipal(nsnull, getter_AddRefs(principal));
     if (NS_FAILED(rv) || !principal)
         return NS_ERROR_FAILURE;
 
     PRUint32 entryCount = 0;
 
     // first verify all files in the jar are also in the manifest.
     nsCOMPtr<nsIUTF8StringEnumerator> entries;
     rv = hZip->FindEntries(nsnull, getter_AddRefs(entries));
@@ -665,27 +660,27 @@ VerifySigning(nsIZipReader* hZip, nsIPri
         if ((name.Last() == '/') ||
             (PL_strncasecmp("META-INF/", name.get(), 9) == 0))
             continue;
 
         // Count the entries to be verified
         entryCount++;
 
         // Each entry must be signed
-        rv = jar->GetCertificatePrincipal(name.get(), getter_AddRefs(principal));
+        rv = hZip->GetCertificatePrincipal(name.get(), getter_AddRefs(principal));
         if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
 
         PRBool equal;
         rv = principal->Equals(aPrincipal, &equal);
         if (NS_FAILED(rv) || !equal) return NS_ERROR_FAILURE;
     }
 
     // next verify all files in the manifest are in the archive.
     PRUint32 manifestEntryCount;
-    rv = jar->GetManifestEntriesCount(&manifestEntryCount);
+    rv = hZip->GetManifestEntriesCount(&manifestEntryCount);
     if (NS_FAILED(rv))
         return rv;
 
     if (entryCount != manifestEntryCount)
         return NS_ERROR_FAILURE;  // some files were deleted from archive
 
     return NS_OK;
 }