From 3fcaf094f407c3e390ecfb323347e1eb1c1d4bdd Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Mon, 14 Jun 2010 16:10:04 -0700 Subject: [PATCH] Bug 570488 - Fix loading of XPTs nested in JARs [2/2] r=mwu --HG-- extra : rebase_source : b97a591c0260daed1f2ef2eba69e60ff82acd18f --- modules/libjar/nsJARFactory.cpp | 7 --- modules/libjar/nsXPTZipLoader.cpp | 26 +++----- modules/libjar/nsXPTZipLoader.h | 9 +-- modules/libjar/objs.mk | 1 + testing/xpcshell/Makefile.in | 4 ++ xpcom/build/nsXPComInit.cpp | 8 +-- .../xptinfo/src/xptiInterfaceInfoManager.cpp | 13 ++-- xpcom/tests/Makefile.in | 5 ++ xpcom/tests/xptinfo/Makefile.in | 59 +++++++++++++++++++ xpcom/tests/xptinfo/xptiITestInterface.idl | 47 +++++++++++++++ .../xptinfo/xptunit/test_jar_xptloading.js | 7 +++ 11 files changed, 139 insertions(+), 47 deletions(-) create mode 100644 xpcom/tests/xptinfo/Makefile.in create mode 100644 xpcom/tests/xptinfo/xptiITestInterface.idl create mode 100644 xpcom/tests/xptinfo/xptunit/test_jar_xptloading.js diff --git a/modules/libjar/nsJARFactory.cpp b/modules/libjar/nsJARFactory.cpp index 32c8fe4db04..e312c0878e4 100644 --- a/modules/libjar/nsJARFactory.cpp +++ b/modules/libjar/nsJARFactory.cpp @@ -54,13 +54,11 @@ #include "nsJAR.h" #include "nsIJARFactory.h" #include "nsRecyclingAllocator.h" -#include "nsXPTZipLoader.h" #include "nsJARProtocolHandler.h" #include "nsJARURI.h" extern nsRecyclingAllocator *gZlibAllocator; -NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPTZipLoader) NS_GENERIC_FACTORY_CONSTRUCTOR(nsJAR) NS_GENERIC_FACTORY_CONSTRUCTOR(nsZipReaderCache) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsJARProtocolHandler, @@ -70,11 +68,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsJARURI) // The list of components we register static const nsModuleComponentInfo components[] = { - { "XPT Zip Reader", - NS_XPTZIPREADER_CID, - NS_XPTLOADER_CONTRACTID_PREFIX "zip", - nsXPTZipLoaderConstructor - }, { "Zip Reader", NS_ZIPREADER_CID, "@mozilla.org/libjar/zip-reader;1", diff --git a/modules/libjar/nsXPTZipLoader.cpp b/modules/libjar/nsXPTZipLoader.cpp index 02fe27baea1..cc6b7f3f884 100644 --- a/modules/libjar/nsXPTZipLoader.cpp +++ b/modules/libjar/nsXPTZipLoader.cpp @@ -39,15 +39,10 @@ #include "nsXPTZipLoader.h" -#include "nsIZipReader.h" -#include "nsXPIDLString.h" +#include "nsJAR.h" #include "nsString.h" #include "nsStringEnumerator.h" -static const char gCacheContractID[] = - "@mozilla.org/libjar/zip-reader-cache;1"; -static const PRUint32 gCacheSize = 1; - nsXPTZipLoader::nsXPTZipLoader() { } @@ -102,22 +97,15 @@ nsXPTZipLoader::EnumerateEntries(nsILocalFile* aFile, return NS_OK; } -nsIZipReader* +already_AddRefed nsXPTZipLoader::GetZipReader(nsILocalFile* file) { NS_ASSERTION(file, "bad file"); - if(!mCache) - { - mCache = do_CreateInstance(gCacheContractID); - if(!mCache || NS_FAILED(mCache->Init(gCacheSize))) - return nsnull; - } + nsCOMPtr reader = new nsJAR(); + nsresult rv = reader->Open(file); + if (NS_FAILED(rv)) + return NULL; - nsIZipReader* reader = nsnull; - - if(NS_FAILED(mCache->GetZip(file, &reader))) - return nsnull; - - return reader; + return reader.forget(); } diff --git a/modules/libjar/nsXPTZipLoader.h b/modules/libjar/nsXPTZipLoader.h index 80029cbd7e2..2dc6b2f7046 100644 --- a/modules/libjar/nsXPTZipLoader.h +++ b/modules/libjar/nsXPTZipLoader.h @@ -42,12 +42,6 @@ #include "nsIZipReader.h" -// {0320E073-79C7-4dae-8055-81BED8B8DB96} -#define NS_XPTZIPREADER_CID \ - { 0x320e073, 0x79c7, 0x4dae, \ - { 0x80, 0x55, 0x81, 0xbe, 0xd8, 0xb8, 0xdb, 0x96 } } - - class nsXPTZipLoader : public nsIXPTLoader { public: @@ -58,7 +52,6 @@ class nsXPTZipLoader : public nsIXPTLoader NS_DECL_NSIXPTLOADER private: - nsIZipReader* GetZipReader(nsILocalFile* aFile); - nsCOMPtr mCache; + already_AddRefed GetZipReader(nsILocalFile* aFile); }; diff --git a/modules/libjar/objs.mk b/modules/libjar/objs.mk index f4e2f51f8a3..a422746195c 100644 --- a/modules/libjar/objs.mk +++ b/modules/libjar/objs.mk @@ -49,6 +49,7 @@ MODULES_LIBJAR_LCPPSRCS = \ MODULES_LIBJAR_LEXPORTS = \ zipstruct.h \ nsZipArchive.h \ + nsXPTZipLoader.h \ $(NULL) MODULES_LIBJAR_LXPIDLSRCS = \ diff --git a/testing/xpcshell/Makefile.in b/testing/xpcshell/Makefile.in index 38e957b397d..4ff4aa76618 100644 --- a/testing/xpcshell/Makefile.in +++ b/testing/xpcshell/Makefile.in @@ -82,6 +82,10 @@ ifdef MOZ_CRASHREPORTER TEST_HARNESS_COMPONENTS += crashreporter_test.xpt endif +ifdef MOZ_ENABLE_LIBXUL +TEST_HARNESS_COMPONENTS += xpcom_typelib_test.jar +endif + # Rules for staging the necessary harness bits for a test package PKG_STAGE = $(DIST)/test-package-stage diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index e687ce96cb9..a95360c187f 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -696,18 +696,12 @@ NS_InitXPCOM3(nsIServiceManager* *result, NS_TIME_FUNCTION_MARK("Next: interface info manager init"); - // Pay the cost at startup time of starting this singleton. + // The iimanager constructor searches and registers XPT files. nsIInterfaceInfoManager* iim = xptiInterfaceInfoManager::GetSingleton(); NS_TIME_FUNCTION_MARK("Next: try to load compreg.dat"); -#if 0 // The constructor does this, don't do it twice! - // If the component registry is out of date, malformed, or incomplete, - // autoregister the default component directories. - (void) iim->AutoRegisterInterfaces(); -#endif, - // "Re-register the world" if compreg.dat doesn't exist rv = nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry(); if (NS_FAILED(rv)) { diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index 03fc15d07b1..339f382ff70 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -45,6 +45,7 @@ #include "nsISupportsArray.h" #include "nsArrayEnumerator.h" #include "mozilla/FunctionTimer.h" +#include "nsXPTZipLoader.h" #define NS_ZIPLOADER_CONTRACTID NS_XPTLOADER_CONTRACTID_PREFIX "zip" @@ -296,14 +297,14 @@ xptiInterfaceInfoManager::RegisterFile(nsILocalFile* aFile, xptiFileType::Type a RegisterXPTHeader(header); break; } - - case xptiFileType::ZIP: { - // XXX XPCOM registration ordering issue, use C++! - nsCOMPtr loader = do_GetService(NS_ZIPLOADER_CONTRACTID); - if (!loader) - return; + case xptiFileType::ZIP: { +#ifndef MOZ_ENABLE_LIBXUL + NS_WARNING("Trying to register XPTs in a JAR in a non-libxul build"); +#else + nsCOMPtr loader = new nsXPTZipLoader(); loader->EnumerateEntries(aFile, this); +#endif break; } diff --git a/xpcom/tests/Makefile.in b/xpcom/tests/Makefile.in index f23f5437bbf..f90ccdf331d 100644 --- a/xpcom/tests/Makefile.in +++ b/xpcom/tests/Makefile.in @@ -49,6 +49,11 @@ MOZILLA_INTERNAL_API = 1 endif DIRS = dynamic services external + +ifdef MOZ_ENABLE_LIBXUL +DIRS += xptinfo +endif + ifeq ($(OS_ARCH),WINNT) DIRS += windows endif diff --git a/xpcom/tests/xptinfo/Makefile.in b/xpcom/tests/xptinfo/Makefile.in new file mode 100644 index 00000000000..d6537a4bb26 --- /dev/null +++ b/xpcom/tests/xptinfo/Makefile.in @@ -0,0 +1,59 @@ +# ***** 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 Firefox. +# +# The Initial Developer of the Original Code is +# the Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# 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 = xpcom +XPIDL_MODULE = xpcom_typelib_testxpt +NO_DIST_INSTALL = 1 + +XPIDLSRCS = xptiITestInterface.idl + +XPCSHELL_TESTS = xptunit + +include $(topsrcdir)/config/rules.mk + +xpcom_typelib_test.jar:: $(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt + $(RM) -f $@ + cd $(XPIDL_GEN_DIR) && $(ZIP) -q ../$(@F) $(^F) + +libs:: xpcom_typelib_test.jar + $(INSTALL) $^ $(FINAL_TARGET)/components diff --git a/xpcom/tests/xptinfo/xptiITestInterface.idl b/xpcom/tests/xptinfo/xptiITestInterface.idl new file mode 100644 index 00000000000..36f368eb379 --- /dev/null +++ b/xpcom/tests/xptinfo/xptiITestInterface.idl @@ -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 Mozilla Firefox. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation . + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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" + +/** + * This interface is not implemented: it exists only for a test of whether + * we load XPTs from JAR files correctly. + */ +[scriptable, uuid(13c9fc33-40e6-44dc-81e2-21e0dd41f232)] +interface xptiITestInterface : nsISupports +{ + void testMethod(in unsigned long testArg); +}; diff --git a/xpcom/tests/xptinfo/xptunit/test_jar_xptloading.js b/xpcom/tests/xptinfo/xptunit/test_jar_xptloading.js new file mode 100644 index 00000000000..338bc53c1e5 --- /dev/null +++ b/xpcom/tests/xptinfo/xptunit/test_jar_xptloading.js @@ -0,0 +1,7 @@ +const xptiITestInterface_IID = "{13c9fc33-40e6-44dc-81e2-21e0dd41f232}"; + +var id = Components.interfaces.xptiITestInterface; +do_check_true(id, "xptiITestInterface not registered"); + +var id2 = Components.interfacesById[xptiITestInterface_IID]; +do_check_true(id === id2, "xptiITestInterface info doesn't match");