Bug 695843 part 10 - Allow nested omni.jar and build one for Android. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 08 Dec 2011 11:03:36 +0100
changeset 82252 792a9ba2aa26628e4eb540b51dfe66f6479d6e06
parent 82251 502c67d69baa1c2e214781d5d92df7db9e4c0918
child 82253 1e0d0ad9767a009180f4ffc3409fbff5b23582ba
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs695843
milestone11.0a1
Bug 695843 part 10 - Allow nested omni.jar and build one for Android. r=bsmedberg
toolkit/mozapps/installer/packager.mk
xpcom/build/Omnijar.cpp
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -255,19 +255,16 @@ INNER_MAKE_PACKAGE = $(RPM_CMD)
 #Avoiding rpm repacks, going to try creating/uploading xpi in rpm files instead
 INNER_UNMAKE_PACKAGE = $(error Try using rpm2cpio and cpio)
 
 endif #Create an RPM file
 
 
 ifeq ($(MOZ_PKG_FORMAT),APK)
 
-# we have custom stuff for Android
-MOZ_OMNIJAR =
-
 JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
 include $(topsrcdir)/config/android-common.mk
 
 JARSIGNER ?= echo
 
 DIST_FILES = \
   resources.arsc \
   AndroidManifest.xml \
@@ -341,17 +338,18 @@ INNER_MAKE_PACKAGE	= \
     mv libmozutils.so $(MOZ_CHILD_PROCESS_NAME) lib/$(ABI_DIR) && \
     rm -f lib.id && \
     for SOMELIB in *.so ; \
     do \
       printf "`basename $$SOMELIB`:`$(_ABS_DIST)/host/bin/file_id $$SOMELIB`\n" >> lib.id ; \
     done && \
     unzip -o $(_ABS_DIST)/gecko.ap_ && \
     rm $(_ABS_DIST)/gecko.ap_ && \
-    $(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ $(DIST_FILES) -x $(NON_DIST_FILES) ) && \
+    $(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ $(DIST_FILES) -x $(NON_DIST_FILES) && \
+    $(ZIP) -0 $(_ABS_DIST)/gecko.ap_ $(OMNIJAR_NAME)) && \
   rm -f $(_ABS_DIST)/gecko.apk && \
   $(APKBUILDER) $(_ABS_DIST)/gecko.apk -v $(APKBUILDER_FLAGS) -z $(_ABS_DIST)/gecko.ap_ -f $(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH)/classes.dex && \
   cp $(_ABS_DIST)/gecko.apk $(_ABS_DIST)/gecko-unsigned-unaligned.apk && \
   $(JARSIGNER) $(_ABS_DIST)/gecko.apk && \
   $(ZIPALIGN) -f -v 4 $(_ABS_DIST)/gecko.apk $(PACKAGE)
 INNER_UNMAKE_PACKAGE	= \
   mkdir $(MOZ_PKG_DIR) && \
   cd $(MOZ_PKG_DIR) && \
--- a/xpcom/build/Omnijar.cpp
+++ b/xpcom/build/Omnijar.cpp
@@ -46,16 +46,17 @@
 #include "nsNetUtil.h"
 
 namespace mozilla {
 
 nsIFile *Omnijar::sPath[2] = { nsnull, nsnull };
 nsZipArchive *Omnijar::sReader[2] = { nsnull, nsnull };
 bool Omnijar::sInitialized = false;
 static bool sIsUnified = false;
+static bool sIsNested[2] = { false, false };
 
 static const char *sProp[2] =
     { NS_GRE_DIR, NS_XPCOM_CURRENT_PROCESS_DIR };
 
 #define SPROP(Type) ((Type == mozilla::Omnijar::GRE) ? sProp[GRE] : sProp[APP])
 
 void
 Omnijar::CleanUpOne(Type aType)
@@ -106,16 +107,24 @@ Omnijar::InitOne(nsIFile *aPath, Type aT
         return;
     }
 
     nsRefPtr<nsZipArchive> zipReader = new nsZipArchive();
     if (NS_FAILED(zipReader->OpenArchive(file))) {
         return;
     }
 
+    nsRefPtr<nsZipHandle> handle;
+    if (NS_SUCCEEDED(nsZipHandle::Init(zipReader, NS_STRINGIFY(OMNIJAR_NAME), getter_AddRefs(handle)))) {
+        zipReader = new nsZipArchive();
+        if (NS_FAILED(zipReader->OpenArchive(handle)))
+            return;
+        sIsNested[aType] = true;
+    }
+
     CleanUpOne(aType);
     sReader[aType] = zipReader;
     NS_IF_ADDREF(sReader[aType]);
     sPath[aType] = file;
     NS_IF_ADDREF(sPath[aType]);
 }
 
 void
@@ -137,22 +146,22 @@ Omnijar::CleanUp()
 already_AddRefed<nsZipArchive>
 Omnijar::GetReader(nsIFile *aPath)
 {
     NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized");
 
     bool equals;
     nsresult rv;
 
-    if (sPath[GRE]) {
+    if (sPath[GRE] && !sIsNested[GRE]) {
         rv = sPath[GRE]->Equals(aPath, &equals);
         if (NS_SUCCEEDED(rv) && equals)
             return GetReader(GRE);
     }
-    if (sPath[APP]) {
+    if (sPath[APP] && !sIsNested[APP]) {
         rv = sPath[APP]->Equals(aPath, &equals);
         if (NS_SUCCEEDED(rv) && equals)
             return GetReader(APP);
     }
     return nsnull;
 }
 
 nsresult
@@ -168,18 +177,22 @@ Omnijar::GetURIString(Type aType, nsACSt
     }
 
     nsCAutoString omniJarSpec;
     if (sPath[aType]) {
         nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec);
         NS_ENSURE_SUCCESS(rv, rv);
 
         result = "jar:";
+        if (sIsNested[aType])
+            result += "jar:";
         result += omniJarSpec;
         result += "!";
+        if (sIsNested[aType])
+            result += "/" NS_STRINGIFY(OMNIJAR_NAME) "!";
     } else {
         nsCOMPtr<nsIFile> dir;
         nsDirectoryService::gService->Get(SPROP(aType), NS_GET_IID(nsIFile), getter_AddRefs(dir));
         nsresult rv = NS_GetURLSpecFromActualFile(dir, result);
         NS_ENSURE_SUCCESS(rv, rv);
     }
     result += "/";
     return NS_OK;